Explorar o código

YARN-11262. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcemanager Part1. (#7474)

Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcemanager Part1.

Co-authored-by: Chris Nauroth <cnauroth@apache.org>
Co-authored-by: Hualong Zhang <hualong.z@hotmail.com>
Reviewed-by: Chris Nauroth <cnauroth@apache.org>
Reviewed-by: Hualong Zhang <hualong.z@hotmail.com>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
slfan1989 hai 1 mes
pai
achega
7d143b7fb1
Modificáronse 43 ficheiros con 2026 adicións e 1599 borrados
  1. 188 128
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java
  2. 43 30
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientImpl.java
  3. 4 10
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ParameterizedSchedulerTestBase.java
  4. 55 56
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java
  5. 105 70
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java
  6. 236 181
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java
  7. 178 97
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java
  8. 42 25
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingUnmanagedAM.java
  9. 44 40
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ahs/TestRMApplicationHistoryWriter.java
  10. 44 42
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRMRPCNodeUpdates.java
  11. 15 12
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRMRPCResponseId.java
  12. 139 97
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java
  13. 19 34
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/blacklist/TestBlacklistManager.java
  14. 58 54
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/federation/TestFederationRMStateStoreService.java
  15. 2 2
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/federation/TestFederationStateStoreServiceMetrics.java
  16. 65 64
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/logaggregationstatus/TestRMAppLogAggregationStatus.java
  17. 42 35
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestCombinedSystemMetricsPublisher.java
  18. 124 100
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisher.java
  19. 38 36
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisherForV2.java
  20. 10 6
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/TestSchedulingMonitor.java
  21. 3 3
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestPreemptionForQueueWithPriorities.java
  22. 21 20
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java
  23. 3 3
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForNodePartitions.java
  24. 3 3
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForReservedContainers.java
  25. 3 3
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyInterQueueWithDRF.java
  26. 3 3
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueue.java
  27. 3 3
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueFairOrdering.java
  28. 3 3
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueUserLimit.java
  29. 3 3
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueWithDRF.java
  30. 28 23
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyMockFramework.java
  31. 2 2
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java
  32. 12 12
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/mockframework/ProportionalCapacityPreemptionPolicyMockFramework.java
  33. 7 5
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/invariants/TestMetricsInvariantChecker.java
  34. 30 35
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java
  35. 42 40
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestNodeAttributesManager.java
  36. 5 5
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestNodeLabelFileReplication.java
  37. 8 7
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestRMDelegatedNodeLabelsUpdater.java
  38. 108 97
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestRMNodeLabelsManager.java
  39. 28 21
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystem.java
  40. 41 29
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMReconnect.java
  41. 148 107
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestAbstractYarnScheduler.java
  42. 33 21
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulingWithAllocationRequestId.java
  43. 38 32
      hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java

+ 188 - 128
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClient.java

@@ -77,9 +77,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
 import org.apache.hadoop.yarn.util.Records;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.mockito.ArgumentCaptor;
 import org.slf4j.event.Level;
 
@@ -97,6 +97,12 @@ import java.util.Map;
 import java.util.Set;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
@@ -109,20 +115,22 @@ import static org.mockito.Mockito.when;
  */
 public class TestYarnClient extends ParameterizedSchedulerTestBase {
 
-  public TestYarnClient(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestYarnClient(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
+    setup();
   }
 
   protected void configureFairScheduler(YarnConfiguration conf) {}
 
-  @Before
   public void setup() {
     QueueMetrics.clearQueueMetrics();
     DefaultMetricsSystem.setMiniClusterMode(true);
   }
 
-  @Test
-  public void testClientStop() {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testClientStop(SchedulerType type) throws IOException {
+    initTestYarnClient(type);
     Configuration conf = getConf();
     ResourceManager rm = new ResourceManager();
     rm.init(conf);
@@ -135,9 +143,11 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     rm.stop();
   }
 
-  @Test
-  public void testStartTimelineClientWithErrors()
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testStartTimelineClientWithErrors(SchedulerType type)
       throws Exception {
+    initTestYarnClient(type);
     // If timeline client failed to init with a NoClassDefFoundError
     // it should be wrapped with an informative error message
     testCreateTimelineClientWithError(
@@ -148,10 +158,9 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         new CreateTimelineClientErrorVerifier(1) {
           @Override
           public void verifyError(Throwable e) {
-            Assert.assertTrue(e instanceof NoClassDefFoundError);
-            Assert.assertTrue(e.getMessage() != null &&
-                e.getMessage().contains(
-                    YarnConfiguration.TIMELINE_SERVICE_ENABLED));
+            assertTrue(e instanceof NoClassDefFoundError);
+            assertTrue(e.getMessage() != null &&
+                e.getMessage().contains(YarnConfiguration.TIMELINE_SERVICE_ENABLED));
           }
         });
 
@@ -164,7 +173,7 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         new NoClassDefFoundError("Mock a NoClassDefFoundError"),
         new CreateTimelineClientErrorVerifier(0) {
           @Override public void verifyError(Throwable e) {
-            Assert.fail("NoClassDefFoundError while creating timeline client"
+            fail("NoClassDefFoundError while creating timeline client"
                 + "should be tolerated when timeline service is disabled.");
           }
         }
@@ -178,10 +187,9 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         new NoClassDefFoundError("Mock a NoClassDefFoundError"),
         new CreateTimelineClientErrorVerifier(1) {
           @Override public void verifyError(Throwable e) {
-            Assert.assertTrue(e instanceof NoClassDefFoundError);
-            Assert.assertTrue(e.getMessage() != null &&
-                e.getMessage().contains(
-                    YarnConfiguration.TIMELINE_SERVICE_ENABLED));
+            assertTrue(e instanceof NoClassDefFoundError);
+            assertTrue(e.getMessage() != null &&
+                e.getMessage().contains(YarnConfiguration.TIMELINE_SERVICE_ENABLED));
           }
         }
     );
@@ -196,7 +204,7 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         new CreateTimelineClientErrorVerifier(1) {
           @Override
           public void verifyError(Throwable e) {
-            Assert.assertTrue(e instanceof IOException);
+            assertTrue(e instanceof IOException);
           }
         }
     );
@@ -211,7 +219,7 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         new CreateTimelineClientErrorVerifier(0) {
           @Override
           public void verifyError(Throwable e) {
-            Assert.fail("IOException while creating timeline client"
+            fail("IOException while creating timeline client"
                 + "should be tolerated when best effort is true");
           }
         }
@@ -219,8 +227,11 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
   }
 
   @SuppressWarnings("deprecation")
-  @Test (timeout = 30000)
-  public void testSubmitApplication() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testSubmitApplication(SchedulerType type) throws Exception {
+    initTestYarnClient(type);
     Configuration conf = getConf();
     conf.setLong(YarnConfiguration.YARN_CLIENT_APP_SUBMISSION_POLL_INTERVAL_MS,
         100); // speed up tests
@@ -241,10 +252,10 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         mock(ApplicationSubmissionContext.class);
     try {
       client.submitApplication(contextWithoutApplicationId);
-      Assert.fail("Should throw the ApplicationIdNotProvidedException");
+      fail("Should throw the ApplicationIdNotProvidedException");
     } catch (YarnException e) {
-      Assert.assertTrue(e instanceof ApplicationIdNotProvidedException);
-      Assert.assertTrue(e.getMessage().contains(
+      assertTrue(e instanceof ApplicationIdNotProvidedException);
+      assertTrue(e.getMessage().contains(
           "ApplicationId is not provided in ApplicationSubmissionContext"));
     }
 
@@ -266,8 +277,11 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
   }
 
   @SuppressWarnings("deprecation")
-  @Test (timeout = 20000)
-  public void testSubmitApplicationInterrupted() throws IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 20)
+  public void testSubmitApplicationInterrupted(SchedulerType type) throws IOException {
+    initTestYarnClient(type);
     Configuration conf = getConf();
     int pollIntervalMs = 1000;
     conf.setLong(YarnConfiguration.YARN_CLIENT_APP_SUBMISSION_POLL_INTERVAL_MS,
@@ -311,13 +325,16 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         appSubmitThread.join();
       } catch (InterruptedException e) {
       }
-      Assert.assertTrue("Expected an InterruptedException wrapped inside a " +
-          "YarnException", appSubmitThread.isInterrupted);
+      assertTrue(appSubmitThread.isInterrupted,
+          "Expected an InterruptedException wrapped inside a YarnException");
     }
   }
 
-  @Test (timeout = 30000)
-  public void testSubmitIncorrectQueueToCapacityScheduler() throws IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testSubmitIncorrectQueueToCapacityScheduler(SchedulerType type) throws IOException {
+    initTestYarnClient(type);
     MiniYARNCluster cluster = new MiniYARNCluster("testMRAMTokens", 1, 1, 1);
     YarnClient rmClient = null;
     try {
@@ -356,9 +373,9 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
 
       // Submit the application to the applications manager
       rmClient.submitApplication(appContext);
-      Assert.fail("Job submission should have thrown an exception");
+      fail("Job submission should have thrown an exception");
     } catch (YarnException e) {
-      Assert.assertTrue(e.getMessage().contains("Failed to submit"));
+      assertTrue(e.getMessage().contains("Failed to submit"));
     } finally {
       if (rmClient != null) {
         rmClient.stop();
@@ -366,9 +383,12 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
       cluster.stop();
     }
   }
-  
-  @Test
-  public void testKillApplication() throws Exception {
+
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testKillApplication(SchedulerType type) throws Exception {
+    initTestYarnClient(type);
     MockRM rm = new MockRM();
     rm.start();
     RMApp app = MockRMAppSubmitter.submitWithMemory(2000, rm);
@@ -383,8 +403,11 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
       .forceKillApplication(any(KillApplicationRequest.class));
   }
 
-  @Test(timeout = 30000)
-  public void testApplicationType() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testApplicationType(SchedulerType type) throws Exception {
+    initTestYarnClient(type);
     GenericTestUtils.setRootLogLevel(Level.DEBUG);
     MockRM rm = new MockRM();
     rm.start();
@@ -401,13 +424,16 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
                 .withCredentials(null)
                 .withAppType("MAPREDUCE")
                 .build());
-    Assert.assertEquals("YARN", app.getApplicationType());
-    Assert.assertEquals("MAPREDUCE", app1.getApplicationType());
+    assertEquals("YARN", app.getApplicationType());
+    assertEquals("MAPREDUCE", app1.getApplicationType());
     rm.stop();
   }
 
-  @Test(timeout = 30000)
-  public void testApplicationTypeLimit() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testApplicationTypeLimit(SchedulerType type) throws Exception {
+    initTestYarnClient(type);
     GenericTestUtils.setRootLogLevel(Level.DEBUG);
     MockRM rm = new MockRM();
     rm.start();
@@ -423,12 +449,15 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
                 .withCredentials(null)
                 .withAppType("MAPREDUCE-LENGTH-IS-20")
                 .build());
-    Assert.assertEquals("MAPREDUCE-LENGTH-IS-", app1.getApplicationType());
+    assertEquals("MAPREDUCE-LENGTH-IS-", app1.getApplicationType());
     rm.stop();
   }
 
-  @Test (timeout = 10000)
-  public void testGetApplications() throws YarnException, IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 10)
+  public void testGetApplications(SchedulerType type) throws YarnException, IOException {
+    initTestYarnClient(type);
     final YarnClient client = new MockYarnClient();
     client.init(getConf());
     client.start();
@@ -445,13 +474,12 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     reports =
         client.getApplications(appTypes, null);
     assertThat(reports).hasSize(2);
-    Assert
-        .assertTrue((reports.get(0).getApplicationType().equals("YARN") && reports
-            .get(1).getApplicationType().equals("NON-YARN"))
-            || (reports.get(1).getApplicationType().equals("YARN") && reports
-                .get(0).getApplicationType().equals("NON-YARN")));
+    assertTrue((reports.get(0).getApplicationType().equals("YARN") && reports
+        .get(1).getApplicationType().equals("NON-YARN"))
+        || (reports.get(1).getApplicationType().equals("YARN") && reports
+        .get(0).getApplicationType().equals("NON-YARN")));
     for(ApplicationReport report : reports) {
-      Assert.assertTrue(expectedReports.contains(report));
+      assertTrue(expectedReports.contains(report));
     }
 
     EnumSet<YarnApplicationState> appStates =
@@ -460,27 +488,29 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     appStates.add(YarnApplicationState.FAILED);
     reports = client.getApplications(null, appStates);
     assertThat(reports).hasSize(2);
-    Assert
-    .assertTrue((reports.get(0).getApplicationType().equals("NON-YARN") && reports
+    assertTrue((reports.get(0).getApplicationType().equals("NON-YARN") && reports
         .get(1).getApplicationType().equals("NON-MAPREDUCE"))
         || (reports.get(1).getApplicationType().equals("NON-YARN") && reports
-            .get(0).getApplicationType().equals("NON-MAPREDUCE")));
+        .get(0).getApplicationType().equals("NON-MAPREDUCE")));
     for (ApplicationReport report : reports) {
-      Assert.assertTrue(expectedReports.contains(report));
+      assertTrue(expectedReports.contains(report));
     }
 
     reports = client.getApplications(appTypes, appStates);
-    Assert.assertEquals(1, reports.size());
-    Assert.assertEquals("NON-YARN", reports.get(0).getApplicationType());
+    assertEquals(1, reports.size());
+    assertEquals("NON-YARN", reports.get(0).getApplicationType());
     for (ApplicationReport report : reports) {
-      Assert.assertTrue(expectedReports.contains(report));
+      assertTrue(expectedReports.contains(report));
     }
 
     client.stop();
   }
 
-  @Test(timeout = 10000)
-  public void testGetApplicationAttempts() throws YarnException, IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 10)
+  public void testGetApplicationAttempts(SchedulerType type) throws YarnException, IOException {
+    initTestYarnClient(type);
     final YarnClient client = new MockYarnClient();
     client.init(getConf());
     client.start();
@@ -488,7 +518,7 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
     List<ApplicationAttemptReport> reports = client
         .getApplicationAttempts(applicationId);
-    Assert.assertNotNull(reports);
+    assertNotNull(reports);
     assertThat(reports.get(0).getApplicationAttemptId()).isEqualTo(
         ApplicationAttemptId.newInstance(applicationId, 1));
     assertThat(reports.get(1).getApplicationAttemptId()).isEqualTo(
@@ -496,8 +526,11 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     client.stop();
   }
 
-  @Test(timeout = 10000)
-  public void testGetApplicationAttempt() throws YarnException, IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 10)
+  public void testGetApplicationAttempt(SchedulerType type) throws YarnException, IOException {
+    initTestYarnClient(type);
     Configuration conf = new Configuration();
     final YarnClient client = new MockYarnClient();
     client.init(conf);
@@ -511,14 +544,17 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         applicationId, 1);
     ApplicationAttemptReport report = client
         .getApplicationAttemptReport(appAttemptId);
-    Assert.assertNotNull(report);
+    assertNotNull(report);
     assertThat(report.getApplicationAttemptId().toString()).isEqualTo(
         expectedReports.get(0).getCurrentApplicationAttemptId().toString());
     client.stop();
   }
 
-  @Test(timeout = 10000)
-  public void testGetContainers() throws YarnException, IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 10)
+  public void testGetContainers(SchedulerType type) throws YarnException, IOException {
+    initTestYarnClient(type);
     Configuration conf = getConf();
     conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
         true);
@@ -531,7 +567,7 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(
         applicationId, 1);
     List<ContainerReport> reports = client.getContainers(appAttemptId);
-    Assert.assertNotNull(reports);
+    assertNotNull(reports);
     assertThat(reports.get(0).getContainerId()).isEqualTo(
         (ContainerId.newContainerId(appAttemptId, 1)));
     assertThat(reports.get(1).getContainerId()).isEqualTo(
@@ -541,17 +577,20 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     
     //First2 containers should come from RM with updated state information and 
     // 3rd container is not there in RM and should
-    Assert.assertEquals(ContainerState.RUNNING,
+    assertEquals(ContainerState.RUNNING,
         (reports.get(0).getContainerState()));
-    Assert.assertEquals(ContainerState.RUNNING,
+    assertEquals(ContainerState.RUNNING,
         (reports.get(1).getContainerState()));
-    Assert.assertEquals(ContainerState.COMPLETE,
+    assertEquals(ContainerState.COMPLETE,
         (reports.get(2).getContainerState()));
     client.stop();
   }
 
-  @Test(timeout = 10000)
-  public void testGetContainersOnAHSFail() throws YarnException, IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 10)
+  public void testGetContainersOnAHSFail(SchedulerType type) throws YarnException, IOException {
+    initTestYarnClient(type);
     Configuration conf = getConf();
     conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
         true);
@@ -572,24 +611,27 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(
         applicationId, 1);
     List<ContainerReport> reports = client.getContainers(appAttemptId);
-    Assert.assertNotNull(reports);
-    Assert.assertTrue(reports.size() == 2);
+    assertNotNull(reports);
+    assertTrue(reports.size() == 2);
     assertThat(reports.get(0).getContainerId()).isEqualTo(
         (ContainerId.newContainerId(appAttemptId, 1)));
     assertThat(reports.get(1).getContainerId()).isEqualTo(
         (ContainerId.newContainerId(appAttemptId, 2)));
 
     //Only 2 running containers from RM are present when AHS throws exception
-    Assert.assertEquals(ContainerState.RUNNING,
+    assertEquals(ContainerState.RUNNING,
         (reports.get(0).getContainerState()));
-    Assert.assertEquals(ContainerState.RUNNING,
+    assertEquals(ContainerState.RUNNING,
         (reports.get(1).getContainerState()));
     client.stop();
   }
 
 
-  @Test(timeout = 10000)
-  public void testGetContainerReport() throws YarnException, IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 10)
+  public void testGetContainerReport(SchedulerType type) throws YarnException, IOException {
+    initTestYarnClient(type);
     Configuration conf = getConf();
     conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
         true);
@@ -605,22 +647,25 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         applicationId, 1);
     ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1);
     ContainerReport report = client.getContainerReport(containerId);
-    Assert.assertNotNull(report);
+    assertNotNull(report);
     assertThat(report.getContainerId().toString()).isEqualTo(
         (ContainerId.newContainerId(expectedReports.get(0)
             .getCurrentApplicationAttemptId(), 1)).toString());
     containerId = ContainerId.newContainerId(appAttemptId, 3);
     report = client.getContainerReport(containerId);
-    Assert.assertNotNull(report);
+    assertNotNull(report);
     assertThat(report.getContainerId().toString()).isEqualTo(
         (ContainerId.newContainerId(expectedReports.get(0)
             .getCurrentApplicationAttemptId(), 3)).toString());
-    Assert.assertNotNull(report.getExecutionType());
+    assertNotNull(report.getExecutionType());
     client.stop();
   }
 
-  @Test (timeout = 10000)
-  public void testGetLabelsToNodes() throws YarnException, IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 10)
+  public void testGetLabelsToNodes(SchedulerType type) throws YarnException, IOException {
+    initTestYarnClient(type);
     final YarnClient client = new MockYarnClient();
     client.init(getConf());
     client.start();
@@ -644,8 +689,11 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     client.close();
   }
 
-  @Test (timeout = 10000)
-  public void testGetNodesToLabels() throws YarnException, IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 10)
+  public void testGetNodesToLabels(SchedulerType type) throws YarnException, IOException {
+    initTestYarnClient(type);
     final YarnClient client = new MockYarnClient();
     client.init(getConf());
     client.start();
@@ -731,7 +779,7 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
         historyClient = mock(AHSClient.class);
 
       } catch (Exception e) {
-        Assert.fail("Unexpected exception caught: " + e);
+        fail("Unexpected exception caught: " + e);
       }
 
       when(mockResponse.getApplicationReport()).thenReturn(mockReport);
@@ -1048,8 +1096,11 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test(timeout = 30000)
-  public void testAMMRTokens() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testAMMRTokens(SchedulerType type) throws Exception {
+    initTestYarnClient(type);
     MiniYARNCluster cluster = new MiniYARNCluster("testMRAMTokens", 1, 1, 1);
     YarnClient rmClient = null;
     try {
@@ -1063,19 +1114,19 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
       ApplicationId appId = createApp(rmClient, false);
       waitTillAccepted(rmClient, appId, false);
       //managed AMs don't return AMRM token
-      Assert.assertNull(rmClient.getAMRMToken(appId));
+      assertNull(rmClient.getAMRMToken(appId));
 
       appId = createApp(rmClient, true);
       waitTillAccepted(rmClient, appId, true);
       long start = System.currentTimeMillis();
       while (rmClient.getAMRMToken(appId) == null) {
         if (System.currentTimeMillis() - start > 20 * 1000) {
-          Assert.fail("AMRM token is null");
+          fail("AMRM token is null");
         }
         Thread.sleep(100);
       }
       //unmanaged AMs do return AMRM token
-      Assert.assertNotNull(rmClient.getAMRMToken(appId));
+      assertNotNull(rmClient.getAMRMToken(appId));
       
       UserGroupInformation other =
         UserGroupInformation.createUserForTesting("foo", new String[]{});
@@ -1091,17 +1142,17 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
             long start = System.currentTimeMillis();
             while (rmClient.getAMRMToken(appId) == null) {
               if (System.currentTimeMillis() - start > 20 * 1000) {
-                Assert.fail("AMRM token is null");
+                fail("AMRM token is null");
               }
               Thread.sleep(100);
             }
             //unmanaged AMs do return AMRM token
-            Assert.assertNotNull(rmClient.getAMRMToken(appId));
+            assertNotNull(rmClient.getAMRMToken(appId));
             return appId;
           }
         });
       //other users don't get AMRM token
-      Assert.assertNull(rmClient.getAMRMToken(appId));
+      assertNull(rmClient.getAMRMToken(appId));
     } finally {
       if (rmClient != null) {
         rmClient.stop();
@@ -1160,43 +1211,52 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
       Thread.sleep(200);
       report = rmClient.getApplicationReport(appId);
     }
-    Assert.assertEquals(unmanagedApplication, report.isUnmanagedApp());
+    assertEquals(unmanagedApplication, report.isUnmanagedApp());
   }
 
