Skip to content

Commit d552670

Browse files
slfan1989cnauroth
andauthored
MAPREDUCE-7418. [JDK17] Upgrade Junit 4 to 5 in hadoop-mapreduce-client-app. (#7350)
Co-authored-by: Chris Nauroth <[email protected]> Reviewed-by: Chris Nauroth <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent 851b4c3 commit d552670

File tree

54 files changed

+1735
-1770
lines changed

Some content is hidden

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

54 files changed

+1735
-1770
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@
173173
<artifactId>junit-vintage-engine</artifactId>
174174
<scope>test</scope>
175175
</dependency>
176+
<dependency>
177+
<groupId>org.mockito</groupId>
178+
<artifactId>mockito-junit-jupiter</artifactId>
179+
</dependency>
176180
</dependencies>
177181

178182
<build>

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestLocalContainerLauncher.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,17 @@
5353
import org.apache.hadoop.yarn.api.records.NodeId;
5454
import org.apache.hadoop.yarn.event.Event;
5555
import org.apache.hadoop.yarn.event.EventHandler;
56-
import org.junit.AfterClass;
57-
import org.junit.Assert;
58-
import org.junit.BeforeClass;
59-
import org.junit.Test;
56+
import org.junit.jupiter.api.AfterAll;
57+
import org.junit.jupiter.api.BeforeAll;
58+
import org.junit.jupiter.api.Test;
59+
import org.junit.jupiter.api.Timeout;
6060
import org.mockito.invocation.InvocationOnMock;
6161
import org.mockito.stubbing.Answer;
6262
import org.slf4j.Logger;
6363
import org.slf4j.LoggerFactory;
6464

65+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
66+
6567
public class TestLocalContainerLauncher {
6668
private static final Logger LOG =
6769
LoggerFactory.getLogger(TestLocalContainerLauncher.class);
@@ -75,7 +77,7 @@ private static void delete(File dir) throws IOException {
7577
fs.delete(p, true);
7678
}
7779

78-
@BeforeClass
80+
@BeforeAll
7981
public static void setupTestDirs() throws IOException {
8082
testWorkDir = new File("target",
8183
TestLocalContainerLauncher.class.getCanonicalName());
@@ -89,15 +91,16 @@ public static void setupTestDirs() throws IOException {
8991
}
9092
}
9193

92-
@AfterClass
94+
@AfterAll
9395
public static void cleanupTestDirs() throws IOException {
9496
if (testWorkDir != null) {
9597
delete(testWorkDir);
9698
}
9799
}
98100

99101
@SuppressWarnings("rawtypes")
100-
@Test(timeout=10000)
102+
@Test
103+
@Timeout(value = 10)
101104
public void testKillJob() throws Exception {
102105
JobConf conf = new JobConf();
103106
AppContext context = mock(AppContext.class);
@@ -198,8 +201,8 @@ public void testRenameMapOutputForReduce() throws Exception {
198201
final Path mapOut = mrOutputFiles.getOutputFileForWrite(1);
199202
conf.set(MRConfig.LOCAL_DIR, localDirs[1].toString());
200203
final Path mapOutIdx = mrOutputFiles.getOutputIndexFileForWrite(1);
201-
Assert.assertNotEquals("Paths must be different!",
202-
mapOut.getParent(), mapOutIdx.getParent());
204+
assertNotEquals(mapOut.getParent(), mapOutIdx.getParent(),
205+
"Paths must be different!");
203206

204207
// make both dirs part of LOCAL_DIR
205208
conf.setStrings(MRConfig.LOCAL_DIR, localDirs);

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestTaskAttemptFinishingMonitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import org.apache.hadoop.yarn.event.EventHandler;
3838
import org.apache.hadoop.yarn.util.SystemClock;
3939

40-
import org.junit.Test;
41-
import static org.junit.Assert.assertTrue;
40+
import org.junit.jupiter.api.Test;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
4242
import static org.mockito.Mockito.mock;
4343
import static org.mockito.Mockito.when;
4444

@@ -87,7 +87,7 @@ public void testFinshingAttemptTimeout()
8787
}
8888
taskAttemptFinishingMonitor.stop();
8989

90-
assertTrue("Finishing attempt didn't time out.", eventHandler.timedOut);
90+
assertTrue(eventHandler.timedOut, "Finishing attempt didn't time out.");
9191

9292
}
9393

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestTaskAttemptListenerImpl.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
22-
import java.util.Arrays;
2322
import java.util.List;
2423
import java.util.concurrent.ConcurrentMap;
2524
import java.util.concurrent.atomic.AtomicReference;
2625
import java.util.function.Supplier;
2726

28-
import org.junit.After;
29-
import org.junit.Test;
30-
import org.junit.runner.RunWith;
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.Timeout;
30+
import org.junit.jupiter.api.extension.ExtendWith;
3131
import org.mockito.ArgumentCaptor;
3232
import org.mockito.Captor;
3333
import org.mockito.Mock;
34-
import org.mockito.junit.MockitoJUnitRunner;
34+
import org.mockito.junit.jupiter.MockitoExtension;
3535

3636
import org.apache.hadoop.conf.Configuration;
3737
import org.apache.hadoop.fs.Path;
@@ -69,12 +69,12 @@
6969
import org.apache.hadoop.yarn.util.SystemClock;
7070

7171
import static org.assertj.core.api.Assertions.assertThat;
72-
import static org.junit.Assert.assertEquals;
73-
import static org.junit.Assert.assertFalse;
74-
import static org.junit.Assert.assertNotNull;
75-
import static org.junit.Assert.assertNull;
76-
import static org.junit.Assert.assertTrue;
77-
import static org.junit.Assert.fail;
72+
import static org.junit.jupiter.api.Assertions.assertEquals;
73+
import static org.junit.jupiter.api.Assertions.assertFalse;
74+
import static org.junit.jupiter.api.Assertions.assertNotNull;
75+
import static org.junit.jupiter.api.Assertions.assertNull;
76+
import static org.junit.jupiter.api.Assertions.assertTrue;
77+
import static org.junit.jupiter.api.Assertions.fail;
7878
import static org.mockito.Mockito.any;
7979
import static org.mockito.Mockito.doReturn;
8080
import static org.mockito.Mockito.eq;
@@ -87,7 +87,7 @@
8787
/**
8888
* Tests the behavior of TaskAttemptListenerImpl.
8989
*/
90-
@RunWith(MockitoJUnitRunner.class)
90+
@ExtendWith(MockitoExtension.class)
9191
public class TestTaskAttemptListenerImpl {
9292
private static final String ATTEMPT1_ID =
9393
"attempt_123456789012_0001_m_000001_0";
@@ -172,15 +172,16 @@ protected void stopRpcServer() {
172172
}
173173
}
174174

175-
@After
175+
@AfterEach
176176
public void after() throws IOException {
177177
if (listener != null) {
178178
listener.close();
179179
listener = null;
180180
}
181181
}
182182

183-
@Test (timeout=5000)
183+
@Test
184+
@Timeout(value = 5)
184185
public void testGetTask() throws IOException {
185186
configureMocks();
186187
startListener(false);
@@ -238,7 +239,8 @@ public void testGetTask() throws IOException {
238239

239240
}
240241

241-
@Test (timeout=5000)
242+
@Test
243+
@Timeout(value = 5)
242244
public void testJVMId() {
243245

244246
JVMId jvmid = new JVMId("test", 1, true, 2);
@@ -247,7 +249,8 @@ public void testJVMId() {
247249
assertEquals(0, jvmid.compareTo(jvmid1));
248250
}
249251

250-
@Test (timeout=10000)
252+
@Test
253+
@Timeout(value = 10)
251254
public void testGetMapCompletionEvents() throws IOException {
252255
TaskAttemptCompletionEvent[] empty = {};
253256
TaskAttemptCompletionEvent[] taskEvents = {
@@ -257,12 +260,6 @@ public void testGetMapCompletionEvents() throws IOException {
257260
createTce(3, false, TaskAttemptCompletionEventStatus.FAILED) };
258261
TaskAttemptCompletionEvent[] mapEvents = { taskEvents[0], taskEvents[2] };
259262
Job mockJob = mock(Job.class);
260-
when(mockJob.getTaskAttemptCompletionEvents(0, 100))
261-
.thenReturn(taskEvents);
262-
when(mockJob.getTaskAttemptCompletionEvents(0, 2))
263-
.thenReturn(Arrays.copyOfRange(taskEvents, 0, 2));
264-
when(mockJob.getTaskAttemptCompletionEvents(2, 100))
265-
.thenReturn(Arrays.copyOfRange(taskEvents, 2, 4));
266263
when(mockJob.getMapAttemptCompletionEvents(0, 100)).thenReturn(
267264
TypeConverter.fromYarn(mapEvents));
268265
when(mockJob.getMapAttemptCompletionEvents(0, 2)).thenReturn(
@@ -312,7 +309,8 @@ private static TaskAttemptCompletionEvent createTce(int eventId,
312309
return tce;
313310
}
314311

315-
@Test (timeout=10000)
312+
@Test
313+
@Timeout(value = 10)
316314
public void testCommitWindow() throws IOException {
317315
SystemClock clock = SystemClock.getInstance();
318316

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapred/TestYarnChild.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121

2222
import org.apache.hadoop.conf.Configuration;
2323
import org.apache.hadoop.fs.ClusterStorageCapacityExceededException;
24-
import org.junit.Before;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2626

27-
import static org.mockito.Mockito.*;
27+
import static org.mockito.Mockito.any;
28+
import static org.mockito.Mockito.anyString;
29+
import static org.mockito.Mockito.eq;
30+
import static org.mockito.Mockito.mock;
31+
import static org.mockito.Mockito.verify;
32+
import static org.mockito.Mockito.when;
2833

2934
/**
3035
* Tests the behavior of YarnChild.
@@ -36,7 +41,7 @@ public class TestYarnChild {
3641
final static private String KILL_LIMIT_EXCEED_CONF_NAME =
3742
"mapreduce.job.dfs.storage.capacity.kill-limit-exceed";
3843

39-
@Before
44+
@BeforeEach
4045
public void setUp() throws Exception {
4146
task = mock(Task.class);
4247
umbilical = mock(TaskUmbilicalProtocol.class);

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/jobhistory/TestEvents.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
package org.apache.hadoop.mapreduce.jobhistory;
2020

2121
import static org.assertj.core.api.Assertions.assertThat;
22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

2525
import java.io.ByteArrayInputStream;
2626
import java.io.ByteArrayOutputStream;
@@ -40,7 +40,8 @@
4040
import org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl;
4141
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent;
4242
import org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric;
43-
import org.junit.Test;
43+
import org.junit.jupiter.api.Test;
44+
import org.junit.jupiter.api.Timeout;
4445

4546
public class TestEvents {
4647

@@ -50,7 +51,8 @@ public class TestEvents {
5051
*
5152
* @throws Exception
5253
*/
53-
@Test(timeout = 10000)
54+
@Test
55+
@Timeout(value = 10)
5456
public void testTaskAttemptFinishedEvent() throws Exception {
5557

5658
JobID jid = new JobID("001", 1);
@@ -79,7 +81,8 @@ public void testTaskAttemptFinishedEvent() throws Exception {
7981
* @throws Exception
8082
*/
8183

82-
@Test(timeout = 10000)
84+
@Test
85+
@Timeout(value = 10)
8386
public void testJobPriorityChange() throws Exception {
8487
org.apache.hadoop.mapreduce.JobID jid = new JobID("001", 1);
8588
JobPriorityChangeEvent test = new JobPriorityChangeEvent(jid,
@@ -89,7 +92,8 @@ public void testJobPriorityChange() throws Exception {
8992

9093
}
9194

92-
@Test(timeout = 10000)
95+
@Test
96+
@Timeout(value = 10)
9397
public void testJobQueueChange() throws Exception {
9498
org.apache.hadoop.mapreduce.JobID jid = new JobID("001", 1);
9599
JobQueueChangeEvent test = new JobQueueChangeEvent(jid,
@@ -103,7 +107,8 @@ public void testJobQueueChange() throws Exception {
103107
*
104108
* @throws Exception
105109
*/
106-
@Test(timeout = 10000)
110+
@Test
111+
@Timeout(value = 10)
107112
public void testTaskUpdated() throws Exception {
108113
JobID jid = new JobID("001", 1);
109114
TaskID tid = new TaskID(jid, TaskType.REDUCE, 2);
@@ -118,7 +123,8 @@ public void testTaskUpdated() throws Exception {
118123
* instance of HistoryEvent Different HistoryEvent should have a different
119124
* datum.
120125
*/
121-
@Test(timeout = 10000)
126+
@Test
127+
@Timeout(value = 10)
122128
public void testEvents() throws Exception {
123129

124130
EventReader reader = new EventReader(new DataInputStream(

0 commit comments

Comments
 (0)