Skip to content

Commit c42469e

Browse files
slfan1989cnauroth
andauthored
MAPREDUCE-7421. [JDK17] Upgrade Junit 4 to 5 in hadoop-mapreduce-client-jobclient Part2. (#7372)
Co-authored-by: Chris Nauroth <[email protected]> Reviewed-by: Chris Nauroth <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent 6e7511c commit c42469e

File tree

78 files changed

+1242
-1153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1242
-1153
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestChild.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ private Job submitAndValidateJob(JobConf conf, int numMaps, int numReds,
140140
assertTrue(fs.exists(outDir), "Job output directory doesn't exit!");
141141
FileStatus[] list = fs.listStatus(outDir, new OutputFilter());
142142
int numPartFiles = numReds == 0 ? numMaps : numReds;
143-
assertTrue(list.length == numPartFiles, "Number of part-files is " + list.length + " and not "
144-
+ numPartFiles);
143+
assertTrue(list.length == numPartFiles,
144+
"Number of part-files is " + list.length + " and not " + numPartFiles);
145145
return job;
146146
}
147147

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestClientProtocolProviderImpls.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import org.apache.hadoop.mapred.YARNRunner;
2828
import org.apache.hadoop.mapreduce.server.jobtracker.JTConfig;
2929
import org.apache.hadoop.util.StringUtils;
30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
3131

32-
import static org.junit.Assert.assertTrue;
33-
import static org.junit.Assert.fail;
32+
import static org.junit.jupiter.api.Assertions.assertTrue;
33+
import static org.junit.jupiter.api.Assertions.fail;
3434

3535
public class TestClientProtocolProviderImpls {
3636

@@ -91,9 +91,9 @@ public void testClusterExceptionRootCause() throws Exception {
9191
fail("Cluster init should fail because of non-existing FileSystem");
9292
} catch (IOException ioEx) {
9393
final String stackTrace = StringUtils.stringifyException(ioEx);
94-
assertTrue("No root cause detected",
95-
stackTrace.contains(UnsupportedFileSystemException.class.getName())
96-
&& stackTrace.contains("nosuchfs"));
94+
assertTrue(stackTrace.contains(
95+
UnsupportedFileSystemException.class.getName()) && stackTrace.contains("nosuchfs"),
96+
"No root cause detected");
9797
}
9898
}
9999
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestCounters.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
import org.apache.hadoop.mapreduce.counters.Limits;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertSame;
30+
import static org.junit.jupiter.api.Assertions.assertTrue;
2731

28-
import static org.junit.Assert.*;
2932
/**
3033
* TestCounters checks the sanity and recoverability of {@code Counters}
3134
*/
@@ -46,19 +49,19 @@ public void testCounterValue() {
4649
long expectedValue = initValue;
4750
Counter counter = new Counters().findCounter("test", "foo");
4851
counter.setValue(initValue);
49-
assertEquals("Counter value is not initialized correctly",
50-
expectedValue, counter.getValue());
52+
assertEquals(expectedValue, counter.getValue(),
53+
"Counter value is not initialized correctly");
5154
for (int j = 0; j < NUMBER_INC; j++) {
5255
int incValue = rand.nextInt();
5356
counter.increment(incValue);
5457
expectedValue += incValue;
55-
assertEquals("Counter value is not incremented correctly",
56-
expectedValue, counter.getValue());
58+
assertEquals(expectedValue, counter.getValue(),
59+
"Counter value is not incremented correctly");
5760
}
5861
expectedValue = rand.nextInt();
5962
counter.setValue(expectedValue);
60-
assertEquals("Counter value is not set correctly",
61-
expectedValue, counter.getValue());
63+
assertEquals(expectedValue, counter.getValue(),
64+
"Counter value is not set correctly");
6265
}
6366
}
6467

@@ -148,6 +151,6 @@ private void shouldThrow(Class<? extends Exception> ecls, Runnable runnable) {
148151
LOG.info("got expected: "+ e);
149152
return;
150153
}
151-
assertTrue("Should've thrown "+ ecls.getSimpleName(), false);
154+
assertTrue(false, "Should've thrown "+ ecls.getSimpleName());
152155
}
153156
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestLargeSort.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@
2323
import org.apache.hadoop.mapred.MiniMRClientClusterFactory;
2424
import org.apache.hadoop.util.ToolRunner;
2525
import org.apache.hadoop.yarn.conf.YarnConfiguration;
26-
import org.junit.After;
27-
import org.junit.Before;
28-
import org.junit.Test;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
2929

3030
import java.io.IOException;
3131

32-
import static org.junit.Assert.assertEquals;
32+
import static org.junit.jupiter.api.Assertions.assertEquals;
3333