-  @Test(timeout = 30000, expected = ApplicationNotFoundException.class)
-  public void testShouldNotRetryForeverForNonNetworkExceptions() throws Exception {
-    YarnConfiguration conf = getConf();
-    conf.setInt(YarnConfiguration.RESOURCEMANAGER_CONNECT_MAX_WAIT_MS, -1);
-
-    ResourceManager rm = null;
-    YarnClient yarnClient = null;
-    try {
-      // start rm
-      rm = new ResourceManager();
-      rm.init(conf);
-      rm.start();
-
-      yarnClient = YarnClient.createYarnClient();
-      yarnClient.init(conf);
-      yarnClient.start();
-
-      // create invalid application id
-      ApplicationId appId = ApplicationId.newInstance(1430126768L, 10645);
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testShouldNotRetryForeverForNonNetworkExceptions(SchedulerType type)
+      throws Exception {
+    assertThrows(ApplicationNotFoundException.class, () -> {
+      initTestYarnClient(type);
+      YarnConfiguration conf = getConf();
+      conf.setInt(YarnConfiguration.RESOURCEMANAGER_CONNECT_MAX_WAIT_MS, -1);
 
-      // RM should throw ApplicationNotFoundException exception
-      yarnClient.getApplicationReport(appId);
-    } finally {
-      if (yarnClient != null) {
-        yarnClient.stop();
-      }
-      if (rm != null) {
-        rm.stop();
+      ResourceManager rm = null;
+      YarnClient yarnClient = null;
+      try {
+        // start rm
+        rm = new ResourceManager();
+        rm.init(conf);
+        rm.start();
+
+        yarnClient = YarnClient.createYarnClient();
+        yarnClient.init(conf);
+        yarnClient.start();
+
+        // create invalid application id
+        ApplicationId appId = ApplicationId.newInstance(1430126768L, 10645);
+
+        // RM should throw ApplicationNotFoundException exception
+        yarnClient.getApplicationReport(appId);
+      } finally {
+        if (yarnClient != null) {
+          yarnClient.stop();
+        }
+        if (rm != null) {
+          rm.stop();
+        }
       }
-    }
+    });
   }
 
-  @Test
-  public void testSignalContainer() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testSignalContainer(SchedulerType type) throws Exception {
+    initTestYarnClient(type);
     @SuppressWarnings("resource")
     final YarnClient client = new MockYarnClient();
     client.init(getConf());
@@ -1212,8 +1272,8 @@ public class TestYarnClient extends ParameterizedSchedulerTestBase {
     verify(((MockYarnClient) client).getRMClient())
         .signalToContainer(signalReqCaptor.capture());
     SignalContainerRequest request = signalReqCaptor.getValue();
-    Assert.assertEquals(containerId, request.getContainerId());
-    Assert.assertEquals(command, request.getCommand());
+    assertEquals(containerId, request.getContainerId());
+    assertEquals(command, request.getCommand());
   }
 
   private void testCreateTimelineClientWithError(

+ 43 - 30
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestYarnClientImpl.java

@@ -50,9 +50,8 @@ import org.apache.hadoop.yarn.security.client.TimelineDelegationTokenIdentifier;
 import org.apache.hadoop.yarn.server.resourcemanager
         .ParameterizedSchedulerTestBase;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -60,6 +59,8 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.Collection;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
@@ -75,18 +76,20 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
 
   protected static final String YARN_RM = "yarn-rm@EXAMPLE.COM";
 
-  public TestYarnClientImpl(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestYarnClientImpl(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
+    setup();
   }
 
-  @Before
   public void setup() {
     QueueMetrics.clearQueueMetrics();
     DefaultMetricsSystem.setMiniClusterMode(true);
   }
 
-  @Test
-  public void testStartWithTimelineV15() {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testStartWithTimelineV15(SchedulerType type) throws IOException {
+    initTestYarnClientImpl(type);
     Configuration conf = getConf();
     conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
     conf.setFloat(YarnConfiguration.TIMELINE_SERVICE_VERSION, 1.5f);
@@ -96,8 +99,10 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
     client.stop();
   }
 
-  @Test
-  public void testAsyncAPIPollTimeout() {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAsyncAPIPollTimeout(SchedulerType type) throws IOException {
+    initTestYarnClientImpl(type);
     testAsyncAPIPollTimeoutHelper(null, false);
     testAsyncAPIPollTimeoutHelper(0L, true);
     testAsyncAPIPollTimeoutHelper(1L, true);
@@ -116,16 +121,17 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
 
       client.init(conf);
 
-      Assert.assertEquals(
-              expectedTimeoutEnforcement, client.enforceAsyncAPITimeout());
+      assertEquals(expectedTimeoutEnforcement, client.enforceAsyncAPITimeout());
     } finally {
       IOUtils.closeStream(client);
     }
   }
 
-  @Test
-  public void testBestEffortTimelineDelegationToken()
-          throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testBestEffortTimelineDelegationToken(SchedulerType type)
+      throws Exception {
+    initTestYarnClientImpl(type);
     Configuration conf = getConf();
     conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
     SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, conf);
@@ -152,7 +158,7 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
       conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_CLIENT_BEST_EFFORT, false);
       client.serviceInit(conf);
       client.getTimelineDelegationToken();
-      Assert.fail("Get delegation token should have thrown an exception");
+      fail("Get delegation token should have thrown an exception");
     } catch (IOException e) {
       // Success
     }
@@ -161,9 +167,11 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
   // Validates if YarnClientImpl automatically adds HDFS Delegation
   // token for Log Aggregation Path in a cluster setup with fs.DefaultFS
   // set to LocalFileSystem and Log Aggregation Path set to HDFS.
-  @Test
-  public void testAutomaitcLogAggregationDelegationToken()
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAutomaitcLogAggregationDelegationToken(SchedulerType type)
       throws Exception {
+    initTestYarnClientImpl(type);
     Configuration conf = getConf();
     SecurityUtil.setAuthenticationMethod(
         UserGroupInformation.AuthenticationMethod.KERBEROS, conf);
@@ -262,10 +270,10 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
       }
       Collection<Token<? extends TokenIdentifier>> dTokens =
            credentials.getAllTokens();
-      Assert.assertEquals("Failed to place token for Log Aggregation Path",
-          1, dTokens.size());
-      Assert.assertEquals("Wrong Token for Log Aggregation",
-          hdfsDT.getKind(), dTokens.iterator().next().getKind());
+      assertEquals(1, dTokens.size(),
+          "Failed to place token for Log Aggregation Path");
+      assertEquals(hdfsDT.getKind(), dTokens.iterator().next().getKind(),
+          "Wrong Token for Log Aggregation");
 
     } finally {
       if (hdfsCluster != null) {
@@ -274,9 +282,11 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test
-  public void testAutomaticTimelineDelegationTokenLoading()
-          throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAutomaticTimelineDelegationTokenLoading(SchedulerType type)
+      throws Exception {
+    initTestYarnClientImpl(type);
     Configuration conf = getConf();
     conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
     SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, conf);
@@ -356,16 +366,19 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
         }
         Collection<Token<? extends TokenIdentifier>> dTokens =
                 credentials.getAllTokens();
-        Assert.assertEquals(1, dTokens.size());
-        Assert.assertEquals(dToken, dTokens.iterator().next());
+        assertEquals(1, dTokens.size());
+        assertEquals(dToken, dTokens.iterator().next());
       }
     } finally {
       client.stop();
     }
   }
 
-  @Test
-  public void testParseTimelineDelegationTokenRenewer() {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testParseTimelineDelegationTokenRenewer(SchedulerType type)
+      throws IOException {
+    initTestYarnClientImpl(type);
     // Client side
     YarnClientImpl client = (YarnClientImpl) YarnClient.createYarnClient();
     Configuration conf = getConf();
@@ -376,7 +389,7 @@ public class TestYarnClientImpl extends ParameterizedSchedulerTestBase {
     try {
       client.init(conf);
       client.start();
-      Assert.assertEquals("rm/localhost@EXAMPLE.COM", client.timelineDTRenewer);
+      assertEquals("rm/localhost@EXAMPLE.COM", client.timelineDTRenewer);
     } finally {
       client.stop();
     }

+ 4 - 10
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ParameterizedSchedulerTestBase.java

@@ -26,15 +26,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.Capacity
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration;
 
-
-
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair
     .allocationfile.AllocationFileQueue;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair
     .allocationfile.AllocationFileWriter;
-import org.junit.After;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
 
 import java.io.File;
 import java.io.IOException;
@@ -42,7 +38,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.stream.Collectors;
 
-@RunWith(Parameterized.class)
 public abstract class ParameterizedSchedulerTestBase {
   protected final static String TEST_DIR =
       new File(System.getProperty("test.build.data", "/tmp")).getAbsolutePath();
@@ -53,7 +48,6 @@ public abstract class ParameterizedSchedulerTestBase {
     CAPACITY, FAIR
   }
 
-  @Parameterized.Parameters(name = "{0}")
   public static Collection<Object[]> getParameters() {
     return Arrays.stream(SchedulerType.values()).map(
         type -> new Object[]{type}).collect(Collectors.toList());
@@ -68,7 +62,7 @@ public abstract class ParameterizedSchedulerTestBase {
   }
 
   // Due to parameterization, this gets called before each test method
-  public ParameterizedSchedulerTestBase(SchedulerType type)
+  public void initParameterizedSchedulerTestBase(SchedulerType type)
       throws IOException {
     conf = new YarnConfiguration();
 
@@ -113,7 +107,7 @@ public abstract class ParameterizedSchedulerTestBase {
     configuration.setLong(FairSchedulerConfiguration.UPDATE_INTERVAL_MS, 10);
   }
 
-  @After
+  @AfterEach
   public void tearDown() {
     if (schedulerType == SchedulerType.FAIR) {
       (new File(FS_ALLOC_FILE)).delete();
@@ -128,7 +122,7 @@ public abstract class ParameterizedSchedulerTestBase {
    * Return a scheduler configured by {@code YarnConfiguration.RM_SCHEDULER}
    *
    * <p>The scheduler is configured by
-   * {@link #ParameterizedSchedulerTestBase(SchedulerType)}.
+   * {@link ParameterizedSchedulerTestBase}.
    * Client test code can obtain the scheduler with this getter method.
    * Schedulers supported by this class are {@link FairScheduler} or
    * {@link CapacityScheduler}. </p>

+ 55 - 56
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java

@@ -18,6 +18,9 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+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.when;
 import static org.mockito.ArgumentMatchers.any;
@@ -43,8 +46,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair
     .allocationfile.AllocationFileQueuePlacementRule;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair
     .allocationfile.AllocationFileWriter;
-import org.junit.After;
-import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -76,8 +80,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager;
 import org.apache.hadoop.yarn.util.resource.Resources;
-import org.junit.Before;
-import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -103,11 +105,12 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
   private RecordFactory recordFactory;
   private boolean isQueueUser;
 
-  public TestApplicationACLs(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestApplicationACLs(SchedulerType type)
+      throws IOException, InterruptedException {
+    initParameterizedSchedulerTestBase(type);
+    setup();
   }
 
-  @Before
   public void setup() throws InterruptedException, IOException {
     conf = getConf();
     rpc = YarnRPC.create(conf);
@@ -181,7 +184,7 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
     });
   }
 
-  @After
+  @AfterEach
   public void tearDown() {
     if(resourceManager != null) {
       resourceManager.stop();
@@ -210,8 +213,11 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
     configuration.set(FairSchedulerConfiguration.ALLOCATION_FILE, allocFile);
   }
 
-  @Test
-  public void testApplicationACLs() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testApplicationACLs(SchedulerType type) throws Exception {
+
+    initTestApplicationACLs(type);
 
     verifyOwnerAccess();
 
@@ -294,10 +300,9 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
     rmClient.getApplicationReport(appReportRequest);
 
     // List apps as owner
-    Assert.assertEquals("App view by owner should list the apps!!", 1,
-        rmClient.getApplications(
-            recordFactory.newRecordInstance(GetApplicationsRequest.class))
-            .getApplicationList().size());
+    assertEquals(1, rmClient.getApplications(
+        recordFactory.newRecordInstance(GetApplicationsRequest.class))
+        .getApplicationList().size(), "App view by owner should list the apps!!");
 
     // Kill app as owner
     rmClient.forceKillApplication(finishAppRequest);
@@ -325,10 +330,10 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
     superUserClient.getApplicationReport(appReportRequest);
 
     // List apps as superUser
-    Assert.assertEquals("App view by super-user should list the apps!!", 2,
+    assertEquals(2,
         superUserClient.getApplications(
-            recordFactory.newRecordInstance(GetApplicationsRequest.class))
-            .getApplicationList().size());
+        recordFactory.newRecordInstance(GetApplicationsRequest.class))
+        .getApplicationList().size(), "App view by super-user should list the apps!!");
 
     // Kill app as the superUser
     superUserClient.forceKillApplication(finishAppRequest);
@@ -356,10 +361,9 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
     friendClient.getApplicationReport(appReportRequest);
 
     // List apps as friend
-    Assert.assertEquals("App view by a friend should list the apps!!", 3,
-        friendClient.getApplications(
-            recordFactory.newRecordInstance(GetApplicationsRequest.class))
-            .getApplicationList().size());
+    assertEquals(3, friendClient.getApplications(
+        recordFactory.newRecordInstance(GetApplicationsRequest.class))
+        .getApplicationList().size(), "App view by a friend should list the apps!!");
 
     // Kill app as the friend
     friendClient.forceKillApplication(finishAppRequest);
@@ -393,8 +397,8 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
         .getApplications(recordFactory
             .newRecordInstance(GetApplicationsRequest.class))
         .getApplicationList();
-    Assert.assertEquals("App view by enemy should list the apps!!", 4,
-        appReports.size());
+    assertEquals(4, appReports.size(),
+        "App view by enemy should list the apps!!");
     for (ApplicationReport report : appReports) {
       verifyEnemyAppReport(report);
     }
@@ -402,43 +406,39 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
     // Kill app as the enemy
     try {
       enemyRmClient.forceKillApplication(finishAppRequest);
-      Assert.fail("App killing by the enemy should fail!!");
+      fail("App killing by the enemy should fail!!");
     } catch (YarnException e) {
       LOG.info("Got exception while killing app as the enemy", e);
-      Assert
-          .assertTrue(e.getMessage().contains(
-              "User enemy cannot perform operation MODIFY_APP on "
-                  + applicationId));
+      assertTrue(e.getMessage().contains(
+          "User enemy cannot perform operation MODIFY_APP on " + applicationId));
     }
 
     rmClient.forceKillApplication(finishAppRequest);
   }
 
   private void verifyEnemyAppReport(ApplicationReport appReport) {
-    Assert.assertEquals("Enemy should not see app host!",
-        UNAVAILABLE, appReport.getHost());
-    Assert.assertEquals("Enemy should not see app rpc port!",
-        -1, appReport.getRpcPort());
-    Assert.assertEquals("Enemy should not see app client token!",
-        null, appReport.getClientToAMToken());
-    Assert.assertEquals("Enemy should not see app diagnostics!",
-        UNAVAILABLE, appReport.getDiagnostics());
-    Assert.assertEquals("Enemy should not see app tracking url!",
-        UNAVAILABLE, appReport.getTrackingUrl());
-    Assert.assertEquals("Enemy should not see app original tracking url!",
-        UNAVAILABLE, appReport.getOriginalTrackingUrl());
+    assertEquals(UNAVAILABLE, appReport.getHost(), "Enemy should not see app host!");
+    assertEquals(-1, appReport.getRpcPort(), "Enemy should not see app rpc port!");
+    assertEquals(null, appReport.getClientToAMToken(),
+        "Enemy should not see app client token!");
+    assertEquals(UNAVAILABLE, appReport.getDiagnostics(),
+        "Enemy should not see app diagnostics!");
+    assertEquals(UNAVAILABLE, appReport.getTrackingUrl(),
+        "Enemy should not see app tracking url!");
+    assertEquals(UNAVAILABLE, appReport.getOriginalTrackingUrl(),
+        "Enemy should not see app original tracking url!");
     ApplicationResourceUsageReport usageReport =
         appReport.getApplicationResourceUsageReport();
-    Assert.assertEquals("Enemy should not see app used containers",
-        -1, usageReport.getNumUsedContainers());
-    Assert.assertEquals("Enemy should not see app reserved containers",
-        -1, usageReport.getNumReservedContainers());
-    Assert.assertEquals("Enemy should not see app used resources",
-        -1, usageReport.getUsedResources().getMemorySize());
-    Assert.assertEquals("Enemy should not see app reserved resources",
-        -1, usageReport.getReservedResources().getMemorySize());
-    Assert.assertEquals("Enemy should not see app needed resources",
-        -1, usageReport.getNeededResources().getMemorySize());
+    assertEquals(-1, usageReport.getNumUsedContainers(),
+        "Enemy should not see app used containers");
+    assertEquals(-1, usageReport.getNumReservedContainers(),
+        "Enemy should not see app reserved containers");
+    assertEquals(-1, usageReport.getUsedResources().getMemorySize(),
+        "Enemy should not see app used resources");
+    assertEquals(-1, usageReport.getReservedResources().getMemorySize(),
+        "Enemy should not see app reserved resources");
+    assertEquals(-1, usageReport.getNeededResources().getMemorySize(),
+        "Enemy should not see app needed resources");
   }
 
   private void verifyInvalidQueueWithAcl() throws Exception {
@@ -472,10 +472,10 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
     ApplicationReport appReport = applicationReport.getApplicationReport();
     if (conf.get(YarnConfiguration.RM_SCHEDULER)
         .equals(FairScheduler.class.getName())) {
-      Assert.assertTrue(appReport.getDiagnostics()
+      assertTrue(appReport.getDiagnostics()
           .contains("user owner application rejected by placement rules."));
     } else {
-      Assert.assertTrue(appReport.getDiagnostics()
+      assertTrue(appReport.getDiagnostics()
           .contains("submitted by user owner to unknown queue: InvalidQueue"));
     }
   }
@@ -502,10 +502,9 @@ public class TestApplicationACLs extends ParameterizedSchedulerTestBase {
     administerQueueUserRmClient.getApplicationReport(appReportRequest);
 
     // List apps as administerQueueUserRmClient
-    Assert.assertEquals("App view by queue-admin-user should list the apps!!",
-        5, administerQueueUserRmClient.getApplications(
-               recordFactory.newRecordInstance(GetApplicationsRequest.class))
-               .getApplicationList().size());
+    assertEquals(5, administerQueueUserRmClient.getApplications(
+        recordFactory.newRecordInstance(GetApplicationsRequest.class))
+        .getApplicationList().size(), "App view by queue-admin-user should list the apps!!");
 
     // Kill app as the administerQueueUserRmClient
     administerQueueUserRmClient.forceKillApplication(finishAppRequest);

+ 105 - 70
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java

@@ -22,7 +22,10 @@ import java.util.function.Supplier;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.yarn.event.DrainDispatcher;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler;
-import org.junit.Before;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.spy;
@@ -36,9 +39,11 @@ import java.util.Map;
 
 import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics;
-import org.junit.After;
-import org.junit.Assert;
 
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.event.Level;
@@ -76,7 +81,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptS
 import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
 import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM;
-import org.junit.Test;
 import org.mockito.ArgumentMatcher;
 
 @SuppressWarnings({"unchecked", "rawtypes"})
@@ -89,24 +93,26 @@ public class TestRM extends ParameterizedSchedulerTestBase {
 
   private YarnConfiguration conf;
 
-  public TestRM(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestRM(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
+    setup();
   }
 
-  @Before
   public void setup() {
     conf = getConf();
   }
 
-  @After
+  @AfterEach
   public void tearDown() {
     ClusterMetrics.destroy();
     QueueMetrics.clearQueueMetrics();
     DefaultMetricsSystem.shutdown();
   }
 
-  @Test
-  public void testGetNewAppId() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testGetNewAppId(SchedulerType type) throws Exception {
+    initTestRM(type);
     GenericTestUtils.setRootLogLevel(Level.DEBUG);
     MockRM rm = new MockRM(conf);
     rm.start();
@@ -116,9 +122,12 @@ public class TestRM extends ParameterizedSchedulerTestBase {
     assert (resp.getMaximumResourceCapability().getMemorySize() > 0);
     rm.stop();
   }
-  
-  @Test (timeout = 30000)
-  public void testAppWithNoContainers() throws Exception {
+
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(30)
+  public void testAppWithNoContainers(SchedulerType type) throws Exception {
+    initTestRM(type);
     GenericTestUtils.setRootLogLevel(Level.DEBUG);
     MockRM rm = new MockRM(conf);
     rm.start();
@@ -138,8 +147,11 @@ public class TestRM extends ParameterizedSchedulerTestBase {
     rm.stop();
   }
 
-  @Test (timeout = 30000)
-  public void testAppOnMultiNode() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(30)
+  public void testAppOnMultiNode(SchedulerType type) throws Exception {
+    initTestRM(type);
     GenericTestUtils.setRootLogLevel(Level.DEBUG);
     conf.set(CapacitySchedulerConfiguration.NODE_LOCALITY_DELAY, "-1");
     MockRM rm = new MockRM(conf);
@@ -172,7 +184,7 @@ public class TestRM extends ParameterizedSchedulerTestBase {
       LOG.info("Got " + contReceived + " containers. Waiting to get " + 3);
       Thread.sleep(WAIT_SLEEP_MS);
     }
-    Assert.assertEquals(3, conts.size());
+    assertEquals(3, conts.size());
 
     //send node2 heartbeat
     conts = am.allocate(new ArrayList<ResourceRequest>(),
@@ -186,7 +198,7 @@ public class TestRM extends ParameterizedSchedulerTestBase {
       LOG.info("Got " + contReceived + " containers. Waiting to get " + 10);
       Thread.sleep(WAIT_SLEEP_MS);
     }
-    Assert.assertEquals(10, conts.size());
+    assertEquals(10, conts.size());
 
     am.unregisterAppAttempt();
     nm1.nodeHeartbeat(attempt.getAppAttemptId(), 1, ContainerState.COMPLETE);
@@ -198,8 +210,11 @@ public class TestRM extends ParameterizedSchedulerTestBase {
   // Test even if AM container is allocated with containerId not equal to 1, the
   // following allocate requests from AM should be able to retrieve the
   // corresponding NM Token.
-  @Test (timeout = 20000)
-  public void testNMTokenSentForNormalContainer() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(20)
+  public void testNMTokenSentForNormalContainer(SchedulerType type) throws Exception {
+    initTestRM(type);
     MockRM rm = new MockRM(conf);
     rm.start();
     MockNM nm1 = rm.registerNode("h1:1234", 5120);
@@ -215,10 +230,10 @@ public class TestRM extends ParameterizedSchedulerTestBase {
 
     MockAM am = MockRM.launchAM(app, rm, nm1);
     // am container Id not equal to 1.
-    Assert.assertTrue(
+    assertTrue(
         attempt.getMasterContainer().getId().getContainerId() != 1);
     // NMSecretManager doesn't record the node on which the am is allocated.
-    Assert.assertFalse(rm.getRMContext().getNMTokenSecretManager()
+    assertFalse(rm.getRMContext().getNMTokenSecretManager()
       .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(),
         nm1.getNodeId()));
     am.registerAppAttempt();
@@ -245,11 +260,15 @@ public class TestRM extends ParameterizedSchedulerTestBase {
     }
     NodeId nodeId = expectedNMTokens.get(0).getNodeId();
     // NMToken is sent for the allocated container.
-    Assert.assertEquals(nm1.getNodeId(), nodeId);
+    assertEquals(nm1.getNodeId(), nodeId);
   }
 
-  @Test (timeout = 40000)
-  public void testNMToken() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(40)
+  @SuppressWarnings("checkstyle:MethodLength")
+  public void testNMToken(SchedulerType type) throws Exception {
+    initTestRM(type);
     MockRM rm = new MockRM(conf);
     try {
       rm.start();
@@ -270,7 +289,7 @@ public class TestRM extends ParameterizedSchedulerTestBase {
 
       MockAM am = rm.sendAMLaunched(attempt.getAppAttemptId());
 
-      Assert.assertTrue(nmTokenSecretManager
+      assertTrue(nmTokenSecretManager
           .isApplicationAttemptRegistered(attempt.getAppAttemptId()));
       
       // This will register application master.
@@ -285,18 +304,18 @@ public class TestRM extends ParameterizedSchedulerTestBase {
       // initially requesting 2 containers.
       AllocateResponse response =
           am.allocate("h1", 1000, 2, releaseContainerList);
-      Assert.assertEquals(0, response.getAllocatedContainers().size());
+      assertEquals(0, response.getAllocatedContainers().size());
       allocateContainersAndValidateNMTokens(am, containersReceivedForNM1, 2,
           nmTokens, nm1);
-      Assert.assertEquals(1, nmTokens.size());
+      assertEquals(1, nmTokens.size());
 
       
       // requesting 2 more containers.
       response = am.allocate("h1", 1000, 2, releaseContainerList);
-      Assert.assertEquals(0, response.getAllocatedContainers().size());
+      assertEquals(0, response.getAllocatedContainers().size());
       allocateContainersAndValidateNMTokens(am, containersReceivedForNM1, 4,
           nmTokens, nm1);
-      Assert.assertEquals(1, nmTokens.size());
+      assertEquals(1, nmTokens.size());
       
       
       // We will be simulating NM restart so restarting newly added h2:1234
@@ -307,10 +326,10 @@ public class TestRM extends ParameterizedSchedulerTestBase {
           new ArrayList<Container>();
       
       response = am.allocate("h2", 1000, 2, releaseContainerList);
-      Assert.assertEquals(0, response.getAllocatedContainers().size());
+      assertEquals(0, response.getAllocatedContainers().size());
       allocateContainersAndValidateNMTokens(am, containersReceivedForNM2, 2,
           nmTokens, nm2);
-      Assert.assertEquals(2, nmTokens.size());
+      assertEquals(2, nmTokens.size());
       
       // Simulating NM-2 restart.
       nm2 = rm.registerNode("h2:1234", 10000);
@@ -329,57 +348,57 @@ public class TestRM extends ParameterizedSchedulerTestBase {
         LOG.info("waiting for nmToken to be cleared for : " + nm2.getNodeId());
         Thread.sleep(WAIT_SLEEP_MS);
       }
-      Assert.assertTrue(nmTokenSecretManager
+      assertTrue(nmTokenSecretManager
           .isApplicationAttemptRegistered(attempt.getAppAttemptId()));
       
       // removing NMToken for h2:1234
       nmTokens.remove(nm2.getNodeId().toString());
-      Assert.assertEquals(1, nmTokens.size());
+      assertEquals(1, nmTokens.size());
       
       // We should again receive the NMToken.
       response = am.allocate("h2", 1000, 2, releaseContainerList);
-      Assert.assertEquals(0, response.getAllocatedContainers().size());
+      assertEquals(0, response.getAllocatedContainers().size());
       allocateContainersAndValidateNMTokens(am, containersReceivedForNM2, 4,
           nmTokens, nm2);
-      Assert.assertEquals(2, nmTokens.size());
+      assertEquals(2, nmTokens.size());
 
       // Now rolling over NMToken masterKey. it should resend the NMToken in
       // next allocate call.
-      Assert.assertTrue(nmTokenSecretManager
+      assertTrue(nmTokenSecretManager
           .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(),
               nm1.getNodeId()));
-      Assert.assertTrue(nmTokenSecretManager
+      assertTrue(nmTokenSecretManager
           .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(),
               nm2.getNodeId()));
       
       nmTokenSecretManager.rollMasterKey();
       nmTokenSecretManager.activateNextMasterKey();
       
-      Assert.assertFalse(nmTokenSecretManager
+      assertFalse(nmTokenSecretManager
           .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(),
               nm1.getNodeId()));
-      Assert.assertFalse(nmTokenSecretManager
+      assertFalse(nmTokenSecretManager
           .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(),
               nm2.getNodeId()));
       // It should not remove application attempt entry.
-      Assert.assertTrue(nmTokenSecretManager
+      assertTrue(nmTokenSecretManager
           .isApplicationAttemptRegistered(attempt.getAppAttemptId()));
 
       nmTokens.clear();
-      Assert.assertEquals(0, nmTokens.size());
+      assertEquals(0, nmTokens.size());
       // We should again receive the NMToken.
       response = am.allocate("h2", 1000, 1, releaseContainerList);
-      Assert.assertEquals(0, response.getAllocatedContainers().size());
+      assertEquals(0, response.getAllocatedContainers().size());
       allocateContainersAndValidateNMTokens(am, containersReceivedForNM2, 5,
           nmTokens, nm2);
-      Assert.assertEquals(1, nmTokens.size());
-      Assert.assertTrue(nmTokenSecretManager
+      assertEquals(1, nmTokens.size());
+      assertTrue(nmTokenSecretManager
           .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(),
               nm2.getNodeId()));
       
       
       // After AM is finished making sure that nmtoken entry for app
-      Assert.assertTrue(nmTokenSecretManager
+      assertTrue(nmTokenSecretManager
           .isApplicationAttemptRegistered(attempt.getAppAttemptId()));
       am.unregisterAppAttempt();
       // marking all the containers as finished.
@@ -396,7 +415,7 @@ public class TestRM extends ParameterizedSchedulerTestBase {
       nm1.nodeHeartbeat(am.getApplicationAttemptId(), 1,
         ContainerState.COMPLETE);
       rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.FINISHED);
-      Assert.assertFalse(nmTokenSecretManager
+      assertFalse(nmTokenSecretManager
           .isApplicationAttemptRegistered(attempt.getAppAttemptId()));
     } finally {
       rm.stop();
@@ -421,7 +440,7 @@ public class TestRM extends ParameterizedSchedulerTestBase {
         for (NMToken nmToken : response.getNMTokens()) {
           String nodeId = nmToken.getNodeId().toString();
           if (nmTokens.containsKey(nodeId)) {
-            Assert.fail("Duplicate NMToken received for : " + nodeId);
+            fail("Duplicate NMToken received for : " + nodeId);
           }
           nmTokens.put(nodeId, nmToken.getToken());
         }
@@ -432,8 +451,11 @@ public class TestRM extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test (timeout = 300000)
-  public void testActivatingApplicationAfterAddingNM() throws Exception {
+  @Timeout(300)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testActivatingApplicationAfterAddingNM(SchedulerType type) throws Exception {
+    initTestRM(type);
     MockRM rm1 = new MockRM(conf);
 
     // start like normal because state is empty
@@ -477,8 +499,11 @@ public class TestRM extends ParameterizedSchedulerTestBase {
 
   // This is to test AM Host and rpc port are invalidated after the am attempt
   // is killed or failed, so that client doesn't get the wrong information.
-  @Test (timeout = 80000)
-  public void testInvalidateAMHostPortWhenAMFailedOrKilled() throws Exception {
+  @Timeout(80)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testInvalidateAMHostPortWhenAMFailedOrKilled(SchedulerType type) throws Exception {
+    initTestRM(type);
     conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
     MockRM rm1 = new MockRM(conf);
     rm1.start();
@@ -513,24 +538,27 @@ public class TestRM extends ParameterizedSchedulerTestBase {
         rm1.getClientRMService().getApplications(request1);
     List<ApplicationReport> appList1 = response1.getApplicationList();
 
-    Assert.assertEquals(3, appList1.size());
+    assertEquals(3, appList1.size());
     for (ApplicationReport report : appList1) {
       // killed/failed apps host and rpc port are invalidated.
       if (report.getApplicationId().equals(app2.getApplicationId())
           || report.getApplicationId().equals(app3.getApplicationId())) {
-        Assert.assertEquals("N/A", report.getHost());
-        Assert.assertEquals(-1, report.getRpcPort());
+        assertEquals("N/A", report.getHost());
+        assertEquals(-1, report.getRpcPort());
       }
       // succeeded app's host and rpc port is not invalidated
       if (report.getApplicationId().equals(app1.getApplicationId())) {
-        Assert.assertFalse(report.getHost().equals("N/A"));
-        Assert.assertTrue(report.getRpcPort() != -1);
+        assertFalse(report.getHost().equals("N/A"));
+        assertTrue(report.getRpcPort() != -1);
       }
     }
   }
 
-  @Test (timeout = 60000)
-  public void testInvalidatedAMHostPortOnAMRestart() throws Exception {
+  @Timeout(60)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testInvalidatedAMHostPortOnAMRestart(SchedulerType type) throws Exception {
+    initTestRM(type);
     MockRM rm1 = new MockRM(conf);
     rm1.start();
     MockNM nm1 =
@@ -552,17 +580,19 @@ public class TestRM extends ParameterizedSchedulerTestBase {
     ApplicationReport report1 =
         rm1.getClientRMService().getApplicationReport(request1)
           .getApplicationReport();
-    Assert.assertEquals("N/A", report1.getHost());
-    Assert.assertEquals(-1, report1.getRpcPort());
+    assertEquals("N/A", report1.getHost());
+    assertEquals(-1, report1.getRpcPort());
   }
 
   /**
    * Validate killing an application when it is at accepted state.
    * @throws Exception exception
    */
-  @Test (timeout = 60000)
-  public void testApplicationKillAtAcceptedState() throws Exception {
-
+  @Timeout(60)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testApplicationKillAtAcceptedState(SchedulerType type) throws Exception {
+    initTestRM(type);
     final Dispatcher dispatcher = new DrainDispatcher() {
       @Override
       public EventHandler<Event> getEventHandler() {
@@ -641,13 +671,16 @@ public class TestRM extends ParameterizedSchedulerTestBase {
             && appsSubmitted + 1 == metrics.getAppsSubmitted();
       }
     }, 100, 10000);
-    Assert.assertEquals(appsKilled + 1, metrics.getAppsKilled());
-    Assert.assertEquals(appsSubmitted + 1, metrics.getAppsSubmitted());
+    assertEquals(appsKilled + 1, metrics.getAppsKilled());
+    assertEquals(appsSubmitted + 1, metrics.getAppsSubmitted());
   }
 
   // Test Kill an app while the app is finishing in the meanwhile.
-  @Test (timeout = 30000)
-  public void testKillFinishingApp() throws Exception{
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testKillFinishingApp(SchedulerType type) throws Exception {
+    initTestRM(type);
 
     // this dispatcher ignores RMAppAttemptEventType.KILL event
     final Dispatcher dispatcher = new DrainDispatcher() {
@@ -700,9 +733,11 @@ public class TestRM extends ParameterizedSchedulerTestBase {
   }
 
   // Test Kill an app while the app is failing
-  @Test (timeout = 30000)
-  public void testKillFailingApp() throws Exception{
-
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testKillFailingApp(SchedulerType type) throws Exception{
+    initTestRM(type);
     // this dispatcher ignores RMAppAttemptEventType.KILL event
     final Dispatcher dispatcher = new DrainDispatcher() {
       @Override

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 236 - 181
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java


+ 178 - 97
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java

@@ -87,11 +87,10 @@ import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.ResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.Resources;
 import org.slf4j.event.Level;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import java.io.File;
 import java.io.IOException;
 import java.net.UnknownHostException;
@@ -110,7 +109,12 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler
     .capacity.TestCapacitySchedulerAutoCreatedQueueBase.USER1;
 import static org.apache.hadoop.yarn.server.resourcemanager.webapp
     .RMWebServices.DEFAULT_QUEUE;
-import static org.junit.Assert.*;
+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;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -123,11 +127,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   MockRM rm1 = null;
   MockRM rm2 = null;
 
-  public TestWorkPreservingRMRestart(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestWorkPreservingRMRestart(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
+    setup();
   }
 
-  @Before
   public void setup() throws UnknownHostException {
     GenericTestUtils.setRootLogLevel(Level.DEBUG);
     conf = getConf();
@@ -139,7 +143,7 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     DefaultMetricsSystem.setMiniClusterMode(true);
   }
 
-  @After
+  @AfterEach
   public void tearDown() {
     if (rm1 != null) {
       rm1.stop();
@@ -158,8 +162,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   // Test Strategy: send 3 container recovery reports(AMContainer, running
   // container, completed container) on NM re-registration, check the states of
   // SchedulerAttempt, SchedulerNode etc. are updated accordingly.
-  @Test(timeout = 20000)
-  public void testSchedulerRecovery() throws Exception {
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testSchedulerRecovery(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.setBoolean(CapacitySchedulerConfiguration.ENABLE_USER_METRICS, true);
     conf.set(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS,
       DominantResourceCalculator.class.getName());
@@ -218,14 +225,13 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     AbstractYarnScheduler scheduler =
         (AbstractYarnScheduler) rm2.getResourceScheduler();
     SchedulerNode schedulerNode1 = scheduler.getSchedulerNode(nm1.getNodeId());
+    assertTrue(schedulerNode1
+        .toString().contains(schedulerNode1.getUnallocatedResource().toString()),
+        "SchedulerNode#toString is not in expected format");
     assertTrue(
-        "SchedulerNode#toString is not in expected format",
-        schedulerNode1
-        .toString().contains(schedulerNode1.getUnallocatedResource().toString()));
-    assertTrue(
-        "SchedulerNode#toString is not in expected format",
         schedulerNode1
-        .toString().contains(schedulerNode1.getAllocatedResource().toString()));
+        .toString().contains(schedulerNode1.getAllocatedResource().toString()),
+        "SchedulerNode#toString is not in expected format");
 
     // ********* check scheduler node state.*******
     // 2 running containers.
@@ -322,8 +328,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   // 5. Check if all running containers are recovered,
   // 6. Verify the scheduler state like attempt info,
   // 7. Verify the queue/user metrics for the dynamic reservable queue.
-  @Test(timeout = 30000)
-  public void testDynamicQueueRecovery() throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testDynamicQueueRecovery(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.setBoolean(CapacitySchedulerConfiguration.ENABLE_USER_METRICS, true);
     conf.set(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS,
         DominantResourceCalculator.class.getName());
@@ -512,7 +521,7 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
       }
       retry++;
       if (retry > 30) {
-        Assert.fail("Apps are not scheduled within assumed timeout");
+        fail("Apps are not scheduled within assumed timeout");
       }
     }
 
@@ -622,8 +631,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   // 1. submit an app to default queue and let it finish
   // 2. restart rm with no default queue
   // 3. getApplicationReport call should succeed (with no NPE)
-  @Test (timeout = 30000)
-  public void testRMRestartWithRemovedQueue() throws Exception{
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testRMRestartWithRemovedQueue(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
     conf.set(YarnConfiguration.YARN_ADMIN_ACL, "");
     rm1 = new MockRM(conf);
@@ -659,7 +671,7 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
             return rm2.getApplicationReport(app1.getApplicationId());
           }
     });
-    Assert.assertNotNull(report);
+    assertNotNull(report);
   }
 
   // Test CS recovery with multi-level queues and multi-users:
@@ -673,8 +685,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   // 8. nm2 re-syncs back containers belong to user2.
   // 9. Assert the parent queue and 2 leaf queues state and the metrics.
   // 10. Assert each user's consumption inside the queue.
-  @Test (timeout = 30000)
-  public void testCapacitySchedulerRecovery() throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testCapacitySchedulerRecovery(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     if (getSchedulerType() != SchedulerType.CAPACITY) {
       return;
     }
@@ -852,7 +867,7 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     MockRM rm = new MockRM(csConf, memStore2);
     try {
       rm.start();
-      Assert.fail("QueueException must have been thrown");
+      fail("QueueException must have been thrown");
     } catch (QueueInvalidException e) {
     } finally {
       rm.close();
@@ -866,8 +881,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   //   fail fast config as false and once with fail fast as true.
   //3. Verify that app was killed if fail fast is false.
   //4. Verify that QueueException was thrown if fail fast is true.
-  @Test (timeout = 30000)
-  public void testCapacityLeafQueueBecomesParentOnRecovery() throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testCapacityLeafQueueBecomesParentOnRecovery(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     if (getSchedulerType() != SchedulerType.CAPACITY) {
       return;
     }
@@ -922,8 +940,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   //   false and once with fail fast as true.
   //3. Verify that app was killed if fail fast is false.
   //4. Verify that QueueException was thrown if fail fast is true.
-  @Test (timeout = 30000)
-  public void testCapacitySchedulerQueueRemovedRecovery() throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testCapacitySchedulerQueueRemovedRecovery(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     if (getSchedulerType() != SchedulerType.CAPACITY) {
       return;
     }
@@ -1016,8 +1037,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
 
   // Test RM shuts down, in the meanwhile, AM fails. Restarted RM scheduler
   // should not recover the containers that belong to the failed AM.
-  @Test(timeout = 20000)
-  public void testAMfailedBetweenRMRestart() throws Exception {
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAMfailedBetweenRMRestart(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.setLong(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_SCHEDULING_WAIT_MS, 0);
     rm1 = new MockRM(conf);
     rm1.start();
@@ -1068,8 +1092,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
 
   // Apps already completed before RM restart. Restarted RM scheduler should not
   // recover containers for completed apps.
-  @Test(timeout = 20000)
-  public void testContainersNotRecoveredForCompletedApps() throws Exception {
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testContainersNotRecoveredForCompletedApps(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     rm1 = new MockRM(conf);
     rm1.start();
     MockMemoryRMStateStore memStore =
@@ -1105,8 +1132,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     assertNull(scheduler.getRMContainer(completedContainer.getContainerId()));
   }
 
-  @Test (timeout = 600000)
-  public void testAppReregisterOnRMWorkPreservingRestart() throws Exception {
+  @Timeout(600)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAppReregisterOnRMWorkPreservingRestart(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
 
     // start RM
@@ -1136,9 +1166,12 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     rm2.waitForState(app0.getApplicationId(), RMAppState.RUNNING);
     rm2.waitForState(am0.getApplicationAttemptId(), RMAppAttemptState.RUNNING);
   }
-  
-  @Test (timeout = 30000)
-  public void testAMContainerStatusWithRMRestart() throws Exception {  
+
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAMContainerStatusWithRMRestart(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     rm1 = new MockRM(conf);
     rm1.start();
     MockNM nm1 =
@@ -1150,7 +1183,7 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     RMAppAttempt attempt0 = app1_1.getCurrentAppAttempt();
     YarnScheduler scheduler = rm1.getResourceScheduler();
 
-    Assert.assertTrue(scheduler.getRMContainer(
+    assertTrue(scheduler.getRMContainer(
         attempt0.getMasterContainer().getId()).isAMContainer());
 
     // Re-start RM
@@ -1166,12 +1199,15 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     waitForNumContainersToRecover(2, rm2, am1_1.getApplicationAttemptId());
 
     scheduler = rm2.getResourceScheduler();
-    Assert.assertTrue(scheduler.getRMContainer(
+    assertTrue(scheduler.getRMContainer(
         attempt0.getMasterContainer().getId()).isAMContainer());
   }
 
-  @Test (timeout = 20000)
-  public void testRecoverSchedulerAppAndAttemptSynchronously() throws Exception {
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testRecoverSchedulerAppAndAttemptSynchronously(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     // start RM
     rm1 = new MockRM(conf);
     rm1.start();
@@ -1187,7 +1223,7 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     rm2.start();
     nm1.setResourceTrackerService(rm2.getResourceTrackerService());
     // scheduler app/attempt is immediately available after RM is re-started.
-    Assert.assertNotNull(rm2.getResourceScheduler().getSchedulerAppInfo(
+    assertNotNull(rm2.getResourceScheduler().getSchedulerAppInfo(
       am0.getApplicationAttemptId()));
 
     // getTransferredContainers should not throw NPE.
@@ -1202,8 +1238,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   // Test if RM on recovery receives the container release request from AM
   // before it receives the container status reported by NM for recovery. this
   // container should not be recovered.
-  @Test (timeout = 50000)
-  public void testReleasedContainerNotRecovered() throws Exception {
+  @Timeout(50)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testReleasedContainerNotRecovered(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     rm1 = new MockRM(conf);
     MockNM nm1 = new MockNM("h1:1234", 15120, rm1.getResourceTrackerService());
     nm1.registerNode();
@@ -1295,9 +1334,12 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     }
   }
 
-  @Test (timeout = 20000)
-  public void testNewContainersNotAllocatedDuringSchedulerRecovery()
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testNewContainersNotAllocatedDuringSchedulerRecovery(SchedulerType type)
       throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.setLong(
       YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_SCHEDULING_WAIT_MS, 4000);
     rm1 = new MockRM(conf);
@@ -1332,7 +1374,7 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     containers.addAll(am1.allocate(new ArrayList<ResourceRequest>(),
       new ArrayList<ContainerId>()).getAllocatedContainers());
     // container is not allocated during scheduling recovery.
-    Assert.assertTrue(containers.isEmpty());
+    assertTrue(containers.isEmpty());
 
     clock.setTime(startTime + 8000);
     nm1.nodeHeartbeat(true);
@@ -1348,9 +1390,12 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
    * Testing to confirm that retried finishApplicationMaster() doesn't throw
    * InvalidApplicationMasterRequest before and after RM restart.
    */
-  @Test (timeout = 20000)
-  public void testRetriedFinishApplicationMasterRequest()
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testRetriedFinishApplicationMasterRequest(SchedulerType type)
       throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
     // start RM
     rm1 = new MockRM(conf);
@@ -1383,8 +1428,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     am0.unregisterAppAttempt(false);
   }
 
-  @Test (timeout = 30000)
-  public void testAppFailedToRenewTokenOnRecovery() throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAppFailedToRenewTokenOnRecovery(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
       "kerberos");
     conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
@@ -1432,8 +1480,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
    * Test validateAndCreateResourceRequest fails on recovery, app should ignore
    * this Exception and continue
    */
-  @Test (timeout = 30000)
-  public void testAppFailToValidateResourceRequestOnRecovery() throws Exception{
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAppFailToValidateResourceRequestOnRecovery(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     rm1 = new MockRM(conf);
     rm1.start();
     MockNM nm1 =
@@ -1452,8 +1503,12 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     rm2.start();
   }
 
-  @Test(timeout = 20000)
-  public void testContainerCompleteMsgNotLostAfterAMFailedAndRMRestart() throws Exception {
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testContainerCompleteMsgNotLostAfterAMFailedAndRMRestart(SchedulerType type)
+      throws Exception {
+    initTestWorkPreservingRMRestart(type);
     rm1 = new MockRM(conf);
     rm1.start();
 
@@ -1516,8 +1571,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
 
   // Test that if application state was saved, but attempt state was not saved.
   // RM should start correctly.
-  @Test (timeout = 20000)
-  public void testAppStateSavedButAttemptStateNotSaved() throws Exception {
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAppStateSavedButAttemptStateNotSaved(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     MockMemoryRMStateStore memStore = new MockMemoryRMStateStore() {
       @Override public synchronized void updateApplicationAttemptStateInternal(
           ApplicationAttemptId appAttemptId,
@@ -1555,8 +1613,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     assertEquals(RMAppAttemptState.FINISHED, recoveredApp1.getCurrentAppAttempt().getState());
   }
 
-  @Test(timeout = 600000)
-  public void testUAMRecoveryOnRMWorkPreservingRestart() throws Exception {
+  @Timeout(600)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testUAMRecoveryOnRMWorkPreservingRestart(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
 
     // start RM
@@ -1635,18 +1696,18 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
         schedulerApps.get(recoveredApp.getApplicationId());
     SchedulerApplicationAttempt schedulerAttempt =
         schedulerApp.getCurrentAppAttempt();
-    Assert.assertEquals(numContainers,
+    assertEquals(numContainers,
         schedulerAttempt.getLiveContainers().size());
 
     // Check if UAM is able to heart beat
-    Assert.assertNotNull(am0.doHeartbeat());
+    assertNotNull(am0.doHeartbeat());
     assertUnmanagedAMQueueMetrics(qm2, 1, 0, 1, 0);
 
     // Complete the UAM
     am0.unregisterAppAttempt(false);
     rm2.waitForState(am0.getApplicationAttemptId(), RMAppAttemptState.FINISHED);
     rm2.waitForState(app0.getApplicationId(), RMAppState.FINISHED);
-    Assert.assertEquals(FinalApplicationStatus.SUCCEEDED,
+    assertEquals(FinalApplicationStatus.SUCCEEDED,
         recoveredApp.getFinalApplicationStatus());
     assertUnmanagedAMQueueMetrics(qm2, 1, 0, 0, 1);
 
@@ -1655,7 +1716,7 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     rm3.start();
     recoveredApp = rm3.getRMContext().getRMApps().get(app0.getApplicationId());
     QueueMetrics qm3 = rm3.getResourceScheduler().getRootQueueMetrics();
-    Assert.assertEquals(RMAppState.FINISHED, recoveredApp.getState());
+    assertEquals(RMAppState.FINISHED, recoveredApp.getState());
     assertUnmanagedAMQueueMetrics(qm2, 1, 0, 0, 1);
   }
 
@@ -1666,8 +1727,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
   //2. While the applications is running, restart the rm and
   //   check whether the app submitted to the queue it was submitted initially.
   //3. Verify that application running successfully.
-  @Test(timeout = 60000)
-  public void testQueueRecoveryOnRMWorkPreservingRestart() throws Exception {
+  @Timeout(60)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testQueueRecoveryOnRMWorkPreservingRestart(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     if (getSchedulerType() != SchedulerType.CAPACITY) {
       return;
     }
@@ -1742,21 +1806,23 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     am.registerAppAttempt(true);
     rm2.waitForState(recoveredApp0.getApplicationId(), RMAppState.RUNNING);
 
-    Assert.assertEquals("root.joe.test", recoveredApp0.getQueue());
+    assertEquals("root.joe.test", recoveredApp0.getQueue());
   }
 
   private void assertUnmanagedAMQueueMetrics(QueueMetrics qm, int appsSubmitted,
       int appsPending, int appsRunning, int appsCompleted) {
-    Assert.assertEquals(appsSubmitted, qm.getUnmanagedAppsSubmitted());
-    Assert.assertEquals(appsPending, qm.getUnmanagedAppsPending());
-    Assert.assertEquals(appsRunning, qm.getUnmanagedAppsRunning());
-    Assert.assertEquals(appsCompleted, qm.getUnmanagedAppsCompleted());
+    assertEquals(appsSubmitted, qm.getUnmanagedAppsSubmitted());
+    assertEquals(appsPending, qm.getUnmanagedAppsPending());
+    assertEquals(appsRunning, qm.getUnmanagedAppsRunning());
+    assertEquals(appsCompleted, qm.getUnmanagedAppsCompleted());
   }
 
 
-  @Test(timeout = 30000)
-  public void testUnknownUserOnRecovery() throws Exception {
-
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testUnknownUserOnRecovery(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     MockRM rm1 = new MockRM(conf);
     rm1.start();
     MockMemoryRMStateStore memStore =
@@ -1797,32 +1863,44 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     rm2.start();
     RMApp recoveredApp =
         rm2.getRMContext().getRMApps().get(app0.getApplicationId());
-    Assert.assertEquals(RMAppState.KILLED, recoveredApp.getState());
+    assertEquals(RMAppState.KILLED, recoveredApp.getState());
   }
 
-  @Test(timeout = 30000)
-  public void testDynamicFlexibleAutoCreatedQueueRecoveryWithDefaultQueue()
-          throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testDynamicFlexibleAutoCreatedQueueRecoveryWithDefaultQueue(
+      SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     //if queue name is not specified, it should submit to 'default' queue
     testDynamicAutoCreatedQueueRecovery(USER1, null, true);
   }
 
-  @Test(timeout = 30000)
-  public void testDynamicAutoCreatedQueueRecoveryWithDefaultQueue()
-      throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testDynamicAutoCreatedQueueRecoveryWithDefaultQueue(
+      SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     //if queue name is not specified, it should submit to 'default' queue
     testDynamicAutoCreatedQueueRecovery(USER1, null, false);
   }
 
-  @Test(timeout = 30000)
-  public void testDynamicFlexibleAutoCreatedQueueRecoveryWithOverrideQueueMappingFlag()
-          throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testDynamicFlexibleAutoCreatedQueueRecoveryWithOverrideQueueMappingFlag(
+      SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     testDynamicAutoCreatedQueueRecovery(USER1, USER1, true);
   }
 
-  @Test(timeout = 30000)
-  public void testDynamicAutoCreatedQueueRecoveryWithOverrideQueueMappingFlag()
-      throws Exception {
+  @Timeout(30)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testDynamicAutoCreatedQueueRecoveryWithOverrideQueueMappingFlag(
+      SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     testDynamicAutoCreatedQueueRecovery(USER1, USER1, false);
   }
 
@@ -1962,8 +2040,11 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
 
   // Apps already completed before RM restart. Make sure we restore the queue
   // correctly
-  @Test(timeout = 20000)
-  public void testFairSchedulerCompletedAppsQueue() throws Exception {
+  @Timeout(20)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testFairSchedulerCompletedAppsQueue(SchedulerType type) throws Exception {
+    initTestWorkPreservingRMRestart(type);
     if (getSchedulerType() != SchedulerType.FAIR) {
       return;
     }
@@ -1979,10 +2060,10 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
 
     String fsQueueContext = app.getApplicationSubmissionContext().getQueue();
     String fsQueueApp = app.getQueue();
-    assertEquals("Queue in app not equal to submission context", fsQueueApp,
-        fsQueueContext);
+    assertEquals(fsQueueApp,
+        fsQueueContext, "Queue in app not equal to submission context");
     RMAppAttempt rmAttempt = app.getCurrentAppAttempt();
-    assertNotNull("No AppAttempt found", rmAttempt);
+    assertNotNull(rmAttempt, "No AppAttempt found");
 
     rm2 = new MockRM(conf, rm1.getRMStateStore());
     rm2.start();
@@ -1990,12 +2071,12 @@ public class TestWorkPreservingRMRestart extends ParameterizedSchedulerTestBase
     RMApp recoveredApp =
         rm2.getRMContext().getRMApps().get(app.getApplicationId());
     RMAppAttempt rmAttemptRecovered = recoveredApp.getCurrentAppAttempt();
-    assertNotNull("No AppAttempt found after recovery", rmAttemptRecovered);
+    assertNotNull(rmAttemptRecovered, "No AppAttempt found after recovery");
     String fsQueueContextRecovered =
         recoveredApp.getApplicationSubmissionContext().getQueue();
     String fsQueueAppRecovered = recoveredApp.getQueue();
     assertEquals(RMAppState.FINISHED, recoveredApp.getState());
-    assertEquals("Recovered app queue is not the same as context queue",
-        fsQueueAppRecovered, fsQueueContextRecovered);
+    assertEquals(fsQueueAppRecovered, fsQueueContextRecovered,
+        "Recovered app queue is not the same as context queue");
   }
 }

+ 42 - 25
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingUnmanagedAM.java

@@ -18,6 +18,9 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -39,9 +42,9 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.exceptions.InvalidApplicationMasterRequestException;
 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
 import org.slf4j.event.Level;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 /**
  * Test UAM handling in RM.
@@ -51,11 +54,11 @@ public class TestWorkPreservingUnmanagedAM
 
   private YarnConfiguration conf;
 
-  public TestWorkPreservingUnmanagedAM(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestWorkPreservingUnmanagedAM(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
+    setup();
   }
 
-  @Before
   public void setup() {
     GenericTestUtils.setRootLogLevel(Level.DEBUG);
     conf = getConf();
@@ -142,15 +145,15 @@ public class TestWorkPreservingUnmanagedAM
       response.getNMTokensFromPreviousAttempts()
           .forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
     } catch (InvalidApplicationMasterRequestException e) {
-      Assert.assertEquals(false, keepContainers);
+      assertEquals(false, keepContainers);
       return;
     }
-    Assert.assertEquals("RM should not allow second register"
-        + " for UAM without keep container flag ", true, keepContainers);
+    assertEquals(true, keepContainers, "RM should not allow second register"
+        + " for UAM without keep container flag ");
 
     // Expecting the two running containers previously
-    Assert.assertEquals(2, response.getContainersFromPreviousAttempts().size());
-    Assert.assertEquals(1, response.getNMTokensFromPreviousAttempts().size());
+    assertEquals(2, response.getContainersFromPreviousAttempts().size());
+    assertEquals(1, response.getNMTokensFromPreviousAttempts().size());
 
     // Allocate one more containers to UAM, just to be safe
     numContainers = 1;
@@ -248,15 +251,15 @@ public class TestWorkPreservingUnmanagedAM
       response.getNMTokensFromPreviousAttempts()
           .forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
     } catch (InvalidApplicationMasterRequestException e) {
-      Assert.assertEquals(false, keepContainers);
+      assertEquals(false, keepContainers);
       return;
     }
-    Assert.assertEquals("RM should not allow second register"
-        + " for UAM without keep container flag ", true, keepContainers);
+    assertEquals(true, keepContainers, "RM should not allow second register"
+        + " for UAM without keep container flag ");
 
     // Expecting the zero running containers previously
-    Assert.assertEquals(0, response.getContainersFromPreviousAttempts().size());
-    Assert.assertEquals(0, response.getNMTokensFromPreviousAttempts().size());
+    assertEquals(0, response.getContainersFromPreviousAttempts().size());
+    assertEquals(0, response.getNMTokensFromPreviousAttempts().size());
 
     // Allocate one more containers to UAM, just to be safe
     numContainers = 1;
@@ -278,29 +281,43 @@ public class TestWorkPreservingUnmanagedAM
     rm.stop();
   }
 
-  @Test(timeout = 600000)
-  public void testUAMRestartKeepContainers() throws Exception {
+  @Timeout(value = 600)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testUAMRestartKeepContainers(SchedulerType type) throws Exception {
+    initTestWorkPreservingUnmanagedAM(type);
     testUAMRestart(true);
   }
 
-  @Test(timeout = 600000)
-  public void testUAMRestartNoKeepContainers() throws Exception {
+  @Timeout(value = 600)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testUAMRestartNoKeepContainers(SchedulerType type) throws Exception {
+    initTestWorkPreservingUnmanagedAM(type);
     testUAMRestart(false);
   }
 
-  @Test(timeout = 600000)
-  public void testUAMRestartKeepContainersWithoutTransferContainer() throws Exception {
+  @Timeout(value = 600)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testUAMRestartKeepContainersWithoutTransferContainer(
+      SchedulerType type) throws Exception {
+    initTestWorkPreservingUnmanagedAM(type);
     testUAMRestartWithoutTransferContainer(true);
   }
 
-  @Test(timeout = 600000)
-  public void testUAMRestartNoKeepContainersWithoutTransferContainer() throws Exception {
+  @Timeout(value = 600)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testUAMRestartNoKeepContainersWithoutTransferContainer(
+      SchedulerType type) throws Exception {
+    initTestWorkPreservingUnmanagedAM(type);
     testUAMRestartWithoutTransferContainer(false);
   }
 
   private void checkNMTokenForContainer(Set<NodeId> cacheToken, List<Container> containers) {
     for (Container container : containers) {
-      Assert.assertTrue(cacheToken.contains(container.getNodeId()));
+      assertTrue(cacheToken.contains(container.getNodeId()));
     }
   }
 }

+ 44 - 40
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ahs/TestRMApplicationHistoryWriter.java

@@ -18,6 +18,11 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.ahs;
 
+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;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -28,7 +33,6 @@ import java.util.Map;
 import java.util.Random;
 
 import org.apache.hadoop.yarn.server.resourcemanager.MockRMAppSubmitter;
-import org.junit.Assert;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
@@ -64,9 +68,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 public class TestRMApplicationHistoryWriter {
 
@@ -77,7 +81,7 @@ public class TestRMApplicationHistoryWriter {
   private List<CounterDispatcher> dispatchers =
       new ArrayList<CounterDispatcher>();
 
-  @Before
+  @BeforeEach
   public void setup() {
     store = new MemoryApplicationHistoryStore();
     Configuration conf = new Configuration();
@@ -124,7 +128,7 @@ public class TestRMApplicationHistoryWriter {
     writer.start();
   }
 
-  @After
+  @AfterEach
   public void tearDown() {
     writer.stop();
   }
@@ -188,8 +192,8 @@ public class TestRMApplicationHistoryWriter {
     writer.init(conf);
     writer.start();
     try {
-      Assert.assertFalse(writer.historyServiceEnabled);
-      Assert.assertNull(writer.writer);
+      assertFalse(writer.historyServiceEnabled);
+      assertNull(writer.writer);
     } finally {
       writer.stop();
       writer.close();
@@ -210,13 +214,13 @@ public class TestRMApplicationHistoryWriter {
         Thread.sleep(100);
       }
     }
-    Assert.assertNotNull(appHD);
-    Assert.assertEquals("test app", appHD.getApplicationName());
-    Assert.assertEquals("test app type", appHD.getApplicationType());
-    Assert.assertEquals("test user", appHD.getUser());
-    Assert.assertEquals("test queue", appHD.getQueue());
-    Assert.assertEquals(0L, appHD.getSubmitTime());
-    Assert.assertEquals(1L, appHD.getStartTime());
+    assertNotNull(appHD);
+    assertEquals("test app", appHD.getApplicationName());
+    assertEquals("test app type", appHD.getApplicationType());
+    assertEquals("test user", appHD.getUser());
+    assertEquals("test queue", appHD.getQueue());
+    assertEquals(0L, appHD.getSubmitTime());
+    assertEquals(1L, appHD.getStartTime());
 
     writer.applicationFinished(app, RMAppState.FINISHED);
     for (int i = 0; i < MAX_RETRIES; ++i) {
@@ -227,11 +231,11 @@ public class TestRMApplicationHistoryWriter {
         Thread.sleep(100);
       }
     }
-    Assert.assertEquals(2L, appHD.getFinishTime());
-    Assert.assertEquals("test diagnostics info", appHD.getDiagnosticsInfo());
-    Assert.assertEquals(FinalApplicationStatus.UNDEFINED,
+    assertEquals(2L, appHD.getFinishTime());
+    assertEquals("test diagnostics info", appHD.getDiagnosticsInfo());
+    assertEquals(FinalApplicationStatus.UNDEFINED,
       appHD.getFinalApplicationStatus());
-    Assert.assertEquals(YarnApplicationState.FINISHED,
+    assertEquals(YarnApplicationState.FINISHED,
       appHD.getYarnApplicationState());
   }
 
@@ -252,10 +256,10 @@ public class TestRMApplicationHistoryWriter {
         Thread.sleep(100);
       }
     }
-    Assert.assertNotNull(appAttemptHD);
-    Assert.assertEquals("test host", appAttemptHD.getHost());
-    Assert.assertEquals(-100, appAttemptHD.getRPCPort());
-    Assert.assertEquals(ContainerId.newContainerId(
+    assertNotNull(appAttemptHD);
+    assertEquals("test host", appAttemptHD.getHost());
+    assertEquals(-100, appAttemptHD.getRPCPort());
+    assertEquals(ContainerId.newContainerId(
       ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1), 1),
       appAttemptHD.getMasterContainerId());
 
@@ -270,12 +274,12 @@ public class TestRMApplicationHistoryWriter {
         Thread.sleep(100);
       }
     }
-    Assert.assertEquals("test diagnostics info",
+    assertEquals("test diagnostics info",
       appAttemptHD.getDiagnosticsInfo());
-    Assert.assertEquals("test url", appAttemptHD.getTrackingURL());
-    Assert.assertEquals(FinalApplicationStatus.UNDEFINED,
+    assertEquals("test url", appAttemptHD.getTrackingURL());
+    assertEquals(FinalApplicationStatus.UNDEFINED,
       appAttemptHD.getFinalApplicationStatus());
-    Assert.assertEquals(YarnApplicationAttemptState.FINISHED,
+    assertEquals(YarnApplicationAttemptState.FINISHED,
       appAttemptHD.getYarnApplicationAttemptState());
   }
 
@@ -297,13 +301,13 @@ public class TestRMApplicationHistoryWriter {
         Thread.sleep(100);
       }
     }
-    Assert.assertNotNull(containerHD);
-    Assert.assertEquals(NodeId.newInstance("test host", -100),
+    assertNotNull(containerHD);
+    assertEquals(NodeId.newInstance("test host", -100),
       containerHD.getAssignedNode());
-    Assert.assertEquals(Resource.newInstance(-1, -1),
+    assertEquals(Resource.newInstance(-1, -1),
       containerHD.getAllocatedResource());
-    Assert.assertEquals(Priority.UNDEFINED, containerHD.getPriority());
-    Assert.assertEquals(0L, container.getCreationTime());
+    assertEquals(Priority.UNDEFINED, containerHD.getPriority());
+    assertEquals(0L, container.getCreationTime());
 
     writer.containerFinished(container);
     for (int i = 0; i < MAX_RETRIES; ++i) {
@@ -316,10 +320,10 @@ public class TestRMApplicationHistoryWriter {
         Thread.sleep(100);
       }
     }
-    Assert.assertEquals("test diagnostics info",
+    assertEquals("test diagnostics info",
       containerHD.getDiagnosticsInfo());
-    Assert.assertEquals(-1, containerHD.getContainerExitStatus());
-    Assert.assertEquals(ContainerState.COMPLETE,
+    assertEquals(-1, containerHD.getContainerExitStatus());
+    assertEquals(ContainerState.COMPLETE,
       containerHD.getContainerState());
   }
 
@@ -355,10 +359,10 @@ public class TestRMApplicationHistoryWriter {
         Thread.sleep(500);
       }
     }
-    Assert.assertTrue(allEventsHandled(20 * 10 * 10 + 20 * 10 + 20));
+    assertTrue(allEventsHandled(20 * 10 * 10 + 20 * 10 + 20));
     // Validate all events of one application are handled by one dispatcher
     for (ApplicationId appId : appIds) {
-      Assert.assertTrue(handledByOne(appId));
+      assertTrue(handledByOne(appId));
     }
   }
 
@@ -438,7 +442,7 @@ public class TestRMApplicationHistoryWriter {
     long elapsedTime2 = finishTime2 - startTime2;
     // No more than 10% additional workload
     // Should be much less, but computation time is fluctuated
-    Assert.assertTrue(elapsedTime2 - elapsedTime1 < elapsedTime1 / 10);
+    assertTrue(elapsedTime2 - elapsedTime1 < elapsedTime1 / 10);
   }
 
   private void testRMWritingMassiveHistory(MockRM rm) throws Exception {
@@ -470,7 +474,7 @@ public class TestRMApplicationHistoryWriter {
       allocatedSize += allocated.size();
       nm.nodeHeartbeat(true);
     }
-    Assert.assertEquals(request, allocatedSize);
+    assertEquals(request, allocatedSize);
 
     am.unregisterAppAttempt();
     rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.FINISHING);
@@ -487,7 +491,7 @@ public class TestRMApplicationHistoryWriter {
       cleaned = resp.getContainersToCleanup();
       cleanedSize += cleaned.size();
     }
-    Assert.assertEquals(allocatedSize, cleanedSize);
+    assertEquals(allocatedSize, cleanedSize);
     rm.waitForState(app.getApplicationId(), RMAppState.FINISHED);
 
     rm.stop();

+ 44 - 42
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRMRPCNodeUpdates.java

@@ -18,12 +18,14 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
 import java.security.PrivilegedExceptionAction;
 import java.util.List;
 
 import org.apache.hadoop.yarn.server.resourcemanager.MockRMAppSubmitter;
 import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeEventType;
-import org.junit.Assert;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.security.UserGroupInformation;
@@ -42,15 +44,15 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 public class TestAMRMRPCNodeUpdates {
   private MockRM rm;
   private ApplicationMasterService amService;
 
-  @Before
+  @BeforeEach
   public void setUp() {
     this.rm = new MockRM() {
       @Override
@@ -66,7 +68,7 @@ public class TestAMRMRPCNodeUpdates {
     amService = rm.getApplicationMasterService();
   }
   
-  @After
+  @AfterEach
   public void tearDown() {
     if (rm != null) {
       this.rm.stop();
@@ -139,11 +141,11 @@ public class TestAMRMRPCNodeUpdates {
     AllocateResponse response1 =
         allocate(attempt1.getAppAttemptId(), allocateRequest1);
     List<NodeReport> updatedNodes = response1.getUpdatedNodes();
-    Assert.assertEquals(1, updatedNodes.size());
+    assertEquals(1, updatedNodes.size());
     NodeReport nr = updatedNodes.iterator().next();
-    Assert.assertEquals(
+    assertEquals(
         decommissioningTimeout, nr.getDecommissioningTimeout());
-    Assert.assertEquals(
+    assertEquals(
         NodeUpdateType.NODE_DECOMMISSIONING, nr.getNodeUpdateType());
   }
 
@@ -173,11 +175,11 @@ public class TestAMRMRPCNodeUpdates {
     AllocateResponse response1 =
             allocate(attempt1.getAppAttemptId(), allocateRequest1);
     List<NodeReport> updatedNodes = response1.getUpdatedNodes();
-    Assert.assertEquals(1, updatedNodes.size());
+    assertEquals(1, updatedNodes.size());
     NodeReport nr = updatedNodes.iterator().next();
-    Assert.assertEquals(
+    assertEquals(
             decommissioningTimeout, nr.getDecommissioningTimeout());
-    Assert.assertEquals(
+    assertEquals(
             NodeUpdateType.NODE_DECOMMISSIONING, nr.getNodeUpdateType());
 
     // Wait for nm2 to RECOMMISSION
@@ -188,9 +190,9 @@ public class TestAMRMRPCNodeUpdates {
     AllocateResponse response2 =
             allocate(attempt1.getAppAttemptId(), allocateRequest2);
     List<NodeReport> updatedNodes2 = response2.getUpdatedNodes();
-    Assert.assertEquals(1, updatedNodes2.size());
+    assertEquals(1, updatedNodes2.size());
     NodeReport nr2 = updatedNodes2.iterator().next();
-    Assert.assertEquals(
+    assertEquals(
             NodeUpdateType.NODE_USABLE, nr2.getNodeUpdateType());
   }
 
@@ -220,7 +222,7 @@ public class TestAMRMRPCNodeUpdates {
     AllocateResponse response1 =
         allocate(attempt1.getAppAttemptId(), allocateRequest1);
     List<NodeReport> updatedNodes = response1.getUpdatedNodes();
-    Assert.assertEquals(0, updatedNodes.size());
+    assertEquals(0, updatedNodes.size());
 
     syncNodeHeartbeat(nm4, false);
     
@@ -230,22 +232,22 @@ public class TestAMRMRPCNodeUpdates {
           null);
     response1 = allocate(attempt1.getAppAttemptId(), allocateRequest1);
     updatedNodes = response1.getUpdatedNodes();
-    Assert.assertEquals(1, updatedNodes.size());
+    assertEquals(1, updatedNodes.size());
     NodeReport nr = updatedNodes.iterator().next();
-    Assert.assertEquals(nm4.getNodeId(), nr.getNodeId());
-    Assert.assertEquals(NodeState.UNHEALTHY, nr.getNodeState());
-    Assert.assertNull(nr.getDecommissioningTimeout());
-    Assert.assertEquals(NodeUpdateType.NODE_UNUSABLE, nr.getNodeUpdateType());
+    assertEquals(nm4.getNodeId(), nr.getNodeId());
+    assertEquals(NodeState.UNHEALTHY, nr.getNodeState());
+    assertNull(nr.getDecommissioningTimeout());
+    assertEquals(NodeUpdateType.NODE_UNUSABLE, nr.getNodeUpdateType());
     
     // resending the allocate request returns the same result
     response1 = allocate(attempt1.getAppAttemptId(), allocateRequest1);
     updatedNodes = response1.getUpdatedNodes();
-    Assert.assertEquals(1, updatedNodes.size());
+    assertEquals(1, updatedNodes.size());
     nr = updatedNodes.iterator().next();
-    Assert.assertEquals(nm4.getNodeId(), nr.getNodeId());
-    Assert.assertEquals(NodeState.UNHEALTHY, nr.getNodeState());
-    Assert.assertNull(nr.getDecommissioningTimeout());
-    Assert.assertEquals(NodeUpdateType.NODE_UNUSABLE, nr.getNodeUpdateType());
+    assertEquals(nm4.getNodeId(), nr.getNodeId());
+    assertEquals(NodeState.UNHEALTHY, nr.getNodeState());
+    assertNull(nr.getDecommissioningTimeout());
+    assertEquals(NodeUpdateType.NODE_UNUSABLE, nr.getNodeUpdateType());
 
     syncNodeLost(nm3);
     
@@ -255,12 +257,12 @@ public class TestAMRMRPCNodeUpdates {
           null);
     response1 = allocate(attempt1.getAppAttemptId(), allocateRequest1);
     updatedNodes = response1.getUpdatedNodes();
-    Assert.assertEquals(1, updatedNodes.size());
+    assertEquals(1, updatedNodes.size());
     nr = updatedNodes.iterator().next();
-    Assert.assertEquals(nm3.getNodeId(), nr.getNodeId());
-    Assert.assertEquals(NodeState.LOST, nr.getNodeState());
-    Assert.assertNull(nr.getDecommissioningTimeout());
-    Assert.assertEquals(NodeUpdateType.NODE_UNUSABLE, nr.getNodeUpdateType());
+    assertEquals(nm3.getNodeId(), nr.getNodeId());
+    assertEquals(NodeState.LOST, nr.getNodeState());
+    assertNull(nr.getDecommissioningTimeout());
+    assertEquals(NodeUpdateType.NODE_UNUSABLE, nr.getNodeUpdateType());
         
     // registering another AM gives it the complete failed list
     RMApp app2 = MockRMAppSubmitter.submitWithMemory(2000, rm);
@@ -278,7 +280,7 @@ public class TestAMRMRPCNodeUpdates {
     AllocateResponse response2 =
         allocate(attempt2.getAppAttemptId(), allocateRequest2);
     updatedNodes = response2.getUpdatedNodes();
-    Assert.assertEquals(0, updatedNodes.size());
+    assertEquals(0, updatedNodes.size());
     
     syncNodeHeartbeat(nm4, true);
     
@@ -288,24 +290,24 @@ public class TestAMRMRPCNodeUpdates {
           null);
     response1 = allocate(attempt1.getAppAttemptId(), allocateRequest1);
     updatedNodes = response1.getUpdatedNodes();
-    Assert.assertEquals(1, updatedNodes.size());
+    assertEquals(1, updatedNodes.size());
     nr = updatedNodes.iterator().next();
-    Assert.assertEquals(nm4.getNodeId(), nr.getNodeId());
-    Assert.assertEquals(NodeState.RUNNING, nr.getNodeState());
-    Assert.assertNull(nr.getDecommissioningTimeout());
-    Assert.assertEquals(NodeUpdateType.NODE_USABLE, nr.getNodeUpdateType());
+    assertEquals(nm4.getNodeId(), nr.getNodeId());
+    assertEquals(NodeState.RUNNING, nr.getNodeState());
+    assertNull(nr.getDecommissioningTimeout());
+    assertEquals(NodeUpdateType.NODE_USABLE, nr.getNodeUpdateType());
     
     allocateRequest2 =
         AllocateRequest.newInstance(response2.getResponseId(), 0F, null, null,
           null);
     response2 = allocate(attempt2.getAppAttemptId(), allocateRequest2);
     updatedNodes = response2.getUpdatedNodes();
-    Assert.assertEquals(1, updatedNodes.size());
+    assertEquals(1, updatedNodes.size());
     nr = updatedNodes.iterator().next();
-    Assert.assertEquals(nm4.getNodeId(), nr.getNodeId());
-    Assert.assertEquals(NodeState.RUNNING, nr.getNodeState());
-    Assert.assertNull(nr.getDecommissioningTimeout());
-    Assert.assertEquals(NodeUpdateType.NODE_USABLE, nr.getNodeUpdateType());
+    assertEquals(nm4.getNodeId(), nr.getNodeId());
+    assertEquals(NodeState.RUNNING, nr.getNodeState());
+    assertNull(nr.getDecommissioningTimeout());
+    assertEquals(NodeUpdateType.NODE_USABLE, nr.getNodeUpdateType());
 
     // subsequent allocate calls should return no updated nodes
     allocateRequest2 =
@@ -313,7 +315,7 @@ public class TestAMRMRPCNodeUpdates {
           null);
     response2 = allocate(attempt2.getAppAttemptId(), allocateRequest2);
     updatedNodes = response2.getUpdatedNodes();
-    Assert.assertEquals(0, updatedNodes.size());
+    assertEquals(0, updatedNodes.size());
     
     // how to do the above for LOST node
   

+ 15 - 12
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRMRPCResponseId.java

@@ -18,6 +18,10 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
 import java.security.PrivilegedExceptionAction;
 
 import org.apache.hadoop.security.UserGroupInformation;
@@ -33,24 +37,23 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
 import org.apache.hadoop.yarn.server.resourcemanager.MockRMAppSubmitter;
 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 public class TestAMRMRPCResponseId {
 
   private MockRM rm;
   ApplicationMasterService amService = null;
 
-  @Before
+  @BeforeEach
   public void setUp() {
     this.rm = new MockRM();
     rm.start();
     amService = rm.getApplicationMasterService();
   }
   
-  @After
+  @AfterEach
   public void tearDown() {
     if (rm != null) {
       this.rm.stop();
@@ -93,26 +96,26 @@ public class TestAMRMRPCResponseId {
 
     AllocateResponse response =
         allocate(attempt.getAppAttemptId(), allocateRequest);
-    Assert.assertEquals(1, response.getResponseId());
-    Assert.assertTrue(response.getAMCommand() == null);
+    assertEquals(1, response.getResponseId());
+    assertTrue(response.getAMCommand() == null);
     allocateRequest =
         AllocateRequest.newInstance(response.getResponseId(), 0F, null, null,
           null);
     
     response = allocate(attempt.getAppAttemptId(), allocateRequest);
-    Assert.assertEquals(2, response.getResponseId());
+    assertEquals(2, response.getResponseId());
     /* try resending */
     response = allocate(attempt.getAppAttemptId(), allocateRequest);
-    Assert.assertEquals(2, response.getResponseId());
+    assertEquals(2, response.getResponseId());
     
     /** try sending old request again **/
     allocateRequest = AllocateRequest.newInstance(0, 0F, null, null, null);
 
     try {
       allocate(attempt.getAppAttemptId(), allocateRequest);
-      Assert.fail();
+      fail();
     } catch (Exception e) {
-      Assert.assertTrue(e.getCause() instanceof InvalidApplicationMasterRequestException);
+      assertTrue(e.getCause() instanceof InvalidApplicationMasterRequestException);
     }
   }
 }

+ 139 - 97
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java

@@ -18,6 +18,13 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
 
+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;
+import static org.junit.jupiter.api.Assertions.fail;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -72,20 +79,25 @@ import org.apache.hadoop.yarn.util.Records;
 
 import org.apache.hadoop.thirdparty.com.google.common.base.Throwables;
 
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 /**
  * Test AM restart functions.
  */
 public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
-  public TestAMRestart(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestAMRestart(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
   }
 
-  @Test(timeout = 30000)
-  public void testAMRestartWithExistingContainers() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  @SuppressWarnings("checkstyle:methodlength")
+  public void testAMRestartWithExistingContainers(SchedulerType type) throws Exception {
+    initTestAMRestart(type);
     getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2);
 
     MockRM rm1 = new MockRM(getConf());
@@ -158,7 +170,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
       Thread.sleep(200);
     }
     // assert containerId6 is reserved.
-    Assert.assertEquals(containerId6, schedulerAttempt.getReservedContainers()
+    assertEquals(containerId6, schedulerAttempt.getReservedContainers()
       .get(0).getContainerId());
 
     // fail the AM by sending CONTAINER_FINISHED event without registering.
@@ -170,15 +182,15 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     Thread.sleep(3000);
     rm1.waitForState(nm1, containerId2, RMContainerState.RUNNING);
     // acquired/allocated containers are cleaned up.
-    Assert.assertNull(rm1.getResourceScheduler().getRMContainer(containerId4));
-    Assert.assertNull(rm1.getResourceScheduler().getRMContainer(containerId5));
+    assertNull(rm1.getResourceScheduler().getRMContainer(containerId4));
+    assertNull(rm1.getResourceScheduler().getRMContainer(containerId5));
 
     // wait for app to start a new attempt.
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
     // assert this is a new AM.
     ApplicationAttemptId newAttemptId =
         app1.getCurrentAppAttempt().getAppAttemptId();
-    Assert.assertFalse(newAttemptId.equals(am1.getApplicationAttemptId()));
+    assertFalse(newAttemptId.equals(am1.getApplicationAttemptId()));
 
     // launch the new AM
     MockAM am2 = rm1.launchAM(app1, rm1, nm1);
@@ -187,7 +199,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
 
     // Assert two containers are running: container2 and container3;
-    Assert.assertEquals(2, registerResponse.getContainersFromPreviousAttempts()
+    assertEquals(2, registerResponse.getContainersFromPreviousAttempts()
       .size());
     boolean containerId2Exists = false, containerId3Exists = false;
     for (Container container : registerResponse
@@ -199,7 +211,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
         containerId3Exists = true;
       }
     }
-    Assert.assertTrue(containerId2Exists && containerId3Exists);
+    assertTrue(containerId2Exists && containerId3Exists);
     rm1.waitForState(app1.getApplicationId(), RMAppState.RUNNING);
 
     // complete container by sending the container complete event which has earlier
@@ -236,7 +248,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
         container6Exists = true;
       }
     }
-    Assert.assertTrue(container3Exists && container4Exists && container5Exists
+    assertTrue(container3Exists && container4Exists && container5Exists
         && container6Exists);
 
     // New SchedulerApplicationAttempt also has the containers info.
@@ -251,7 +263,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
     // the 2nd attempt released the 1st attempt's running container, when the
     // 2nd attempt finishes.
-    Assert.assertFalse(schedulerNewAttempt.getLiveContainers().contains(
+    assertFalse(schedulerNewAttempt.getLiveContainers().contains(
       containerId2));
     // all 4 normal containers finished.
     System.out.println("New attempt's just finished containers: "
@@ -278,8 +290,8 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
       Thread.sleep(200);
     }
 
-    Assert.assertEquals("Did not get all containers allocated",
-        NUM_CONTAINERS, containers.size());
+    assertEquals(NUM_CONTAINERS, containers.size(),
+        "Did not get all containers allocated");
     return containers;
   }
 
@@ -293,8 +305,11 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test(timeout = 30000)
-  public void testNMTokensRebindOnAMRestart() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testNMTokensRebindOnAMRestart(SchedulerType type) throws Exception {
+    initTestAMRestart(type);
     getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 3);
     // To prevent test from blacklisting nm1 for AM, we sit threshold to half
     // of 2 nodes which is 1
@@ -369,10 +384,10 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     rm1.waitForState(am2.getApplicationAttemptId(), RMAppAttemptState.RUNNING);
 
     // check am2 get the nm token from am1.
-    Assert.assertEquals(expectedNMTokens.size(),
+    assertEquals(expectedNMTokens.size(),
         registerResponse.getNMTokensFromPreviousAttempts().size());
     for (int i = 0; i < expectedNMTokens.size(); i++) {
-      Assert.assertTrue(expectedNMTokens.get(i)
+      assertTrue(expectedNMTokens.get(i)
           .equals(registerResponse.getNMTokensFromPreviousAttempts().get(i)));
     }
 
@@ -408,8 +423,8 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
     // check am3 get the NM token from both am1 and am2;
     List<NMToken> transferredTokens = registerResponse.getNMTokensFromPreviousAttempts();
-    Assert.assertEquals(2, transferredTokens.size());
-    Assert.assertTrue(transferredTokens.containsAll(expectedNMTokens));
+    assertEquals(2, transferredTokens.size());
+    assertTrue(transferredTokens.containsAll(expectedNMTokens));
     rm1.stop();
   }
 
@@ -417,8 +432,11 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
    * AM container preempted, nm disk failure
    * should not be counted towards AM max retry count.
    */
-  @Test(timeout = 100000)
-  public void testShouldNotCountFailureToMaxAttemptRetry() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 100)
+  public void testShouldNotCountFailureToMaxAttemptRetry(SchedulerType type) throws Exception {
+    initTestAMRestart(type);
     getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2);
     getConf().setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
     getConf().set(
@@ -442,7 +460,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am1.getApplicationAttemptId());
 
-    Assert.assertFalse(attempt1.shouldCountTowardsMaxAttemptRetry());
+    assertFalse(attempt1.shouldCountTowardsMaxAttemptRetry());
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
     ApplicationStateData appState =
         ((MemoryRMStateStore) rm1.getRMStateStore()).getState()
@@ -462,7 +480,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am2.getApplicationAttemptId());
 
-    Assert.assertFalse(attempt2.shouldCountTowardsMaxAttemptRetry());
+    assertFalse(attempt2.shouldCountTowardsMaxAttemptRetry());
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
     MockAM am3 =
         rm1.waitForNewAMToLaunchAndRegister(app1.getApplicationId(), 3, nm1);
@@ -484,8 +502,8 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am3.getApplicationAttemptId());
 
-    Assert.assertFalse(attempt3.shouldCountTowardsMaxAttemptRetry());
-    Assert.assertEquals(ContainerExitStatus.DISKS_FAILED,
+    assertFalse(attempt3.shouldCountTowardsMaxAttemptRetry());
+    assertEquals(ContainerExitStatus.DISKS_FAILED,
       appState.getAttempt(am3.getApplicationAttemptId())
         .getAMContainerExitStatus());
 
@@ -505,8 +523,8 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am4.getApplicationAttemptId());
 
-    Assert.assertFalse(attempt4.shouldCountTowardsMaxAttemptRetry());
-    Assert.assertEquals(ContainerExitStatus.ABORTED,
+    assertFalse(attempt4.shouldCountTowardsMaxAttemptRetry());
+    assertEquals(ContainerExitStatus.ABORTED,
       appState.getAttempt(am4.getApplicationAttemptId())
         .getAMContainerExitStatus());
     // launch next AM in nm2
@@ -520,7 +538,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am5.getApplicationAttemptId());
 
-    Assert.assertTrue(attempt5.shouldCountTowardsMaxAttemptRetry());
+    assertTrue(attempt5.shouldCountTowardsMaxAttemptRetry());
 
     // launch next AM in nm2
     MockAM am6 =
@@ -534,16 +552,19 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am6.getApplicationAttemptId());
 
-    Assert.assertTrue(attempt6.shouldCountTowardsMaxAttemptRetry());
+    assertTrue(attempt6.shouldCountTowardsMaxAttemptRetry());
 
     // AM should not be restarted.
     rm1.waitForState(app1.getApplicationId(), RMAppState.FAILED);
-    Assert.assertEquals(6, app1.getAppAttempts().size());
+    assertEquals(6, app1.getAppAttempts().size());
     rm1.stop();
   }
 
-  @Test(timeout = 100000)
-  public void testMaxAttemptOneMeansOne() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 100)
+  public void testMaxAttemptOneMeansOne(SchedulerType type) throws Exception {
+    initTestAMRestart(type);
     getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
     getConf().setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
     getConf().set(
@@ -569,7 +590,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
     // AM should not be restarted.
     rm1.waitForState(app1.getApplicationId(), RMAppState.FAILED);
-    Assert.assertEquals(1, app1.getAppAttempts().size());
+    assertEquals(1, app1.getAppAttempts().size());
     rm1.stop();
   }
 
@@ -578,8 +599,11 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
    * AM preemption failure towards the max-retry-account and should be able to
    * re-launch the AM.
    */
-  @Test(timeout = 60000)
-  public void testPreemptedAMRestartOnRMRestart() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 60)
+  public void testPreemptedAMRestartOnRMRestart(SchedulerType type) throws Exception {
+    initTestAMRestart(type);
     getConf().setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
     getConf().setBoolean(
         YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, false);
@@ -608,7 +632,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     rm1.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.FAILED);
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am1.getApplicationAttemptId());
-    Assert.assertTrue(attempt1.shouldCountTowardsMaxAttemptRetry());
+    assertTrue(attempt1.shouldCountTowardsMaxAttemptRetry());
 
     // wait for the next AM to start
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
@@ -621,21 +645,21 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     scheduler.killContainer(scheduler.getRMContainer(amContainer));
 
     rm1.waitForState(am2.getApplicationAttemptId(), RMAppAttemptState.FAILED);
-    Assert.assertFalse(attempt2.shouldCountTowardsMaxAttemptRetry());
+    assertFalse(attempt2.shouldCountTowardsMaxAttemptRetry());
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
 
     // state store has 2 attempts stored.
     ApplicationStateData appState =
         memStore.getState().getApplicationState().get(app1.getApplicationId());
-    Assert.assertEquals(2, appState.getAttemptCount());
+    assertEquals(2, appState.getAttemptCount());
     if (getSchedulerType().equals(SchedulerType.FAIR)) {
       // attempt stored has the preempted container exit status.
-      Assert.assertEquals(ContainerExitStatus.KILLED_BY_RESOURCEMANAGER,
+      assertEquals(ContainerExitStatus.KILLED_BY_RESOURCEMANAGER,
           appState.getAttempt(am2.getApplicationAttemptId())
               .getAMContainerExitStatus());
     } else {
       // attempt stored has the preempted container exit status.
-      Assert.assertEquals(ContainerExitStatus.PREEMPTED,
+      assertEquals(ContainerExitStatus.PREEMPTED,
           appState.getAttempt(am2.getApplicationAttemptId())
               .getAMContainerExitStatus());
     }
@@ -652,8 +676,8 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     RMAppAttempt attempt3 =
         rm2.getRMContext().getRMApps().get(app1.getApplicationId())
           .getCurrentAppAttempt();
-    Assert.assertTrue(attempt3.shouldCountTowardsMaxAttemptRetry());
-    Assert.assertEquals(ContainerExitStatus.INVALID,
+    assertTrue(attempt3.shouldCountTowardsMaxAttemptRetry());
+    assertEquals(ContainerExitStatus.INVALID,
         appState.getAttempt(am3.getApplicationAttemptId())
             .getAMContainerExitStatus());
     rm1.stop();
@@ -665,9 +689,12 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
    * AM failure towards the max-retry-account and should be able to
    * re-launch the AM.
    */
-  @Test(timeout = 50000)
-  public void testRMRestartOrFailoverNotCountedForAMFailures()
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 50)
+  public void testRMRestartOrFailoverNotCountedForAMFailures(SchedulerType type)
       throws Exception {
+    initTestAMRestart(type);
     getConf().setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
     getConf().setBoolean(
         YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, false);
@@ -696,7 +723,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     rm1.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.FAILED);
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am1.getApplicationAttemptId());
-    Assert.assertTrue(attempt1.shouldCountTowardsMaxAttemptRetry());
+    assertTrue(attempt1.shouldCountTowardsMaxAttemptRetry());
 
     // wait for the next AM to start
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
@@ -720,7 +747,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     nm1.registerNode(Collections.singletonList(status), null);
 
     rm2.waitForState(attempt2.getAppAttemptId(), RMAppAttemptState.FAILED);
-    Assert.assertEquals(ContainerExitStatus.KILLED_BY_RESOURCEMANAGER,
+    assertEquals(ContainerExitStatus.KILLED_BY_RESOURCEMANAGER,
         appState.getAttempt(am2.getApplicationAttemptId())
             .getAMContainerExitStatus());
     // Will automatically start a new AppAttempt in rm2
@@ -731,8 +758,8 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     RMAppAttempt attempt3 =
         rm2.getRMContext().getRMApps().get(app1.getApplicationId())
           .getCurrentAppAttempt();
-    Assert.assertTrue(attempt3.shouldCountTowardsMaxAttemptRetry());
-    Assert.assertEquals(ContainerExitStatus.INVALID,
+    assertTrue(attempt3.shouldCountTowardsMaxAttemptRetry());
+    assertEquals(ContainerExitStatus.INVALID,
         appState.getAttempt(am3.getApplicationAttemptId())
             .getAMContainerExitStatus());
 
@@ -740,8 +767,11 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     rm2.stop();
   }
 
-  @Test (timeout = 120000)
-  public void testRMAppAttemptFailuresValidityInterval() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 120)
+  public void testRMAppAttemptFailuresValidityInterval(SchedulerType type) throws Exception {
+    initTestAMRestart(type);
     getConf().setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
     getConf().setBoolean(
         YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, false);
@@ -778,7 +808,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     rm1.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.FAILED);
     // launch the second attempt
     rm1.waitForState(app.getApplicationId(), RMAppState.ACCEPTED);
-    Assert.assertEquals(2, app.getAppAttempts().size());
+    assertEquals(2, app.getAppAttempts().size());
 
     MockAM am_2 = MockRM.launchAndRegisterAM(app, rm1, nm1);
     rm1.waitForState(am_2.getApplicationAttemptId(), RMAppAttemptState.RUNNING);
@@ -809,7 +839,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
     // launch the second attempt
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
-    Assert.assertEquals(2, app1.getAppAttempts().size());
+    assertEquals(2, app1.getAppAttempts().size());
 
     RMAppAttempt attempt2 = app1.getCurrentAppAttempt();
     MockAM am2 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
@@ -824,7 +854,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
     // can launch the third attempt successfully
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
-    Assert.assertEquals(3, app1.getAppAttempts().size());
+    assertEquals(3, app1.getAppAttempts().size());
     RMAppAttempt attempt3 = app1.getCurrentAppAttempt();
     clock.reset();
     MockAM am3 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
@@ -840,7 +870,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     ApplicationStateData app1State =
         memStore1.getState().getApplicationState().
         get(app1.getApplicationId());
-    Assert.assertEquals(1, app1State.getFirstAttemptId());
+    assertEquals(1, app1State.getFirstAttemptId());
 
     // re-register the NM
     nm1.setResourceTrackerService(rm2.getResourceTrackerService());
@@ -856,7 +886,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     //Wait to make sure attempt3 be removed in State Store
     //TODO explore a better way than sleeping for a while (YARN-4929)
     Thread.sleep(15 * 1000);
-    Assert.assertEquals(2, app1State.getAttemptCount());
+    assertEquals(2, app1State.getAttemptCount());
 
     rm2.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
 
@@ -870,7 +900,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     nm1
       .nodeHeartbeat(am4.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
     rm2.waitForState(am4.getApplicationAttemptId(), RMAppAttemptState.FAILED);
-    Assert.assertEquals(2, app1State.getAttemptCount());
+    assertEquals(2, app1State.getAttemptCount());
 
     // can launch the 5th attempt successfully
     rm2.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
@@ -884,7 +914,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     nm1
       .nodeHeartbeat(am5.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
     rm2.waitForState(am5.getApplicationAttemptId(), RMAppAttemptState.FAILED);
-    Assert.assertEquals(2, app1State.getAttemptCount());
+    assertEquals(2, app1State.getAttemptCount());
 
     rm2.waitForState(app1.getApplicationId(), RMAppState.FAILED);
     rm1.stop();
@@ -901,8 +931,11 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     return false;
   }
 
-  @Test(timeout = 40000)
-  public void testAMRestartNotLostContainerCompleteMsg() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 40)
+  public void testAMRestartNotLostContainerCompleteMsg(SchedulerType type) throws Exception {
+    initTestAMRestart(type);
     getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2);
 
     MockRM rm1 = new MockRM(getConf());
@@ -958,7 +991,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
           app1.getCurrentAppAttempt().getJustFinishedContainers();
       if (isContainerIdInContainerStatus(containerStatuses,
           containerId2)) {
-        Assert.fail();
+        fail();
       }
       break;
     }
@@ -973,7 +1006,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     // assert this is a new AM.
     ApplicationAttemptId newAttemptId =
         app1.getCurrentAppAttempt().getAppAttemptId();
-    Assert.assertFalse(newAttemptId.equals(am1.getApplicationAttemptId()));
+    assertFalse(newAttemptId.equals(am1.getApplicationAttemptId()));
 
     // launch the new AM
     RMAppAttempt attempt2 = app1.getCurrentAppAttempt();
@@ -986,11 +1019,11 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
         allocateResponse.getCompletedContainersStatuses();
     if (isContainerIdInContainerStatus(containerStatuses,
         containerId2) == false) {
-      Assert.fail();
+      fail();
     }
     containerStatuses = attempt2.getJustFinishedContainers();
     if (isContainerIdInContainerStatus(containerStatuses, containerId2)) {
-      Assert.fail();
+      fail();
     }
 
     // the second allocate should not get container complete msg
@@ -999,7 +1032,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     containerStatuses =
         allocateResponse.getCompletedContainersStatuses();
     if (isContainerIdInContainerStatus(containerStatuses, containerId2)) {
-      Assert.fail();
+      fail();
     }
 
     rm1.stop();
@@ -1010,9 +1043,12 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
    * after AM reset window, even if AM who was the last is failed,
    * all containers are launched by previous AM should be kept.
    */
-  @Test (timeout = 20000)
-  public void testAMRestartNotLostContainerAfterAttemptFailuresValidityInterval()
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 20)
+  public void testAMRestartNotLostContainerAfterAttemptFailuresValidityInterval(SchedulerType type)
       throws Exception {
+    initTestAMRestart(type);
     // explicitly set max-am-retry count as 2.
     getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2);
 
@@ -1047,7 +1083,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
     // launch the second attempt
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
-    Assert.assertEquals(2, app1.getAppAttempts().size());
+    assertEquals(2, app1.getAppAttempts().size());
 
     // It will be the last attempt.
     RMAppAttempt attempt2 = app1.getCurrentAppAttempt();
@@ -1064,20 +1100,20 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
 
     // can launch the third attempt successfully
     rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED);
-    Assert.assertEquals(3, app1.getAppAttempts().size());
+    assertEquals(3, app1.getAppAttempts().size());
     MockAM am3 = rm1.launchAM(app1, rm1, nm1);
     RegisterApplicationMasterResponse registerResponse =
             am3.registerAppAttempt();
 
     // keepContainers is applied, even if attempt2 was the last attempt.
-    Assert.assertEquals(1, registerResponse.getContainersFromPreviousAttempts()
+    assertEquals(1, registerResponse.getContainersFromPreviousAttempts()
             .size());
     boolean containerId2Exists = false;
     Container container = registerResponse.getContainersFromPreviousAttempts().get(0);
     if (container.getId().equals(containerId2)) {
       containerId2Exists = true;
     }
-    Assert.assertTrue(containerId2Exists);
+    assertTrue(containerId2Exists);
 
     rm1.waitForState(app1.getApplicationId(), RMAppState.RUNNING);
     rm1.stop();
@@ -1102,9 +1138,12 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
    * 8. Verify that the app master receives container 3 in the RM response to
    *    its heartbeat.
    */
-  @Test(timeout = 200000)
-  public void testContainersFromPreviousAttemptsWithRMRestart()
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 200)
+  public void testContainersFromPreviousAttemptsWithRMRestart(SchedulerType type)
       throws Exception {
+    initTestAMRestart(type);
     getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2);
     getConf().setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
     getConf().setBoolean(
@@ -1182,7 +1221,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 2,
         ContainerState.RUNNING);
     rm2.waitForState(nm1, containerId2, RMContainerState.RUNNING);
-    Assert.assertNotNull(rm2.getResourceScheduler()
+    assertNotNull(rm2.getResourceScheduler()
         .getRMContainer(containerId2));
 
     // wait for app to start a new attempt.
@@ -1190,7 +1229,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     // assert this is a new AM.
     ApplicationAttemptId newAttemptId =
         app1.getCurrentAppAttempt().getAppAttemptId();
-    Assert.assertFalse(newAttemptId.equals(am1.getApplicationAttemptId()));
+    assertFalse(newAttemptId.equals(am1.getApplicationAttemptId()));
 
     // launch the new AM
     MockAM am2 = MockRM.launchAMWhenAsyncSchedulingEnabled(app1, rm2);
@@ -1198,15 +1237,15 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
         am2.registerAppAttempt();
 
     // container2 is recovered from previous attempt
-    Assert.assertEquals(1,
+    assertEquals(1,
         registerResponse.getContainersFromPreviousAttempts().size());
-    Assert.assertEquals("container 2", containerId2,
-        registerResponse.getContainersFromPreviousAttempts().get(0).getId());
+    assertEquals(containerId2, registerResponse.getContainersFromPreviousAttempts().get(0).getId(),
+        "container 2");
     List<NMToken> prevNMTokens = registerResponse
         .getNMTokensFromPreviousAttempts();
-    Assert.assertEquals(1, prevNMTokens.size());
+    assertEquals(1, prevNMTokens.size());
     // container 2 is running on node 1
-    Assert.assertEquals(nm1Address, prevNMTokens.get(0).getNodeId().toString());
+    assertEquals(nm1Address, prevNMTokens.get(0).getNodeId().toString());
 
     rm2.waitForState(app1.getApplicationId(), RMAppState.RUNNING);
 
@@ -1220,7 +1259,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     nm2.nodeHeartbeat(am1.getApplicationAttemptId(), 3,
         ContainerState.RUNNING);
     rm2.waitForState(nm2, containerId3, RMContainerState.RUNNING);
-    Assert.assertNotNull(rm2.getResourceScheduler()
+    assertNotNull(rm2.getResourceScheduler()
         .getRMContainer(containerId3));
 
     List<Container> containersFromPreviousAttempts = new ArrayList<>();
@@ -1230,12 +1269,12 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
         if (allocateResponse.getContainersFromPreviousAttempts().size() > 0){
           containersFromPreviousAttempts.addAll(
               allocateResponse.getContainersFromPreviousAttempts());
-          Assert.assertEquals("new containers should not be allocated",
-              0, allocateResponse.getAllocatedContainers().size());
+          assertEquals(0, allocateResponse.getAllocatedContainers().size(),
+              "new containers should not be allocated");
           List<NMToken> nmTokens = allocateResponse.getNMTokens();
-          Assert.assertEquals(1, nmTokens.size());
+          assertEquals(1, nmTokens.size());
           // container 3 is running on node 2
-          Assert.assertEquals(nm2Address,
+          assertEquals(nm2Address,
               nmTokens.get(0).getNodeId().toString());
           return true;
         }
@@ -1245,8 +1284,8 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
       }
       return false;
     }, 2000, 200000);
-    Assert.assertEquals("container 3", containerId3,
-        containersFromPreviousAttempts.get(0).getId());
+    assertEquals(containerId3,
+        containersFromPreviousAttempts.get(0).getId(), "container 3");
     rm2.stop();
     rm1.stop();
   }
@@ -1262,8 +1301,11 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
    * 4. Verify that the used resource of queue should be cleaned up normally
    *    after app fail.
    */
-  @Test(timeout = 30000)
-  public void testQueueResourceDoesNotLeak() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(value = 30)
+  public void testQueueResourceDoesNotLeak(SchedulerType type) throws Exception {
+    initTestAMRestart(type);
     getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
     getConf().setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
     getConf()
@@ -1301,7 +1343,7 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler,
         am1.getApplicationAttemptId());
 
-    Assert.assertFalse(attempt1.shouldCountTowardsMaxAttemptRetry());
+    assertFalse(attempt1.shouldCountTowardsMaxAttemptRetry());
 
     // AM should not be restarted.
     rm1.waitForState(app1.getApplicationId(), RMAppState.FAILED);
@@ -1311,20 +1353,20 @@ public class TestAMRestart extends ParameterizedSchedulerTestBase {
     if (getSchedulerType() == SchedulerType.CAPACITY) {
       LeafQueue queue =
           (LeafQueue) ((CapacityScheduler) scheduler).getQueue("default");
-      Assert.assertEquals(0,
+      assertEquals(0,
           queue.getQueueResourceUsage().getUsed().getMemorySize());
-      Assert.assertEquals(0,
+      assertEquals(0,
           queue.getQueueResourceUsage().getUsed().getVirtualCores());
     } else if (getSchedulerType() == SchedulerType.FAIR) {
       // The default queue is not auto created after YARN-7769 so
       // user-as-default-queue option is used
       Collection<FSLeafQueue> queues = ((FairScheduler) scheduler)
           .getQueueManager().getLeafQueues();
-      Assert.assertEquals(1, queues.size());
+      assertEquals(1, queues.size());
 
       FSLeafQueue queue = queues.iterator().next();
-      Assert.assertEquals(0, queue.getResourceUsage().getMemorySize());
-      Assert.assertEquals(0, queue.getResourceUsage().getVirtualCores());
+      assertEquals(0, queue.getResourceUsage().getMemorySize());
+      assertEquals(0, queue.getResourceUsage().getVirtualCores());
     }
 
     rm1.stop();

+ 19 - 34
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/blacklist/TestBlacklistManager.java

@@ -18,13 +18,14 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.blacklist;
 
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.Collections;
 import java.util.List;
 
 import org.apache.hadoop.yarn.api.records.ResourceBlacklistRequest;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class TestBlacklistManager {
 
@@ -45,14 +46,10 @@ public class TestBlacklistManager {
     Collections.sort(blacklistAdditions);
     List<String> blacklistRemovals = blacklist.getBlacklistRemovals();
     String[] expectedBlacklistAdditions = new String[]{anyNode2, anyNode};
-    Assert.assertArrayEquals(
-        "Blacklist additions was not as expected",
-        expectedBlacklistAdditions,
-        blacklistAdditions.toArray());
-    Assert.assertTrue(
-        "Blacklist removals should be empty but was " +
-            blacklistRemovals,
-        blacklistRemovals.isEmpty());
+    assertArrayEquals(expectedBlacklistAdditions,
+        blacklistAdditions.toArray(), "Blacklist additions was not as expected");
+    assertTrue(blacklistRemovals.isEmpty(),
+        "Blacklist removals should be empty but was " + blacklistRemovals);
   }
 
   @Test
@@ -69,14 +66,10 @@ public class TestBlacklistManager {
     Collections.sort(blacklistAdditions);
     List<String> blacklistRemovals = blacklist.getBlacklistRemovals();
     String[] expectedBlacklistAdditions = new String[]{anyNode};
-    Assert.assertArrayEquals(
-        "Blacklist additions was not as expected",
-        expectedBlacklistAdditions,
-        blacklistAdditions.toArray());
-    Assert.assertTrue(
-        "Blacklist removals should be empty but was " +
-            blacklistRemovals,
-        blacklistRemovals.isEmpty());
+    assertArrayEquals(expectedBlacklistAdditions,
+        blacklistAdditions.toArray(), "Blacklist additions was not as expected");
+    assertTrue(blacklistRemovals.isEmpty(),
+        "Blacklist removals should be empty but was " + blacklistRemovals);
 
     manager.addNode(anyNode2);
 
@@ -87,14 +80,10 @@ public class TestBlacklistManager {
     blacklistRemovals = blacklist.getBlacklistRemovals();
     Collections.sort(blacklistRemovals);
     String[] expectedBlacklistRemovals = new String[] {anyNode2, anyNode};
-    Assert.assertTrue(
-        "Blacklist additions should be empty but was " +
-            blacklistAdditions,
-        blacklistAdditions.isEmpty());
-    Assert.assertArrayEquals(
-        "Blacklist removals was not as expected",
-        expectedBlacklistRemovals,
-        blacklistRemovals.toArray());
+    assertTrue(blacklistAdditions.isEmpty(),
+        "Blacklist additions should be empty but was " + blacklistAdditions);
+    assertArrayEquals(expectedBlacklistRemovals,
+        blacklistRemovals.toArray(), "Blacklist removals was not as expected");
   }
 
   @Test
@@ -107,13 +96,9 @@ public class TestBlacklistManager {
 
     List<String> blacklistAdditions = blacklist.getBlacklistAdditions();
     List<String> blacklistRemovals = blacklist.getBlacklistRemovals();
-    Assert.assertTrue(
-        "Blacklist additions should be empty but was " +
-            blacklistAdditions,
-        blacklistAdditions.isEmpty());
-    Assert.assertTrue(
-        "Blacklist removals should be empty but was " +
-            blacklistRemovals,
-        blacklistRemovals.isEmpty());
+    assertTrue(blacklistAdditions.isEmpty(),
+        "Blacklist additions should be empty but was " + blacklistAdditions);
+    assertTrue(blacklistRemovals.isEmpty(),
+        "Blacklist removals should be empty but was " + blacklistRemovals);
   }
 }

+ 58 - 54
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/federation/TestFederationRMStateStoreService.java

@@ -17,6 +17,11 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.federation;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.io.IOException;
 import java.io.StringReader;
 import java.net.UnknownHostException;
@@ -74,10 +79,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppImpl;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterMetricsInfo;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import org.glassfish.jersey.jettison.JettisonJaxbContext;
 import org.glassfish.jersey.jettison.JettisonUnmarshaller;
@@ -103,7 +107,7 @@ public class TestFederationRMStateStoreService {
   private JettisonUnmarshaller jsonUnmarshaller;
   private MockRM mockRM;
 
-  @Before
+  @BeforeEach
   public void setUp() throws IOException, YarnException, JAXBException {
     conf = new YarnConfiguration();
     this.jettisonJaxbContext = new JettisonJaxbContext(ClusterMetricsInfo.class);
@@ -118,7 +122,7 @@ public class TestFederationRMStateStoreService {
     mockRM.start();
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     jettisonJaxbContext = null;
     jsonUnmarshaller = null;
@@ -136,12 +140,12 @@ public class TestFederationRMStateStoreService {
     rm.init(conf);
     stateStore = rm.getFederationStateStoreService().getStateStoreClient();
     GetSubClusterInfoResponse response = stateStore.getSubCluster(request);
-    Assert.assertNull(response);
+    assertNull(response);
 
     // Validate if sub-cluster is registered
     rm.start();
     String capability = checkSubClusterInfo(SubClusterState.SC_NEW);
-    Assert.assertTrue(capability.isEmpty());
+    assertTrue(capability.isEmpty());
 
     // Heartbeat to see if sub-cluster transitions to running
     FederationStateStoreHeartbeat storeHeartbeat =
@@ -166,7 +170,7 @@ public class TestFederationRMStateStoreService {
     explicitFailover(rm);
 
     capability = checkSubClusterInfo(SubClusterState.SC_NEW);
-    Assert.assertTrue(capability.isEmpty());
+    assertTrue(capability.isEmpty());
 
     // Heartbeat to see if sub-cluster transitions to running
     storeHeartbeat =
@@ -186,10 +190,10 @@ public class TestFederationRMStateStoreService {
 
   private void explicitFailover(MockRM rm) throws IOException {
     rm.getAdminService().transitionToStandby(requestInfo);
-    Assert.assertTrue(rm.getRMContext()
+    assertTrue(rm.getRMContext()
         .getHAServiceState() == HAServiceProtocol.HAServiceState.STANDBY);
     rm.getAdminService().transitionToActive(requestInfo);
-    Assert.assertTrue(rm.getRMContext()
+    assertTrue(rm.getRMContext()
         .getHAServiceState() == HAServiceProtocol.HAServiceState.ACTIVE);
     lastHearbeatTS = 0;
     stateStore = rm.getFederationStateStoreService().getStateStoreClient();
@@ -199,23 +203,23 @@ public class TestFederationRMStateStoreService {
       throws JAXBException {
     ClusterMetricsInfo clusterMetricsInfo = jsonUnmarshaller.unmarshalFromJSON(
         new StringReader(capability), ClusterMetricsInfo.class);
-    Assert.assertEquals(numNodes, clusterMetricsInfo.getTotalNodes());
+    assertEquals(numNodes, clusterMetricsInfo.getTotalNodes());
   }
 
   private String checkSubClusterInfo(SubClusterState state)
       throws YarnException, UnknownHostException {
-    Assert.assertNotNull(stateStore.getSubCluster(request));
+    assertNotNull(stateStore.getSubCluster(request));
     SubClusterInfo response =
         stateStore.getSubCluster(request).getSubClusterInfo();
-    Assert.assertEquals(state, response.getState());
-    Assert.assertTrue(response.getLastHeartBeat() >= lastHearbeatTS);
+    assertEquals(state, response.getState());
+    assertTrue(response.getLastHeartBeat() >= lastHearbeatTS);
     String expectedAddress =
         (response.getClientRMServiceAddress().split(":"))[0];
-    Assert.assertEquals(expectedAddress,
+    assertEquals(expectedAddress,
         (response.getAMRMServiceAddress().split(":"))[0]);
-    Assert.assertEquals(expectedAddress,
+    assertEquals(expectedAddress,
         (response.getRMAdminServiceAddress().split(":"))[0]);
-    Assert.assertEquals(expectedAddress,
+    assertEquals(expectedAddress,
         (response.getRMWebServiceAddress().split(":"))[0]);
     lastHearbeatTS = response.getLastHeartBeat();
     return response.getCapability();
@@ -236,12 +240,12 @@ public class TestFederationRMStateStoreService {
     rm.init(conf);
     stateStore = rm.getFederationStateStoreService().getStateStoreClient();
     GetSubClusterInfoResponse response = stateStore.getSubCluster(request);
-    Assert.assertNull(response);
+    assertNull(response);
 
     // Validate if sub-cluster is registered
     rm.start();
     String capability = checkSubClusterInfo(SubClusterState.SC_NEW);
-    Assert.assertTrue(capability.isEmpty());
+    assertTrue(capability.isEmpty());
 
     // Heartbeat to see if sub-cluster transitions to running
     FederationStateStoreHeartbeat storeHeartbeat =
@@ -250,7 +254,7 @@ public class TestFederationRMStateStoreService {
     capability = checkSubClusterInfo(SubClusterState.SC_RUNNING);
     checkClusterMetricsInfo(capability, 0);
 
-    Assert.assertTrue(logCapture.getOutput().contains(
+    assertTrue(logCapture.getOutput().contains(
         "Started federation membership heartbeat with interval: 300 and initial delay: 10"));
     rm.stop();
   }
@@ -285,16 +289,16 @@ public class TestFederationRMStateStoreService {
          GetApplicationHomeSubClusterRequest.newInstance(appId);
     GetApplicationHomeSubClusterResponse response =
          stateStore.getApplicationHomeSubCluster(appRequest);
-    Assert.assertNotNull(response);
+    assertNotNull(response);
     ApplicationHomeSubCluster appHomeSubCluster = response.getApplicationHomeSubCluster();
-    Assert.assertNotNull(appHomeSubCluster);
-    Assert.assertNotNull(appHomeSubCluster.getApplicationId());
-    Assert.assertEquals(appId, appHomeSubCluster.getApplicationId());
+    assertNotNull(appHomeSubCluster);
+    assertNotNull(appHomeSubCluster.getApplicationId());
+    assertEquals(appId, appHomeSubCluster.getApplicationId());
 
     // clean up the app.
     boolean cleanUpResult =
         stateStoreService.cleanUpFinishApplicationsWithRetries(appId, true);
-    Assert.assertTrue(cleanUpResult);
+    assertTrue(cleanUpResult);
 
     // after clean, the app can no longer be queried from the stateStore.
     LambdaTestUtils.intercept(FederationStateStoreException.class,
@@ -344,10 +348,10 @@ public class TestFederationRMStateStoreService {
         GetApplicationsHomeSubClusterRequest.newInstance(subClusterId);
     GetApplicationsHomeSubClusterResponse allResponse =
         stateStore.getApplicationsHomeSubCluster(allRequest);
-    Assert.assertNotNull(allResponse);
+    assertNotNull(allResponse);
     List<ApplicationHomeSubCluster> appHomeSCLists = allResponse.getAppsHomeSubClusters();
-    Assert.assertNotNull(appHomeSCLists);
-    Assert.assertEquals(3, appHomeSCLists.size());
+    assertNotNull(appHomeSCLists);
+    assertEquals(3, appHomeSCLists.size());
 
     // app04 exists in both RM memory and stateStore.
     ApplicationId appId04 = ApplicationId.newInstance(Time.now(), 4);
@@ -363,7 +367,7 @@ public class TestFederationRMStateStoreService {
       try {
         List<ApplicationHomeSubCluster> subClusters =
             getApplicationsFromStateStore();
-        Assert.assertNotNull(subClusters);
+        assertNotNull(subClusters);
         appsSize = subClusters.size();
       } catch (YarnException e) {
         e.printStackTrace();
@@ -446,11 +450,11 @@ public class TestFederationRMStateStoreService {
 
     // app03 should remain in statestore
     List<ApplicationHomeSubCluster> appHomeScList = getApplicationsFromStateStore();
-    Assert.assertNotNull(appHomeScList);
-    Assert.assertEquals(1, appHomeScList.size());
+    assertNotNull(appHomeScList);
+    assertEquals(1, appHomeScList.size());
     ApplicationHomeSubCluster homeSubCluster = appHomeScList.get(0);
-    Assert.assertNotNull(homeSubCluster);
-    Assert.assertEquals(appId03, homeSubCluster.getApplicationId());
+    assertNotNull(homeSubCluster);
+    assertEquals(appId03, homeSubCluster.getApplicationId());
   }
 
   private void addApplication2StateStore(ApplicationId appId,
@@ -468,9 +472,9 @@ public class TestFederationRMStateStoreService {
         GetApplicationsHomeSubClusterRequest.newInstance(subClusterId);
     GetApplicationsHomeSubClusterResponse allResponse =
         stateStore.getApplicationsHomeSubCluster(allRequest);
-    Assert.assertNotNull(allResponse);
+    assertNotNull(allResponse);
     List<ApplicationHomeSubCluster> appHomeSCLists = allResponse.getAppsHomeSubClusters();
-    Assert.assertNotNull(appHomeSCLists);
+    assertNotNull(appHomeSCLists);
     return appHomeSCLists;
   }
 
@@ -533,25 +537,25 @@ public class TestFederationRMStateStoreService {
         GetSubClusterPolicyConfigurationRequest.newInstance(queue1);
     GetSubClusterPolicyConfigurationResponse response =
         stateStoreService.getPolicyConfiguration(request1);
-    Assert.assertNotNull(response);
+    assertNotNull(response);
 
     SubClusterPolicyConfiguration responsePolicyConf =
         response.getPolicyConfiguration();
-    Assert.assertNotNull(responsePolicyConf);
-    Assert.assertEquals(requestPolicyConf1, responsePolicyConf);
+    assertNotNull(responsePolicyConf);
+    assertEquals(requestPolicyConf1, responsePolicyConf);
 
     // get policy configurations
     GetSubClusterPoliciesConfigurationsRequest policiesRequest1 =
         GetSubClusterPoliciesConfigurationsRequest.newInstance();
     GetSubClusterPoliciesConfigurationsResponse policiesResponse1 =
         stateStoreService.getPoliciesConfigurations(policiesRequest1);
-    Assert.assertNotNull(policiesResponse1);
+    assertNotNull(policiesResponse1);
 
     List<SubClusterPolicyConfiguration> policiesConfigs = policiesResponse1.getPoliciesConfigs();
-    Assert.assertNotNull(policiesConfigs);
-    Assert.assertEquals(2, policiesConfigs.size());
-    Assert.assertTrue(policiesConfigs.contains(requestPolicyConf1));
-    Assert.assertTrue(policiesConfigs.contains(requestPolicyConf2));
+    assertNotNull(policiesConfigs);
+    assertEquals(2, policiesConfigs.size());
+    assertTrue(policiesConfigs.contains(requestPolicyConf1));
+    assertTrue(policiesConfigs.contains(requestPolicyConf2));
   }
 
   public SubClusterPolicyConfiguration getUniformPolicy(String queue)
@@ -596,12 +600,12 @@ public class TestFederationRMStateStoreService {
         GetSubClusterInfoRequest.newInstance(subClusterId1);
     GetSubClusterInfoResponse subClusterResponse =
         stateStoreService.getSubCluster(subClusterRequest);
-    Assert.assertNotNull(subClusterResponse);
+    assertNotNull(subClusterResponse);
 
     // We query subCluster1, we want to get SubClusterInfo of subCluster1
     SubClusterInfo subClusterInfo1Resp = subClusterResponse.getSubClusterInfo();
-    Assert.assertNotNull(subClusterInfo1Resp);
-    Assert.assertEquals(subClusterInfo1, subClusterInfo1Resp);
+    assertNotNull(subClusterInfo1Resp);
+    assertEquals(subClusterInfo1, subClusterInfo1Resp);
 
     // We call the getSubClusters method and filter the Active SubCluster
     // subCluster1 and subCluster2 are just registered, they are in NEW state,
@@ -610,10 +614,10 @@ public class TestFederationRMStateStoreService {
         GetSubClustersInfoRequest.newInstance(true);
     GetSubClustersInfoResponse subClustersInfoResp =
         stateStoreService.getSubClusters(subClustersInfoRequest);
-    Assert.assertNotNull(subClustersInfoResp);
+    assertNotNull(subClustersInfoResp);
     List<SubClusterInfo> subClusterInfos = subClustersInfoResp.getSubClusters();
-    Assert.assertNotNull(subClusterInfos);
-    Assert.assertEquals(0, subClusterInfos.size());
+    assertNotNull(subClusterInfos);
+    assertEquals(0, subClusterInfos.size());
 
     // We let subCluster1 heartbeat and set subCluster1 to Running state
     SubClusterHeartbeatRequest heartbeatRequest =
@@ -621,7 +625,7 @@ public class TestFederationRMStateStoreService {
         "capability");
     SubClusterHeartbeatResponse heartbeatResponse =
         stateStoreService.subClusterHeartbeat(heartbeatRequest);
-    Assert.assertNotNull(heartbeatResponse);
+    assertNotNull(heartbeatResponse);
 
     // We call the getSubClusters method again and filter the Active SubCluster
     // We want to get 1 active SubCluster
@@ -629,10 +633,10 @@ public class TestFederationRMStateStoreService {
         GetSubClustersInfoRequest.newInstance(true);
     GetSubClustersInfoResponse subClustersInfoResp1 =
         stateStoreService.getSubClusters(subClustersInfoRequest1);
-    Assert.assertNotNull(subClustersInfoResp1);
+    assertNotNull(subClustersInfoResp1);
     List<SubClusterInfo> subClusterInfos1 = subClustersInfoResp1.getSubClusters();
-    Assert.assertNotNull(subClusterInfos1);
-    Assert.assertEquals(1, subClusterInfos1.size());
+    assertNotNull(subClusterInfos1);
+    assertEquals(1, subClusterInfos1.size());
   }
 
   private SubClusterInfo createSubClusterInfo(SubClusterId clusterId) {

+ 2 - 2
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/federation/TestFederationStateStoreServiceMetrics.java

@@ -17,11 +17,11 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.federation;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
  * Unit tests for TestFederationStateStoreServiceMetrics.

+ 65 - 64
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/logaggregationstatus/TestRMAppLogAggregationStatus.java

@@ -19,6 +19,9 @@
 package org.apache.hadoop.yarn.server.resourcemanager.logaggregationstatus;
 
 import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
@@ -60,10 +63,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType;
 import org.apache.hadoop.yarn.server.resourcemanager.timelineservice.RMTimelineCollectorManager;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -85,7 +88,7 @@ public class TestRMAppLogAggregationStatus {
     }
   }
 
-  @Before
+  @BeforeEach
   public void setUp() throws Exception {
     InlineDispatcher rmDispatcher = new InlineDispatcher();
 
@@ -120,7 +123,7 @@ public class TestRMAppLogAggregationStatus {
     appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
   }
 
@@ -155,13 +158,13 @@ public class TestRMAppLogAggregationStatus {
     // should be NOT_STARTED
     Map<NodeId, LogAggregationReport> logAggregationStatus =
         rmApp.getLogAggregationReportsForApp();
-    Assert.assertEquals(2, logAggregationStatus.size());
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId1));
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId2));
+    assertEquals(2, logAggregationStatus.size());
+    assertTrue(logAggregationStatus.containsKey(nodeId1));
+    assertTrue(logAggregationStatus.containsKey(nodeId2));
     for (Entry<NodeId, LogAggregationReport> report : logAggregationStatus
       .entrySet()) {
-      Assert.assertEquals(LogAggregationStatus.NOT_START, report.getValue()
-        .getLogAggregationStatus());
+      assertEquals(LogAggregationStatus.NOT_START, report.getValue()
+          .getLogAggregationStatus());
     }
 
     List<LogAggregationReport> node1ReportForApp =
@@ -195,25 +198,24 @@ public class TestRMAppLogAggregationStatus {
     // verify that the log aggregation status for node1, node2
     // has been changed
     logAggregationStatus = rmApp.getLogAggregationReportsForApp();
-    Assert.assertEquals(2, logAggregationStatus.size());
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId1));
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId2));
+    assertEquals(2, logAggregationStatus.size());
+    assertTrue(logAggregationStatus.containsKey(nodeId1));
+    assertTrue(logAggregationStatus.containsKey(nodeId2));
     for (Entry<NodeId, LogAggregationReport> report : logAggregationStatus
       .entrySet()) {
       if (report.getKey().equals(node1.getNodeID())) {
-        Assert.assertEquals(LogAggregationStatus.RUNNING, report.getValue()
-          .getLogAggregationStatus());
-        Assert.assertEquals(messageForNode1_1, report.getValue()
-          .getDiagnosticMessage());
+        assertEquals(LogAggregationStatus.RUNNING, report.getValue()
+            .getLogAggregationStatus());
+        assertEquals(messageForNode1_1, report.getValue()
+            .getDiagnosticMessage());
       } else if (report.getKey().equals(node2.getNodeID())) {
-        Assert.assertEquals(LogAggregationStatus.RUNNING, report.getValue()
-          .getLogAggregationStatus());
-        Assert.assertEquals(messageForNode2_1, report.getValue()
-          .getDiagnosticMessage());
+        assertEquals(LogAggregationStatus.RUNNING, report.getValue()
+            .getLogAggregationStatus());
+        assertEquals(messageForNode2_1, report.getValue()
+            .getDiagnosticMessage());
       } else {
         // should not contain log aggregation report for other nodes
-        Assert
-          .fail("should not contain log aggregation report for other nodes");
+        fail("should not contain log aggregation report for other nodes");
       }
     }
 
@@ -234,26 +236,25 @@ public class TestRMAppLogAggregationStatus {
     // verify that the log aggregation status for node2
     // does not change
     logAggregationStatus = rmApp.getLogAggregationReportsForApp();
-    Assert.assertEquals(2, logAggregationStatus.size());
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId1));
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId2));
+    assertEquals(2, logAggregationStatus.size());
+    assertTrue(logAggregationStatus.containsKey(nodeId1));
+    assertTrue(logAggregationStatus.containsKey(nodeId2));
     for (Entry<NodeId, LogAggregationReport> report : logAggregationStatus
       .entrySet()) {
       if (report.getKey().equals(node1.getNodeID())) {
-        Assert.assertEquals(LogAggregationStatus.RUNNING, report.getValue()
+        assertEquals(LogAggregationStatus.RUNNING, report.getValue()
           .getLogAggregationStatus());
-        Assert.assertEquals(
+        assertEquals(
           messageForNode1_1 + "\n" + messageForNode1_2, report
             .getValue().getDiagnosticMessage());
       } else if (report.getKey().equals(node2.getNodeID())) {
-        Assert.assertEquals(LogAggregationStatus.RUNNING, report.getValue()
+        assertEquals(LogAggregationStatus.RUNNING, report.getValue()
           .getLogAggregationStatus());
-        Assert.assertEquals(messageForNode2_1, report.getValue()
+        assertEquals(messageForNode2_1, report.getValue()
           .getDiagnosticMessage());
       } else {
         // should not contain log aggregation report for other nodes
-        Assert
-          .fail("should not contain log aggregation report for other nodes");
+        fail("should not contain log aggregation report for other nodes");
       }
     }
 
@@ -261,7 +262,7 @@ public class TestRMAppLogAggregationStatus {
     rmApp.handle(new RMAppEvent(appId, RMAppEventType.KILL));
     rmApp.handle(new RMAppEvent(appId, RMAppEventType.ATTEMPT_KILLED));
     rmApp.handle(new RMAppEvent(appId, RMAppEventType.APP_UPDATE_SAVED));
-    Assert.assertEquals(RMAppState.KILLED, rmApp.getState());
+    assertEquals(RMAppState.KILLED, rmApp.getState());
 
     // wait for 1500 ms
     Thread.sleep(1500);
@@ -269,12 +270,12 @@ public class TestRMAppLogAggregationStatus {
     // the log aggregation status for both nodes should be changed
     // to TIME_OUT
     logAggregationStatus = rmApp.getLogAggregationReportsForApp();
-    Assert.assertEquals(2, logAggregationStatus.size());
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId1));
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId2));
+    assertEquals(2, logAggregationStatus.size());
+    assertTrue(logAggregationStatus.containsKey(nodeId1));
+    assertTrue(logAggregationStatus.containsKey(nodeId2));
     for (Entry<NodeId, LogAggregationReport> report : logAggregationStatus
       .entrySet()) {
-      Assert.assertEquals(LogAggregationStatus.TIME_OUT, report.getValue()
+      assertEquals(LogAggregationStatus.TIME_OUT, report.getValue()
         .getLogAggregationStatus());
     }
 
@@ -298,13 +299,13 @@ public class TestRMAppLogAggregationStatus {
         node1ReportForApp3));
 
     logAggregationStatus = rmApp.getLogAggregationReportsForApp();
-    Assert.assertEquals(2, logAggregationStatus.size());
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId1));
-    Assert.assertTrue(logAggregationStatus.containsKey(nodeId2));
+    assertEquals(2, logAggregationStatus.size());
+    assertTrue(logAggregationStatus.containsKey(nodeId1));
+    assertTrue(logAggregationStatus.containsKey(nodeId2));
     for (Entry<NodeId, LogAggregationReport> report : logAggregationStatus
       .entrySet()) {
       if (report.getKey().equals(node1.getNodeID())) {
-        Assert.assertEquals(LogAggregationStatus.SUCCEEDED, report.getValue()
+        assertEquals(LogAggregationStatus.SUCCEEDED, report.getValue()
           .getLogAggregationStatus());
         StringBuilder builder = new StringBuilder();
         for (int i = 0; i < 9; i ++) {
@@ -312,15 +313,14 @@ public class TestRMAppLogAggregationStatus {
           builder.append("\n");
         }
         builder.append("test_message_" + 9);
-        Assert.assertEquals(builder.toString(), report.getValue()
+        assertEquals(builder.toString(), report.getValue()
           .getDiagnosticMessage());
       } else if (report.getKey().equals(node2.getNodeID())) {
-        Assert.assertEquals(LogAggregationStatus.TIME_OUT, report.getValue()
+        assertEquals(LogAggregationStatus.TIME_OUT, report.getValue()
           .getLogAggregationStatus());
       } else {
         // should not contain log aggregation report for other nodes
-        Assert
-          .fail("should not contain log aggregation report for other nodes");
+        fail("should not contain log aggregation report for other nodes");
       }
     }
 
@@ -340,17 +340,18 @@ public class TestRMAppLogAggregationStatus {
     node2ReportForApp2.add(report2_3);
     node2.handle(new RMNodeStatusEvent(node2.getNodeID(), nodeStatus2,
         node2ReportForApp2));
-    Assert.assertEquals(LogAggregationStatus.FAILED,
+    assertEquals(LogAggregationStatus.FAILED,
       rmApp.getLogAggregationStatusForAppReport());
     logAggregationStatus = rmApp.getLogAggregationReportsForApp();
-    Assert.assertTrue(logAggregationStatus.size() == 1);
-    Assert.assertTrue(logAggregationStatus.containsKey(node2.getNodeID()));
-    Assert.assertTrue(!logAggregationStatus.containsKey(node1.getNodeID()));
-    Assert.assertEquals("Fail_Message",
+    assertTrue(logAggregationStatus.size() == 1);
+    assertTrue(logAggregationStatus.containsKey(node2.getNodeID()));
+    assertTrue(!logAggregationStatus.containsKey(node1.getNodeID()));
+    assertEquals("Fail_Message",
       ((RMAppImpl)rmApp).getLogAggregationFailureMessagesForNM(nodeId2));
   }
 
-  @Test (timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testGetLogAggregationStatusForAppReport() {
     YarnConfiguration conf = new YarnConfiguration();
 
@@ -358,7 +359,7 @@ public class TestRMAppLogAggregationStatus {
     conf.setBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED, false);
     RMAppImpl rmApp = (RMAppImpl)createRMApp(conf);
     // The log aggregation status should be DISABLED.
-    Assert.assertEquals(LogAggregationStatus.DISABLED,
+    assertEquals(LogAggregationStatus.DISABLED,
       rmApp.getLogAggregationStatusForAppReport());
 
     // Enable the log aggregation
@@ -367,7 +368,7 @@ public class TestRMAppLogAggregationStatus {
     // If we do not know any NodeManagers for this application , and
     // the log aggregation is enabled, the log aggregation status will
     // return NOT_START
-    Assert.assertEquals(LogAggregationStatus.NOT_START,
+    assertEquals(LogAggregationStatus.NOT_START,
       rmApp.getLogAggregationStatusForAppReport());
 
     NodeId nodeId1 = NodeId.newInstance("localhost", 1111);
@@ -385,7 +386,7 @@ public class TestRMAppLogAggregationStatus {
       rmApp.getApplicationId(), LogAggregationStatus.NOT_START, ""));
     rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance(
       rmApp.getApplicationId(), LogAggregationStatus.NOT_START, ""));
-    Assert.assertEquals(LogAggregationStatus.NOT_START,
+    assertEquals(LogAggregationStatus.NOT_START,
       rmApp.getLogAggregationStatusForAppReport());
 
     rmApp.aggregateLogReport(nodeId1, LogAggregationReport.newInstance(
@@ -396,11 +397,11 @@ public class TestRMAppLogAggregationStatus {
       rmApp.getApplicationId(), LogAggregationStatus.SUCCEEDED, ""));
     rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance(
       rmApp.getApplicationId(), LogAggregationStatus.SUCCEEDED, ""));
-    Assert.assertEquals(LogAggregationStatus.RUNNING,
+    assertEquals(LogAggregationStatus.RUNNING,
       rmApp.getLogAggregationStatusForAppReport());
 
     rmApp.handle(new RMAppEvent(rmApp.getApplicationId(), RMAppEventType.KILL));
-    Assert.assertTrue(RMAppImpl.isAppInFinalState(rmApp));
+    assertTrue(RMAppImpl.isAppInFinalState(rmApp));
 
     // If at least of one log aggregation status for one NM is TIME_OUT,
     // others are SUCCEEDED, the log aggregation status for this app will
@@ -413,7 +414,7 @@ public class TestRMAppLogAggregationStatus {
       rmApp.getApplicationId(), LogAggregationStatus.SUCCEEDED, ""));
     rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance(
       rmApp.getApplicationId(), LogAggregationStatus.SUCCEEDED, ""));
-    Assert.assertEquals(LogAggregationStatus.TIME_OUT,
+    assertEquals(LogAggregationStatus.TIME_OUT,
       rmApp.getLogAggregationStatusForAppReport());
 
     rmApp = (RMAppImpl)createRMApp(conf);
@@ -429,7 +430,7 @@ public class TestRMAppLogAggregationStatus {
       rmApp.getApplicationId(), LogAggregationStatus.SUCCEEDED, ""));
     rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance(
       rmApp.getApplicationId(), LogAggregationStatus.SUCCEEDED, ""));
-    Assert.assertEquals(LogAggregationStatus.SUCCEEDED,
+    assertEquals(LogAggregationStatus.SUCCEEDED,
       rmApp.getLogAggregationStatusForAppReport());
 
     rmApp = (RMAppImpl)createRMApp(conf);
@@ -443,7 +444,7 @@ public class TestRMAppLogAggregationStatus {
       rmApp.getApplicationId(), LogAggregationStatus.NOT_START, ""));
     rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance(
       rmApp.getApplicationId(), LogAggregationStatus.NOT_START, ""));
-    Assert.assertEquals(LogAggregationStatus.RUNNING,
+    assertEquals(LogAggregationStatus.RUNNING,
       rmApp.getLogAggregationStatusForAppReport());
 
     // If the log aggregation status for at least one of NMs
@@ -458,7 +459,7 @@ public class TestRMAppLogAggregationStatus {
     rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance(
       rmApp.getApplicationId(), LogAggregationStatus.RUNNING_WITH_FAILURE,
       ""));
-    Assert.assertEquals(LogAggregationStatus.RUNNING_WITH_FAILURE,
+    assertEquals(LogAggregationStatus.RUNNING_WITH_FAILURE,
       rmApp.getLogAggregationStatusForAppReport());
 
     // For node4, the previous log aggregation status is RUNNING_WITH_FAILURE,
@@ -472,11 +473,11 @@ public class TestRMAppLogAggregationStatus {
       rmApp.getApplicationId(), LogAggregationStatus.NOT_START, ""));
     rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance(
       rmApp.getApplicationId(), LogAggregationStatus.RUNNING, ""));
-    Assert.assertEquals(LogAggregationStatus.RUNNING_WITH_FAILURE,
+    assertEquals(LogAggregationStatus.RUNNING_WITH_FAILURE,
       rmApp.getLogAggregationStatusForAppReport());
 
     rmApp.handle(new RMAppEvent(rmApp.getApplicationId(), RMAppEventType.KILL));
-    Assert.assertTrue(RMAppImpl.isAppInFinalState(rmApp));
+    assertTrue(RMAppImpl.isAppInFinalState(rmApp));
     // If at least of one log aggregation status for one NM is FAILED,
     // others are either SUCCEEDED or TIME_OUT, and this application is
     // at the final state, the log aggregation status for this app
@@ -489,7 +490,7 @@ public class TestRMAppLogAggregationStatus {
       rmApp.getApplicationId(), LogAggregationStatus.FAILED, ""));
     rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance(
       rmApp.getApplicationId(), LogAggregationStatus.FAILED, ""));
-    Assert.assertEquals(LogAggregationStatus.FAILED,
+    assertEquals(LogAggregationStatus.FAILED,
       rmApp.getLogAggregationStatusForAppReport());
 
   }

+ 42 - 35
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestCombinedSystemMetricsPublisher.java

@@ -18,8 +18,11 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.metrics;
 
-import static org.junit.Assert.assertEquals;
-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.assertNull;
+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.when;
 
@@ -62,8 +65,8 @@ import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineW
 import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter;
 import org.apache.hadoop.yarn.util.TimelineServiceHelper;
 import org.apache.hadoop.yarn.util.timeline.TimelineUtils;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 /**
  * Tests that a CombinedSystemMetricsPublisher publishes metrics for timeline
@@ -132,18 +135,18 @@ public class TestCombinedSystemMetricsPublisher {
         new ArrayList<SystemMetricsPublisher>();
 
     if (YarnConfiguration.timelineServiceV1Enabled(conf)) {
-      Assert.assertTrue(enableV1);
+      assertTrue(enableV1);
       publisherV1 = new TimelineServiceV1Publisher();
       publishers.add(publisherV1);
       publisherV1.init(conf);
       publisherV1.start();
     } else {
-      Assert.assertFalse(enableV1);
+      assertFalse(enableV1);
       publisherV1 = null;
     }
 
     if (YarnConfiguration.timelineServiceV2Enabled(conf)) {
-      Assert.assertTrue(enableV2);
+      assertTrue(enableV2);
       publisherV2 = new TimelineServiceV2Publisher(
           rmTimelineCollectorManager) {
         @Override
@@ -155,7 +158,7 @@ public class TestCombinedSystemMetricsPublisher {
       publisherV2.init(conf);
       publisherV2.start();
     } else {
-      Assert.assertFalse(enableV2);
+      assertFalse(enableV2);
       publisherV2 = null;
     }
 
@@ -220,7 +223,7 @@ public class TestCombinedSystemMetricsPublisher {
                 testRootDir.getCanonicalPath());
       } catch (IOException e) {
         e.printStackTrace();
-        Assert.fail("Exception while setting the " +
+        fail("Exception while setting the " +
             "TIMELINE_SERVICE_STORAGE_DIR_ROOT ");
       }
     }
@@ -246,28 +249,33 @@ public class TestCombinedSystemMetricsPublisher {
     testCleanup();
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testTimelineServiceEventPublishingV1V2Enabled()
       throws Exception {
     runTest(true, true);
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testTimelineServiceEventPublishingV1Enabled() throws Exception {
     runTest(true, false);
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testTimelineServiceEventPublishingV2Enabled() throws Exception {
     runTest(false, true);
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testTimelineServiceEventPublishingNoService() throws Exception {
     runTest(false, false);
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testTimelineServiceConfiguration()
       throws Exception {
     Configuration config = new Configuration(false);
@@ -275,21 +283,21 @@ public class TestCombinedSystemMetricsPublisher {
     config.set(YarnConfiguration.TIMELINE_SERVICE_VERSIONS, "2.0,1.5");
     config.set(YarnConfiguration.TIMELINE_SERVICE_VERSION, "2.0");
 
-    Assert.assertTrue(YarnConfiguration.timelineServiceV2Enabled(config));
-    Assert.assertTrue(YarnConfiguration.timelineServiceV15Enabled(config));
-    Assert.assertTrue(YarnConfiguration.timelineServiceV1Enabled(config));
+    assertTrue(YarnConfiguration.timelineServiceV2Enabled(config));
+    assertTrue(YarnConfiguration.timelineServiceV15Enabled(config));
+    assertTrue(YarnConfiguration.timelineServiceV1Enabled(config));
 
     config.set(YarnConfiguration.TIMELINE_SERVICE_VERSIONS, "2.0,1");
     config.set(YarnConfiguration.TIMELINE_SERVICE_VERSION, "1.5");
-    Assert.assertTrue(YarnConfiguration.timelineServiceV2Enabled(config));
-    Assert.assertFalse(YarnConfiguration.timelineServiceV15Enabled(config));
-    Assert.assertTrue(YarnConfiguration.timelineServiceV1Enabled(config));
+    assertTrue(YarnConfiguration.timelineServiceV2Enabled(config));
+    assertFalse(YarnConfiguration.timelineServiceV15Enabled(config));
+    assertTrue(YarnConfiguration.timelineServiceV1Enabled(config));
 
     config.set(YarnConfiguration.TIMELINE_SERVICE_VERSIONS, "2.0");
     config.set(YarnConfiguration.TIMELINE_SERVICE_VERSION, "1.5");
-    Assert.assertTrue(YarnConfiguration.timelineServiceV2Enabled(config));
-    Assert.assertFalse(YarnConfiguration.timelineServiceV15Enabled(config));
-    Assert.assertFalse(YarnConfiguration.timelineServiceV1Enabled(config));
+    assertTrue(YarnConfiguration.timelineServiceV2Enabled(config));
+    assertFalse(YarnConfiguration.timelineServiceV15Enabled(config));
+    assertFalse(YarnConfiguration.timelineServiceV1Enabled(config));
   }
 
   private void publishEvents(boolean v1Enabled, boolean v2Enabled) {
@@ -326,7 +334,7 @@ public class TestCombinedSystemMetricsPublisher {
           store.getEntity(appAttemptId.toString(),
               AppAttemptMetricsConstants.ENTITY_TYPE,
               EnumSet.allOf(Field.class));
-      Assert.assertNull(entity);
+      assertNull(entity);
       return;
     }
 
@@ -349,19 +357,18 @@ public class TestCombinedSystemMetricsPublisher {
       } else if (event.getEventType().equals(
           AppAttemptMetricsConstants.FINISHED_EVENT_TYPE)) {
         hasFinishedEvent = true;
-        Assert.assertEquals(
+        assertEquals(
             FinalApplicationStatus.UNDEFINED.toString(),
             event.getEventInfo().get(
                 AppAttemptMetricsConstants.FINAL_STATUS_INFO));
-        Assert.assertEquals(
+        assertEquals(
             YarnApplicationAttemptState.FINISHED.toString(),
             event.getEventInfo().get(
                 AppAttemptMetricsConstants.STATE_INFO));
       }
-      Assert
-      .assertEquals(appAttemptId.toString(), entity.getEntityId());
+      assertEquals(appAttemptId.toString(), entity.getEntityId());
     }
-    Assert.assertTrue(hasRegisteredEvent && hasFinishedEvent);
+    assertTrue(hasRegisteredEvent && hasFinishedEvent);
   }
 
   private void validateV2(boolean v2Enabled) throws Exception {
@@ -370,13 +377,13 @@ public class TestCombinedSystemMetricsPublisher {
             + TimelineEntityType.YARN_APPLICATION_ATTEMPT + "/";
 
     File entityFolder = new File(outputDirApp);
-    Assert.assertEquals(v2Enabled, entityFolder.isDirectory());
+    assertEquals(v2Enabled, entityFolder.isDirectory());
 
     if (v2Enabled) {
       String timelineServiceFileName = appAttemptId.toString()
           + FileSystemTimelineWriterImpl.TIMELINE_SERVICE_STORAGE_EXTENSION;
       File entityFile = new File(outputDirApp, timelineServiceFileName);
-      Assert.assertTrue(entityFile.exists());
+      assertTrue(entityFile.exists());
       long idPrefix = TimelineServiceHelper
           .invertLong(appAttemptId.getAttemptId());
       verifyEntity(entityFile, 2,
@@ -414,10 +421,10 @@ public class TestCombinedSystemMetricsPublisher {
     } finally {
       reader.close();
     }
-    assertEquals("Expected " + expectedEvents + " events to be published",
-        expectedEvents, count);
-    assertEquals("Expected " + expectedMetrics + " metrics is incorrect",
-        expectedMetrics, metricsCount);
+    assertEquals(expectedEvents, count,
+        "Expected " + expectedEvents + " events to be published");
+    assertEquals(expectedMetrics, metricsCount,
+        "Expected " + expectedMetrics + " metrics is incorrect");
   }
 
   private String getTimelineEntityDir() {

+ 124 - 100
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisher.java

@@ -18,6 +18,7 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.metrics;
 
+
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -27,13 +28,10 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import org.apache.hadoop.ipc.CallerContext;
 import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
@@ -72,15 +70,16 @@ import org.apache.hadoop.yarn.server.timeline.recovery.MemoryTimelineStateStore;
 import org.apache.hadoop.yarn.server.timeline.recovery.TimelineStateStore;
 
 import static org.assertj.core.api.Assertions.assertThat;
+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.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(Parameterized.class)
 public class TestSystemMetricsPublisher {
 
-  @Parameters
   public static Collection<Object[]> data() {
-    return Arrays.asList(new Object[][] {{false, 0}, {true, 1}});
+    return Arrays.asList(new Object[][]{{false, 0}, {true, 1}});
   }
 
   private static ApplicationHistoryServer timelineServer;
@@ -90,13 +89,13 @@ public class TestSystemMetricsPublisher {
   private boolean rmTimelineServerV1PublisherBatchEnabled;
   private int rmTimelineServerV1PublisherInterval;
 
-  public TestSystemMetricsPublisher(boolean rmTimelineServerV1PublisherBatchEnabled,
-      int rmTimelineServerV1PublisherInterval) {
-    this.rmTimelineServerV1PublisherBatchEnabled = rmTimelineServerV1PublisherBatchEnabled;
-    this.rmTimelineServerV1PublisherInterval = rmTimelineServerV1PublisherInterval;
+  private void initTestSystemMetricsPublisher(boolean pRmTimelineServerV1PublisherBatchEnabled,
+      int pRmTimelineServerV1PublisherInterval) throws Exception {
+    this.rmTimelineServerV1PublisherBatchEnabled = pRmTimelineServerV1PublisherBatchEnabled;
+    this.rmTimelineServerV1PublisherInterval = pRmTimelineServerV1PublisherInterval;
+    setup();
   }
 
-  @Before
   public void setup() throws Exception {
     YarnConfiguration conf = new YarnConfiguration();
     conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
@@ -123,7 +122,7 @@ public class TestSystemMetricsPublisher {
     metricsPublisher.start();
   }
 
-  @After
+  @AfterEach
   public void tearDown() throws Exception {
     if (metricsPublisher != null) {
       metricsPublisher.stop();
@@ -133,8 +132,14 @@ public class TestSystemMetricsPublisher {
     }
   }
 
-  @Test(timeout = 10000)
-  public void testPublishApplicationMetrics() throws Exception {
+  @ParameterizedTest
+  @MethodSource("data")
+  @Timeout(value = 10)
+  @SuppressWarnings("checkstyle:methodlength")
+  public void testPublishApplicationMetrics(boolean pRmTimelineServerV1PublisherBatchEnabled,
+      int pRmTimelineServerV1PublisherInterval) throws Exception {
+    initTestSystemMetricsPublisher(pRmTimelineServerV1PublisherBatchEnabled,
+        pRmTimelineServerV1PublisherInterval);
     long stateUpdateTimeStamp = System.currentTimeMillis();
     for (int i = 1; i <= 2; ++i) {
       ApplicationId appId = ApplicationId.newInstance(0, i);
@@ -178,92 +183,90 @@ public class TestSystemMetricsPublisher {
         // ensure Five events are both published before leaving the loop
       } while (entity == null || entity.getEvents().size() < 6);
       // verify all the fields
-      Assert.assertEquals(ApplicationMetricsConstants.ENTITY_TYPE,
+      assertEquals(ApplicationMetricsConstants.ENTITY_TYPE,
           entity.getEntityType());
-      Assert
-          .assertEquals(app.getApplicationId().toString(), entity.getEntityId());
-      Assert
-          .assertEquals(
+      assertEquals(app.getApplicationId().toString(), entity.getEntityId());
+      assertEquals(
               app.getName(),
               entity.getOtherInfo().get(
                   ApplicationMetricsConstants.NAME_ENTITY_INFO));
       if (i != 1) {
-        Assert.assertEquals(
+        assertEquals(
             app.getQueue(),
             entity.getOtherInfo().get(
                 ApplicationMetricsConstants.QUEUE_ENTITY_INFO));
       }
 
-      Assert.assertEquals(
+      assertEquals(
           app.getApplicationSubmissionContext().getUnmanagedAM(),
           entity.getOtherInfo().get(
               ApplicationMetricsConstants.UNMANAGED_APPLICATION_ENTITY_INFO));
 
       if (i != 1) {
-        Assert.assertEquals(
+        assertEquals(
             app.getApplicationSubmissionContext().getPriority().getPriority(),
             entity.getOtherInfo().get(
                 ApplicationMetricsConstants.APPLICATION_PRIORITY_INFO));
       }
 
-      Assert.assertEquals(app.getAmNodeLabelExpression(), entity.getOtherInfo()
+      assertEquals(app.getAmNodeLabelExpression(), entity.getOtherInfo()
           .get(ApplicationMetricsConstants.AM_NODE_LABEL_EXPRESSION));
 
-      Assert.assertEquals(
+      assertEquals(
           app.getApplicationSubmissionContext().getNodeLabelExpression(),
           entity.getOtherInfo()
               .get(ApplicationMetricsConstants.APP_NODE_LABEL_EXPRESSION));
 
-      Assert
-          .assertEquals(
+
+      assertEquals(
               app.getUser(),
               entity.getOtherInfo().get(
                   ApplicationMetricsConstants.USER_ENTITY_INFO));
-      Assert
-          .assertEquals(
+
+      assertEquals(
               app.getApplicationType(),
               entity.getOtherInfo().get(
                   ApplicationMetricsConstants.TYPE_ENTITY_INFO));
-      Assert.assertEquals(app.getSubmitTime(),
+      assertEquals(app.getSubmitTime(),
           entity.getOtherInfo().get(
               ApplicationMetricsConstants.SUBMITTED_TIME_ENTITY_INFO));
-      Assert.assertTrue(verifyAppTags(app.getApplicationTags(),
+      assertTrue(verifyAppTags(app.getApplicationTags(),
           entity.getOtherInfo()));
       if (i == 1) {
-        Assert.assertEquals("uers1,user2",
+        assertEquals("uers1,user2",
             entity.getOtherInfo().get(
                 ApplicationMetricsConstants.APP_VIEW_ACLS_ENTITY_INFO));
 
-        Assert.assertEquals(
+        assertEquals(
             app.getApplicationSubmissionContext().getAMContainerSpec()
                 .getCommands(),
             entity.getOtherInfo()
                 .get(ApplicationMetricsConstants.AM_CONTAINER_LAUNCH_COMMAND));
       } else {
-        Assert.assertEquals(
+        assertEquals(
             "",
             entity.getOtherInfo().get(
                 ApplicationMetricsConstants.APP_VIEW_ACLS_ENTITY_INFO));
-        Assert.assertEquals(
+        assertEquals(
             app.getRMAppMetrics().getMemorySeconds(),
             Long.parseLong(entity.getOtherInfo()
                 .get(ApplicationMetricsConstants.APP_MEM_METRICS).toString()));
-        Assert.assertEquals(
+        assertEquals(
             app.getRMAppMetrics().getVcoreSeconds(),
             Long.parseLong(entity.getOtherInfo()
                 .get(ApplicationMetricsConstants.APP_CPU_METRICS).toString()));
-        Assert.assertEquals(
+        assertEquals(
             app.getRMAppMetrics().getPreemptedMemorySeconds(),
             Long.parseLong(entity.getOtherInfo()
                 .get(ApplicationMetricsConstants.APP_MEM_PREEMPT_METRICS)
                 .toString()));
-        Assert.assertEquals(
+        assertEquals(
             app.getRMAppMetrics().getPreemptedVcoreSeconds(),
             Long.parseLong(entity.getOtherInfo()
                 .get(ApplicationMetricsConstants.APP_CPU_PREEMPT_METRICS)
                 .toString()));
       }
-      Assert.assertEquals("context", entity.getOtherInfo()
+      assertEquals("context", entity.getOtherInfo()
           .get(ApplicationMetricsConstants.YARN_APP_CALLER_CONTEXT));
       boolean hasCreatedEvent = false;
       boolean hasLaunchedEvent = false;
@@ -275,35 +278,35 @@ public class TestSystemMetricsPublisher {
         if (event.getEventType().equals(
             ApplicationMetricsConstants.CREATED_EVENT_TYPE)) {
           hasCreatedEvent = true;
-          Assert.assertEquals(app.getStartTime(), event.getTimestamp());
+          assertEquals(app.getStartTime(), event.getTimestamp());
         } else if (event.getEventType().equals(
             ApplicationMetricsConstants.LAUNCHED_EVENT_TYPE)) {
           hasLaunchedEvent = true;
-          Assert.assertEquals(app.getLaunchTime(), event.getTimestamp());
+          assertEquals(app.getLaunchTime(), event.getTimestamp());
         } else if (event.getEventType().equals(
             ApplicationMetricsConstants.FINISHED_EVENT_TYPE)) {
           hasFinishedEvent = true;
-          Assert.assertEquals(app.getFinishTime(), event.getTimestamp());
-          Assert.assertEquals(
+          assertEquals(app.getFinishTime(), event.getTimestamp());
+          assertEquals(
               app.getDiagnostics().toString(),
               event.getEventInfo().get(
                   ApplicationMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO));
-          Assert.assertEquals(
+          assertEquals(
               app.getFinalApplicationStatus().toString(),
               event.getEventInfo().get(
                   ApplicationMetricsConstants.FINAL_STATUS_EVENT_INFO));
-          Assert.assertEquals(YarnApplicationState.FINISHED.toString(), event
+          assertEquals(YarnApplicationState.FINISHED.toString(), event
               .getEventInfo().get(ApplicationMetricsConstants.STATE_EVENT_INFO));
         } else if (event.getEventType().equals(
             ApplicationMetricsConstants.UPDATED_EVENT_TYPE)) {
           hasUpdatedEvent = true;
-          Assert.assertEquals(4L, event.getTimestamp());
+          assertEquals(4L, event.getTimestamp());
           if (1 == i) {
-            Assert.assertEquals(
+            assertEquals(
                 1,
                 event.getEventInfo().get(
                     ApplicationMetricsConstants.APPLICATION_PRIORITY_INFO));
-            Assert.assertEquals(
+            assertEquals(
                 "new test queue",
                 event.getEventInfo().get(
                     ApplicationMetricsConstants.QUEUE_ENTITY_INFO));
@@ -311,28 +314,34 @@ public class TestSystemMetricsPublisher {
         } else if (event.getEventType().equals(
             ApplicationMetricsConstants.ACLS_UPDATED_EVENT_TYPE)) {
           hasACLsUpdatedEvent = true;
-          Assert.assertEquals(4L, event.getTimestamp());
+          assertEquals(4L, event.getTimestamp());
         } else if (event.getEventType().equals(
               ApplicationMetricsConstants.STATE_UPDATED_EVENT_TYPE)) {
           hasStateUpdateEvent = true;
           assertThat(event.getTimestamp()).isEqualTo(stateUpdateTimeStamp);
-          Assert.assertEquals(YarnApplicationState.RUNNING.toString(), event
+          assertEquals(YarnApplicationState.RUNNING.toString(), event
               .getEventInfo().get(
                    ApplicationMetricsConstants.STATE_EVENT_INFO));
         }
       }
       // Do assertTrue verification separately for easier debug
-      Assert.assertTrue(hasCreatedEvent);
-      Assert.assertTrue(hasLaunchedEvent);
-      Assert.assertTrue(hasFinishedEvent);
-      Assert.assertTrue(hasACLsUpdatedEvent);
-      Assert.assertTrue(hasUpdatedEvent);
-      Assert.assertTrue(hasStateUpdateEvent);
+      assertTrue(hasCreatedEvent);
+      assertTrue(hasLaunchedEvent);
+      assertTrue(hasFinishedEvent);
+      assertTrue(hasACLsUpdatedEvent);
+      assertTrue(hasUpdatedEvent);
+      assertTrue(hasStateUpdateEvent);
     }
   }
 
-  @Test(timeout = 10000)
-  public void testPublishAppAttemptMetricsForUnmanagedAM() throws Exception {
+  @ParameterizedTest
+  @MethodSource("data")
+  @Timeout(value = 10)
+  public void testPublishAppAttemptMetricsForUnmanagedAM(boolean
+      pRmTimelineServerV1PublisherBatchEnabled,
+      int pRmTimelineServerV1PublisherInterval) throws Exception {
+    initTestSystemMetricsPublisher(pRmTimelineServerV1PublisherBatchEnabled,
+        pRmTimelineServerV1PublisherInterval);
     ApplicationAttemptId appAttemptId =
         ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1);
     RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId,true);
@@ -351,8 +360,13 @@ public class TestSystemMetricsPublisher {
     } while (entity == null || entity.getEvents().size() < 2);
   }
 
-  @Test(timeout = 10000)
-  public void testPublishAppAttemptMetrics() throws Exception {
+  @ParameterizedTest
+  @MethodSource("data")
+  @Timeout(value = 10)
+  public void testPublishAppAttemptMetrics(boolean pRmTimelineServerV1PublisherBatchEnabled,
+      int pRmTimelineServerV1PublisherInterval) throws Exception {
+    initTestSystemMetricsPublisher(pRmTimelineServerV1PublisherBatchEnabled,
+        pRmTimelineServerV1PublisherInterval);
     ApplicationAttemptId appAttemptId =
         ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1);
     RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId, false);
@@ -370,10 +384,10 @@ public class TestSystemMetricsPublisher {
       // ensure two events are both published before leaving the loop
     } while (entity == null || entity.getEvents().size() < 2);
     // verify all the fields
-    Assert.assertEquals(AppAttemptMetricsConstants.ENTITY_TYPE,
+    assertEquals(AppAttemptMetricsConstants.ENTITY_TYPE,
         entity.getEntityType());
-    Assert.assertEquals(appAttemptId.toString(), entity.getEntityId());
-    Assert.assertEquals(
+    assertEquals(appAttemptId.toString(), entity.getEntityId());
+    assertEquals(
         appAttemptId.getApplicationId().toString(),
         entity.getPrimaryFilters()
             .get(AppAttemptMetricsConstants.PARENT_PRIMARY_FILTER).iterator()
@@ -384,43 +398,48 @@ public class TestSystemMetricsPublisher {
       if (event.getEventType().equals(
           AppAttemptMetricsConstants.REGISTERED_EVENT_TYPE)) {
         hasRegisteredEvent = true;
-        Assert.assertEquals(appAttempt.getHost(),
+        assertEquals(appAttempt.getHost(),
             event.getEventInfo()
                 .get(AppAttemptMetricsConstants.HOST_INFO));
-        Assert
-            .assertEquals(appAttempt.getRpcPort(),
+        assertEquals(appAttempt.getRpcPort(),
                 event.getEventInfo().get(
                     AppAttemptMetricsConstants.RPC_PORT_INFO));
-        Assert.assertEquals(
+        assertEquals(
             appAttempt.getMasterContainer().getId().toString(),
             event.getEventInfo().get(
                 AppAttemptMetricsConstants.MASTER_CONTAINER_INFO));
       } else if (event.getEventType().equals(
           AppAttemptMetricsConstants.FINISHED_EVENT_TYPE)) {
         hasFinishedEvent = true;
-        Assert.assertEquals(appAttempt.getDiagnostics(), event.getEventInfo()
+        assertEquals(appAttempt.getDiagnostics(), event.getEventInfo()
             .get(AppAttemptMetricsConstants.DIAGNOSTICS_INFO));
-        Assert.assertEquals(appAttempt.getTrackingUrl(), event.getEventInfo()
+        assertEquals(appAttempt.getTrackingUrl(), event.getEventInfo()
             .get(AppAttemptMetricsConstants.TRACKING_URL_INFO));
-        Assert.assertEquals(
+        assertEquals(
             appAttempt.getOriginalTrackingUrl(),
             event.getEventInfo().get(
                 AppAttemptMetricsConstants.ORIGINAL_TRACKING_URL_INFO));
-        Assert.assertEquals(
+        assertEquals(
             FinalApplicationStatus.UNDEFINED.toString(),
             event.getEventInfo().get(
                 AppAttemptMetricsConstants.FINAL_STATUS_INFO));
-        Assert.assertEquals(
+        assertEquals(
             YarnApplicationAttemptState.FINISHED.toString(),
             event.getEventInfo().get(
                 AppAttemptMetricsConstants.STATE_INFO));
       }
     }
-    Assert.assertTrue(hasRegisteredEvent && hasFinishedEvent);
+    assertTrue(hasRegisteredEvent && hasFinishedEvent);
   }
 
-  @Test(timeout = 10000)
-  public void testPublishHostPortInfoOnContainerFinished() throws Exception {
+  @ParameterizedTest
+  @MethodSource("data")
+  @Timeout(value = 10)
+  public void testPublishHostPortInfoOnContainerFinished(
+      boolean pRmTimelineServerV1PublisherBatchEnabled,
+      int pRmTimelineServerV1PublisherInterval) throws Exception {
+    initTestSystemMetricsPublisher(pRmTimelineServerV1PublisherBatchEnabled,
+        pRmTimelineServerV1PublisherInterval);
     ContainerId containerId =
         ContainerId.newContainerId(ApplicationAttemptId.newInstance(
             ApplicationId.newInstance(0, 1), 1), 1);
@@ -433,24 +452,29 @@ public class TestSystemMetricsPublisher {
               ContainerMetricsConstants.ENTITY_TYPE,
               EnumSet.allOf(Field.class));
     } while (entity == null || entity.getEvents().size() < 1);
-    Assert.assertNotNull(entity.getOtherInfo());
-    Assert.assertEquals(2, entity.getOtherInfo().size());
-    Assert.assertNotNull(entity.getOtherInfo().get(
+    assertNotNull(entity.getOtherInfo());
+    assertEquals(2, entity.getOtherInfo().size());
+    assertNotNull(entity.getOtherInfo().get(
         ContainerMetricsConstants.ALLOCATED_HOST_INFO));
-    Assert.assertNotNull(entity.getOtherInfo().get(
+    assertNotNull(entity.getOtherInfo().get(
         ContainerMetricsConstants.ALLOCATED_PORT_INFO));
-    Assert.assertEquals(
+    assertEquals(
         container.getAllocatedNode().getHost(),
         entity.getOtherInfo().get(
             ContainerMetricsConstants.ALLOCATED_HOST_INFO));
-    Assert.assertEquals(
+    assertEquals(
         container.getAllocatedNode().getPort(),
         entity.getOtherInfo().get(
             ContainerMetricsConstants.ALLOCATED_PORT_INFO));
   }
 
-  @Test(timeout = 10000)
-  public void testPublishContainerMetrics() throws Exception {
+  @ParameterizedTest
+  @MethodSource("data")
+  @Timeout(value = 10)
+  public void testPublishContainerMetrics(boolean pRmTimelineServerV1PublisherBatchEnabled,
+      int pRmTimelineServerV1PublisherInterval) throws Exception {
+    initTestSystemMetricsPublisher(pRmTimelineServerV1PublisherBatchEnabled,
+        pRmTimelineServerV1PublisherInterval);
     ContainerId containerId =
         ContainerId.newContainerId(ApplicationAttemptId.newInstance(
             ApplicationId.newInstance(0, 1), 1), 1);
@@ -466,33 +490,33 @@ public class TestSystemMetricsPublisher {
       // ensure two events are both published before leaving the loop
     } while (entity == null || entity.getEvents().size() < 2);
     // verify all the fields
-    Assert.assertEquals(ContainerMetricsConstants.ENTITY_TYPE,
+    assertEquals(ContainerMetricsConstants.ENTITY_TYPE,
         entity.getEntityType());
-    Assert.assertEquals(containerId.toString(), entity.getEntityId());
-    Assert.assertEquals(
+    assertEquals(containerId.toString(), entity.getEntityId());
+    assertEquals(
         containerId.getApplicationAttemptId().toString(),
         entity.getPrimaryFilters()
             .get(ContainerMetricsConstants.PARENT_PRIMARIY_FILTER).iterator()
             .next());
-    Assert.assertEquals(
+    assertEquals(
         container.getAllocatedNode().getHost(),
         entity.getOtherInfo().get(
             ContainerMetricsConstants.ALLOCATED_HOST_INFO));
-    Assert.assertEquals(
+    assertEquals(
         container.getAllocatedNode().getPort(),
         entity.getOtherInfo().get(
             ContainerMetricsConstants.ALLOCATED_PORT_INFO));
-    Assert.assertEquals(container.getAllocatedResource().getMemorySize(),
+    assertEquals(container.getAllocatedResource().getMemorySize(),
         // KeyValueBasedTimelineStore could cast long to integer, need make sure
         // variables for compare have same type.
         ((Integer) entity.getOtherInfo().get(
             ContainerMetricsConstants.ALLOCATED_MEMORY_INFO))
             .longValue());
-    Assert.assertEquals(
+    assertEquals(
         container.getAllocatedResource().getVirtualCores(),
         entity.getOtherInfo().get(
             ContainerMetricsConstants.ALLOCATED_VCORE_INFO));
-    Assert.assertEquals(
+    assertEquals(
         container.getAllocatedPriority().getPriority(),
         entity.getOtherInfo().get(
             ContainerMetricsConstants.ALLOCATED_PRIORITY_INFO));
@@ -502,24 +526,24 @@ public class TestSystemMetricsPublisher {
       if (event.getEventType().equals(
           ContainerMetricsConstants.CREATED_EVENT_TYPE)) {
         hasCreatedEvent = true;
-        Assert.assertEquals(container.getCreationTime(), event.getTimestamp());
+        assertEquals(container.getCreationTime(), event.getTimestamp());
       } else if (event.getEventType().equals(
           ContainerMetricsConstants.FINISHED_EVENT_TYPE)) {
         hasFinishedEvent = true;
-        Assert.assertEquals(container.getFinishTime(), event.getTimestamp());
-        Assert.assertEquals(
+        assertEquals(container.getFinishTime(), event.getTimestamp());
+        assertEquals(
             container.getDiagnosticsInfo(),
             event.getEventInfo().get(
                 ContainerMetricsConstants.DIAGNOSTICS_INFO));
-        Assert.assertEquals(
+        assertEquals(
             container.getContainerExitStatus(),
             event.getEventInfo().get(
                 ContainerMetricsConstants.EXIT_STATUS_INFO));
-        Assert.assertEquals(container.getContainerState().toString(), event
+        assertEquals(container.getContainerState().toString(), event
             .getEventInfo().get(ContainerMetricsConstants.STATE_INFO));
       }
     }
-    Assert.assertTrue(hasCreatedEvent && hasFinishedEvent);
+    assertTrue(hasCreatedEvent && hasFinishedEvent);
   }
 
   private static RMApp createRMApp(ApplicationId appId) {

+ 38 - 36
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/metrics/TestSystemMetricsPublisherForV2.java

@@ -18,9 +18,10 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.metrics;
 
-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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -79,10 +80,10 @@ import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineW
 import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter;
 import org.apache.hadoop.yarn.util.TimelineServiceHelper;
 import org.apache.hadoop.yarn.util.timeline.TimelineUtils;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 public class TestSystemMetricsPublisherForV2 {
 
@@ -100,7 +101,7 @@ public class TestSystemMetricsPublisherForV2 {
 
   private static RMTimelineCollectorManager rmTimelineCollectorManager;
 
-  @BeforeClass
+  @BeforeAll
   public static void setup() throws Exception {
     if (testRootDir.exists()) {
       //cleanup before hand
@@ -136,7 +137,7 @@ public class TestSystemMetricsPublisherForV2 {
     metricsPublisher.start();
   }
 
-  @AfterClass
+  @AfterAll
   public static void tearDown() throws Exception {
     if (testRootDir.exists()) {
       FileContext.getLocalFSFileContext().delete(
@@ -164,9 +165,7 @@ public class TestSystemMetricsPublisherForV2 {
           testRootDir.getCanonicalPath());
     } catch (IOException e) {
       e.printStackTrace();
-      Assert
-          .fail("Exception while setting the " +
-              "TIMELINE_SERVICE_STORAGE_DIR_ROOT ");
+      fail("Exception while setting the TIMELINE_SERVICE_STORAGE_DIR_ROOT ");
     }
     return conf;
   }
@@ -181,9 +180,8 @@ public class TestSystemMetricsPublisherForV2 {
       conf.setBoolean(YarnConfiguration.RM_PUBLISH_CONTAINER_EVENTS_ENABLED,
           YarnConfiguration.DEFAULT_RM_PUBLISH_CONTAINER_EVENTS_ENABLED);
       publisher.init(conf);
-      assertFalse(
-          "Default configuration should not publish container events from RM",
-          publisher.isPublishContainerEvents());
+      assertFalse(publisher.isPublishContainerEvents(),
+          "Default configuration should not publish container events from RM");
 
       publisher.stop();
 
@@ -191,18 +189,19 @@ public class TestSystemMetricsPublisherForV2 {
           mock(RMTimelineCollectorManager.class));
       conf = getTimelineV2Conf();
       publisher.init(conf);
-      assertTrue("Expected to have registered event handlers and set ready to "
-          + "publish events after init",
-          publisher.isPublishContainerEvents());
+      assertTrue(publisher.isPublishContainerEvents(),
+          "Expected to have registered event handlers and set ready to "
+          + "publish events after init");
       publisher.start();
-      assertTrue("Expected to publish container events from RM",
-          publisher.isPublishContainerEvents());
+      assertTrue(publisher.isPublishContainerEvents(),
+          "Expected to publish container events from RM");
     } finally {
       publisher.stop();
     }
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testPublishApplicationMetrics() throws Exception {
     ApplicationId appId = ApplicationId.newInstance(0, 1);
     RMApp app = createAppAndRegister(appId);
@@ -218,19 +217,20 @@ public class TestSystemMetricsPublisherForV2 {
             + "/";
 
     File entityFolder = new File(outputDirApp);
-    Assert.assertTrue(entityFolder.isDirectory());
+    assertTrue(entityFolder.isDirectory());
 
     // file name is <entityId>.thist
     String timelineServiceFileName =
         appId.toString()
             + FileSystemTimelineWriterImpl.TIMELINE_SERVICE_STORAGE_EXTENSION;
     File appFile = new File(outputDirApp, timelineServiceFileName);
-    Assert.assertTrue(appFile.exists());
+    assertTrue(appFile.exists());
     verifyEntity(
         appFile, 4, ApplicationMetricsConstants.CREATED_EVENT_TYPE, 8, 0);
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testPublishAppAttemptMetrics() throws Exception {
     ApplicationId appId = ApplicationId.newInstance(0, 1);
     RMApp app = rmAppsMapInContext.get(appId);
@@ -253,19 +253,20 @@ public class TestSystemMetricsPublisherForV2 {
             + TimelineEntityType.YARN_APPLICATION_ATTEMPT + "/";
 
     File entityFolder = new File(outputDirApp);
-    Assert.assertTrue(entityFolder.isDirectory());
+    assertTrue(entityFolder.isDirectory());
 
     // file name is <entityId>.thist
     String timelineServiceFileName =
         appAttemptId.toString()
             + FileSystemTimelineWriterImpl.TIMELINE_SERVICE_STORAGE_EXTENSION;
     File appFile = new File(outputDirApp, timelineServiceFileName);
-    Assert.assertTrue(appFile.exists());
+    assertTrue(appFile.exists());
     verifyEntity(appFile, 2, AppAttemptMetricsConstants.REGISTERED_EVENT_TYPE,
         0, TimelineServiceHelper.invertLong(appAttemptId.getAttemptId()));
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testPublishContainerMetrics() throws Exception {
     ApplicationId appId = ApplicationId.newInstance(0, 1);
     RMApp app = rmAppsMapInContext.get(appId);
@@ -285,20 +286,21 @@ public class TestSystemMetricsPublisherForV2 {
             + TimelineEntityType.YARN_CONTAINER + "/";
 
     File entityFolder = new File(outputDirApp);
-    Assert.assertTrue(entityFolder.isDirectory());
+    assertTrue(entityFolder.isDirectory());
 
     // file name is <entityId>.thist
     String timelineServiceFileName =
         containerId.toString()
             + FileSystemTimelineWriterImpl.TIMELINE_SERVICE_STORAGE_EXTENSION;
     File appFile = new File(outputDirApp, timelineServiceFileName);
-    Assert.assertTrue(appFile.exists());
+    assertTrue(appFile.exists());
     verifyEntity(appFile, 2,
         ContainerMetricsConstants.CREATED_IN_RM_EVENT_TYPE, 0,
         TimelineServiceHelper.invertLong(containerId.getContainerId()));
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testPutEntityWhenNoCollector() throws Exception {
     // Validating the logs as DrainDispatcher won't throw exception
     class TestAppender extends AppenderSkeleton {
@@ -332,8 +334,8 @@ public class TestSystemMetricsPublisherForV2 {
       metricsPublisher.appCreated(app, app.getStartTime());
       dispatcher.await();
       for (LoggingEvent event : appender.getLog()) {
-        assertFalse("Dispatcher Crashed",
-            event.getRenderedMessage().contains("Error in dispatcher thread"));
+        assertFalse(event.getRenderedMessage().
+            contains("Error in dispatcher thread"), "Dispatcher Crashed");
       }
     } finally {
       logger.removeAppender(appender);
@@ -377,10 +379,10 @@ public class TestSystemMetricsPublisherForV2 {
     } finally {
       reader.close();
     }
-    assertEquals("Expected " + expectedEvents + " events to be published",
-        expectedEvents, count);
-    assertEquals("Expected " + expectedMetrics + " metrics is incorrect",
-        expectedMetrics, metricsCount);
+    assertEquals(expectedEvents, count,
+        "Expected " + expectedEvents + " events to be published");
+    assertEquals(expectedMetrics, metricsCount,
+        "Expected " + expectedMetrics + " metrics is incorrect");
   }
 
   private String getTimelineEntityDir(RMApp app) {

+ 10 - 6
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/TestSchedulingMonitor.java

@@ -27,12 +27,13 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedQueueDeletionPolicy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 import java.util.HashSet;
 import java.util.Set;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
@@ -40,7 +41,8 @@ import static org.mockito.Mockito.when;
 
 public class TestSchedulingMonitor {
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testRMStarts() throws Exception {
     Configuration conf = new YarnConfiguration();
     conf.setBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS, true);
@@ -60,7 +62,8 @@ public class TestSchedulingMonitor {
     rm.close();
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testRMUpdateSchedulingEditPolicy() throws Exception {
     CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
     conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
@@ -95,7 +98,8 @@ public class TestSchedulingMonitor {
     rm.close();
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testRMUpdateAutoCreatedQueueDeletionPolicy() throws Exception {
     CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
     conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,

+ 3 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestPreemptionForQueueWithPriorities.java

@@ -25,8 +25,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.Capacity
 import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.ResourceUtils;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 
@@ -38,7 +38,7 @@ import static org.mockito.Mockito.when;
 
 public class TestPreemptionForQueueWithPriorities
     extends ProportionalCapacityPreemptionPolicyMockFramework {
-  @Before
+  @BeforeEach
   public void setup() {
     resourceCalculator = new DefaultResourceCalculator();
     super.setup();

+ 21 - 20
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java

@@ -19,6 +19,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.service.Service;
+import org.apache.hadoop.test.TestName;
 import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.Container;
@@ -58,10 +59,9 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.ResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.Resources;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 import org.mockito.ArgumentCaptor;
 import org.mockito.ArgumentMatcher;
 import org.mockito.invocation.InvocationOnMock;
@@ -81,11 +81,11 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType.MARK_CONTAINER_FOR_KILLABLE;
 import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType.MARK_CONTAINER_FOR_PREEMPTION;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.argThat;
@@ -148,11 +148,12 @@ public class TestProportionalCapacityPreemptionPolicy {
     public int getValue() {
       return this.value;
     }
-  };  
+  };
 
-  @Rule public TestName name = new TestName();
+  @RegisterExtension
+  private TestName name = new TestName();
 
-  @Before
+  @BeforeEach
   @SuppressWarnings("unchecked")
   public void setup() {
     conf = new CapacitySchedulerConfiguration(new Configuration(false));
@@ -400,8 +401,8 @@ public class TestProportionalCapacityPreemptionPolicy {
     ApplicationAttemptId expectedAttemptOnQueueB = 
         ApplicationAttemptId.newInstance(
             appA.getApplicationId(), appA.getAttemptId());
-    assertTrue("appA should be running on queueB",
-        mCS.getAppsInQueue("queueB").contains(expectedAttemptOnQueueB));
+    assertTrue(mCS.getAppsInQueue("queueB").contains(expectedAttemptOnQueueB),
+        "appA should be running on queueB");
     verify(mDisp, times(10)).handle(argThat(new IsPreemptionRequestFor(appA)));
 
     // Need to call setup() again to reset mDisp
@@ -418,10 +419,10 @@ public class TestProportionalCapacityPreemptionPolicy {
             appC.getApplicationId(), appC.getAttemptId());
     // Now, all of queueB's (appA) over capacity is not preemptable, so neither
     // is queueA's. Verify that capacity is taken from queueE (appC).
-    assertTrue("appB should be running on queueC",
-        mCS.getAppsInQueue("queueC").contains(expectedAttemptOnQueueC));
-    assertTrue("appC should be running on queueE",
-        mCS.getAppsInQueue("queueE").contains(expectedAttemptOnQueueE));
+    assertTrue(mCS.getAppsInQueue("queueC").contains(expectedAttemptOnQueueC),
+        "appB should be running on queueC");
+    assertTrue(mCS.getAppsInQueue("queueE").contains(expectedAttemptOnQueueE),
+        "appC should be running on queueE");
     // Resources should have come from queueE (appC) and neither of queueA's
     // children.
     verify(mDisp, never()).handle(argThat(new IsPreemptionRequestFor(appA)));
@@ -1118,8 +1119,8 @@ public class TestProportionalCapacityPreemptionPolicy {
 
     policy.editSchedule();
 
-    assertFalse("dynamicParent should not be a LeafQueue " +
-        "candidate", policy.getLeafQueueNames().contains("root.dynamicParent"));
+    assertFalse(policy.getLeafQueueNames().contains("root.dynamicParent"),
+        "dynamicParent should not be a LeafQueue candidate");
   }
 
   static class IsPreemptionRequestFor

+ 3 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForNodePartitions.java

@@ -25,8 +25,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.TestPropor
 import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.mockframework.ProportionalCapacityPreemptionPolicyMockFramework;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
 import org.apache.hadoop.yarn.util.resource.ResourceUtils;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.verify;
 
 public class TestProportionalCapacityPreemptionPolicyForNodePartitions
     extends ProportionalCapacityPreemptionPolicyMockFramework {
-  @Before
+  @BeforeEach
   public void setup() {
     super.setup();
     policy = new ProportionalCapacityPreemptionPolicy(rmContext, cs, mClock);

+ 3 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyForReservedContainers.java

@@ -21,8 +21,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity;
 import org.apache.hadoop.yarn.api.records.NodeId;
 import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.mockframework.ProportionalCapacityPreemptionPolicyMockFramework;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.verify;
 
 public class TestProportionalCapacityPreemptionPolicyForReservedContainers
     extends ProportionalCapacityPreemptionPolicyMockFramework {
-  @Before
+  @BeforeEach
   public void setup() {
     super.setup();
     conf.setBoolean(

+ 3 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyInterQueueWithDRF.java

@@ -20,8 +20,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity;
 
 import java.io.IOException;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
 import org.apache.hadoop.yarn.api.records.Resource;
@@ -43,7 +43,7 @@ import static org.mockito.Mockito.when;
 public class TestProportionalCapacityPreemptionPolicyInterQueueWithDRF
     extends ProportionalCapacityPreemptionPolicyMockFramework {
 
-  @Before
+  @BeforeEach
   public void setup() {
     super.setup();
     resourceCalculator = new DominantResourceCalculator();

+ 3 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueue.java

@@ -21,8 +21,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity;
 import java.io.IOException;
 
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.TestProportionalCapacityPreemptionPolicy.IsPreemptionRequestFor;
 import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.mockframework.ProportionalCapacityPreemptionPolicyMockFramework;
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.verify;
 public class TestProportionalCapacityPreemptionPolicyIntraQueue
     extends
     ProportionalCapacityPreemptionPolicyMockFramework {
-  @Before
+  @BeforeEach
   public void setup() {
     super.setup();
     conf.setBoolean(

+ 3 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueFairOrdering.java

@@ -26,8 +26,8 @@ import java.io.IOException;
 
 import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.mockframework.ProportionalCapacityPreemptionPolicyMockFramework;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 /*
  * Test class for testing intra-queue preemption when the fair ordering policy
@@ -35,7 +35,7 @@ import org.junit.Test;
  */
 public class TestProportionalCapacityPreemptionPolicyIntraQueueFairOrdering
     extends ProportionalCapacityPreemptionPolicyMockFramework {
-  @Before
+  @BeforeEach
   public void setup() {
     super.setup();
     conf.setBoolean(

+ 3 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueUserLimit.java

@@ -20,8 +20,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity;
 
 import java.io.IOException;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.mockframework.ProportionalCapacityPreemptionPolicyMockFramework;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.verify;
 public class TestProportionalCapacityPreemptionPolicyIntraQueueUserLimit
     extends
     ProportionalCapacityPreemptionPolicyMockFramework {
-  @Before
+  @BeforeEach
   public void setup() {
     super.setup();
     conf.setBoolean(

+ 3 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyIntraQueueWithDRF.java

@@ -26,8 +26,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.Capacity
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.LeafQueue;
 import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.ResourceUtils;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 
@@ -44,7 +44,7 @@ import static org.mockito.Mockito.when;
 public class TestProportionalCapacityPreemptionPolicyIntraQueueWithDRF
     extends
     ProportionalCapacityPreemptionPolicyMockFramework {
-  @Before
+  @BeforeEach
   public void setup() {
     super.setup();
     conf.setBoolean(

+ 28 - 23
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyMockFramework.java

@@ -23,8 +23,13 @@ import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.mockframew
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNode;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.LeafQueue;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+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;
 
 public class TestProportionalCapacityPreemptionPolicyMockFramework
     extends ProportionalCapacityPreemptionPolicyMockFramework {
@@ -104,7 +109,7 @@ public class TestProportionalCapacityPreemptionPolicyMockFramework
     checkAbsCapacities(cs.getQueue("a2"), "blue", 0.5f, 1f, 0f);
     checkPendingResource(cs.getQueue("a2"), "blue", 200);
     checkPriority(cs.getQueue("a2"), 2);
-    Assert.assertFalse(cs.getQueue("a2").getPreemptionDisabled());
+    assertFalse(cs.getQueue("a2").getPreemptionDisabled());
 
     // b
     checkAbsCapacities(cs.getQueue("b"), "", 0.5f, 1f, 0f);
@@ -114,16 +119,16 @@ public class TestProportionalCapacityPreemptionPolicyMockFramework
     checkAbsCapacities(cs.getQueue("b"), "blue", 0f, 0f, 0f);
     checkPendingResource(cs.getQueue("b"), "blue", 0);
     checkPriority(cs.getQueue("b"), 1);
-    Assert.assertTrue(cs.getQueue("b").getPreemptionDisabled());
+    assertTrue(cs.getQueue("b").getPreemptionDisabled());
 
     // Check ignored partitioned containers in queue
-    Assert.assertEquals(100, ((LeafQueue) cs.getQueue("a1"))
+    assertEquals(100, ((LeafQueue) cs.getQueue("a1"))
         .getIgnoreExclusivityRMContainers().get("blue").size());
 
     // Check applications
-    Assert.assertEquals(2, ((LeafQueue)cs.getQueue("a1")).getApplications().size());
-    Assert.assertEquals(1, ((LeafQueue)cs.getQueue("a2")).getApplications().size());
-    Assert.assertEquals(1, ((LeafQueue)cs.getQueue("b")).getApplications().size());
+    assertEquals(2, ((LeafQueue)cs.getQueue("a1")).getApplications().size());
+    assertEquals(1, ((LeafQueue)cs.getQueue("a2")).getApplications().size());
+    assertEquals(1, ((LeafQueue)cs.getQueue("b")).getApplications().size());
 
     // Check #containers
     FiCaSchedulerApp app1 = getApp("a1", 1);
@@ -131,17 +136,17 @@ public class TestProportionalCapacityPreemptionPolicyMockFramework
     FiCaSchedulerApp app3 = getApp("a2", 3);
     FiCaSchedulerApp app4 = getApp("b", 4);
 
-    Assert.assertEquals(50, app1.getLiveContainers().size());
+    assertEquals(50, app1.getLiveContainers().size());
     checkContainerNodesInApp(app1, 50, "n3");
 
-    Assert.assertEquals(50, app2.getLiveContainers().size());
-    Assert.assertEquals(150, app2.getReservedContainers().size());
+    assertEquals(50, app2.getLiveContainers().size());
+    assertEquals(150, app2.getReservedContainers().size());
     checkContainerNodesInApp(app2, 200, "n2");
 
-    Assert.assertEquals(50, app3.getLiveContainers().size());
+    assertEquals(50, app3.getLiveContainers().size());
     checkContainerNodesInApp(app3, 50, "n3");
 
-    Assert.assertEquals(100, app4.getLiveContainers().size());
+    assertEquals(100, app4.getLiveContainers().size());
     checkContainerNodesInApp(app4, 100, "n1");
   }
 
@@ -236,20 +241,20 @@ public class TestProportionalCapacityPreemptionPolicyMockFramework
     buildEnv(labelsConfig, nodesConfig, queuesConfig, appsConfig);
 
     // Check host resources
-    Assert.assertEquals(3, this.cs.getAllNodes().size());
+    assertEquals(3, this.cs.getAllNodes().size());
     SchedulerNode node1 = cs.getSchedulerNode(NodeId.newInstance("n1", 1));
-    Assert.assertEquals(100, node1.getTotalResource().getMemorySize());
-    Assert.assertEquals(100, node1.getCopiedListOfRunningContainers().size());
-    Assert.assertNull(node1.getReservedContainer());
+    assertEquals(100, node1.getTotalResource().getMemorySize());
+    assertEquals(100, node1.getCopiedListOfRunningContainers().size());
+    assertNull(node1.getReservedContainer());
 
     SchedulerNode node2 = cs.getSchedulerNode(NodeId.newInstance("n2", 1));
-    Assert.assertEquals(0, node2.getTotalResource().getMemorySize());
-    Assert.assertEquals(50, node2.getCopiedListOfRunningContainers().size());
-    Assert.assertNotNull(node2.getReservedContainer());
+    assertEquals(0, node2.getTotalResource().getMemorySize());
+    assertEquals(50, node2.getCopiedListOfRunningContainers().size());
+    assertNotNull(node2.getReservedContainer());
 
     SchedulerNode node3 = cs.getSchedulerNode(NodeId.newInstance("n3", 1));
-    Assert.assertEquals(30, node3.getTotalResource().getMemorySize());
-    Assert.assertEquals(100, node3.getCopiedListOfRunningContainers().size());
-    Assert.assertNull(node3.getReservedContainer());
+    assertEquals(30, node3.getTotalResource().getMemorySize());
+    assertEquals(100, node3.getCopiedListOfRunningContainers().size());
+    assertNull(node3.getReservedContainer());
   }
 }

+ 2 - 2
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicyPreemptToBalance.java

@@ -24,12 +24,12 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import java.io.IOException;
 import java.util.Map;
 import java.util.Set;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;

+ 12 - 12
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/mockframework/ProportionalCapacityPreemptionPolicyMockFramework.java

@@ -49,9 +49,8 @@ import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.ResourceCalculator;
 import org.apache.hadoop.yarn.util.resource.ResourceUtils;
 import org.apache.hadoop.yarn.util.resource.Resources;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 import org.mockito.ArgumentMatcher;
 
 import java.io.IOException;
@@ -62,6 +61,7 @@ import java.util.Map;
 
 import org.apache.hadoop.yarn.event.Event;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -106,7 +106,7 @@ public class ProportionalCapacityPreemptionPolicyMockFramework {
   }
 
   @SuppressWarnings("unchecked")
-  @Before
+  @BeforeEach
   public void setup() {
     resetResourceInformationMap();
 
@@ -147,7 +147,7 @@ public class ProportionalCapacityPreemptionPolicyMockFramework {
     clusterResource = Resource.newInstance(0, 0);
   }
 
-  @After
+  @AfterEach
   public void cleanup() {
     resetResourceInformationMap();
   }
@@ -252,7 +252,7 @@ public class ProportionalCapacityPreemptionPolicyMockFramework {
         num++;
       }
     }
-    Assert.assertEquals(expectedContainersNumber, num);
+    assertEquals(expectedContainersNumber, num);
   }
 
   public FiCaSchedulerApp getApp(String queueName, int appId) {
@@ -268,28 +268,28 @@ public class ProportionalCapacityPreemptionPolicyMockFramework {
   protected void checkAbsCapacities(CSQueue queue, String partition,
       float guaranteed, float max, float used) {
     QueueCapacities qc = queue.getQueueCapacities();
-    Assert.assertEquals(guaranteed, qc.getAbsoluteCapacity(partition),
+    assertEquals(guaranteed, qc.getAbsoluteCapacity(partition),
         ALLOWED_CAPACITY_DELTA);
-    Assert.assertEquals(max, qc.getAbsoluteMaximumCapacity(partition),
+    assertEquals(max, qc.getAbsoluteMaximumCapacity(partition),
         ALLOWED_CAPACITY_DELTA);
-    Assert.assertEquals(used, qc.getAbsoluteUsedCapacity(partition),
+    assertEquals(used, qc.getAbsoluteUsedCapacity(partition),
         ALLOWED_CAPACITY_DELTA);
   }
 
   protected void checkPendingResource(CSQueue queue, String partition,
       int pending) {
     ResourceUsage ru = queue.getQueueResourceUsage();
-    Assert.assertEquals(pending, ru.getPending(partition).getMemorySize());
+    assertEquals(pending, ru.getPending(partition).getMemorySize());
   }
 
   protected void checkPriority(CSQueue queue, int expectedPriority) {
-    Assert.assertEquals(expectedPriority, queue.getPriority().getPriority());
+    assertEquals(expectedPriority, queue.getPriority().getPriority());
   }
 
   protected void checkReservedResource(CSQueue queue, String partition,
       int reserved) {
     ResourceUsage ru = queue.getQueueResourceUsage();
-    Assert.assertEquals(reserved, ru.getReserved(partition).getMemorySize());
+    assertEquals(reserved, ru.getReserved(partition).getMemorySize());
   }
 
   public static class IsPreemptionRequestForQueueAndNode

+ 7 - 5
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/invariants/TestMetricsInvariantChecker.java

@@ -26,10 +26,11 @@ import org.apache.hadoop.yarn.api.records.Resource;
 import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics;
 import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
-import static junit.framework.TestCase.fail;
+import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * This class tests the {@code MetricsInvariantChecker} by running it multiple
@@ -44,7 +45,7 @@ public class TestMetricsInvariantChecker {
   private MetricsInvariantChecker ic;
   private Configuration conf;
 
-  @Before
+  @BeforeEach
   public void setup() {
     this.metricsSystem = DefaultMetricsSystem.instance();
     JvmMetrics.initSingleton("ResourceManager", null);
@@ -61,7 +62,8 @@ public class TestMetricsInvariantChecker {
     ic.init(conf, null, null);
   }
 
-  @Test(timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testManyRuns() {
 
     QueueMetrics qm =

+ 30 - 35
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestFileSystemNodeAttributeStore.java

@@ -18,6 +18,8 @@
 package org.apache.hadoop.yarn.server.resourcemanager.nodelabels;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
@@ -32,10 +34,10 @@ import org.apache.hadoop.yarn.event.InlineDispatcher;
 import org.apache.hadoop.yarn.nodelabels.AttributeValue;
 import org.apache.hadoop.yarn.nodelabels.NodeAttributeStore;
 import org.apache.hadoop.yarn.server.resourcemanager.NodeAttributeTestUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -68,7 +70,7 @@ public class TestFileSystemNodeAttributeStore {
     }
   }
 
-  @Before
+  @BeforeEach
   public void before() throws IOException {
     mgr = new MockNodeAttrbuteManager();
     conf = new Configuration();
@@ -79,7 +81,7 @@ public class TestFileSystemNodeAttributeStore {
     mgr.start();
   }
 
-  @After
+  @AfterEach
   public void after() throws IOException {
     FileSystemNodeAttributeStore fsStore =
         ((FileSystemNodeAttributeStore) mgr.store);
@@ -87,7 +89,8 @@ public class TestFileSystemNodeAttributeStore {
     mgr.stop();
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testEmptyRecoverSkipInternalUdpate() throws Exception {
     // Stop manager
     mgr.stop();
@@ -101,7 +104,8 @@ public class TestFileSystemNodeAttributeStore {
         .internalUpdateAttributesOnNodes(any(), any(), any(), any());
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testRecoverWithMirror() throws Exception {
 
     //------host0----
@@ -126,8 +130,7 @@ public class TestFileSystemNodeAttributeStore {
     // Add node attribute
     mgr.addNodeAttributes(toAddAttributes);
 
-    Assert.assertEquals("host0 size", 2,
-        mgr.getAttributesForNode("host0").size());
+    assertEquals(2, mgr.getAttributesForNode("host0").size(), "host0 size");
     // Add test to remove
     toAddAttributes.clear();
     toAddAttributes.put("host0", ImmutableSet.of(gpu));
@@ -150,10 +153,8 @@ public class TestFileSystemNodeAttributeStore {
     mgr.start();
 
     mgr.getAttributesForNode("host0");
-    Assert.assertEquals("host0 size", 1,
-        mgr.getAttributesForNode("host0").size());
-    Assert.assertEquals("host1 size", 1,
-        mgr.getAttributesForNode("host1").size());
+    assertEquals(1, mgr.getAttributesForNode("host0").size(), "host0 size");
+    assertEquals(1, mgr.getAttributesForNode("host1").size(), "host1 size");
     attrs = mgr.getAttributesForNode("host0");
     assertThat(attrs).hasSize(1);
     assertThat(attrs.keySet().toArray()[0]).isEqualTo(docker);
@@ -177,19 +178,18 @@ public class TestFileSystemNodeAttributeStore {
     mgr = new MockNodeAttrbuteManager();
     mgr.init(conf);
     mgr.start();
-    Assert.assertEquals("host0 size", 1,
-        mgr.getAttributesForNode("host0").size());
-    Assert.assertEquals("host1 size", 2,
-        mgr.getAttributesForNode("host1").size());
+    assertEquals(1, mgr.getAttributesForNode("host0").size(), "host0 size");
+    assertEquals(2, mgr.getAttributesForNode("host1").size(), "host1 size");
     attrs = mgr.getAttributesForNode("host0");
     assertThat(attrs).hasSize(1);
     assertThat(attrs.keySet().toArray()[0]).isEqualTo(gpu);
     attrs = mgr.getAttributesForNode("host1");
-    Assert.assertTrue(attrs.keySet().contains(docker));
-    Assert.assertTrue(attrs.keySet().contains(gpu));
+    assertTrue(attrs.keySet().contains(docker));
+    assertTrue(attrs.keySet().contains(gpu));
   }
 
-  @Test(timeout = 10000)
+  @Test
+  @Timeout(value = 10)
   public void testRecoverFromEditLog() throws Exception {
     NodeAttribute docker = NodeAttribute
         .newInstance(NodeAttribute.PREFIX_CENTRALIZED, "DOCKER",
@@ -208,8 +208,7 @@ public class TestFileSystemNodeAttributeStore {
     // Add node attribute
     mgr.addNodeAttributes(toAddAttributes);
 
-    Assert.assertEquals("host0 size", 2,
-        mgr.getAttributesForNode("host0").size());
+    assertEquals(2, mgr.getAttributesForNode("host0").size(), "host0 size");
 
     //  Increase editlog operation
     for (int i = 0; i < 5; i++) {
@@ -241,10 +240,8 @@ public class TestFileSystemNodeAttributeStore {
     mgr.init(conf);
     mgr.start();
 
-    Assert.assertEquals("host0 size", 1,
-        mgr.getAttributesForNode("host0").size());
-    Assert.assertEquals("host1 size", 2,
-        mgr.getAttributesForNode("host1").size());
+    assertEquals(1, mgr.getAttributesForNode("host0").size(), "host0 size");
+    assertEquals(2, mgr.getAttributesForNode("host1").size(), "host1 size");
 
     toAddAttributes.clear();
     NodeAttribute replaced =
@@ -262,19 +259,17 @@ public class TestFileSystemNodeAttributeStore {
     Map.Entry<NodeAttribute, AttributeValue> entry =
         valueMap.entrySet().iterator().next();
     NodeAttribute attribute = entry.getKey();
-    Assert.assertEquals("host0 size", 1,
-        mgr.getAttributesForNode("host0").size());
-    Assert.assertEquals("host1 size", 2,
-        mgr.getAttributesForNode("host1").size());
+    assertEquals(1, mgr.getAttributesForNode("host0").size(), "host0 size");
+    assertEquals(2, mgr.getAttributesForNode("host1").size(), "host1 size");
     checkNodeAttributeEqual(replaced, attribute);
   }
 
   public void checkNodeAttributeEqual(NodeAttribute atr1, NodeAttribute atr2) {
-    Assert.assertEquals(atr1.getAttributeType(), atr2.getAttributeType());
-    Assert.assertEquals(atr1.getAttributeKey().getAttributeName(),
+    assertEquals(atr1.getAttributeType(), atr2.getAttributeType());
+    assertEquals(atr1.getAttributeKey().getAttributeName(),
         atr2.getAttributeKey().getAttributeName());
-    Assert.assertEquals(atr1.getAttributeKey().getAttributePrefix(),
+    assertEquals(atr1.getAttributeKey().getAttributePrefix(),
         atr2.getAttributeKey().getAttributePrefix());
-    Assert.assertEquals(atr1.getAttributeValue(), atr2.getAttributeValue());
+    assertEquals(atr1.getAttributeValue(), atr2.getAttributeValue());
   }
 }

+ 42 - 40
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestNodeAttributesManager.java

@@ -18,6 +18,9 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.nodelabels;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.util.Sets;
@@ -29,10 +32,9 @@ import org.apache.hadoop.yarn.nodelabels.NodeAttributeStore;
 import org.apache.hadoop.yarn.nodelabels.NodeAttributesManager;
 import org.apache.hadoop.yarn.nodelabels.NodeLabelUtil;
 import org.apache.hadoop.yarn.server.resourcemanager.NodeAttributeTestUtils;
-import org.junit.Test;
-import org.junit.Before;
-import org.junit.After;
-import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.AfterEach;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -51,7 +53,7 @@ public class TestNodeAttributesManager {
   private final static String[] HOSTNAMES =
       new String[] {"host1", "host2", "host3"};
 
-  @Before
+  @BeforeEach
   public void init() throws IOException {
     Configuration conf = new Configuration();
     attributesManager = new NodeAttributesManagerImpl();
@@ -62,7 +64,7 @@ public class TestNodeAttributesManager {
     attributesManager.start();
   }
 
-  @After
+  @AfterEach
   public void cleanUp() {
     if (attributesManager != null) {
       attributesManager.stop();
@@ -102,8 +104,8 @@ public class TestNodeAttributesManager {
     attributesManager.addNodeAttributes(toAddAttributes);
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
 
-    Assert.assertEquals(3, nodeAttributes.size());
-    Assert.assertTrue(sameAttributeSet(toAddAttributes.get(HOSTNAMES[0]),
+    assertEquals(3, nodeAttributes.size());
+    assertTrue(sameAttributeSet(toAddAttributes.get(HOSTNAMES[0]),
         nodeAttributes.keySet()));
 
     // Add 2 attributes to host2
@@ -116,12 +118,12 @@ public class TestNodeAttributesManager {
 
     // Verify host1 attributes are still valid.
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(3, nodeAttributes.size());
+    assertEquals(3, nodeAttributes.size());
 
     // Verify new added host2 attributes are correctly updated.
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[1]);
-    Assert.assertEquals(2, nodeAttributes.size());
-    Assert.assertTrue(sameAttributeSet(toAddAttributes.get(HOSTNAMES[1]),
+    assertEquals(2, nodeAttributes.size());
+    assertTrue(sameAttributeSet(toAddAttributes.get(HOSTNAMES[1]),
         nodeAttributes.keySet()));
 
     // Cluster wide, it only has 3 attributes.
@@ -130,17 +132,17 @@ public class TestNodeAttributesManager {
     //  yarn.test1.io/A3
     Set<NodeAttribute> clusterAttributes = attributesManager
         .getClusterNodeAttributes(Sets.newHashSet(PREFIXES[0]));
-    Assert.assertEquals(3, clusterAttributes.size());
+    assertEquals(3, clusterAttributes.size());
 
     // Query for attributes under a non-exist prefix,
     // ensure it returns an empty set.
     clusterAttributes = attributesManager
         .getClusterNodeAttributes(Sets.newHashSet("non_exist_prefix"));
-    Assert.assertEquals(0, clusterAttributes.size());
+    assertEquals(0, clusterAttributes.size());
 
     // Not provide any prefix, ensure it returns all attributes.
     clusterAttributes = attributesManager.getClusterNodeAttributes(null);
-    Assert.assertEquals(3, clusterAttributes.size());
+    assertEquals(3, clusterAttributes.size());
 
     // Add some other attributes with different prefixes on host1 and host2.
     toAddAttributes.clear();
@@ -160,10 +162,10 @@ public class TestNodeAttributesManager {
     attributesManager.addNodeAttributes(toAddAttributes);
 
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(13, nodeAttributes.size());
+    assertEquals(13, nodeAttributes.size());
 
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[1]);
-    Assert.assertEquals(22, nodeAttributes.size());
+    assertEquals(22, nodeAttributes.size());
   }
 
   @Test
@@ -210,20 +212,20 @@ public class TestNodeAttributesManager {
     attributesManager.addNodeAttributes(toAddAttributes);
 
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(8, nodeAttributes.size());
+    assertEquals(8, nodeAttributes.size());
 
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[1]);
-    Assert.assertEquals(4, nodeAttributes.size());
+    assertEquals(4, nodeAttributes.size());
 
     allAttributesPerPrefix = attributesManager
         .getClusterNodeAttributes(Sets.newHashSet(PREFIXES[0]));
-    Assert.assertEquals(3, allAttributesPerPrefix.size());
+    assertEquals(3, allAttributesPerPrefix.size());
     allAttributesPerPrefix = attributesManager
         .getClusterNodeAttributes(Sets.newHashSet(PREFIXES[1]));
-    Assert.assertEquals(5, allAttributesPerPrefix.size());
+    assertEquals(5, allAttributesPerPrefix.size());
     allAttributesPerPrefix = attributesManager
         .getClusterNodeAttributes(Sets.newHashSet(PREFIXES[2]));
-    Assert.assertEquals(2, allAttributesPerPrefix.size());
+    assertEquals(2, allAttributesPerPrefix.size());
 
     // Remove "yarn.test1.io/A_2" from host1
     Set<NodeAttribute> attributes2rm1 = new HashSet<>();
@@ -233,7 +235,7 @@ public class TestNodeAttributesManager {
     attributesManager.removeNodeAttributes(toRemoveAttributes);
 
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(7, nodeAttributes.size());
+    assertEquals(7, nodeAttributes.size());
 
     // Remove again, but give a non-exist attribute name
     attributes2rm1.clear();
@@ -244,7 +246,7 @@ public class TestNodeAttributesManager {
     attributesManager.removeNodeAttributes(toRemoveAttributes);
 
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(7, nodeAttributes.size());
+    assertEquals(7, nodeAttributes.size());
 
     // Remove "yarn.test1.io/A_2" from host2 too,
     // by then there will be no such attribute exist in the cluster.
@@ -261,7 +263,7 @@ public class TestNodeAttributesManager {
     // us A_1 and A_3.
     allAttributesPerPrefix = attributesManager
         .getClusterNodeAttributes(Sets.newHashSet(PREFIXES[0]));
-    Assert.assertEquals(2, allAttributesPerPrefix.size());
+    assertEquals(2, allAttributesPerPrefix.size());
   }
 
   @Test
@@ -281,7 +283,7 @@ public class TestNodeAttributesManager {
 
     attributesManager.addNodeAttributes(toAddAttributes);
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(3, nodeAttributes.size());
+    assertEquals(3, nodeAttributes.size());
 
     // Add 10 distributed node attributes to host1
     //  nn.yarn.io/dist-node-attribute1=dist_v1_1
@@ -294,10 +296,10 @@ public class TestNodeAttributesManager {
             10, "dist-node-attribute", "dist_v1"));
     attributesManager.addNodeAttributes(toAddAttributes);
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(13, nodeAttributes.size());
+    assertEquals(13, nodeAttributes.size());
     clusterAttributes = attributesManager.getClusterNodeAttributes(
         Sets.newHashSet(NodeAttribute.PREFIX_DISTRIBUTED, PREFIXES[0]));
-    Assert.assertEquals(13, clusterAttributes.size());
+    assertEquals(13, clusterAttributes.size());
 
     // Replace by prefix
     // Same distributed attributes names, but different values.
@@ -308,24 +310,24 @@ public class TestNodeAttributesManager {
     attributesManager.replaceNodeAttributes(NodeAttribute.PREFIX_DISTRIBUTED,
         ImmutableMap.of(HOSTNAMES[0], toReplaceAttributes));
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(8, nodeAttributes.size());
+    assertEquals(8, nodeAttributes.size());
     clusterAttributes = attributesManager.getClusterNodeAttributes(
         Sets.newHashSet(NodeAttribute.PREFIX_DISTRIBUTED, PREFIXES[0]));
-    Assert.assertEquals(8, clusterAttributes.size());
+    assertEquals(8, clusterAttributes.size());
 
     // Now we have 5 distributed attributes
     filteredAttributes = NodeLabelUtil.filterAttributesByPrefix(
         nodeAttributes.keySet(), NodeAttribute.PREFIX_DISTRIBUTED);
-    Assert.assertEquals(5, filteredAttributes.size());
+    assertEquals(5, filteredAttributes.size());
     // Values are updated to have prefix dist_v2
-    Assert.assertTrue(filteredAttributes.stream().allMatch(
+    assertTrue(filteredAttributes.stream().allMatch(
         nodeAttribute ->
             nodeAttribute.getAttributeValue().startsWith("dist_v2")));
 
     // We still have 3 yarn.test1.io attributes
     filteredAttributes = NodeLabelUtil.filterAttributesByPrefix(
         nodeAttributes.keySet(), PREFIXES[0]);
-    Assert.assertEquals(3, filteredAttributes.size());
+    assertEquals(3, filteredAttributes.size());
 
     // Replace with prefix
     // Different attribute names
@@ -335,16 +337,16 @@ public class TestNodeAttributesManager {
     attributesManager.replaceNodeAttributes(NodeAttribute.PREFIX_DISTRIBUTED,
         ImmutableMap.of(HOSTNAMES[0], toReplaceAttributes));
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(4, nodeAttributes.size());
+    assertEquals(4, nodeAttributes.size());
     clusterAttributes = attributesManager.getClusterNodeAttributes(
         Sets.newHashSet(NodeAttribute.PREFIX_DISTRIBUTED));
-    Assert.assertEquals(1, clusterAttributes.size());
+    assertEquals(1, clusterAttributes.size());
     NodeAttribute attr = clusterAttributes.iterator().next();
-    Assert.assertEquals("dist-node-attribute-v2_0",
+    assertEquals("dist-node-attribute-v2_0",
         attr.getAttributeKey().getAttributeName());
-    Assert.assertEquals(NodeAttribute.PREFIX_DISTRIBUTED,
+    assertEquals(NodeAttribute.PREFIX_DISTRIBUTED,
         attr.getAttributeKey().getAttributePrefix());
-    Assert.assertEquals("dist_v3_0", attr.getAttributeValue());
+    assertEquals("dist_v3_0", attr.getAttributeValue());
 
     // Replace all attributes
     toReplaceMap.put(HOSTNAMES[0],
@@ -352,13 +354,13 @@ public class TestNodeAttributesManager {
     attributesManager.replaceNodeAttributes(null, toReplaceMap);
 
     nodeAttributes = attributesManager.getAttributesForNode(HOSTNAMES[0]);
-    Assert.assertEquals(2, nodeAttributes.size());
+    assertEquals(2, nodeAttributes.size());
     clusterAttributes = attributesManager
         .getClusterNodeAttributes(Sets.newHashSet(PREFIXES[1]));
-    Assert.assertEquals(2, clusterAttributes.size());
+    assertEquals(2, clusterAttributes.size());
     clusterAttributes = attributesManager
         .getClusterNodeAttributes(Sets.newHashSet(
             NodeAttribute.PREFIX_DISTRIBUTED));
-    Assert.assertEquals(0, clusterAttributes.size());
+    assertEquals(0, clusterAttributes.size());
   }
 }

+ 5 - 5
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestNodeLabelFileReplication.java

@@ -18,6 +18,8 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.nodelabels;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.io.IOException;
 
 import org.apache.hadoop.conf.Configuration;
@@ -26,8 +28,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 public class TestNodeLabelFileReplication {
 
@@ -51,9 +52,8 @@ public class TestNodeLabelFileReplication {
       int fileReplication = fs
           .getFileStatus(new Path(nodeLabelDir, "nodelabel.mirror"))
           .getReplication();
-      Assert.assertEquals(
-          "Node label file replication should be " + expectedReplication,
-          expectedReplication, fileReplication);
+      assertEquals(expectedReplication, fileReplication,
+          "Node label file replication should be " + expectedReplication);
       manager.close();
     } finally {
       if (cluster != null) {

+ 8 - 7
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestRMDelegatedNodeLabelsUpdater.java

@@ -18,7 +18,9 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.nodelabels;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.IOException;
 import java.util.Map;
@@ -37,9 +39,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.ResourceTrackerService;
 import org.apache.hadoop.yarn.util.Records;
 import org.apache.hadoop.yarn.util.YarnVersionInfo;
 import org.apache.hadoop.yarn.util.resource.Resources;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
 import org.apache.hadoop.thirdparty.com.google.common.collect.Maps;
@@ -48,7 +49,7 @@ public class TestRMDelegatedNodeLabelsUpdater extends NodeLabelTestBase {
   private YarnConfiguration conf;
   private static Map<NodeId, Set<NodeLabel>> nodeLabelsMap = Maps.newHashMap();
 
-  @Before
+  @BeforeEach
   public void setup() {
     conf = new YarnConfiguration();
     conf.setBoolean(YarnConfiguration.NODE_LABELS_ENABLED, true);
@@ -66,10 +67,10 @@ public class TestRMDelegatedNodeLabelsUpdater extends NodeLabelTestBase {
       MockRM rm = new MockRM(conf);
       rm.init(conf);
       rm.start();
-      Assert.fail("Expected an exception");
+      fail("Expected an exception");
     } catch (Exception e) {
       // expected an exception
-      Assert.assertTrue(e.getMessage().contains(
+      assertTrue(e.getMessage().contains(
           "RMNodeLabelsMappingProvider should be configured"));
     }
   }

+ 108 - 97
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/TestRMNodeLabelsManager.java

@@ -19,9 +19,11 @@
 package org.apache.hadoop.yarn.server.resourcemanager.nodelabels;
 
 import static org.assertj.core.api.Assertions.assertThat;
-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.assertNull;
+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.when;
 
@@ -55,10 +57,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeLabelsU
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType;
 import org.apache.hadoop.yarn.util.resource.Resources;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 
 import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap;
 import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet;
@@ -71,7 +73,7 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
   NullRMNodeLabelsManager mgr = null;
   RMNodeLabelsManager lmgr = null;
   boolean checkQueueCall = false;
-  @Before
+  @BeforeEach
   public void before() {
     mgr = new NullRMNodeLabelsManager();
     Configuration conf = new Configuration();
@@ -80,12 +82,13 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.start();
   }
 
-  @After
+  @AfterEach
   public void after() {
     mgr.stop();
   }
   
-  @Test(timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testGetLabelResourceWhenNodeActiveDeactive() throws Exception {
     mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1", "p2", "p3"));
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p1"),
@@ -108,7 +111,7 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1", "p4"));
     assertThat(mgr.getResourceByLabel("p1", null)).isEqualTo(
         Resources.add(SMALL_RESOURCE, LARGE_NODE));
-    Assert.assertEquals(mgr.getResourceByLabel("p4", null), EMPTY_RESOURCE);
+    assertEquals(mgr.getResourceByLabel("p4", null), EMPTY_RESOURCE);
 
     // change the large NM to small, check if resource updated
     mgr.updateNodeResource(NodeId.newInstance("n1", 2), SMALL_RESOURCE);
@@ -133,7 +136,8 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
         isEqualTo(Resources.add(SMALL_RESOURCE, LARGE_NODE));
   }
   
-  @Test(timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testActivateNodeManagerWithZeroPort() throws Exception {
     // active two NM, one is zero port , another is non-zero port. no exception
     // should be raised
@@ -142,7 +146,8 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
   }
 
   @SuppressWarnings({ "unchecked", "rawtypes" })
-  @Test(timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testGetLabelResource() throws Exception {
     mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1", "p2", "p3"));
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p1"),
@@ -229,7 +234,9 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
         Resources.multiply(SMALL_RESOURCE, 2));
   }
   
-  @Test(timeout=5000)
+  @Test
+  @Timeout(value = 5)
+  @SuppressWarnings("checkstyle:MethodLength")
   public void testGetQueueResource() throws Exception {
     Resource clusterResource = Resource.newInstance(9999, 1);
     
@@ -268,15 +275,15 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.reinitializeQueueLabels(queueToLabels);
     
     // check resource
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q1", q1Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q2", q2Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
         mgr.getQueueResource("Q3", q3Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
         mgr.getQueueResource("Q4", q4Label, clusterResource));
-    Assert.assertEquals(clusterResource,
+    assertEquals(clusterResource,
         mgr.getQueueResource("Q5", q5Label, clusterResource));
     
     mgr.removeLabelsFromNode(ImmutableMap.of(toNodeId("host2"), toSet("blue")));
@@ -290,15 +297,15 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
      */
     
     // check resource
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q1", q1Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q2", q2Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q3", q3Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
         mgr.getQueueResource("Q4", q4Label, clusterResource));
-    Assert.assertEquals(clusterResource,
+    assertEquals(clusterResource,
         mgr.getQueueResource("Q5", q5Label, clusterResource));
     
     /*
@@ -314,15 +321,15 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.activateNode(NodeId.newInstance("host3", 1), SMALL_RESOURCE);
     
     // check resource
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
         mgr.getQueueResource("Q1", q1Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q2", q2Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q3", q3Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
         mgr.getQueueResource("Q4", q4Label, clusterResource));
-    Assert.assertEquals(clusterResource,
+    assertEquals(clusterResource,
         mgr.getQueueResource("Q5", q5Label, clusterResource));
     
     /*
@@ -349,15 +356,15 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.reinitializeQueueLabels(queueToLabels);
     
     // check resource
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
         mgr.getQueueResource("Q1", q1Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
         mgr.getQueueResource("Q2", q2Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
         mgr.getQueueResource("Q3", q3Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 2),
         mgr.getQueueResource("Q4", q4Label, clusterResource));
-    Assert.assertEquals(clusterResource,
+    assertEquals(clusterResource,
         mgr.getQueueResource("Q5", q5Label, clusterResource));
     
     /*
@@ -372,15 +379,15 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.activateNode(NodeId.newInstance("host4", 2), SMALL_RESOURCE);
     
     // check resource
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q1", q1Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q2", q2Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q3", q3Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 3),
         mgr.getQueueResource("Q4", q4Label, clusterResource));
-    Assert.assertEquals(clusterResource,
+    assertEquals(clusterResource,
         mgr.getQueueResource("Q5", q5Label, clusterResource));
     
     /*
@@ -395,19 +402,20 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.deactivateNode(NodeId.newInstance("host4", 1));
     
     // check resource
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
         mgr.getQueueResource("Q1", q1Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
         mgr.getQueueResource("Q2", q2Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
         mgr.getQueueResource("Q3", q3Label, clusterResource));
-    Assert.assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
+    assertEquals(Resources.multiply(SMALL_RESOURCE, 1),
         mgr.getQueueResource("Q4", q4Label, clusterResource));
-    Assert.assertEquals(clusterResource,
+    assertEquals(clusterResource,
         mgr.getQueueResource("Q5", q5Label, clusterResource));
   }
 
-  @Test(timeout=5000)
+  @Test
+  @Timeout(value = 5)
   public void testGetLabelResourceWhenMultipleNMsExistingInSameHost() throws IOException {
     // active two NM to n1, one large and one small
     mgr.activateNode(NodeId.newInstance("n1", 1), SMALL_RESOURCE);
@@ -434,7 +442,8 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
         Resources.multiply(SMALL_RESOURCE, 2));
   }
 
-  @Test(timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testRemoveLabelsFromNode() throws Exception {
     mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1", "p2", "p3"));
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p1"),
@@ -443,14 +452,14 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.activateNode(NodeId.newInstance("n1", 1), SMALL_RESOURCE);
     try {
       mgr.removeLabelsFromNode(ImmutableMap.of(toNodeId("n1:1"), toSet("p1")));
-      Assert.fail("removeLabelsFromNode should trigger IOException");
+      fail("removeLabelsFromNode should trigger IOException");
     } catch (IOException e) {
     }
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1:1"), toSet("p1")));
     try {
       mgr.removeLabelsFromNode(ImmutableMap.of(toNodeId("n1:1"), toSet("p1")));
     } catch (IOException e) {
-      Assert.fail("IOException from removeLabelsFromNode " + e);
+      fail("IOException from removeLabelsFromNode " + e);
     }
   }
 
@@ -489,53 +498,54 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
 
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1:1"), toSet("p1"),
         toNodeId("n2:1"), toSet("p2"), toNodeId("n3"), toSet("p3")));
-    assertTrue("Event should be sent when there is change in labels",
-        schedEventsHandler.receivedEvent);
-    assertEquals("3 node label mapping modified", 3,
-        schedEventsHandler.updatedNodeToLabels.size());
+    assertTrue(schedEventsHandler.receivedEvent,
+        "Event should be sent when there is change in labels");
+    assertEquals(3, schedEventsHandler.updatedNodeToLabels.size(),
+        "3 node label mapping modified");
     ImmutableMap<NodeId, Set<String>> modifiedMap =
         ImmutableMap.of(toNodeId("n1:1"), toSet("p1"), toNodeId("n2:1"),
             toSet("p2"), toNodeId("n3:1"), toSet("p3"));
-    assertEquals("Node label mapping is not matching", modifiedMap,
-        schedEventsHandler.updatedNodeToLabels);
+    assertEquals(modifiedMap, schedEventsHandler.updatedNodeToLabels,
+        "Node label mapping is not matching");
     schedEventsHandler.receivedEvent = false;
 
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1:1"), toSet("p1")));
-    assertFalse("No event should be sent when there is no change in labels",
-        schedEventsHandler.receivedEvent);
+    assertFalse(schedEventsHandler.receivedEvent,
+        "No event should be sent when there is no change in labels");
     schedEventsHandler.receivedEvent = false;
 
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n2:1"), toSet("p1"),
         toNodeId("n3"), toSet("p3")));
-    assertTrue("Event should be sent when there is change in labels",
-        schedEventsHandler.receivedEvent);
-    assertEquals("Single node label mapping modified", 1,
-        schedEventsHandler.updatedNodeToLabels.size());
+    assertTrue(schedEventsHandler.receivedEvent,
+        "Event should be sent when there is change in labels");
+    assertEquals(1, schedEventsHandler.updatedNodeToLabels.size(),
+        "Single node label mapping modified");
     assertCollectionEquals(toSet("p1"),
         schedEventsHandler.updatedNodeToLabels.get(toNodeId("n2:1")));
     schedEventsHandler.receivedEvent = false;
 
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n3"), toSet("p2")));
-    assertTrue("Event should be sent when there is change in labels @ HOST",
-        schedEventsHandler.receivedEvent);
-    assertEquals("Single node label mapping modified", 1,
-        schedEventsHandler.updatedNodeToLabels.size());
+    assertTrue(schedEventsHandler.receivedEvent,
+        "Event should be sent when there is change in labels @ HOST");
+    assertEquals(1, schedEventsHandler.updatedNodeToLabels.size(),
+        "Single node label mapping modified");
     assertCollectionEquals(toSet("p2"),
         schedEventsHandler.updatedNodeToLabels.get(toNodeId("n3:1")));
     schedEventsHandler.receivedEvent = false;
 
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p2")));
-    assertTrue(
-        "Event should be sent when labels are modified at host though labels were set @ NM level",
-        schedEventsHandler.receivedEvent);
-    assertEquals("Single node label mapping modified", 1,
-        schedEventsHandler.updatedNodeToLabels.size());
+    assertTrue(schedEventsHandler.receivedEvent,
+        "Event should be sent when labels are " +
+        "modified at host though labels were set @ NM level");
+    assertEquals(1, schedEventsHandler.updatedNodeToLabels.size(),
+        "Single node label mapping modified");
     assertCollectionEquals(toSet("p2"),
         schedEventsHandler.updatedNodeToLabels.get(toNodeId("n1:1")));
     schedEventsHandler.receivedEvent = false;
   }
 
-  @Test(timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testGetLabelsOnNodesWhenNodeActiveDeactive() throws Exception {
     mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1", "p2", "p3"));
     mgr.replaceLabelsOnNode(ImmutableMap.of(
@@ -560,7 +570,7 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     assertCollectionEquals(toSet("p2"),
         mgr.getNodeLabels().get(toNodeId("n1:2")));
     mgr.deactivateNode(toNodeId("n1:2"));
-    Assert.assertNull(mgr.getNodeLabels().get(toNodeId("n1:2")));
+    assertNull(mgr.getNodeLabels().get(toNodeId("n1:2")));
     // Host will not affected too
     assertCollectionEquals(toSet("p2"),
         mgr.getNodeLabels().get(toNodeId("n1")));
@@ -574,7 +584,7 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     assertCollectionEquals(toSet("p3"),
         mgr.getNodeLabels().get(toNodeId("n1:2")));
     mgr.deactivateNode(toNodeId("n1:2"));
-    Assert.assertNull(mgr.getNodeLabels().get(toNodeId("n1:2")));
+    assertNull(mgr.getNodeLabels().get(toNodeId("n1:2")));
     // Host will not affected too
     assertCollectionEquals(toSet("p3"),
         mgr.getNodeLabels().get(toNodeId("n1")));
@@ -583,15 +593,16 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
   private void checkNodeLabelInfo(List<RMNodeLabel> infos, String labelName, int activeNMs, int memory) {
     for (RMNodeLabel info : infos) {
       if (info.getLabelName().equals(labelName)) {
-        Assert.assertEquals(activeNMs, info.getNumActiveNMs());
-        Assert.assertEquals(memory, info.getResource().getMemorySize());
+        assertEquals(activeNMs, info.getNumActiveNMs());
+        assertEquals(memory, info.getResource().getMemorySize());
         return;
       }
     }
-    Assert.fail("Failed to find info has label=" + labelName);
+    fail("Failed to find info has label=" + labelName);
   }
   
-  @Test(timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testPullRMNodeLabelsInfo() throws IOException {
     mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("x", "y", "z"));
     mgr.activateNode(NodeId.newInstance("n1", 1), Resource.newInstance(10, 0));
@@ -604,14 +615,15 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     
     // x, y, z and ""
     List<RMNodeLabel> infos = mgr.pullRMNodeLabelsInfo();
-    Assert.assertEquals(4, infos.size());
+    assertEquals(4, infos.size());
     checkNodeLabelInfo(infos, RMNodeLabelsManager.NO_LABEL, 2, 20);
     checkNodeLabelInfo(infos, "x", 2, 20);
     checkNodeLabelInfo(infos, "y", 1, 10);
     checkNodeLabelInfo(infos, "z", 0, 0);
   }
 
-  @Test(timeout = 60000)
+  @Test
+  @Timeout(value = 60)
   public void testcheckRemoveFromClusterNodeLabelsOfQueue() throws Exception {
     lmgr = new RMNodeLabelsManager();
     Configuration conf = new Configuration();
@@ -640,14 +652,11 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     }
     lmgr = new TestRMLabelManger();
     MockRM rm2 = initRM(withQueueLabels);
-    Assert.assertFalse(
-        "checkRemoveFromClusterNodeLabelsOfQueue should not be called"
-            + "on recovery",
-        checkQueueCall);
+    assertFalse(checkQueueCall,
+        "checkRemoveFromClusterNodeLabelsOfQueue should not be called on recovery");
     lmgr.removeFromClusterNodeLabels(Arrays.asList(new String[] { "x" }));
-    Assert
-        .assertTrue("checkRemoveFromClusterNodeLabelsOfQueue should be called "
-            + "since its not recovery", checkQueueCall);
+    assertTrue(checkQueueCall, "checkRemoveFromClusterNodeLabelsOfQueue should be called "
+        + "since its not recovery");
     rm2.stop();
   }
 
@@ -660,7 +669,7 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     };
     rm.getRMContext().setNodeLabelManager(lmgr);
     rm.start();
-    Assert.assertEquals(Service.STATE.STARTED, rm.getServiceState());
+    assertEquals(Service.STATE.STARTED, rm.getServiceState());
     return rm;
   }
 
@@ -679,11 +688,12 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     return conf;
   }
 
-  @Test(timeout = 5000)
+  @Test
+  @Timeout(value = 5)
   public void testLabelsToNodesOnNodeActiveDeactive() throws Exception {
     // Activate a node without assigning any labels
     mgr.activateNode(NodeId.newInstance("n1", 1), Resource.newInstance(10, 0));
-    Assert.assertTrue(mgr.getLabelsToNodes().isEmpty());
+    assertTrue(mgr.getLabelsToNodes().isEmpty());
     assertLabelsToNodesEquals(
         mgr.getLabelsToNodes(), transposeNodeToLabels(mgr.getNodeLabels()));
 
@@ -691,26 +701,27 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     mgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("p1"));
     mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("p1")));
     // p1 -> n1, n1:1
-    Assert.assertEquals(2, mgr.getLabelsToNodes().get("p1").size());
+    assertEquals(2, mgr.getLabelsToNodes().get("p1").size());
     assertLabelsToNodesEquals(
         mgr.getLabelsToNodes(), transposeNodeToLabels(mgr.getNodeLabels()));
 
     // Activate a node for which host to label mapping exists
     mgr.activateNode(NodeId.newInstance("n1", 2), Resource.newInstance(10, 0));
     // p1 -> n1, n1:1, n1:2
-    Assert.assertEquals(3, mgr.getLabelsToNodes().get("p1").size());
+    assertEquals(3, mgr.getLabelsToNodes().get("p1").size());
     assertLabelsToNodesEquals(
         mgr.getLabelsToNodes(), transposeNodeToLabels(mgr.getNodeLabels()));
 
     // Deactivate a node. n1:1 will be removed from the map
     mgr.deactivateNode(NodeId.newInstance("n1", 1));
     // p1 -> n1, n1:2
-    Assert.assertEquals(2, mgr.getLabelsToNodes().get("p1").size());
+    assertEquals(2, mgr.getLabelsToNodes().get("p1").size());
     assertLabelsToNodesEquals(
         mgr.getLabelsToNodes(), transposeNodeToLabels(mgr.getNodeLabels()));
   }
 
-  @Test(timeout = 60000)
+  @Test
+  @Timeout(value = 60)
   public void testBackwardsCompatableMirror() throws Exception {
     lmgr = new RMNodeLabelsManager();
     Configuration conf = new Configuration();
@@ -747,12 +758,12 @@ public class TestRMNodeLabelsManager extends NodeLabelTestBase {
     Set<String> labelNames = lmgr.getClusterNodeLabelNames();
     Map<String, Set<NodeId>> labeledNodes = lmgr.getLabelsToNodes();
 
-    Assert.assertTrue(labelNames.contains("a"));
-    Assert.assertTrue(labelNames.contains("b"));
-    Assert.assertTrue(labelNames.contains("c"));
-    Assert.assertTrue(labeledNodes.get("a")
+    assertTrue(labelNames.contains("a"));
+    assertTrue(labelNames.contains("b"));
+    assertTrue(labelNames.contains("c"));
+    assertTrue(labeledNodes.get("a")
         .contains(NodeId.newInstance("host1", 0)));
-    Assert.assertTrue(labeledNodes.get("b")
+    assertTrue(labeledNodes.get("b")
         .contains(NodeId.newInstance("host2", 0)));
 
     rm.stop();

+ 28 - 21
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystem.java

@@ -17,6 +17,11 @@
  *******************************************************************************/
 package org.apache.hadoop.yarn.server.resourcemanager.reservation;
 
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
@@ -32,11 +37,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.Capacity
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerTestBase;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import java.io.File;
 import java.io.IOException;
@@ -54,11 +57,11 @@ public class TestReservationSystem extends
   private Configuration conf;
   private RMContext mockRMContext;
 
-  public TestReservationSystem(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestReservationSystem(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
+    setUp();
   }
 
-  @Before
   public void setUp() throws IOException {
     scheduler = initializeScheduler();
     rmContext = getRMContext();
@@ -67,7 +70,7 @@ public class TestReservationSystem extends
     DefaultMetricsSystem.setMiniClusterMode(true);
   }
 
-  @After
+  @AfterEach
   public void tearDown() {
     conf = null;
     reservationSystem = null;
@@ -77,12 +80,14 @@ public class TestReservationSystem extends
     QueueMetrics.clearQueueMetrics();
   }
 
-  @Test
-  public void testInitialize() throws IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testInitialize(SchedulerType type) throws IOException {
+    initTestReservationSystem(type);
     try {
       reservationSystem.reinitialize(scheduler.getConfig(), rmContext);
     } catch (YarnException e) {
-      Assert.fail(e.getMessage());
+      fail(e.getMessage());
     }
     if (getSchedulerType().equals(SchedulerType.CAPACITY)) {
       ReservationSystemTestUtil.validateReservationQueue(reservationSystem,
@@ -94,13 +99,15 @@ public class TestReservationSystem extends
 
   }
 
-  @Test
-  public void testReinitialize() throws IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testReinitialize(SchedulerType type) throws IOException {
+    initTestReservationSystem(type);
     conf = scheduler.getConfig();
     try {
       reservationSystem.reinitialize(conf, rmContext);
     } catch (YarnException e) {
-      Assert.fail(e.getMessage());
+      fail(e.getMessage());
     }
     if (getSchedulerType().equals(SchedulerType.CAPACITY)) {
       ReservationSystemTestUtil.validateReservationQueue(reservationSystem,
@@ -112,17 +119,17 @@ public class TestReservationSystem extends
 
     // Dynamically add a plan
     String newQ = "reservation";
-    Assert.assertNull(reservationSystem.getPlan(newQ));
+    assertNull(reservationSystem.getPlan(newQ));
     updateSchedulerConf(conf, newQ);
     try {
       scheduler.reinitialize(conf, rmContext);
     } catch (IOException e) {
-      Assert.fail(e.getMessage());
+      fail(e.getMessage());
     }
     try {
       reservationSystem.reinitialize(conf, rmContext);
     } catch (YarnException e) {
-      Assert.fail(e.getMessage());
+      fail(e.getMessage());
     }
     ReservationSystemTestUtil.validateReservationQueue(
         reservationSystem,
@@ -174,10 +181,10 @@ public class TestReservationSystem extends
     CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();
     ReservationSystemTestUtil.setupQueueConfiguration(conf);
 
-    CapacityScheduler cs = Mockito.spy(new CapacityScheduler());
+    CapacityScheduler cs = spy(new CapacityScheduler());
     cs.setConf(conf);
     CSMaxRunningAppsEnforcer enforcer =
-        Mockito.mock(CSMaxRunningAppsEnforcer.class);
+        mock(CSMaxRunningAppsEnforcer.class);
     cs.setMaxRunningAppsEnforcer(enforcer);
 
     mockRMContext = ReservationSystemTestUtil.createRMContext(conf);
@@ -186,7 +193,7 @@ public class TestReservationSystem extends
     try {
       cs.serviceInit(conf);
     } catch (Exception e) {
-      Assert.fail(e.getMessage());
+      fail(e.getMessage());
     }
     ReservationSystemTestUtil.initializeRMContext(10, cs, mockRMContext);
     return cs;

+ 41 - 29
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMReconnect.java

@@ -19,6 +19,9 @@
 package org.apache.hadoop.yarn.server.resourcemanager.resourcetracker;
 
 import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus;
+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 java.io.IOException;
 import java.util.ArrayList;
@@ -56,10 +59,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEv
 import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM;
 import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager;
 import org.apache.hadoop.yarn.util.resource.Resources;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 /**
  * TestNMReconnect run tests against the scheduler set by
@@ -74,8 +77,9 @@ public class TestNMReconnect extends ParameterizedSchedulerTestBase {
   private Dispatcher dispatcher;
   private RMContextImpl context;
 
-  public TestNMReconnect(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestNMReconnect(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
+    setUp();
   }
 
   private class TestRMNodeEventDispatcher implements
@@ -90,7 +94,6 @@ public class TestNMReconnect extends ParameterizedSchedulerTestBase {
 
   ResourceTrackerService resourceTrackerService;
 
-  @Before
   public void setUp() {
     Configuration conf = new Configuration();
     // Dispatcher that processes events inline
@@ -125,13 +128,15 @@ public class TestNMReconnect extends ParameterizedSchedulerTestBase {
     resourceTrackerService.start();
   }
 
-  @After
+  @AfterEach
   public void tearDown() {
     resourceTrackerService.stop();
   }
 
-  @Test
-  public void testReconnect() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testReconnect(SchedulerType type) throws Exception {
+    initTestNMReconnect(type);
     String hostname1 = "localhost1";
     Resource capability = Resources.createResource(1024);
 
@@ -143,23 +148,25 @@ public class TestNMReconnect extends ParameterizedSchedulerTestBase {
     request1.setResource(capability);
     resourceTrackerService.registerNodeManager(request1);
 
-    Assert.assertEquals(RMNodeEventType.STARTED, rmNodeEvents.get(0).getType());
+    assertEquals(RMNodeEventType.STARTED, rmNodeEvents.get(0).getType());
 
     rmNodeEvents.clear();
     resourceTrackerService.registerNodeManager(request1);
-    Assert.assertEquals(RMNodeEventType.RECONNECTED,
+    assertEquals(RMNodeEventType.RECONNECTED,
         rmNodeEvents.get(0).getType());
 
     rmNodeEvents.clear();
     resourceTrackerService.registerNodeManager(request1);
     capability = Resources.createResource(1024, 2);
     request1.setResource(capability);
-    Assert.assertEquals(RMNodeEventType.RECONNECTED,
+    assertEquals(RMNodeEventType.RECONNECTED,
         rmNodeEvents.get(0).getType());
   }
 
-  @Test
-  public void testCompareRMNodeAfterReconnect() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testCompareRMNodeAfterReconnect(SchedulerType type) throws Exception {
+    initTestNMReconnect(type);
     AbstractYarnScheduler scheduler = getScheduler();
     Configuration yarnConf = new YarnConfiguration();
     ConfigurationProvider configurationProvider =
@@ -189,31 +196,34 @@ public class TestNMReconnect extends ParameterizedSchedulerTestBase {
     request1.setResource(capability);
     request1.setNodeStatus(mockNodeStatus);
     resourceTrackerService.registerNodeManager(request1);
-    Assert.assertNotNull(context.getRMNodes().get(nodeId1));
+    assertNotNull(context.getRMNodes().get(nodeId1));
     // verify Scheduler and RMContext use same RMNode reference.
-    Assert.assertTrue(scheduler.getSchedulerNode(nodeId1).getRMNode() ==
+    assertTrue(scheduler.getSchedulerNode(nodeId1).getRMNode() ==
         context.getRMNodes().get(nodeId1));
-    Assert.assertEquals(context.getRMNodes().get(nodeId1).
+    assertEquals(context.getRMNodes().get(nodeId1).
         getTotalCapability(), capability);
     Resource capability1 = Resources.createResource(2048, 2);
     request1.setResource(capability1);
     resourceTrackerService.registerNodeManager(request1);
-    Assert.assertNotNull(context.getRMNodes().get(nodeId1));
+    assertNotNull(context.getRMNodes().get(nodeId1));
     // verify Scheduler and RMContext use same RMNode reference
     // after reconnect.
-    Assert.assertTrue(scheduler.getSchedulerNode(nodeId1).getRMNode() ==
+    assertTrue(scheduler.getSchedulerNode(nodeId1).getRMNode() ==
         context.getRMNodes().get(nodeId1));
     // verify RMNode's capability is changed.
-    Assert.assertEquals(context.getRMNodes().get(nodeId1).
+    assertEquals(context.getRMNodes().get(nodeId1).
         getTotalCapability(), capability1);
     nlm.stop();
     scheduler.stop();
   }
 
   @SuppressWarnings("unchecked")
-  @Test(timeout = 10000)
-  public void testDecommissioningNodeReconnect()
-      throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(10)
+  public void testDecommissioningNodeReconnect(SchedulerType type) throws Exception {
+    initTestNMReconnect(type);
+
     MockRM rm = new MockRM();
     rm.start();
     MockNM nm1 =
@@ -230,12 +240,15 @@ public class TestNMReconnect extends ParameterizedSchedulerTestBase {
         new MockNM("127.0.0.1:1234", 15120, rm.getResourceTrackerService());
     RegisterNodeManagerResponse response = nm2.registerNode();
     // not SHUTDOWN
-    Assert.assertTrue(response.getNodeAction().equals(NodeAction.NORMAL));
+    assertTrue(response.getNodeAction().equals(NodeAction.NORMAL));
     rm.stop();
   }
 
-  @Test(timeout = 10000)
-  public void testRMNodeStatusAfterReconnect() throws Exception {
+  @Timeout(10)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testRMNodeStatusAfterReconnect(SchedulerType type) throws Exception {
+    initTestNMReconnect(type);
     // The node(127.0.0.1:1234) reconnected with RM. When it registered with
     // RM, RM set its lastNodeHeartbeatResponse's id to 0 asynchronously. But
     // the node's heartbeat come before RM succeeded setting the id to 0.
@@ -258,8 +271,7 @@ public class TestNMReconnect extends ParameterizedSchedulerTestBase {
     RMNode rmNode = rm.getRMContext().getRMNodes().get(nm2.getNodeId());
     nm2.nodeHeartbeat(true);
     rm.drainEvents();
-    Assert.assertEquals("Node is Not in Running state.", NodeState.RUNNING,
-        rmNode.getState());
+    assertEquals(NodeState.RUNNING, rmNode.getState(), "Node is Not in Running state.");
     rm.stop();
   }
 }

+ 148 - 107
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestAbstractYarnScheduler.java

@@ -20,7 +20,12 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler;
 
 import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus;
 import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestUtils.createResourceRequest;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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.when;
 
@@ -94,19 +99,21 @@ import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey;
 import org.apache.hadoop.yarn.server.utils.BuilderUtils;
 import org.apache.hadoop.yarn.util.resource.Resources;
 
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 @SuppressWarnings("unchecked")
 public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
 
-  public TestAbstractYarnScheduler(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestAbstractYarnScheduler(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
   }
 
-  @Test
-  public void testMaximimumAllocationMemory() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testMaximimumAllocationMemory(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     final int node1MaxMemory = 15 * 1024;
     final int node2MaxMemory = 5 * 1024;
     final int node3MaxMemory = 6 * 1024;
@@ -150,49 +157,51 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
        final int node1MaxMemory, final int node2MaxMemory,
        final int node3MaxMemory, final int... expectedMaxMemory)
        throws Exception {
-    Assert.assertEquals(6, expectedMaxMemory.length);
+    assertEquals(6, expectedMaxMemory.length);
 
-    Assert.assertEquals(0, scheduler.getNumClusterNodes());
+    assertEquals(0, scheduler.getNumClusterNodes());
     long maxMemory = scheduler.getMaximumResourceCapability().getMemorySize();
-    Assert.assertEquals(expectedMaxMemory[0], maxMemory);
+    assertEquals(expectedMaxMemory[0], maxMemory);
 
     RMNode node1 = MockNodes.newNodeInfo(
         0, Resources.createResource(node1MaxMemory), 1, "127.0.0.2");
     scheduler.handle(new NodeAddedSchedulerEvent(node1));
-    Assert.assertEquals(1, scheduler.getNumClusterNodes());
+    assertEquals(1, scheduler.getNumClusterNodes());
     maxMemory = scheduler.getMaximumResourceCapability().getMemorySize();
-    Assert.assertEquals(expectedMaxMemory[1], maxMemory);
+    assertEquals(expectedMaxMemory[1], maxMemory);
 
     scheduler.handle(new NodeRemovedSchedulerEvent(node1));
-    Assert.assertEquals(0, scheduler.getNumClusterNodes());
+    assertEquals(0, scheduler.getNumClusterNodes());
     maxMemory = scheduler.getMaximumResourceCapability().getMemorySize();
-    Assert.assertEquals(expectedMaxMemory[2], maxMemory);
+    assertEquals(expectedMaxMemory[2], maxMemory);
 
     RMNode node2 = MockNodes.newNodeInfo(
         0, Resources.createResource(node2MaxMemory), 2, "127.0.0.3");
     scheduler.handle(new NodeAddedSchedulerEvent(node2));
-    Assert.assertEquals(1, scheduler.getNumClusterNodes());
+    assertEquals(1, scheduler.getNumClusterNodes());
     maxMemory = scheduler.getMaximumResourceCapability().getMemorySize();
-    Assert.assertEquals(expectedMaxMemory[3], maxMemory);
+    assertEquals(expectedMaxMemory[3], maxMemory);
 
     RMNode node3 = MockNodes.newNodeInfo(
         0, Resources.createResource(node3MaxMemory), 3, "127.0.0.4");
     scheduler.handle(new NodeAddedSchedulerEvent(node3));
-    Assert.assertEquals(2, scheduler.getNumClusterNodes());
+    assertEquals(2, scheduler.getNumClusterNodes());
     maxMemory = scheduler.getMaximumResourceCapability().getMemorySize();
-    Assert.assertEquals(expectedMaxMemory[4], maxMemory);
+    assertEquals(expectedMaxMemory[4], maxMemory);
 
     scheduler.handle(new NodeRemovedSchedulerEvent(node3));
-    Assert.assertEquals(1, scheduler.getNumClusterNodes());
+    assertEquals(1, scheduler.getNumClusterNodes());
     maxMemory = scheduler.getMaximumResourceCapability().getMemorySize();
-    Assert.assertEquals(expectedMaxMemory[5], maxMemory);
+    assertEquals(expectedMaxMemory[5], maxMemory);
 
     scheduler.handle(new NodeRemovedSchedulerEvent(node2));
-    Assert.assertEquals(0, scheduler.getNumClusterNodes());
+    assertEquals(0, scheduler.getNumClusterNodes());
   }
 
-  @Test
-  public void testMaximimumAllocationVCores() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testMaximimumAllocationVCores(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     final int node1MaxVCores = 15;
     final int node2MaxVCores = 5;
     final int node3MaxVCores = 6;
@@ -236,52 +245,54 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       final int node1MaxVCores, final int node2MaxVCores,
       final int node3MaxVCores, final int... expectedMaxVCores)
       throws Exception {
-    Assert.assertEquals(6, expectedMaxVCores.length);
+    assertEquals(6, expectedMaxVCores.length);
 
-    Assert.assertEquals(0, scheduler.getNumClusterNodes());
+    assertEquals(0, scheduler.getNumClusterNodes());
     int maxVCores = scheduler.getMaximumResourceCapability().getVirtualCores();
-    Assert.assertEquals(expectedMaxVCores[0], maxVCores);
+    assertEquals(expectedMaxVCores[0], maxVCores);
 
     RMNode node1 = MockNodes.newNodeInfo(
         0, Resources.createResource(1024, node1MaxVCores), 1, "127.0.0.2");
     scheduler.handle(new NodeAddedSchedulerEvent(node1));
-    Assert.assertEquals(1, scheduler.getNumClusterNodes());
+    assertEquals(1, scheduler.getNumClusterNodes());
     maxVCores = scheduler.getMaximumResourceCapability().getVirtualCores();
-    Assert.assertEquals(expectedMaxVCores[1], maxVCores);
+    assertEquals(expectedMaxVCores[1], maxVCores);
 
     scheduler.handle(new NodeRemovedSchedulerEvent(node1));
-    Assert.assertEquals(0, scheduler.getNumClusterNodes());
+    assertEquals(0, scheduler.getNumClusterNodes());
     maxVCores = scheduler.getMaximumResourceCapability().getVirtualCores();
-    Assert.assertEquals(expectedMaxVCores[2], maxVCores);
+    assertEquals(expectedMaxVCores[2], maxVCores);
 
     RMNode node2 = MockNodes.newNodeInfo(
         0, Resources.createResource(1024, node2MaxVCores), 2, "127.0.0.3");
     scheduler.handle(new NodeAddedSchedulerEvent(node2));
-    Assert.assertEquals(1, scheduler.getNumClusterNodes());
+    assertEquals(1, scheduler.getNumClusterNodes());
     maxVCores = scheduler.getMaximumResourceCapability().getVirtualCores();
-    Assert.assertEquals(expectedMaxVCores[3], maxVCores);
+    assertEquals(expectedMaxVCores[3], maxVCores);
 
     RMNode node3 = MockNodes.newNodeInfo(
         0, Resources.createResource(1024, node3MaxVCores), 3, "127.0.0.4");
     scheduler.handle(new NodeAddedSchedulerEvent(node3));
-    Assert.assertEquals(2, scheduler.getNumClusterNodes());
+    assertEquals(2, scheduler.getNumClusterNodes());
     maxVCores = scheduler.getMaximumResourceCapability().getVirtualCores();
-    Assert.assertEquals(expectedMaxVCores[4], maxVCores);
+    assertEquals(expectedMaxVCores[4], maxVCores);
 
     scheduler.handle(new NodeRemovedSchedulerEvent(node3));
-    Assert.assertEquals(1, scheduler.getNumClusterNodes());
+    assertEquals(1, scheduler.getNumClusterNodes());
     maxVCores = scheduler.getMaximumResourceCapability().getVirtualCores();
-    Assert.assertEquals(expectedMaxVCores[5], maxVCores);
+    assertEquals(expectedMaxVCores[5], maxVCores);
 
     scheduler.handle(new NodeRemovedSchedulerEvent(node2));
-    Assert.assertEquals(0, scheduler.getNumClusterNodes());
+    assertEquals(0, scheduler.getNumClusterNodes());
   }
 
   /**
    * Test for testing autocorrect container allocation feature.
    */
-  @Test
-  public void testAutoCorrectContainerAllocation() {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testAutoCorrectContainerAllocation(SchedulerType type) throws IOException {
+    initTestAbstractYarnScheduler(type);
     Configuration conf = new Configuration(getConf());
     conf.setBoolean(YarnConfiguration.RM_SCHEDULER_AUTOCORRECT_CONTAINER_ALLOCATION, true);
     conf.setBoolean("yarn.scheduler.capacity.root.auto-create-child-queue.enabled",
@@ -623,8 +634,10 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
     assertEquals(4, application.pullNewlyAllocatedContainers().size());
   }
 
-  @Test
-  public void testUpdateMaxAllocationUsesTotal() throws IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testUpdateMaxAllocationUsesTotal(SchedulerType type) throws IOException {
+    initTestAbstractYarnScheduler(type);
     final int configuredMaxVCores = 20;
     final int configuredMaxMemory = 10 * 1024;
     Resource configuredMaximumResource = Resource.newInstance
@@ -677,8 +690,10 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test
-  public void testMaxAllocationAfterUpdateNodeResource() throws IOException {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testMaxAllocationAfterUpdateNodeResource(SchedulerType type) throws IOException {
+    initTestAbstractYarnScheduler(type);
     final int configuredMaxVCores = 20;
     final int configuredMaxMemory = 10 * 1024;
     Resource configuredMaximumResource = Resource.newInstance
@@ -743,8 +758,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
    * null (no attempt).
    */
   @SuppressWarnings({ "rawtypes" })
-  @Test(timeout = 10000)
-  public void testReleasedContainerIfAppAttemptisNull() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(10)
+  public void testReleasedContainerIfAppAttemptisNull(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     YarnConfiguration conf=getConf();
     MockRM rm1 = new MockRM(conf);
     try {
@@ -777,9 +795,9 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
 
       scheduler.clearPendingContainerCache();
 
-      Assert.assertEquals("Pending containers are not released "
-          + "when one of the application attempt is null !", schedulerApp
-          .getCurrentAppAttempt().getPendingRelease().size(), 0);
+      assertEquals(schedulerApp.getCurrentAppAttempt().getPendingRelease().size(),
+          0, "Pending containers are not released "
+           + "when one of the application attempt is null !");
     } finally {
       if (rm1 != null) {
         rm1.stop();
@@ -787,8 +805,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test(timeout = 30000l)
-  public void testContainerReleaseWithAllocationTags() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(30)
+  public void testContainerReleaseWithAllocationTags(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     // Currently only can be tested against capacity scheduler.
     if (getSchedulerType().equals(SchedulerType.CAPACITY)) {
       final String testTag1 = "some-tag";
@@ -847,13 +868,13 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
         Thread.sleep(1000);
       }
 
-      Assert.assertEquals(4, allocated.size());
+      assertEquals(4, allocated.size());
 
       Set<Container> containers = allocated.stream()
           .filter(container -> container.getAllocationRequestId() == 1l)
           .collect(Collectors.toSet());
-      Assert.assertNotNull(containers);
-      Assert.assertEquals(1, containers.size());
+      assertNotNull(containers);
+      assertEquals(1, containers.size());
       ContainerId cid = containers.iterator().next().getId();
 
       // mock container start
@@ -864,8 +885,8 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       Map<String, Long> nodeTags = rm1.getRMContext()
           .getAllocationTagsManager()
           .getAllocationTagsWithCount(nm1.getNodeId());
-      Assert.assertNotNull(nodeTags.get(testTag1));
-      Assert.assertEquals(1, nodeTags.get(testTag1).intValue());
+      assertNotNull(nodeTags.get(testTag1));
+      assertEquals(1, nodeTags.get(testTag1).intValue());
 
       // release a container
       am1.allocate(new ArrayList<>(), Lists.newArrayList(cid));
@@ -873,9 +894,9 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       // before NM confirms, the tag should still exist
       nodeTags = rm1.getRMContext().getAllocationTagsManager()
           .getAllocationTagsWithCount(nm1.getNodeId());
-      Assert.assertNotNull(nodeTags);
-      Assert.assertNotNull(nodeTags.get(testTag1));
-      Assert.assertEquals(1, nodeTags.get(testTag1).intValue());
+      assertNotNull(nodeTags);
+      assertNotNull(nodeTags.get(testTag1));
+      assertEquals(1, nodeTags.get(testTag1).intValue());
 
       // NM reports back that container is released
       // RM should cleanup the tag
@@ -897,8 +918,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
   }
 
 
-  @Test(timeout = 30000L)
-  public void testNodeRemovedWithAllocationTags() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(30)
+  public void testNodeRemovedWithAllocationTags(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     // Currently only can be tested against capacity scheduler.
     if (getSchedulerType().equals(SchedulerType.CAPACITY)) {
       final String testTag1 = "some-tag";
@@ -948,13 +972,13 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
         Thread.sleep(1000);
       }
 
-      Assert.assertEquals(1, allocated.size());
+      assertEquals(1, allocated.size());
 
       Set<Container> containers = allocated.stream()
           .filter(container -> container.getAllocationRequestId() == 1L)
           .collect(Collectors.toSet());
-      Assert.assertNotNull(containers);
-      Assert.assertEquals(1, containers.size());
+      assertNotNull(containers);
+      assertEquals(1, containers.size());
       ContainerId cid = containers.iterator().next().getId();
 
       // mock container start
@@ -965,8 +989,8 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       Map<String, Long> nodeTags = rm1.getRMContext()
           .getAllocationTagsManager()
           .getAllocationTagsWithCount(nm1.getNodeId());
-      Assert.assertNotNull(nodeTags.get(testTag1));
-      Assert.assertEquals(1, nodeTags.get(testTag1).intValue());
+      assertNotNull(nodeTags.get(testTag1));
+      assertEquals(1, nodeTags.get(testTag1).intValue());
 
       // remove the  node
       RMNode node1 = MockNodes.newNodeInfo(
@@ -977,13 +1001,15 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       // Once the node is removed, the tag should be removed immediately
       nodeTags = rm1.getRMContext().getAllocationTagsManager()
           .getAllocationTagsWithCount(nm1.getNodeId());
-      Assert.assertNull(nodeTags);
+      assertNull(nodeTags);
     }
   }
 
-
-  @Test(timeout=60000)
-  public void testContainerReleasedByNode() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(60)
+  public void testContainerReleasedByNode(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     System.out.println("Starting testContainerReleasedByNode");
     YarnConfiguration conf = getConf();
     MockRM rm1 = new MockRM(conf);
@@ -1075,15 +1101,15 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       containers = am1.allocate("127.0.0.1", 8192, 1,
           new ArrayList<ContainerId>()).getAllocatedContainers();
       nm1.nodeHeartbeat(true);
-      Assert.assertTrue("new container allocated before node freed old",
-          containers.isEmpty());
+      assertTrue(containers.isEmpty(),
+          "new container allocated before node freed old");
       for (int i = 0; i < 10; ++i) {
         Thread.sleep(10);
         containers = am1.allocate(new ArrayList<ResourceRequest>(),
             new ArrayList<ContainerId>()).getAllocatedContainers();
         nm1.nodeHeartbeat(true);
-        Assert.assertTrue("new container allocated before node freed old",
-            containers.isEmpty());
+        assertTrue(containers.isEmpty(),
+            "new container allocated before node freed old");
       }
 
       // free the old container from the node
@@ -1105,9 +1131,12 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test(timeout = 60000)
-  public void testResourceRequestRestoreWhenRMContainerIsAtAllocated()
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(60)
+  public void testResourceRequestRestoreWhenRMContainerIsAtAllocated(SchedulerType type)
       throws Exception {
+    initTestAbstractYarnScheduler(type);
     YarnConfiguration conf = getConf();
     MockRM rm1 = new MockRM(conf);
     try {
@@ -1203,10 +1232,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
    *
    * @throws Exception
    */
-  @Test
-  public void testResourceRequestRecoveryToTheRightAppAttempt()
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testResourceRequestRecoveryToTheRightAppAttempt(SchedulerType type)
       throws Exception {
-
+    initTestAbstractYarnScheduler(type);
     YarnConfiguration conf = getConf();
     MockRM rm = new MockRM(conf);
     try {
@@ -1280,11 +1310,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       RMAppAttempt rmAppAttempt2 = MockRM.waitForAttemptScheduled(rmApp, rm);
       ApplicationAttemptId applicationAttemptTwoID =
           rmAppAttempt2.getAppAttemptId();
-      Assert.assertEquals(2, applicationAttemptTwoID.getAttemptId());
+      assertEquals(2, applicationAttemptTwoID.getAttemptId());
 
       // All outstanding allocated containers will be killed (irrespective of
       // keep-alive of container across app-attempts)
-      Assert.assertEquals(RMContainerState.KILLED,
+      assertEquals(RMContainerState.KILLED,
         allocatedContainer.getState());
 
       // The core part of this test
@@ -1292,11 +1322,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       // original app-attempt, not the new one
       for (SchedulerRequestKey key : firstSchedulerAppAttempt.getSchedulerKeys()) {
         if (key.getPriority().getPriority() == 0) {
-          Assert.assertEquals(0,
+          assertEquals(0,
               firstSchedulerAppAttempt.getOutstandingAsksCount(key));
         } else if (key.getPriority().getPriority() ==
             ALLOCATED_CONTAINER_PRIORITY) {
-          Assert.assertEquals(1,
+          assertEquals(1,
               firstSchedulerAppAttempt.getOutstandingAsksCount(key));
         }
       }
@@ -1307,8 +1337,8 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       List<Container> transferredContainers =
           rm.getResourceScheduler().getTransferredContainers(
             applicationAttemptTwoID);
-      Assert.assertEquals(1, transferredContainers.size());
-      Assert.assertEquals(runningContainerID, transferredContainers.get(0)
+      assertEquals(1, transferredContainers.size());
+      assertEquals(runningContainerID, transferredContainers.get(0)
         .getId());
 
     } finally {
@@ -1321,9 +1351,9 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
 
     final Resource schedulerMaximumResourceCapability = scheduler
         .getMaximumResourceCapability();
-    Assert.assertEquals(expectedMaximumResource.getMemorySize(),
+    assertEquals(expectedMaximumResource.getMemorySize(),
         schedulerMaximumResourceCapability.getMemorySize());
-    Assert.assertEquals(expectedMaximumResource.getVirtualCores(),
+    assertEquals(expectedMaximumResource.getVirtualCores(),
         schedulerMaximumResourceCapability.getVirtualCores());
   }
 
@@ -1349,7 +1379,7 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
     RMContext privateContext =
         new RMContextImpl(privateDispatcher, null, null, null, null, null, null,
             null, null, null);
-    privateContext.setNodeLabelManager(Mockito.mock(RMNodeLabelsManager.class));
+    privateContext.setNodeLabelManager(mock(RMNodeLabelsManager.class));
 
     privateDispatcher.register(SchedulerEventType.class, sleepHandler);
     privateDispatcher.register(SchedulerEventType.class,
@@ -1386,8 +1416,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
    * that might occur due to the use of the RMNode object.
    * @throws Exception
    */
-  @Test(timeout = 60000)
-  public void testNodemanagerReconnect() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(60)
+  public void testNodemanagerReconnect(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     Configuration conf = getConf();
     MockRM rm = new MockRM(conf);
     try {
@@ -1418,8 +1451,8 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       privateDispatcher.await();
       Resource clusterResource =
           rm.getResourceScheduler().getClusterResource();
-      Assert.assertEquals("Initial cluster resources don't match", capability,
-          clusterResource);
+      assertEquals(capability,
+          clusterResource, "Initial cluster resources don't match");
 
       Resource newCapability = Resources.createResource(1024);
       RegisterNodeManagerRequest request2 =
@@ -1431,16 +1464,19 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
       sleepHandler.sleepFlag = true;
       privateResourceTrackerService.registerNodeManager(request2);
       privateDispatcher.await();
-      Assert.assertEquals("Cluster resources don't match", newCapability,
-          rm.getResourceScheduler().getClusterResource());
+      assertEquals(newCapability, rm.getResourceScheduler().getClusterResource(),
+          "Cluster resources don't match");
       privateResourceTrackerService.stop();
     } finally {
       rm.stop();
     }
   }
 
-  @Test(timeout = 10000)
-  public void testUpdateThreadLifeCycle() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(10)
+  public void testUpdateThreadLifeCycle(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     MockRM rm = new MockRM(getConf());
     try {
       rm.start();
@@ -1449,7 +1485,7 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
 
       if (getSchedulerType().equals(SchedulerType.FAIR)) {
         Thread updateThread = scheduler.updateThread;
-        Assert.assertTrue(updateThread.isAlive());
+        assertTrue(updateThread.isAlive());
         scheduler.stop();
 
         int numRetries = 100;
@@ -1457,12 +1493,12 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
           Thread.sleep(50);
         }
 
-        Assert.assertNotEquals("The Update thread is still alive", 0, numRetries);
+        assertNotEquals(0, numRetries, "The Update thread is still alive");
       } else if (getSchedulerType().equals(SchedulerType.CAPACITY)) {
-        Assert.assertNull("updateThread shouldn't have been created",
-            scheduler.updateThread);
+        assertNull(scheduler.updateThread,
+            "updateThread shouldn't have been created");
       } else {
-        Assert.fail("Unhandled SchedulerType, " + getSchedulerType() +
+        fail("Unhandled SchedulerType, " + getSchedulerType() +
             ", please update this unit test.");
       }
     } finally {
@@ -1470,8 +1506,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test(timeout=60000)
-  public void testContainerRecoveredByNode() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(60)
+  public void testContainerRecoveredByNode(SchedulerType type) throws Exception {
+    initTestAbstractYarnScheduler(type);
     System.out.println("Starting testContainerRecoveredByNode");
     final int maxMemory = 10 * 1024;
     YarnConfiguration conf = getConf();
@@ -1521,11 +1560,11 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
 
       //verify queue name when rmContainer is recovered
       if (scheduler instanceof CapacityScheduler) {
-        Assert.assertEquals(
+        assertEquals(
             app1.getQueue(),
             rmContainer.getQueueName());
       } else {
-        Assert.assertEquals(app1.getQueue(), rmContainer.getQueueName());
+        assertEquals(app1.getQueue(), rmContainer.getQueueName());
       }
 
     } finally {
@@ -1538,8 +1577,10 @@ public class TestAbstractYarnScheduler extends ParameterizedSchedulerTestBase {
    * Test the order we get the containers to kill. It should respect the order
    * described in {@link SchedulerNode#getContainersToKill()}.
    */
-  @Test
-  public void testGetRunningContainersToKill() {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testGetRunningContainersToKill(SchedulerType type) throws IOException {
+    initTestAbstractYarnScheduler(type);
     final SchedulerNode node = new MockSchedulerNode();
     assertEquals(Collections.emptyList(), node.getContainersToKill());
 

+ 33 - 21
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulingWithAllocationRequestId.java

@@ -18,6 +18,8 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.scheduler;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.io.IOException;
 import java.util.List;
 
@@ -34,8 +36,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.ParameterizedSchedulerTestB
 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
 import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,8 +53,8 @@ public class TestSchedulingWithAllocationRequestId
       LoggerFactory.getLogger(TestSchedulingWithAllocationRequestId.class);
   private static final int GB = 1024;
 
-  public TestSchedulingWithAllocationRequestId(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestSchedulingWithAllocationRequestId(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
   }
 
   @Override
@@ -65,8 +68,11 @@ public class TestSchedulingWithAllocationRequestId
     return conf;
   }
 
-  @Test (timeout = 10000)
-  public void testMultipleAllocationRequestIds() throws Exception {
+  @Timeout(10)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testMultipleAllocationRequestIds(SchedulerType type) throws Exception {
+    initParameterizedSchedulerTestBase(type);
     YarnConfiguration conf = getConf();
     MockRM rm = new MockRM(conf);
     try {
@@ -90,13 +96,13 @@ public class TestSchedulingWithAllocationRequestId
       // check if request id 10 is satisfied
       AllocateResponse allocResponse = waitForAllocResponse(rm, am1, nm1, 1);
       List<Container> allocated = allocResponse.getAllocatedContainers();
-      Assert.assertEquals(1, allocated.size());
+      assertEquals(1, allocated.size());
       checkAllocatedContainer(allocated.get(0), 2 * GB, nm1.getNodeId(), 10);
 
       // check now if request id 20 is satisfied
       allocResponse = waitForAllocResponse(rm, am1, nm2, 2);
       allocated = allocResponse.getAllocatedContainers();
-      Assert.assertEquals(2, allocated.size());
+      assertEquals(2, allocated.size());
       for (Container container : allocated) {
         checkAllocatedContainer(container, 2 * GB, nm2.getNodeId(), 20);
       }
@@ -107,8 +113,11 @@ public class TestSchedulingWithAllocationRequestId
     }
   }
 
-  @Test (timeout = 10000)
-  public void testMultipleAllocationRequestDiffPriority() throws Exception {
+  @Timeout(10)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testMultipleAllocationRequestDiffPriority(SchedulerType type) throws Exception {
+    initTestSchedulingWithAllocationRequestId(type);
     YarnConfiguration conf = getConf();
     MockRM rm = new MockRM(conf);
     try {
@@ -132,7 +141,7 @@ public class TestSchedulingWithAllocationRequestId
       // check if request id 20 is satisfied first
       AllocateResponse allocResponse = waitForAllocResponse(rm, am1, nm2, 2);
       List<Container> allocated = allocResponse.getAllocatedContainers();
-      Assert.assertEquals(2, allocated.size());
+      assertEquals(2, allocated.size());
       for (Container container : allocated) {
         checkAllocatedContainer(container, 2 * GB, nm2.getNodeId(), 20);
       }
@@ -140,7 +149,7 @@ public class TestSchedulingWithAllocationRequestId
       // check now if request id 10 is satisfied
       allocResponse = waitForAllocResponse(rm, am1, nm1, 1);
       allocated = allocResponse.getAllocatedContainers();
-      Assert.assertEquals(1, allocated.size());
+      assertEquals(1, allocated.size());
       checkAllocatedContainer(allocated.get(0), 2 * GB, nm1.getNodeId(), 10);
     } finally {
       if (rm != null) {
@@ -151,14 +160,17 @@ public class TestSchedulingWithAllocationRequestId
 
   private void checkAllocatedContainer(Container allocated, int memory,
       NodeId nodeId, long allocationRequestId) {
-    Assert.assertEquals(memory, allocated.getResource().getMemorySize());
-    Assert.assertEquals(nodeId, allocated.getNodeId());
-    Assert.assertEquals(allocationRequestId,
+    assertEquals(memory, allocated.getResource().getMemorySize());
+    assertEquals(nodeId, allocated.getNodeId());
+    assertEquals(allocationRequestId,
         allocated.getAllocationRequestId());
   }
 
-  @Test (timeout = 10000)
-  public void testMultipleAppsWithAllocationReqId() throws Exception {
+  @Timeout(10)
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testMultipleAppsWithAllocationReqId(SchedulerType type) throws Exception {
+    initTestSchedulingWithAllocationRequestId(type);
     YarnConfiguration conf = getConf();
     MockRM rm = new MockRM(conf);
     try {
@@ -193,7 +205,7 @@ public class TestSchedulingWithAllocationRequestId
       // wait for container to be allocated.
       AllocateResponse allocResponse = waitForAllocResponse(rm, am1, nm1, 1);
       List<Container> allocated = allocResponse.getAllocatedContainers();
-      Assert.assertEquals(1, allocated.size());
+      assertEquals(1, allocated.size());
       checkAllocatedContainer(allocated.get(0), 1 * GB, nm1.getNodeId(), 5L);
 
       // Submit another application
@@ -212,7 +224,7 @@ public class TestSchedulingWithAllocationRequestId
       // wait for container to be allocated.
       allocResponse = waitForAllocResponse(rm, am2, nm2, 1);
       allocated = allocResponse.getAllocatedContainers();
-      Assert.assertEquals(1, allocated.size());
+      assertEquals(1, allocated.size());
       checkAllocatedContainer(allocated.get(0), 2 * GB, nm2.getNodeId(), 5L);
 
       // Now submit app2 RR with allocationReqId = 10
@@ -222,7 +234,7 @@ public class TestSchedulingWithAllocationRequestId
       // wait for container to be allocated.
       allocResponse = waitForAllocResponse(rm, am2, nm1, 1);
       allocated = allocResponse.getAllocatedContainers();
-      Assert.assertEquals(1, allocated.size());
+      assertEquals(1, allocated.size());
       checkAllocatedContainer(allocated.get(0), 3 * GB, nm1.getNodeId(), 10L);
 
       // Now submit app1 RR with allocationReqId = 10
@@ -232,7 +244,7 @@ public class TestSchedulingWithAllocationRequestId
       // wait for container to be allocated.
       allocResponse = waitForAllocResponse(rm, am1, nm2, 1);
       allocated = allocResponse.getAllocatedContainers();
-      Assert.assertEquals(1, allocated.size());
+      assertEquals(1, allocated.size());
       checkAllocatedContainer(allocated.get(0), 4 * GB, nm2.getNodeId(), 10L);
     } finally {
       if (rm != null) {

+ 38 - 32
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java

@@ -65,9 +65,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
 import org.apache.hadoop.yarn.server.utils.BuilderUtils;
 import org.apache.hadoop.yarn.util.ConverterUtils;
 import org.apache.hadoop.yarn.util.Records;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import javax.security.sasl.SaslException;
 import java.io.IOException;
@@ -79,7 +79,11 @@ import java.security.PrivilegedExceptionAction;
 import java.util.Timer;
 import java.util.TimerTask;
 
-import static org.junit.Assert.fail;
+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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -87,11 +91,11 @@ import static org.mockito.Mockito.when;
 public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
   private YarnConfiguration conf;
 
-  public TestClientToAMTokens(SchedulerType type) throws IOException {
-    super(type);
+  public void initTestClientToAMTokens(SchedulerType type) throws IOException {
+    initParameterizedSchedulerTestBase(type);
+    setup();
   }
 
-  @Before
   public void setup() {
     conf = getConf();
   }
@@ -189,8 +193,10 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
     }
   }
 
-  @Test
-  public void testClientToAMTokens() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  public void testClientToAMTokens(SchedulerType type) throws Exception {
+    initTestClientToAMTokens(type);
     conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
       "kerberos");
     // Set RPC engine to protobuf RPC engine
@@ -242,7 +248,7 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
             try {
               response = mockAM.registerAppAttempt();
             } catch (Exception e) {
-              Assert.fail("Exception was not expected");
+              fail("Exception was not expected");
             }
             return response;
           }
@@ -260,14 +266,13 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
 
     // ClientToAMToken master key should have been received on register
     // application master response.
-    Assert.assertNotNull(response.getClientToAMTokenMasterKey());
-    Assert
-        .assertTrue(response.getClientToAMTokenMasterKey().array().length > 0);
+    assertNotNull(response.getClientToAMTokenMasterKey());
+    assertTrue(response.getClientToAMTokenMasterKey().array().length > 0);
     
     // Start the AM with the correct shared-secret.
     ApplicationAttemptId appAttemptId =
         app.getAppAttempts().keySet().iterator().next();
-    Assert.assertNotNull(appAttemptId);
+    assertNotNull(appAttemptId);
     final CustomAM am =
         new CustomAM(appAttemptId, response.getClientToAMTokenMasterKey()
             .array());
@@ -285,7 +290,7 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
       client.ping(null, TestRpcBase.newEmptyRequest());
       fail("Access by unauthenticated user should fail!!");
     } catch (Exception e) {
-      Assert.assertFalse(am.pinged);
+      assertFalse(am.pinged);
     }
 
     Token<ClientToAMTokenIdentifier> token =
@@ -360,18 +365,15 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
         }
       });
     } catch (Exception e) {
-      Assert.assertEquals(RemoteException.class.getName(), e.getClass()
+      assertEquals(RemoteException.class.getName(), e.getClass()
           .getName());
       e = ((RemoteException)e).unwrapRemoteException();
-      Assert
-        .assertEquals(SaslException.class
+      assertEquals(SaslException.class
           .getCanonicalName(), e.getClass().getCanonicalName());
-      Assert.assertTrue(e
-        .getMessage()
-        .contains(
-          "DIGEST-MD5: digest response format violation. "
-              + "Mismatched response."));
-      Assert.assertFalse(am.pinged);
+      assertTrue(e
+          .getMessage()
+          .contains("DIGEST-MD5: digest response format violation. " + "Mismatched response."));
+      assertFalse(am.pinged);
     }
   }
 
@@ -395,7 +397,7 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
         CustomProtocol client =
             RPC.getProxy(CustomProtocol.class, 1L, am.address, conf);
         client.ping(null, TestRpcBase.newEmptyRequest());
-        Assert.assertTrue(am.pinged);
+        assertTrue(am.pinged);
         return null;
       }
     });
@@ -414,14 +416,18 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
         CustomProtocol client = RPC.getProxy(CustomProtocol.class,
             1L, am.address, conf);
         client.ping(null, TestRpcBase.newEmptyRequest());
-        Assert.assertTrue(am.pinged);
+        assertTrue(am.pinged);
         return null;
       }
     });
   }
 
-  @Test(timeout=20000)
-  public void testClientTokenRace() throws Exception {
+  @ParameterizedTest(name = "{0}")
+  @MethodSource("getParameters")
+  @Timeout(20)
+  public void testClientTokenRace(SchedulerType type) throws Exception {
+
+    initTestClientToAMTokens(type);
 
     conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
       "kerberos");
@@ -472,7 +478,7 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
             try {
               response = mockAM.registerAppAttempt();
             } catch (Exception e) {
-              Assert.fail("Exception was not expected");
+              fail("Exception was not expected");
             }
             return response;
           }
@@ -491,13 +497,13 @@ public class TestClientToAMTokens extends ParameterizedSchedulerTestBase {
     // ClientToAMToken master key should have been received on register
     // application master response.
     final ByteBuffer clientMasterKey = response.getClientToAMTokenMasterKey();
-    Assert.assertNotNull(clientMasterKey);
-    Assert.assertTrue(clientMasterKey.array().length > 0);
+    assertNotNull(clientMasterKey);
+    assertTrue(clientMasterKey.array().length > 0);
 
     // Start the AM with the correct shared-secret.
     ApplicationAttemptId appAttemptId =
         app.getAppAttempts().keySet().iterator().next();
-    Assert.assertNotNull(appAttemptId);
+    assertNotNull(appAttemptId);
     final CustomAM am = new CustomAM(appAttemptId, null);
     am.init(conf);
     am.start();

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio