Преглед изворни кода

YARN-11760. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-applications-distributedshell. (#7373)

Co-authored-by: Chris Nauroth <cnauroth@apache.org>
Reviewed-by: Chris Nauroth <cnauroth@apache.org>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
slfan1989 пре 2 месеци
родитељ
комит
b4168c37b7
7 измењених фајлова са 327 додато и 286 уклоњено
  1. 57 53
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/DistributedShellBaseTest.java
  2. 2 2
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestClient.java
  3. 34 34
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSAppMaster.java
  4. 121 97
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSTimelineV10.java
  5. 10 8
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSTimelineV15.java
  6. 48 41
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSTimelineV20.java
  7. 55 51
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSWithMultipleNodeManager.java

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

@@ -28,21 +28,18 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
 import java.util.List;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Supplier;
 
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestName;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.io.TempDir;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -75,9 +72,15 @@ import org.apache.hadoop.yarn.server.timeline.NameValuePair;
 import org.apache.hadoop.yarn.util.LinuxResourceCalculatorPlugin;
 import org.apache.hadoop.yarn.util.ProcfsBasedProcessTree;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
 /**
  * Base class for testing DistributedShell features.
  */
+@Timeout(160)
 public abstract class DistributedShellBaseTest {
   protected static final int MIN_ALLOCATION_MB = 128;
   protected static final int NUM_DATA_NODES = 1;
@@ -105,19 +108,15 @@ public abstract class DistributedShellBaseTest {
   private static MiniYARNCluster yarnCluster = null;
   private static String yarnSiteBackupPath = null;
   private static String yarnSitePath = null;
-  @Rule
-  public Timeout globalTimeout = new Timeout(TEST_TIME_OUT,
-      TimeUnit.MILLISECONDS);
-  @Rule
-  public TemporaryFolder tmpFolder = new TemporaryFolder();
-  @Rule
-  public TestName name = new TestName();
+  @TempDir
+  private java.nio.file.Path tmpFolder;
+
   private Client dsClient;
   private YarnConfiguration conf = null;
   // location of the filesystem timeline writer for timeline service v.2
   private String timelineV2StorageDir = null;
 
-  @BeforeClass
+  @BeforeAll
   public static void setupUnitTests() throws Exception {
     URL url = Thread.currentThread().getContextClassLoader().getResource(
         "yarn-site.xml");
@@ -134,7 +133,7 @@ public abstract class DistributedShellBaseTest {
         StandardCopyOption.REPLACE_EXISTING);
   }
 
-  @AfterClass
+  @AfterAll
   public static void tearDownUnitTests() throws Exception {
     // shutdown the clusters.
     shutdownYarnCluster();
@@ -212,15 +211,15 @@ public abstract class DistributedShellBaseTest {
   }
 
   public void setTimelineV2StorageDir() throws Exception {
-    timelineV2StorageDir = tmpFolder.newFolder().getAbsolutePath();
+    timelineV2StorageDir = tmpFolder.toFile().getAbsolutePath();
   }
 
-  @Before
-  public void setup() throws Exception {
-    setupInternal(NUM_NMS, new YarnConfiguration());
+  @BeforeEach
+  public void setup(TestInfo testInfo) throws Exception {
+    setupInternal(NUM_NMS, new YarnConfiguration(), getMethodName(testInfo));
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws IOException {
     cleanUpDFSClient();
     FileContext fsContext = FileContext.getLocalFSFileContext();
@@ -232,8 +231,8 @@ public abstract class DistributedShellBaseTest {
     shutdownHdfsCluster();
   }
 
-  protected String[] createArgumentsWithAppName(String... args) {
-    return createArguments(() -> generateAppName(), args);
+  protected String[] createArgumentsWithAppName(String methodName, String... args) {
+    return createArguments(() -> generateAppName(methodName), args);
   }
 
   protected void waitForContainersLaunch(YarnClient client, int nContainers,
@@ -307,9 +306,10 @@ public abstract class DistributedShellBaseTest {
     return dsClient;
   }
 
-  protected void baseTestDSShell(boolean haveDomain, boolean defaultFlow)
+  protected void baseTestDSShell(String methodName, boolean haveDomain, boolean defaultFlow)
       throws Exception {
     String[] baseArgs = createArgumentsWithAppName(
+        methodName,
         "--num_containers",
         "2",
         "--shell_command",
@@ -329,7 +329,7 @@ public abstract class DistributedShellBaseTest {
     YarnClient yarnClient;
     dsClient = setAndGetDSClient(new Configuration(yarnCluster.getConfig()));
     boolean initSuccess = dsClient.init(args);
-    Assert.assertTrue(initSuccess);
+    assertTrue(initSuccess);
     LOG.info("Running DS Client");
     final AtomicBoolean result = new AtomicBoolean(false);
     Thread t = new Thread(() -> {
@@ -379,17 +379,17 @@ public abstract class DistributedShellBaseTest {
     t.join();
     if (waitResult.get() == 2) {
       // Exception was raised
-      Assert.fail("Exception in getting application report. Failed");
+      fail("Exception in getting application report. Failed");
     }
     if (waitResult.get() == 1) {
-      Assert.assertEquals("Failed waiting for expected rpc port to be -1.",
-          -1, appReportRef.get().getRpcPort());
+      assertEquals(-1, appReportRef.get().getRpcPort(),
+          "Failed waiting for expected rpc port to be -1.");
     }
     checkTimeline(appIdRef.get(), defaultFlow, haveDomain, appReportRef.get());
   }
 
-  protected void baseTestDSShell(boolean haveDomain) throws Exception {
-    baseTestDSShell(haveDomain, true);
+  protected void baseTestDSShell(String methodName, boolean haveDomain) throws Exception {
+    baseTestDSShell(methodName, haveDomain, true);
   }
 
   protected void checkTimeline(ApplicationId appId,
@@ -399,22 +399,22 @@ public abstract class DistributedShellBaseTest {
     if (haveDomain) {
       domain = yarnCluster.getApplicationHistoryServer()
           .getTimelineStore().getDomain("TEST_DOMAIN");
-      Assert.assertNotNull(domain);
-      Assert.assertEquals("reader_user reader_group", domain.getReaders());
-      Assert.assertEquals("writer_user writer_group", domain.getWriters());
+      assertNotNull(domain);
+      assertEquals("reader_user reader_group", domain.getReaders());
+      assertEquals("writer_user writer_group", domain.getWriters());
     }
     TimelineEntities entitiesAttempts = yarnCluster
         .getApplicationHistoryServer()
         .getTimelineStore()
         .getEntities(ApplicationMaster.DSEntity.DS_APP_ATTEMPT.toString(),
             null, null, null, null, null, null, null, null, null);
-    Assert.assertNotNull(entitiesAttempts);
-    Assert.assertEquals(1, entitiesAttempts.getEntities().size());
-    Assert.assertEquals(2, entitiesAttempts.getEntities().get(0).getEvents()
+    assertNotNull(entitiesAttempts);
+    assertEquals(1, entitiesAttempts.getEntities().size());
+    assertEquals(2, entitiesAttempts.getEntities().get(0).getEvents()
         .size());
-    Assert.assertEquals(entitiesAttempts.getEntities().get(0).getEntityType(),
+    assertEquals(entitiesAttempts.getEntities().get(0).getEntityType(),
         ApplicationMaster.DSEntity.DS_APP_ATTEMPT.toString());
-    Assert.assertEquals(haveDomain ? domain.getId() : "DEFAULT",
+    assertEquals(haveDomain ? domain.getId() : "DEFAULT",
         entitiesAttempts.getEntities().get(0).getDomainId());
     String currAttemptEntityId =
         entitiesAttempts.getEntities().get(0).getEntityId();
@@ -428,9 +428,9 @@ public abstract class DistributedShellBaseTest {
         .getTimelineStore()
         .getEntities(ApplicationMaster.DSEntity.DS_CONTAINER.toString(), null,
             null, null, null, null, primaryFilter, null, null, null);
-    Assert.assertNotNull(entities);
-    Assert.assertEquals(2, entities.getEntities().size());
-    Assert.assertEquals(entities.getEntities().get(0).getEntityType(),
+    assertNotNull(entities);
+    assertEquals(2, entities.getEntities().size());
+    assertEquals(entities.getEntities().get(0).getEntityType(),
         ApplicationMaster.DSEntity.DS_CONTAINER.toString());
 
     String entityId = entities.getEntities().get(0).getEntityId();
@@ -438,9 +438,9 @@ public abstract class DistributedShellBaseTest {
         yarnCluster.getApplicationHistoryServer().getTimelineStore()
             .getEntity(entityId,
                 ApplicationMaster.DSEntity.DS_CONTAINER.toString(), null);
-    Assert.assertNotNull(entity);
-    Assert.assertEquals(entityId, entity.getEntityId());
-    Assert.assertEquals(haveDomain ? domain.getId() : "DEFAULT",
+    assertNotNull(entity);
+    assertEquals(entityId, entity.getEntityId());
+    assertEquals(haveDomain ? domain.getId() : "DEFAULT",
         entities.getEntities().get(0).getDomainId());
   }
 
@@ -452,12 +452,12 @@ public abstract class DistributedShellBaseTest {
     return res;
   }
 
-  protected String generateAppName() {
-    return generateAppName(null);
+  protected String generateAppName(String methodName) {
+    return generateAppName(methodName, null);
   }
 
-  protected String generateAppName(String postFix) {
-    return name.getMethodName().replaceFirst("test", "")
+  protected String generateAppName(String methodName, String postFix) {
+    return methodName.replaceFirst("test", "")
         .concat(postFix == null ? "" : "-" + postFix);
   }
 
@@ -501,9 +501,9 @@ public abstract class DistributedShellBaseTest {
   }
 
   protected void setupInternal(int numNodeManagers,
-      YarnConfiguration yarnConfig) throws Exception {
+      YarnConfiguration yarnConfig, String methodName) throws Exception {
     LOG.info("========== Setting UP UnitTest {}#{} ==========",
-        getClass().getCanonicalName(), name.getMethodName());
+        getClass().getCanonicalName(), methodName);
     LOG.info("Starting up YARN cluster. Timeline version {}",
         getTimelineVersion());
     conf = yarnConfig;
@@ -604,4 +604,8 @@ public abstract class DistributedShellBaseTest {
   protected MiniDFSCluster getHDFSCluster() {
     return hdfsCluster;
   }
+
+  public String getMethodName(TestInfo testInfo) {
+    return testInfo.getTestMethod().get().getName();
+  }
 }

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

@@ -18,12 +18,12 @@
 
 package org.apache.hadoop.yarn.applications.distributedshell;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class TestClient {
   @Test

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

@@ -38,8 +38,7 @@ import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineWriterImpl;
 import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter;
 import org.apache.hadoop.yarn.server.utils.BuilderUtils;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.mockito.ArgumentMatchers;
 import org.mockito.Mockito;
 
@@ -48,6 +47,12 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 /**
  * A bunch of tests to make sure that the container allocations
  * and releases occur correctly.
@@ -105,12 +110,12 @@ public class TestDSAppMaster {
 
     // first allocate a single container, everything should be fine
     handler.onContainersAllocated(containers);
-    Assert.assertEquals("Wrong container allocation count", 1,
-        master.getAllocatedContainers());
-    Assert.assertEquals("Incorrect number of threads launched", 1,
-        master.threadsLaunched);
-    Assert.assertEquals("Incorrect YARN Shell IDs",
-        Arrays.asList("1"), master.yarnShellIds);
+    assertEquals(1, master.getAllocatedContainers(),
+        "Wrong container allocation count");
+    assertEquals(1, master.threadsLaunched,
+        "Incorrect number of threads launched");
+    assertEquals(Arrays.asList("1"), master.yarnShellIds,
+        "Incorrect YARN Shell IDs");
 
     // now send 3 extra containers
     containers.clear();
@@ -121,14 +126,12 @@ public class TestDSAppMaster {
     ContainerId id4 = BuilderUtils.newContainerId(1, 1, 1, 4);
     containers.add(generateContainer(id4));
     handler.onContainersAllocated(containers);
-    Assert.assertEquals("Wrong final container allocation count", 2,
-        master.getAllocatedContainers());
-
-    Assert.assertEquals("Incorrect number of threads launched", 2,
-        master.threadsLaunched);
-
-    Assert.assertEquals("Incorrect YARN Shell IDs",
-        Arrays.asList("1", "2"), master.yarnShellIds);
+    assertEquals(2, master.getAllocatedContainers(),
+        "Wrong final container allocation count");
+    assertEquals(2, master.threadsLaunched,
+        "Incorrect number of threads launched");
+    assertEquals(Arrays.asList("1", "2"), master.yarnShellIds,
+        "Incorrect YARN Shell IDs");
     // make sure we handle completion events correctly
     List<ContainerStatus> status = new ArrayList<>();
     status.add(generateContainerStatus(id1, ContainerExitStatus.SUCCESS));
@@ -137,25 +140,22 @@ public class TestDSAppMaster {
     status.add(generateContainerStatus(id4, ContainerExitStatus.ABORTED));
     handler.onContainersCompleted(status);
 
-    Assert.assertEquals("Unexpected number of completed containers",
-        targetContainers, master.getNumCompletedContainers());
-    Assert.assertTrue("Master didn't finish containers as expected",
-        master.getDone());
+    assertEquals(targetContainers, master.getNumCompletedContainers(),
+        "Unexpected number of completed containers");
+    assertTrue(master.getDone(), "Master didn't finish containers as expected");
 
     // test for events from containers we know nothing about
     // these events should be ignored
     status = new ArrayList<>();
     ContainerId id5 = BuilderUtils.newContainerId(1, 1, 1, 5);
     status.add(generateContainerStatus(id5, ContainerExitStatus.ABORTED));
-    Assert.assertEquals("Unexpected number of completed containers",
-        targetContainers, master.getNumCompletedContainers());
-    Assert.assertTrue("Master didn't finish containers as expected",
-        master.getDone());
+    assertEquals(targetContainers, master.getNumCompletedContainers(),
+        "Unexpected number of completed containers");
+    assertTrue(master.getDone(), "Master didn't finish containers as expected");
     status.add(generateContainerStatus(id5, ContainerExitStatus.SUCCESS));
-    Assert.assertEquals("Unexpected number of completed containers",
-        targetContainers, master.getNumCompletedContainers());
-    Assert.assertTrue("Master didn't finish containers as expected",
-        master.getDone());
+    assertEquals(targetContainers, master.getNumCompletedContainers(),
+        "Unexpected number of completed containers");
+    assertTrue(master.getDone(), "Master didn't finish containers as expected");
   }
 
   private Container generateContainer(ContainerId cid) {
@@ -200,15 +200,15 @@ public class TestDSAppMaster {
   private void validateAppMasterTimelineService(boolean v1Enabled,
       boolean v2Enabled, ApplicationMaster appMaster) {
     if (v1Enabled) {
-      Assert.assertEquals(appMaster.appSubmitterUgi,
-          ((TimelineClientImpl)appMaster.timelineClient).getUgi());
+      assertEquals(appMaster.appSubmitterUgi,
+          ((TimelineClientImpl) appMaster.timelineClient).getUgi());
     } else {
-      Assert.assertNull(appMaster.timelineClient);
+      assertNull(appMaster.timelineClient);
     }
     if (v2Enabled) {
-      Assert.assertNotNull(appMaster.timelineV2Client);
+      assertNotNull(appMaster.timelineV2Client);
     } else {
-      Assert.assertNull(appMaster.timelineV2Client);
+      assertNull(appMaster.timelineV2Client);
     }
   }
 
@@ -227,7 +227,7 @@ public class TestDSAppMaster {
   private Configuration getTimelineServiceConf(boolean v1Enabled,
       boolean v2Enabled) {
     Configuration conf = new YarnConfiguration(new Configuration(false));
-    Assert.assertFalse(YarnConfiguration.timelineServiceEnabled(conf));
+    assertFalse(YarnConfiguration.timelineServiceEnabled(conf));
 
     if (v1Enabled || v2Enabled) {
       conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);

+ 121 - 97
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSTimelineV10.java

@@ -35,8 +35,8 @@ import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
 
 import net.jodah.failsafe.RetryPolicy;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -65,9 +65,12 @@ import org.apache.hadoop.yarn.util.Records;
 
 import javax.ws.rs.ProcessingException;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
@@ -90,18 +93,20 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
   }
 
   @Test
-  public void testDSShellWithDomain() throws Exception {
-    baseTestDSShell(true);
+  public void testDSShellWithDomain(TestInfo testInfo) throws Exception {
+    baseTestDSShell(getMethodName(testInfo), true);
   }
 
   @Test
-  public void testDSShellWithoutDomain() throws Exception {
-    baseTestDSShell(false);
+  public void testDSShellWithoutDomain(TestInfo testInfo) throws Exception {
+    baseTestDSShell(getMethodName(testInfo), false);
   }
 
   @Test
-  public void testDSRestartWithPreviousRunningContainers() throws Exception {
+  public void testDSRestartWithPreviousRunningContainers(TestInfo testInfo)
+      throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "1",
         "--shell_command",
@@ -123,7 +128,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
     boolean result = getDSClient().run();
     LOG.info("Client run completed. Result={}", result);
     // application should succeed
-    Assert.assertTrue(result);
+    assertTrue(result);
   }
 
   /*
@@ -133,8 +138,9 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
    * The application is expected to be successful.
    */
   @Test
-  public void testDSAttemptFailuresValidityIntervalSuccess() throws Exception {
+  public void testDSAttemptFailuresValidityIntervalSuccess(TestInfo testInfo) throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "1",
         "--shell_command",
@@ -160,7 +166,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
 
     LOG.info("Client run completed. Result = {}.", result);
     // application should succeed
-    Assert.assertTrue(result);
+    assertTrue(result);
   }
 
   /*
@@ -170,8 +176,9 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
    * The application is expected to be fail.
    */
   @Test
-  public void testDSAttemptFailuresValidityIntervalFailed() throws Exception {
+  public void testDSAttemptFailuresValidityIntervalFailed(TestInfo testInfo) throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "1",
         "--shell_command",
@@ -197,11 +204,11 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
 
     LOG.info("Client run completed. Result=" + result);
     // application should be failed
-    Assert.assertFalse(result);
+    assertFalse(result);
   }
 
   @Test
-  public void testDSShellWithCustomLogPropertyFile() throws Exception {
+  public void testDSShellWithCustomLogPropertyFile(TestInfo testInfo) throws Exception {
     final File basedir = getBaseDirForTest();
     final File tmpDir = new File(basedir, "tmpDir");
     tmpDir.mkdirs();
@@ -210,13 +217,14 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
       customLogProperty.delete();
     }
     if (!customLogProperty.createNewFile()) {
-      Assert.fail("Can not create custom log4j property file.");
+      fail("Can not create custom log4j property file.");
     }
     PrintWriter fileWriter = new PrintWriter(customLogProperty);
     // set the output to DEBUG level
     fileWriter.write("log4j.rootLogger=debug,stdout");
     fileWriter.close();
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "3",
         "--shell_command",
@@ -238,39 +246,40 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
     // Before run the DS, the default the log level is INFO
     final Logger LOG_Client =
         LoggerFactory.getLogger(Client.class);
-    Assert.assertTrue(LOG_Client.isInfoEnabled());
-    Assert.assertFalse(LOG_Client.isDebugEnabled());
+    assertTrue(LOG_Client.isInfoEnabled());
+    assertFalse(LOG_Client.isDebugEnabled());
     final Logger LOG_AM = LoggerFactory.getLogger(ApplicationMaster.class);
-    Assert.assertTrue(LOG_AM.isInfoEnabled());
-    Assert.assertFalse(LOG_AM.isDebugEnabled());
+    assertTrue(LOG_AM.isInfoEnabled());
+    assertFalse(LOG_AM.isDebugEnabled());
 
     LOG.info("Initializing DS Client");
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
     boolean initSuccess = getDSClient().init(args);
-    Assert.assertTrue(initSuccess);
+    assertTrue(initSuccess);
 
     LOG.info("Running DS Client");
     boolean result = getDSClient().run();
     LOG.info("Client run completed. Result=" + result);
-    Assert.assertTrue(verifyContainerLog(3, null, true, "DEBUG") > 10);
+    assertTrue(verifyContainerLog(3, null, true, "DEBUG") > 10);
     //After DS is finished, the log level should be DEBUG
-    Assert.assertTrue(LOG_Client.isInfoEnabled());
-    Assert.assertTrue(LOG_Client.isDebugEnabled());
-    Assert.assertTrue(LOG_AM.isInfoEnabled());
-    Assert.assertTrue(LOG_AM.isDebugEnabled());
+    assertTrue(LOG_Client.isInfoEnabled());
+    assertTrue(LOG_Client.isDebugEnabled());
+    assertTrue(LOG_AM.isInfoEnabled());
+    assertTrue(LOG_AM.isDebugEnabled());
   }
 
   @Test
-  public void testSpecifyingLogAggregationContext() throws Exception {
+  public void testSpecifyingLogAggregationContext(TestInfo testInfo) throws Exception {
     String regex = ".*(foo|bar)\\d";
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--shell_command",
         "echo",
         "--rolling_log_pattern",
         regex
     );
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
-    Assert.assertTrue(getDSClient().init(args));
+    assertTrue(getDSClient().init(args));
 
     ApplicationSubmissionContext context =
         Records.newRecord(ApplicationSubmissionContext.class);
@@ -281,8 +290,9 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
   }
 
   @Test
-  public void testDSShellWithMultipleArgs() throws Exception {
+  public void testDSShellWithMultipleArgs(TestInfo testInfo) throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "4",
         "--shell_command",
@@ -302,7 +312,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
     LOG.info("Initializing DS Client");
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
     boolean initSuccess = getDSClient().init(args);
-    Assert.assertTrue(initSuccess);
+    assertTrue(initSuccess);
     LOG.info("Running DS Client");
 
     boolean result = getDSClient().run();
@@ -313,7 +323,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
   }
 
   @Test
-  public void testDSShellWithShellScript() throws Exception {
+  public void testDSShellWithShellScript(TestInfo testInfo) throws Exception {
     final File basedir = getBaseDirForTest();
     final File tmpDir = new File(basedir, "tmpDir");
     tmpDir.mkdirs();
@@ -322,7 +332,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
       customShellScript.delete();
     }
     if (!customShellScript.createNewFile()) {
-      Assert.fail("Can not create custom shell script file.");
+      fail("Can not create custom shell script file.");
     }
     PrintWriter fileWriter = new PrintWriter(customShellScript);
     // set the output to DEBUG level
@@ -330,6 +340,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
     fileWriter.close();
     LOG.info(customShellScript.getAbsolutePath());
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "1",
         "--shell_script",
@@ -346,7 +357,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
 
     LOG.info("Initializing DS Client");
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
-    Assert.assertTrue(getDSClient().init(args));
+    assertTrue(getDSClient().init(args));
     LOG.info("Running DS Client");
     assertTrue(getDSClient().run());
     List<String> expectedContent = new ArrayList<>();
@@ -564,8 +575,9 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
   }
 
   @Test
-  public void testContainerLaunchFailureHandling() throws Exception {
+  public void testContainerLaunchFailureHandling(TestInfo testInfo) throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "2",
         "--shell_command",
@@ -579,14 +591,15 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
     LOG.info("Initializing DS Client");
     setAndGetDSClient(ContainerLaunchFailAppMaster.class.getName(),
         new Configuration(getYarnClusterConfiguration()));
-    Assert.assertTrue(getDSClient().init(args));
+    assertTrue(getDSClient().init(args));
     LOG.info("Running DS Client");
-    Assert.assertFalse(getDSClient().run());
+    assertFalse(getDSClient().run());
   }
 
   @Test
-  public void testDebugFlag() throws Exception {
+  public void testDebugFlag(TestInfo testInfo) throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "2",
         "--shell_command",
@@ -604,9 +617,9 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
 
     LOG.info("Initializing DS Client");
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
-    Assert.assertTrue(getDSClient().init(args));
+    assertTrue(getDSClient().init(args));
     LOG.info("Running DS Client");
-    Assert.assertTrue(getDSClient().run());
+    assertTrue(getDSClient().run());
   }
 
   private int verifyContainerLog(int containerNum,
@@ -617,7 +630,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
                 YarnConfiguration.DEFAULT_NM_LOG_DIRS));
 
     File[] listOfFiles = logFolder.listFiles();
-    Assert.assertNotNull(listOfFiles);
+    assertNotNull(listOfFiles);
     int currentContainerLogFileIndex = -1;
     for (int i = listOfFiles.length - 1; i >= 0; i--) {
       if (listOfFiles[i].listFiles().length == containerNum + 1) {
@@ -625,7 +638,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
         break;
       }
     }
-    Assert.assertTrue(currentContainerLogFileIndex != -1);
+    assertTrue(currentContainerLogFileIndex != -1);
     File[] containerFiles =
         listOfFiles[currentContainerLogFileIndex].listFiles();
 
@@ -648,8 +661,8 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
                 }
               } else if (output.getName().trim().equals("stdout")) {
                 if (!Shell.WINDOWS) {
-                  Assert.assertEquals("The current is" + sCurrentLine,
-                      expectedContent.get(numOffline), sCurrentLine.trim());
+                  assertEquals(expectedContent.get(numOffline), sCurrentLine.trim(),
+                      "The current is" + sCurrentLine);
                   numOffline++;
                 } else {
                   stdOutContent.add(sCurrentLine.trim());
@@ -664,7 +677,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
              */
             if (Shell.WINDOWS && !count
                 && output.getName().trim().equals("stdout")) {
-              Assert.assertTrue(stdOutContent.containsAll(expectedContent));
+              assertTrue(stdOutContent.containsAll(expectedContent));
             }
           } catch (IOException e) {
             LOG.error("Exception reading the buffer", e);
@@ -696,7 +709,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
     for (int i = 0; i < args.length; ++i) {
       LOG.info("Initializing DS Client[{}]", i);
       setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
-      Assert.assertTrue(getDSClient().init(args[i]));
+      assertTrue(getDSClient().init(args[i]));
       LOG.info("Running DS Client[{}]", i);
       LambdaTestUtils.intercept(Exception.class,
           () -> getDSClient().run());
@@ -704,10 +717,11 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
   }
 
   @Test
-  public void testDSShellWithOpportunisticContainers() throws Exception {
+  public void testDSShellWithOpportunisticContainers(TestInfo testInfo) throws Exception {
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
 
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "2",
         "--master_memory",
@@ -727,42 +741,48 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
     assertTrue(getDSClient().run());
   }
 
-  @Test(expected = ResourceNotFoundException.class)
-  public void testDistributedShellAMResourcesWithUnknownResource()
+  @Test
+  public void testDistributedShellAMResourcesWithUnknownResource(TestInfo testInfo)
       throws Exception {
-    String[] args = createArgumentsWithAppName(
-        "--num_containers",
-        "1",
-        "--shell_command",
-        getListCommand(),
-        "--master_resources",
-        "unknown-resource=5"
-    );
-    setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
-    assertTrue(getDSClient().init(args));
-    getDSClient().run();
+    assertThrows(ResourceNotFoundException.class, () -> {
+      String[] args = createArgumentsWithAppName(
+              getMethodName(testInfo),
+              "--num_containers",
+              "1",
+              "--shell_command",
+              getListCommand(),
+              "--master_resources",
+              "unknown-resource=5"
+      );
+      setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
+      assertTrue(getDSClient().init(args));
+      getDSClient().run();
+    });
   }
 
-  @Test(expected = IllegalArgumentException.class)
-  public void testDistributedShellNonExistentQueue()
-      throws Exception {
-    String[] args = createArgumentsWithAppName(
-        "--num_containers",
-        "1",
-        "--shell_command",
-        getListCommand(),
-        "--queue",
-        "non-existent-queue"
-    );
-    setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
-    assertTrue(getDSClient().init(args));
-    getDSClient().run();
+  @Test
+  public void testDistributedShellNonExistentQueue(TestInfo testInfo) throws Exception {
+    assertThrows(IllegalArgumentException.class, () -> {
+      String[] args = createArgumentsWithAppName(
+          getMethodName(testInfo),
+          "--num_containers",
+          "1",
+          "--shell_command",
+          getListCommand(),
+          "--queue",
+          "non-existent-queue"
+      );
+      setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
+      assertTrue(getDSClient().init(args));
+      getDSClient().run();
+    });
   }
 
   @Test
-  public void testDistributedShellWithSingleFileLocalization()
+  public void testDistributedShellWithSingleFileLocalization(TestInfo testInfo)
       throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "1",
         "--shell_command",
@@ -775,13 +795,14 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
 
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
     assertTrue(getDSClient().init(args));
-    assertTrue("Client exited with an error", getDSClient().run());
+    assertTrue(getDSClient().run(), "Client exited with an error");
   }
 
   @Test
-  public void testDistributedShellWithMultiFileLocalization()
+  public void testDistributedShellWithMultiFileLocalization(TestInfo testInfo)
       throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "1",
         "--shell_command",
@@ -794,32 +815,35 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
 
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
     assertTrue(getDSClient().init(args));
-    assertTrue("Client exited with an error", getDSClient().run());
+    assertTrue(getDSClient().run(), "Client exited with an error");
   }
 
-  @Test(expected = UncheckedIOException.class)
-  public void testDistributedShellWithNonExistentFileLocalization()
+  @Test
+  public void testDistributedShellWithNonExistentFileLocalization(TestInfo testInfo)
       throws Exception {
-    String[] args = createArgumentsWithAppName(
-        "--num_containers",
-        "1",
-        "--shell_command",
-        getCatCommand(),
-        "--localize_files",
-        "/non/existing/path/file.txt",
-        "--shell_args",
-        "file.txt"
-    );
-
-    setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
-    assertTrue(getDSClient().init(args));
-    assertTrue(getDSClient().run());
+    assertThrows(UncheckedIOException.class, () -> {
+      String[] args = createArgumentsWithAppName(
+              getMethodName(testInfo),
+              "--num_containers",
+              "1",
+              "--shell_command",
+              getCatCommand(),
+              "--localize_files",
+              "/non/existing/path/file.txt",
+              "--shell_args",
+              "file.txt"
+      );
+      setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
+      assertTrue(getDSClient().init(args));
+      assertTrue(getDSClient().run());
+    });
   }
 
   @Test
-  public void testDistributedShellCleanup()
+  public void testDistributedShellCleanup(TestInfo testInfo)
       throws Exception {
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "1",
         "--shell_command",
@@ -832,7 +856,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
     assertTrue(getDSClient().run());
     ApplicationId appId = getDSClient().getAppId();
     String relativePath =
-        ApplicationMaster.getRelativePath(generateAppName(),
+        ApplicationMaster.getRelativePath(generateAppName(getMethodName(testInfo)),
             appId.toString(), "");
     FileSystem fs1 = FileSystem.get(config);
     Path path = new Path(fs1.getHomeDirectory(), relativePath);
@@ -845,7 +869,7 @@ public class TestDSTimelineV10 extends DistributedShellBaseTest {
       }
     }, 10, 60000);
 
-    assertFalse("Distributed Shell Cleanup failed", fs1.exists(path));
+    assertFalse(fs1.exists(path), "Distributed Shell Cleanup failed");
   }
 
   @Override

+ 10 - 8
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSTimelineV15.java

@@ -20,8 +20,8 @@ package org.apache.hadoop.yarn.applications.distributedshell;
 
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -34,6 +34,8 @@ import org.apache.hadoop.yarn.api.records.ApplicationReport;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.server.timeline.PluginStoreTestUtils;
 
+import static org.junit.jupiter.api.Assertions.assertNull;
+
 /**
  * Unit tests implementations for distributed shell on TimeLineV1.5.
  */
@@ -83,18 +85,18 @@ public class TestDSTimelineV15 extends DistributedShellBaseTest {
         return true;
       }
     }, scanInterval * 2, TEST_TIME_WINDOW_EXPIRE);
-    Assert.assertNull("Exception in getting listing status",
-        exceptionRef.get());
+    assertNull(exceptionRef.get(),
+        "Exception in getting listing status");
     super.checkTimeline(appId, defaultFlow, haveDomain, appReport);
   }
 
   @Test
-  public void testDSShellWithDomain() throws Exception {
-    baseTestDSShell(true);
+  public void testDSShellWithDomain(TestInfo testInfo) throws Exception {
+    baseTestDSShell(getMethodName(testInfo), true);
   }
 
   @Test
-  public void testDSShellWithoutDomain() throws Exception {
-    baseTestDSShell(false);
+  public void testDSShellWithoutDomain(TestInfo testInfo) throws Exception {
+    baseTestDSShell(getMethodName(testInfo), false);
   }
 }

+ 48 - 41
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSTimelineV20.java

@@ -26,9 +26,8 @@ import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -58,6 +57,12 @@ import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineR
 import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineWriterImpl;
 import org.apache.hadoop.yarn.util.timeline.TimelineUtils;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
 /**
  * Unit tests implementations for distributed shell on TimeLineV2.
  */
@@ -91,7 +96,7 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
   }
 
   @Test
-  public void testDSShellWithEnforceExecutionType() throws Exception {
+  public void testDSShellWithEnforceExecutionType(TestInfo testInfo) throws Exception {
     YarnClient yarnClient = null;
     AtomicReference<Throwable> thrownError = new AtomicReference<>(null);
     AtomicReference<List<ContainerReport>> containersListRef =
@@ -101,6 +106,7 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
     AtomicReference<ApplicationAttemptReport> appAttemptReportRef =
         new AtomicReference<>(null);
     String[] args = createArgumentsWithAppName(
+        getMethodName(testInfo),
         "--num_containers",
         "2",
         "--master_memory",
@@ -137,18 +143,18 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
       waitForContainersLaunch(yarnClient, 3, appAttemptReportRef,
           containersListRef, appAttemptIdRef, thrownError);
       if (thrownError.get() != null) {
-        Assert.fail(thrownError.get().getMessage());
+        fail(thrownError.get().getMessage());
       }
       ContainerId amContainerId = appAttemptReportRef.get().getAMContainerId();
       for (ContainerReport container : containersListRef.get()) {
         if (!container.getContainerId().equals(amContainerId)) {
-          Assert.assertEquals(container.getExecutionType(),
+          assertEquals(container.getExecutionType(),
               ExecutionType.OPPORTUNISTIC);
         }
       }
     } catch (Exception e) {
       LOG.error("Job execution with enforce execution type failed.", e);
-      Assert.fail("Exception. " + e.getMessage());
+      fail("Exception. " + e.getMessage());
     } finally {
       if (yarnClient != null) {
         yarnClient.stop();
@@ -157,17 +163,18 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
   }
 
   @Test
-  public void testDistributedShellWithResources() throws Exception {
-    doTestDistributedShellWithResources(false);
+  public void testDistributedShellWithResources(TestInfo testInfo) throws Exception {
+    doTestDistributedShellWithResources(getMethodName(testInfo), false);
   }
 
   @Test
-  public void testDistributedShellWithResourcesWithLargeContainers()
-      throws Exception {
-    doTestDistributedShellWithResources(true);
+  public void testDistributedShellWithResourcesWithLargeContainers(TestInfo testInfo)
+          throws Exception {
+    doTestDistributedShellWithResources(getMethodName(testInfo), true);
   }
 
-  private void doTestDistributedShellWithResources(boolean largeContainers)
+  private void doTestDistributedShellWithResources(
+      String methodName, boolean largeContainers)
       throws Exception {
     AtomicReference<Throwable> thrownExceptionRef =
         new AtomicReference<>(null);
@@ -183,10 +190,10 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
     String containerMemoryString = "512 Mi";
     long[] memVars = {1024, 512};
     YarnClient yarnClient = null;
-    Assume.assumeTrue("The cluster doesn't have enough memory for this test",
-        clusterResource.getMemorySize() >= memVars[0] + memVars[1]);
-    Assume.assumeTrue("The cluster doesn't have enough cores for this test",
-        clusterResource.getVirtualCores() >= 2);
+    assumeTrue(clusterResource.getMemorySize() >= memVars[0] + memVars[1],
+        "The cluster doesn't have enough memory for this test");
+    assumeTrue(clusterResource.getVirtualCores() >= 2,
+        "The cluster doesn't have enough cores for this test");
     if (largeContainers) {
       memVars[0] = clusterResource.getMemorySize() * 2 / 3;
       memVars[0] = memVars[0] - memVars[0] % MIN_ALLOCATION_MB;
@@ -197,6 +204,7 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
     }
 
     String[] args = createArgumentsWithAppName(
+        methodName,
         "--num_containers",
         "2",
         "--shell_command",
@@ -209,7 +217,7 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
 
     LOG.info("Initializing DS Client");
     setAndGetDSClient(new Configuration(getYarnClusterConfiguration()));
-    Assert.assertTrue(getDSClient().init(args));
+    assertTrue(getDSClient().init(args));
     LOG.info("Running DS Client");
     final AtomicBoolean result = new AtomicBoolean(false);
     Thread dsClientRunner = new Thread(() -> {
@@ -228,19 +236,19 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
       waitForContainersLaunch(yarnClient, 2, appAttemptReportRef,
           containersListRef, appAttemptIdRef, thrownExceptionRef);
       if (thrownExceptionRef.get() != null) {
-        Assert.fail(thrownExceptionRef.get().getMessage());
+        fail(thrownExceptionRef.get().getMessage());
       }
       ContainerId amContainerId = appAttemptReportRef.get().getAMContainerId();
       ContainerReport report = yarnClient.getContainerReport(amContainerId);
       Resource masterResource = report.getAllocatedResource();
-      Assert.assertEquals(memVars[0], masterResource.getMemorySize());
-      Assert.assertEquals(1, masterResource.getVirtualCores());
+      assertEquals(memVars[0], masterResource.getMemorySize());
+      assertEquals(1, masterResource.getVirtualCores());
       for (ContainerReport container : containersListRef.get()) {
         if (!container.getContainerId().equals(amContainerId)) {
           Resource containerResource = container.getAllocatedResource();
-          Assert.assertEquals(memVars[1],
+          assertEquals(memVars[1],
               containerResource.getMemorySize());
-          Assert.assertEquals(1, containerResource.getVirtualCores());
+          assertEquals(1, containerResource.getVirtualCores());
         }
       }
     } finally {
@@ -253,18 +261,18 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
   }
 
   @Test
-  public void testDSShellWithoutDomain() throws Exception {
-    baseTestDSShell(false);
+  public void testDSShellWithoutDomain(TestInfo testInfo) throws Exception {
+    baseTestDSShell(getMethodName(testInfo), false);
   }
 
   @Test
-  public void testDSShellWithoutDomainDefaultFlow() throws Exception {
-    baseTestDSShell(false, true);
+  public void testDSShellWithoutDomainDefaultFlow(TestInfo testInfo) throws Exception {
+    baseTestDSShell(getMethodName(testInfo), false, true);
   }
 
   @Test
-  public void testDSShellWithoutDomainCustomizedFlow() throws Exception {
-    baseTestDSShell(false, false);
+  public void testDSShellWithoutDomainCustomizedFlow(TestInfo testInfo) throws Exception {
+    baseTestDSShell(getMethodName(testInfo), false, false);
   }
 
   @Override
@@ -294,7 +302,7 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
 
     File tmpRootFolder = new File(tmpRoot);
     try {
-      Assert.assertTrue(tmpRootFolder.isDirectory());
+      assertTrue(tmpRootFolder.isDirectory());
       String basePath = tmpRoot +
           YarnConfiguration.DEFAULT_RM_CLUSTER_ID + File.separator +
           UserGroupInformation.getCurrentUser().getShortUserName() +
@@ -436,21 +444,20 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
             TimelineEntity entity = FileSystemTimelineReaderImpl.
                 getTimelineRecordFromJSON(entityLine, TimelineEntity.class);
             TimelineEvent event = entity.getEvents().pollFirst();
-            Assert.assertNotNull(event);
-            Assert.assertTrue("diagnostics",
-                event.getInfo().containsKey(ApplicationMaster.DIAGNOSTICS));
+            assertNotNull(event);
+            assertTrue(event.getInfo().containsKey(ApplicationMaster.DIAGNOSTICS),
+                "diagnostics");
           }
           if (checkIdPrefix) {
             TimelineEntity entity = FileSystemTimelineReaderImpl.
                 getTimelineRecordFromJSON(entityLine, TimelineEntity.class);
-            Assert.assertTrue("Entity ID prefix expected to be > 0",
-                entity.getIdPrefix() > 0);
+            assertTrue(entity.getIdPrefix() > 0,
+                "Entity ID prefix expected to be > 0");
             if (idPrefix == -1) {
               idPrefix = entity.getIdPrefix();
             } else {
-              Assert.assertEquals(
-                  "Entity ID prefix should be same across each publish of "
-                      + "same entity", idPrefix, entity.getIdPrefix());
+              assertEquals(idPrefix, entity.getIdPrefix(),
+                  "Entity ID prefix should be same across each publish of same entity");
             }
           }
         }
@@ -463,7 +470,7 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
     }, sleepTime, (checkTimes + 1) * sleepTime);
 
     if (thrownExceptionRef.get() != null) {
-      Assert.fail("verifyEntityForTimeline failed "
+      fail("verifyEntityForTimeline failed "
           + thrownExceptionRef.get().getMessage());
     }
   }
@@ -475,10 +482,10 @@ public class TestDSTimelineV20 extends DistributedShellBaseTest {
     LOG.info("verifyEntityTypeFileExists output path for entityType {}: {}",
         entityType, outputDirPathForEntity);
     File outputDirForEntity = new File(outputDirPathForEntity);
-    Assert.assertTrue(outputDirForEntity.isDirectory());
+    assertTrue(outputDirForEntity.isDirectory());
     String entityFilePath = outputDirPathForEntity + entityFileName;
     File entityFile = new File(entityFilePath);
-    Assert.assertTrue(entityFile.exists());
+    assertTrue(entityFile.exists());
     return entityFile;
   }
 }

+ 55 - 51
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/test/java/org/apache/hadoop/yarn/applications/distributedshell/TestDSWithMultipleNodeManager.java

@@ -25,20 +25,15 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestName;
-import org.junit.rules.Timeout;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -61,13 +56,16 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.Resourc
 import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
 
 import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * Test for Distributed Shell With Multiple Node Managers.
  * Parameter 0 tests with Single Node Placement and
  * parameter 1 tests with Multiple Node Placement.
  */
-@RunWith(value = Parameterized.class)
+
+@Timeout(160)
 public class TestDSWithMultipleNodeManager {
   private static final Logger LOG =
       LoggerFactory.getLogger(TestDSWithMultipleNodeManager.class);
@@ -75,21 +73,17 @@ public class TestDSWithMultipleNodeManager {
   private static final int NUM_NMS = 2;
   private static final String POLICY_CLASS_NAME =
       ResourceUsageMultiNodeLookupPolicy.class.getName();
-  private final Boolean multiNodePlacementEnabled;
-  @Rule
-  public TestName name = new TestName();
-  @Rule
-  public Timeout globalTimeout =
-      new Timeout(DistributedShellBaseTest.TEST_TIME_OUT,
-          TimeUnit.MILLISECONDS);
+  private Boolean multiNodePlacementEnabled;
+
   private DistributedShellBaseTest distShellTest;
   private Client dsClient;
 
-  public TestDSWithMultipleNodeManager(Boolean multiNodePlacementEnabled) {
-    this.multiNodePlacementEnabled = multiNodePlacementEnabled;
+  public void initTestDSWithMultipleNodeManager(
+      Boolean pMultiNodePlacementEnabled, TestInfo testInfo) throws Exception {
+    this.multiNodePlacementEnabled = pMultiNodePlacementEnabled;
+    setup(testInfo);
   }
 
-  @Parameterized.Parameters
   public static Collection<Boolean> getParams() {
     return Arrays.asList(false, true);
   }
@@ -116,24 +110,23 @@ public class TestDSWithMultipleNodeManager {
     return conf;
   }
 
-  @BeforeClass
+  @BeforeAll
   public static void setupUnitTests() throws Exception {
     TestDSTimelineV10.setupUnitTests();
   }
 
-  @AfterClass
+  @AfterAll
   public static void tearDownUnitTests() throws Exception {
     TestDSTimelineV10.tearDownUnitTests();
   }
 
-  @Before
-  public void setup() throws Exception {
+  public void setup(TestInfo testInfo) throws Exception {
     distShellTest = new TestDSTimelineV10();
     distShellTest.setupInternal(NUM_NMS,
-        getConfiguration(multiNodePlacementEnabled));
+        getConfiguration(multiNodePlacementEnabled), testInfo.getDisplayName());
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     if (dsClient != null) {
       dsClient.sendStopSignal();
@@ -176,8 +169,11 @@ public class TestDSWithMultipleNodeManager {
     labelsMgr.addLabelsToNode(ImmutableMap.of(nodeIds[1], labels));
   }
 
-  @Test
-  public void testDSShellWithNodeLabelExpression() throws Exception {
+  @MethodSource("getParams")
+  @ParameterizedTest
+  public void testDSShellWithNodeLabelExpression(Boolean pMultiNodePlacementEnabled,
+      TestInfo testInfo) throws Exception {
+    initTestDSWithMultipleNodeManager(pMultiNodePlacementEnabled, testInfo);
     NMContainerMonitor containerMonitorRunner = null;
     initializeNodeLabels();
 
@@ -188,7 +184,8 @@ public class TestDSWithMultipleNodeManager {
 
       // Submit a job which will sleep for 60 sec
       String[] args =
-          DistributedShellBaseTest.createArguments(() -> generateAppName(),
+          DistributedShellBaseTest.createArguments(() ->
+              generateAppName(distShellTest.getMethodName(testInfo)),
               "--num_containers",
               "4",
               "--shell_command",
@@ -211,7 +208,7 @@ public class TestDSWithMultipleNodeManager {
       dsClient =
           new Client(
               new Configuration(distShellTest.getYarnClusterConfiguration()));
-      Assert.assertTrue(dsClient.init(args));
+      assertTrue(dsClient.init(args));
       LOG.info("Running DS Client");
       boolean result = dsClient.run();
       LOG.info("Client run completed. Result={}", result);
@@ -222,9 +219,9 @@ public class TestDSWithMultipleNodeManager {
       int[] maxRunningContainersOnNMs =
           containerMonitorRunner.getMaxRunningContainersReport();
       // Check no container allocated on NM[0]
-      Assert.assertEquals(0, maxRunningContainersOnNMs[0]);
+      assertEquals(0, maxRunningContainersOnNMs[0]);
       // Check there are some containers allocated on NM[1]
-      Assert.assertTrue(maxRunningContainersOnNMs[1] > 0);
+      assertTrue(maxRunningContainersOnNMs[1] > 0);
     } finally {
       if (containerMonitorRunner != null) {
         containerMonitorRunner.stopMonitoring();
@@ -233,12 +230,16 @@ public class TestDSWithMultipleNodeManager {
     }
   }
 
-  @Test
-  public void testDistributedShellWithPlacementConstraint()
+  @MethodSource("getParams")
+  @ParameterizedTest
+  public void testDistributedShellWithPlacementConstraint(
+      Boolean pMultiNodePlacementEnabled, TestInfo testInfo)
       throws Exception {
+    initTestDSWithMultipleNodeManager(pMultiNodePlacementEnabled, testInfo);
     NMContainerMonitor containerMonitorRunner = null;
     String[] args =
-        DistributedShellBaseTest.createArguments(() -> generateAppName(),
+        DistributedShellBaseTest.createArguments(() ->
+            generateAppName(distShellTest.getMethodName(testInfo)),
             "1",
             "--shell_command",
             DistributedShellBaseTest.getSleepCommand(15),
@@ -253,7 +254,7 @@ public class TestDSWithMultipleNodeManager {
       dsClient =
           new Client(
               new Configuration(distShellTest.getYarnClusterConfiguration()));
-      Assert.assertTrue(dsClient.init(args));
+      assertTrue(dsClient.init(args));
       LOG.info("Running DS Client");
       boolean result = dsClient.run();
       LOG.info("Client run completed. Result={}", result);
@@ -276,8 +277,8 @@ public class TestDSWithMultipleNodeManager {
 
       int[] maxRunningContainersOnNMs =
           containerMonitorRunner.getMaxRunningContainersReport();
-      Assert.assertEquals(expectedNMsCount[0], maxRunningContainersOnNMs[0]);
-      Assert.assertEquals(expectedNMsCount[1], maxRunningContainersOnNMs[1]);
+      assertEquals(expectedNMsCount[0], maxRunningContainersOnNMs[0]);
+      assertEquals(expectedNMsCount[1], maxRunningContainersOnNMs[1]);
     } finally {
       if (containerMonitorRunner != null) {
         containerMonitorRunner.stopMonitoring();
@@ -286,9 +287,12 @@ public class TestDSWithMultipleNodeManager {
     }
   }
 
-  @Test
-  public void testDistributedShellWithAllocationTagNamespace()
+  @MethodSource("getParams")
+  @ParameterizedTest
+  public void testDistributedShellWithAllocationTagNamespace(
+      Boolean pMultiNodePlacementEnabled, TestInfo testInfo)
       throws Exception {
+    initTestDSWithMultipleNodeManager(pMultiNodePlacementEnabled, testInfo);
     NMContainerMonitor containerMonitorRunner = null;
     Client clientB = null;
     YarnClient yarnClient = null;
@@ -339,7 +343,7 @@ public class TestDSWithMultipleNodeManager {
           getNodeId();
       NodeId nodeB = distShellTest.getNodeManager(1).getNMContext().
           getNodeId();
-      Assert.assertEquals(2, (expectedNMCounts[0] + expectedNMCounts[1]));
+      assertEquals(2, (expectedNMCounts[0] + expectedNMCounts[1]));
       if (expectedNMCounts[0] != expectedNMCounts[1]) {
         taskContainerNodeIdA = masterContainerNodeIdARef.get();
       } else {
@@ -351,7 +355,7 @@ public class TestDSWithMultipleNodeManager {
           new Client(
               new Configuration(distShellTest.getYarnClusterConfiguration()));
       clientB.init(argsB);
-      Assert.assertTrue(clientB.run());
+      assertTrue(clientB.run());
       containerMonitorRunner.stopMonitoring();
       apps = distShellTest.getResourceManager().getRMContext().getRMApps();
       Iterator<RMApp> it = apps.values().iterator();
@@ -379,8 +383,8 @@ public class TestDSWithMultipleNodeManager {
       }
       int[] maxRunningContainersOnNMs =
           containerMonitorRunner.getMaxRunningContainersReport();
-      Assert.assertEquals(expectedNMCounts[0], maxRunningContainersOnNMs[0]);
-      Assert.assertEquals(expectedNMCounts[1], maxRunningContainersOnNMs[1]);
+      assertEquals(expectedNMCounts[0], maxRunningContainersOnNMs[0]);
+      assertEquals(expectedNMCounts[1], maxRunningContainersOnNMs[1]);
 
       try {
         yarnClient = YarnClient.createYarnClient();
@@ -406,12 +410,12 @@ public class TestDSWithMultipleNodeManager {
     }
   }
 
-  protected String generateAppName() {
-    return generateAppName(null);
+  protected String generateAppName(String name) {
+    return generateAppName(name, null);
   }
 
-  protected String generateAppName(String postFix) {
-    return name.getMethodName().replaceFirst("test", "")
+  protected String generateAppName(String name, String postFix) {
+    return name.replaceFirst("test", "")
         .concat(postFix == null ? "" : "-" + postFix);
   }