Skip to content

Commit 0cf1e41

Browse files
author
fanshilun
committed
MAPREDUCE-7420. Upgrade Junit 4 to 5 in hadoop-mapreduce-client-core.
1 parent 851b4c3 commit 0cf1e41

File tree

77 files changed

+1575
-1459
lines changed

Some content is hidden

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

77 files changed

+1575
-1459
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractFSContractTestBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.junit.Before;
2828
import org.junit.BeforeClass;
2929
import org.junit.Rule;
30+
import org.junit.jupiter.api.TestInfo;
3031
import org.junit.AssumptionViolatedException;
3132
import org.junit.rules.TestName;
3233
import org.junit.rules.Timeout;
@@ -250,6 +251,11 @@ protected Path methodPath() throws IOException {
250251
return path(methodName.getMethodName());
251252
}
252253

254+
protected Path methodPath(String name) throws IOException {
255+
return path(name);
256+
}
257+
258+
253259
/**
254260
* Take a simple path like "/something" and turn it into
255261
* a qualified path against the test FS.

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@
9797
<artifactId>junit-vintage-engine</artifactId>
9898
<scope>test</scope>
9999
</dependency>
100+
<dependency>
101+
<groupId>org.mockito</groupId>
102+
<artifactId>mockito-junit-jupiter</artifactId>
103+
<scope>test</scope>
104+
</dependency>
100105
</dependencies>
101106

102107
<build>

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestClock.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@
1818
*/
1919
package org.apache.hadoop.mapred;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.Timeout;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
2225

