Skip to content

Commit

Permalink
MAPREDUCE-7415. Fix CheckStyle & Junit Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
fanshilun committed Feb 5, 2025
1 parent 884581c commit 4b12c1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.mapred.nativetask.kvtest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.io.IOException;
import java.util.List;
Expand All @@ -33,18 +34,14 @@
import org.apache.hadoop.util.Lists;
import org.junit.jupiter.api.AfterAll;
import org.apache.hadoop.util.NativeCodeLoader;
import org.junit.Assume;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hadoop.thirdparty.com.google.common.base.Splitter;

@RunWith(Parameterized.class)
public class KVTest {
private static final Logger LOG =
LoggerFactory.getLogger(KVTest.class);
Expand Down Expand Up @@ -73,7 +70,6 @@ private static List<Class<?>> parseClassNames(String spec) {
/**
* Parameterize the test with the specified key and value types.
*/
@Parameters(name = "key:{0}\nvalue:{1}")
public static Iterable<Class<?>[]> data() throws Exception {
// Parse the config.
final String valueClassesStr = nativekvtestconf
Expand All @@ -98,22 +94,24 @@ public static Iterable<Class<?>[]> data() throws Exception {
return pairs;
}

private final Class<?> keyclass;
private final Class<?> valueclass;
private Class<?> keyclass;
private Class<?> valueclass;

public KVTest(Class<?> keyclass, Class<?> valueclass) {
public void initKVTest(Class<?> keyclass, Class<?> valueclass) {
this.keyclass = keyclass;
this.valueclass = valueclass;
}

@BeforeEach
public void startUp() throws Exception {
Assume.assumeTrue(NativeCodeLoader.isNativeCodeLoaded());
Assume.assumeTrue(NativeRuntime.isNativeLibraryLoaded());
assumeTrue(NativeCodeLoader.isNativeCodeLoaded());
assumeTrue(NativeRuntime.isNativeLibraryLoaded());
}

@Test
public void testKVCompatibility() throws Exception {
@MethodSource("data")
@ParameterizedTest(name = "key:{0}\nvalue:{1}")
public void testKVCompatibility(Class<?> keyclass, Class<?> valueclass) throws Exception {
initKVTest(keyclass, valueclass);
final FileSystem fs = FileSystem.get(nativekvtestconf);
final String jobName = "Test:" + keyclass.getSimpleName() + "--"
+ valueclass.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.junit.jupiter.api.AfterAll;
import org.apache.hadoop.util.NativeCodeLoader;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@SuppressWarnings({ "rawtypes", "unchecked" })
public class TestKVSerializer {

int inputArraySize = 1000; // 1000 bytes Writable elements
private int inputArraySize = 1000; // 1000 bytes Writable elements
int bufferSize = 100; // bytes
private KV<BytesWritable, BytesWritable>[] inputArray;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,15 @@ public static void verifyCounters(Job normalJob, Job nativeJob, boolean hasCombi
throws IOException {
Counters normalCounters = normalJob.getCounters();
Counters nativeCounters = nativeJob.getCounters();
assertEquals(
normalCounters.findCounter(TaskCounter.MAP_OUTPUT_RECORDS).getValue(),
nativeCounters.findCounter(TaskCounter.MAP_OUTPUT_RECORDS).getValue(),
assertEquals(normalCounters.findCounter(TaskCounter.MAP_OUTPUT_RECORDS).getValue(),
nativeCounters.findCounter(TaskCounter.MAP_OUTPUT_RECORDS).getValue(),
"Counter MAP_OUTPUT_RECORDS should be equal");
assertEquals(normalCounters.findCounter(TaskCounter.REDUCE_INPUT_GROUPS).getValue(),
nativeCounters.findCounter(TaskCounter.REDUCE_INPUT_GROUPS).getValue(),
nativeCounters.findCounter(TaskCounter.REDUCE_INPUT_GROUPS).getValue(),
"Counter REDUCE_INPUT_GROUPS should be equal");
if (!hasCombiner) {
assertEquals(normalCounters.findCounter(TaskCounter.REDUCE_INPUT_RECORDS).getValue(),
nativeCounters.findCounter(TaskCounter.REDUCE_INPUT_RECORDS).getValue(),
nativeCounters.findCounter(TaskCounter.REDUCE_INPUT_RECORDS).getValue(),
"Counter REDUCE_INPUT_RECORDS should be equal");
}
}
Expand Down

0 comments on commit 4b12c1c

Please sign in to comment.