3434
public class TestLargeSort {
3535
MiniMRClientCluster cluster;
3636

37-
@Before
37+
@BeforeEach
3838
public void setup() throws IOException {
3939
Configuration conf = new YarnConfiguration();
4040
cluster = MiniMRClientClusterFactory.create(this.getClass(), 2, conf);
4141
cluster.start();
4242
}
4343

44-
@After
44+
@AfterEach
4545
public void cleanup() throws IOException {
4646
if (cluster != null) {
4747
cluster.stop();
@@ -59,8 +59,8 @@ public void testLargeSort() throws Exception {
5959
conf.setInt(MRJobConfig.IO_SORT_MB, ioSortMb);
6060
conf.setInt(LargeSorter.NUM_MAP_TASKS, 1);
6161
conf.setInt(LargeSorter.MBS_PER_MAP, ioSortMb);
62-
assertEquals("Large sort failed for " + ioSortMb, 0,
63-
ToolRunner.run(conf, new LargeSorter(), args));
62+
assertEquals(0, ToolRunner.run(conf, new LargeSorter(), args),
63+
"Large sort failed for " + ioSortMb);
6464
}
6565
}
6666
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestLocalRunner.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
3131
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
3232
import org.apache.hadoop.util.ReflectionUtils;
33-
import org.junit.Test;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.Timeout;
3435
import org.slf4j.Logger;
3536
import org.slf4j.LoggerFactory;
3637

@@ -44,10 +45,10 @@
4445
import java.util.ArrayList;
4546
import java.util.List;
4647

47-
import static org.junit.Assert.assertEquals;
48-
import static org.junit.Assert.assertFalse;
49-
import static org.junit.Assert.assertNotNull;
50-
import static org.junit.Assert.assertTrue;
48+
import static org.junit.jupiter.api.Assertions.assertEquals;
49+
import static org.junit.jupiter.api.Assertions.assertFalse;
50+
import static org.junit.jupiter.api.Assertions.assertNotNull;
51+
import static org.junit.jupiter.api.Assertions.assertTrue;
5152

5253
/**
5354
* Stress tests for the LocalJobRunner
@@ -235,9 +236,9 @@ private void verifyOutput(Path outputPath) throws IOException {
235236

236237
// Should get a single line of the form "0\t(count)"
237238
String line = r.readLine().trim();
238-
assertTrue("Line does not have correct key", line.startsWith("0\t"));
239+
assertTrue(line.startsWith("0\t"), "Line does not have correct key");
239240
int count = Integer.valueOf(line.substring(2));
240-
assertEquals("Incorrect count generated!", TOTAL_RECORDS, count);
241+
assertEquals(TOTAL_RECORDS, count, "Incorrect count generated!");
241242

242243
r.close();
243244

@@ -276,23 +277,24 @@ public void testGcCounter() throws Exception {
276277
FileOutputFormat.setOutputPath(job, outputPath);
277278

278279
boolean ret = job.waitForCompletion(true);
279-
assertTrue("job failed", ret);
280+
assertTrue(ret, "job failed");
280281

281282
// This job should have done *some* gc work.
282283
// It had to clean up 400,000 objects.
283284
// We strongly suspect this will result in a few milliseconds effort.
284285
Counter gcCounter = job.getCounters().findCounter(
285286
TaskCounter.GC_TIME_MILLIS);
286287
assertNotNull(gcCounter);
287-
assertTrue("No time spent in gc", gcCounter.getValue() > 0);
288+
assertTrue(gcCounter.getValue() > 0, "No time spent in gc");
288289
}
289290

290291

291292
/**
292293
* Run a test with several mappers in parallel, operating at different
293294
* speeds. Verify that the correct amount of output is created.
294295
*/
295-
@Test(timeout=120*1000)
296+
@Test
297+
@Timeout(value=120)
296298
public void testMultiMaps() throws Exception {
297299
Job job = Job.getInstance();
298300

@@ -377,7 +379,7 @@ public void testInvalidMultiMapParallelism() throws Exception {
377379
FileOutputFormat.setOutputPath(job, outputPath);
378380

379381
boolean success = job.waitForCompletion(true);
380-
assertFalse("Job succeeded somehow", success);
382+
assertFalse(success, "Job succeeded somehow");
381383
}
382384

383385
/** An IF that creates no splits */
@@ -434,7 +436,7 @@ public void testEmptyMaps() throws Exception {
434436
FileOutputFormat.setOutputPath(job, outputPath);
435437

436438
boolean success = job.waitForCompletion(true);
437-
assertTrue("Empty job should work", success);
439+
assertTrue(success, "Empty job should work");
438440
}
439441

440442
/** @return the directory where numberfiles are written (mapper inputs) */
@@ -510,7 +512,7 @@ private void verifyNumberJob(int numMaps) throws Exception {
510512
int expectedPerMapper = maxVal * (maxVal + 1) / 2;
511513
int expectedSum = expectedPerMapper * numMaps;
512514
LOG.info("expected sum: " + expectedSum + ", got " + valueSum);
513-
assertEquals("Didn't get all our results back", expectedSum, valueSum);
515+
assertEquals(expectedSum, valueSum, "Didn't get all our results back");
514516
}
515517

516518
/**
@@ -551,7 +553,7 @@ private void doMultiReducerTest(int numMaps, int numReduces,
551553
LocalJobRunner.setLocalMaxRunningReduces(job, parallelReduces);
552554

553555
boolean result = job.waitForCompletion(true);
554-
assertTrue("Job failed!!", result);
556+
assertTrue(result, "Job failed!!");
555557

556558
verifyNumberJob(numMaps);
557559
}

0 commit comments

Comments
 (0)