23-
import static org.junit.Assert.*;
2426
/**
25-
* test Clock class
26-
*
27+
* test Clock class
2728
*/
2829
public class TestClock {
2930

30-
@Test (timeout=10000)
31+
@Test
32+
@Timeout(value = 10)
3133
public void testClock(){
32-
Clock clock= new Clock();
33-
long templateTime=System.currentTimeMillis();
34-
long time=clock.getTime();
35-
assertEquals(templateTime, time,30);
36-
34+
Clock clock = new Clock();
35+
long templateTime = System.currentTimeMillis();
36+
long time = clock.getTime();
37+
assertEquals(templateTime, time, 30);
3738
}
3839
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapred/TestClusterStatus.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,29 @@
1717
*/
1818
package org.apache.hadoop.mapred;
1919

20-
import org.junit.Assert;
20+
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.Timeout;
2122

22-
import org.junit.Test;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2325

2426
public class TestClusterStatus {
2527

2628
private ClusterStatus clusterStatus = new ClusterStatus();
2729

2830
@SuppressWarnings("deprecation")
29-
@Test (timeout = 10000)
30-
public void testGraylistedTrackers() {
31-
Assert.assertEquals(0, clusterStatus.getGraylistedTrackers());
32-
Assert.assertTrue(clusterStatus.getGraylistedTrackerNames().isEmpty());
31+
@Test
32+
@Timeout(value = 10)
33+
public void testGrayListedTrackers() {
34+
assertEquals(0, clusterStatus.getGraylistedTrackers());
35+
assertTrue(clusterStatus.getGraylistedTrackerNames().isEmpty());
3336
}
3437

3538
@SuppressWarnings("deprecation")
36-
@Test (timeout = 10000)
39+
@Test
40+
@Timeout(value = 10)
3741
public void testJobTrackerState() {
38-
Assert.assertEquals(JobTracker.State.RUNNING,
42+
assertEquals(JobTracker.State.RUNNING,
3943
clusterStatus.getJobTrackerState());
4044
}
4145
}

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

Lines changed: 51 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,12 @@
1717
*/
1818
package org.apache.hadoop.mapred;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
23-
2420
import java.io.IOException;
2521
import java.text.ParseException;
2622
import java.util.HashSet;
2723
import java.util.Iterator;
2824
import java.util.Random;
2925

30-
import org.junit.Assert;
31-
3226
import org.apache.hadoop.mapred.Counters.Counter;
3327
import org.apache.hadoop.mapred.Counters.CountersExceededException;
3428
import org.apache.hadoop.mapred.Counters.Group;
@@ -38,15 +32,22 @@
3832
import org.apache.hadoop.mapreduce.TaskCounter;
3933
import org.apache.hadoop.mapreduce.counters.FrameworkCounterGroup;
4034
import org.apache.hadoop.mapreduce.counters.CounterGroupFactory.FrameworkGroupFactory;
41-
import org.junit.Test;
35+
import org.junit.jupiter.api.Test;
4236
import org.slf4j.Logger;
4337
import org.slf4j.LoggerFactory;
4438

39+
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
import static org.junit.jupiter.api.Assertions.assertFalse;
41+
import static org.junit.jupiter.api.Assertions.assertNotNull;
42+
import static org.junit.jupiter.api.Assertions.assertNull;
43+
import static org.junit.jupiter.api.Assertions.assertTrue;
44+
import static org.junit.jupiter.api.Assertions.fail;
45+
4546
/**
4647
* TestCounters checks the sanity and recoverability of {@code Counters}
4748
*/
4849
public class TestCounters {
49-
enum myCounters {TEST1, TEST2};
50+
enum myCounters {TEST1, TEST2}
5051
private static final long MAX_VALUE = 10;
5152
private static final Logger LOG = LoggerFactory.getLogger(TestCounters.class);
5253

@@ -85,14 +86,14 @@ private Counters getEnumCounters(String[] gNames, String[] cNames) {
8586
*/
8687
private void testCounter(Counters counter) throws ParseException {
8788
String compactEscapedString = counter.makeEscapedCompactString();
88-
assertFalse("compactEscapedString should not contain null",
89-
compactEscapedString.contains("null"));
89+
assertFalse(compactEscapedString.contains("null"),
90+
"compactEscapedString should not contain null");
9091

9192
Counters recoveredCounter =
9293
Counters.fromEscapedCompactString(compactEscapedString);
9394
// Check for recovery from string
94-
assertEquals("Recovered counter does not match on content",
95-
counter, recoveredCounter);
95+
assertEquals(counter, recoveredCounter,
96+
"Recovered counter does not match on content");
9697
}
9798

9899
@Test
@@ -109,7 +110,7 @@ public void testCounters() throws IOException {
109110
// I. Check enum counters that have resource bundler
110111
testCounter(getEnumCounters(keysWithResource));
111112

112-
// II. Check enum counters that dont have resource bundler
113+
// II. Check enum counters that don't have resource bundler
113114
testCounter(getEnumCounters(keysWithoutResource));
114115

115116
// III. Check string counters
@@ -134,19 +135,19 @@ public void testCounterValue() {
134135
long expectedValue = initValue;
135136
Counter counter = counters.findCounter("foo", "bar");
136137
counter.setValue(initValue);
137-
assertEquals("Counter value is not initialized correctly",
138-
expectedValue, counter.getValue());
138+
assertEquals(expectedValue, counter.getValue(),
139+
"Counter value is not initialized correctly");
139140
for (int j = 0; j < NUMBER_INC; j++) {
140141
int incValue = rand.nextInt();
141142
counter.increment(incValue);
142143
expectedValue += incValue;
143-
assertEquals("Counter value is not incremented correctly",
144-
expectedValue, counter.getValue());
144+
assertEquals(expectedValue, counter.getValue(),
145+
"Counter value is not incremented correctly");
145146
}
146147
expectedValue = rand.nextInt();
147148
counter.setValue(expectedValue);
148-
assertEquals("Counter value is not set correctly",
149-
expectedValue, counter.getValue());
149+
assertEquals(expectedValue, counter.getValue(),
150+
"Counter value is not set correctly");
150151
}
151152
}
152153

@@ -174,29 +175,27 @@ public void testWriteWithLegacyNames() {
174175

175176
@SuppressWarnings("deprecation")
176177
private void checkLegacyNames(Counters counters) {
177-
assertEquals("New name", 1, counters.findCounter(
178-
TaskCounter.class.getName(), "MAP_INPUT_RECORDS").getValue());
179-
assertEquals("Legacy name", 1, counters.findCounter(
178+
assertEquals(1, counters.findCounter(
179+
TaskCounter.class.getName(), "MAP_INPUT_RECORDS").getValue(), "New name");
180+
assertEquals(1, counters.findCounter(
180181
"org.apache.hadoop.mapred.Task$Counter",
181-
"MAP_INPUT_RECORDS").getValue());
182-
assertEquals("Legacy enum", 1,
183-
counters.findCounter(Task.Counter.MAP_INPUT_RECORDS).getValue());
182+
"MAP_INPUT_RECORDS").getValue(), "Legacy name");
183+
assertEquals(1, counters.findCounter(Task.Counter.MAP_INPUT_RECORDS).getValue(), "Legacy enum");
184184

185-
assertEquals("New name", 1, counters.findCounter(
186-
JobCounter.class.getName(), "DATA_LOCAL_MAPS").getValue());
187-
assertEquals("Legacy name", 1, counters.findCounter(
185+
assertEquals(1, counters.findCounter(
186+
JobCounter.class.getName(), "DATA_LOCAL_MAPS").getValue(), "New name");
187+
assertEquals(1, counters.findCounter(
188188
"org.apache.hadoop.mapred.JobInProgress$Counter",
189-
"DATA_LOCAL_MAPS").getValue());
190-
assertEquals("Legacy enum", 1,
191-
counters.findCounter(JobInProgress.Counter.DATA_LOCAL_MAPS).getValue());
189+
"DATA_LOCAL_MAPS").getValue(), "Legacy name");
190+
assertEquals(1, counters.findCounter(JobInProgress.Counter.DATA_LOCAL_MAPS).getValue(), "Legacy enum");
192191

193-
assertEquals("New name", 1, counters.findCounter(
194-
FileSystemCounter.class.getName(), "FILE_BYTES_READ").getValue());
195-
assertEquals("New name and method", 1, counters.findCounter("file",
196-
FileSystemCounter.BYTES_READ).getValue());
197-
assertEquals("Legacy name", 1, counters.findCounter(
192+
assertEquals(1, counters.findCounter(
193+
FileSystemCounter.class.getName(), "FILE_BYTES_READ").getValue(), "New name");
194+
assertEquals(1, counters.findCounter("file",
195+
FileSystemCounter.BYTES_READ).getValue(), "New name and method");
196+
assertEquals(1, counters.findCounter(
198197
"FileSystemCounters",
199-
"FILE_BYTES_READ").getValue());
198+
"FILE_BYTES_READ").getValue(), "Legacy name");
200199
}
201200

202201
@SuppressWarnings("deprecation")
@@ -248,8 +247,8 @@ public void testLegacyGetGroupNames() {
248247
counters.findCounter("fs2", FileSystemCounter.BYTES_READ).increment(1);
249248
counters.incrCounter("group1", "counter1", 1);
250249

251-
HashSet<String> groups = new HashSet<String>(counters.getGroupNames());
252-
HashSet<String> expectedGroups = new HashSet<String>();
250+
HashSet<String> groups = new HashSet<>(counters.getGroupNames());
251+
HashSet<String> expectedGroups = new HashSet<>();
253252
expectedGroups.add("group1");
254253
expectedGroups.add("FileSystemCounters"); //Legacy Name
255254
expectedGroups.add("org.apache.hadoop.mapreduce.FileSystemCounter");
@@ -266,8 +265,8 @@ public void testMakeCompactString() {
266265
assertEquals("group1.counter1:1", counters.makeCompactString());
267266
counters.incrCounter("group2", "counter2", 3);
268267
String cs = counters.makeCompactString();
269-
assertTrue("Bad compact string",
270-
cs.equals(GC1 + ',' + GC2) || cs.equals(GC2 + ',' + GC1));
268+
assertTrue(
269+
cs.equals(GC1 + ',' + GC2) || cs.equals(GC2 + ',' + GC1), "Bad compact string");
271270
}
272271

273272
@Test
@@ -281,11 +280,7 @@ private void testMaxCountersLimits(final Counters counters) {
281280
counters.findCounter("test", "test" + i);
282281
}
283282
setExpected(counters);
284-
shouldThrow(CountersExceededException.class, new Runnable() {
285-
public void run() {
286-
counters.findCounter("test", "bad");
287-
}
288-
});
283+
shouldThrow(CountersExceededException.class, () -> counters.findCounter("test", "bad"));
289284
checkExpected(counters);
290285
}
291286

@@ -295,11 +290,7 @@ private void testMaxGroupsLimits(final Counters counters) {
295290
counters.findCounter("test" + i, "test");
296291
}
297292
setExpected(counters);
298-
shouldThrow(CountersExceededException.class, new Runnable() {
299-
public void run() {
300-
counters.findCounter("bad", "test");
301-
}
302-
});
293+
shouldThrow(CountersExceededException.class, () -> counters.findCounter("bad", "test"));
303294
checkExpected(counters);
304295
}
305296

@@ -321,7 +312,7 @@ private void shouldThrow(Class<? extends Exception> ecls, Runnable runnable) {
321312
} catch (CountersExceededException e) {
322313
return;
323314
}
324-
Assert.fail("Should've thrown " + ecls.getSimpleName());
315+
fail("Should've thrown " + ecls.getSimpleName());
325316
}
326317

327318
public static void main(String[] args) throws IOException {
@@ -341,12 +332,12 @@ public void testFrameworkCounter() {
341332

342333
org.apache.hadoop.mapreduce.Counter count1 =
343334
counterGroup.findCounter(JobCounter.NUM_FAILED_MAPS.toString());
344-
Assert.assertNotNull(count1);
335+
assertNotNull(count1);
345336

346337
// Verify no exception get thrown when finding an unknown counter
347338
org.apache.hadoop.mapreduce.Counter count2 =
348339
counterGroup.findCounter("Unknown");
349-
Assert.assertNull(count2);
340+
assertNull(count2);
350341
}
351342

352343
@SuppressWarnings("rawtypes")
@@ -363,19 +354,19 @@ public void testTaskCounter() {
363354
org.apache.hadoop.mapreduce.Counter count1 =
364355
counterGroup.findCounter(
365356
TaskCounter.PHYSICAL_MEMORY_BYTES.toString());
366-
Assert.assertNotNull(count1);
357+
assertNotNull(count1);
367358
count1.increment(10);
368359
count1.increment(10);
369-
Assert.assertEquals(20, count1.getValue());
360+
assertEquals(20, count1.getValue());
370361

371362
// Verify no exception get thrown when finding an unknown counter
372363
org.apache.hadoop.mapreduce.Counter count2 =
373364
counterGroup.findCounter(
374365
TaskCounter.MAP_PHYSICAL_MEMORY_BYTES_MAX.toString());
375-
Assert.assertNotNull(count2);
366+
assertNotNull(count2);
376367
count2.increment(5);
377368
count2.increment(10);
378-
Assert.assertEquals(10, count2.getValue());
369+
assertEquals(10, count2.getValue());
379370
}
380371

381372
@Test
@@ -385,12 +376,12 @@ public void testFilesystemCounter() {
385376

386377
org.apache.hadoop.mapreduce.Counter count1 =
387378
fsGroup.findCounter("ANY_BYTES_READ");
388-
Assert.assertNotNull(count1);
379+
assertNotNull(count1);
389380

390381
// Verify no exception get thrown when finding an unknown counter
391382
org.apache.hadoop.mapreduce.Counter count2 =
392383
fsGroup.findCounter("Unknown");
393-
Assert.assertNull(count2);
384+
assertNull(count2);
394385
}
395386

396387
}

0 commit comments

Comments
 (0)