Skip to content

Commit b5ddf3b

Browse files
author
fanshilun
committed
YARN-11760. Upgrade JUnit from 4 to 5 in hadoop-yarn-applications-distributedshell.
1 parent 81146fe commit b5ddf3b

File tree

7 files changed

+186
-184
lines changed

7 files changed

+186
-184
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/DistributedShellBaseTest.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
import java.util.concurrent.atomic.AtomicReference;
3535
import java.util.function.Supplier;
3636

37-
import org.junit.After;
38-
import org.junit.AfterClass;
39-
import org.junit.Assert;
40-
import org.junit.Before;
41-
import org.junit.BeforeClass;
37+
import org.junit.jupiter.api.AfterEach;
38+
import org.junit.jupiter.api.AfterAll;
39+
import org.junit.jupiter.api.Assertions;
40+
import org.junit.jupiter.api.BeforeEach;
41+
import org.junit.jupiter.api.BeforeAll;
4242
import org.junit.Rule;
4343
import org.junit.rules.TemporaryFolder;
4444
import org.junit.rules.TestName;
@@ -117,7 +117,7 @@ public abstract class DistributedShellBaseTest {
117117
// location of the filesystem timeline writer for timeline service v.2
118118
private String timelineV2StorageDir = null;
119119

120-
@BeforeClass
120+
@BeforeAll
121121
public static void setupUnitTests() throws Exception {
122122
URL url = Thread.currentThread().getContextClassLoader().getResource(
123123
"yarn-site.xml");
@@ -134,7 +134,7 @@ public static void setupUnitTests() throws Exception {
134134
StandardCopyOption.REPLACE_EXISTING);
135135
}
136136

137-
@AfterClass
137+
@AfterAll
138138
public static void tearDownUnitTests() throws Exception {
139139
// shutdown the clusters.
140140
shutdownYarnCluster();
@@ -215,12 +215,12 @@ public void setTimelineV2StorageDir() throws Exception {
215215
timelineV2StorageDir = tmpFolder.newFolder().getAbsolutePath();
216216
}
217217

218-
@Before
218+
@BeforeEach
219219
public void setup() throws Exception {
220220
setupInternal(NUM_NMS, new YarnConfiguration());
221221
}
222222

223-
@After
223+
@AfterEach
224224
public void tearDown() throws IOException {
225225
cleanUpDFSClient();
226226
FileContext fsContext = FileContext.getLocalFSFileContext();
@@ -329,7 +329,7 @@ protected void baseTestDSShell(boolean haveDomain, boolean defaultFlow)
329329
YarnClient yarnClient;
330330
dsClient = setAndGetDSClient(new Configuration(yarnCluster.getConfig()));
331331
boolean initSuccess = dsClient.init(args);
332-
Assert.assertTrue(initSuccess);
332+
Assertions.assertTrue(initSuccess);
333333
LOG.info("Running DS Client");
334334
final AtomicBoolean result = new AtomicBoolean(false);
335335
Thread t = new Thread(() -> {
@@ -379,11 +379,11 @@ protected void baseTestDSShell(boolean haveDomain, boolean defaultFlow)
379379
t.join();
380380
if (waitResult.get() == 2) {
381381
// Exception was raised
382-
Assert.fail("Exception in getting application report. Failed");
382+
Assertions.fail("Exception in getting application report. Failed");
383383
}
384384
if (waitResult.get() == 1) {
385-
Assert.assertEquals("Failed waiting for expected rpc port to be -1.",
386-
-1, appReportRef.get().getRpcPort());
385+
Assertions.assertEquals(
386+
-1, appReportRef.get().getRpcPort(), "Failed waiting for expected rpc port to be -1.");
387387
}
388388
checkTimeline(appIdRef.get(), defaultFlow, haveDomain, appReportRef.get());
389389
}
@@ -399,22 +399,22 @@ protected void checkTimeline(ApplicationId appId,
399399
if (haveDomain) {
400400
domain = yarnCluster.getApplicationHistoryServer()
401401
.getTimelineStore().getDomain("TEST_DOMAIN");
402-
Assert.assertNotNull(domain);
403-
Assert.assertEquals("reader_user reader_group", domain.getReaders());
404-
Assert.assertEquals("writer_user writer_group", domain.getWriters());
402+
Assertions.assertNotNull(domain);
403+
Assertions.assertEquals("reader_user reader_group", domain.getReaders());
404+
Assertions.assertEquals("writer_user writer_group", domain.getWriters());
405405
}
406406
TimelineEntities entitiesAttempts = yarnCluster
407407
.getApplicationHistoryServer()
408408
.getTimelineStore()
409409
.getEntities(ApplicationMaster.DSEntity.DS_APP_ATTEMPT.toString(),
410410
null, null, null, null, null, null, null, null, null);
411-
Assert.assertNotNull(entitiesAttempts);
412-
Assert.assertEquals(1, entitiesAttempts.getEntities().size());
413-
Assert.assertEquals(2, entitiesAttempts.getEntities().get(0).getEvents()
411+
Assertions.assertNotNull(entitiesAttempts);
412+
Assertions.assertEquals(1, entitiesAttempts.getEntities().size());
413+
Assertions.assertEquals(2, entitiesAttempts.getEntities().get(0).getEvents()
414414
.size());
415-
Assert.assertEquals(entitiesAttempts.getEntities().get(0).getEntityType(),
415+
Assertions.assertEquals(entitiesAttempts.getEntities().get(0).getEntityType(),
416416
ApplicationMaster.DSEntity.DS_APP_ATTEMPT.toString());
417-
Assert.assertEquals(haveDomain ? domain.getId() : "DEFAULT",
417+
Assertions.assertEquals(haveDomain ? domain.getId() : "DEFAULT",
418418
entitiesAttempts.getEntities().get(0).getDomainId());
419419
String currAttemptEntityId =
420420
entitiesAttempts.getEntities().get(0).getEntityId();
@@ -428,19 +428,19 @@ protected void checkTimeline(ApplicationId appId,
428428
.getTimelineStore()
429429
.getEntities(ApplicationMaster.DSEntity.DS_CONTAINER.toString(), null,
430430
null, null, null, null, primaryFilter, null, null, null);
431-
Assert.assertNotNull(entities);
432-
Assert.assertEquals(2, entities.getEntities().size());
433-
Assert.assertEquals(entities.getEntities().get(0).getEntityType(),
431+
Assertions.assertNotNull(entities);
432+
Assertions.assertEquals(2, entities.getEntities().size());
433+
Assertions.assertEquals(entities.getEntities().get(0).getEntityType(),
434434
ApplicationMaster.DSEntity.DS_CONTAINER.toString());
435435

436436
String entityId = entities.getEntities().get(0).getEntityId();
437437
TimelineEntity entity =
438438
yarnCluster.getApplicationHistoryServer().getTimelineStore()
439439
.getEntity(entityId,
440440
ApplicationMaster.DSEntity.DS_CONTAINER.toString(), null);
441-
Assert.assertNotNull(entity);
442-
Assert.assertEquals(entityId, entity.getEntityId());
443-
Assert.assertEquals(haveDomain ? domain.getId() : "DEFAULT",
441+
Assertions.assertNotNull(entity);
442+
Assertions.assertEquals(entityId, entity.getEntityId());
443+
Assertions.assertEquals(haveDomain ? domain.getId() : "DEFAULT",
444444
entities.getEntities().get(0).getDomainId());
445445
}
446446

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
package org.apache.hadoop.yarn.applications.distributedshell;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import java.util.HashMap;
2424
import java.util.Map;
2525

26-
import static org.junit.Assert.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
2727

2828
public class TestClient {
2929
@Test

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSAppMaster.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineWriterImpl;
3939
import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter;
4040
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
41-
import org.junit.Assert;
42-
import org.junit.Test;
41+
import org.junit.jupiter.api.Assertions;
42+
import org.junit.jupiter.api.Test;
4343
import org.mockito.ArgumentMatchers;
4444
import org.mockito.Mockito;
4545

@@ -105,12 +105,12 @@ public void testDSAppMasterAllocateHandler() throws Exception {
105105

106106
// first allocate a single container, everything should be fine
107107
handler.onContainersAllocated(containers);
108-
Assert.assertEquals("Wrong container allocation count", 1,
109-
master.getAllocatedContainers());
110-
Assert.assertEquals("Incorrect number of threads launched", 1,
111-
master.threadsLaunched);
112-
Assert.assertEquals("Incorrect YARN Shell IDs",
113-
Arrays.asList("1"), master.yarnShellIds);
108+
Assertions.assertEquals(1
109+
, master.getAllocatedContainers(), "Wrong container allocation count");
110+
Assertions.assertEquals(1
111+
, master.threadsLaunched, "Incorrect number of threads launched");
112+
Assertions.assertEquals(
113+
Arrays.asList("1"), master.yarnShellIds, "Incorrect YARN Shell IDs");
114114

115115
// now send 3 extra containers
116116
containers.clear();
@@ -121,14 +121,14 @@ public void testDSAppMasterAllocateHandler() throws Exception {
121121
ContainerId id4 = BuilderUtils.newContainerId(1, 1, 1, 4);
122122
containers.add(generateContainer(id4));
123123
handler.onContainersAllocated(containers);
124-
Assert.assertEquals("Wrong final container allocation count", 2,
125-
master.getAllocatedContainers());
124+
Assertions.assertEquals(2
125+
, master.getAllocatedContainers(), "Wrong final container allocation count");
126126

127-
Assert.assertEquals("Incorrect number of threads launched", 2,
128-
master.threadsLaunched);
127+
Assertions.assertEquals(2
128+
, master.threadsLaunched, "Incorrect number of threads launched");
129129

130-
Assert.assertEquals("Incorrect YARN Shell IDs",
131-
Arrays.asList("1", "2"), master.yarnShellIds);
130+
Assertions.assertEquals(
131+
Arrays.asList("1", "2"), master.yarnShellIds, "Incorrect YARN Shell IDs");
132132
// make sure we handle completion events correctly
133133
List<ContainerStatus> status = new ArrayList<>();
134134
status.add(generateContainerStatus(id1, ContainerExitStatus.SUCCESS));
@@ -137,25 +137,25 @@ public void testDSAppMasterAllocateHandler() throws Exception {
137137
status.add(generateContainerStatus(id4, ContainerExitStatus.ABORTED));
138138
handler.onContainersCompleted(status);
139139

140-
Assert.assertEquals("Unexpected number of completed containers",
141-
targetContainers, master.getNumCompletedContainers());
142-
Assert.assertTrue("Master didn't finish containers as expected",
143-
master.getDone());
140+
Assertions.assertEquals(
141+
targetContainers, master.getNumCompletedContainers(), "Unexpected number of completed containers");
142+
Assertions.assertTrue(
143+
master.getDone(), "Master didn't finish containers as expected");
144144

145145
// test for events from containers we know nothing about
146146
// these events should be ignored
147147
status = new ArrayList<>();
148148
ContainerId id5 = BuilderUtils.newContainerId(1, 1, 1, 5);
149149
status.add(generateContainerStatus(id5, ContainerExitStatus.ABORTED));
150-
Assert.assertEquals("Unexpected number of completed containers",
151-
targetContainers, master.getNumCompletedContainers());
152-
Assert.assertTrue("Master didn't finish containers as expected",
153-
master.getDone());
150+
Assertions.assertEquals(
151+
targetContainers, master.getNumCompletedContainers(), "Unexpected number of completed containers");
152+
Assertions.assertTrue(
153+
master.getDone(), "Master didn't finish containers as expected");
154154
status.add(generateContainerStatus(id5, ContainerExitStatus.SUCCESS));
155-
Assert.assertEquals("Unexpected number of completed containers",
156-
targetContainers, master.getNumCompletedContainers());
157-
Assert.assertTrue("Master didn't finish containers as expected",
158-
master.getDone());
155+
Assertions.assertEquals(
156+
targetContainers, master.getNumCompletedContainers(), "Unexpected number of completed containers");
157+
Assertions.assertTrue(
158+
master.getDone(), "Master didn't finish containers as expected");
159159
}
160160

161161
private Container generateContainer(ContainerId cid) {
@@ -200,15 +200,15 @@ private void runTimelineClientInDSAppMaster(boolean v1Enabled,
200200
private void validateAppMasterTimelineService(boolean v1Enabled,
201201
boolean v2Enabled, ApplicationMaster appMaster) {
202202
if (v1Enabled) {
203-
Assert.assertEquals(appMaster.appSubmitterUgi,
203+
Assertions.assertEquals(appMaster.appSubmitterUgi,
204204
((TimelineClientImpl)appMaster.timelineClient).getUgi());
205205
} else {
206-
Assert.assertNull(appMaster.timelineClient);
206+
Assertions.assertNull(appMaster.timelineClient);
207207
}
208208
if (v2Enabled) {
209-
Assert.assertNotNull(appMaster.timelineV2Client);
209+
Assertions.assertNotNull(appMaster.timelineV2Client);
210210
} else {
211-
Assert.assertNull(appMaster.timelineV2Client);
211+
Assertions.assertNull(appMaster.timelineV2Client);
212212
}
213213
}
214214

@@ -227,7 +227,7 @@ private ApplicationMaster createAppMasterWithStartedTimelineService(
227227
private Configuration getTimelineServiceConf(boolean v1Enabled,
228228
boolean v2Enabled) {
229229
Configuration conf = new YarnConfiguration(new Configuration(false));
230-
Assert.assertFalse(YarnConfiguration.timelineServiceEnabled(conf));
230+
Assertions.assertFalse(YarnConfiguration.timelineServiceEnabled(conf));
231231

232232
if (v1Enabled || v2Enabled) {
233233
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);

0 commit comments

Comments
 (0)