diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ACLsTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ACLsTestBase.java index 26e3ee2920d0a..efaaf77bb63a1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ACLsTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ACLsTestBase.java @@ -33,7 +33,7 @@ import org.apache.hadoop.yarn.api.ApplicationClientProtocol; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.ipc.YarnRPC; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public abstract class ACLsTestBase { @@ -65,7 +65,7 @@ public abstract class ACLsTestBase { YarnRPC rpc; InetSocketAddress rmAddress; - @Before + @BeforeEach public void setup() throws InterruptedException, IOException { conf = createConfiguration(); rpc = YarnRPC.create(conf); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterServiceTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterServiceTestBase.java index 3f2ecff06a1cf..663e58fb4597b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterServiceTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterServiceTestBase.java @@ -52,9 +52,10 @@ import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.ArrayList; import java.util.Collections; @@ -66,7 +67,7 @@ import static java.lang.Thread.sleep; import static org.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB; import static org.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * Base class for Application Master test classes. @@ -122,14 +123,15 @@ private void requestResources(MockAM am, long memory, int vCores, .build()), null); } - @Before + @BeforeEach public void setup() { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class, ResourceScheduler.class); } - @Test(timeout = 3000000) + @Test + @Timeout(value = 3000) public void testRMIdentifierOnContainerAllocation() throws Exception { MockRM rm = new MockRM(conf); rm.start(); @@ -163,12 +165,13 @@ public void testRMIdentifierOnContainerAllocation() throws Exception { ContainerTokenIdentifier tokenId = BuilderUtils.newContainerTokenIdentifier(allocatedContainer .getContainerToken()); - Assert.assertEquals(MockRM.getClusterTimeStamp(), + Assertions.assertEquals(MockRM.getClusterTimeStamp(), tokenId.getRMIdentifier()); rm.stop(); } - @Test(timeout = 3000000) + @Test + @Timeout(value = 3000) public void testAllocateResponseIdOverflow() throws Exception { MockRM rm = new MockRM(conf); @@ -188,21 +191,22 @@ public void testAllocateResponseIdOverflow() throws Exception { am1.registerAppAttempt(); // Set the last responseId to be Integer.MAX_VALUE - Assert.assertTrue(am1.setApplicationLastResponseId(Integer.MAX_VALUE)); + Assertions.assertTrue(am1.setApplicationLastResponseId(Integer.MAX_VALUE)); // Both allocate should succeed am1.schedule(); // send allocate with responseId = Integer.MAX_VALUE - Assert.assertEquals(0, am1.getResponseId()); + Assertions.assertEquals(0, am1.getResponseId()); am1.schedule(); // send allocate with responseId = 0 - Assert.assertEquals(1, am1.getResponseId()); + Assertions.assertEquals(1, am1.getResponseId()); } finally { rm.stop(); } } - @Test(timeout=600000) + @Test + @Timeout(value = 600) public void testInvalidContainerReleaseRequest() throws Exception { MockRM rm = new MockRM(conf); @@ -232,7 +236,7 @@ public void testInvalidContainerReleaseRequest() throws Exception { alloc1Response = am1.schedule(); } - Assert.assertTrue(alloc1Response.getAllocatedContainers().size() > 0); + Assertions.assertTrue(alloc1Response.getAllocatedContainers().size() > 0); RMApp app2 = MockRMAppSubmitter.submitWithMemory(1024, rm); @@ -252,14 +256,15 @@ public void testInvalidContainerReleaseRequest() throws Exception { sb.append(cId.toString()); sb.append(" not belonging to this application attempt : "); sb.append(attempt2.getAppAttemptId().toString()); - Assert.assertTrue(e.getMessage().contains(sb.toString())); + Assertions.assertTrue(e.getMessage().contains(sb.toString())); } } finally { rm.stop(); } } - @Test(timeout=1200000) + @Test + @Timeout(value = 1200) public void testProgressFilter() throws Exception{ MockRM rm = new MockRM(conf); rm.start(); @@ -324,7 +329,8 @@ public void testProgressFilter() throws Exception{ } } - @Test(timeout=1200000) + @Test + @Timeout(value = 1200) public void testFinishApplicationMasterBeforeRegistering() throws Exception { MockRM rm = new MockRM(conf); @@ -342,9 +348,9 @@ public void testFinishApplicationMasterBeforeRegistering() throws Exception { am1.unregisterAppAttempt(req, false); fail("ApplicationMasterNotRegisteredException should be thrown"); } catch (ApplicationMasterNotRegisteredException e) { - Assert.assertNotNull(e); - Assert.assertNotNull(e.getMessage()); - Assert.assertTrue(e.getMessage().contains( + Assertions.assertNotNull(e); + Assertions.assertNotNull(e.getMessage()); + Assertions.assertTrue(e.getMessage().contains( "Application Master is trying to unregister before registering for:" )); } catch (Exception e) { @@ -361,7 +367,8 @@ public void testFinishApplicationMasterBeforeRegistering() throws Exception { } } - @Test(timeout = 1200000) + @Test + @Timeout(value = 1200) public void testRepeatedFinishApplicationMaster() throws Exception { CountingDispatcher dispatcher = new CountingDispatcher(); @@ -387,8 +394,8 @@ protected Dispatcher createDispatcher() { am1.unregisterAppAttempt(req, false); } rm.drainEvents(); - Assert.assertEquals("Expecting only one event", 1, - dispatcher.getEventCount()); + Assertions.assertEquals(1 +, dispatcher.getEventCount(), "Expecting only one event"); } finally { rm.stop(); } @@ -412,7 +419,8 @@ public int getEventCount() { } } - @Test(timeout = 3000000) + @Test + @Timeout(value = 3000) public void testResourceTypes() throws Exception { HashMap> driver = @@ -464,12 +472,13 @@ public void testResourceTypes() throws Exception { EnumSet types = resp.getSchedulerResourceTypes(); LOG.info("types = " + types.toString()); - Assert.assertEquals(expectedValue, types); + Assertions.assertEquals(expectedValue, types); rm.stop(); } } - @Test(timeout=1200000) + @Test + @Timeout(value = 1200) public void testAllocateAfterUnregister() throws Exception { MockRM rm = new MockRM(conf); rm.start(); @@ -495,10 +504,11 @@ public void testAllocateAfterUnregister() throws Exception { nm1.nodeHeartbeat(true); rm.drainEvents(); alloc1Response = am1.schedule(); - Assert.assertEquals(0, alloc1Response.getAllocatedContainers().size()); + Assertions.assertEquals(0, alloc1Response.getAllocatedContainers().size()); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testUpdateTrackingUrl() throws Exception { conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class); @@ -514,7 +524,7 @@ public void testUpdateTrackingUrl() throws Exception { RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); am1.registerAppAttempt(); - Assert.assertEquals("N/A", rm.getRMContext().getRMApps().get( + Assertions.assertEquals("N/A", rm.getRMContext().getRMApps().get( app1.getApplicationId()).getOriginalTrackingUrl()); AllocateRequestPBImpl allocateRequest = new AllocateRequestPBImpl(); @@ -526,17 +536,18 @@ public void testUpdateTrackingUrl() throws Exception { // wait until RMAppAttemptEventType.STATUS_UPDATE is handled rm.drainEvents(); - Assert.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( + Assertions.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( app1.getApplicationId()).getOriginalTrackingUrl()); // Send it again am1.allocate(allocateRequest); - Assert.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( + Assertions.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( app1.getApplicationId()).getOriginalTrackingUrl()); rm.stop(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testValidateRequestCapacityAgainstMinMaxAllocation() throws Exception { Map riMap = @@ -582,7 +593,7 @@ public void testValidateRequestCapacityAgainstMinMaxAllocation() } catch (InvalidResourceRequestException e) { exception = true; } - Assert.assertTrue(exception); + Assertions.assertTrue(exception); exception = false; try { @@ -595,12 +606,13 @@ public void testValidateRequestCapacityAgainstMinMaxAllocation() } catch (InvalidResourceRequestException e) { exception = true; } - Assert.assertTrue(exception); + Assertions.assertTrue(exception); rm.close(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testRequestCapacityMinMaxAllocationForResourceTypes() throws Exception { Map riMap = initializeMandatoryResources(); @@ -637,25 +649,25 @@ public void testRequestCapacityMinMaxAllocationForResourceTypes() RMApp app1 = MockRMAppSubmitter.submit(rm, data); MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm1); - Assert.assertEquals(Resource.newInstance(GB, 1), + Assertions.assertEquals(Resource.newInstance(GB, 1), getResourceUsageForQueue(rm, getDefaultQueueName())); // Request memory > allowed try { requestResources(am1, 9 * GB, 1, ImmutableMap.of()); - Assert.fail("Should throw InvalidResourceRequestException"); + Assertions.fail("Should throw InvalidResourceRequestException"); } catch (InvalidResourceRequestException ignored) {} try { // Request vcores > allowed requestResources(am1, GB, 18, ImmutableMap.of()); - Assert.fail("Should throw InvalidResourceRequestException"); + Assertions.fail("Should throw InvalidResourceRequestException"); } catch (InvalidResourceRequestException ignored) {} try { // Request custom resource 'res_1' > allowed requestResources(am1, GB, 2, ImmutableMap.of(CUSTOM_RES, 100)); - Assert.fail("Should throw InvalidResourceRequestException"); + Assertions.fail("Should throw InvalidResourceRequestException"); } catch (InvalidResourceRequestException ignored) {} rm.close(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockRM.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockRM.java index 6c24a0563aff8..88c3561345bbd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockRM.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/MockRM.java @@ -100,7 +100,7 @@ import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.YarnVersionInfo; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.event.Level; @@ -239,7 +239,7 @@ private void waitForState(ApplicationId appId, EnumSet finalStates) throws InterruptedException { drainEventsImplicitly(); RMApp app = getRMContext().getRMApps().get(appId); - Assert.assertNotNull("app shouldn't be null", app); + Assertions.assertNotNull(app, "app shouldn't be null"); final int timeoutMsecs = 80 * SECOND; int timeWaiting = 0; while (!finalStates.contains(app.getState())) { @@ -254,8 +254,8 @@ private void waitForState(ApplicationId appId, EnumSet finalStates) } LOG.info("App State is : " + app.getState()); - Assert.assertTrue("App State is not correct (timeout).", - finalStates.contains(app.getState())); + Assertions.assertTrue( + finalStates.contains(app.getState()), "App State is not correct (timeout)."); } /** @@ -270,7 +270,7 @@ public void waitForState(ApplicationId appId, RMAppState finalState) throws InterruptedException { drainEventsImplicitly(); RMApp app = getRMContext().getRMApps().get(appId); - Assert.assertNotNull("app shouldn't be null", app); + Assertions.assertNotNull(app, "app shouldn't be null"); final int timeoutMsecs = 80 * SECOND; int timeWaiting = 0; while (!finalState.equals(app.getState())) { @@ -285,8 +285,8 @@ public void waitForState(ApplicationId appId, RMAppState finalState) } LOG.info("App State is : " + app.getState()); - Assert.assertEquals("App State is not correct (timeout).", finalState, - app.getState()); + Assertions.assertEquals(finalState +, app.getState(), "App State is not correct (timeout)."); } /** @@ -316,7 +316,7 @@ public void waitForState(ApplicationAttemptId attemptId, throws InterruptedException { drainEventsImplicitly(); RMApp app = getRMContext().getRMApps().get(attemptId.getApplicationId()); - Assert.assertNotNull("app shouldn't be null", app); + Assertions.assertNotNull(app, "app shouldn't be null"); RMAppAttempt attempt = app.getRMAppAttempt(attemptId); MockRM.waitForState(attempt, finalState, timeoutMsecs); } @@ -359,8 +359,8 @@ public static void waitForState(RMAppAttempt attempt, } LOG.info("Attempt State is : " + attempt.getAppAttemptState()); - Assert.assertEquals("Attempt state is not correct (timeout).", finalState, - attempt.getState()); + Assertions.assertEquals(finalState +, attempt.getState(), "Attempt state is not correct (timeout)."); } public void waitForContainerToComplete(RMAppAttempt attempt, @@ -384,7 +384,7 @@ public void waitForContainerToComplete(RMAppAttempt attempt, public MockAM waitForNewAMToLaunchAndRegister(ApplicationId appId, int attemptSize, MockNM nm) throws Exception { RMApp app = getRMContext().getRMApps().get(appId); - Assert.assertNotNull(app); + Assertions.assertNotNull(app); int timeWaiting = 0; while (app.getAppAttempts().size() != attemptSize) { if (timeWaiting >= TIMEOUT_MS_FOR_ATTEMPT) { @@ -607,7 +607,7 @@ public void waitForState(NodeId nodeId, NodeState finalState) Thread.sleep(WAIT_MS_PER_LOOP); timeWaiting += WAIT_MS_PER_LOOP; } - Assert.assertNotNull("node shouldn't be null (timedout)", node); + Assertions.assertNotNull(node, "node shouldn't be null (timedout)"); while (!finalState.equals(node.getState())) { if (timeWaiting >= TIMEOUT_MS_FOR_CONTAINER_AND_NODE) { break; @@ -620,22 +620,22 @@ public void waitForState(NodeId nodeId, NodeState finalState) } LOG.info("Node " + nodeId + " State is : " + node.getState()); - Assert.assertEquals("Node state is not correct (timedout)", finalState, - node.getState()); + Assertions.assertEquals(finalState +, node.getState(), "Node state is not correct (timedout)"); } public void sendNodeGracefulDecommission( MockNM nm, int timeout) throws Exception { RMNodeImpl node = (RMNodeImpl) getRMContext().getRMNodes().get(nm.getNodeId()); - Assert.assertNotNull("node shouldn't be null", node); + Assertions.assertNotNull(node, "node shouldn't be null"); node.handle(new RMNodeDecommissioningEvent(nm.getNodeId(), timeout)); } public void sendNodeEvent(MockNM nm, RMNodeEventType event) throws Exception { RMNodeImpl node = (RMNodeImpl) getRMContext().getRMNodes().get(nm.getNodeId()); - Assert.assertNotNull("node shouldn't be null", node); + Assertions.assertNotNull(node, "node shouldn't be null"); node.handle(new RMNodeEvent(nm.getNodeId(), event)); } @@ -883,9 +883,9 @@ private static void waitForSchedulerAppAttemptAdded( } tick++; } - Assert.assertNotNull("Timed out waiting for SchedulerApplicationAttempt=" + - attemptId + " to be added.", ((AbstractYarnScheduler) - rm.getResourceScheduler()).getApplicationAttempt(attemptId)); + Assertions.assertNotNull(((AbstractYarnScheduler) + rm.getResourceScheduler()).getApplicationAttempt(attemptId), "Timed out waiting for SchedulerApplicationAttempt=" + + attemptId + " to be added."); } public static MockAM launchAMWhenAsyncSchedulingEnabled(RMApp app, MockRM rm) @@ -1033,8 +1033,8 @@ public void waitForAppRemovedFromScheduler(ApplicationId appId) Thread.sleep(WAIT_MS_PER_LOOP); timeWaiting += WAIT_MS_PER_LOOP; } - Assert.assertTrue("app is not removed from scheduler (timeout).", - !apps.containsKey(appId)); + Assertions.assertTrue( + !apps.containsKey(appId), "app is not removed from scheduler (timeout)."); LOG.info("app is removed from scheduler, " + appId); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/NodeManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/NodeManager.java index 06c4527e5ba73..bb3dec9970fb4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/NodeManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/NodeManager.java @@ -38,7 +38,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.ResourceLocalizationResponse; import org.apache.hadoop.yarn.api.protocolrecords.RestartContainerResponse; import org.apache.hadoop.yarn.api.protocolrecords.RollbackResponse; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.classification.InterfaceAudience.Private; @@ -225,10 +225,10 @@ synchronized public StartContainersResponse startContainers( synchronized public void checkResourceUsage() { LOG.info("Checking resource usage for " + containerManagerAddress); - Assert.assertEquals(available.getMemorySize(), + Assertions.assertEquals(available.getMemorySize(), resourceManager.getResourceScheduler().getNodeReport( this.nodeId).getAvailableResource().getMemorySize()); - Assert.assertEquals(used.getMemorySize(), + Assertions.assertEquals(used.getMemorySize(), resourceManager.getResourceScheduler().getNodeReport( this.nodeId).getUsedResource().getMemorySize()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ParameterizedSchedulerTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ParameterizedSchedulerTestBase.java index 262168573d0ce..b6e5cd34d8adb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ParameterizedSchedulerTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ParameterizedSchedulerTestBase.java @@ -32,7 +32,7 @@ .allocationfile.AllocationFileQueue; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair .allocationfile.AllocationFileWriter; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -113,7 +113,7 @@ protected void configureFairScheduler(YarnConfiguration configuration) { configuration.setLong(FairSchedulerConfiguration.UPDATE_INTERVAL_MS, 10); } - @After + @AfterEach public void tearDown() { if (schedulerType == SchedulerType.FAIR) { (new File(FS_ALLOC_FILE)).delete(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/QueueACLsTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/QueueACLsTestBase.java index 84e86fa6168b4..398cf406286c3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/QueueACLsTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/QueueACLsTestBase.java @@ -24,7 +24,7 @@ import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.yarn.api.records.QueueACL; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.apache.hadoop.security.authorize.AccessControlList; import org.apache.hadoop.yarn.api.ApplicationClientProtocol; @@ -41,8 +41,8 @@ import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; public abstract class QueueACLsTestBase extends ACLsTestBase { @@ -59,7 +59,7 @@ public abstract class QueueACLsTestBase extends ACLsTestBase { abstract public void updateConfigWithDAndD1Queues(String rootAcl, String queueDAcl, String queueD1Acl) throws IOException; - @After + @AfterEach public void tearDown() { if (resourceManager != null) { resourceManager.stop(); @@ -211,14 +211,14 @@ private void checkAccess(boolean access, String queueName) UserGroupInformation user = UserGroupInformation.getCurrentUser(); String failureMsg = "Wrong %s access to %s queue"; - Assert.assertEquals( - String.format(failureMsg, QueueACL.ADMINISTER_QUEUE, queueName), - access, resourceManager.getResourceScheduler() - .checkAccess(user, QueueACL.ADMINISTER_QUEUE, queueName)); - Assert.assertEquals( - String.format(failureMsg, QueueACL.SUBMIT_APPLICATIONS, queueName), - access, resourceManager.getResourceScheduler() - .checkAccess(user, QueueACL.SUBMIT_APPLICATIONS, queueName)); + Assertions.assertEquals( + + access, resourceManager.getResourceScheduler() + .checkAccess(user, QueueACL.ADMINISTER_QUEUE, queueName), String.format(failureMsg, QueueACL.ADMINISTER_QUEUE, queueName)); + Assertions.assertEquals( + + access, resourceManager.getResourceScheduler() + .checkAccess(user, QueueACL.SUBMIT_APPLICATIONS, queueName), String.format(failureMsg, QueueACL.SUBMIT_APPLICATIONS, queueName)); } private void verifyGetClientAMToken(String submitter, String queueAdmin, @@ -236,7 +236,7 @@ private void verifyGetClientAMToken(String submitter, String queueAdmin, GetApplicationReportResponse adMinUserGetReport = adMinUserClient.getApplicationReport(appReportRequest); - Assert.assertEquals(submitterGetReport.getApplicationReport() + Assertions.assertEquals(submitterGetReport.getApplicationReport() .getClientToAMToken(), adMinUserGetReport.getApplicationReport() .getClientToAMToken()); } @@ -255,10 +255,10 @@ private void verifyKillAppFailure(String submitter, String killer, // Kill app as the killer try { killerClient.forceKillApplication(finishAppRequest); - Assert.fail("App killing by the enemy should fail!!"); + Assertions.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( + Assertions.assertTrue(e.getMessage().contains( "User " + killer + " cannot perform operation MODIFY_APP on " + applicationId)); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/RMHATestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/RMHATestBase.java index c4a6e9dad64f8..04e0aa0e887fa 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/RMHATestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/RMHATestBase.java @@ -40,9 +40,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler; import org.apache.hadoop.yarn.server.security.ApplicationACLsManager; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; public abstract class RMHATestBase extends ClientBaseWithFixes{ @@ -57,7 +57,7 @@ public abstract class RMHATestBase extends ClientBaseWithFixes{ Configuration confForRM1; Configuration confForRM2; - @Before + @BeforeEach public void setup() throws Exception { configuration.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); configuration.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2"); @@ -83,7 +83,7 @@ public void setup() throws Exception { confForRM2.set(YarnConfiguration.RM_HA_ID, "rm2"); } - @After + @AfterEach public void teardown() { if (rm1 != null) { rm1.stop(); @@ -197,9 +197,9 @@ protected boolean isFinalState(RMAppState state) { protected void explicitFailover() throws IOException { rm1.adminService.transitionToStandby(requestInfo); rm2.adminService.transitionToActive(requestInfo); - Assert.assertTrue(rm1.getRMContext().getHAServiceState() + Assertions.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.STANDBY); - Assert.assertTrue(rm2.getRMContext().getHAServiceState() + Assertions.assertTrue(rm2.getRMContext().getHAServiceState() == HAServiceState.ACTIVE); } @@ -207,16 +207,16 @@ protected void startRMs(MockRM rm1, Configuration confForRM1, MockRM rm2, Configuration confForRM2) throws IOException { rm1.init(confForRM1); rm1.start(); - Assert.assertTrue(rm1.getRMContext().getHAServiceState() + Assertions.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.STANDBY); rm2.init(confForRM2); rm2.start(); - Assert.assertTrue(rm2.getRMContext().getHAServiceState() + Assertions.assertTrue(rm2.getRMContext().getHAServiceState() == HAServiceState.STANDBY); rm1.adminService.transitionToActive(requestInfo); - Assert.assertTrue(rm1.getRMContext().getHAServiceState() + Assertions.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.ACTIVE); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ReservationACLsTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ReservationACLsTestBase.java index a0fe708c77e20..91b2d45c1db3b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ReservationACLsTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/ReservationACLsTestBase.java @@ -58,9 +58,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair .allocationfile.AllocationFileWriter; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -82,7 +82,7 @@ public ReservationACLsTestBase(Configuration conf, boolean useFullPath) { useFullQueuePath = useFullPath; } - @After + @AfterEach public void tearDown() { if (resourceManager != null) { resourceManager.stop(); @@ -258,7 +258,7 @@ private void verifySubmitReservationFailure(String submitter, String try { ReservationId reservationId = createReservation(submitter); submitReservation(submitter, queueName, reservationId); - Assert.fail("Submit reservation by the enemy should fail!"); + Assertions.fail("Submit reservation by the enemy should fail!"); } catch (YarnException e) { handleAdministerException(e, submitter, queueName, ReservationACL .SUBMIT_RESERVATIONS.name()); @@ -286,7 +286,7 @@ private void verifyListReservationFailure(String lister, try { listReservation(lister, queueName); - Assert.fail("List reservation by the enemy should fail!"); + Assertions.fail("List reservation by the enemy should fail!"); } catch (YarnException e) { handleAdministerException(e, lister, queueName, ReservationACL .LIST_RESERVATIONS.name()); @@ -316,7 +316,7 @@ private void verifyListReservationByIdFailure(String lister, submitReservation(originalSubmitter, queueName, reservationId); try { listReservationById(lister, reservationId, queueName); - Assert.fail("List reservation by the enemy should fail!"); + Assertions.fail("List reservation by the enemy should fail!"); } catch (YarnException e) { handleAdministerException(e, lister, queueName, ReservationACL .LIST_RESERVATIONS.name()); @@ -341,7 +341,7 @@ private void verifyDeleteReservationFailure(String killer, try { deleteReservation(killer, reservationId); - Assert.fail("Reservation deletion by the enemy should fail!"); + Assertions.fail("Reservation deletion by the enemy should fail!"); } catch (YarnException e) { handleAdministerException(e, killer, queueName, ReservationACL .ADMINISTER_RESERVATIONS.name()); @@ -378,7 +378,7 @@ private void verifyUpdateReservationFailure(String updater, ApplicationClientProtocol unauthorizedClient = getRMClientForUser(updater); try { unauthorizedClient.updateReservation(updateRequest); - Assert.fail("Reservation updating by the enemy should fail."); + Assertions.fail("Reservation updating by the enemy should fail."); } catch (YarnException e) { handleAdministerException(e, updater, queueName, ReservationACL .ADMINISTER_RESERVATIONS.name()); @@ -454,7 +454,7 @@ private void submitReservation(String submitter, private void handleAdministerException(Exception e, String user, String queue, String operation) { LOG.info("Got exception while killing app as the enemy", e); - Assert.assertTrue(e.getMessage().contains("User " + user + Assertions.assertTrue(e.getMessage().contains("User " + user + " cannot perform operation " + operation + " on queue " + queue)); } @@ -477,13 +477,13 @@ private void registerNode(String host, int memory, int vCores) throws Thread.sleep(100); } while (attempts-- > 0); if (attempts <= 0) { - Assert.fail("Exhausted attempts in checking if node capacity was " + Assertions.fail("Exhausted attempts in checking if node capacity was " + "added to the plan"); } } catch (Exception e) { e.printStackTrace(); - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java index 79b0cabce107a..bcfa1dcdcf16a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java @@ -75,11 +75,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState; import org.apache.hadoop.yarn.util.Records; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @@ -96,7 +96,7 @@ public class TestAMAuthorization { // Note : Any test case in ResourceManager package that creates a proxy has // to be run with enabling hadoop.security.token.service.use_ip. And reset // to false at the end of test class. See YARN-5208 - @BeforeClass + @BeforeAll public static void setUp() { Configuration conf = new Configuration(); conf.setBoolean( @@ -104,7 +104,7 @@ public static void setUp() { SecurityUtil.setConfiguration(conf); } - @AfterClass + @AfterAll public static void resetConf() { Configuration conf = new Configuration(); conf.setBoolean( @@ -127,7 +127,7 @@ public TestAMAuthorization(Configuration conf) { UserGroupInformation.setConfiguration(conf); } - @After + @AfterEach public void tearDown() { if (rm != null) { rm.stop(); @@ -285,7 +285,7 @@ public void testAuthorizedAccess() throws Exception { LOG.info("Waiting for AM Launch to happen.."); Thread.sleep(1000); } - Assert.assertNotNull(containerManager.containerTokens); + Assertions.assertNotNull(containerManager.containerTokens); RMAppAttempt attempt = app.getCurrentAppAttempt(); ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId(); @@ -317,12 +317,12 @@ public ApplicationMasterProtocol run() { .newRecord(RegisterApplicationMasterRequest.class); RegisterApplicationMasterResponse response = client.registerApplicationMaster(request); - Assert.assertNotNull(response.getClientToAMTokenMasterKey()); + Assertions.assertNotNull(response.getClientToAMTokenMasterKey()); if (UserGroupInformation.isSecurityEnabled()) { - Assert + Assertions .assertTrue(response.getClientToAMTokenMasterKey().array().length > 0); } - Assert.assertEquals("Register response has bad ACLs", "*", + Assertions.assertEquals("Register response has bad ACLs", "*", response.getApplicationACLs().get(ApplicationAccessType.VIEW_APP)); } @@ -343,7 +343,7 @@ public void testUnauthorizedAccess() throws Exception { LOG.info("Waiting for AM Launch to happen.."); Thread.sleep(1000); } - Assert.assertNotNull(containerManager.containerTokens); + Assertions.assertNotNull(containerManager.containerTokens); RMAppAttempt attempt = app.getCurrentAppAttempt(); ApplicationAttemptId applicationAttemptId = attempt.getAppAttemptId(); @@ -373,7 +373,7 @@ public ApplicationMasterProtocol run() { .newRecord(RegisterApplicationMasterRequest.class); try { client.registerApplicationMaster(request); - Assert.fail("Should fail with authorization error"); + Assertions.fail("Should fail with authorization error"); } catch (Exception e) { if (isCause(AccessControlException.class, e)) { // Because there are no tokens, the request should be rejected as the @@ -385,7 +385,7 @@ public ApplicationMasterProtocol run() { expectedMessage = "SIMPLE authentication is not enabled. Available:[TOKEN]"; } - Assert.assertTrue(e.getCause().getMessage().contains(expectedMessage)); + Assertions.assertTrue(e.getCause().getMessage().contains(expectedMessage)); } else { throw e; } @@ -441,7 +441,7 @@ private void waitForLaunchedState(RMAppAttempt attempt) + "Current state is " + attempt.getAppAttemptState()); Thread.sleep(1000); } - Assert.assertEquals(attempt.getAppAttemptState(), + Assertions.assertEquals(attempt.getAppAttemptState(), RMAppAttemptState.LAUNCHED); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java index 50fc8fd67deac..0fc6847ecd0df 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManager.java @@ -87,11 +87,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.mockito.ArgumentCaptor; @@ -118,8 +119,8 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes.getAutoCreatedQueueTemplateConfPrefix; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePrefixes.getQueuePrefix; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -248,7 +249,7 @@ protected void addToCompletedApps(TestRMAppManager appMonitor, RMContext rmConte private QueueInfo mockDefaultQueueInfo; @SuppressWarnings("deprecation") - @Before + @BeforeEach public void setUp() throws IOException { long now = System.currentTimeMillis(); @@ -510,7 +511,7 @@ public void testLegacyAutoCreatedQueuesWithACLTemplates() ((CapacityScheduler) newMockRM.getResourceScheduler()); cs.getCapacitySchedulerQueueManager().createQueue(user2QueuePath); AutoCreatedLeafQueue autoCreatedLeafQueue = (AutoCreatedLeafQueue) cs.getQueue("user2"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedLeafQueue); + Assertions.assertNotNull(autoCreatedLeafQueue, "Auto Creation of Queue failed"); ManagedParentQueue parentQueue = (ManagedParentQueue) cs.getQueue("parent"); assertEquals(parentQueue, autoCreatedLeafQueue.getParent()); // reinitialize to load the ACLs for the queue @@ -599,12 +600,12 @@ public void testFlexibleAutoCreatedQueuesWithSpecializedACLTemplatesAndDynamicPa cs.getCapacitySchedulerQueueManager().createQueue(new QueuePath("root.parent.user2.user3")); ParentQueue autoCreatedParentQueue = (ParentQueue) cs.getQueue("user2"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedParentQueue); + Assertions.assertNotNull(autoCreatedParentQueue, "Auto Creation of Queue failed"); ParentQueue parentQueue = (ParentQueue) cs.getQueue("parent"); assertEquals(parentQueue, autoCreatedParentQueue.getParent()); LeafQueue autoCreatedLeafQueue = (LeafQueue) cs.getQueue("user3"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedLeafQueue); + Assertions.assertNotNull(autoCreatedLeafQueue, "Auto Creation of Queue failed"); assertEquals(autoCreatedParentQueue, autoCreatedLeafQueue.getParent()); // reinitialize to load the ACLs for the queue @@ -722,12 +723,12 @@ private void testFlexibleAQCDWithMixedTemplatesDynamicParentACLScenario( cs.getCapacitySchedulerQueueManager().createQueue(new QueuePath("root.parent.user2.user3")); ParentQueue autoCreatedParentQueue = (ParentQueue) cs.getQueue("user2"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedParentQueue); + Assertions.assertNotNull(autoCreatedParentQueue, "Auto Creation of Queue failed"); ParentQueue parentQueue = (ParentQueue) cs.getQueue("parent"); assertEquals(parentQueue, autoCreatedParentQueue.getParent()); LeafQueue autoCreatedLeafQueue = (LeafQueue) cs.getQueue("user3"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedLeafQueue); + Assertions.assertNotNull(autoCreatedLeafQueue, "Auto Creation of Queue failed"); assertEquals(autoCreatedParentQueue, autoCreatedLeafQueue.getParent()); // reinitialize to load the ACLs for the queue @@ -822,7 +823,7 @@ private void testFlexibleAQCLeafOnly( ParentQueue autoCreatedParentQueue = (ParentQueue) cs.getQueue("parent"); LeafQueue autoCreatedLeafQueue = (LeafQueue) cs.getQueue("user2"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedLeafQueue); + Assertions.assertNotNull(autoCreatedLeafQueue, "Auto Creation of Queue failed"); assertEquals(autoCreatedParentQueue, autoCreatedLeafQueue.getParent()); // reinitialize to load the ACLs for the queue @@ -916,12 +917,12 @@ public void testFlexibleAutoCreatedQueuesWithSpecializedACLTemplatesAndDynamicRo cs.getCapacitySchedulerQueueManager().createQueue(new QueuePath("root.user2.user3")); ParentQueue autoCreatedParentQueue = (ParentQueue) cs.getQueue("user2"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedParentQueue); + Assertions.assertNotNull(autoCreatedParentQueue, "Auto Creation of Queue failed"); ParentQueue parentQueue = (ParentQueue) cs.getQueue("root"); assertEquals(parentQueue, autoCreatedParentQueue.getParent()); LeafQueue autoCreatedLeafQueue = (LeafQueue) cs.getQueue("user3"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedLeafQueue); + Assertions.assertNotNull(autoCreatedLeafQueue, "Auto Creation of Queue failed"); assertEquals(autoCreatedParentQueue, autoCreatedLeafQueue.getParent()); // reinitialize to load the ACLs for the queue @@ -994,16 +995,16 @@ public void testFlexibleAutoCreatedQueuesMultiLevelDynamicParentACL() cs.getCapacitySchedulerQueueManager().createQueue(new QueuePath("root.user2.user3.queue")); ParentQueue autoCreatedParentQueue = (ParentQueue) cs.getQueue("user2"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedParentQueue); + Assertions.assertNotNull(autoCreatedParentQueue, "Auto Creation of Queue failed"); ParentQueue parentQueue = (ParentQueue) cs.getQueue("root"); assertEquals(parentQueue, autoCreatedParentQueue.getParent()); ParentQueue autoCreatedParentQueue2 = (ParentQueue) cs.getQueue("user3"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedParentQueue2); + Assertions.assertNotNull(autoCreatedParentQueue2, "Auto Creation of Queue failed"); assertEquals(autoCreatedParentQueue, autoCreatedParentQueue2.getParent()); LeafQueue autoCreatedLeafQueue = (LeafQueue) cs.getQueue("queue"); - Assert.assertNotNull("Auto Creation of Queue failed", autoCreatedLeafQueue); + Assertions.assertNotNull(autoCreatedLeafQueue, "Auto Creation of Queue failed"); assertEquals(autoCreatedParentQueue, autoCreatedParentQueue2.getParent()); // reinitialize to load the ACLs for the queue @@ -1046,7 +1047,7 @@ private static void verifyAppSubmissionFailure(TestRMAppManager appManager, String user) { try { appManager.submitApplication(submission, user); - Assert.fail( + Assertions.fail( String.format("should fail since %s does not have permission to submit to queue", user)); } catch (YarnException e) { assertTrue(e.getCause() instanceof AccessControlException); @@ -1060,10 +1061,10 @@ private static void verifyAppSubmission(ApplicationSubmissionContext submission, String expectedQueue) throws YarnException { appManager.submitApplication(submission, user); RMApp app = rmContext.getRMApps().get(submission.getApplicationId()); - Assert.assertNotNull("app should not be null", app); - Assert.assertEquals(String.format("the queue should be placed on '%s' queue", expectedQueue), - expectedQueue, - app.getQueue()); + Assertions.assertNotNull(app, "app should not be null"); + Assertions.assertEquals( + expectedQueue +, app.getQueue(), String.format("the queue should be placed on '%s' queue", expectedQueue)); } private static ApplicationSubmissionContext createAppSubmissionContext(ApplicationId id) { @@ -1078,7 +1079,7 @@ private static ApplicationSubmissionContext createAppSubmissionContext(Applicati return appSubmission; } - @After + @AfterEach public void tearDown() { setAppEventType(RMAppEventType.KILL); ((Service)rmContext.getDispatcher()).stop(); @@ -1096,18 +1097,18 @@ public void testRMAppRetireNone() throws Exception { conf.setInt(YarnConfiguration.RM_MAX_COMPLETED_APPLICATIONS, 10); TestRMAppManager appMonitor = new TestRMAppManager(rmContext,conf); - Assert.assertEquals("Number of apps incorrect before checkAppTimeLimit", - 10, rmContext.getRMApps().size()); + Assertions.assertEquals( + 10, rmContext.getRMApps().size(), "Number of apps incorrect before checkAppTimeLimit"); // add them to completed apps list addToCompletedApps(appMonitor, rmContext); // shouldn't have to many apps appMonitor.checkAppNumCompletedLimit(); - Assert.assertEquals("Number of apps incorrect after # completed check", 10, - rmContext.getRMApps().size()); - Assert.assertEquals("Number of completed apps incorrect after check", 10, - appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals(10 +, rmContext.getRMApps().size(), "Number of apps incorrect after # completed check"); + Assertions.assertEquals(10 +, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect after check"); verify(rmContext.getStateStore(), never()).removeApplication( isA(RMApp.class)); } @@ -1141,7 +1142,7 @@ public void testQueueSubmitWithNoPermission() throws IOException { if (e instanceof YarnException) { assertTrue(e.getCause() instanceof AccessControlException); } else { - Assert.fail("Yarn exception is expected : " + e.getMessage()); + Assertions.fail("Yarn exception is expected : " + e.getMessage()); } } finally { mockRM.close(); @@ -1158,18 +1159,18 @@ public void testRMAppRetireSome() throws Exception { conf.setInt(YarnConfiguration.RM_MAX_COMPLETED_APPLICATIONS, 3); TestRMAppManager appMonitor = new TestRMAppManager(rmContext, conf); - Assert.assertEquals("Number of apps incorrect before", 10, rmContext - .getRMApps().size()); + Assertions.assertEquals(10, rmContext + .getRMApps().size(), "Number of apps incorrect before"); // add them to completed apps list addToCompletedApps(appMonitor, rmContext); // shouldn't have to many apps appMonitor.checkAppNumCompletedLimit(); - Assert.assertEquals("Number of apps incorrect after # completed check", 3, - rmContext.getRMApps().size()); - Assert.assertEquals("Number of completed apps incorrect after check", 3, - appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals(3 +, rmContext.getRMApps().size(), "Number of apps incorrect after # completed check"); + Assertions.assertEquals(3 +, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect after check"); verify(rmContext.getStateStore(), times(7)).removeApplication( isA(RMApp.class)); } @@ -1188,7 +1189,7 @@ public void testRMAppRetireSomeDifferentStates() throws Exception { // clear out applications map rmContext.getRMApps().clear(); - Assert.assertEquals("map isn't empty", 0, rmContext.getRMApps().size()); + Assertions.assertEquals(0, rmContext.getRMApps().size(), "map isn't empty"); // 6 applications are in final state, 4 are not in final state. // / set with various finished states @@ -1215,18 +1216,18 @@ public void testRMAppRetireSomeDifferentStates() throws Exception { app = new MockRMApp(9, now - 20000, RMAppState.FAILED); rmContext.getRMApps().put(app.getApplicationId(), app); - Assert.assertEquals("Number of apps incorrect before", 10, rmContext - .getRMApps().size()); + Assertions.assertEquals(10, rmContext + .getRMApps().size(), "Number of apps incorrect before"); // add them to completed apps list addToCompletedApps(appMonitor, rmContext); // shouldn't have to many apps appMonitor.checkAppNumCompletedLimit(); - Assert.assertEquals("Number of apps incorrect after # completed check", 6, - rmContext.getRMApps().size()); - Assert.assertEquals("Number of completed apps incorrect after check", 2, - appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals(6 +, rmContext.getRMApps().size(), "Number of apps incorrect after # completed check"); + Assertions.assertEquals(2 +, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect after check"); // 6 applications in final state, 4 of them are removed verify(rmContext.getStateStore(), times(4)).removeApplication( isA(RMApp.class)); @@ -1239,13 +1240,13 @@ public void testRMAppRetireNullApp() throws Exception { RMContext rmContext = mockRMContext(10, now - 20000); TestRMAppManager appMonitor = new TestRMAppManager(rmContext, new Configuration()); - Assert.assertEquals("Number of apps incorrect before", 10, rmContext - .getRMApps().size()); + Assertions.assertEquals(10, rmContext + .getRMApps().size(), "Number of apps incorrect before"); appMonitor.finishApplication(null); - Assert.assertEquals("Number of completed apps incorrect after check", 0, - appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals(0 +, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect after check"); } @Test @@ -1257,19 +1258,19 @@ public void testRMAppRetireZeroSetting() throws Exception { conf.setInt(YarnConfiguration.RM_STATE_STORE_MAX_COMPLETED_APPLICATIONS, 0); conf.setInt(YarnConfiguration.RM_MAX_COMPLETED_APPLICATIONS, 0); TestRMAppManager appMonitor = new TestRMAppManager(rmContext, conf); - Assert.assertEquals("Number of apps incorrect before", 10, rmContext - .getRMApps().size()); + Assertions.assertEquals(10, rmContext + .getRMApps().size(), "Number of apps incorrect before"); addToCompletedApps(appMonitor, rmContext); - Assert.assertEquals("Number of completed apps incorrect", 10, - appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals(10 +, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect"); appMonitor.checkAppNumCompletedLimit(); - Assert.assertEquals("Number of apps incorrect after # completed check", 0, - rmContext.getRMApps().size()); - Assert.assertEquals("Number of completed apps incorrect after check", 0, - appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals(0 +, rmContext.getRMApps().size(), "Number of apps incorrect after # completed check"); + Assertions.assertEquals(0 +, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect after check"); verify(rmContext.getStateStore(), times(10)).removeApplication( isA(RMApp.class)); } @@ -1288,19 +1289,19 @@ public void testStateStoreAppLimitLessThanMemoryAppLimit() { TestRMAppManager appMonitor = new TestRMAppManager(rmContext, conf); addToCompletedApps(appMonitor, rmContext); - Assert.assertEquals("Number of completed apps incorrect", allApps, - appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals(allApps +, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect"); appMonitor.checkAppNumCompletedLimit(); - Assert.assertEquals("Number of apps incorrect after # completed check", - maxAppsInMemory, rmContext.getRMApps().size()); - Assert.assertEquals("Number of completed apps incorrect after check", - maxAppsInMemory, appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals( + maxAppsInMemory, rmContext.getRMApps().size(), "Number of apps incorrect after # completed check"); + Assertions.assertEquals( + maxAppsInMemory, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect after check"); int numRemoveAppsFromStateStore = 10 - maxAppsInStateStore; verify(rmContext.getStateStore(), times(numRemoveAppsFromStateStore)) .removeApplication(isA(RMApp.class)); - Assert.assertEquals(maxAppsInStateStore, + Assertions.assertEquals(maxAppsInStateStore, appMonitor.getNumberOfCompletedAppsInStateStore()); } @@ -1317,18 +1318,18 @@ public void testStateStoreAppLimitGreaterThanMemoryAppLimit() { TestRMAppManager appMonitor = new TestRMAppManager(rmContext, conf); addToCompletedApps(appMonitor, rmContext); - Assert.assertEquals("Number of completed apps incorrect", allApps, - appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals(allApps +, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect"); appMonitor.checkAppNumCompletedLimit(); int numRemoveApps = allApps - maxAppsInMemory; - Assert.assertEquals("Number of apps incorrect after # completed check", - maxAppsInMemory, rmContext.getRMApps().size()); - Assert.assertEquals("Number of completed apps incorrect after check", - maxAppsInMemory, appMonitor.getCompletedAppsListSize()); + Assertions.assertEquals( + maxAppsInMemory, rmContext.getRMApps().size(), "Number of apps incorrect after # completed check"); + Assertions.assertEquals( + maxAppsInMemory, appMonitor.getCompletedAppsListSize(), "Number of completed apps incorrect after check"); verify(rmContext.getStateStore(), times(numRemoveApps)).removeApplication( isA(RMApp.class)); - Assert.assertEquals(maxAppsInMemory, + Assertions.assertEquals(maxAppsInMemory, appMonitor.getNumberOfCompletedAppsInStateStore()); } @@ -1340,7 +1341,7 @@ protected void setupDispatcher(RMContext rmContext, Configuration conf) { rmContext.getDispatcher().register(RMAppManagerEventType.class, testAppManagerDispatcher); ((Service)rmContext.getDispatcher()).init(conf); ((Service)rmContext.getDispatcher()).start(); - Assert.assertEquals("app event type is wrong before", RMAppEventType.KILL, appEventType); + Assertions.assertEquals(RMAppEventType.KILL, appEventType, "app event type is wrong before"); } @SuppressWarnings("deprecation") @@ -1360,8 +1361,8 @@ public void testRMAppSubmitAMContainerResourceRequests() throws Exception { asContext.setAMContainerResourceRequests(cloneResourceRequests(reqs)); // getAMContainerResourceRequest uses the first entry of // getAMContainerResourceRequests - Assert.assertEquals(reqs.get(0), asContext.getAMContainerResourceRequest()); - Assert.assertEquals(reqs, asContext.getAMContainerResourceRequests()); + Assertions.assertEquals(reqs.get(0), asContext.getAMContainerResourceRequest()); + Assertions.assertEquals(reqs, asContext.getAMContainerResourceRequests()); RMApp app = testRMAppSubmit(); for (ResourceRequest req : reqs) { req.setNodeLabelExpression(RMNodeLabelsManager.NO_LABEL); @@ -1369,7 +1370,7 @@ public void testRMAppSubmitAMContainerResourceRequests() throws Exception { // setAMContainerResourceRequests has priority over // setAMContainerResourceRequest and setResource - Assert.assertEquals(reqs, app.getAMResourceRequests()); + Assertions.assertEquals(reqs, app.getAMResourceRequests()); } @SuppressWarnings("deprecation") @@ -1384,12 +1385,12 @@ public void testRMAppSubmitAMContainerResourceRequest() throws Exception { asContext.setAMContainerResourceRequest(ResourceRequest.clone(req)); // getAMContainerResourceRequests uses a singleton list of // getAMContainerResourceRequest - Assert.assertEquals(req, asContext.getAMContainerResourceRequest()); - Assert.assertEquals(req, asContext.getAMContainerResourceRequests().get(0)); - Assert.assertEquals(1, asContext.getAMContainerResourceRequests().size()); + Assertions.assertEquals(req, asContext.getAMContainerResourceRequest()); + Assertions.assertEquals(req, asContext.getAMContainerResourceRequests().get(0)); + Assertions.assertEquals(1, asContext.getAMContainerResourceRequests().size()); RMApp app = testRMAppSubmit(); // setAMContainerResourceRequest has priority over setResource - Assert.assertEquals(Collections.singletonList(req), + Assertions.assertEquals(Collections.singletonList(req), app.getAMResourceRequests()); } @@ -1416,7 +1417,7 @@ public void testRMAppSubmitAMContainerWithNoLabelByRMDefaultAMNodeLabel() throws RMApp app = rmContext.getRMApps().get(appId); waitUntilEventProcessed(); - Assert.assertEquals(defaultAMNodeLabel, + Assertions.assertEquals(defaultAMNodeLabel, app.getAMResourceRequests().get(0).getNodeLabelExpression()); } @@ -1427,7 +1428,7 @@ public void testRMAppSubmitResource() throws Exception { RMApp app = testRMAppSubmit(); // setResource - Assert.assertEquals(Collections.singletonList( + Assertions.assertEquals(Collections.singletonList( ResourceRequest.newInstance(RMAppAttemptImpl.AM_CONTAINER_PRIORITY, ResourceRequest.ANY, Resources.createResource(1024), 1, true, "")), @@ -1440,9 +1441,9 @@ public void testRMAppSubmitNoResourceRequests() throws Exception { asContext.setAMContainerResourceRequests(null); try { testRMAppSubmit(); - Assert.fail("Should have failed due to no ResourceRequest"); + Assertions.fail("Should have failed due to no ResourceRequest"); } catch (InvalidResourceRequestException e) { - Assert.assertEquals( + Assertions.assertEquals( "Invalid resource request, no resources requested", e.getMessage()); } @@ -1476,7 +1477,7 @@ public void testRMAppSubmitAMContainerResourceRequestsDisagree() req.setNumContainers(1); req.setPriority(Priority.newInstance(0)); } - Assert.assertEquals(reqs, app.getAMResourceRequests()); + Assertions.assertEquals(reqs, app.getAMResourceRequests()); } @Test @@ -1491,12 +1492,12 @@ public void testRMAppSubmitAMContainerResourceRequestsNoAny() asContext.setAMContainerResourceRequests(cloneResourceRequests(reqs)); // getAMContainerResourceRequest uses the first entry of // getAMContainerResourceRequests - Assert.assertEquals(reqs, asContext.getAMContainerResourceRequests()); + Assertions.assertEquals(reqs, asContext.getAMContainerResourceRequests()); try { testRMAppSubmit(); - Assert.fail("Should have failed due to missing ANY ResourceRequest"); + Assertions.fail("Should have failed due to missing ANY ResourceRequest"); } catch (InvalidResourceRequestException e) { - Assert.assertEquals( + Assertions.assertEquals( "Invalid resource request, no resource request specified with *", e.getMessage()); } @@ -1514,12 +1515,12 @@ public void testRMAppSubmitAMContainerResourceRequestsTwoManyAny() asContext.setAMContainerResourceRequests(cloneResourceRequests(reqs)); // getAMContainerResourceRequest uses the first entry of // getAMContainerResourceRequests - Assert.assertEquals(reqs, asContext.getAMContainerResourceRequests()); + Assertions.assertEquals(reqs, asContext.getAMContainerResourceRequests()); try { testRMAppSubmit(); - Assert.fail("Should have failed due to too many ANY ResourceRequests"); + Assertions.fail("Should have failed due to too many ANY ResourceRequests"); } catch (InvalidResourceRequestException e) { - Assert.assertEquals( + Assertions.assertEquals( "Invalid resource request, only one resource request with * is " + "allowed", e.getMessage()); } @@ -1532,17 +1533,17 @@ private RMApp testRMAppSubmit() throws Exception { private RMApp waitUntilEventProcessed() throws InterruptedException { RMApp app = rmContext.getRMApps().get(appId); - Assert.assertNotNull("app is null", app); - Assert.assertEquals("app id doesn't match", appId, app.getApplicationId()); - Assert.assertEquals("app state doesn't match", RMAppState.NEW, app.getState()); + Assertions.assertNotNull(app, "app is null"); + Assertions.assertEquals(appId, app.getApplicationId(), "app id doesn't match"); + Assertions.assertEquals(RMAppState.NEW, app.getState(), "app state doesn't match"); // wait for event to be processed int timeoutSecs = 0; while ((getAppEventType() == RMAppEventType.KILL) && timeoutSecs++ < 20) { Thread.sleep(1000); } - Assert.assertEquals("app event type sent is wrong", RMAppEventType.START, - getAppEventType()); + Assertions.assertEquals(RMAppEventType.START +, getAppEventType(), "app event type sent is wrong"); return app; } @@ -1559,25 +1560,26 @@ public void testRMAppSubmitWithInvalidTokens() throws Exception { asContext.getAMContainerSpec().setTokens(securityTokens); try { appMonitor.submitApplication(asContext, "test"); - Assert.fail("Application submission should fail because" + + Assertions.fail("Application submission should fail because" + " Tokens are invalid."); } catch (YarnException e) { // Exception is expected - assertTrue("The thrown exception is not" + - " java.io.EOFException", - e.getMessage().contains("java.io.EOFException")); + assertTrue( + e.getMessage().contains("java.io.EOFException"), "The thrown exception is not" + + " java.io.EOFException"); } int timeoutSecs = 0; while ((getAppEventType() == RMAppEventType.KILL) && timeoutSecs++ < 20) { Thread.sleep(1000); } - Assert.assertEquals("app event type sent is wrong", - RMAppEventType.APP_REJECTED, getAppEventType()); + Assertions.assertEquals( + RMAppEventType.APP_REJECTED, getAppEventType(), "app event type sent is wrong"); asContext.getAMContainerSpec().setTokens(null); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testRMAppSubmitMaxAppAttempts() throws Exception { int[] globalMaxAppAttempts = new int[] { 10, 1 }; int[] rmAmMaxAttempts = new int[] { 8, 1 }; @@ -1607,8 +1609,8 @@ public void testRMAppSubmitMaxAppAttempts() throws Exception { } appMonitor.submitApplication(asContext, "test"); RMApp app = rmContext.getRMApps().get(appID); - Assert.assertEquals("max application attempts doesn't match", - expectedNums[i][j], app.getMaxAppAttempts()); + Assertions.assertEquals( + expectedNums[i][j], app.getMaxAppAttempts(), "max application attempts doesn't match"); // wait for event to be processed int timeoutSecs = 0; @@ -1621,34 +1623,36 @@ public void testRMAppSubmitMaxAppAttempts() throws Exception { } } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testRMAppSubmitDuplicateApplicationId() throws Exception { ApplicationId appId = MockApps.newAppID(0); asContext.setApplicationId(appId); RMApp appOrig = rmContext.getRMApps().get(appId); - assertTrue("app name matches " - + "but shouldn't", "testApp1" != appOrig.getName()); + assertTrue("testApp1" != appOrig.getName(), "app name matches " + + "but shouldn't"); // our testApp1 should be rejected and original app with same id should be left in place try { appMonitor.submitApplication(asContext, "test"); - Assert.fail("Exception is expected when applicationId is duplicate."); + Assertions.fail("Exception is expected when applicationId is duplicate."); } catch (YarnException e) { - assertTrue("The thrown exception is not the expectd one.", - e.getMessage().contains("Cannot add a duplicate!")); + assertTrue( + e.getMessage().contains("Cannot add a duplicate!"), "The thrown exception is not the expectd one."); } // make sure original app didn't get removed RMApp app = rmContext.getRMApps().get(appId); - Assert.assertNotNull("app is null", app); - Assert.assertEquals("app id doesn't match", - appId, app.getApplicationId()); - Assert.assertEquals("app state doesn't match", - RMAppState.FINISHED, app.getState()); + Assertions.assertNotNull(app, "app is null"); + Assertions.assertEquals( + appId, app.getApplicationId(), "app id doesn't match"); + Assertions.assertEquals( + RMAppState.FINISHED, app.getState(), "app state doesn't match"); } @SuppressWarnings("deprecation") - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testRMAppSubmitInvalidResourceRequest() throws Exception { asContext.setResource(Resources.createResource( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB + 1)); @@ -1656,19 +1660,20 @@ public void testRMAppSubmitInvalidResourceRequest() throws Exception { // submit an app try { appMonitor.submitApplication(asContext, "test"); - Assert.fail("Application submission should fail because resource" + + Assertions.fail("Application submission should fail because resource" + " request is invalid."); } catch (YarnException e) { // Exception is expected // TODO Change this to assert the expected exception type - post YARN-142 // sub-task related to specialized exceptions. - assertTrue("The thrown exception is not" + - " InvalidResourceRequestException", - e.getMessage().contains("Invalid resource request")); + assertTrue( + e.getMessage().contains("Invalid resource request"), "The thrown exception is not" + + " InvalidResourceRequestException"); } } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testEscapeApplicationSummary() { RMApp app = mock(RMAppImpl.class); ApplicationSubmissionContext asc = mock(ApplicationSubmissionContext.class); @@ -1709,8 +1714,8 @@ public void testEscapeApplicationSummary() { new RMAppManager.ApplicationSummary().createAppSummary(app); String msg = summary.toString(); LOG.info("summary: " + msg); - Assert.assertFalse(msg.contains("\n")); - Assert.assertFalse(msg.contains("\r")); + Assertions.assertFalse(msg.contains("\n")); + Assertions.assertFalse(msg.contains("\r")); String escaped = "\\n\\n\\r\\r"; assertTrue(msg.contains("Multiline" + escaped +"AppName")); @@ -1759,16 +1764,16 @@ public ApplicationPlacementContext answer(InvocationOnMock invocation) event = new RMAppEvent(appId, RMAppEventType.APP_NEW_SAVED); rmContext.getRMApps().get(appId).handle(event); - Assert.assertNotNull("app is null", app); - Assert.assertEquals("newQueue", asContext.getQueue()); + Assertions.assertNotNull(app, "app is null"); + Assertions.assertEquals("newQueue", asContext.getQueue()); // wait for event to be processed int timeoutSecs = 0; while ((getAppEventType() == RMAppEventType.KILL) && timeoutSecs++ < 20) { Thread.sleep(1000); } - Assert.assertEquals("app event type sent is wrong", RMAppEventType.START, - getAppEventType()); + Assertions.assertEquals(RMAppEventType.START +, getAppEventType(), "app event type sent is wrong"); } private static ResourceScheduler mockResourceScheduler() { @@ -2012,7 +2017,7 @@ public void testGetUserNameForPlacementNoRuleDefined() .thenReturn(null); String userNameForPlacement = appMonitor .getUserNameForPlacement(user, asContext, placementMgr); - Assert.assertEquals(expectedUser, userNameForPlacement); + Assertions.assertEquals(expectedUser, userNameForPlacement); } @Test @@ -2056,8 +2061,8 @@ private void testCheckAccess(String parent, String queue) verify(scheduler).checkAccess(any(UserGroupInformation.class), any(QueueACL.class), queueNameCaptor.capture()); - assertEquals("Expected access check for queue", - expectedQueue, queueNameCaptor.getValue()); + assertEquals( + expectedQueue, queueNameCaptor.getValue(), "Expected access check for queue"); } private void enableApplicationTagPlacement(boolean userHasAccessToQueue, @@ -2090,7 +2095,7 @@ private void verifyPlacementUsername(final String queue, .thenReturn(appContext); String userNameForPlacement = appMonitor .getUserNameForPlacement(submittingUser, asContext, placementMgr); - Assert.assertEquals(expectedUser, userNameForPlacement); + Assertions.assertEquals(expectedUser, userNameForPlacement); } private void setApplicationTags(String... tags) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManagerWithFairScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManagerWithFairScheduler.java index b3ed5ef58ce48..baf71bb06b922 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManagerWithFairScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAppManagerWithFairScheduler.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; -import static junit.framework.TestCase.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.apache.hadoop.yarn.exceptions.InvalidResourceRequestException.InvalidResourceType.GREATER_THEN_MAX_ALLOCATION; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -55,10 +55,10 @@ import org.apache.hadoop.yarn.server.security.ApplicationACLsManager; import org.apache.hadoop.yarn.util.Records; 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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Testing RMAppManager application submission with fair scheduler. @@ -74,7 +74,7 @@ public class TestAppManagerWithFairScheduler extends AppManagerTestBase { private static String allocFileName = GenericTestUtils.getTestDir(TEST_FOLDER).getAbsolutePath(); - @Before + @BeforeEach public void setup() throws IOException { // Basic config with one queue (override in test if needed) AllocationFileWriter.create() @@ -98,7 +98,7 @@ public void setup() throws IOException { masterService, new ApplicationACLsManager(conf), conf); } - @After + @AfterEach public void teardown(){ File allocFile = GenericTestUtils.getTestDir(TEST_FOLDER); allocFile.delete(); @@ -131,9 +131,9 @@ public void testQueueSubmitWithHighQueueContainerSize() .thenReturn(new ApplicationPlacementContext("limited")); try { rmAppManager.submitApplication(asContext, "test"); - Assert.fail("Test should fail on too high allocation!"); + Assertions.fail("Test should fail on too high allocation!"); } catch (InvalidResourceRequestException e) { - Assert.assertEquals(GREATER_THEN_MAX_ALLOCATION, + Assertions.assertEquals(GREATER_THEN_MAX_ALLOCATION, e.getInvalidResourceType()); } @@ -176,10 +176,10 @@ public void testQueueSubmitWithPermissionLimits() .thenReturn(new ApplicationPlacementContext("noaccess")); try { rmAppManager.submitApplication(asContext, "test"); - Assert.fail("Test should have failed with access denied"); + Assertions.fail("Test should have failed with access denied"); } catch (YarnException e) { - assertTrue("Access exception not found", - e.getCause() instanceof AccessControlException); + assertTrue( + e.getCause() instanceof AccessControlException, "Access exception not found"); } // Submit to submit access queue when(placementMgr.placeApplication(any(), any(), any(Boolean.class))) @@ -249,10 +249,10 @@ public void testQueueSubmitWithAutoCreateQueue() .thenReturn(new ApplicationPlacementContext("root.noaccess.child")); try { rmAppManager.submitApplication(asContext, "test"); - Assert.fail("Test should have failed with access denied"); + Assertions.fail("Test should have failed with access denied"); } catch (YarnException e) { - assertTrue("Access exception not found", - e.getCause() instanceof AccessControlException); + assertTrue( + e.getCause() instanceof AccessControlException, "Access exception not found"); } // Submit to submitonly parent with non existent child queue when(placementMgr.placeApplication(any(), any(), any(Boolean.class))) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java index 7e8cf7e6f4ff2..f8b0ba1b060c3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationACLs.java @@ -43,8 +43,8 @@ .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.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; @@ -76,8 +76,8 @@ 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.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -107,7 +107,7 @@ public TestApplicationACLs(SchedulerType type) throws IOException { super(type); } - @Before + @BeforeEach public void setup() throws InterruptedException, IOException { conf = getConf(); rpc = YarnRPC.create(conf); @@ -181,7 +181,7 @@ public ApplicationClientProtocol run() throws Exception { }); } - @After + @AfterEach public void tearDown() { if(resourceManager != null) { resourceManager.stop(); @@ -294,10 +294,10 @@ private void verifyOwnerAccess() throws Exception { rmClient.getApplicationReport(appReportRequest); // List apps as owner - Assert.assertEquals("App view by owner should list the apps!!", 1, - rmClient.getApplications( + Assertions.assertEquals(1 +, rmClient.getApplications( recordFactory.newRecordInstance(GetApplicationsRequest.class)) - .getApplicationList().size()); + .getApplicationList().size(), "App view by owner should list the apps!!"); // Kill app as owner rmClient.forceKillApplication(finishAppRequest); @@ -325,10 +325,10 @@ private void verifySuperUserAccess() throws Exception { superUserClient.getApplicationReport(appReportRequest); // List apps as superUser - Assert.assertEquals("App view by super-user should list the apps!!", 2, - superUserClient.getApplications( + Assertions.assertEquals(2 +, superUserClient.getApplications( recordFactory.newRecordInstance(GetApplicationsRequest.class)) - .getApplicationList().size()); + .getApplicationList().size(), "App view by super-user should list the apps!!"); // Kill app as the superUser superUserClient.forceKillApplication(finishAppRequest); @@ -356,10 +356,10 @@ private void verifyFriendAccess() throws Exception { friendClient.getApplicationReport(appReportRequest); // List apps as friend - Assert.assertEquals("App view by a friend should list the apps!!", 3, - friendClient.getApplications( + Assertions.assertEquals(3 +, friendClient.getApplications( recordFactory.newRecordInstance(GetApplicationsRequest.class)) - .getApplicationList().size()); + .getApplicationList().size(), "App view by a friend should list the apps!!"); // Kill app as the friend friendClient.forceKillApplication(finishAppRequest); @@ -393,8 +393,8 @@ private void verifyEnemyAccess() throws Exception { .getApplications(recordFactory .newRecordInstance(GetApplicationsRequest.class)) .getApplicationList(); - Assert.assertEquals("App view by enemy should list the apps!!", 4, - appReports.size()); + Assertions.assertEquals(4 +, appReports.size(), "App view by enemy should list the apps!!"); for (ApplicationReport report : appReports) { verifyEnemyAppReport(report); } @@ -402,10 +402,10 @@ private void verifyEnemyAccess() throws Exception { // Kill app as the enemy try { enemyRmClient.forceKillApplication(finishAppRequest); - Assert.fail("App killing by the enemy should fail!!"); + Assertions.fail("App killing by the enemy should fail!!"); } catch (YarnException e) { LOG.info("Got exception while killing app as the enemy", e); - Assert + Assertions .assertTrue(e.getMessage().contains( "User enemy cannot perform operation MODIFY_APP on " + applicationId)); @@ -415,30 +415,30 @@ private void verifyEnemyAccess() throws Exception { } 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()); + Assertions.assertEquals( + UNAVAILABLE, appReport.getHost(), "Enemy should not see app host!"); + Assertions.assertEquals( + -1, appReport.getRpcPort(), "Enemy should not see app rpc port!"); + Assertions.assertEquals( + null, appReport.getClientToAMToken(), "Enemy should not see app client token!"); + Assertions.assertEquals( + UNAVAILABLE, appReport.getDiagnostics(), "Enemy should not see app diagnostics!"); + Assertions.assertEquals( + UNAVAILABLE, appReport.getTrackingUrl(), "Enemy should not see app tracking url!"); + Assertions.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()); + Assertions.assertEquals( + -1, usageReport.getNumUsedContainers(), "Enemy should not see app used containers"); + Assertions.assertEquals( + -1, usageReport.getNumReservedContainers(), "Enemy should not see app reserved containers"); + Assertions.assertEquals( + -1, usageReport.getUsedResources().getMemorySize(), "Enemy should not see app used resources"); + Assertions.assertEquals( + -1, usageReport.getReservedResources().getMemorySize(), "Enemy should not see app reserved resources"); + Assertions.assertEquals( + -1, usageReport.getNeededResources().getMemorySize(), "Enemy should not see app needed resources"); } private void verifyInvalidQueueWithAcl() throws Exception { @@ -472,10 +472,10 @@ private void verifyInvalidQueueWithAcl() throws Exception { ApplicationReport appReport = applicationReport.getApplicationReport(); if (conf.get(YarnConfiguration.RM_SCHEDULER) .equals(FairScheduler.class.getName())) { - Assert.assertTrue(appReport.getDiagnostics() + Assertions.assertTrue(appReport.getDiagnostics() .contains("user owner application rejected by placement rules.")); } else { - Assert.assertTrue(appReport.getDiagnostics() + Assertions.assertTrue(appReport.getDiagnostics() .contains("submitted by user owner to unknown queue: InvalidQueue")); } } @@ -502,10 +502,10 @@ private void verifyAdministerQueueUserAccess() throws Exception { administerQueueUserRmClient.getApplicationReport(appReportRequest); // List apps as administerQueueUserRmClient - Assert.assertEquals("App view by queue-admin-user should list the apps!!", - 5, administerQueueUserRmClient.getApplications( + Assertions.assertEquals( + 5, administerQueueUserRmClient.getApplications( recordFactory.newRecordInstance(GetApplicationsRequest.class)) - .getApplicationList().size()); + .getApplicationList().size(), "App view by queue-admin-user should list the apps!!"); // Kill app as the administerQueueUserRmClient administerQueueUserRmClient.forceKillApplication(finishAppRequest); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationCleanup.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationCleanup.java index 807000a981021..234ce8201f377 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationCleanup.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationCleanup.java @@ -51,9 +51,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.utils.BuilderUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; public class TestApplicationCleanup { @@ -62,14 +63,14 @@ public class TestApplicationCleanup { private YarnConfiguration conf; - @Before + @BeforeEach public void setup() throws UnknownHostException { GenericTestUtils.setRootLogLevel(Level.DEBUG); conf = new YarnConfiguration(); UserGroupInformation.setConfiguration(conf); conf.set(YarnConfiguration.RECOVERY_ENABLED, "true"); conf.set(YarnConfiguration.RM_STORE, MemoryRMStateStore.class.getName()); - Assert.assertTrue(YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS > 1); + Assertions.assertTrue(YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS > 1); } @SuppressWarnings("resource") @@ -110,7 +111,7 @@ public void testAppCleanup() throws Exception { contReceived += conts.size(); nm1.nodeHeartbeat(true); } - Assert.assertEquals(request, contReceived); + Assertions.assertEquals(request, contReceived); am.unregisterAppAttempt(); NodeHeartbeatResponse resp = nm1.nodeHeartbeat(attempt.getAppAttemptId(), 1, @@ -142,10 +143,10 @@ public void testAppCleanup() throws Exception { numCleanedApps = appsToCleanup.size(); } - Assert.assertEquals(1, appsToCleanup.size()); - Assert.assertEquals(app.getApplicationId(), appsToCleanup.get(0)); - Assert.assertEquals(1, numCleanedApps); - Assert.assertEquals(2, numCleanedContainers); + Assertions.assertEquals(1, appsToCleanup.size()); + Assertions.assertEquals(app.getApplicationId(), appsToCleanup.get(0)); + Assertions.assertEquals(1, numCleanedApps); + Assertions.assertEquals(2, numCleanedContainers); rm.stop(); } @@ -190,7 +191,7 @@ public void testContainerCleanup() throws Exception { contReceived += conts.size(); nm1.nodeHeartbeat(true); } - Assert.assertEquals(request, contReceived); + Assertions.assertEquals(request, contReceived); // Release a container. ArrayList release = new ArrayList(); @@ -252,7 +253,7 @@ protected void waitForContainerCleanup(MockRM rm, MockNM nm, } else { LOG.info("Got cleanup for " + contsToClean.get(0)); } - Assert.assertEquals(1, cleanedConts); + Assertions.assertEquals(1, cleanedConts); } private void waitForAppCleanupMessageRecved(MockNM nm, ApplicationId appId) @@ -283,7 +284,8 @@ private MockAM launchAM(RMApp app, MockRM rm, MockNM nm) } @SuppressWarnings("resource") - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testAppCleanupWhenRMRestartedAfterAppFinished() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); // start RM @@ -318,7 +320,8 @@ public void testAppCleanupWhenRMRestartedAfterAppFinished() throws Exception { } @SuppressWarnings("resource") - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAppCleanupWhenRMRestartedBeforeAppFinished() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -375,7 +378,8 @@ public void testAppCleanupWhenRMRestartedBeforeAppFinished() throws Exception { rm2.stop(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testContainerCleanupWhenRMRestartedAppNotRegistered() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -411,7 +415,8 @@ public void testContainerCleanupWhenRMRestartedAppNotRegistered() throws rm2.stop(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testAppCleanupWhenNMReconnects() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -449,7 +454,8 @@ public void testAppCleanupWhenNMReconnects() throws Exception { // 6. Verify for Memory Used, it should be 1024 // 7. Send AM heatbeat to RM. Allocated response should contain completed // container. - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testProcessingNMContainerStatusesOnNMRestart() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -472,7 +478,7 @@ public void testProcessingNMContainerStatusesOnNMRestart() throws Exception { am0.allocateAndWaitForContainers(noOfContainers, containerMemory, nm1); // 3. Verify for number of container allocated by RM - Assert.assertEquals(noOfContainers, allocateContainers.size()); + Assertions.assertEquals(noOfContainers, allocateContainers.size()); Container container = allocateContainers.get(0); nm1.nodeHeartbeat(am0.getApplicationAttemptId(), 1, ContainerState.RUNNING); @@ -485,7 +491,7 @@ public void testProcessingNMContainerStatusesOnNMRestart() throws Exception { // requested memory. 1024 + 2048=3072 ResourceScheduler rs = rm1.getRMContext().getScheduler(); long allocatedMB = rs.getRootQueueMetrics().getAllocatedMB(); - Assert.assertEquals(amMemory + containerMemory, allocatedMB); + Assertions.assertEquals(amMemory + containerMemory, allocatedMB); // 5. Re-register NM by sending completed container status List nMContainerStatusForApp = @@ -496,7 +502,7 @@ public void testProcessingNMContainerStatusesOnNMRestart() throws Exception { waitForClusterMemory(nm1, rs, amMemory); // 6. Verify for Memory Used, it should be 1024 - Assert.assertEquals(amMemory, rs.getRootQueueMetrics().getAllocatedMB()); + Assertions.assertEquals(amMemory, rs.getRootQueueMetrics().getAllocatedMB()); // 7. Send AM heatbeat to RM. Allocated response should contain completed // container @@ -506,7 +512,7 @@ public void testProcessingNMContainerStatusesOnNMRestart() throws Exception { AllocateResponse allocate = am0.allocate(req); List completedContainersStatuses = allocate.getCompletedContainersStatuses(); - Assert.assertEquals(noOfContainers, completedContainersStatuses.size()); + Assertions.assertEquals(noOfContainers, completedContainersStatuses.size()); // Application clean up should happen Cluster memory used is 0 nm1.nodeHeartbeat(am0.getApplicationAttemptId(), 1, ContainerState.COMPLETE); @@ -523,7 +529,7 @@ private void waitForClusterMemory(MockNM nm1, ResourceScheduler rs, Thread.sleep(100); if (counter++ == 50) { - Assert.fail("Wait for cluster memory is timed out.Expected=" + Assertions.fail("Wait for cluster memory is timed out.Expected=" + clusterMemory + " Actual=" + rs.getRootQueueMetrics().getAllocatedMB()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterLauncher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterLauncher.java index 355f28877b7d7..a28a324fae1c7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterLauncher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterLauncher.java @@ -89,12 +89,13 @@ import org.apache.hadoop.yarn.server.security.AMSecretKeys; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.server.webproxy.ProxyCA; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.function.Supplier; -import static org.junit.Assert.fail; +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; @@ -244,20 +245,20 @@ public void testAMLaunchAndCleanup() throws Exception { } catch (TimeoutException e) { fail("timed out while waiting for AM Launch to happen."); } - Assert.assertTrue(containerManager.launched); + Assertions.assertTrue(containerManager.launched); RMAppAttempt attempt = app.getCurrentAppAttempt(); ApplicationAttemptId appAttemptId = attempt.getAppAttemptId(); - Assert.assertEquals(appAttemptId.toString(), + Assertions.assertEquals(appAttemptId.toString(), containerManager.attemptIdAtContainerManager); - Assert.assertEquals(app.getSubmitTime(), + Assertions.assertEquals(app.getSubmitTime(), containerManager.submitTimeAtContainerManager); - Assert.assertEquals(app.getRMAppAttempt(appAttemptId) + Assertions.assertEquals(app.getRMAppAttempt(appAttemptId) .getMasterContainer().getId() .toString(), containerManager.containerIdAtContainerManager); - Assert.assertEquals(nm1.getNodeId().toString(), + Assertions.assertEquals(nm1.getNodeId().toString(), containerManager.nmHostAtContainerManager); - Assert.assertEquals(YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS, + Assertions.assertEquals(YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS, containerManager.maxAppAttempts); MockAM am = new MockAM(rm.getRMContext(), rm @@ -278,7 +279,7 @@ public void testAMLaunchAndCleanup() throws Exception { } catch (TimeoutException e) { fail("timed out while waiting for AM cleanup to happen."); } - Assert.assertTrue(containerManager.cleanedup); + Assertions.assertTrue(containerManager.cleanedup); rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.FINISHED); rm.stop(); @@ -312,9 +313,9 @@ public void testAMCleanupBeforeLaunch() throws Exception { attempt, AMLauncherEventType.LAUNCH, rm.getConfig()) { @Override public void onAMLaunchFailed(ContainerId containerId, Exception e) { - Assert.assertFalse("NullPointerException happens " - + " while launching " + containerId, - e instanceof NullPointerException); + Assertions.assertFalse( + e instanceof NullPointerException, "NullPointerException happens " + + " while launching " + containerId); } @Override protected ContainerManagementProtocol getContainerMgrProxy( @@ -378,7 +379,8 @@ protected YarnRPC getYarnRPC() { @SuppressWarnings("unused") - @Test(timeout = 100000) + @Test + @Timeout(value = 100) public void testallocateBeforeAMRegistration() throws Exception { boolean thrown = false; GenericTestUtils.setRootLogLevel(Level.DEBUG); @@ -396,7 +398,7 @@ public void testallocateBeforeAMRegistration() throws Exception { AllocateResponse ar = null; try { ar = am.allocate("h1", 1000, request, new ArrayList()); - Assert.fail(); + Assertions.fail(); } catch (ApplicationMasterNotRegisteredException e) { } @@ -407,16 +409,16 @@ public void testallocateBeforeAMRegistration() throws Exception { try { amrs = am.allocate(new ArrayList(), new ArrayList()); - Assert.fail(); + Assertions.fail(); } catch (ApplicationMasterNotRegisteredException e) { } am.registerAppAttempt(); try { am.registerAppAttempt(false); - Assert.fail(); + Assertions.fail(); } catch (Exception e) { - Assert.assertEquals(AMRMClientUtils.APP_ALREADY_REGISTERED_MESSAGE + Assertions.assertEquals(AMRMClientUtils.APP_ALREADY_REGISTERED_MESSAGE + attempt.getAppAttemptId().getApplicationId(), e.getMessage()); } @@ -430,7 +432,7 @@ public void testallocateBeforeAMRegistration() throws Exception { try { amrs = am.allocate(new ArrayList(), new ArrayList()); - Assert.fail(); + Assertions.fail(); } catch (ApplicationAttemptNotFoundException e) { } } @@ -477,7 +479,7 @@ public void testAMMasterContainerHost() throws Exception { fail("timed out while waiting for AM Launch to happen."); } - Assert.assertEquals( + Assertions.assertEquals( app.getCurrentAppAttempt().getMasterContainer().getNodeId().getHost(), host); @@ -531,7 +533,7 @@ private void testSetupTokens(boolean https, YarnConfiguration conf) try { launcher.setupTokens(amContainer, containerId); } catch (java.io.EOFException e) { - Assert.fail("EOFException should not happen."); + Assertions.fail("EOFException should not happen."); } // verify token @@ -539,30 +541,30 @@ private void testSetupTokens(boolean https, YarnConfiguration conf) dibb.reset(amContainer.getTokens()); Credentials credentials = new Credentials(); credentials.readTokenStorageStream(dibb); - Assert.assertEquals(1, credentials.numberOfTokens()); + Assertions.assertEquals(1, credentials.numberOfTokens()); org.apache.hadoop.security.token.Token token = credentials.getAllTokens().iterator().next(); - Assert.assertEquals(tokenIdentifier.getKind(), token.getKind()); - Assert.assertArrayEquals(tokenIdentifier.getBytes(), token.getIdentifier()); - Assert.assertArrayEquals("password".getBytes(), token.getPassword()); + Assertions.assertEquals(tokenIdentifier.getKind(), token.getKind()); + Assertions.assertArrayEquals(tokenIdentifier.getBytes(), token.getIdentifier()); + Assertions.assertArrayEquals("password".getBytes(), token.getPassword()); // verify keystore and truststore if (https) { - Assert.assertEquals(4, credentials.numberOfSecretKeys()); - Assert.assertArrayEquals("keystore".getBytes(), + Assertions.assertEquals(4, credentials.numberOfSecretKeys()); + Assertions.assertArrayEquals("keystore".getBytes(), credentials.getSecretKey( AMSecretKeys.YARN_APPLICATION_AM_KEYSTORE)); - Assert.assertArrayEquals("kPassword".getBytes(), + Assertions.assertArrayEquals("kPassword".getBytes(), credentials.getSecretKey( AMSecretKeys.YARN_APPLICATION_AM_KEYSTORE_PASSWORD)); - Assert.assertArrayEquals("truststore".getBytes(), + Assertions.assertArrayEquals("truststore".getBytes(), credentials.getSecretKey( AMSecretKeys.YARN_APPLICATION_AM_TRUSTSTORE)); - Assert.assertArrayEquals("tPassword".getBytes(), + Assertions.assertArrayEquals("tPassword".getBytes(), credentials.getSecretKey( AMSecretKeys.YARN_APPLICATION_AM_TRUSTSTORE_PASSWORD)); } else { - Assert.assertEquals(0, credentials.numberOfSecretKeys()); + Assertions.assertEquals(0, credentials.numberOfSecretKeys()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceCapacity.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceCapacity.java index ab68515911651..d260132e548f4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceCapacity.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceCapacity.java @@ -47,8 +47,9 @@ import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.ArrayList; import java.util.Arrays; @@ -57,7 +58,7 @@ import java.util.Set; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestUtils.toSet; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * Unit tests for {@link ApplicationMasterService} @@ -103,7 +104,8 @@ private void sentRMContainerLaunched(MockRM rm, ContainerId containerId) { } } - @Test(timeout=60000) + @Test + @Timeout(value = 60) public void testInvalidIncreaseDecreaseRequest() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -142,8 +144,8 @@ public void testInvalidIncreaseDecreaseRequest() throws Exception { ContainerId.newContainerId(attempt1.getAppAttemptId(), 1), ContainerUpdateType.INCREASE_RESOURCE, Resources.createResource(-1), null))); - Assert.assertEquals(1, response.getUpdateErrors().size()); - Assert.assertEquals("RESOURCE_OUTSIDE_ALLOWED_RANGE", + Assertions.assertEquals(1, response.getUpdateErrors().size()); + Assertions.assertEquals("RESOURCE_OUTSIDE_ALLOWED_RANGE", response.getUpdateErrors().get(0).getReason()); // Target resource is more than maxAllocation, should fail @@ -154,8 +156,8 @@ public void testInvalidIncreaseDecreaseRequest() throws Exception { Resources.add( registerResponse.getMaximumResourceCapability(), Resources.createResource(1)), null))); - Assert.assertEquals(1, response.getUpdateErrors().size()); - Assert.assertEquals("RESOURCE_OUTSIDE_ALLOWED_RANGE", + Assertions.assertEquals(1, response.getUpdateErrors().size()); + Assertions.assertEquals("RESOURCE_OUTSIDE_ALLOWED_RANGE", response.getUpdateErrors().get(0).getReason()); // Contains multiple increase/decrease requests for same containerId @@ -168,13 +170,14 @@ public void testInvalidIncreaseDecreaseRequest() throws Exception { ContainerId.newContainerId(attempt1.getAppAttemptId(), 1), ContainerUpdateType.DECREASE_RESOURCE, Resources.createResource(1024, 1), null))); - Assert.assertEquals(1, response.getUpdateErrors().size()); - Assert.assertEquals("UPDATE_OUTSTANDING_ERROR", + Assertions.assertEquals(1, response.getUpdateErrors().size()); + Assertions.assertEquals("UPDATE_OUTSTANDING_ERROR", response.getUpdateErrors().get(0).getReason()); } } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testPriorityInAllocatedResponse() throws Exception { conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class); @@ -206,7 +209,7 @@ public void testPriorityInAllocatedResponse() throws Exception { allocateRequest.setAskList(ask); AllocateResponse response1 = am1.allocate(allocateRequest); - Assert.assertEquals(appPriority1, response1.getApplicationPriority()); + Assertions.assertEquals(appPriority1, response1.getApplicationPriority()); // Change the priority of App1 to 8 Priority appPriority2 = Priority.newInstance(8); @@ -216,11 +219,12 @@ public void testPriorityInAllocatedResponse() throws Exception { appPriority2); AllocateResponse response2 = am1.allocate(allocateRequest); - Assert.assertEquals(appPriority2, response2.getApplicationPriority()); + Assertions.assertEquals(appPriority2, response2.getApplicationPriority()); rm.stop(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testGetNMNumInAllocatedResponseWithOutNodeLabel() throws Exception { conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class); MockRM rm = new MockRM(conf); @@ -252,7 +256,7 @@ public void testGetNMNumInAllocatedResponseWithOutNodeLabel() throws Exception { allocateRequest.setAskList(ask); AllocateResponse response1 = am1.allocate(allocateRequest); - Assert.assertEquals(3, response1.getNumClusterNodes()); + Assertions.assertEquals(3, response1.getNumClusterNodes()); rm.stop(); } @@ -285,7 +289,8 @@ private Configuration getConfigurationWithQueueLabels(Configuration config) { return conf; } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testGetNMNumInAllocatedResponseWithNodeLabel() throws Exception { conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class); conf.setBoolean(YarnConfiguration.NODE_LABELS_ENABLED, true); @@ -368,10 +373,10 @@ protected RMNodeLabelsManager createNodeLabelManager() { } //has 3 nodes with node label "x" - Assert.assertEquals(3, response1.getNumClusterNodes()); + Assertions.assertEquals(3, response1.getNumClusterNodes()); //has 1 node with node label "y" - Assert.assertEquals(1, response2.getNumClusterNodes()); + Assertions.assertEquals(1, response2.getNumClusterNodes()); rm.stop(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceFair.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceFair.java index 6b268381fd4a4..17f860c8467ba 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceFair.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceFair.java @@ -30,14 +30,14 @@ 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.util.resource.ResourceUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.Map; import static org.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB; import static org.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * Unit tests for {@link ApplicationMasterService} with {@link FairScheduler}. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceInterceptor.java index e1d6defa63d9c..7f90d68302126 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceInterceptor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestApplicationMasterServiceInterceptor.java @@ -37,9 +37,10 @@ .ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler; import org.apache.hadoop.yarn.server.utils.BuilderUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +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.concurrent.atomic.AtomicInteger; @@ -152,14 +153,15 @@ public void finishApplicationMaster( private static YarnConfiguration conf; private static final int GB = 1024; - @Before + @BeforeEach public void setup() { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class, ResourceScheduler.class); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testApplicationMasterInterceptor() throws Exception { conf.set(YarnConfiguration.RM_APPLICATION_MASTER_SERVICE_PROCESSORS, TestInterceptor1.class.getName() + "," @@ -201,17 +203,17 @@ public void testApplicationMasterInterceptor() throws Exception { .getContainerToken()); am1.unregisterAppAttempt(); - Assert.assertEquals(1, beforeRegCount.get()); - Assert.assertEquals(1, afterRegCount.get()); + Assertions.assertEquals(1, beforeRegCount.get()); + Assertions.assertEquals(1, afterRegCount.get()); // The allocate calls should be incremented twice - Assert.assertEquals(allocCount * 2, beforeAllocCount.get()); - Assert.assertEquals(allocCount * 2, afterAllocCount.get()); + Assertions.assertEquals(allocCount * 2, beforeAllocCount.get()); + Assertions.assertEquals(allocCount * 2, afterAllocCount.get()); // Finish should only be called once, since the FirstInterceptor // does not forward the call. - Assert.assertEquals(1, beforeFinishCount.get()); - Assert.assertEquals(1, afterFinishCount.get()); + Assertions.assertEquals(1, beforeFinishCount.get()); + Assertions.assertEquals(1, afterFinishCount.get()); rm.stop(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestCapacitySchedulerMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestCapacitySchedulerMetrics.java index 99b3983f863eb..7e7b04b51135d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestCapacitySchedulerMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestCapacitySchedulerMetrics.java @@ -27,9 +27,9 @@ 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.CapacitySchedulerMetrics; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.concurrent.TimeoutException; @@ -67,7 +67,7 @@ public RMNodeLabelsManager createNodeLabelManager() { nm2.nodeHeartbeat(true); CapacitySchedulerMetrics csMetrics = CapacitySchedulerMetrics.getMetrics(); - Assert.assertNotNull(csMetrics); + Assertions.assertNotNull(csMetrics); try { GenericTestUtils.waitFor(() -> csMetrics.getNumOfNodeUpdate() == 2, 100, 3000); @@ -75,11 +75,11 @@ public RMNodeLabelsManager createNodeLabelManager() { .waitFor(() -> csMetrics.getNumOfSchedulerNodeHBInterval() == 2, 100, 3000); } catch(TimeoutException e) { - Assert.fail("CS metrics not updated on node-update events."); + Assertions.fail("CS metrics not updated on node-update events."); } - Assert.assertEquals(0, csMetrics.getNumOfAllocates()); - Assert.assertEquals(0, csMetrics.getNumOfCommitSuccess()); + Assertions.assertEquals(0, csMetrics.getNumOfAllocates()); + Assertions.assertEquals(0, csMetrics.getNumOfCommitSuccess()); RMApp rmApp = MockRMAppSubmitter.submit(rm, MockRMAppSubmissionData.Builder.createWithMemory(1024, rm) @@ -108,16 +108,16 @@ public RMNodeLabelsManager createNodeLabelManager() { .waitFor(() -> csMetrics.getNumOfSchedulerNodeHBInterval() == 4, 100, 3000); // For async mode, the number of alloc might be bigger than 1 - Assert.assertTrue(csMetrics.getNumOfAllocates() > 0); + Assertions.assertTrue(csMetrics.getNumOfAllocates() > 0); // But there will be only 2 successful commit (1 AM + 1 task) GenericTestUtils.waitFor(() -> csMetrics.getNumOfCommitSuccess() == 2, 100, 3000); } catch(TimeoutException e) { - Assert.fail("CS metrics not updated on node-update events."); + Assertions.fail("CS metrics not updated on node-update events."); } } - @After + @AfterEach public void tearDown() { if (rm != null) { rm.stop(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java index e001bc9bd65b0..fbeb0d42f94b1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMService.java @@ -20,8 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyList; @@ -185,10 +184,11 @@ 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.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -251,10 +251,10 @@ protected ClientRMService createClientRMService() { GetClusterNodesRequest.newInstance( EnumSet.of(NodeState.DECOMMISSIONING))) .getNodeReports(); - Assert.assertEquals(1, nodeReports.size()); + Assertions.assertEquals(1, nodeReports.size()); NodeReport nr = nodeReports.iterator().next(); - Assert.assertEquals(decommissioningTimeout, nr.getDecommissioningTimeout()); - Assert.assertNull(nr.getNodeUpdateType()); + Assertions.assertEquals(decommissioningTimeout, nr.getDecommissioningTimeout()); + Assertions.assertNull(nr.getNodeUpdateType()); } @Test @@ -299,14 +299,14 @@ protected ClientRMService createClientRMService() { GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.RUNNING)); List nodeReports = client.getClusterNodes(request).getNodeReports(); - Assert.assertEquals(1, nodeReports.size()); - Assert.assertNotSame("Node is expected to be healthy!", NodeState.UNHEALTHY, - nodeReports.get(0).getNodeState()); + Assertions.assertEquals(1, nodeReports.size()); + Assertions.assertNotSame(NodeState.UNHEALTHY +, nodeReports.get(0).getNodeState(), "Node is expected to be healthy!"); // Check node's label = x - Assert.assertTrue(nodeReports.get(0).getNodeLabels().contains("x")); - Assert.assertNull(nodeReports.get(0).getDecommissioningTimeout()); - Assert.assertNull(nodeReports.get(0).getNodeUpdateType()); + Assertions.assertTrue(nodeReports.get(0).getNodeLabels().contains("x")); + Assertions.assertNull(nodeReports.get(0).getDecommissioningTimeout()); + Assertions.assertNull(nodeReports.get(0).getNodeUpdateType()); // Now make the node unhealthy. node.nodeHeartbeat(false); @@ -314,8 +314,8 @@ protected ClientRMService createClientRMService() { // Call again nodeReports = client.getClusterNodes(request).getNodeReports(); - Assert.assertEquals("Unhealthy nodes should not show up by default", 0, - nodeReports.size()); + Assertions.assertEquals(0 +, nodeReports.size(), "Unhealthy nodes should not show up by default"); // Change label of host1 to y map = new HashMap>(); @@ -325,13 +325,13 @@ protected ClientRMService createClientRMService() { // Now query for UNHEALTHY nodes request = GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.UNHEALTHY)); nodeReports = client.getClusterNodes(request).getNodeReports(); - Assert.assertEquals(1, nodeReports.size()); - Assert.assertEquals("Node is expected to be unhealthy!", NodeState.UNHEALTHY, - nodeReports.get(0).getNodeState()); + Assertions.assertEquals(1, nodeReports.size()); + Assertions.assertEquals(NodeState.UNHEALTHY +, nodeReports.get(0).getNodeState(), "Node is expected to be unhealthy!"); - Assert.assertTrue(nodeReports.get(0).getNodeLabels().contains("y")); - Assert.assertNull(nodeReports.get(0).getDecommissioningTimeout()); - Assert.assertNull(nodeReports.get(0).getNodeUpdateType()); + Assertions.assertTrue(nodeReports.get(0).getNodeLabels().contains("y")); + Assertions.assertNull(nodeReports.get(0).getDecommissioningTimeout()); + Assertions.assertNull(nodeReports.get(0).getNodeUpdateType()); // Remove labels of host1 map = new HashMap>(); @@ -342,14 +342,14 @@ protected ClientRMService createClientRMService() { rm.registerNode("host3:1236", 1024); request = GetClusterNodesRequest.newInstance(EnumSet.allOf(NodeState.class)); nodeReports = client.getClusterNodes(request).getNodeReports(); - Assert.assertEquals(3, nodeReports.size()); + Assertions.assertEquals(3, nodeReports.size()); // All host1-3's label should be empty (instead of null) for (NodeReport report : nodeReports) { - Assert.assertTrue(report.getNodeLabels() != null + Assertions.assertTrue(report.getNodeLabels() != null && report.getNodeLabels().isEmpty()); - Assert.assertNull(report.getDecommissioningTimeout()); - Assert.assertNull(report.getNodeUpdateType()); + Assertions.assertNull(report.getDecommissioningTimeout()); + Assertions.assertNull(report.getNodeUpdateType()); } } @@ -365,9 +365,9 @@ public void testNonExistingApplicationReport() throws YarnException { request.setApplicationId(ApplicationId.newInstance(0, 0)); try { rmService.getApplicationReport(request); - Assert.fail(); + Assertions.fail(); } catch (ApplicationNotFoundException ex) { - Assert.assertEquals(ex.getMessage(), + Assertions.assertEquals(ex.getMessage(), "Application with id '" + request.getApplicationId() + "' doesn't exist in RM. Please check that the " + "job submission was successful."); @@ -398,10 +398,10 @@ public void testGetApplicationReport() throws Exception { ApplicationReport report = response.getApplicationReport(); ApplicationResourceUsageReport usageReport = report.getApplicationResourceUsageReport(); - Assert.assertEquals(10, usageReport.getMemorySeconds()); - Assert.assertEquals(3, usageReport.getVcoreSeconds()); - Assert.assertEquals("", report.getAmNodeLabelExpression()); - Assert.assertEquals("", report.getAppNodeLabelExpression()); + Assertions.assertEquals(10, usageReport.getMemorySeconds()); + Assertions.assertEquals(3, usageReport.getVcoreSeconds()); + Assertions.assertEquals("", report.getAmNodeLabelExpression()); + Assertions.assertEquals("", report.getAppNodeLabelExpression()); // if application has am node label set to blank ApplicationId appId2 = getApplicationId(2); @@ -411,9 +411,9 @@ public void testGetApplicationReport() throws Exception { response = rmService.getApplicationReport(request); report = response.getApplicationReport(); - Assert.assertEquals(NodeLabel.DEFAULT_NODE_LABEL_PARTITION, + Assertions.assertEquals(NodeLabel.DEFAULT_NODE_LABEL_PARTITION, report.getAmNodeLabelExpression()); - Assert.assertEquals(NodeLabel.NODE_LABEL_EXPRESSION_NOT_SET, + Assertions.assertEquals(NodeLabel.NODE_LABEL_EXPRESSION_NOT_SET, report.getAppNodeLabelExpression()); // if application has am node label set to blank @@ -425,8 +425,8 @@ public void testGetApplicationReport() throws Exception { response = rmService.getApplicationReport(request); report = response.getApplicationReport(); - Assert.assertEquals("high-mem", report.getAmNodeLabelExpression()); - Assert.assertEquals("high-mem", report.getAppNodeLabelExpression()); + Assertions.assertEquals("high-mem", report.getAmNodeLabelExpression()); + Assertions.assertEquals("high-mem", report.getAppNodeLabelExpression()); // if application id is null GetApplicationReportRequest invalidRequest = recordFactory @@ -437,7 +437,7 @@ public void testGetApplicationReport() throws Exception { } catch (YarnException e) { // rmService should return a ApplicationNotFoundException // when a null application id is provided - Assert.assertTrue(e instanceof ApplicationNotFoundException); + Assertions.assertTrue(e instanceof ApplicationNotFoundException); } } finally { rmService.close(); @@ -457,10 +457,10 @@ public void testGetApplicationAttemptReport() throws YarnException, try { GetApplicationAttemptReportResponse response = rmService .getApplicationAttemptReport(request); - Assert.assertEquals(attemptId, response.getApplicationAttemptReport() + Assertions.assertEquals(attemptId, response.getApplicationAttemptReport() .getApplicationAttemptId()); } catch (ApplicationNotFoundException ex) { - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } } @@ -498,12 +498,12 @@ public void testGetApplicationAttempts() throws YarnException, IOException { try { GetApplicationAttemptsResponse response = rmService .getApplicationAttempts(request); - Assert.assertEquals(1, response.getApplicationAttemptList().size()); - Assert.assertEquals(attemptId, response.getApplicationAttemptList() + Assertions.assertEquals(1, response.getApplicationAttemptList().size()); + Assertions.assertEquals(attemptId, response.getApplicationAttemptList() .get(0).getApplicationAttemptId()); } catch (ApplicationNotFoundException ex) { - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } } @@ -520,10 +520,10 @@ public void testGetContainerReport() throws YarnException, IOException { try { GetContainerReportResponse response = rmService .getContainerReport(request); - Assert.assertEquals(containerId, response.getContainerReport() + Assertions.assertEquals(containerId, response.getContainerReport() .getContainerId()); } catch (ApplicationNotFoundException ex) { - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } } @@ -538,10 +538,10 @@ public void testGetContainers() throws YarnException, IOException { request.setApplicationAttemptId(attemptId); try { GetContainersResponse response = rmService.getContainers(request); - Assert.assertEquals(containerId, response.getContainerList().get(0) + Assertions.assertEquals(containerId, response.getContainerList().get(0) .getContainerId()); } catch (ApplicationNotFoundException ex) { - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } } @@ -584,9 +584,9 @@ public void testForceKillNonExistingApplication() throws YarnException { KillApplicationRequest.newInstance(applicationId); try { rmService.forceKillApplication(request); - Assert.fail(); + Assertions.fail(); } catch (ApplicationNotFoundException ex) { - Assert.assertEquals(ex.getMessage(), + Assertions.assertEquals(ex.getMessage(), "Trying to kill an absent " + "application " + request.getApplicationId()); } @@ -631,9 +631,9 @@ private void validateApplicationTag(ClientRMService rmService, new HashSet(tags)); try { rmService.submitApplication(submitRequest); - Assert.fail(); + Assertions.fail(); } catch (Exception ex) { - Assert.assertTrue(ex.getMessage().contains(errorMsg)); + Assertions.assertTrue(ex.getMessage().contains(errorMsg)); } } @@ -657,8 +657,8 @@ public void testForceKillApplication() throws Exception { .build(); RMApp app2 = MockRMAppSubmitter.submit(rm, data); - assertEquals("Incorrect number of apps in the RM", 0, - rmService.getApplications(getRequest).getApplicationList().size()); + assertEquals(0 +, rmService.getApplications(getRequest).getApplicationList().size(), "Incorrect number of apps in the RM"); KillApplicationRequest killRequest1 = KillApplicationRequest.newInstance(app1.getApplicationId()); @@ -677,17 +677,17 @@ public void testForceKillApplication() throws Exception { } Thread.sleep(10); } - assertTrue("Kill attempt count should be greater than 1 for managed AMs", - killAttemptCount > 1); - assertEquals("Incorrect number of apps in the RM", 1, - rmService.getApplications(getRequest).getApplicationList().size()); - assertTrue("Diagnostic message is incorrect", - app1.getDiagnostics().toString().contains(diagnostic)); + assertTrue( + killAttemptCount > 1, "Kill attempt count should be greater than 1 for managed AMs"); + assertEquals(1 +, rmService.getApplications(getRequest).getApplicationList().size(), "Incorrect number of apps in the RM"); + assertTrue( + app1.getDiagnostics().toString().contains(diagnostic), "Diagnostic message is incorrect"); KillApplicationResponse killResponse2 = rmService.forceKillApplication(killRequest2); - assertTrue("Killing UnmanagedAM should falsely acknowledge true", - killResponse2.getIsKillCompleted()); + assertTrue( + killResponse2.getIsKillCompleted(), "Killing UnmanagedAM should falsely acknowledge true"); for (int i = 0; i < 100; i++) { if (2 == rmService.getApplications(getRequest).getApplicationList().size()) { @@ -695,23 +695,25 @@ public void testForceKillApplication() throws Exception { } Thread.sleep(10); } - assertEquals("Incorrect number of apps in the RM", 2, - rmService.getApplications(getRequest).getApplicationList().size()); + assertEquals(2 +, rmService.getApplications(getRequest).getApplicationList().size(), "Incorrect number of apps in the RM"); } - @Test (expected = ApplicationNotFoundException.class) + @Test public void testMoveAbsentApplication() throws YarnException { - RMContext rmContext = mock(RMContext.class); - when(rmContext.getRMApps()).thenReturn( - new ConcurrentHashMap()); - ClientRMService rmService = new ClientRMService(rmContext, null, null, - null, null, null); - ApplicationId applicationId = - BuilderUtils.newApplicationId(System.currentTimeMillis(), 0); - MoveApplicationAcrossQueuesRequest request = - MoveApplicationAcrossQueuesRequest.newInstance(applicationId, - "newqueue"); - rmService.moveApplicationAcrossQueues(request); + assertThrows(ApplicationNotFoundException.class, ()->{ + RMContext rmContext = mock(RMContext.class); + when(rmContext.getRMApps()).thenReturn( + new ConcurrentHashMap()); + ClientRMService rmService = new ClientRMService(rmContext, null, null, + null, null, null); + ApplicationId applicationId = + BuilderUtils.newApplicationId(System.currentTimeMillis(), 0); + MoveApplicationAcrossQueuesRequest request = + MoveApplicationAcrossQueuesRequest.newInstance(applicationId, + "newqueue"); + rmService.moveApplicationAcrossQueues(request); + }); } @Test @@ -739,10 +741,10 @@ public void testMoveApplicationSubmitTargetQueue() throws Exception { try { rmService.moveApplicationAcrossQueues(moveAppRequest); - Assert.fail("The request should fail with an AccessControlException"); + Assertions.fail("The request should fail with an AccessControlException"); } catch (YarnException rex) { - Assert.assertTrue("AccessControlException is expected", - rex.getCause() instanceof AccessControlException); + Assertions.assertTrue( + rex.getCause() instanceof AccessControlException, "AccessControlException is expected"); } // ACL is owned by "moveuser", move is performed as a different user @@ -761,10 +763,10 @@ public void testMoveApplicationSubmitTargetQueue() throws Exception { newInstance(applicationId, "move_queue"); try { rmService2.moveApplicationAcrossQueues(moveAppRequest2); - Assert.fail("The request should fail with an AccessControlException"); + Assertions.fail("The request should fail with an AccessControlException"); } catch (YarnException rex) { - Assert.assertTrue("AccessControlException is expected", - rex.getCause() instanceof AccessControlException); + Assertions.assertTrue( + rex.getCause() instanceof AccessControlException, "AccessControlException is expected"); } // execute the move as the acl owner @@ -800,10 +802,10 @@ public void testMoveApplicationAdminTargetQueue() throws Exception { try { rmService.moveApplicationAcrossQueues(moveAppRequest); - Assert.fail("The request should fail with an AccessControlException"); + Assertions.fail("The request should fail with an AccessControlException"); } catch (YarnException rex) { - Assert.assertTrue("AccessControlException is expected", - rex.getCause() instanceof AccessControlException); + Assertions.assertTrue( + rex.getCause() instanceof AccessControlException, "AccessControlException is expected"); } // ACL is owned by "moveuser", move is performed as a different user @@ -823,10 +825,10 @@ public void testMoveApplicationAdminTargetQueue() throws Exception { try { rmService2.moveApplicationAcrossQueues(moveAppRequest2); - Assert.fail("The request should fail with an AccessControlException"); + Assertions.fail("The request should fail with an AccessControlException"); } catch (YarnException rex) { - Assert.assertTrue("AccessControlException is expected", - rex.getCause() instanceof AccessControlException); + Assertions.assertTrue( + rex.getCause() instanceof AccessControlException, "AccessControlException is expected"); } // execute the move as the acl owner @@ -839,20 +841,22 @@ public Object run() throws Exception { }); } - @Test (expected = YarnException.class) + @Test public void testNonExistingQueue() throws Exception { - ApplicationId applicationId = getApplicationId(1); - UserGroupInformation aclUGI = UserGroupInformation.getCurrentUser(); - QueueACLsManager queueAclsManager = getQueueAclManager(); - ApplicationACLsManager appAclsManager = getAppAclManager(); - ClientRMService rmService = - createClientRMServiceForMoveApplicationRequest(applicationId, - aclUGI.getShortUserName(), appAclsManager, queueAclsManager); - - MoveApplicationAcrossQueuesRequest moveAppRequest = - MoveApplicationAcrossQueuesRequest.newInstance(applicationId, - "unknown_queue"); - rmService.moveApplicationAcrossQueues(moveAppRequest); + assertThrows(YarnException.class, ()->{ + ApplicationId applicationId = getApplicationId(1); + UserGroupInformation aclUGI = UserGroupInformation.getCurrentUser(); + QueueACLsManager queueAclsManager = getQueueAclManager(); + ApplicationACLsManager appAclsManager = getAppAclManager(); + ClientRMService rmService = + createClientRMServiceForMoveApplicationRequest(applicationId, + aclUGI.getShortUserName(), appAclsManager, queueAclsManager); + + MoveApplicationAcrossQueuesRequest moveAppRequest = + MoveApplicationAcrossQueuesRequest.newInstance(applicationId, + "unknown_queue"); + rmService.moveApplicationAcrossQueues(moveAppRequest); + }); } /** @@ -990,17 +994,17 @@ public void testGetQueueInfo() throws Exception { GetQueueInfoResponse queueInfo = rmService.getQueueInfo(request); List applications = queueInfo.getQueueInfo() .getApplications(); - Assert.assertEquals(2, applications.size()); + Assertions.assertEquals(2, applications.size()); Map queueConfigsByPartition = queueInfo.getQueueInfo().getQueueConfigurations(); - Assert.assertEquals(1, queueConfigsByPartition.size()); - Assert.assertTrue(queueConfigsByPartition.containsKey("*")); + Assertions.assertEquals(1, queueConfigsByPartition.size()); + Assertions.assertTrue(queueConfigsByPartition.containsKey("*")); QueueConfigurations queueConfigs = queueConfigsByPartition.get("*"); - Assert.assertEquals(0.5f, queueConfigs.getCapacity(), 0.0001f); - Assert.assertEquals(0.1f, queueConfigs.getAbsoluteCapacity(), 0.0001f); - Assert.assertEquals(1.0f, queueConfigs.getMaxCapacity(), 0.0001f); - Assert.assertEquals(1.0f, queueConfigs.getAbsoluteMaxCapacity(), 0.0001f); - Assert.assertEquals(0.2f, queueConfigs.getMaxAMPercentage(), 0.0001f); + Assertions.assertEquals(0.5f, queueConfigs.getCapacity(), 0.0001f); + Assertions.assertEquals(0.1f, queueConfigs.getAbsoluteCapacity(), 0.0001f); + Assertions.assertEquals(1.0f, queueConfigs.getMaxCapacity(), 0.0001f); + Assertions.assertEquals(1.0f, queueConfigs.getAbsoluteMaxCapacity(), 0.0001f); + Assertions.assertEquals(0.2f, queueConfigs.getMaxAMPercentage(), 0.0001f); request.setQueueName("nonexistentqueue"); request.setIncludeApplications(true); @@ -1027,10 +1031,11 @@ public void testGetQueueInfo() throws Exception { GetQueueInfoResponse queueInfo1 = rmService1.getQueueInfo(request); List applications1 = queueInfo1.getQueueInfo() .getApplications(); - Assert.assertEquals(0, applications1.size()); + Assertions.assertEquals(0, applications1.size()); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) @SuppressWarnings ("rawtypes") public void testAppSubmitWithSubmissionPreProcessor() throws Exception { ResourceScheduler scheduler = mockResourceScheduler(); @@ -1095,16 +1100,16 @@ public void handle(Event event) {} try { rmService.submitApplication(submitRequest1); } catch (YarnException e) { - Assert.fail("Exception is not expected."); + Assertions.fail("Exception is not expected."); } RMApp app1 = rmContext.getRMApps().get(appId1); - Assert.assertNotNull("app doesn't exist", app1); - Assert.assertEquals("app name doesn't match", - YarnConfiguration.DEFAULT_APPLICATION_NAME, app1.getName()); - Assert.assertTrue("custom tag not present", - app1.getApplicationTags().contains("cluster:cluster1")); - Assert.assertEquals("app queue doesn't match", "bar", app1.getQueue()); - Assert.assertEquals("app node label doesn't match", + Assertions.assertNotNull(app1, "app doesn't exist"); + Assertions.assertEquals( + YarnConfiguration.DEFAULT_APPLICATION_NAME, app1.getName(), "app name doesn't match"); + Assertions.assertTrue( + app1.getApplicationTags().contains("cluster:cluster1"), "custom tag not present"); + Assertions.assertEquals("app queue doesn't match", "bar", app1.getQueue()); + Assertions.assertEquals("app node label doesn't match", "foo", app1.getApplicationSubmissionContext().getNodeLabelExpression()); setupCurrentCall("host.cluster2.com"); ApplicationId appId2 = getApplicationId(101); @@ -1118,18 +1123,18 @@ public void handle(Event event) {} try { rmService.submitApplication(submitRequest2); } catch (YarnException e) { - Assert.fail("Exception is not expected."); + Assertions.fail("Exception is not expected."); } RMApp app2 = rmContext.getRMApps().get(appId2); - Assert.assertNotNull("app doesn't exist", app2); - Assert.assertEquals("app name doesn't match", - YarnConfiguration.DEFAULT_APPLICATION_NAME, app2.getName()); - Assert.assertTrue("client tag not present", - app2.getApplicationTags().contains(APPLICATION_TAG_SC_PREPROCESSOR)); - Assert.assertTrue("custom tag not present", - app2.getApplicationTags().contains("cluster:cluster2")); - Assert.assertEquals("app queue doesn't match", "hello", app2.getQueue()); - Assert.assertEquals("app node label doesn't match", + Assertions.assertNotNull(app2, "app doesn't exist"); + Assertions.assertEquals( + YarnConfiguration.DEFAULT_APPLICATION_NAME, app2.getName(), "app name doesn't match"); + Assertions.assertTrue( + app2.getApplicationTags().contains(APPLICATION_TAG_SC_PREPROCESSOR), "client tag not present"); + Assertions.assertTrue( + app2.getApplicationTags().contains("cluster:cluster2"), "custom tag not present"); + Assertions.assertEquals("app queue doesn't match", "hello", app2.getQueue()); + Assertions.assertEquals("app node label doesn't match", "zuess", app2.getApplicationSubmissionContext().getNodeLabelExpression()); // Test Default commands @@ -1143,18 +1148,18 @@ public void handle(Event event) {} try { rmService.submitApplication(submitRequest3); } catch (YarnException e) { - Assert.fail("Exception is not expected."); + Assertions.fail("Exception is not expected."); } RMApp app3 = rmContext.getRMApps().get(appId3); - Assert.assertNotNull("app doesn't exist", app3); - Assert.assertEquals("app name doesn't match", - YarnConfiguration.DEFAULT_APPLICATION_NAME, app3.getName()); - Assert.assertTrue("client tag not present", - app3.getApplicationTags().contains(APPLICATION_TAG_SC_PREPROCESSOR)); - Assert.assertTrue("custom tag not present", - app3.getApplicationTags().contains("cluster:other")); - Assert.assertEquals("app queue doesn't match", "default", app3.getQueue()); - Assert.assertEquals("app node label doesn't match", + Assertions.assertNotNull(app3, "app doesn't exist"); + Assertions.assertEquals( + YarnConfiguration.DEFAULT_APPLICATION_NAME, app3.getName(), "app name doesn't match"); + Assertions.assertTrue( + app3.getApplicationTags().contains(APPLICATION_TAG_SC_PREPROCESSOR), "client tag not present"); + Assertions.assertTrue( + app3.getApplicationTags().contains("cluster:other"), "custom tag not present"); + Assertions.assertEquals("app queue doesn't match", "default", app3.getQueue()); + Assertions.assertEquals("app node label doesn't match", "barfoo", app3.getApplicationSubmissionContext().getNodeLabelExpression()); // Test regex @@ -1165,12 +1170,12 @@ public void handle(Event event) {} try { rmService.submitApplication(submitRequest4); } catch (YarnException e) { - Assert.fail("Exception is not expected."); + Assertions.fail("Exception is not expected."); } RMApp app4 = rmContext.getRMApps().get(appId4); - Assert.assertTrue("custom tag not present", - app4.getApplicationTags().contains("cluster:reg")); - Assert.assertEquals("app node label doesn't match", + Assertions.assertTrue( + app4.getApplicationTags().contains("cluster:reg"), "custom tag not present"); + Assertions.assertEquals("app node label doesn't match", "reg", app4.getApplicationSubmissionContext().getNodeLabelExpression()); testSubmissionContextWithAbsentTAG(rmService, rmContext); rmService.serviceStop(); @@ -1185,14 +1190,14 @@ private void testSubmissionContextWithAbsentTAG(ClientRMService rmService, try { rmService.submitApplication(submitRequest5); } catch (YarnException e) { - Assert.fail("Exception is not expected."); + Assertions.fail("Exception is not expected."); } RMApp app5 = rmContext.getRMApps().get(appId5); - Assert.assertEquals("custom tag present", - app5.getApplicationTags().size(), 0); - Assert.assertNull("app node label present", - app5.getApplicationSubmissionContext().getNodeLabelExpression()); - Assert.assertEquals("Queue name is not present", + Assertions.assertEquals( + app5.getApplicationTags().size(), 0, "custom tag present"); + Assertions.assertNull( + app5.getApplicationSubmissionContext().getNodeLabelExpression(), "app node label present"); + Assertions.assertEquals("Queue name is not present", app5.getQueue(), "default"); } private void setupCurrentCall(String hostName) throws UnknownHostException { @@ -1203,7 +1208,8 @@ private void setupCurrentCall(String hostName) throws UnknownHostException { Server.getCurCall().set(mockCall); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) @SuppressWarnings ("rawtypes") public void testAppSubmit() throws Exception { ResourceScheduler scheduler = mockResourceScheduler(); @@ -1244,14 +1250,14 @@ public void handle(Event event) {} try { rmService.submitApplication(submitRequest1); } catch (YarnException e) { - Assert.fail("Exception is not expected."); + Assertions.fail("Exception is not expected."); } RMApp app1 = rmContext.getRMApps().get(appId1); - Assert.assertNotNull("app doesn't exist", app1); - Assert.assertEquals("app name doesn't match", - YarnConfiguration.DEFAULT_APPLICATION_NAME, app1.getName()); - Assert.assertEquals("app queue doesn't match", - YarnConfiguration.DEFAULT_QUEUE_NAME, app1.getQueue()); + Assertions.assertNotNull(app1, "app doesn't exist"); + Assertions.assertEquals( + YarnConfiguration.DEFAULT_APPLICATION_NAME, app1.getName(), "app name doesn't match"); + Assertions.assertEquals( + YarnConfiguration.DEFAULT_QUEUE_NAME, app1.getQueue(), "app queue doesn't match"); // with name and queue String name = MockApps.newAppName(); @@ -1264,25 +1270,25 @@ public void handle(Event event) {} try { rmService.submitApplication(submitRequest2); } catch (YarnException e) { - Assert.fail("Exception is not expected."); + Assertions.fail("Exception is not expected."); } RMApp app2 = rmContext.getRMApps().get(appId2); - Assert.assertNotNull("app doesn't exist", app2); - Assert.assertEquals("app name doesn't match", name, app2.getName()); - Assert.assertEquals("app queue doesn't match", queue, app2.getQueue()); + Assertions.assertNotNull(app2, "app doesn't exist"); + Assertions.assertEquals(name, app2.getName(), "app name doesn't match"); + Assertions.assertEquals(queue, app2.getQueue(), "app queue doesn't match"); // duplicate appId try { rmService.submitApplication(submitRequest2); } catch (YarnException e) { - Assert.fail("Exception is not expected."); + Assertions.fail("Exception is not expected."); } GetApplicationsRequest getAllAppsRequest = GetApplicationsRequest.newInstance(new HashSet()); GetApplicationsResponse getAllApplicationsResponse = rmService.getApplications(getAllAppsRequest); - Assert.assertEquals(5, + Assertions.assertEquals(5, getAllApplicationsResponse.getApplicationList().size()); Set appTypes = new HashSet(); @@ -1291,9 +1297,9 @@ public void handle(Event event) {} getAllAppsRequest = GetApplicationsRequest.newInstance(appTypes); getAllApplicationsResponse = rmService.getApplications(getAllAppsRequest); - Assert.assertEquals(1, + Assertions.assertEquals(1, getAllApplicationsResponse.getApplicationList().size()); - Assert.assertEquals(appId2, + Assertions.assertEquals(appId2, getAllApplicationsResponse.getApplicationList() .get(0).getApplicationId()); @@ -1303,9 +1309,9 @@ public void handle(Event event) {} getAllAppsRequest = GetApplicationsRequest.newInstance(appTypes); getAllApplicationsResponse = rmService.getApplications(getAllAppsRequest); - Assert.assertEquals(1, + Assertions.assertEquals(1, getAllApplicationsResponse.getApplicationList().size()); - Assert.assertEquals(appId2, + Assertions.assertEquals(appId2, getAllApplicationsResponse.getApplicationList() .get(0).getApplicationId()); } @@ -1370,31 +1376,31 @@ public void handle(Event event) {} // Test different cases of ClientRMService#getApplications() GetApplicationsRequest request = GetApplicationsRequest.newInstance(); - assertEquals("Incorrect total number of apps", 6, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(6 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect total number of apps"); // Check limit request.setLimit(1L); - assertEquals("Failed to limit applications", 1, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(1 +, rmService.getApplications(request).getApplicationList().size(), "Failed to limit applications"); // Check start range request = GetApplicationsRequest.newInstance(); request.setStartRange(submitTimeMillis[0] + 1, System.currentTimeMillis()); // 2 applications are submitted after first timeMills - assertEquals("Incorrect number of matching start range", - 2, rmService.getApplications(request).getApplicationList().size()); + assertEquals( + 2, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of matching start range"); // 1 application is submitted after the second timeMills request.setStartRange(submitTimeMillis[1] + 1, System.currentTimeMillis()); - assertEquals("Incorrect number of matching start range", - 1, rmService.getApplications(request).getApplicationList().size()); + assertEquals( + 1, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of matching start range"); // no application is submitted after the third timeMills request.setStartRange(submitTimeMillis[2] + 1, System.currentTimeMillis()); - assertEquals("Incorrect number of matching start range", - 0, rmService.getApplications(request).getApplicationList().size()); + assertEquals( + 0, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of matching start range"); // Check queue request = GetApplicationsRequest.newInstance(); @@ -1402,14 +1408,14 @@ public void handle(Event event) {} request.setQueues(queueSet); queueSet.add(queues[0]); - assertEquals("Incorrect number of applications in queue", 3, - rmService.getApplications(request).getApplicationList().size()); - assertEquals("Incorrect number of applications in queue", 3, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(3 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications in queue"); + assertEquals(3 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications in queue"); queueSet.add(queues[1]); - assertEquals("Incorrect number of applications in queue", 3, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(3 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications in queue"); // Check user request = GetApplicationsRequest.newInstance(); @@ -1417,17 +1423,17 @@ public void handle(Event event) {} request.setUsers(userSet); userSet.add("random-user-name"); - assertEquals("Incorrect number of applications for user", 0, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(0 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications for user"); userSet.add(UserGroupInformation.getCurrentUser().getShortUserName()); - assertEquals("Incorrect number of applications for user", 3, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(3 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications for user"); rmService.setDisplayPerUserApps(true); userSet.clear(); - assertEquals("Incorrect number of applications for user", 6, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(6 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications for user"); rmService.setDisplayPerUserApps(false); // Check tags @@ -1436,37 +1442,38 @@ public void handle(Event event) {} null, null); Set tagSet = new HashSet(); request.setApplicationTags(tagSet); - assertEquals("Incorrect number of matching tags", 6, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(6 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of matching tags"); tagSet = Sets.newHashSet(tags.get(0)); request.setApplicationTags(tagSet); - assertEquals("Incorrect number of matching tags", 3, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(3 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of matching tags"); tagSet = Sets.newHashSet(tags.get(1)); request.setApplicationTags(tagSet); - assertEquals("Incorrect number of matching tags", 2, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(2 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of matching tags"); tagSet = Sets.newHashSet(tags.get(2)); request.setApplicationTags(tagSet); - assertEquals("Incorrect number of matching tags", 1, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(1 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of matching tags"); // Check scope request = GetApplicationsRequest.newInstance( ApplicationsRequestScope.VIEWABLE); - assertEquals("Incorrect number of applications for the scope", 6, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(6 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications for the scope"); request = GetApplicationsRequest.newInstance( ApplicationsRequestScope.OWN); - assertEquals("Incorrect number of applications for the scope", 3, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(3 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications for the scope"); } - @Test(timeout=4000) + @Test + @Timeout(value = 4) public void testConcurrentAppSubmit() throws IOException, InterruptedException, BrokenBarrierException, YarnException { @@ -1753,7 +1760,7 @@ private ResourceManager setupResourceManager() { // allow plan follower to synchronize Thread.sleep(1050); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } return rm; } @@ -1769,7 +1776,7 @@ private ReservationSubmissionRequest submitReservationTestHelper( reservationID = clientService.getNewReservation(newReservationRequest) .getReservationId(); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } ReservationSubmissionRequest sRequest = ReservationSystemTestUtil.createSimpleReservationRequest(reservationID, @@ -1777,10 +1784,10 @@ private ReservationSubmissionRequest submitReservationTestHelper( try { sResponse = clientService.submitReservation(sRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(sResponse); - Assert.assertNotNull(reservationID); + Assertions.assertNotNull(sResponse); + Assertions.assertNotNull(reservationID); System.out.println("Submit reservation response: " + reservationID); return sRequest; } @@ -1801,7 +1808,7 @@ public void testCreateReservation() { try { clientService.submitReservation(sRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // Submit the reservation with the same reservation id but different @@ -1812,11 +1819,11 @@ public void testCreateReservation() { sRequest.setReservationDefinition(rDef); try { clientService.submitReservation(sRequest); - Assert.fail("Reservation submission should fail if a duplicate " + Assertions.fail("Reservation submission should fail if a duplicate " + "reservation id is used, but the reservation definition has been " + "updated."); } catch (Exception e) { - Assert.assertTrue(e instanceof YarnException); + Assertions.assertTrue(e instanceof YarnException); } } @@ -1848,9 +1855,9 @@ public void testUpdateReservation() { try { uResponse = clientService.updateReservation(uRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(uResponse); + Assertions.assertNotNull(uResponse); System.out.println("Update reservation response: " + uResponse); } @@ -1873,13 +1880,13 @@ public void testListReservationsByReservationId() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertEquals(1, response.getReservationAllocationState().size()); - Assert.assertEquals(response.getReservationAllocationState().get(0) + Assertions.assertNotNull(response); + Assertions.assertEquals(1, response.getReservationAllocationState().size()); + Assertions.assertEquals(response.getReservationAllocationState().get(0) .getReservationId().getId(), reservationID.getId()); - Assert.assertEquals(response.getReservationAllocationState().get(0) + Assertions.assertEquals(response.getReservationAllocationState().get(0) .getResourceAllocationRequests().size(), 0); } @@ -1906,11 +1913,11 @@ public void testListReservationsByTimeInterval() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertEquals(1, response.getReservationAllocationState().size()); - Assert.assertEquals(response.getReservationAllocationState().get(0) + Assertions.assertNotNull(response); + Assertions.assertEquals(1, response.getReservationAllocationState().size()); + Assertions.assertEquals(response.getReservationAllocationState().get(0) .getReservationId().getId(), reservationID.getId()); // List reservations, search by time within reservation interval. request = ReservationListRequest.newInstance( @@ -1920,23 +1927,23 @@ public void testListReservationsByTimeInterval() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertEquals(1, response.getReservationAllocationState().size()); - Assert.assertEquals(response.getReservationAllocationState().get(0) + Assertions.assertNotNull(response); + Assertions.assertEquals(1, response.getReservationAllocationState().size()); + Assertions.assertEquals(response.getReservationAllocationState().get(0) .getReservationId().getId(), reservationID.getId()); // Verify that the full resource allocations exist. - Assert.assertTrue(response.getReservationAllocationState().get(0) + Assertions.assertTrue(response.getReservationAllocationState().get(0) .getResourceAllocationRequests().size() > 0); // Verify that the full RDL is returned. ReservationRequests reservationRequests = response.getReservationAllocationState().get(0) .getReservationDefinition().getReservationRequests(); - Assert.assertEquals("R_ALL", + Assertions.assertEquals("R_ALL", reservationRequests.getInterpreter().toString()); - Assert.assertTrue(reservationRequests.getReservationResources().get(0) + Assertions.assertTrue(reservationRequests.getReservationResources().get(0) .getDuration() == duration); } @@ -1959,11 +1966,11 @@ public void testListReservationsByInvalidTimeInterval() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertEquals(1, response.getReservationAllocationState().size()); - Assert.assertEquals(response.getReservationAllocationState().get(0) + Assertions.assertNotNull(response); + Assertions.assertEquals(1, response.getReservationAllocationState().size()); + Assertions.assertEquals(response.getReservationAllocationState().get(0) .getReservationId().getId(), sRequest.getReservationId().getId()); // List reservations, search by invalid end time < -1. @@ -1974,11 +1981,11 @@ public void testListReservationsByInvalidTimeInterval() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertEquals(1, response.getReservationAllocationState().size()); - Assert.assertEquals(response.getReservationAllocationState().get(0) + Assertions.assertNotNull(response); + Assertions.assertEquals(1, response.getReservationAllocationState().size()); + Assertions.assertEquals(response.getReservationAllocationState().get(0) .getReservationId().getId(), sRequest.getReservationId().getId()); } @@ -2001,11 +2008,11 @@ public void testListReservationsByTimeIntervalContainingNoReservations() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // Ensure all reservations are filtered out. - Assert.assertNotNull(response); + Assertions.assertNotNull(response); assertThat(response.getReservationAllocationState()).isEmpty(); duration = 30000; @@ -2021,11 +2028,11 @@ public void testListReservationsByTimeIntervalContainingNoReservations() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // Ensure all reservations are filtered out. - Assert.assertNotNull(response); + Assertions.assertNotNull(response); assertThat(response.getReservationAllocationState()).isEmpty(); arrival = clock.getTime(); @@ -2039,11 +2046,11 @@ public void testListReservationsByTimeIntervalContainingNoReservations() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // Ensure all reservations are filtered out. - Assert.assertNotNull(response); + Assertions.assertNotNull(response); assertThat(response.getReservationAllocationState()).isEmpty(); // List reservations, search by very small end time. @@ -2054,11 +2061,11 @@ public void testListReservationsByTimeIntervalContainingNoReservations() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // Ensure all reservations are filtered out. - Assert.assertNotNull(response); + Assertions.assertNotNull(response); assertThat(response.getReservationAllocationState()).isEmpty(); } @@ -2081,9 +2088,9 @@ public void testReservationDelete() { try { dResponse = clientService.deleteReservation(dRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(dResponse); + Assertions.assertNotNull(dResponse); System.out.println("Delete reservation response: " + dResponse); // List reservations, search by non-existent reservationID @@ -2095,10 +2102,10 @@ public void testReservationDelete() { try { response = clientService.listReservations(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertEquals(0, response.getReservationAllocationState().size()); + Assertions.assertNotNull(response); + Assertions.assertEquals(0, response.getReservationAllocationState().size()); } @Test @@ -2136,21 +2143,21 @@ protected ClientRMService createClientRMService() { // Get node labels collection GetClusterNodeLabelsResponse response = client .getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance()); - Assert.assertTrue(response.getNodeLabelList().containsAll( + Assertions.assertTrue(response.getNodeLabelList().containsAll( Arrays.asList(labelX, labelY))); // Get node labels mapping GetNodesToLabelsResponse response1 = client .getNodeToLabels(GetNodesToLabelsRequest.newInstance()); Map> nodeToLabels = response1.getNodeToLabels(); - Assert.assertTrue(nodeToLabels.keySet().containsAll( + Assertions.assertTrue(nodeToLabels.keySet().containsAll( Arrays.asList(node1, node2))); - Assert.assertTrue(nodeToLabels.get(node1) + Assertions.assertTrue(nodeToLabels.get(node1) .containsAll(Arrays.asList(labelX.getName()))); - Assert.assertTrue(nodeToLabels.get(node2) + Assertions.assertTrue(nodeToLabels.get(node2) .containsAll(Arrays.asList(labelY.getName()))); // Below label "x" is not present in the response as exclusivity is true - Assert.assertFalse(nodeToLabels.get(node1).containsAll( + Assertions.assertFalse(nodeToLabels.get(node1).containsAll( Arrays.asList(NodeLabel.newInstance("x")))); } @@ -2197,20 +2204,20 @@ protected ClientRMService createClientRMService() { // Get node labels collection GetClusterNodeLabelsResponse response = client .getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance()); - Assert.assertTrue(response.getNodeLabelList().containsAll( + Assertions.assertTrue(response.getNodeLabelList().containsAll( Arrays.asList(labelX, labelY, labelZ))); // Get labels to nodes mapping GetLabelsToNodesResponse response1 = client .getLabelsToNodes(GetLabelsToNodesRequest.newInstance()); Map> labelsToNodes = response1.getLabelsToNodes(); - Assert.assertTrue(labelsToNodes.keySet().containsAll( + Assertions.assertTrue(labelsToNodes.keySet().containsAll( Arrays.asList(labelX.getName(), labelY.getName(), labelZ.getName()))); - Assert.assertTrue(labelsToNodes.get(labelX.getName()).containsAll( + Assertions.assertTrue(labelsToNodes.get(labelX.getName()).containsAll( Arrays.asList(node1A))); - Assert.assertTrue(labelsToNodes.get(labelY.getName()).containsAll( + Assertions.assertTrue(labelsToNodes.get(labelY.getName()).containsAll( Arrays.asList(node2A, node3A))); - Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll( + Assertions.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll( Arrays.asList(node1B, node3B))); // Get labels to nodes mapping for specific labels @@ -2219,16 +2226,17 @@ protected ClientRMService createClientRMService() { GetLabelsToNodesResponse response2 = client .getLabelsToNodes(GetLabelsToNodesRequest.newInstance(setlabels)); labelsToNodes = response2.getLabelsToNodes(); - Assert.assertTrue(labelsToNodes.keySet().containsAll( + Assertions.assertTrue(labelsToNodes.keySet().containsAll( Arrays.asList(labelX.getName(), labelZ.getName()))); - Assert.assertTrue(labelsToNodes.get(labelX.getName()).containsAll( + Assertions.assertTrue(labelsToNodes.get(labelX.getName()).containsAll( Arrays.asList(node1A))); - Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll( + Assertions.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll( Arrays.asList(node1B, node3B))); assertThat(labelsToNodes.get(labelY.getName())).isNull(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testGetClusterNodeAttributes() throws IOException, YarnException { Configuration newConf = NodeAttributeTestUtils.getRandomDirConf(null); MockRM rm = new MockRM(newConf) { @@ -2270,14 +2278,15 @@ protected ClientRMService createClientRMService() { GetClusterNodeAttributesResponse response = client.getClusterNodeAttributes(request); Set attributes = response.getNodeAttributes(); - Assert.assertEquals("Size not correct", 3, attributes.size()); - Assert.assertTrue(attributes.contains(NodeAttributeInfo.newInstance(gpu))); - Assert.assertTrue(attributes.contains(NodeAttributeInfo.newInstance(os))); - Assert + Assertions.assertEquals(3, attributes.size(), "Size not correct"); + Assertions.assertTrue(attributes.contains(NodeAttributeInfo.newInstance(gpu))); + Assertions.assertTrue(attributes.contains(NodeAttributeInfo.newInstance(os))); + Assertions .assertTrue(attributes.contains(NodeAttributeInfo.newInstance(docker))); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testGetAttributesToNodes() throws IOException, YarnException { Configuration newConf = NodeAttributeTestUtils.getRandomDirConf(null); MockRM rm = new MockRM(newConf) { @@ -2327,11 +2336,11 @@ protected ClientRMService createClientRMService() { assertThat(attrs.get(dist.getAttributeKey())).hasSize(2); assertThat(attrs.get(os.getAttributeKey())).hasSize(1); assertThat(attrs.get(gpu.getAttributeKey())).hasSize(1); - Assert.assertTrue(findHostnameAndValInMapping(node1, "3_0_2", + Assertions.assertTrue(findHostnameAndValInMapping(node1, "3_0_2", attrs.get(dist.getAttributeKey()))); - Assert.assertTrue(findHostnameAndValInMapping(node2, "3_0_2", + Assertions.assertTrue(findHostnameAndValInMapping(node2, "3_0_2", attrs.get(dist.getAttributeKey()))); - Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0", + Assertions.assertTrue(findHostnameAndValInMapping(node2, "docker0", attrs.get(docker.getAttributeKey()))); GetAttributesToNodesRequest request2 = GetAttributesToNodesRequest @@ -2341,7 +2350,7 @@ protected ClientRMService createClientRMService() { Map> attrs2 = response2.getAttributesToNodes(); assertThat(attrs2).hasSize(1); - Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0", + Assertions.assertTrue(findHostnameAndValInMapping(node2, "docker0", attrs2.get(docker.getAttributeKey()))); GetAttributesToNodesRequest request3 = @@ -2352,9 +2361,9 @@ protected ClientRMService createClientRMService() { Map> attrs3 = response3.getAttributesToNodes(); assertThat(attrs3).hasSize(2); - Assert.assertTrue(findHostnameAndValInMapping(node1, "windows64", + Assertions.assertTrue(findHostnameAndValInMapping(node1, "windows64", attrs3.get(os.getAttributeKey()))); - Assert.assertTrue(findHostnameAndValInMapping(node2, "docker0", + Assertions.assertTrue(findHostnameAndValInMapping(node2, "docker0", attrs3.get(docker.getAttributeKey()))); } @@ -2368,7 +2377,8 @@ private boolean findHostnameAndValInMapping(String hostname, String attrVal, return false; } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testGetNodesToAttributes() throws IOException, YarnException { Configuration newConf = NodeAttributeTestUtils.getRandomDirConf(null); MockRM rm = new MockRM(newConf) { @@ -2415,11 +2425,11 @@ protected ClientRMService createClientRMService() { client.getNodesToAttributes(request1); Map> hostToAttrs = response1.getNodeToAttributes(); - Assert.assertEquals(2, hostToAttrs.size()); + Assertions.assertEquals(2, hostToAttrs.size()); - Assert.assertTrue(hostToAttrs.get(node2).contains(dist)); - Assert.assertTrue(hostToAttrs.get(node2).contains(docker)); - Assert.assertTrue(hostToAttrs.get(node1).contains(dist)); + Assertions.assertTrue(hostToAttrs.get(node2).contains(dist)); + Assertions.assertTrue(hostToAttrs.get(node2).contains(docker)); + Assertions.assertTrue(hostToAttrs.get(node1).contains(dist)); // Specify particular node GetNodesToAttributesRequest request2 = @@ -2427,8 +2437,8 @@ protected ClientRMService createClientRMService() { GetNodesToAttributesResponse response2 = client.getNodesToAttributes(request2); hostToAttrs = response2.getNodeToAttributes(); - Assert.assertEquals(1, response2.getNodeToAttributes().size()); - Assert.assertTrue(hostToAttrs.get(node1).contains(dist)); + Assertions.assertEquals(1, response2.getNodeToAttributes().size()); + Assertions.assertTrue(hostToAttrs.get(node1).contains(dist)); // Test queury with empty set GetNodesToAttributesRequest request3 = @@ -2436,11 +2446,11 @@ protected ClientRMService createClientRMService() { GetNodesToAttributesResponse response3 = client.getNodesToAttributes(request3); hostToAttrs = response3.getNodeToAttributes(); - Assert.assertEquals(2, hostToAttrs.size()); + Assertions.assertEquals(2, hostToAttrs.size()); - Assert.assertTrue(hostToAttrs.get(node2).contains(dist)); - Assert.assertTrue(hostToAttrs.get(node2).contains(docker)); - Assert.assertTrue(hostToAttrs.get(node1).contains(dist)); + Assertions.assertTrue(hostToAttrs.get(node2).contains(dist)); + Assertions.assertTrue(hostToAttrs.get(node2).contains(docker)); + Assertions.assertTrue(hostToAttrs.get(node1).contains(dist)); // test invalid hostname GetNodesToAttributesRequest request4 = @@ -2448,10 +2458,11 @@ protected ClientRMService createClientRMService() { GetNodesToAttributesResponse response4 = client.getNodesToAttributes(request4); hostToAttrs = response4.getNodeToAttributes(); - Assert.assertEquals(0, hostToAttrs.size()); + Assertions.assertEquals(0, hostToAttrs.size()); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testUpdatePriorityAndKillAppWithZeroClusterResource() throws Exception { int maxPriority = 10; @@ -2477,7 +2488,8 @@ public void testUpdatePriorityAndKillAppWithZeroClusterResource() rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testUpdateApplicationPriorityRequest() throws Exception { int maxPriority = 10; int appPriority = 5; @@ -2499,8 +2511,8 @@ public void testUpdateApplicationPriorityRequest() throws Exception { .build(); RMApp app1 = MockRMAppSubmitter.submit(rm, data); - Assert.assertEquals("Incorrect priority has been set to application", - appPriority, app1.getApplicationPriority().getPriority()); + Assertions.assertEquals( + appPriority, app1.getApplicationPriority().getPriority(), "Incorrect priority has been set to application"); appPriority = 11; ClientRMService rmService = rm.getClientRMService(); @@ -2520,7 +2532,7 @@ public void testUpdateApplicationPriorityRequest() throws Exception { Priority.newInstance(appPriority)); try { rmService.updateApplicationPriority(updateRequest); - Assert.fail("ApplicationNotFoundException should be thrown " + Assertions.fail("ApplicationNotFoundException should be thrown " + "for invalid application id"); } catch (ApplicationNotFoundException e) { // Expected @@ -2529,9 +2541,9 @@ public void testUpdateApplicationPriorityRequest() throws Exception { updateRequest = UpdateApplicationPriorityRequest.newInstance(app1.getApplicationId(), Priority.newInstance(11)); - Assert.assertEquals("Incorrect priority has been set to application", - appPriority, rmService.updateApplicationPriority(updateRequest) - .getApplicationPriority().getPriority()); + Assertions.assertEquals( + appPriority, rmService.updateApplicationPriority(updateRequest) + .getApplicationPriority().getPriority(), "Incorrect priority has been set to application"); } private void testApplicationPriorityUpdation(ClientRMService rmService, @@ -2544,11 +2556,11 @@ private void testApplicationPriorityUpdation(ClientRMService rmService, UpdateApplicationPriorityResponse updateApplicationPriority = rmService.updateApplicationPriority(updateRequest); - Assert.assertEquals("Incorrect priority has been set to application", - expected, app1.getApplicationSubmissionContext().getPriority() - .getPriority()); - Assert.assertEquals("Incorrect priority has been returned", expected, - updateApplicationPriority.getApplicationPriority().getPriority()); + Assertions.assertEquals( + expected, app1.getApplicationSubmissionContext().getPriority() + .getPriority(), "Incorrect priority has been set to application"); + Assertions.assertEquals(expected +, updateApplicationPriority.getApplicationPriority().getPriority(), "Incorrect priority has been returned"); } private File createExcludeFile(File testDir) throws IOException { @@ -2562,7 +2574,7 @@ private File createExcludeFile(File testDir) throws IOException { @Test public void testRMStartWithDecommissionedNode() throws Exception { File testDir = GenericTestUtils.getRandomizedTestDir(); - assertTrue("Failed to create test directory: " + testDir.getAbsolutePath(), testDir.mkdirs()); + assertTrue(testDir.mkdirs(), "Failed to create test directory: " + testDir.getAbsolutePath()); try { File excludeFile = createExcludeFile(testDir); conf = new YarnConfiguration(); @@ -2619,18 +2631,18 @@ protected ClientRMService createClientRMService() { GetAllResourceTypeInfoRequest.newInstance(); GetAllResourceTypeInfoResponse response = client.getResourceTypeInfo(request); - Assert.assertEquals(2, response.getResourceTypeInfo().size()); + Assertions.assertEquals(2, response.getResourceTypeInfo().size()); // Check memory - Assert.assertEquals(ResourceInformation.MEMORY_MB.getName(), + Assertions.assertEquals(ResourceInformation.MEMORY_MB.getName(), response.getResourceTypeInfo().get(0).getName()); - Assert.assertEquals(ResourceInformation.MEMORY_MB.getUnits(), + Assertions.assertEquals(ResourceInformation.MEMORY_MB.getUnits(), response.getResourceTypeInfo().get(0).getDefaultUnit()); // Check vcores - Assert.assertEquals(ResourceInformation.VCORES.getName(), + Assertions.assertEquals(ResourceInformation.VCORES.getName(), response.getResourceTypeInfo().get(1).getName()); - Assert.assertEquals(ResourceInformation.VCORES.getUnits(), + Assertions.assertEquals(ResourceInformation.VCORES.getUnits(), response.getResourceTypeInfo().get(1).getDefaultUnit()); } @@ -2693,12 +2705,12 @@ public void handle(Event event) { // Test different cases of ClientRMService#getApplications() GetApplicationsRequest request = GetApplicationsRequest.newInstance(); - assertEquals("Incorrect total number of apps", 6, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(6 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect total number of apps"); rmService.setDisplayPerUserApps(true); - assertEquals("Incorrect number of applications for user", 0, - rmService.getApplications(request).getApplicationList().size()); + assertEquals(0 +, rmService.getApplications(request).getApplicationList().size(), "Incorrect number of applications for user"); rmService.setDisplayPerUserApps(false); } @@ -2752,30 +2764,30 @@ protected ClientRMService createClientRMService() { GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.RUNNING)); List nodeReports = client.getClusterNodes(request).getNodeReports(); - Assert.assertEquals(1, nodeReports.size()); - Assert.assertNotSame("Node is expected to be healthy!", NodeState.UNHEALTHY, - nodeReports.get(0).getNodeState()); - Assert.assertEquals(1, nodeReports.size()); + Assertions.assertEquals(1, nodeReports.size()); + Assertions.assertNotSame(NodeState.UNHEALTHY +, nodeReports.get(0).getNodeState(), "Node is expected to be healthy!"); + Assertions.assertEquals(1, nodeReports.size()); //Resource 'resource1' has been passed as 1T while registering NM. //1T should be converted to 1000G - Assert.assertEquals("G", nodeReports.get(0).getCapability(). + Assertions.assertEquals("G", nodeReports.get(0).getCapability(). getResourceInformation("resource1").getUnits()); - Assert.assertEquals(1000, nodeReports.get(0).getCapability(). + Assertions.assertEquals(1000, nodeReports.get(0).getCapability(). getResourceInformation("resource1").getValue()); //Resource 'resource2' has been passed as 1M while registering NM //1M should be converted to 1000000000M - Assert.assertEquals("m", nodeReports.get(0).getCapability(). + Assertions.assertEquals("m", nodeReports.get(0).getCapability(). getResourceInformation("resource2").getUnits()); - Assert.assertEquals(1000000000, nodeReports.get(0).getCapability(). + Assertions.assertEquals(1000000000, nodeReports.get(0).getCapability(). getResourceInformation("resource2").getValue()); //Resource 'memory-mb' has been passed as 976562G while registering NM //976562G should be converted to 976562Mi - Assert.assertEquals("Mi", nodeReports.get(0).getCapability(). + Assertions.assertEquals("Mi", nodeReports.get(0).getCapability(). getResourceInformation("memory-mb").getUnits()); - Assert.assertEquals(976562, nodeReports.get(0).getCapability(). + Assertions.assertEquals(976562, nodeReports.get(0).getCapability(). getResourceInformation("memory-mb").getValue()); } @@ -2811,17 +2823,17 @@ protected ClientRMService createClientRMService() { YarnClusterMetrics ymetrics = client.getClusterMetrics( GetClusterMetricsRequest.newInstance()).getClusterMetrics(); - Assert.assertEquals(0, ymetrics.getNumNodeManagers()); - Assert.assertEquals(1, ymetrics.getNumDecommissioningNodeManagers()); - Assert.assertEquals(2, ymetrics.getNumDecommissionedNodeManagers()); - Assert.assertEquals(3, ymetrics.getNumActiveNodeManagers()); - Assert.assertEquals(4, ymetrics.getNumLostNodeManagers()); - Assert.assertEquals(5, ymetrics.getNumUnhealthyNodeManagers()); - Assert.assertEquals(6, ymetrics.getNumRebootedNodeManagers()); - Assert.assertEquals(7, ymetrics.getNumShutdownNodeManagers()); + Assertions.assertEquals(0, ymetrics.getNumNodeManagers()); + Assertions.assertEquals(1, ymetrics.getNumDecommissioningNodeManagers()); + Assertions.assertEquals(2, ymetrics.getNumDecommissionedNodeManagers()); + Assertions.assertEquals(3, ymetrics.getNumActiveNodeManagers()); + Assertions.assertEquals(4, ymetrics.getNumLostNodeManagers()); + Assertions.assertEquals(5, ymetrics.getNumUnhealthyNodeManagers()); + Assertions.assertEquals(6, ymetrics.getNumRebootedNodeManagers()); + Assertions.assertEquals(7, ymetrics.getNumShutdownNodeManagers()); } - @After + @AfterEach public void tearDown() throws Exception { if (resourceTypesFile != null && resourceTypesFile.exists()) { resourceTypesFile.delete(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMTokens.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMTokens.java index 928f5f506647d..7c171d91a7e21 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMTokens.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClientRMTokens.java @@ -17,8 +17,8 @@ package org.apache.hadoop.yarn.server.resourcemanager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +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.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -41,8 +41,8 @@ import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData; -import org.junit.AfterClass; -import org.junit.Assert; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -78,9 +78,9 @@ import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TestClientRMTokens { @@ -91,7 +91,7 @@ public class TestClientRMTokens { // Note : Any test case in ResourceManager package that creates a proxy has // to be run with enabling hadoop.security.token.service.use_ip. And reset // to false at the end of test class. See YARN-5208 - @BeforeClass + @BeforeAll public static void setUp() { Configuration conf = new Configuration(); conf.setBoolean( @@ -99,7 +99,7 @@ public static void setUp() { SecurityUtil.setConfiguration(conf); } - @AfterClass + @AfterAll public static void tearDown() { Configuration conf = new Configuration(); conf.setBoolean( @@ -107,7 +107,7 @@ public static void tearDown() { SecurityUtil.setConfiguration(conf); } - @Before + @BeforeEach public void resetSecretManager() { RMDelegationTokenIdentifier.Renewer.setSecretManager(null, null); } @@ -149,7 +149,7 @@ public void testDelegationToken() throws Exception { // Create a user for the renewr and fake the authentication-method UserGroupInformation loggedInUser = UserGroupInformation .createRemoteUser("testrenewer@APACHE.ORG"); - Assert.assertEquals("testrenewer", loggedInUser.getShortUserName()); + Assertions.assertEquals("testrenewer", loggedInUser.getShortUserName()); // Default realm is APACHE.ORG loggedInUser.setAuthenticationMethod(AuthenticationMethod.KERBEROS); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClusterMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClusterMetrics.java index 645a2f1c40e59..f74e4aa1280f4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClusterMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestClusterMetrics.java @@ -21,10 +21,10 @@ import org.apache.hadoop.metrics2.MetricsSystem; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.function.Supplier; @@ -40,24 +40,24 @@ public class TestClusterMetrics { @Test public void testAmMetrics() throws Exception { assert(metrics != null); - Assert.assertTrue(!metrics.aMLaunchDelay.changed()); - Assert.assertTrue(!metrics.aMRegisterDelay.changed()); - Assert.assertTrue(!metrics.getAMContainerAllocationDelay().changed()); + Assertions.assertTrue(!metrics.aMLaunchDelay.changed()); + Assertions.assertTrue(!metrics.aMRegisterDelay.changed()); + Assertions.assertTrue(!metrics.getAMContainerAllocationDelay().changed()); metrics.addAMLaunchDelay(1); metrics.addAMRegisterDelay(1); metrics.addAMContainerAllocationDelay(1); - Assert.assertTrue(metrics.aMLaunchDelay.changed()); - Assert.assertTrue(metrics.aMRegisterDelay.changed()); - Assert.assertTrue(metrics.getAMContainerAllocationDelay().changed()); + Assertions.assertTrue(metrics.aMLaunchDelay.changed()); + Assertions.assertTrue(metrics.aMRegisterDelay.changed()); + Assertions.assertTrue(metrics.getAMContainerAllocationDelay().changed()); } - @Before + @BeforeEach public void setup() { DefaultMetricsSystem.initialize("ResourceManager"); metrics = ClusterMetrics.getMetrics(); } - @After + @AfterEach public void tearDown() { ClusterMetrics.destroy(); @@ -69,7 +69,7 @@ public void tearDown() { @Test public void testClusterMetrics() throws Exception { - Assert.assertTrue(!metrics.containerAssignedPerSecond.changed()); + Assertions.assertTrue(!metrics.containerAssignedPerSecond.changed()); metrics.incrNumContainerAssigned(); metrics.incrNumContainerAssigned(); GenericTestUtils.waitFor(new Supplier() { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestContainerResourceUsage.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestContainerResourceUsage.java index 54fd6509647e9..cd63f583230ba 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestContainerResourceUsage.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestContainerResourceUsage.java @@ -47,16 +47,17 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer; import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerState; 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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; public class TestContainerResourceUsage { private YarnConfiguration conf; - @Before + @BeforeEach public void setup() throws UnknownHostException { GenericTestUtils.setRootLogLevel(Level.DEBUG); conf = new YarnConfiguration(); @@ -65,11 +66,12 @@ public void setup() throws UnknownHostException { YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS); } - @After + @AfterEach public void tearDown() { } - @Test (timeout = 120000) + @Test + @Timeout(value = 120) public void testUsageWithOneAttemptAndOneContainer() throws Exception { MockRM rm = new MockRM(conf); rm.start(); @@ -81,14 +83,14 @@ public void testUsageWithOneAttemptAndOneContainer() throws Exception { RMApp app0 = MockRMAppSubmitter.submitWithMemory(200, rm); RMAppMetrics rmAppMetrics = app0.getRMAppMetrics(); - Assert.assertTrue( - "Before app submittion, memory seconds should have been 0 but was " - + rmAppMetrics.getMemorySeconds(), - rmAppMetrics.getMemorySeconds() == 0); - Assert.assertTrue( - "Before app submission, vcore seconds should have been 0 but was " - + rmAppMetrics.getVcoreSeconds(), - rmAppMetrics.getVcoreSeconds() == 0); + Assertions.assertTrue( + + rmAppMetrics.getMemorySeconds() == 0, "Before app submittion, memory seconds should have been 0 but was " + + rmAppMetrics.getMemorySeconds()); + Assertions.assertTrue( + + rmAppMetrics.getVcoreSeconds() == 0, "Before app submission, vcore seconds should have been 0 but was " + + rmAppMetrics.getVcoreSeconds()); RMAppAttempt attempt0 = app0.getCurrentAppAttempt(); @@ -109,29 +111,30 @@ public void testUsageWithOneAttemptAndOneContainer() throws Exception { } rmAppMetrics = app0.getRMAppMetrics(); - Assert.assertTrue( - "While app is running, memory seconds should be >0 but is " - + rmAppMetrics.getMemorySeconds(), - rmAppMetrics.getMemorySeconds() > 0); - Assert.assertTrue( - "While app is running, vcore seconds should be >0 but is " - + rmAppMetrics.getVcoreSeconds(), - rmAppMetrics.getVcoreSeconds() > 0); + Assertions.assertTrue( + + rmAppMetrics.getMemorySeconds() > 0, "While app is running, memory seconds should be >0 but is " + + rmAppMetrics.getMemorySeconds()); + Assertions.assertTrue( + + rmAppMetrics.getVcoreSeconds() > 0, "While app is running, vcore seconds should be >0 but is " + + rmAppMetrics.getVcoreSeconds()); MockRM.finishAMAndVerifyAppState(app0, rm, nm, am0); AggregateAppResourceUsage ru = calculateContainerResourceMetrics(rmContainer); rmAppMetrics = app0.getRMAppMetrics(); - Assert.assertEquals("Unexpected MemorySeconds value", - ru.getMemorySeconds(), rmAppMetrics.getMemorySeconds()); - Assert.assertEquals("Unexpected VcoreSeconds value", - ru.getVcoreSeconds(), rmAppMetrics.getVcoreSeconds()); + Assertions.assertEquals( + ru.getMemorySeconds(), rmAppMetrics.getMemorySeconds(), "Unexpected MemorySeconds value"); + Assertions.assertEquals( + ru.getVcoreSeconds(), rmAppMetrics.getVcoreSeconds(), "Unexpected VcoreSeconds value"); rm.stop(); } - @Test (timeout = 120000) + @Test + @Timeout(value = 120) public void testUsageWithMultipleContainersAndRMRestart() throws Exception { // Set max attempts to 1 so that when the first attempt fails, the app // won't try to start a new one. @@ -223,12 +226,12 @@ public void testUsageWithMultipleContainersAndRMRestart() throws Exception { } RMAppMetrics metricsBefore = app0.getRMAppMetrics(); - Assert.assertEquals("Unexpected MemorySeconds value", - memorySeconds, metricsBefore.getMemorySeconds()); - Assert.assertEquals("Unexpected VcoreSeconds value", - vcoreSeconds, metricsBefore.getVcoreSeconds()); - Assert.assertEquals("Unexpected totalAllocatedContainers value", - NUM_CONTAINERS + 1, metricsBefore.getTotalAllocatedContainers()); + Assertions.assertEquals( + memorySeconds, metricsBefore.getMemorySeconds(), "Unexpected MemorySeconds value"); + Assertions.assertEquals( + vcoreSeconds, metricsBefore.getVcoreSeconds(), "Unexpected VcoreSeconds value"); + Assertions.assertEquals( + NUM_CONTAINERS + 1, metricsBefore.getTotalAllocatedContainers(), "Unexpected totalAllocatedContainers value"); // create new RM to represent RM restart. Load up the state store. MockRM rm1 = new MockRM(conf, memStore); @@ -238,13 +241,13 @@ public void testUsageWithMultipleContainersAndRMRestart() throws Exception { // Compare container resource usage metrics from before and after restart. RMAppMetrics metricsAfter = app0After.getRMAppMetrics(); - Assert.assertEquals("Vcore seconds were not the same after RM Restart", - metricsBefore.getVcoreSeconds(), metricsAfter.getVcoreSeconds()); - Assert.assertEquals("Memory seconds were not the same after RM Restart", - metricsBefore.getMemorySeconds(), metricsAfter.getMemorySeconds()); - Assert.assertEquals("TotalAllocatedContainers was not the same after " + - "RM Restart", metricsBefore.getTotalAllocatedContainers(), - metricsAfter.getTotalAllocatedContainers()); + Assertions.assertEquals( + metricsBefore.getVcoreSeconds(), metricsAfter.getVcoreSeconds(), "Vcore seconds were not the same after RM Restart"); + Assertions.assertEquals( + metricsBefore.getMemorySeconds(), metricsAfter.getMemorySeconds(), "Memory seconds were not the same after RM Restart"); + Assertions.assertEquals(metricsBefore.getTotalAllocatedContainers() +, metricsAfter.getTotalAllocatedContainers(), "TotalAllocatedContainers was not the same after " + + "RM Restart"); rm0.stop(); rm0.close(); @@ -252,12 +255,14 @@ public void testUsageWithMultipleContainersAndRMRestart() throws Exception { rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testUsageAfterAMRestartWithMultipleContainers() throws Exception { amRestartTests(false); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testUsageAfterAMRestartKeepContainers() throws Exception { amRestartTests(true); } @@ -339,9 +344,9 @@ private void amRestartTests(boolean keepRunningContainers) vcoreSeconds += ru.getVcoreSeconds(); } else { // The remaining container should be RUNNING. - Assert.assertTrue("After first attempt failed, remaining container " - + "should still be running. ", - c.getContainerState().equals(ContainerState.RUNNING)); + Assertions.assertTrue( + c.getContainerState().equals(ContainerState.RUNNING), "After first attempt failed, remaining container " + + "should still be running. "); } } } else { @@ -360,7 +365,7 @@ private void amRestartTests(boolean keepRunningContainers) // assert this is a new AM. RMAppAttempt attempt2 = app.getCurrentAppAttempt(); - Assert.assertFalse(attempt2.getAppAttemptId() + Assertions.assertFalse(attempt2.getAppAttemptId() .equals(am0.getApplicationAttemptId())); rm.waitForState(attempt2.getAppAttemptId(), RMAppAttemptState.SCHEDULED); @@ -408,10 +413,10 @@ private void amRestartTests(boolean keepRunningContainers) RMAppMetrics rmAppMetrics = app.getRMAppMetrics(); - Assert.assertEquals("Unexpected MemorySeconds value", - memorySeconds, rmAppMetrics.getMemorySeconds()); - Assert.assertEquals("Unexpected VcoreSeconds value", - vcoreSeconds, rmAppMetrics.getVcoreSeconds()); + Assertions.assertEquals( + memorySeconds, rmAppMetrics.getMemorySeconds(), "Unexpected MemorySeconds value"); + Assertions.assertEquals( + vcoreSeconds, rmAppMetrics.getVcoreSeconds(), "Unexpected VcoreSeconds value"); rm.stop(); return; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDecommissioningNodesWatcher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDecommissioningNodesWatcher.java index c662b55e8db4a..9665c356119a9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDecommissioningNodesWatcher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestDecommissioningNodesWatcher.java @@ -37,9 +37,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeImpl; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeStatusEvent; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * This class tests DecommissioningNodesWatcher. @@ -84,25 +84,25 @@ public void testDecommissioningNodesWatcher() throws Exception { nodeStatus = createNodeStatus(id1, app, 2); node1.handle(new RMNodeStatusEvent(nm1.getNodeId(), nodeStatus)); watcher.update(node1, nodeStatus); - Assert.assertFalse(watcher.checkReadyToBeDecommissioned(id1)); + Assertions.assertFalse(watcher.checkReadyToBeDecommissioned(id1)); nodeStatus = createNodeStatus(id1, app, 1); node1.handle(new RMNodeStatusEvent(nm1.getNodeId(), nodeStatus)); watcher.update(node1, nodeStatus); - Assert.assertEquals(DecommissioningNodeStatus.WAIT_CONTAINER, + Assertions.assertEquals(DecommissioningNodeStatus.WAIT_CONTAINER, watcher.checkDecommissioningStatus(id1)); nodeStatus = createNodeStatus(id1, app, 0); watcher.update(node1, nodeStatus); node1.handle(new RMNodeStatusEvent(nm1.getNodeId(), nodeStatus)); - Assert.assertEquals(DecommissioningNodeStatus.WAIT_APP, + Assertions.assertEquals(DecommissioningNodeStatus.WAIT_APP, watcher.checkDecommissioningStatus(id1)); // Set app to be FINISHED and verified DecommissioningNodeStatus is READY. MockRM.finishAMAndVerifyAppState(app, rm, nm1, am); rm.waitForState(app.getApplicationId(), RMAppState.FINISHED); watcher.update(node1, nodeStatus); - Assert.assertEquals(DecommissioningNodeStatus.READY, + Assertions.assertEquals(DecommissioningNodeStatus.READY, watcher.checkDecommissioningStatus(id1)); } @@ -132,13 +132,13 @@ public void testDecommissioningNodesWatcherWithPreviousRunningApps() NodeStatus nodeStatus = createNodeStatus(id1, app, 3); node1.handle(new RMNodeStatusEvent(nm1.getNodeId(), nodeStatus)); - Assert.assertEquals(1, node1.getRunningApps().size()); + Assertions.assertEquals(1, node1.getRunningApps().size()); // update node with 0 running containers nodeStatus = createNodeStatus(id1, app, 0); node1.handle(new RMNodeStatusEvent(nm1.getNodeId(), nodeStatus)); - Assert.assertEquals(1, node1.getRunningApps().size()); + Assertions.assertEquals(1, node1.getRunningApps().size()); // Setup nm1 as DECOMMISSIONING for DecommissioningNodesWatcher. Right now // there is no container running on the node. @@ -149,20 +149,20 @@ public void testDecommissioningNodesWatcherWithPreviousRunningApps() // we should still get WAIT_APP as container for a running app previously // ran on this node. watcher.update(node1, nodeStatus); - Assert.assertFalse(watcher.checkReadyToBeDecommissioned(id1)); - Assert.assertEquals(DecommissioningNodeStatus.WAIT_APP, + Assertions.assertFalse(watcher.checkReadyToBeDecommissioned(id1)); + Assertions.assertEquals(DecommissioningNodeStatus.WAIT_APP, watcher.checkDecommissioningStatus(id1)); // Set app to be FINISHED and verified DecommissioningNodeStatus is READY. MockRM.finishAMAndVerifyAppState(app, rm, nm1, am); rm.waitForState(app.getApplicationId(), RMAppState.FINISHED); - Assert.assertEquals(0, node1.getRunningApps().size()); + Assertions.assertEquals(0, node1.getRunningApps().size()); watcher.update(node1, nodeStatus); - Assert.assertEquals(DecommissioningNodeStatus.READY, + Assertions.assertEquals(DecommissioningNodeStatus.READY, watcher.checkDecommissioningStatus(id1)); } - @After + @AfterEach public void tearDown() { if (rm != null) { rm.stop(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestKillApplicationWithRMHA.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestKillApplicationWithRMHA.java index e0f9bf57cc0d9..49ca89fe3014c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestKillApplicationWithRMHA.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestKillApplicationWithRMHA.java @@ -19,7 +19,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; @@ -41,8 +41,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager; import org.apache.hadoop.yarn.server.resourcemanager.security.RMDelegationTokenSecretManager; import org.apache.hadoop.yarn.server.security.ApplicationACLsManager; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; public class TestKillApplicationWithRMHA extends RMHATestBase{ @@ -50,7 +51,8 @@ public class TestKillApplicationWithRMHA extends RMHATestBase{ public static final Logger LOG = LoggerFactory .getLogger(TestKillApplicationWithRMHA.class); - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testKillAppWhenFailoverHappensAtNewState() throws Exception { // create a customized RMAppManager @@ -92,12 +94,13 @@ public void testKillAppWhenFailoverHappensAtNewState() failOverAndKillApp(app0.getApplicationId(), RMAppState.NEW); fail("Should get an exception here"); } catch (ApplicationNotFoundException ex) { - Assert.assertTrue(ex.getMessage().contains( + Assertions.assertTrue(ex.getMessage().contains( "Trying to kill an absent application " + app0.getApplicationId())); } } - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testKillAppWhenFailoverHappensAtRunningState() throws Exception { startRMs(); @@ -120,7 +123,8 @@ public void testKillAppWhenFailoverHappensAtRunningState() RMAppAttemptState.RUNNING, RMAppState.ACCEPTED); } - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testKillAppWhenFailoverHappensAtFinalState() throws Exception { startRMs(); @@ -148,7 +152,8 @@ public void testKillAppWhenFailoverHappensAtFinalState() RMAppAttemptState.KILLED, RMAppState.KILLED); } - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testKillAppWhenFailOverHappensDuringApplicationKill() throws Exception { // create a customized ClientRMService @@ -182,22 +187,22 @@ private void failOverAndKillApp(ApplicationId appId, ApplicationAttemptId appAttemptId, RMAppState initialRMAppState, RMAppAttemptState initialRMAppAttemptState, RMAppState expectedAppStateBeforeKillApp) throws Exception { - Assert.assertEquals(initialRMAppState, + Assertions.assertEquals(initialRMAppState, rm1.getRMContext().getRMApps().get(appId).getState()); - Assert.assertEquals(initialRMAppAttemptState, rm1.getRMContext() + Assertions.assertEquals(initialRMAppAttemptState, rm1.getRMContext() .getRMApps().get(appId).getAppAttempts().get(appAttemptId).getState()); explicitFailover(); - Assert.assertEquals(expectedAppStateBeforeKillApp, + Assertions.assertEquals(expectedAppStateBeforeKillApp, rm2.getRMContext().getRMApps().get(appId).getState()); killApplication(rm2, appId, appAttemptId, initialRMAppState); } private void failOverAndKillApp(ApplicationId appId, RMAppState initialRMAppState) throws Exception { - Assert.assertEquals(initialRMAppState, + Assertions.assertEquals(initialRMAppState, rm1.getRMContext().getRMApps().get(appId).getState()); explicitFailover(); - Assert.assertTrue(rm2.getRMContext().getRMApps().get(appId) == null); + Assertions.assertTrue(rm2.getRMContext().getRMApps().get(appId) == null); killApplication(rm2, appId, null, initialRMAppState); } @@ -259,7 +264,7 @@ private void killApplication(MockRM rm, ApplicationId appId, ApplicationAttemptId appAttemptId, RMAppState rmAppState) throws Exception { KillApplicationResponse response = rm.killApp(appId); - Assert + Assertions .assertTrue(response.getIsKillCompleted() == isFinalState(rmAppState)); RMApp loadedApp0 = rm.getRMContext().getRMApps().get(appId); @@ -268,6 +273,6 @@ private void killApplication(MockRM rm, ApplicationId appId, rm.waitForState(appAttemptId, RMAppAttemptState.KILLED); } // no new attempt is created. - Assert.assertEquals(1, loadedApp0.getAppAttempts().size()); + Assertions.assertEquals(1, loadedApp0.getAppAttempts().size()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestLeaderElectorService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestLeaderElectorService.java index a5762680942d0..a7e7253171fe1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestLeaderElectorService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestLeaderElectorService.java @@ -33,9 +33,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.recovery.records.ApplicationStateData; import org.slf4j.event.Level; import org.apache.zookeeper.ZooKeeper; -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; +import org.junit.jupiter.api.Timeout; import java.io.IOException; import java.util.Collection; @@ -54,7 +55,7 @@ public class TestLeaderElectorService { MockRM rm1; MockRM rm2; TestingCluster zkCluster; - @Before + @BeforeEach public void setUp() throws Exception { GenericTestUtils.setRootLogLevel(Level.INFO); conf = new Configuration(); @@ -73,7 +74,7 @@ public void setUp() throws Exception { zkCluster.start(); } - @After + @AfterEach public void tearDown() throws Exception { if (rm1 != null) { rm1.stop(); @@ -87,7 +88,8 @@ public void tearDown() throws Exception { // 2. rm2 standby // 3. stop rm1 // 4. rm2 become active - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testRMShutDownCauseFailover() throws Exception { rm1 = startRM("rm1", HAServiceState.ACTIVE); rm2 = startRM("rm2", HAServiceState.STANDBY); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestMoveApplication.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestMoveApplication.java index a078fb2ed7b63..36657bbc5fede 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestMoveApplication.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestMoveApplication.java @@ -18,8 +18,8 @@ package org.apache.hadoop.yarn.server.resourcemanager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.security.AccessControlException; import java.security.PrivilegedExceptionAction; @@ -36,16 +36,17 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler; -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; +import org.junit.jupiter.api.Timeout; public class TestMoveApplication { private ResourceManager resourceManager = null; private static boolean failMove; private Configuration conf; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, FifoSchedulerWithMove.class, @@ -59,7 +60,7 @@ public void setUp() throws Exception { failMove = false; } - @After + @AfterEach public void tearDown() { resourceManager.stop(); } @@ -91,7 +92,8 @@ public void testMoveRejectedByScheduler() throws Exception { } } - @Test (timeout = 10000) + @Test + @Timeout(value = 10) public void testMoveTooLate() throws Exception { // Submit application Application application = new Application("user1", resourceManager); @@ -119,8 +121,9 @@ public void testMoveTooLate() throws Exception { } } - @Test (timeout = 10000) - public + @Test + @Timeout(value = 10) + public void testMoveSuccessful() throws Exception { MockRM rm1 = new MockRM(conf); rm1.start(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestNodeBlacklistingOnAMFailures.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestNodeBlacklistingOnAMFailures.java index 8e35faff08d9a..544d0909d9077 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestNodeBlacklistingOnAMFailures.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestNodeBlacklistingOnAMFailures.java @@ -48,9 +48,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.utils.BuilderUtils; 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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; /** * Validate system behavior when the am-scheduling logic 'blacklists' a node for @@ -87,13 +88,14 @@ private RMApp submitAppWithAMResourceRequests(MockRM rm, return MockRMAppSubmitter.submit(rm, data); } - @Before + @BeforeEach public void setup() { QueueMetrics.clearQueueMetrics(); DefaultMetricsSystem.setMiniClusterMode(true); } - @Test(timeout = 100000) + @Test + @Timeout(value = 100) public void testNodeBlacklistingOnAMFailure() throws Exception { YarnConfiguration conf = new YarnConfiguration(); @@ -160,10 +162,10 @@ public void testNodeBlacklistingOnAMFailure() throws Exception { currentNode.nodeHeartbeat(true); rm.drainEvents(); - Assert.assertEquals( - "AppAttemptState should still be SCHEDULED if currentNode is " - + "blacklisted correctly", RMAppAttemptState.SCHEDULED, - attempt.getAppAttemptState()); + Assertions.assertEquals( + RMAppAttemptState.SCHEDULED +, attempt.getAppAttemptState(), "AppAttemptState should still be SCHEDULED if currentNode is " + + "blacklisted correctly"); } // Now try the other node @@ -181,22 +183,23 @@ public void testNodeBlacklistingOnAMFailure() throws Exception { nodeWhereAMRan = rmContainer.getAllocatedNode(); // The other node should now receive the assignment - Assert.assertEquals( - "After blacklisting, AM should have run on the other node", - otherNode.getNodeId(), nodeWhereAMRan); + Assertions.assertEquals( + + otherNode.getNodeId(), nodeWhereAMRan, "After blacklisting, AM should have run on the other node"); am2.registerAppAttempt(); rm.waitForState(app.getApplicationId(), RMAppState.RUNNING); List allocatedContainers = TestAMRestart.allocateContainers(currentNode, am2, 1); - Assert.assertEquals( - "Even though AM is blacklisted from the node, application can " - + "still allocate non-AM containers there", - currentNode.getNodeId(), allocatedContainers.get(0).getNodeId()); + Assertions.assertEquals( + + currentNode.getNodeId(), allocatedContainers.get(0).getNodeId(), "Even though AM is blacklisted from the node, application can " + + "still allocate non-AM containers there"); } - @Test(timeout = 100000) + @Test + @Timeout(value = 100) public void testNodeBlacklistingOnAMFailureStrictNodeLocality() throws Exception { YarnConfiguration conf = new YarnConfiguration(); @@ -251,7 +254,7 @@ public void testNodeBlacklistingOnAMFailureStrictNodeLocality() ContainerId.newContainerId(am1.getApplicationAttemptId(), 1); RMContainer rmContainer = scheduler.getRMContainer(amContainerId); NodeId nodeWhereAMRan = rmContainer.getAllocatedNode(); - Assert.assertEquals(nm2.getNodeId(), nodeWhereAMRan); + Assertions.assertEquals(nm2.getNodeId(), nodeWhereAMRan); // Set the exist status to INVALID so that we can verify that the system // automatically blacklisting the node @@ -277,13 +280,14 @@ public void testNodeBlacklistingOnAMFailureStrictNodeLocality() // The second AM should be on the same node because the strict locality // made the eligible nodes only 1, so the blacklisting threshold kicked in System.out.println("AM ran on " + nodeWhereAMRan); - Assert.assertEquals(nm2.getNodeId(), nodeWhereAMRan); + Assertions.assertEquals(nm2.getNodeId(), nodeWhereAMRan); am2.registerAppAttempt(); rm.waitForState(app.getApplicationId(), RMAppState.RUNNING); } - @Test(timeout = 100000) + @Test + @Timeout(value = 100) public void testNodeBlacklistingOnAMFailureRelaxedNodeLocality() throws Exception { YarnConfiguration conf = new YarnConfiguration(); @@ -338,7 +342,7 @@ public void testNodeBlacklistingOnAMFailureRelaxedNodeLocality() ContainerId.newContainerId(am1.getApplicationAttemptId(), 1); RMContainer rmContainer = scheduler.getRMContainer(amContainerId); NodeId nodeWhereAMRan = rmContainer.getAllocatedNode(); - Assert.assertEquals(nm2.getNodeId(), nodeWhereAMRan); + Assertions.assertEquals(nm2.getNodeId(), nodeWhereAMRan); // Set the exist status to INVALID so that we can verify that the system // automatically blacklisting the node @@ -368,13 +372,14 @@ public void testNodeBlacklistingOnAMFailureRelaxedNodeLocality() // The second AM should be on a different node because the relaxed locality // made the app schedulable on other nodes and nm2 is blacklisted System.out.println("AM ran on " + nodeWhereAMRan); - Assert.assertNotEquals(nm2.getNodeId(), nodeWhereAMRan); + Assertions.assertNotEquals(nm2.getNodeId(), nodeWhereAMRan); am2.registerAppAttempt(); rm.waitForState(app.getApplicationId(), RMAppState.RUNNING); } - @Test(timeout = 100000) + @Test + @Timeout(value = 100) public void testNoBlacklistingForNonSystemErrors() throws Exception { YarnConfiguration conf = new YarnConfiguration(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestOpportunisticContainerAllocatorAMService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestOpportunisticContainerAllocatorAMService.java index b99c456fb8173..980459ab54789 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestOpportunisticContainerAllocatorAMService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestOpportunisticContainerAllocatorAMService.java @@ -98,10 +98,11 @@ import org.apache.hadoop.yarn.server.scheduler.OpportunisticContainerContext; import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey; 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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.io.IOException; import java.net.InetSocketAddress; @@ -124,7 +125,7 @@ public class TestOpportunisticContainerAllocatorAMService { private OpportunisticContainersStatus oppContainersStatus = getOpportunisticStatus(); - @Before + @BeforeEach public void createAndStartRM() { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); @@ -168,7 +169,7 @@ protected Dispatcher createDispatcher() { rm.start(); } - @After + @AfterEach public void stopRM() { if (rm != null) { rm.stop(); @@ -177,7 +178,8 @@ public void stopRM() { OpportunisticSchedulerMetrics.resetMetrics(); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception { HashMap nodes = new HashMap<>(); MockNM nm1 = new MockNM("h1:1234", 4096, rm.getResourceTrackerService()); @@ -236,7 +238,7 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception null); List allocatedContainers = allocateResponse .getAllocatedContainers(); - Assert.assertEquals(2, allocatedContainers.size()); + Assertions.assertEquals(2, allocatedContainers.size()); Container container = allocatedContainers.get(0); MockNM allocNode = nodes.get(container.getNodeId()); MockNM sameHostDiffNode = null; @@ -258,7 +260,7 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception sameHostDiffNode.nodeHeartbeat(oppContainersStatus, true); rm.drainEvents(); allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); - Assert.assertEquals(0, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(0, allocateResponse.getUpdatedContainers().size()); // Wait for scheduler to process all events dispatcher.waitForEventThreadToWait(); @@ -271,11 +273,11 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception Arrays.asList(UpdateContainerRequest.newInstance(0, container.getId(), ContainerUpdateType.PROMOTE_EXECUTION_TYPE, null, ExecutionType.GUARANTEED))); - Assert.assertEquals(0, allocateResponse.getUpdatedContainers().size()); - Assert.assertEquals(1, allocateResponse.getUpdateErrors().size()); - Assert.assertEquals("UPDATE_OUTSTANDING_ERROR", + Assertions.assertEquals(0, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdateErrors().size()); + Assertions.assertEquals("UPDATE_OUTSTANDING_ERROR", allocateResponse.getUpdateErrors().get(0).getReason()); - Assert.assertEquals(container.getId(), + Assertions.assertEquals(container.getId(), allocateResponse.getUpdateErrors().get(0) .getUpdateContainerRequest().getContainerId()); @@ -286,14 +288,14 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception container.getId(), ContainerUpdateType.PROMOTE_EXECUTION_TYPE, null, ExecutionType.GUARANTEED))); - Assert.assertEquals(0, allocateResponse.getUpdatedContainers().size()); - Assert.assertEquals(1, allocateResponse.getUpdateErrors().size()); - Assert.assertEquals("INCORRECT_CONTAINER_VERSION_ERROR", + Assertions.assertEquals(0, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdateErrors().size()); + Assertions.assertEquals("INCORRECT_CONTAINER_VERSION_ERROR", allocateResponse.getUpdateErrors().get(0).getReason()); - Assert.assertEquals(0, + Assertions.assertEquals(0, allocateResponse.getUpdateErrors().get(0) .getCurrentContainerVersion()); - Assert.assertEquals(container.getId(), + Assertions.assertEquals(container.getId(), allocateResponse.getUpdateErrors().get(0) .getUpdateContainerRequest().getContainerId()); @@ -301,12 +303,12 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception allocNode.nodeHeartbeat(oppContainersStatus, true); rm.drainEvents(); allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); - Assert.assertEquals(1, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdatedContainers().size()); Container uc = allocateResponse.getUpdatedContainers().get(0).getContainer(); - Assert.assertEquals(ExecutionType.GUARANTEED, uc.getExecutionType()); - Assert.assertEquals(uc.getId(), container.getId()); - Assert.assertEquals(uc.getVersion(), container.getVersion() + 1); + Assertions.assertEquals(ExecutionType.GUARANTEED, uc.getExecutionType()); + Assertions.assertEquals(uc.getId(), container.getId()); + Assertions.assertEquals(uc.getVersion(), container.getVersion() + 1); // Verify Metrics After OPP allocation : // Allocated cores+mem should have increased, available should decrease @@ -322,7 +324,7 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception RMContainer rmContainer = ((CapacityScheduler) scheduler) .getApplicationAttempt( uc.getId().getApplicationAttemptId()).getRMContainer(uc.getId()); - Assert.assertEquals(RMContainerState.ACQUIRED, rmContainer.getState()); + Assertions.assertEquals(RMContainerState.ACQUIRED, rmContainer.getState()); // Now demote the container back.. allocateResponse = am1.sendContainerUpdateRequest( @@ -330,11 +332,11 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception uc.getId(), ContainerUpdateType.DEMOTE_EXECUTION_TYPE, null, ExecutionType.OPPORTUNISTIC))); // This should happen in the same heartbeat.. - Assert.assertEquals(1, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdatedContainers().size()); uc = allocateResponse.getUpdatedContainers().get(0).getContainer(); - Assert.assertEquals(ExecutionType.OPPORTUNISTIC, uc.getExecutionType()); - Assert.assertEquals(uc.getId(), container.getId()); - Assert.assertEquals(uc.getVersion(), container.getVersion() + 2); + Assertions.assertEquals(ExecutionType.OPPORTUNISTIC, uc.getExecutionType()); + Assertions.assertEquals(uc.getId(), container.getId()); + Assertions.assertEquals(uc.getVersion(), container.getVersion() + 2); // Wait for scheduler to finish processing events dispatcher.waitForEventThreadToWait(); @@ -344,7 +346,8 @@ public void testContainerPromoteAndDemoteBeforeContainerStart() throws Exception verifyMetrics(metrics, 15360, 15, 1024, 1, 1); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testContainerPromoteAfterContainerStart() throws Exception { HashMap nodes = new HashMap<>(); MockNM nm1 = new MockNM("h1:1234", 4096, rm.getResourceTrackerService()); @@ -393,7 +396,7 @@ public void testContainerPromoteAfterContainerStart() throws Exception { null); List allocatedContainers = allocateResponse .getAllocatedContainers(); - Assert.assertEquals(2, allocatedContainers.size()); + Assertions.assertEquals(2, allocatedContainers.size()); Container container = allocatedContainers.get(0); MockNM allocNode = nodes.get(container.getNodeId()); @@ -409,7 +412,7 @@ public void testContainerPromoteAfterContainerStart() throws Exception { .getApplicationAttempt( container.getId().getApplicationAttemptId()).getRMContainer( container.getId()); - Assert.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); + Assertions.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); // Verify Metrics After OPP allocation (Nothing should change) verifyMetrics(metrics, 7168, 7, 1024, 1, 1); @@ -427,11 +430,11 @@ public void testContainerPromoteAfterContainerStart() throws Exception { Arrays.asList(UpdateContainerRequest.newInstance(0, container.getId(), ContainerUpdateType.PROMOTE_EXECUTION_TYPE, null, ExecutionType.GUARANTEED))); - Assert.assertEquals(0, allocateResponse.getUpdatedContainers().size()); - Assert.assertEquals(1, allocateResponse.getUpdateErrors().size()); - Assert.assertEquals("UPDATE_OUTSTANDING_ERROR", + Assertions.assertEquals(0, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdateErrors().size()); + Assertions.assertEquals("UPDATE_OUTSTANDING_ERROR", allocateResponse.getUpdateErrors().get(0).getReason()); - Assert.assertEquals(container.getId(), + Assertions.assertEquals(container.getId(), allocateResponse.getUpdateErrors().get(0) .getUpdateContainerRequest().getContainerId()); @@ -443,25 +446,26 @@ public void testContainerPromoteAfterContainerStart() throws Exception { rm.drainEvents(); allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); - Assert.assertEquals(1, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdatedContainers().size()); Container uc = allocateResponse.getUpdatedContainers().get(0).getContainer(); - Assert.assertEquals(ExecutionType.GUARANTEED, uc.getExecutionType()); - Assert.assertEquals(uc.getId(), container.getId()); - Assert.assertEquals(uc.getVersion(), container.getVersion() + 1); + Assertions.assertEquals(ExecutionType.GUARANTEED, uc.getExecutionType()); + Assertions.assertEquals(uc.getId(), container.getId()); + Assertions.assertEquals(uc.getVersion(), container.getVersion() + 1); // Verify that the Container is still in RUNNING state wrt RM.. rmContainer = ((CapacityScheduler) scheduler) .getApplicationAttempt( uc.getId().getApplicationAttemptId()).getRMContainer(uc.getId()); - Assert.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); + Assertions.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); // Verify Metrics After OPP allocation : // Allocated cores+mem should have increased, available should decrease verifyMetrics(metrics, 6144, 6, 2048, 2, 2); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testContainerPromoteAfterContainerComplete() throws Exception { HashMap nodes = new HashMap<>(); MockNM nm1 = new MockNM("h1:1234", 4096, rm.getResourceTrackerService()); @@ -511,7 +515,7 @@ public void testContainerPromoteAfterContainerComplete() throws Exception { null); List allocatedContainers = allocateResponse .getAllocatedContainers(); - Assert.assertEquals(2, allocatedContainers.size()); + Assertions.assertEquals(2, allocatedContainers.size()); Container container = allocatedContainers.get(0); MockNM allocNode = nodes.get(container.getNodeId()); @@ -527,7 +531,7 @@ public void testContainerPromoteAfterContainerComplete() throws Exception { .getApplicationAttempt( container.getId().getApplicationAttemptId()).getRMContainer( container.getId()); - Assert.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); + Assertions.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); // Container Completed in the NM allocNode.nodeHeartbeat(Arrays.asList( @@ -541,7 +545,7 @@ public void testContainerPromoteAfterContainerComplete() throws Exception { .getApplicationAttempt( container.getId().getApplicationAttemptId()).getRMContainer( container.getId()); - Assert.assertNull(rmContainer); + Assertions.assertNull(rmContainer); // Verify Metrics After OPP allocation (Nothing should change) verifyMetrics(metrics, 7168, 7, 1024, 1, 1); @@ -553,16 +557,16 @@ public void testContainerPromoteAfterContainerComplete() throws Exception { container.getId(), ContainerUpdateType.PROMOTE_EXECUTION_TYPE, null, ExecutionType.GUARANTEED))); - Assert.assertEquals(1, + Assertions.assertEquals(1, allocateResponse.getCompletedContainersStatuses().size()); - Assert.assertEquals(container.getId(), + Assertions.assertEquals(container.getId(), allocateResponse.getCompletedContainersStatuses().get(0) .getContainerId()); - Assert.assertEquals(0, allocateResponse.getUpdatedContainers().size()); - Assert.assertEquals(1, allocateResponse.getUpdateErrors().size()); - Assert.assertEquals("INVALID_CONTAINER_ID", + Assertions.assertEquals(0, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdateErrors().size()); + Assertions.assertEquals("INVALID_CONTAINER_ID", allocateResponse.getUpdateErrors().get(0).getReason()); - Assert.assertEquals(container.getId(), + Assertions.assertEquals(container.getId(), allocateResponse.getUpdateErrors().get(0) .getUpdateContainerRequest().getContainerId()); @@ -570,7 +574,8 @@ public void testContainerPromoteAfterContainerComplete() throws Exception { verifyMetrics(metrics, 7168, 7, 1024, 1, 1); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testContainerAutoUpdateContainer() throws Exception { rm.stop(); createAndStartRMWithAutoUpdateContainer(); @@ -608,7 +613,7 @@ public void testContainerAutoUpdateContainer() throws Exception { allocateResponse.getAllocatedContainers(); allocatedContainers.addAll( am1.allocate(null, null).getAllocatedContainers()); - Assert.assertEquals(2, allocatedContainers.size()); + Assertions.assertEquals(2, allocatedContainers.size()); Container container = allocatedContainers.get(0); // Start Container in NM nm1.nodeHeartbeat(Arrays.asList(ContainerStatus @@ -620,7 +625,7 @@ public void testContainerAutoUpdateContainer() throws Exception { RMContainer rmContainer = ((CapacityScheduler) scheduler) .getApplicationAttempt(container.getId().getApplicationAttemptId()) .getRMContainer(container.getId()); - Assert.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); + Assertions.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); // Send Promotion req... this should result in update error // Since the container doesn't exist anymore.. @@ -636,17 +641,17 @@ public void testContainerAutoUpdateContainer() throws Exception { // Get the update response on next allocate allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); // Check the update response from YARNRM - Assert.assertEquals(1, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdatedContainers().size()); UpdatedContainer uc = allocateResponse.getUpdatedContainers().get(0); - Assert.assertEquals(container.getId(), uc.getContainer().getId()); - Assert.assertEquals(ExecutionType.GUARANTEED, + Assertions.assertEquals(container.getId(), uc.getContainer().getId()); + Assertions.assertEquals(ExecutionType.GUARANTEED, uc.getContainer().getExecutionType()); // Check that the container is updated in NM through NM heartbeat response NodeHeartbeatResponse response = nm1.nodeHeartbeat(true); - Assert.assertEquals(1, response.getContainersToUpdate().size()); + Assertions.assertEquals(1, response.getContainersToUpdate().size()); Container containersFromNM = response.getContainersToUpdate().get(0); - Assert.assertEquals(container.getId(), containersFromNM.getId()); - Assert.assertEquals(ExecutionType.GUARANTEED, + Assertions.assertEquals(container.getId(), containersFromNM.getId()); + Assertions.assertEquals(ExecutionType.GUARANTEED, containersFromNM.getExecutionType()); //Increase resources @@ -662,10 +667,10 @@ public void testContainerAutoUpdateContainer() throws Exception { if (allocateResponse.getUpdatedContainers().size() == 0) { allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); } - Assert.assertEquals(1, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdatedContainers().size()); uc = allocateResponse.getUpdatedContainers().get(0); - Assert.assertEquals(container.getId(), uc.getContainer().getId()); - Assert.assertEquals(Resource.newInstance(2 * GB, 1), + Assertions.assertEquals(container.getId(), uc.getContainer().getId()); + Assertions.assertEquals(Resource.newInstance(2 * GB, 1), uc.getContainer().getResource()); rm.drainEvents(); @@ -674,8 +679,8 @@ public void testContainerAutoUpdateContainer() throws Exception { if (response.getContainersToUpdate().size() == 0) { response = nm1.nodeHeartbeat(true); } - Assert.assertEquals(1, response.getContainersToUpdate().size()); - Assert.assertEquals(Resource.newInstance(2 * GB, 1), + Assertions.assertEquals(1, response.getContainersToUpdate().size()); + Assertions.assertEquals(Resource.newInstance(2 * GB, 1), response.getContainersToUpdate().get(0).getResource()); //Decrease resources @@ -683,14 +688,14 @@ public void testContainerAutoUpdateContainer() throws Exception { UpdateContainerRequest.newInstance(2, container.getId(), ContainerUpdateType.DECREASE_RESOURCE, Resources.createResource(1 * GB, 1), null))); - Assert.assertEquals(1, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdatedContainers().size()); rm.drainEvents(); // Check that the container resources are decreased // in NM through NM heartbeat response response = nm1.nodeHeartbeat(true); - Assert.assertEquals(1, response.getContainersToUpdate().size()); - Assert.assertEquals(Resource.newInstance(1 * GB, 1), + Assertions.assertEquals(1, response.getContainersToUpdate().size()); + Assertions.assertEquals(Resource.newInstance(1 * GB, 1), response.getContainersToUpdate().get(0).getResource()); nm1.nodeHeartbeat(oppContainersStatus, true); @@ -709,30 +714,31 @@ public void testContainerAutoUpdateContainer() throws Exception { allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); } // Check the update response from YARNRM - Assert.assertEquals(1, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(1, allocateResponse.getUpdatedContainers().size()); uc = allocateResponse.getUpdatedContainers().get(0); - Assert.assertEquals(ExecutionType.OPPORTUNISTIC, + Assertions.assertEquals(ExecutionType.OPPORTUNISTIC, uc.getContainer().getExecutionType()); // Check that the container is updated in NM through NM heartbeat response if (response.getContainersToUpdate().size() == 0) { response = nm1.nodeHeartbeat(oppContainersStatus, true); } - Assert.assertEquals(1, response.getContainersToUpdate().size()); - Assert.assertEquals(ExecutionType.OPPORTUNISTIC, + Assertions.assertEquals(1, response.getContainersToUpdate().size()); + Assertions.assertEquals(ExecutionType.OPPORTUNISTIC, response.getContainersToUpdate().get(0).getExecutionType()); } private void verifyMetrics(QueueMetrics metrics, long availableMB, int availableVirtualCores, long allocatedMB, int allocatedVirtualCores, int allocatedContainers) { - Assert.assertEquals(availableMB, metrics.getAvailableMB()); - Assert.assertEquals(availableVirtualCores, metrics.getAvailableVirtualCores()); - Assert.assertEquals(allocatedMB, metrics.getAllocatedMB()); - Assert.assertEquals(allocatedVirtualCores, metrics.getAllocatedVirtualCores()); - Assert.assertEquals(allocatedContainers, metrics.getAllocatedContainers()); + Assertions.assertEquals(availableMB, metrics.getAvailableMB()); + Assertions.assertEquals(availableVirtualCores, metrics.getAvailableVirtualCores()); + Assertions.assertEquals(allocatedMB, metrics.getAllocatedMB()); + Assertions.assertEquals(allocatedVirtualCores, metrics.getAllocatedVirtualCores()); + Assertions.assertEquals(allocatedContainers, metrics.getAllocatedContainers()); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testOpportunisticSchedulerMetrics() throws Exception { HashMap nodes = new HashMap<>(); MockNM nm1 = new MockNM("h1:1234", 4096, rm.getResourceTrackerService()); @@ -783,12 +789,12 @@ public void testOpportunisticSchedulerMetrics() throws Exception { List allocatedContainers = allocateResponse .getAllocatedContainers(); - Assert.assertEquals(2, allocatedContainers.size()); + Assertions.assertEquals(2, allocatedContainers.size()); - Assert.assertEquals(allocContainers + 2, metrics.getAllocatedContainers()); - Assert.assertEquals(aggrAllocatedContainers + 2, + Assertions.assertEquals(allocContainers + 2, metrics.getAllocatedContainers()); + Assertions.assertEquals(aggrAllocatedContainers + 2, metrics.getAggregatedAllocatedContainers()); - Assert.assertEquals(aggrOffSwitchContainers + 2, + Assertions.assertEquals(aggrOffSwitchContainers + 2, metrics.getAggregatedOffSwitchContainers()); Container container = allocatedContainers.get(0); @@ -806,7 +812,7 @@ public void testOpportunisticSchedulerMetrics() throws Exception { .getApplicationAttempt( container.getId().getApplicationAttemptId()).getRMContainer( container.getId()); - Assert.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); + Assertions.assertEquals(RMContainerState.RUNNING, rmContainer.getState()); // Container Completed in the NM allocNode.nodeHeartbeat(Arrays.asList( @@ -820,10 +826,10 @@ public void testOpportunisticSchedulerMetrics() throws Exception { .getApplicationAttempt( container.getId().getApplicationAttemptId()).getRMContainer( container.getId()); - Assert.assertNull(rmContainer); + Assertions.assertNull(rmContainer); - Assert.assertEquals(allocContainers + 1, metrics.getAllocatedContainers()); - Assert.assertEquals(aggrReleasedContainers + 1, + Assertions.assertEquals(allocContainers + 1, metrics.getAllocatedContainers()); + Assertions.assertEquals(aggrReleasedContainers + 1, metrics.getAggregatedReleasedContainers()); } @@ -872,7 +878,7 @@ public void testMetricsRetainsAllocatedOpportunisticAfterRMRestart() ExecutionType.OPPORTUNISTIC, -1); // Make sure that numbers start with 0 - Assert.assertEquals(0, metrics.getAllocatedContainers()); + Assertions.assertEquals(0, metrics.getAllocatedContainers()); // Recover one OContainer only rm.registerNode("h2:1234", 4096, 1, @@ -880,7 +886,7 @@ public void testMetricsRetainsAllocatedOpportunisticAfterRMRestart() appAttemptId.getApplicationId()), Collections.singletonList(recoverOContainerReport1)); - Assert.assertEquals(1, metrics.getAllocatedContainers()); + Assertions.assertEquals(1, metrics.getAllocatedContainers()); // Recover two OContainers at once final ContainerId recoverOContainerId3 = ContainerId.newContainerId( @@ -909,7 +915,7 @@ public void testMetricsRetainsAllocatedOpportunisticAfterRMRestart() appAttemptId.getApplicationId()), Arrays.asList(recoverOContainerReport2, recoverOContainerReport3)); - Assert.assertEquals(3, metrics.getAllocatedContainers()); + Assertions.assertEquals(3, metrics.getAllocatedContainers()); // Make sure that the recovered GContainer // does not increment OContainer count @@ -929,7 +935,7 @@ public void testMetricsRetainsAllocatedOpportunisticAfterRMRestart() appAttemptId.getApplicationId()), Collections.singletonList(recoverGContainerReport)); - Assert.assertEquals(3, metrics.getAllocatedContainers()); + Assertions.assertEquals(3, metrics.getAllocatedContainers()); final ContainerId completedOContainerId = ContainerId.newContainerId( appAttemptId, 6); @@ -948,10 +954,11 @@ public void testMetricsRetainsAllocatedOpportunisticAfterRMRestart() appAttemptId.getApplicationId()), Collections.singletonList(completedOContainerReport)); - Assert.assertEquals(3, metrics.getAllocatedContainers()); + Assertions.assertEquals(3, metrics.getAllocatedContainers()); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAMCrashDuringAllocate() throws Exception { MockNM nm = new MockNM("h:1234", 4096, rm.getResourceTrackerService()); nm.registerNode(); @@ -986,7 +993,8 @@ public void testAMCrashDuringAllocate() throws Exception { "*", Resources.createResource(1 * GB), 2)), null); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testNodeRemovalDuringAllocate() throws Exception { MockNM nm1 = new MockNM("h1:1234", 4096, rm.getResourceTrackerService()); MockNM nm2 = new MockNM("h2:1234", 4096, rm.getResourceTrackerService()); @@ -1032,7 +1040,7 @@ public void testNodeRemovalDuringAllocate() throws Exception { } Thread.sleep(50); } - Assert.assertEquals(2, ctxt.getNodeMap().size()); + Assertions.assertEquals(2, ctxt.getNodeMap().size()); // Remove node from scheduler but not from AM Service. scheduler.handle(new NodeRemovedSchedulerEvent(rmNode1)); // After removal of node 1, only 1 node will be applicable for scheduling. @@ -1043,17 +1051,18 @@ public void testNodeRemovalDuringAllocate() throws Exception { "*", Resources.createResource(1 * GB), 2)), null); } catch (Exception e) { - Assert.fail("Allocate request should be handled on node removal"); + Assertions.fail("Allocate request should be handled on node removal"); } if (ctxt.getNodeMap().size() == 1) { break; } Thread.sleep(50); } - Assert.assertEquals(1, ctxt.getNodeMap().size()); + Assertions.assertEquals(1, ctxt.getNodeMap().size()); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAppAttemptRemovalAfterNodeRemoval() throws Exception { MockNM nm = new MockNM("h:1234", 4096, rm.getResourceTrackerService()); @@ -1189,7 +1198,7 @@ public ResourceScheduler getScheduler() { ((RegisterApplicationMasterRequestPBImpl)factory .newRecordInstance( RegisterApplicationMasterRequest.class)).getProto())); - Assert.assertEquals("dummyQueue", regResp.getQueue()); + Assertions.assertEquals("dummyQueue", regResp.getQueue()); FinishApplicationMasterResponse finishResp = new FinishApplicationMasterResponsePBImpl( ampProxy.finishApplicationMaster(null, @@ -1197,7 +1206,7 @@ public ResourceScheduler getScheduler() { .newRecordInstance( FinishApplicationMasterRequest.class)).getProto() )); - Assert.assertEquals(false, finishResp.getIsUnregistered()); + Assertions.assertEquals(false, finishResp.getIsUnregistered()); AllocateResponse allocResp = new AllocateResponsePBImpl( ampProxy.allocate(null, @@ -1205,10 +1214,10 @@ public ResourceScheduler getScheduler() { .newRecordInstance(AllocateRequest.class)).getProto()) ); List allocatedContainers = allocResp.getAllocatedContainers(); - Assert.assertEquals(1, allocatedContainers.size()); - Assert.assertEquals(ExecutionType.OPPORTUNISTIC, + Assertions.assertEquals(1, allocatedContainers.size()); + Assertions.assertEquals(ExecutionType.OPPORTUNISTIC, allocatedContainers.get(0).getExecutionType()); - Assert.assertEquals(12345, allocResp.getNumClusterNodes()); + Assertions.assertEquals(12345, allocResp.getNumClusterNodes()); // Verify that the DistrubutedSchedulingService can handle the @@ -1225,12 +1234,12 @@ public ResourceScheduler getScheduler() { ((RegisterApplicationMasterRequestPBImpl)factory .newRecordInstance(RegisterApplicationMasterRequest.class)) .getProto())); - Assert.assertEquals(54321l, dsRegResp.getContainerIdStart()); - Assert.assertEquals(4, + Assertions.assertEquals(54321l, dsRegResp.getContainerIdStart()); + Assertions.assertEquals(4, dsRegResp.getMaxContainerResource().getVirtualCores()); - Assert.assertEquals(1024, + Assertions.assertEquals(1024, dsRegResp.getMinContainerResource().getMemorySize()); - Assert.assertEquals(2, + Assertions.assertEquals(2, dsRegResp.getIncrContainerResource().getVirtualCores()); DistributedSchedulingAllocateRequestPBImpl distAllReq = @@ -1242,9 +1251,9 @@ public ResourceScheduler getScheduler() { new DistributedSchedulingAllocateResponsePBImpl( dsProxy.allocateForDistributedScheduling(null, distAllReq.getProto())); - Assert.assertEquals( + Assertions.assertEquals( "h1", dsAllocResp.getNodesForScheduling().get(0).getNodeId().getHost()); - Assert.assertEquals( + Assertions.assertEquals( "l1", dsAllocResp.getNodesForScheduling().get(1).getNodePartition()); FinishApplicationMasterResponse dsfinishResp = @@ -1253,7 +1262,7 @@ public ResourceScheduler getScheduler() { ((FinishApplicationMasterRequestPBImpl) factory .newRecordInstance(FinishApplicationMasterRequest.class)) .getProto())); - Assert.assertEquals( + Assertions.assertEquals( false, dsfinishResp.getIsUnregistered()); } @@ -1315,11 +1324,11 @@ public AllocateResponse allocate(AllocateRequest request) throws List askList = request.getAllocateRequest().getAskList(); List allocatedContainers = request.getAllocatedContainers(); - Assert.assertEquals(1, allocatedContainers.size()); - Assert.assertEquals(ExecutionType.OPPORTUNISTIC, + Assertions.assertEquals(1, allocatedContainers.size()); + Assertions.assertEquals(ExecutionType.OPPORTUNISTIC, allocatedContainers.get(0).getExecutionType()); - Assert.assertEquals(1, askList.size()); - Assert.assertTrue(askList.get(0) + Assertions.assertEquals(1, askList.size()); + Assertions.assertTrue(askList.get(0) .getExecutionTypeRequest().getEnforceExecutionType()); DistributedSchedulingAllocateResponse resp = factory .newRecordInstance(DistributedSchedulingAllocateResponse.class); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java index a3bdf3945ad06..bac476e5869f8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRM.java +++ b/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,7 @@ 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 org.junit.jupiter.api.BeforeEach; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.spy; @@ -36,8 +36,8 @@ 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.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,7 +76,8 @@ 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.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentMatcher; @SuppressWarnings({"unchecked", "rawtypes"}) @@ -93,12 +94,12 @@ public TestRM(SchedulerType type) throws IOException { super(type); } - @Before + @BeforeEach public void setup() { conf = getConf(); } - @After + @AfterEach public void tearDown() { ClusterMetrics.destroy(); QueueMetrics.clearQueueMetrics(); @@ -117,7 +118,8 @@ public void testGetNewAppId() throws Exception { rm.stop(); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppWithNoContainers() throws Exception { GenericTestUtils.setRootLogLevel(Level.DEBUG); MockRM rm = new MockRM(conf); @@ -138,7 +140,8 @@ public void testAppWithNoContainers() throws Exception { rm.stop(); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppOnMultiNode() throws Exception { GenericTestUtils.setRootLogLevel(Level.DEBUG); conf.set(CapacitySchedulerConfiguration.NODE_LOCALITY_DELAY, "-1"); @@ -172,7 +175,7 @@ public void testAppOnMultiNode() throws Exception { LOG.info("Got " + contReceived + " containers. Waiting to get " + 3); Thread.sleep(WAIT_SLEEP_MS); } - Assert.assertEquals(3, conts.size()); + Assertions.assertEquals(3, conts.size()); //send node2 heartbeat conts = am.allocate(new ArrayList(), @@ -186,7 +189,7 @@ public void testAppOnMultiNode() throws Exception { LOG.info("Got " + contReceived + " containers. Waiting to get " + 10); Thread.sleep(WAIT_SLEEP_MS); } - Assert.assertEquals(10, conts.size()); + Assertions.assertEquals(10, conts.size()); am.unregisterAppAttempt(); nm1.nodeHeartbeat(attempt.getAppAttemptId(), 1, ContainerState.COMPLETE); @@ -198,7 +201,8 @@ public void testAppOnMultiNode() throws Exception { // 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) + @Test + @Timeout(value = 20) public void testNMTokenSentForNormalContainer() throws Exception { MockRM rm = new MockRM(conf); rm.start(); @@ -215,10 +219,10 @@ public void testNMTokenSentForNormalContainer() throws Exception { MockAM am = MockRM.launchAM(app, rm, nm1); // am container Id not equal to 1. - Assert.assertTrue( + Assertions.assertTrue( attempt.getMasterContainer().getId().getContainerId() != 1); // NMSecretManager doesn't record the node on which the am is allocated. - Assert.assertFalse(rm.getRMContext().getNMTokenSecretManager() + Assertions.assertFalse(rm.getRMContext().getNMTokenSecretManager() .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(), nm1.getNodeId())); am.registerAppAttempt(); @@ -245,10 +249,11 @@ public void testNMTokenSentForNormalContainer() throws Exception { } NodeId nodeId = expectedNMTokens.get(0).getNodeId(); // NMToken is sent for the allocated container. - Assert.assertEquals(nm1.getNodeId(), nodeId); + Assertions.assertEquals(nm1.getNodeId(), nodeId); } - @Test (timeout = 40000) + @Test + @Timeout(value = 40) public void testNMToken() throws Exception { MockRM rm = new MockRM(conf); try { @@ -270,7 +275,7 @@ public void testNMToken() throws Exception { MockAM am = rm.sendAMLaunched(attempt.getAppAttemptId()); - Assert.assertTrue(nmTokenSecretManager + Assertions.assertTrue(nmTokenSecretManager .isApplicationAttemptRegistered(attempt.getAppAttemptId())); // This will register application master. @@ -285,18 +290,18 @@ public void testNMToken() throws Exception { // initially requesting 2 containers. AllocateResponse response = am.allocate("h1", 1000, 2, releaseContainerList); - Assert.assertEquals(0, response.getAllocatedContainers().size()); + Assertions.assertEquals(0, response.getAllocatedContainers().size()); allocateContainersAndValidateNMTokens(am, containersReceivedForNM1, 2, nmTokens, nm1); - Assert.assertEquals(1, nmTokens.size()); + Assertions.assertEquals(1, nmTokens.size()); // requesting 2 more containers. response = am.allocate("h1", 1000, 2, releaseContainerList); - Assert.assertEquals(0, response.getAllocatedContainers().size()); + Assertions.assertEquals(0, response.getAllocatedContainers().size()); allocateContainersAndValidateNMTokens(am, containersReceivedForNM1, 4, nmTokens, nm1); - Assert.assertEquals(1, nmTokens.size()); + Assertions.assertEquals(1, nmTokens.size()); // We will be simulating NM restart so restarting newly added h2:1234 @@ -307,10 +312,10 @@ public void testNMToken() throws Exception { new ArrayList(); response = am.allocate("h2", 1000, 2, releaseContainerList); - Assert.assertEquals(0, response.getAllocatedContainers().size()); + Assertions.assertEquals(0, response.getAllocatedContainers().size()); allocateContainersAndValidateNMTokens(am, containersReceivedForNM2, 2, nmTokens, nm2); - Assert.assertEquals(2, nmTokens.size()); + Assertions.assertEquals(2, nmTokens.size()); // Simulating NM-2 restart. nm2 = rm.registerNode("h2:1234", 10000); @@ -329,57 +334,57 @@ public void testNMToken() throws Exception { LOG.info("waiting for nmToken to be cleared for : " + nm2.getNodeId()); Thread.sleep(WAIT_SLEEP_MS); } - Assert.assertTrue(nmTokenSecretManager + Assertions.assertTrue(nmTokenSecretManager .isApplicationAttemptRegistered(attempt.getAppAttemptId())); // removing NMToken for h2:1234 nmTokens.remove(nm2.getNodeId().toString()); - Assert.assertEquals(1, nmTokens.size()); + Assertions.assertEquals(1, nmTokens.size()); // We should again receive the NMToken. response = am.allocate("h2", 1000, 2, releaseContainerList); - Assert.assertEquals(0, response.getAllocatedContainers().size()); + Assertions.assertEquals(0, response.getAllocatedContainers().size()); allocateContainersAndValidateNMTokens(am, containersReceivedForNM2, 4, nmTokens, nm2); - Assert.assertEquals(2, nmTokens.size()); + Assertions.assertEquals(2, nmTokens.size()); // Now rolling over NMToken masterKey. it should resend the NMToken in // next allocate call. - Assert.assertTrue(nmTokenSecretManager + Assertions.assertTrue(nmTokenSecretManager .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(), nm1.getNodeId())); - Assert.assertTrue(nmTokenSecretManager + Assertions.assertTrue(nmTokenSecretManager .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(), nm2.getNodeId())); nmTokenSecretManager.rollMasterKey(); nmTokenSecretManager.activateNextMasterKey(); - Assert.assertFalse(nmTokenSecretManager + Assertions.assertFalse(nmTokenSecretManager .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(), nm1.getNodeId())); - Assert.assertFalse(nmTokenSecretManager + Assertions.assertFalse(nmTokenSecretManager .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(), nm2.getNodeId())); // It should not remove application attempt entry. - Assert.assertTrue(nmTokenSecretManager + Assertions.assertTrue(nmTokenSecretManager .isApplicationAttemptRegistered(attempt.getAppAttemptId())); nmTokens.clear(); - Assert.assertEquals(0, nmTokens.size()); + Assertions.assertEquals(0, nmTokens.size()); // We should again receive the NMToken. response = am.allocate("h2", 1000, 1, releaseContainerList); - Assert.assertEquals(0, response.getAllocatedContainers().size()); + Assertions.assertEquals(0, response.getAllocatedContainers().size()); allocateContainersAndValidateNMTokens(am, containersReceivedForNM2, 5, nmTokens, nm2); - Assert.assertEquals(1, nmTokens.size()); - Assert.assertTrue(nmTokenSecretManager + Assertions.assertEquals(1, nmTokens.size()); + Assertions.assertTrue(nmTokenSecretManager .isApplicationAttemptNMTokenPresent(attempt.getAppAttemptId(), nm2.getNodeId())); // After AM is finished making sure that nmtoken entry for app - Assert.assertTrue(nmTokenSecretManager + Assertions.assertTrue(nmTokenSecretManager .isApplicationAttemptRegistered(attempt.getAppAttemptId())); am.unregisterAppAttempt(); // marking all the containers as finished. @@ -396,7 +401,7 @@ public void testNMToken() throws Exception { nm1.nodeHeartbeat(am.getApplicationAttemptId(), 1, ContainerState.COMPLETE); rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.FINISHED); - Assert.assertFalse(nmTokenSecretManager + Assertions.assertFalse(nmTokenSecretManager .isApplicationAttemptRegistered(attempt.getAppAttemptId())); } finally { rm.stop(); @@ -421,7 +426,7 @@ protected void allocateContainersAndValidateNMTokens(MockAM am, for (NMToken nmToken : response.getNMTokens()) { String nodeId = nmToken.getNodeId().toString(); if (nmTokens.containsKey(nodeId)) { - Assert.fail("Duplicate NMToken received for : " + nodeId); + Assertions.fail("Duplicate NMToken received for : " + nodeId); } nmTokens.put(nodeId, nmToken.getToken()); } @@ -432,7 +437,8 @@ protected void allocateContainersAndValidateNMTokens(MockAM am, } } - @Test (timeout = 300000) + @Test + @Timeout(value = 300) public void testActivatingApplicationAfterAddingNM() throws Exception { MockRM rm1 = new MockRM(conf); @@ -477,7 +483,8 @@ public void testActivatingApplicationAfterAddingNM() throws Exception { // 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) + @Test + @Timeout(value = 80) public void testInvalidateAMHostPortWhenAMFailedOrKilled() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); MockRM rm1 = new MockRM(conf); @@ -513,23 +520,24 @@ public void testInvalidateAMHostPortWhenAMFailedOrKilled() throws Exception { rm1.getClientRMService().getApplications(request1); List appList1 = response1.getApplicationList(); - Assert.assertEquals(3, appList1.size()); + Assertions.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()); + Assertions.assertEquals("N/A", report.getHost()); + Assertions.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); + Assertions.assertFalse(report.getHost().equals("N/A")); + Assertions.assertTrue(report.getRpcPort() != -1); } } } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testInvalidatedAMHostPortOnAMRestart() throws Exception { MockRM rm1 = new MockRM(conf); rm1.start(); @@ -552,15 +560,16 @@ public void testInvalidatedAMHostPortOnAMRestart() throws Exception { ApplicationReport report1 = rm1.getClientRMService().getApplicationReport(request1) .getApplicationReport(); - Assert.assertEquals("N/A", report1.getHost()); - Assert.assertEquals(-1, report1.getRpcPort()); + Assertions.assertEquals("N/A", report1.getHost()); + Assertions.assertEquals(-1, report1.getRpcPort()); } /** * Validate killing an application when it is at accepted state. * @throws Exception exception */ - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testApplicationKillAtAcceptedState() throws Exception { final Dispatcher dispatcher = new DrainDispatcher() { @@ -641,12 +650,13 @@ public Boolean get() { && appsSubmitted + 1 == metrics.getAppsSubmitted(); } }, 100, 10000); - Assert.assertEquals(appsKilled + 1, metrics.getAppsKilled()); - Assert.assertEquals(appsSubmitted + 1, metrics.getAppsSubmitted()); + Assertions.assertEquals(appsKilled + 1, metrics.getAppsKilled()); + Assertions.assertEquals(appsSubmitted + 1, metrics.getAppsSubmitted()); } // Test Kill an app while the app is finishing in the meanwhile. - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testKillFinishingApp() throws Exception{ // this dispatcher ignores RMAppAttemptEventType.KILL event @@ -700,7 +710,8 @@ protected Dispatcher createDispatcher() { } // Test Kill an app while the app is failing - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testKillFailingApp() throws Exception{ // this dispatcher ignores RMAppAttemptEventType.KILL event diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAdminService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAdminService.java index 457e9d47dd0b4..0ab20a030b9d2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAdminService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAdminService.java @@ -19,8 +19,6 @@ package org.apache.hadoop.yarn.server.resourcemanager; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; import java.io.DataOutputStream; import java.io.File; @@ -91,10 +89,13 @@ import static org.apache.hadoop.yarn.conf.YarnConfiguration.RM_PROXY_USER_PREFIX; import static org.apache.hadoop.yarn.server.resourcemanager.resource.DynamicResourceConfiguration.NODES; import static org.apache.hadoop.yarn.server.resourcemanager.resource.DynamicResourceConfiguration.PREFIX; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.mockito.Mockito; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList; @@ -105,8 +106,6 @@ import org.apache.hadoop.yarn.nodelabels.NodeAttributesManager; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.AddToClusterNodeLabelsRequestProto; -import static org.junit.Assert.assertTrue; - public class TestRMAdminService { private Configuration configuration; @@ -122,7 +121,7 @@ public class TestRMAdminService { YarnConfiguration.DR_CONFIGURATION_FILE); } - @Before + @BeforeEach public void setup() throws IOException { QueueMetrics.clearQueueMetrics(); DefaultMetricsSystem.setMiniClusterMode(true); @@ -147,7 +146,7 @@ public void setup() throws IOException { MockUnixGroupsMapping.resetGroups(); } - @After + @AfterEach public void tearDown() throws IOException { if (rm != null) { rm.stop(); @@ -169,7 +168,7 @@ public void testAdminRefreshQueuesWithLocalConfigurationProvider() try { rm.adminService.refreshQueues(RefreshQueuesRequest.newInstance()); - Assert.assertEquals(maxAppsBefore, cs.getConfiguration() + Assertions.assertEquals(maxAppsBefore, cs.getConfiguration() .getMaximumSystemApplications()); } catch (Exception ex) { fail("Using localConfigurationProvider. Should not get any exception."); @@ -239,8 +238,8 @@ public void testAdminRefreshQueuesWithFileSystemBasedConfigurationProvider() rm.adminService.refreshQueues(RefreshQueuesRequest.newInstance()); int maxAppsAfter = cs.getConfiguration().getMaximumSystemApplications(); - Assert.assertEquals(maxAppsAfter, 5000); - Assert.assertTrue(maxAppsAfter != maxAppsBefore); + Assertions.assertEquals(maxAppsAfter, 5000); + Assertions.assertTrue(maxAppsAfter != maxAppsBefore); } @Test @@ -313,7 +312,7 @@ public void testRefreshNodesResourceWithFileSystemBasedConfigurationProvider() NodeId nid = NodeId.fromString("h1:1234"); RMNode ni = rm.getRMContext().getRMNodes().get(nid); Resource resource = ni.getTotalCapability(); - Assert.assertEquals("", resource.toString()); + Assertions.assertEquals("", resource.toString()); DynamicResourceConfiguration drConf = new DynamicResourceConfiguration(); @@ -328,7 +327,7 @@ public void testRefreshNodesResourceWithFileSystemBasedConfigurationProvider() RMNode niAfter = rm.getRMContext().getRMNodes().get(nid); Resource resourceAfter = niAfter.getTotalCapability(); - Assert.assertEquals("", resourceAfter.toString()); + Assertions.assertEquals("", resourceAfter.toString()); } @Test @@ -353,7 +352,7 @@ public void testRefreshNodesResourceWithResourceReturnInRegistration() NodeId nid = NodeId.fromString("h1:1234"); RMNode ni = rm.getRMContext().getRMNodes().get(nid); Resource resource = ni.getTotalCapability(); - Assert.assertEquals("", resource.toString()); + Assertions.assertEquals("", resource.toString()); DynamicResourceConfiguration drConf = new DynamicResourceConfiguration(); @@ -375,10 +374,10 @@ public void testRefreshNodesResourceWithResourceReturnInRegistration() RMNode niAfter = rm.getRMContext().getRMNodes().get(nid); Resource resourceAfter = niAfter.getTotalCapability(); - Assert.assertEquals("", resourceAfter.toString()); + Assertions.assertEquals("", resourceAfter.toString()); - Assert.assertEquals(4096, nm.getMemory()); - Assert.assertEquals(4, nm.getvCores()); + Assertions.assertEquals(4096, nm.getMemory()); + Assertions.assertEquals(4, nm.getvCores()); } @Test @@ -403,7 +402,7 @@ public void testRefreshNodesResourceWithResourceReturnInHeartbeat() NodeId nid = NodeId.fromString("h1:1234"); RMNode ni = rm.getRMContext().getRMNodes().get(nid); Resource resource = ni.getTotalCapability(); - Assert.assertEquals("", resource.toString()); + Assertions.assertEquals("", resource.toString()); DynamicResourceConfiguration drConf = new DynamicResourceConfiguration(); @@ -424,10 +423,10 @@ public void testRefreshNodesResourceWithResourceReturnInHeartbeat() RMNode niAfter = rm.getRMContext().getRMNodes().get(nid); Resource resourceAfter = niAfter.getTotalCapability(); - Assert.assertEquals("", resourceAfter.toString()); + Assertions.assertEquals("", resourceAfter.toString()); - Assert.assertEquals(4096, nm.getMemory()); - Assert.assertEquals(4, nm.getvCores()); + Assertions.assertEquals(4096, nm.getMemory()); + Assertions.assertEquals(4, nm.getvCores()); } @Test @@ -451,7 +450,7 @@ public void testResourcePersistentForNMRegistrationWithNewResource() NodeId nid = NodeId.fromString("h1:1234"); RMNode ni = rm.getRMContext().getRMNodes().get(nid); Resource resource = ni.getTotalCapability(); - Assert.assertEquals("", resource.toString()); + Assertions.assertEquals("", resource.toString()); DynamicResourceConfiguration drConf = new DynamicResourceConfiguration(); @@ -473,7 +472,7 @@ public void testResourcePersistentForNMRegistrationWithNewResource() RMNode niAfter = rm.getRMContext().getRMNodes().get(nid); Resource resourceAfter = niAfter.getTotalCapability(); - Assert.assertEquals("", resourceAfter.toString()); + Assertions.assertEquals("", resourceAfter.toString()); // Replace original dr file with an empty dr file, and validate node // registration with new resources will take effective now. @@ -496,7 +495,7 @@ public void testResourcePersistentForNMRegistrationWithNewResource() resourceAfter = niAfter.getTotalCapability(); // new resource in registration should take effective as we empty // dynamic resource file already. - Assert.assertEquals("", resourceAfter.toString()); + Assertions.assertEquals("", resourceAfter.toString()); } @Test @@ -541,8 +540,8 @@ public void testAdminAclsWithFileSystemBasedConfigurationProvider() String aclStringAfter = rm.adminService.getAccessControlList().getAclString().trim(); - Assert.assertTrue(!aclStringAfter.equals(aclStringBefore)); - Assert.assertEquals(aclStringAfter, "world:anyone:rwcda," + + Assertions.assertTrue(!aclStringAfter.equals(aclStringBefore)); + Assertions.assertEquals(aclStringAfter, "world:anyone:rwcda," + UserGroupInformation.getCurrentUser().getShortUserName()); } @@ -643,7 +642,7 @@ private void verifyServiceACLsRefresh(ServiceAuthorizationManager manager, AccessControlList accessList = manager.getProtocolsAcls(protocolClass); if (protocolClass == protocol) { - Assert.assertEquals(accessList.getAclString(), + Assertions.assertEquals(accessList.getAclString(), aclString); } else { assertThat(accessList.getAclString()).isEqualTo("*"); @@ -691,14 +690,14 @@ private void verifyServiceACLsRefresh(ServiceAuthorizationManager manager, rm.adminService.refreshSuperUserGroupsConfiguration( RefreshSuperUserGroupsConfigurationRequest.newInstance()); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() .get("hadoop.proxyuser.test.groups").size() == 1); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() .get("hadoop.proxyuser.test.groups").contains("test_groups")); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() .get("hadoop.proxyuser.test.hosts").size() == 1); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() .get("hadoop.proxyuser.test.hosts").contains("test_hosts")); Configuration yarnConf = new Configuration(false); @@ -709,14 +708,14 @@ private void verifyServiceACLsRefresh(ServiceAuthorizationManager manager, // RM specific configs will overwrite the common ones rm.adminService.refreshSuperUserGroupsConfiguration( RefreshSuperUserGroupsConfigurationRequest.newInstance()); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() .get("hadoop.proxyuser.test.groups").size() == 1); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() .get("hadoop.proxyuser.test.groups").contains("test_groups_1")); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() .get("hadoop.proxyuser.test.hosts").size() == 1); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() .get("hadoop.proxyuser.test.hosts").contains("test_hosts_1")); } @@ -772,11 +771,11 @@ public void testRefreshUserToGroupsMappingsWithLocalConfigurationProvider() { List groupBefore = new ArrayList(Groups.getUserToGroupsMappingService( configuration).getGroups(user)); - Assert.assertTrue(groupBefore.contains("test_group_A") + Assertions.assertTrue(groupBefore.contains("test_group_A") && groupBefore.contains("test_group_B") && groupBefore.contains("test_group_C") && groupBefore.size() == 3); - Assert.assertTrue(groupWithInit.size() != groupBefore.size()); - Assert.assertFalse(groupWithInit.contains("test_group_A") + Assertions.assertTrue(groupWithInit.size() != groupBefore.size()); + Assertions.assertFalse(groupWithInit.contains("test_group_A") || groupWithInit.contains("test_group_B") || groupWithInit.contains("test_group_C")); @@ -790,7 +789,7 @@ public void testRefreshUserToGroupsMappingsWithLocalConfigurationProvider() { Groups.getUserToGroupsMappingService(configuration).getGroups(user); // should get the updated groups - Assert.assertTrue(groupAfter.contains("test_group_D") + Assertions.assertTrue(groupAfter.contains("test_group_D") && groupAfter.contains("test_group_E") && groupAfter.contains("test_group_F") && groupAfter.size() == 3); @@ -832,7 +831,7 @@ public void testRefreshNodesWithFileSystemBasedConfigurationProvider() excludeHostsFile.delete(); } if (!excludeHostsFile.createNewFile()) { - Assert.fail("Can not create " + "excludeHosts"); + Assertions.fail("Can not create " + "excludeHosts"); } PrintWriter fileWriter = new PrintWriter(excludeHostsFile); fileWriter.write("0.0.0.0:123"); @@ -849,8 +848,8 @@ public void testRefreshNodesWithFileSystemBasedConfigurationProvider() .newInstance(DecommissionType.NORMAL)); Set excludeHosts = rm.getNodesListManager().getHostsReader().getExcludedHosts(); - Assert.assertTrue(excludeHosts.size() == 1); - Assert.assertTrue(excludeHosts.contains("0.0.0.0:123")); + Assertions.assertTrue(excludeHosts.size() == 1); + Assertions.assertTrue(excludeHosts.contains("0.0.0.0:123")); } @Test @@ -873,17 +872,17 @@ public void testRMHAWithFileSystemBasedConfiguration() throws IOException, rm1 = new MockRM(conf1); rm1.init(conf1); rm1.start(); - Assert.assertTrue(rm1.getRMContext().getHAServiceState() + Assertions.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.STANDBY); rm2 = new MockRM(conf2); rm2.init(conf1); rm2.start(); - Assert.assertTrue(rm2.getRMContext().getHAServiceState() + Assertions.assertTrue(rm2.getRMContext().getHAServiceState() == HAServiceState.STANDBY); rm1.adminService.transitionToActive(requestInfo); - Assert.assertTrue(rm1.getRMContext().getHAServiceState() + Assertions.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.ACTIVE); CapacitySchedulerConfiguration csConf = @@ -897,28 +896,28 @@ public void testRMHAWithFileSystemBasedConfiguration() throws IOException, int maxApps = ((CapacityScheduler) rm1.getRMContext().getScheduler()) .getConfiguration().getMaximumSystemApplications(); - Assert.assertEquals(maxApps, 5000); + Assertions.assertEquals(maxApps, 5000); // Before failover happens, the maxApps is // still the default value on the standby rm : rm2 int maxAppsBeforeFailOver = ((CapacityScheduler) rm2.getRMContext().getScheduler()) .getConfiguration().getMaximumSystemApplications(); - Assert.assertEquals(maxAppsBeforeFailOver, 10000); + Assertions.assertEquals(maxAppsBeforeFailOver, 10000); // Do the failover rm1.adminService.transitionToStandby(requestInfo); rm2.adminService.transitionToActive(requestInfo); - Assert.assertTrue(rm1.getRMContext().getHAServiceState() + Assertions.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.STANDBY); - Assert.assertTrue(rm2.getRMContext().getHAServiceState() + Assertions.assertTrue(rm2.getRMContext().getHAServiceState() == HAServiceState.ACTIVE); int maxAppsAfter = ((CapacityScheduler) rm2.getRMContext().getScheduler()) .getConfiguration().getMaximumSystemApplications(); - Assert.assertEquals(maxAppsAfter, 5000); + Assertions.assertEquals(maxAppsAfter, 5000); } finally { if (rm1 != null) { rm1.stop(); @@ -1034,7 +1033,7 @@ public void testRMInitialsWithFileSystemBasedConfigurationProvider() excludeHostsFile.delete(); } if (!excludeHostsFile.createNewFile()) { - Assert.fail("Can not create " + "excludeHosts"); + Assertions.fail("Can not create " + "excludeHosts"); } PrintWriter fileWriter = new PrintWriter(excludeHostsFile); fileWriter.write("0.0.0.0:123"); @@ -1085,21 +1084,21 @@ public void testRMInitialsWithFileSystemBasedConfigurationProvider() Set excludeHosts = resourceManager.getRMContext().getNodesListManager() .getHostsReader().getExcludedHosts(); - Assert.assertTrue(excludeHosts.size() == 1); - Assert.assertTrue(excludeHosts.contains("0.0.0.0:123")); + Assertions.assertTrue(excludeHosts.size() == 1); + Assertions.assertTrue(excludeHosts.contains("0.0.0.0:123")); // validate values for admin-acls String aclStringAfter = resourceManager.adminService.getAccessControlList() .getAclString().trim(); - Assert.assertEquals(aclStringAfter, "world:anyone:rwcda," + + Assertions.assertEquals(aclStringAfter, "world:anyone:rwcda," + UserGroupInformation.getCurrentUser().getShortUserName()); // validate values for queue configuration CapacityScheduler cs = (CapacityScheduler) resourceManager.getRMContext().getScheduler(); int maxAppsAfter = cs.getConfiguration().getMaximumSystemApplications(); - Assert.assertEquals(maxAppsAfter, 5000); + Assertions.assertEquals(maxAppsAfter, 5000); // verify service Acls for AdminService ServiceAuthorizationManager adminServiceServiceManager = @@ -1135,14 +1134,14 @@ public void testRMInitialsWithFileSystemBasedConfigurationProvider() // verify ProxyUsers and ProxyHosts ProxyUsers.refreshSuperUserGroupsConfiguration(configuration); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() .get("hadoop.proxyuser.test.groups").size() == 1); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyGroups() .get("hadoop.proxyuser.test.groups").contains("test_groups")); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() .get("hadoop.proxyuser.test.hosts").size() == 1); - Assert.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() + Assertions.assertTrue(ProxyUsers.getDefaultImpersonationProvider().getProxyHosts() .get("hadoop.proxyuser.test.hosts").contains("test_hosts")); // verify UserToGroupsMappings @@ -1150,7 +1149,7 @@ public void testRMInitialsWithFileSystemBasedConfigurationProvider() List groupAfter = Groups.getUserToGroupsMappingService(configuration).getGroups( UserGroupInformation.getCurrentUser().getUserName()); - Assert.assertTrue(groupAfter.contains("test_group_D") + Assertions.assertTrue(groupAfter.contains("test_group_D") && groupAfter.contains("test_group_E") && groupAfter.contains("test_group_F") && groupAfter.size() == 3); } finally { @@ -1219,25 +1218,27 @@ public void testModifyLabelsOnNodesWithDistributedConfigurationDisabled() rm.close(); } - @Test(expected = YarnException.class) + @Test public void testModifyLabelsOnNodesWithCentralizedConfigurationDisabled() throws IOException, YarnException { - // create RM and set it's ACTIVE, and set distributed node label - // configuration to true - MockRM rm = new MockRM(); - rm.adminService.isCentralizedNodeLabelConfiguration = false; - - ((RMContextImpl) rm.getRMContext()) - .setHAServiceState(HAServiceState.ACTIVE); - RMNodeLabelsManager labelMgr = rm.rmContext.getNodeLabelManager(); - - // by default, distributed configuration for node label is disabled, this - // should pass - labelMgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("x", "y")); - rm.adminService.replaceLabelsOnNode(ReplaceLabelsOnNodeRequest - .newInstance(ImmutableMap.of(NodeId.newInstance("host", 0), - (Set) ImmutableSet.of("x")))); - rm.close(); + assertThrows(YarnException.class, ()->{ + // create RM and set it's ACTIVE, and set distributed node label + // configuration to true + MockRM rm = new MockRM(); + rm.adminService.isCentralizedNodeLabelConfiguration = false; + + ((RMContextImpl) rm.getRMContext()) + .setHAServiceState(HAServiceState.ACTIVE); + RMNodeLabelsManager labelMgr = rm.rmContext.getNodeLabelManager(); + + // by default, distributed configuration for node label is disabled, this + // should pass + labelMgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("x", "y")); + rm.adminService.replaceLabelsOnNode(ReplaceLabelsOnNodeRequest + .newInstance(ImmutableMap.of(NodeId.newInstance("host", 0), + (Set) ImmutableSet.of("x")))); + rm.close(); + }); } @Test @@ -1348,7 +1349,8 @@ public void testRemoveClusterNodeLabelsWithCentralizedConfigurationDisabled() rm.close(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAdminRefreshClusterMaxPriority() throws Exception, YarnException { configuration.set(YarnConfiguration.RM_CONFIGURATION_PROVIDER_CLASS, @@ -1364,7 +1366,7 @@ public void testAdminRefreshClusterMaxPriority() throws Exception, rm.start(); CapacityScheduler cs = (CapacityScheduler) rm.getRMContext().getScheduler(); - Assert.assertEquals(5, cs.getMaxClusterLevelAppPriority().getPriority()); + Assertions.assertEquals(5, cs.getMaxClusterLevelAppPriority().getPriority()); yarnConf = new YarnConfiguration(); yarnConf @@ -1375,7 +1377,7 @@ public void testAdminRefreshClusterMaxPriority() throws Exception, rm.adminService .refreshClusterMaxPriority(RefreshClusterMaxPriorityRequest .newInstance()); - Assert.assertEquals(10, cs.getMaxClusterLevelAppPriority().getPriority()); + Assertions.assertEquals(10, cs.getMaxClusterLevelAppPriority().getPriority()); } catch (Exception ex) { fail("Could not refresh cluster max priority."); } @@ -1390,7 +1392,7 @@ private String writeConfigurationXML(Configuration conf, String confXMLName) confFile.delete(); } if (!confFile.createNewFile()) { - Assert.fail("Can not create " + confXMLName); + Assertions.fail("Can not create " + confXMLName); } output = new DataOutputStream( new FileOutputStream(confFile)); @@ -1495,7 +1497,7 @@ public void testSecureRMBecomeActive() throws IOException, try { resourceManager.init(configuration); resourceManager.start(); - Assert.assertTrue(resourceManager.getRMContext().getHAServiceState() + Assertions.assertTrue(resourceManager.getRMContext().getHAServiceState() == HAServiceState.STANDBY); resourceManager.adminService.transitionToActive(requestInfo); } finally { @@ -1537,12 +1539,13 @@ private void checkBadConfiguration(Configuration conf) { rm1.init(conf); fail("The RM allowed an invalid configuration"); } catch (YarnRuntimeException e) { - assertTrue("The RM initialization threw an unexpected exception", - e.getMessage().startsWith(HAUtil.BAD_CONFIG_MESSAGE_PREFIX)); + assertTrue( + e.getMessage().startsWith(HAUtil.BAD_CONFIG_MESSAGE_PREFIX), "The RM initialization threw an unexpected exception"); } } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAdminAddToClusterNodeLabelsWithDeprecatedAPIs() throws Exception, YarnException { configuration.set(YarnConfiguration.RM_CONFIGURATION_PROVIDER_CLASS, @@ -1586,11 +1589,12 @@ protected ClientRMService createClientRMService() { .getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance()); NodeLabel labelX = NodeLabel.newInstance("a"); NodeLabel labelY = NodeLabel.newInstance("b"); - Assert.assertTrue( + Assertions.assertTrue( response.getNodeLabelList().containsAll(Arrays.asList(labelX, labelY))); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testMapAttributesToNodes() throws Exception, YarnException { // 1. Need to test for the Invalid Node // 1.1. Need to test for active nodes @@ -1655,9 +1659,9 @@ public void testMapAttributesToNodes() throws Exception, YarnException { .removeNodeAttributes(Mockito.anyMap()); // Assert node to attributes mappings are empty. - Assert.assertTrue("Attributes of host4 should be empty", - rm.getRMContext().getNodeAttributesManager() - .getAttributesForNode("host4").isEmpty()); + Assertions.assertTrue( + rm.getRMContext().getNodeAttributesManager() + .getAttributesForNode("host4").isEmpty(), "Attributes of host4 should be empty"); // remove non existing attributes. request = NodesToAttributesMappingRequest .newInstance(AttributeMappingOperationType.REMOVE, ImmutableList @@ -1669,7 +1673,7 @@ public void testMapAttributesToNodes() throws Exception, YarnException { rm.adminService.mapAttributesToNodes(request); fail("Should have failed for non exists attribute"); } catch (Exception ex) { - assertTrue("Exception expected if attributes does not exist", true); + assertTrue(true, "Exception expected if attributes does not exist"); } request = @@ -1684,7 +1688,7 @@ public void testMapAttributesToNodes() throws Exception, YarnException { rm.adminService.mapAttributesToNodes(request); fail("host5 is not a valid node, It should have failed"); } catch (YarnException ex) { - Assert.assertEquals("Exception Message is not as desired", + Assertions.assertEquals("Exception Message is not as desired", " Following nodes does not exist : [host5]", ex.getCause().getMessage()); } @@ -1707,7 +1711,7 @@ public void testMapAttributesToNodes() throws Exception, YarnException { rm.adminService.mapAttributesToNodes(request); fail("host with the port should fail as only hostnames are validated"); } catch (YarnException ex) { - Assert.assertEquals("Exception Message is not as desired", + Assertions.assertEquals("Exception Message is not as desired", " Following nodes does not exist : [host4:8889, host2:8889]", ex.getCause().getMessage()); } @@ -1743,7 +1747,7 @@ public void testMapAttributesToNodes() throws Exception, YarnException { rm.adminService.mapAttributesToNodes(request); fail("This operation should fail as prefix should be \"nm.yarn.io\"."); } catch (YarnException ex) { - Assert.assertEquals("Exception Message is not as desired", + Assertions.assertEquals("Exception Message is not as desired", "Invalid Attribute Mapping for the node host5. Prefix should be " + "rm.yarn.io", ex.getCause().getMessage()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAuditLogger.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAuditLogger.java index c78a7788c4dba..874370d4db575 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAuditLogger.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMAuditLogger.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.yarn.server.resourcemanager; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -46,9 +46,9 @@ import org.apache.hadoop.yarn.api.records.ContainerId; import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.server.resourcemanager.RMAuditLogger.Keys; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** @@ -69,7 +69,7 @@ public class TestRMAuditLogger { private static final byte[] CALLER_SIGNATURE = "signature".getBytes(); private static final String PARTITION = "label1"; - @Before + @BeforeEach public void setUp() throws Exception { when(APPID.toString()).thenReturn("app_1"); when(ATTEMPTID.toString()).thenReturn("app_attempt_1"); @@ -242,7 +242,7 @@ private void testSuccessLogFormatHelperWithIP(boolean checkIP, } catch (UnknownHostException uhe) { // should not happen as long as IP address format // stays the same - Assert.fail("Check ip address being constructed"); + Assertions.fail("Check ip address being constructed"); } testSuccessLogFormatHelperWithIP(checkIP, appId, attemptId, containerId, addr); @@ -404,8 +404,8 @@ public TestProtos.EmptyResponseProto ping( throws ServiceException { // Ensure clientId is received byte[] clientId = Server.getClientId(); - Assert.assertNotNull(clientId); - Assert.assertEquals(ClientId.BYTE_LENGTH, clientId.length); + Assertions.assertNotNull(clientId); + Assertions.assertEquals(ClientId.BYTE_LENGTH, clientId.length); // test with ip set testSuccessLogFormat(true); testFailureLogFormat(true); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMDispatcher.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMDispatcher.java index 1ea470cf0944f..a7c57c5af5b84 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMDispatcher.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMDispatcher.java @@ -33,13 +33,15 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.ContainerPreemptEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; public class TestRMDispatcher { @SuppressWarnings("unchecked") - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testSchedulerEventDispatcherForPreemptionEvents() { AsyncDispatcher rmDispatcher = new AsyncDispatcher(); CapacityScheduler sched = spy(new CapacityScheduler()); @@ -73,7 +75,7 @@ public void testSchedulerEventDispatcherForPreemptionEvents() { verify(sched).markContainerForPreemption(appAttemptId, container); verify(sched).markContainerForKillable(container); } catch (InterruptedException e) { - Assert.fail(); + Assertions.fail(); } finally { schedulerDispatcher.stop(); rmDispatcher.stop(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java index 1781fed69a091..f7c9cf7ecdeb5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java @@ -25,16 +25,17 @@ import org.apache.hadoop.service.ServiceStateException; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +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.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.fail; +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; @@ -65,7 +66,7 @@ private enum SyncTestType { STANDBY_TIMING } - @Before + @BeforeEach public void setup() throws IOException { conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); @@ -94,7 +95,8 @@ public void setup() throws IOException { * * The test times out if there is a deadlock. */ - @Test (timeout = 10000) + @Test + @Timeout(value = 10) public void testDeadlockShutdownBecomeActive() throws InterruptedException { MockRM rm = new MockRMWithElector(conf, 1000); rm.start(); @@ -320,9 +322,9 @@ public void testFailureToConnectToZookeeper() throws Exception { new ActiveStandbyElectorBasedElectorService(rm); try { ees.init(myConf); - Assert.fail("expect failure to connect to Zookeeper"); + Assertions.fail("expect failure to connect to Zookeeper"); } catch (ServiceStateException sse) { - Assert.assertTrue(sse.getMessage().contains("ConnectionLoss")); + Assertions.assertTrue(sse.getMessage().contains("ConnectionLoss")); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java index 2f8de6b695a95..9f925914c58bf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHA.java @@ -27,10 +27,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; 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.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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.net.InetSocketAddress; @@ -71,9 +71,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.glassfish.jersey.jettison.internal.entity.JettisonObjectProvider; @@ -96,7 +97,7 @@ public class TestRMHA { private static final String RM3_ADDRESS = "2.2.2.2:2"; private static final String RM3_NODE_ID = "rm3"; - @Before + @BeforeEach public void setUp() throws Exception { configuration = new Configuration(); UserGroupInformation.setConfiguration(configuration); @@ -128,21 +129,21 @@ private void checkMonitorHealth() throws IOException { } private void checkStandbyRMFunctionality() throws IOException { - assertEquals(STATE_ERR, HAServiceState.STANDBY, - rm.adminService.getServiceStatus().getState()); - assertFalse("Active RM services are started", - rm.areActiveServicesRunning()); - assertTrue("RM is not ready to become active", - rm.adminService.getServiceStatus().isReadyToBecomeActive()); + assertEquals(HAServiceState.STANDBY, + rm.adminService.getServiceStatus().getState(), STATE_ERR); + assertFalse( + rm.areActiveServicesRunning(), "Active RM services are started"); + assertTrue( + rm.adminService.getServiceStatus().isReadyToBecomeActive(), "RM is not ready to become active"); } private void checkActiveRMFunctionality() throws Exception { - assertEquals(STATE_ERR, HAServiceState.ACTIVE, - rm.adminService.getServiceStatus().getState()); - assertTrue("Active RM services aren't started", - rm.areActiveServicesRunning()); - assertTrue("RM is not ready to become active", - rm.adminService.getServiceStatus().isReadyToBecomeActive()); + assertEquals(HAServiceState.ACTIVE, + rm.adminService.getServiceStatus().getState(), STATE_ERR); + assertTrue( + rm.areActiveServicesRunning(), "Active RM services aren't started"); + assertTrue( + rm.adminService.getServiceStatus().isReadyToBecomeActive(), "RM is not ready to become active"); try { rm.getNewAppId(); @@ -180,7 +181,7 @@ private void checkActiveRMWebServices() throws JSONException { response.getMediaType().toString()); JSONObject json = response.readEntity(JSONObject.class); - assertEquals("incorrect number of elements", 1, json.length()); + assertEquals(1, json.length(), "incorrect number of elements"); JSONObject appJson = json.getJSONObject("app"); assertEquals("ACCEPTED", appJson.getString("state")); // Other stuff is verified in the regular web-services related tests @@ -197,7 +198,8 @@ private void checkActiveRMWebServices() throws JSONException { * 6. Stop the RM: All services should stop and RM should not be ready to * become Active */ - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testFailoverAndTransitions() throws Exception { configuration.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false); Configuration conf = new YarnConfiguration(configuration); @@ -207,10 +209,10 @@ public void testFailoverAndTransitions() throws Exception { StateChangeRequestInfo requestInfo = new StateChangeRequestInfo( HAServiceProtocol.RequestSource.REQUEST_BY_USER); - assertEquals(STATE_ERR, HAServiceState.INITIALIZING, - rm.adminService.getServiceStatus().getState()); - assertFalse("RM is ready to become active before being started", - rm.adminService.getServiceStatus().isReadyToBecomeActive()); + assertEquals(HAServiceState.INITIALIZING, + rm.adminService.getServiceStatus().getState(), STATE_ERR); + assertFalse( + rm.adminService.getServiceStatus().isReadyToBecomeActive(), "RM is ready to become active before being started"); checkMonitorHealth(); rm.start(); @@ -251,12 +253,12 @@ public void testFailoverAndTransitions() throws Exception { // 6. Stop the RM. All services should stop and RM should not be ready to // become active rm.stop(); - assertEquals(STATE_ERR, HAServiceState.STOPPING, - rm.adminService.getServiceStatus().getState()); - assertFalse("RM is ready to become active even after it is stopped", - rm.adminService.getServiceStatus().isReadyToBecomeActive()); - assertFalse("Active RM services are started", - rm.areActiveServicesRunning()); + assertEquals(HAServiceState.STOPPING, + rm.adminService.getServiceStatus().getState(), STATE_ERR); + assertFalse( + rm.adminService.getServiceStatus().isReadyToBecomeActive(), "RM is ready to become active even after it is stopped"); + assertFalse( + rm.areActiveServicesRunning(), "Active RM services are started"); checkMonitorHealth(); } @@ -341,10 +343,10 @@ protected Dispatcher createDispatcher() { StateChangeRequestInfo requestInfo = new StateChangeRequestInfo( HAServiceProtocol.RequestSource.REQUEST_BY_USER); - assertEquals(STATE_ERR, HAServiceState.INITIALIZING, - rm.adminService.getServiceStatus().getState()); - assertFalse("RM is ready to become active before being started", - rm.adminService.getServiceStatus().isReadyToBecomeActive()); + assertEquals(HAServiceState.INITIALIZING, + rm.adminService.getServiceStatus().getState(), STATE_ERR); + assertFalse( + rm.adminService.getServiceStatus().isReadyToBecomeActive(), "RM is ready to become active before being started"); rm.start(); //call transitions to standby and active a couple of times @@ -359,11 +361,11 @@ protected Dispatcher createDispatcher() { assertTrue(!dispatcher.isStopped()); rm.adminService.transitionToActive(requestInfo); - assertEquals(errorMessageForEventHandler, expectedEventHandlerCount, + assertEquals(expectedEventHandlerCount, ((MyCountingDispatcher) rm.getRMContext().getDispatcher()) - .getEventHandlerCount()); - assertEquals(errorMessageForService, expectedServiceCount, - rm.getServices().size()); + .getEventHandlerCount(), errorMessageForEventHandler); + assertEquals(expectedServiceCount, + rm.getServices().size(), errorMessageForService); // Keep the dispatcher reference before transitioning to standby @@ -371,11 +373,11 @@ protected Dispatcher createDispatcher() { rm.adminService.transitionToStandby(requestInfo); - assertEquals(errorMessageForEventHandler, expectedEventHandlerCount, + assertEquals(expectedEventHandlerCount, ((MyCountingDispatcher) rm.getRMContext().getDispatcher()) - .getEventHandlerCount()); - assertEquals(errorMessageForService, expectedServiceCount, - rm.getServices().size()); + .getEventHandlerCount(), errorMessageForEventHandler); + assertEquals(expectedServiceCount, + rm.getServices().size(), errorMessageForService); assertTrue(dispatcher.isStopped()); @@ -408,7 +410,7 @@ public void testHAIDLookup() { rm.init(conf); fail("Should get an exception here."); } catch (Exception ex) { - Assert.assertTrue(ex.getMessage().contains( + Assertions.assertTrue(ex.getMessage().contains( "Invalid configuration! Can not find valid RM_HA_ID.")); } } @@ -421,7 +423,8 @@ public void testHAWithRMHostName() throws Exception { innerTestHAWithRMHostName(true); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testFailoverWhenTransitionToActiveThrowException() throws Exception { configuration.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false); @@ -447,10 +450,10 @@ public synchronized void startInternal() throws Exception { new StateChangeRequestInfo( HAServiceProtocol.RequestSource.REQUEST_BY_USER); - assertEquals(STATE_ERR, HAServiceState.INITIALIZING, rm.adminService - .getServiceStatus().getState()); - assertFalse("RM is ready to become active before being started", - rm.adminService.getServiceStatus().isReadyToBecomeActive()); + assertEquals(HAServiceState.INITIALIZING, rm.adminService + .getServiceStatus().getState(), STATE_ERR); + assertFalse( + rm.adminService.getServiceStatus().isReadyToBecomeActive(), "RM is ready to become active before being started"); checkMonitorHealth(); rm.start(); @@ -460,7 +463,7 @@ public synchronized void startInternal() throws Exception { // 2. Try Transition to active, throw exception try { rm.adminService.transitionToActive(requestInfo); - Assert.fail("Transitioned to Active should throw exception."); + Assertions.fail("Transitioned to Active should throw exception."); } catch (Exception e) { assertTrue("Error when transitioning to Active mode".contains(e .getMessage())); @@ -500,10 +503,10 @@ void stopActiveServices() { new StateChangeRequestInfo( HAServiceProtocol.RequestSource.REQUEST_BY_USER); - assertEquals(STATE_ERR, HAServiceState.INITIALIZING, rm.adminService - .getServiceStatus().getState()); - assertFalse("RM is ready to become active before being started", - rm.adminService.getServiceStatus().isReadyToBecomeActive()); + assertEquals(HAServiceState.INITIALIZING, rm.adminService + .getServiceStatus().getState(), STATE_ERR); + assertFalse( + rm.adminService.getServiceStatus().isReadyToBecomeActive(), "RM is ready to become active before being started"); checkMonitorHealth(); rm.start(); @@ -562,7 +565,7 @@ public void testFailoverClearsRMContext() throws Exception { verifyClusterMetrics(1, 1, 1, 1, 2048, 1); assertEquals(1, rm.getRMContext().getRMNodes().size()); assertEquals(1, rm.getRMContext().getRMApps().size()); - Assert.assertNotNull("Node not registered", nm); + Assertions.assertNotNull(nm, "Node not registered"); rm.adminService.transitionToStandby(requestInfo); checkMonitorHealth(); @@ -597,7 +600,7 @@ protected void serviceStart() throws Exception { // 4. Try Transition to active, throw exception try { rm.adminService.transitionToActive(requestInfo); - Assert.fail("Transitioned to Active should throw exception."); + Assertions.fail("Transitioned to Active should throw exception."); } catch (Exception e) { assertTrue("Error when transitioning to Active mode".contains(e .getMessage())); @@ -608,7 +611,8 @@ protected void serviceStart() throws Exception { assertEquals(0, rm.getRMContext().getRMApps().size()); } - @Test(timeout = 9000000) + @Test + @Timeout(value = 9000) public void testTransitionedToActiveRefreshFail() throws Exception { configuration.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false); rm = new MockRM(configuration) { @@ -648,21 +652,21 @@ protected Dispatcher createDispatcher() { ((FailFastDispatcher) rm.rmContext.getDispatcher()); // Verify transition to transitionToStandby rm.adminService.transitionToStandby(requestInfo); - assertEquals("Fatal Event should be 0", 0, dispatcher.getEventCount()); - assertEquals("HA state should be in standBy State", HAServiceState.STANDBY, - rm.getRMContext().getHAServiceState()); + assertEquals(0, dispatcher.getEventCount(), "Fatal Event should be 0"); + assertEquals(HAServiceState.STANDBY +, rm.getRMContext().getHAServiceState(), "HA state should be in standBy State"); try { // Verify refreshAll call failure and check fail Event is dispatched rm.adminService.transitionToActive(requestInfo); - Assert.fail("Transition to Active should have failed for refreshAll()"); + Assertions.fail("Transition to Active should have failed for refreshAll()"); } catch (Exception e) { - assertTrue("Service fail Exception expected", - e instanceof ServiceFailedException); + assertTrue( + e instanceof ServiceFailedException, "Service fail Exception expected"); } // Since refreshAll failed we are expecting fatal event to be send // Then fatal event is send RM will shutdown dispatcher.await(); - assertEquals("Fatal Event to be received", 1, dispatcher.getEventCount()); + assertEquals(1, dispatcher.getEventCount(), "Fatal Event to be received"); // Check of refreshAll success HA can be active rm.adminService.transitionToActive(requestInfo); assertEquals(HAServiceState.ACTIVE, rm.getRMContext().getHAServiceState()); @@ -706,7 +710,7 @@ public Boolean get() { } }, 100, 3000); rm.stop(); - Assert.assertEquals(1, appMaster.getLeastLoadedNodes().size()); + Assertions.assertEquals(1, appMaster.getLeastLoadedNodes().size()); } @@ -744,9 +748,9 @@ public void testResourceProfilesManagerAfterRMWentStandbyThenBackToActive() checkActiveRMFunctionality(); // 5. Check ResourceProfilesManager - Assert.assertNotNull( - "ResourceProfilesManager should not be null!", - rm.getRMContext().getResourceProfilesManager()); + Assertions.assertNotNull( + + rm.getRMContext().getResourceProfilesManager(), "ResourceProfilesManager should not be null!"); } @Test @@ -769,12 +773,12 @@ public void testTransitionedToActiveWithExcludeFileNotExist() throws Exception { if (confFile.exists()) { hasRenamed = confFile.renameTo(backupConfFile); if (!hasRenamed) { - Assert.fail("Can not rename " + confFile.getAbsolutePath() + " to " + Assertions.fail("Can not rename " + confFile.getAbsolutePath() + " to " + backupConfFile.getAbsolutePath()); } } if (!confFile.createNewFile()) { - Assert.fail( + Assertions.fail( "Can not create " + YarnConfiguration.YARN_SITE_CONFIGURATION_FILE); } output = new DataOutputStream(Files.newOutputStream(confFile.toPath())); @@ -867,12 +871,12 @@ public void innerTestHAWithRMHostName(boolean includeBindHost) { rm = new MockRM(conf); rm.init(conf); for (String confKey : YarnConfiguration.getServiceAddressConfKeys(conf)) { - assertEquals("RPC address not set for " + confKey, - RM1_ADDRESS, conf.get(HAUtil.addSuffix(confKey, RM1_NODE_ID))); - assertEquals("RPC address not set for " + confKey, - RM2_ADDRESS, conf.get(HAUtil.addSuffix(confKey, RM2_NODE_ID))); - assertEquals("RPC address not set for " + confKey, - RM3_ADDRESS, conf.get(HAUtil.addSuffix(confKey, RM3_NODE_ID))); + assertEquals( + RM1_ADDRESS, conf.get(HAUtil.addSuffix(confKey, RM1_NODE_ID)), "RPC address not set for " + confKey); + assertEquals( + RM2_ADDRESS, conf.get(HAUtil.addSuffix(confKey, RM2_NODE_ID)), "RPC address not set for " + confKey); + assertEquals( + RM3_ADDRESS, conf.get(HAUtil.addSuffix(confKey, RM3_NODE_ID)), "RPC address not set for " + confKey); if (includeBindHost) { assertEquals("Web address misconfigured WITH bind-host", rm.webAppAddress.substring(0, 7), "9.9.9.9"); @@ -941,11 +945,11 @@ private void verifyClusterMetrics(int activeNodes, int appsSubmitted, Thread.sleep(1000); } } - assertTrue(message, isAllMetricAssertionDone); + assertTrue(isAllMetricAssertionDone, message); } private void assertMetric(String metricName, long expected, long actual) { - assertEquals("Incorrect value for metric " + metricName, expected, actual); + assertEquals(expected, actual, "Incorrect value for metric " + metricName); } @SuppressWarnings("rawtypes") diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAForAsyncScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAForAsyncScheduler.java index 1da9a61d1dcdf..11c3494649125 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAForAsyncScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAForAsyncScheduler.java @@ -32,9 +32,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAsyncScheduling; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.Arrays; import java.util.List; @@ -43,7 +44,7 @@ public class TestRMHAForAsyncScheduler extends RMHATestBase { private TestCapacitySchedulerAsyncScheduling.NMHeartbeatThread nmHeartbeatThread = null; - @Before + @BeforeEach @Override public void setup() throws Exception { super.setup(); @@ -82,7 +83,8 @@ private void pauseNMHeartbeat() { } } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAsyncScheduleThreadStateAfterRMHATransit() throws Exception { // start two RMs, and transit rm1 to active, rm2 to standby startRMs(); @@ -114,9 +116,9 @@ public void testAsyncScheduleThreadStateAfterRMHATransit() throws Exception { HAServiceProtocol.RequestSource.REQUEST_BY_USER); rm2.adminService.transitionToStandby(requestInfo); rm1.adminService.transitionToActive(requestInfo); - Assert.assertTrue(rm2.getRMContext().getHAServiceState() + Assertions.assertTrue(rm2.getRMContext().getHAServiceState() == HAServiceProtocol.HAServiceState.STANDBY); - Assert.assertTrue(rm1.getRMContext().getHAServiceState() + Assertions.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceProtocol.HAServiceState.ACTIVE); // check async schedule threads checkAsyncSchedulerThreads(Thread.currentThread()); @@ -136,7 +138,8 @@ public void testAsyncScheduleThreadStateAfterRMHATransit() throws Exception { rm2.stop(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAsyncScheduleThreadExit() throws Exception { // start two RMs, and transit rm1 to active, rm2 to standby startRMs(); @@ -241,10 +244,10 @@ private void checkAsyncSchedulerThreads(Thread currentThread){ } } } - Assert.assertEquals(1, numResourceCommitterService); - Assert.assertEquals(1, numAsyncScheduleThread); - Assert.assertNotNull(asyncScheduleThread); - Assert.assertNotNull(resourceCommitterService); + Assertions.assertEquals(1, numResourceCommitterService); + Assertions.assertEquals(1, numAsyncScheduleThread); + Assertions.assertNotNull(asyncScheduleThread); + Assertions.assertNotNull(resourceCommitterService); } } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAForNodeLabels.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAForNodeLabels.java index 5d6638ce13515..6afeb6add2e9b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAForNodeLabels.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAForNodeLabels.java @@ -29,9 +29,9 @@ import org.apache.hadoop.yarn.api.records.NodeId; import org.apache.hadoop.yarn.api.records.NodeLabel; import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; @@ -39,7 +39,7 @@ public class TestRMHAForNodeLabels extends RMHATestBase { public static final Logger LOG = LoggerFactory .getLogger(TestRMHAForNodeLabels.class); - @Before + @BeforeEach @Override public void setup() throws Exception { super.setup(); @@ -81,13 +81,13 @@ public void testRMHARecoverNodeLabels() throws Exception { explicitFailover(); // Check labels in rm2 - Assert + Assertions .assertTrue(rm2.getRMContext().getNodeLabelManager() .getClusterNodeLabelNames() .containsAll(ImmutableSet.of("a", "b", "c"))); - Assert.assertTrue(rm2.getRMContext().getNodeLabelManager() + Assertions.assertTrue(rm2.getRMContext().getNodeLabelManager() .getNodeLabels().get(NodeId.newInstance("host1", 0)).contains("a")); - Assert.assertTrue(rm2.getRMContext().getNodeLabelManager() + Assertions.assertTrue(rm2.getRMContext().getNodeLabelManager() .getNodeLabels().get(NodeId.newInstance("host2", 0)).contains("b")); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAMetrics.java index b55cee6213f71..b8a4f78279d5c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHAMetrics.java @@ -23,15 +23,16 @@ import org.apache.hadoop.yarn.conf.HAUtil; import org.apache.hadoop.yarn.conf.YarnConfiguration; 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.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import javax.management.MBeanServer; import javax.management.ObjectName; import java.lang.management.ManagementFactory; -import static junit.framework.TestCase.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Metrics related RM HA testing. Metrics are mostly static singletons. To @@ -47,7 +48,7 @@ public class TestRMHAMetrics { private static final String RM2_ADDRESS = "0.0.0.0:0"; private static final String RM2_NODE_ID = "rm2"; - @Before + @BeforeEach public void setUp() throws Exception { configuration = new Configuration(); UserGroupInformation.setConfiguration(configuration); @@ -65,7 +66,8 @@ public void setUp() throws Exception { DefaultMetricsSystem.shutdown(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testMetricsAfterTransitionToStandby() throws Exception { configuration.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false); Configuration conf = new YarnConfiguration(configuration); @@ -76,20 +78,20 @@ public void testMetricsAfterTransitionToStandby() throws Exception { ObjectName mxbeanName = new ObjectName("Hadoop:service=ResourceManager,name=RMInfo"); - Assert.assertEquals("initializing", + Assertions.assertEquals("initializing", (String) mbs.getAttribute(mxbeanName, "State")); rm.start(); - Assert.assertEquals("standby", + Assertions.assertEquals("standby", (String) mbs.getAttribute(mxbeanName, "State")); rm.transitionToActive(); - Assert + Assertions .assertEquals("active", (String) mbs.getAttribute(mxbeanName, "State")); rm.transitionToStandby(true); - Assert.assertEquals("standby", + Assertions.assertEquals("standby", (String) mbs.getAttribute(mxbeanName, "State")); assertNotNull(DefaultMetricsSystem.instance().getSource("JvmMetrics")); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHATimelineCollectors.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHATimelineCollectors.java index 99bf1822ebb6a..01899e4b6714d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHATimelineCollectors.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMHATimelineCollectors.java @@ -25,8 +25,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineWriterImpl; import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.function.Supplier; @@ -34,7 +34,7 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test if the new active RM could recover collector status on a state @@ -42,7 +42,7 @@ */ public class TestRMHATimelineCollectors extends RMHATestBase { - @Before + @BeforeEach @Override public void setup() throws Exception { super.setup(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java index 3a0288715075e..0b3c1cf8a1570 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager; import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus; -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.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -86,10 +86,11 @@ import org.apache.hadoop.yarn.server.utils.YarnServerBuilderUtils; import org.apache.hadoop.yarn.util.Records; 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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -128,7 +129,7 @@ public void handle(NodesListManagerEvent event) { } - @Before + @BeforeEach public void setUp() throws Exception { InlineDispatcher rmDispatcher = new InlineDispatcher(); @@ -172,7 +173,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable { nodesListManagerEventsNodeStateSequence.clear(); } - @After + @AfterEach public void tearDown() throws Exception { } @@ -264,7 +265,8 @@ private static NMContainerStatus createNMContainerStatus( CommonNodeLabelsManager.NO_LABEL, executionType, -1); } - @Test (timeout = 5000) + @Test + @Timeout(value = 5) public void testExpiredContainer() { NodeStatus mockNodeStatus = createMockNodeStatus(); // Start the node @@ -276,7 +278,7 @@ public void testExpiredContainer() { BuilderUtils.newApplicationAttemptId( BuilderUtils.newApplicationId(0, 0), 0), 0); node.handle(new RMNodeCleanContainerEvent(null, completedContainerId)); - Assert.assertEquals(1, node.getContainersToCleanUp().size()); + Assertions.assertEquals(1, node.getContainersToCleanUp().size()); // Now verify that scheduler isn't notified of an expired container // by checking number of 'completedContainers' it got in the previous event @@ -301,35 +303,36 @@ public void testStatusUpdateOnDecommissioningNode() { int initialActive = cm.getNumActiveNMs(); int initialDecommissioning = cm.getNumDecommissioningNMs(); int initialDecommissioned = cm.getNumDecommisionedNMs(); - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); // Verify node in DECOMMISSIONING won't be changed by status update // with running apps RMNodeStatusEvent statusEvent = getMockRMNodeStatusEventWithRunningApps(); node.handle(statusEvent); - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Decommissioning Nodes", initialDecommissioning, - cm.getNumDecommissioningNMs()); - Assert.assertEquals("Decommissioned Nodes", initialDecommissioned, - cm.getNumDecommisionedNMs()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialDecommissioning +, cm.getNumDecommissioningNMs(), "Decommissioning Nodes"); + Assertions.assertEquals(initialDecommissioned +, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); } @Test public void testRecommissionNode() { RMNodeImpl node = getDecommissioningNode(); - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); ClusterMetrics cm = ClusterMetrics.getMetrics(); int initialActive = cm.getNumActiveNMs(); int initialDecommissioning = cm.getNumDecommissioningNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.RECOMMISSION)); - Assert.assertEquals(NodeState.RUNNING, node.getState()); - Assert - .assertEquals("Active Nodes", initialActive + 1, cm.getNumActiveNMs()); - Assert.assertEquals("Decommissioning Nodes", initialDecommissioning - 1, - cm.getNumDecommissioningNMs()); + Assertions.assertEquals(NodeState.RUNNING, node.getState()); + Assertions + .assertEquals(initialActive + 1, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialDecommissioning - 1 +, cm.getNumDecommissioningNMs(), "Decommissioning Nodes"); } - @Test (timeout = 5000) + @Test + @Timeout(value = 5) public void testContainerUpdate() throws InterruptedException{ NodeStatus mockNodeStatus = createMockNodeStatus(); //Start the node @@ -364,8 +367,8 @@ public void testContainerUpdate() throws InterruptedException{ doReturn(Collections.singletonList(containerStatusFromNode1)) .when(statusEventFromNode1).getContainers(); node.handle(statusEventFromNode1); - Assert.assertEquals(1, completedContainers.size()); - Assert.assertEquals(completedContainerIdFromNode1, + Assertions.assertEquals(1, completedContainers.size()); + Assertions.assertEquals(completedContainerIdFromNode1, completedContainers.get(0).getContainerId()); completedContainers.clear(); @@ -381,10 +384,10 @@ public void testContainerUpdate() throws InterruptedException{ node2.setNextHeartBeat(true); node2.handle(statusEventFromNode2_2); - Assert.assertEquals(2, completedContainers.size()); - Assert.assertEquals(completedContainerIdFromNode2_1,completedContainers.get(0) + Assertions.assertEquals(2, completedContainers.size()); + Assertions.assertEquals(completedContainerIdFromNode2_1,completedContainers.get(0) .getContainerId()); - Assert.assertEquals(completedContainerIdFromNode2_2,completedContainers.get(1) + Assertions.assertEquals(completedContainerIdFromNode2_2,completedContainers.get(1) .getContainerId()); } @@ -443,11 +446,11 @@ public void testAddWithAllocatedContainers() { Arrays.asList(newContainerStatus, runningContainerStatus, newOppContainerStatus, runningOppContainerStatus), null, mockNodeStatus)); - Assert.assertEquals(NodeState.RUNNING, node.getState()); - Assert.assertNotNull(nodesListManagerEvent); - Assert.assertEquals(NodesListManagerEventType.NODE_USABLE, + Assertions.assertEquals(NodeState.RUNNING, node.getState()); + Assertions.assertNotNull(nodesListManagerEvent); + Assertions.assertEquals(NodesListManagerEventType.NODE_USABLE, nodesListManagerEvent.getType()); - Assert.assertEquals(expectedResource, node.getAllocatedContainerResource()); + Assertions.assertEquals(expectedResource, node.getAllocatedContainerResource()); } /** @@ -456,14 +459,15 @@ public void testAddWithAllocatedContainers() { * upon a node update. Resources should be counted for both GUARANTEED * and OPPORTUNISTIC containers. */ - @Test (timeout = 5000) + @Test + @Timeout(value = 5) public void testAllocatedContainerUpdate() { NodeStatus mockNodeStatus = createMockNodeStatus(); //Start the node node.handle(new RMNodeStartedEvent(null, null, null, mockNodeStatus)); // Make sure that the node starts with no allocated resources - Assert.assertEquals(Resources.none(), node.getAllocatedContainerResource()); + Assertions.assertEquals(Resources.none(), node.getAllocatedContainerResource()); ApplicationId app0 = BuilderUtils.newApplicationId(0, 0); final ContainerId newContainerId = BuilderUtils.newContainerId( @@ -495,7 +499,7 @@ public void testAllocatedContainerUpdate() { newContainerStatusFromNode, runningContainerStatusFromNode)); doReturn(containerStatuses).when(statusEventFromNode1).getContainers(); node.handle(statusEventFromNode1); - Assert.assertEquals(Resource.newInstance(300, 3), + Assertions.assertEquals(Resource.newInstance(300, 3), node.getAllocatedContainerResource()); final ContainerId newOppContainerId = BuilderUtils.newContainerId( @@ -524,7 +528,7 @@ public void testAllocatedContainerUpdate() { // The result here should be double the first check, // since allocated resources are doubled, just // with different execution types - Assert.assertEquals(Resource.newInstance(600, 6), + Assertions.assertEquals(Resource.newInstance(600, 6), node.getAllocatedContainerResource()); RMNodeStatusEvent statusEventFromNode3 = getMockRMNodeStatusEvent(null); @@ -548,7 +552,7 @@ public void testAllocatedContainerUpdate() { // Adding completed containers should not have changed // the resources allocated - Assert.assertEquals(Resource.newInstance(600, 6), + Assertions.assertEquals(Resource.newInstance(600, 6), node.getAllocatedContainerResource()); RMNodeStatusEvent emptyStatusEventFromNode = @@ -559,11 +563,12 @@ public void testAllocatedContainerUpdate() { node.handle(emptyStatusEventFromNode); // Passing an empty containers list should yield no resources allocated - Assert.assertEquals(Resources.none(), + Assertions.assertEquals(Resources.none(), node.getAllocatedContainerResource()); } - @Test (timeout = 5000) + @Test + @Timeout(value = 5) public void testStatusChange(){ NodeStatus mockNodeStatus = createMockNodeStatus(); //Start the node @@ -596,9 +601,9 @@ public void testStatusChange(){ node.handle(statusEvent1); node.handle(statusEvent2); verify(scheduler, times(1)).handle(any(NodeAddedSchedulerEvent.class)); - Assert.assertEquals(2, node.getQueueSize()); + Assertions.assertEquals(2, node.getQueueSize()); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.EXPIRE)); - Assert.assertEquals(0, node.getQueueSize()); + Assertions.assertEquals(0, node.getQueueSize()); } @Test @@ -611,15 +616,15 @@ public void testRunningExpire() { int initialDecommissioned = cm.getNumDecommisionedNMs(); int initialRebooted = cm.getNumRebootedNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.EXPIRE)); - Assert.assertEquals("Active Nodes", initialActive - 1, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost + 1, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.LOST, node.getState()); + Assertions.assertEquals(initialActive - 1, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost + 1, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals( + initialDecommissioned, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.LOST, node.getState()); } @Test @@ -633,34 +638,34 @@ public void testRunningExpireMultiple() { int initialDecommissioned = cm.getNumDecommisionedNMs(); int initialRebooted = cm.getNumRebootedNMs(); node1.handle(new RMNodeEvent(node1.getNodeID(), RMNodeEventType.EXPIRE)); - Assert.assertEquals("Active Nodes", initialActive - 1, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost + 1, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", initialUnhealthy, - cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", initialDecommissioned, - cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", initialRebooted, - cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.LOST, node1.getState()); - Assert.assertTrue("Node " + node1.toString() + " should be inactive", - rmContext.getInactiveRMNodes().containsKey(node1.getNodeID())); - Assert.assertFalse("Node " + node2.toString() + " should not be inactive", - rmContext.getInactiveRMNodes().containsKey(node2.getNodeID())); + Assertions.assertEquals(initialActive - 1, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost + 1, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals(initialUnhealthy +, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals(initialDecommissioned +, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals(initialRebooted +, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.LOST, node1.getState()); + Assertions.assertTrue( + rmContext.getInactiveRMNodes().containsKey(node1.getNodeID()), "Node " + node1.toString() + " should be inactive"); + Assertions.assertFalse( + rmContext.getInactiveRMNodes().containsKey(node2.getNodeID()), "Node " + node2.toString() + " should not be inactive"); node2.handle(new RMNodeEvent(node1.getNodeID(), RMNodeEventType.EXPIRE)); - Assert.assertEquals("Active Nodes", initialActive - 2, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost + 2, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", initialUnhealthy, - cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", initialDecommissioned, - cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", initialRebooted, - cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.LOST, node2.getState()); - Assert.assertTrue("Node " + node1.toString() + " should be inactive", - rmContext.getInactiveRMNodes().containsKey(node1.getNodeID())); - Assert.assertTrue("Node " + node2.toString() + " should be inactive", - rmContext.getInactiveRMNodes().containsKey(node2.getNodeID())); + Assertions.assertEquals(initialActive - 2, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost + 2, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals(initialUnhealthy +, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals(initialDecommissioned +, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals(initialRebooted +, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.LOST, node2.getState()); + Assertions.assertTrue( + rmContext.getInactiveRMNodes().containsKey(node1.getNodeID()), "Node " + node1.toString() + " should be inactive"); + Assertions.assertTrue( + rmContext.getInactiveRMNodes().containsKey(node2.getNodeID()), "Node " + node2.toString() + " should be inactive"); } @Test @@ -673,15 +678,15 @@ public void testUnhealthyExpire() { int initialDecommissioned = cm.getNumDecommisionedNMs(); int initialRebooted = cm.getNumRebootedNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.EXPIRE)); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost + 1, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy - 1, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.LOST, node.getState()); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost + 1, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy - 1, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals( + initialDecommissioned, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.LOST, node.getState()); } @Test @@ -690,7 +695,7 @@ public void testUnhealthyExpireForSchedulerRemove() { verify(scheduler, times(1)).handle(any(NodeRemovedSchedulerEvent.class)); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.EXPIRE)); verify(scheduler, times(1)).handle(any(NodeRemovedSchedulerEvent.class)); - Assert.assertEquals(NodeState.LOST, node.getState()); + Assertions.assertEquals(NodeState.LOST, node.getState()); } @Test @@ -704,15 +709,15 @@ public void testRunningDecommission() { int initialRebooted = cm.getNumRebootedNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.DECOMMISSION)); - Assert.assertEquals("Active Nodes", initialActive - 1, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned + 1, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.DECOMMISSIONED, node.getState()); + Assertions.assertEquals(initialActive - 1, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals( + initialDecommissioned + 1, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.DECOMMISSIONED, node.getState()); } @Test @@ -726,17 +731,17 @@ public void testDecommissionOnDecommissioningNode() { int initialRebooted = cm.getNumRebootedNMs(); int initialDecommissioning = cm.getNumDecommissioningNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.DECOMMISSION)); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", initialUnhealthy, - cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioning Nodes", initialDecommissioning - 1, - cm.getNumDecommissioningNMs()); - Assert.assertEquals("Decommissioned Nodes", initialDecommissioned + 1, - cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", initialRebooted, - cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.DECOMMISSIONED, node.getState()); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals(initialUnhealthy +, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals(initialDecommissioning - 1 +, cm.getNumDecommissioningNMs(), "Decommissioning Nodes"); + Assertions.assertEquals(initialDecommissioned + 1 +, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals(initialRebooted +, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.DECOMMISSIONED, node.getState()); } @Test @@ -750,15 +755,15 @@ public void testUnhealthyDecommission() { int initialRebooted = cm.getNumRebootedNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.DECOMMISSION)); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy - 1, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned + 1, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.DECOMMISSIONED, node.getState()); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy - 1, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals( + initialDecommissioned + 1, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.DECOMMISSIONED, node.getState()); } // Test Decommissioning on a unhealthy node will make it decommissioning. @@ -774,18 +779,18 @@ public void testUnhealthyDecommissioning() { int initialRebooted = cm.getNumRebootedNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.GRACEFUL_DECOMMISSION)); - Assert.assertEquals("Active Nodes", initialActive, - cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy - 1, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", initialDecommissioned, - cm.getNumDecommisionedNMs()); - Assert.assertEquals("Decommissioning Nodes", initialDecommissioning + 1, - cm.getNumDecommissioningNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertEquals(initialActive +, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy - 1, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals(initialDecommissioned +, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals(initialDecommissioning + 1 +, cm.getNumDecommissioningNMs(), "Decommissioning Nodes"); + Assertions.assertEquals( + initialRebooted, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); } @Test @@ -799,15 +804,15 @@ public void testRunningRebooting() { int initialRebooted = cm.getNumRebootedNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.REBOOTING)); - Assert.assertEquals("Active Nodes", initialActive - 1, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted + 1, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.REBOOTED, node.getState()); + Assertions.assertEquals(initialActive - 1, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals( + initialDecommissioned, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted + 1, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.REBOOTED, node.getState()); } @Test @@ -821,15 +826,15 @@ public void testUnhealthyRebooting() { int initialRebooted = cm.getNumRebootedNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.REBOOTING)); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy - 1, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted + 1, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.REBOOTED, node.getState()); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy - 1, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals( + initialDecommissioned, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted + 1, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.REBOOTED, node.getState()); } @Test @@ -848,32 +853,33 @@ public void testAddUnhealthyNode() { node.handle(new RMNodeStartedEvent(node.getNodeID(), null, null, nodeStatus)); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy + 1, cm.getUnhealthyNMs()); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.UNHEALTHY, node.getState()); + Assertions.assertEquals( + initialUnhealthy + 1, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialDecommissioned, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.UNHEALTHY, node.getState()); } @Test public void testNMShutdown() { RMNodeImpl node = getRunningNode(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.SHUTDOWN)); - Assert.assertEquals(NodeState.SHUTDOWN, node.getState()); + Assertions.assertEquals(NodeState.SHUTDOWN, node.getState()); } @Test public void testUnhealthyNMShutdown() { RMNodeImpl node = getUnhealthyNode(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.SHUTDOWN)); - Assert.assertEquals(NodeState.SHUTDOWN, node.getState()); + Assertions.assertEquals(NodeState.SHUTDOWN, node.getState()); } - @Test(timeout=20000) + @Test + @Timeout(value = 20) public void testUpdateHeartbeatResponseForCleanup() { RMNodeImpl node = getRunningNode(); NodeId nodeId = node.getNodeID(); @@ -883,30 +889,31 @@ public void testUpdateHeartbeatResponseForCleanup() { BuilderUtils.newApplicationAttemptId( BuilderUtils.newApplicationId(0, 0), 0), 0); node.handle(new RMNodeCleanContainerEvent(nodeId, completedContainerId)); - Assert.assertEquals(1, node.getContainersToCleanUp().size()); + Assertions.assertEquals(1, node.getContainersToCleanUp().size()); // Finish an application ApplicationId finishedAppId = BuilderUtils.newApplicationId(0, 1); node.handle(new RMNodeCleanAppEvent(nodeId, finishedAppId)); - Assert.assertEquals(1, node.getAppsToCleanup().size()); + Assertions.assertEquals(1, node.getAppsToCleanup().size()); // Verify status update does not clear containers/apps to cleanup // but updating heartbeat response for cleanup does RMNodeStatusEvent statusEvent = getMockRMNodeStatusEvent(null); node.handle(statusEvent); - Assert.assertEquals(1, node.getContainersToCleanUp().size()); - Assert.assertEquals(1, node.getAppsToCleanup().size()); + Assertions.assertEquals(1, node.getContainersToCleanUp().size()); + Assertions.assertEquals(1, node.getAppsToCleanup().size()); NodeHeartbeatResponse hbrsp = Records.newRecord(NodeHeartbeatResponse.class); node.setAndUpdateNodeHeartbeatResponse(hbrsp); - Assert.assertEquals(0, node.getContainersToCleanUp().size()); - Assert.assertEquals(0, node.getAppsToCleanup().size()); - Assert.assertEquals(1, hbrsp.getContainersToCleanup().size()); - Assert.assertEquals(completedContainerId, hbrsp.getContainersToCleanup().get(0)); - Assert.assertEquals(1, hbrsp.getApplicationsToCleanup().size()); - Assert.assertEquals(finishedAppId, hbrsp.getApplicationsToCleanup().get(0)); + Assertions.assertEquals(0, node.getContainersToCleanUp().size()); + Assertions.assertEquals(0, node.getAppsToCleanup().size()); + Assertions.assertEquals(1, hbrsp.getContainersToCleanup().size()); + Assertions.assertEquals(completedContainerId, hbrsp.getContainersToCleanup().get(0)); + Assertions.assertEquals(1, hbrsp.getApplicationsToCleanup().size()); + Assertions.assertEquals(finishedAppId, hbrsp.getApplicationsToCleanup().get(0)); } - @Test(timeout=20000) + @Test + @Timeout(value = 20) public void testUpdateHeartbeatResponseForAppLifeCycle() { RMNodeImpl node = getRunningNode(); NodeId nodeId = node.getNodeID(); @@ -928,13 +935,13 @@ public void testUpdateHeartbeatResponseForAppLifeCycle() { nodeHealth, null, null, null); node.handle(new RMNodeStatusEvent(nodeId, nodeStatus, null)); - Assert.assertEquals(1, node.getRunningApps().size()); + Assertions.assertEquals(1, node.getRunningApps().size()); // Finish an application ApplicationId finishedAppId = runningAppId; node.handle(new RMNodeCleanAppEvent(nodeId, finishedAppId)); - Assert.assertEquals(1, node.getAppsToCleanup().size()); - Assert.assertEquals(0, node.getRunningApps().size()); + Assertions.assertEquals(1, node.getAppsToCleanup().size()); + Assertions.assertEquals(0, node.getRunningApps().size()); } @Test @@ -946,9 +953,9 @@ public void testUnknownNodeId() { rmContext.getInactiveRMNodes().putIfAbsent(nodeId,node); node.handle( new RMNodeEvent(node.getNodeID(), RMNodeEventType.DECOMMISSION)); - Assert.assertNull( - "Must be null as there is no NODE_UNUSABLE update", - nodesListManagerEvent); + Assertions.assertNull( + + nodesListManagerEvent, "Must be null as there is no NODE_UNUSABLE update"); } private RMNodeImpl getRunningNode() { @@ -967,7 +974,7 @@ private RMNodeImpl getRunningNode(String nmVersion, int port) { NodeStatus mockNodeStatus = createMockNodeStatus(); node.handle(new RMNodeStartedEvent(node.getNodeID(), null, null, mockNodeStatus)); - Assert.assertEquals(NodeState.RUNNING, node.getState()); + Assertions.assertEquals(NodeState.RUNNING, node.getState()); return node; } @@ -978,13 +985,13 @@ private RMNodeImpl getDecommissioningNode() { int initialDecommissioning = cm.getNumDecommissioningNMs(); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.GRACEFUL_DECOMMISSION)); - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); - Assert.assertEquals(Arrays.asList(NodeState.NEW, NodeState.RUNNING), + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertEquals(Arrays.asList(NodeState.NEW, NodeState.RUNNING), nodesListManagerEventsNodeStateSequence); - Assert - .assertEquals("Active Nodes", initialActive - 1, cm.getNumActiveNMs()); - Assert.assertEquals("Decommissioning Nodes", initialDecommissioning + 1, - cm.getNumDecommissioningNMs()); + Assertions + .assertEquals(initialActive - 1, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialDecommissioning + 1 +, cm.getNumDecommissioningNMs(), "Decommissioning Nodes"); return node; } @@ -995,7 +1002,7 @@ private RMNodeImpl getUnhealthyNode() { NodeStatus nodeStatus = NodeStatus.newInstance(node.getNodeID(), 0, new ArrayList(), null, status, null, null, null); node.handle(new RMNodeStatusEvent(node.getNodeID(), nodeStatus, null)); - Assert.assertEquals(NodeState.UNHEALTHY, node.getState()); + Assertions.assertEquals(NodeState.UNHEALTHY, node.getState()); return node; } @@ -1021,9 +1028,9 @@ private RMNodeImpl getRebootedNode() { node.handle(new RMNodeStartedEvent(node.getNodeID(), null, null, mockNodeStatus)); - Assert.assertEquals(NodeState.RUNNING, node.getState()); + Assertions.assertEquals(NodeState.RUNNING, node.getState()); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.REBOOTING)); - Assert.assertEquals(NodeState.REBOOTED, node.getState()); + Assertions.assertEquals(NodeState.REBOOTED, node.getState()); return node; } @@ -1039,17 +1046,17 @@ public void testAdd() { NodeStatus mockNodeStatus = createMockNodeStatus(); node.handle(new RMNodeStartedEvent(node.getNodeID(), null, null, mockNodeStatus)); - Assert.assertEquals("Active Nodes", initialActive + 1, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.RUNNING, node.getState()); - Assert.assertNotNull(nodesListManagerEvent); - Assert.assertEquals(NodesListManagerEventType.NODE_USABLE, + Assertions.assertEquals(initialActive + 1, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals( + initialDecommissioned, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.RUNNING, node.getState()); + Assertions.assertNotNull(nodesListManagerEvent); + Assertions.assertEquals(NodesListManagerEventType.NODE_USABLE, nodesListManagerEvent.getType()); } @@ -1063,17 +1070,17 @@ public void testReconnect() { int initialDecommissioned = cm.getNumDecommisionedNMs(); int initialRebooted = cm.getNumRebootedNMs(); node.handle(new RMNodeReconnectEvent(node.getNodeID(), node, null, null)); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Lost Nodes", initialLost, cm.getNumLostNMs()); - Assert.assertEquals("Unhealthy Nodes", - initialUnhealthy, cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioned Nodes", - initialDecommissioned, cm.getNumDecommisionedNMs()); - Assert.assertEquals("Rebooted Nodes", - initialRebooted, cm.getNumRebootedNMs()); - Assert.assertEquals(NodeState.RUNNING, node.getState()); - Assert.assertNotNull(nodesListManagerEvent); - Assert.assertEquals(NodesListManagerEventType.NODE_USABLE, + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialLost, cm.getNumLostNMs(), "Lost Nodes"); + Assertions.assertEquals( + initialUnhealthy, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals( + initialDecommissioned, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); + Assertions.assertEquals( + initialRebooted, cm.getNumRebootedNMs(), "Rebooted Nodes"); + Assertions.assertEquals(NodeState.RUNNING, node.getState()); + Assertions.assertNotNull(nodesListManagerEvent); + Assertions.assertEquals(NodesListManagerEventType.NODE_USABLE, nodesListManagerEvent.getType()); } @@ -1089,21 +1096,21 @@ public void testReconnectOnDecommissioningNode() { node.handle(new RMNodeReconnectEvent(node.getNodeID(), node, getAppIdList(), null)); // still decommissioning - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Decommissioning Nodes", initialDecommissioning, - cm.getNumDecommissioningNMs()); - Assert.assertEquals("Decommissioned Nodes", initialDecommissioned, - cm.getNumDecommisionedNMs()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialDecommissioning +, cm.getNumDecommissioningNMs(), "Decommissioning Nodes"); + Assertions.assertEquals(initialDecommissioned +, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); // Reconnect event without any running app node.handle(new RMNodeReconnectEvent(node.getNodeID(), node, null, null)); - Assert.assertEquals(NodeState.DECOMMISSIONED, node.getState()); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Decommissioning Nodes", initialDecommissioning - 1, - cm.getNumDecommissioningNMs()); - Assert.assertEquals("Decommissioned Nodes", initialDecommissioned + 1, - cm.getNumDecommisionedNMs()); + Assertions.assertEquals(NodeState.DECOMMISSIONED, node.getState()); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialDecommissioning - 1 +, cm.getNumDecommissioningNMs(), "Decommissioning Nodes"); + Assertions.assertEquals(initialDecommissioned + 1 +, cm.getNumDecommisionedNMs(), "Decommissioned Nodes"); } @Test @@ -1115,30 +1122,30 @@ public void testReconnectWithNewPortOnDecommissioningNode() { node.handle(new RMNodeReconnectEvent(node.getNodeID(), node, getAppIdList(), null)); // still decommissioning - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); node.setHttpPort(r.nextInt(10000)); // Reconnect event without any running app node.handle(new RMNodeReconnectEvent(node.getNodeID(), node, null, null)); - Assert.assertEquals(NodeState.DECOMMISSIONED, node.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONED, node.getState()); } @Test public void testResourceUpdateOnRunningNode() { RMNodeImpl node = getRunningNode(); Resource oldCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", oldCapacity.getMemorySize(), 4096); - assertEquals("CPU resource is not match.", oldCapacity.getVirtualCores(), 4); + assertEquals(oldCapacity.getMemorySize(), 4096, "Memory resource is not match."); + assertEquals(oldCapacity.getVirtualCores(), 4, "CPU resource is not match."); node.handle(new RMNodeResourceUpdateEvent(node.getNodeID(), ResourceOption.newInstance(Resource.newInstance(2048, 2), ResourceOption.OVER_COMMIT_TIMEOUT_MILLIS_DEFAULT))); Resource newCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", newCapacity.getMemorySize(), 2048); - assertEquals("CPU resource is not match.", newCapacity.getVirtualCores(), 2); + assertEquals(newCapacity.getMemorySize(), 2048, "Memory resource is not match."); + assertEquals(newCapacity.getVirtualCores(), 2, "CPU resource is not match."); - Assert.assertEquals(NodeState.RUNNING, node.getState()); - Assert.assertNotNull(nodesListManagerEvent); - Assert.assertEquals(NodesListManagerEventType.NODE_USABLE, + Assertions.assertEquals(NodeState.RUNNING, node.getState()); + Assertions.assertNotNull(nodesListManagerEvent); + Assertions.assertEquals(NodesListManagerEventType.NODE_USABLE, nodesListManagerEvent.getType()); } @@ -1151,16 +1158,16 @@ public void testDecommissioningOnRunningNode(){ public void testResourceUpdateOnNewNode() { RMNodeImpl node = getNewNode(Resource.newInstance(4096, 4)); Resource oldCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", oldCapacity.getMemorySize(), 4096); - assertEquals("CPU resource is not match.", oldCapacity.getVirtualCores(), 4); + assertEquals(oldCapacity.getMemorySize(), 4096, "Memory resource is not match."); + assertEquals(oldCapacity.getVirtualCores(), 4, "CPU resource is not match."); node.handle(new RMNodeResourceUpdateEvent(node.getNodeID(), ResourceOption.newInstance(Resource.newInstance(2048, 2), ResourceOption.OVER_COMMIT_TIMEOUT_MILLIS_DEFAULT))); Resource newCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", newCapacity.getMemorySize(), 2048); - assertEquals("CPU resource is not match.", newCapacity.getVirtualCores(), 2); + assertEquals(newCapacity.getMemorySize(), 2048, "Memory resource is not match."); + assertEquals(newCapacity.getVirtualCores(), 2, "CPU resource is not match."); - Assert.assertEquals(NodeState.NEW, node.getState()); + Assertions.assertEquals(NodeState.NEW, node.getState()); } @Test @@ -1171,21 +1178,21 @@ public void testResourceUpdateOnRebootedNode() { int initialUnHealthy = cm.getUnhealthyNMs(); int initialDecommissioning = cm.getNumDecommissioningNMs(); Resource oldCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", oldCapacity.getMemorySize(), 4096); - assertEquals("CPU resource is not match.", oldCapacity.getVirtualCores(), 4); + assertEquals(oldCapacity.getMemorySize(), 4096, "Memory resource is not match."); + assertEquals(oldCapacity.getVirtualCores(), 4, "CPU resource is not match."); node.handle(new RMNodeResourceUpdateEvent(node.getNodeID(), ResourceOption .newInstance(Resource.newInstance(2048, 2), ResourceOption.OVER_COMMIT_TIMEOUT_MILLIS_DEFAULT))); Resource newCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", newCapacity.getMemorySize(), 2048); - assertEquals("CPU resource is not match.", newCapacity.getVirtualCores(), 2); - - Assert.assertEquals(NodeState.REBOOTED, node.getState()); - Assert.assertEquals("Active Nodes", initialActive, cm.getNumActiveNMs()); - Assert.assertEquals("Unhealthy Nodes", initialUnHealthy, - cm.getUnhealthyNMs()); - Assert.assertEquals("Decommissioning Nodes", initialDecommissioning, - cm.getNumDecommissioningNMs()); + assertEquals(newCapacity.getMemorySize(), 2048, "Memory resource is not match."); + assertEquals(newCapacity.getVirtualCores(), 2, "CPU resource is not match."); + + Assertions.assertEquals(NodeState.REBOOTED, node.getState()); + Assertions.assertEquals(initialActive, cm.getNumActiveNMs(), "Active Nodes"); + Assertions.assertEquals(initialUnHealthy +, cm.getUnhealthyNMs(), "Unhealthy Nodes"); + Assertions.assertEquals(initialDecommissioning +, cm.getNumDecommissioningNMs(), "Decommissioning Nodes"); } // Test unhealthy report on a decommissioning node will make it @@ -1201,10 +1208,10 @@ public void testDecommissioningUnhealthy() { NodeStatus nodeStatus = NodeStatus.newInstance(node.getNodeID(), 0, null, keepAliveApps, status, null, null, null); node.handle(new RMNodeStatusEvent(node.getNodeID(), nodeStatus, null)); - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); nodeStatus.setKeepAliveApplications(null); node.handle(new RMNodeStatusEvent(node.getNodeID(), nodeStatus, null)); - Assert.assertEquals(NodeState.DECOMMISSIONED, node.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONED, node.getState()); } @Test @@ -1212,11 +1219,11 @@ public void testReconnnectUpdate() { final String nmVersion1 = "nm version 1"; final String nmVersion2 = "nm version 2"; RMNodeImpl node = getRunningNode(nmVersion1); - Assert.assertEquals(nmVersion1, node.getNodeManagerVersion()); + Assertions.assertEquals(nmVersion1, node.getNodeManagerVersion()); RMNodeImpl reconnectingNode = getRunningNode(nmVersion2); node.handle(new RMNodeReconnectEvent(node.getNodeID(), reconnectingNode, null, null)); - Assert.assertEquals(nmVersion2, node.getNodeManagerVersion()); + Assertions.assertEquals(nmVersion2, node.getNodeManagerVersion()); } @Test @@ -1259,21 +1266,21 @@ public void testContainerExpire() throws Exception { public void testResourceUpdateOnDecommissioningNode() { RMNodeImpl node = getDecommissioningNode(); Resource oldCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", oldCapacity.getMemorySize(), 4096); - assertEquals("CPU resource is not match.", oldCapacity.getVirtualCores(), 4); + assertEquals(oldCapacity.getMemorySize(), 4096, "Memory resource is not match."); + assertEquals(oldCapacity.getVirtualCores(), 4, "CPU resource is not match."); node.handle(new RMNodeResourceUpdateEvent(node.getNodeID(), ResourceOption.newInstance(Resource.newInstance(2048, 2), ResourceOption.OVER_COMMIT_TIMEOUT_MILLIS_DEFAULT))); Resource originalCapacity = node.getOriginalTotalCapability(); - assertEquals("Memory resource is not match.", originalCapacity.getMemorySize(), oldCapacity.getMemorySize()); - assertEquals("CPU resource is not match.", originalCapacity.getVirtualCores(), oldCapacity.getVirtualCores()); + assertEquals(originalCapacity.getMemorySize(), oldCapacity.getMemorySize(), "Memory resource is not match."); + assertEquals(originalCapacity.getVirtualCores(), oldCapacity.getVirtualCores(), "CPU resource is not match."); Resource newCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", newCapacity.getMemorySize(), 2048); - assertEquals("CPU resource is not match.", newCapacity.getVirtualCores(), 2); + assertEquals(newCapacity.getMemorySize(), 2048, "Memory resource is not match."); + assertEquals(newCapacity.getVirtualCores(), 2, "CPU resource is not match."); - Assert.assertEquals(NodeState.DECOMMISSIONING, node.getState()); - Assert.assertNotNull(nodesListManagerEvent); - Assert.assertEquals(NodesListManagerEventType.NODE_DECOMMISSIONING, + Assertions.assertEquals(NodeState.DECOMMISSIONING, node.getState()); + Assertions.assertNotNull(nodesListManagerEvent); + Assertions.assertEquals(NodesListManagerEventType.NODE_DECOMMISSIONING, nodesListManagerEvent.getType()); } @@ -1281,15 +1288,15 @@ public void testResourceUpdateOnDecommissioningNode() { public void testResourceUpdateOnRecommissioningNode() { RMNodeImpl node = getDecommissioningNode(); Resource oldCapacity = node.getTotalCapability(); - assertEquals("Memory resource is not match.", oldCapacity.getMemorySize(), 4096); - assertEquals("CPU resource is not match.", oldCapacity.getVirtualCores(), 4); - assertFalse("updatedCapability should be false.", - node.isUpdatedCapability()); + assertEquals(oldCapacity.getMemorySize(), 4096, "Memory resource is not match."); + assertEquals(oldCapacity.getVirtualCores(), 4, "CPU resource is not match."); + assertFalse( + node.isUpdatedCapability(), "updatedCapability should be false."); node.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.RECOMMISSION)); Resource originalCapacity = node.getOriginalTotalCapability(); - assertEquals("Original total capability not null after recommission", null, originalCapacity); - assertTrue("updatedCapability should be set.", node.isUpdatedCapability()); + assertEquals(null, originalCapacity, "Original total capability not null after recommission"); + assertTrue(node.isUpdatedCapability(), "updatedCapability should be set."); } @Test @@ -1308,41 +1315,41 @@ public void testDisappearingContainer() { ContainerState.RUNNING, "", -1)); node = getRunningNode(); node.handle(getMockRMNodeStatusEvent(containerStats)); - assertEquals("unexpected number of running containers", - 2, node.getLaunchedContainers().size()); - Assert.assertTrue("first container not running", - node.getLaunchedContainers().contains(cid1)); - Assert.assertTrue("second container not running", - node.getLaunchedContainers().contains(cid2)); - assertEquals("unexpected number of running containers", - 2, node.getUpdatedExistContainers().size()); - Assert.assertTrue("first container not running", - node.getUpdatedExistContainers().containsKey(cid1)); - Assert.assertTrue("second container not running", - node.getUpdatedExistContainers().containsKey(cid2)); - assertEquals("already completed containers", - 0, completedContainers.size()); + assertEquals( + 2, node.getLaunchedContainers().size(), "unexpected number of running containers"); + Assertions.assertTrue( + node.getLaunchedContainers().contains(cid1), "first container not running"); + Assertions.assertTrue( + node.getLaunchedContainers().contains(cid2), "second container not running"); + assertEquals( + 2, node.getUpdatedExistContainers().size(), "unexpected number of running containers"); + Assertions.assertTrue( + node.getUpdatedExistContainers().containsKey(cid1), "first container not running"); + Assertions.assertTrue( + node.getUpdatedExistContainers().containsKey(cid2), "second container not running"); + assertEquals( + 0, completedContainers.size(), "already completed containers"); containerStats.remove(0); node.handle(getMockRMNodeStatusEvent(containerStats)); - assertEquals("expected one container to be completed", - 1, completedContainers.size()); + assertEquals( + 1, completedContainers.size(), "expected one container to be completed"); ContainerStatus cs = completedContainers.get(0); - assertEquals("first container not the one that completed", - cid1, cs.getContainerId()); - assertEquals("completed container not marked complete", - ContainerState.COMPLETE, cs.getState()); - assertEquals("completed container not marked aborted", - ContainerExitStatus.ABORTED, cs.getExitStatus()); - Assert.assertTrue("completed container not marked missing", - cs.getDiagnostics().contains("not reported")); - assertEquals("unexpected number of running containers", - 1, node.getLaunchedContainers().size()); - Assert.assertTrue("second container not running", - node.getLaunchedContainers().contains(cid2)); - assertEquals("unexpected number of running containers", - 1, node.getUpdatedExistContainers().size()); - Assert.assertTrue("second container not running", - node.getUpdatedExistContainers().containsKey(cid2)); + assertEquals( + cid1, cs.getContainerId(), "first container not the one that completed"); + assertEquals( + ContainerState.COMPLETE, cs.getState(), "completed container not marked complete"); + assertEquals( + ContainerExitStatus.ABORTED, cs.getExitStatus(), "completed container not marked aborted"); + Assertions.assertTrue( + cs.getDiagnostics().contains("not reported"), "completed container not marked missing"); + assertEquals( + 1, node.getLaunchedContainers().size(), "unexpected number of running containers"); + Assertions.assertTrue( + node.getLaunchedContainers().contains(cid2), "second container not running"); + assertEquals( + 1, node.getUpdatedExistContainers().size(), "unexpected number of running containers"); + Assertions.assertTrue( + node.getUpdatedExistContainers().containsKey(cid2), "second container not running"); } @Test @@ -1367,12 +1374,12 @@ public void testForHandlingDuplicatedCompltedContainers() { verify(scheduler, times(1)).handle(any(NodeAddedSchedulerEvent.class)); node.handle(statusEvent1); verify(scheduler, times(1)).handle(any(NodeAddedSchedulerEvent.class)); - Assert.assertEquals(1, node.getQueueSize()); - Assert.assertEquals(1, node.getCompletedContainers().size()); + Assertions.assertEquals(1, node.getQueueSize()); + Assertions.assertEquals(1, node.getCompletedContainers().size()); // test for duplicate entries node.handle(statusEvent1); - Assert.assertEquals(1, node.getQueueSize()); + Assertions.assertEquals(1, node.getQueueSize()); // send clean up container event node.handle(new RMNodeFinishedContainersPulledByAMEvent(node.getNodeID(), @@ -1382,8 +1389,8 @@ public void testForHandlingDuplicatedCompltedContainers() { Records.newRecord(NodeHeartbeatResponse.class); node.setAndUpdateNodeHeartbeatResponse(hbrsp); - Assert.assertEquals(1, hbrsp.getContainersToBeRemovedFromNM().size()); - Assert.assertEquals(0, node.getCompletedContainers().size()); + Assertions.assertEquals(1, hbrsp.getContainersToBeRemovedFromNM().size()); + Assertions.assertEquals(0, node.getCompletedContainers().size()); } @Test @@ -1393,7 +1400,7 @@ public void testFinishedContainersPulledByAMOnNewNode() { rmNode.handle(new RMNodeFinishedContainersPulledByAMEvent(nodeId, getContainerIdList())); - Assert.assertEquals(1, rmNode.getContainersToBeRemovedFromNM().size()); + Assertions.assertEquals(1, rmNode.getContainersToBeRemovedFromNM().size()); } @@ -1404,7 +1411,7 @@ private void calcIntervalTest(RMNodeImpl rmNode, ResourceUtilization nodeUtil, rmNode.setNodeUtilization(nodeUtil); long hbInterval = rmNode.calculateHeartBeatInterval(hbDefault, hbMin, hbMax, speedup, slowdown); - assertEquals("heartbeat interval incorrect", expectedHb, hbInterval); + assertEquals(expectedHb, hbInterval, "heartbeat interval incorrect"); } @Test @@ -1510,7 +1517,7 @@ public void testFinishedContainersPulledByAmOnDecommissioningNode() { RMNodeImpl rMNodeImpl = getRunningNode(); rMNodeImpl.handle( new RMNodeEvent(rMNodeImpl.getNodeID(), RMNodeEventType.GRACEFUL_DECOMMISSION)); - Assert.assertEquals(NodeState.DECOMMISSIONING, rMNodeImpl.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, rMNodeImpl.getState()); ContainerId containerId = BuilderUtils.newContainerId( BuilderUtils.newApplicationAttemptId(BuilderUtils.newApplicationId(0, 0), 0), 0); @@ -1518,13 +1525,13 @@ public void testFinishedContainersPulledByAmOnDecommissioningNode() { rMNodeImpl.handle( new RMNodeFinishedContainersPulledByAMEvent(rMNodeImpl.getNodeID(), containerIds)); - Assert.assertEquals(NodeState.DECOMMISSIONING, rMNodeImpl.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, rMNodeImpl.getState()); // Verify expected containersToBeRemovedFromNM from NodeHeartbeatResponse. NodeHeartbeatResponse response = YarnServerBuilderUtils.newNodeHeartbeatResponse(1, NodeAction.NORMAL, null, null, null, null, 1000); rMNodeImpl.setAndUpdateNodeHeartbeatResponse(response); - Assert.assertEquals(1, response.getContainersToBeRemovedFromNM().size()); + Assertions.assertEquals(1, response.getContainersToBeRemovedFromNM().size()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMProxyUsersConf.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMProxyUsersConf.java index 2b67a31d59120..0155ab39586c8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMProxyUsersConf.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMProxyUsersConf.java @@ -27,8 +27,8 @@ import org.apache.hadoop.security.authorize.ProxyUsers; import org.apache.hadoop.yarn.conf.YarnConfiguration; import static org.apache.hadoop.yarn.conf.YarnConfiguration.RM_PROXY_USER_PREFIX; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -94,7 +94,7 @@ public void testProxyUserConfiguration() throws Exception { ipAddress); } catch (AuthorizationException e) { // Exception is not expected - Assert.fail(); + Assertions.fail(); } } finally { if (rm != null) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java index c5c15e2f3dbae..7421c834f007f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMRestart.java @@ -126,10 +126,11 @@ import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.ConverterUtils; -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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.mockito.Mockito; import java.util.function.Supplier; @@ -154,7 +155,7 @@ public TestRMRestart(SchedulerType type) throws IOException { super(type); } - @Before + @BeforeEach public void setup() throws IOException { conf = getConf(); GenericTestUtils.setRootLogLevel(Level.DEBUG); @@ -165,10 +166,10 @@ public void setup() throws IOException { conf.setClass(YarnConfiguration.TIMELINE_SERVICE_WRITER_CLASS, FileSystemTimelineWriterImpl.class, TimelineWriter.class); rmAddr = new InetSocketAddress("localhost", 8032); - Assert.assertTrue(YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS > 1); + Assertions.assertTrue(YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS > 1); } - @After + @AfterEach public void tearDown() { for (MockRM rm : rms) { rm.stop(); @@ -225,7 +226,8 @@ private RMApp submitApp(MockRM rm, List amResourceRequests, return MockRMAppSubmitter.submit(rm, data); } - @Test (timeout=180000) + @Test + @Timeout(value = 180) public void testRMRestart() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS); @@ -251,7 +253,7 @@ public void testRMRestart() throws Exception { RMApp app0 = MockRMAppSubmitter.submitWithMemory(200, rm1); RMAppAttempt attempt0 = app0.getCurrentAppAttempt(); // spot check that app is saved - Assert.assertEquals(1, rmAppState.size()); + Assertions.assertEquals(1, rmAppState.size()); nm1.nodeHeartbeat(true); MockAM am0 = rm1.sendAMLaunched(attempt0.getAppAttemptId()); am0.registerAppAttempt(); @@ -261,9 +263,9 @@ public void testRMRestart() throws Exception { RMApp app1 = MockRMAppSubmitter.submitWithMemory(200, rm1); // assert app1 info is saved ApplicationStateData appState = rmAppState.get(app1.getApplicationId()); - Assert.assertNotNull(appState); - Assert.assertEquals(0, appState.getAttemptCount()); - Assert.assertEquals(appState.getApplicationSubmissionContext() + Assertions.assertNotNull(appState); + Assertions.assertEquals(0, appState.getAttemptCount()); + Assertions.assertEquals(appState.getApplicationSubmissionContext() .getApplicationId(), app1.getApplicationSubmissionContext() .getApplicationId()); @@ -274,11 +276,11 @@ public void testRMRestart() throws Exception { RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); ApplicationAttemptId attemptId1 = attempt1.getAppAttemptId(); rm1.waitForState(attemptId1, RMAppAttemptState.ALLOCATED); - Assert.assertEquals(1, appState.getAttemptCount()); + Assertions.assertEquals(1, appState.getAttemptCount()); ApplicationAttemptStateData attemptState = appState.getAttempt(attemptId1); - Assert.assertNotNull(attemptState); - Assert.assertEquals(BuilderUtils.newContainerId(attemptId1, 1), + Assertions.assertNotNull(attemptState); + Assertions.assertEquals(BuilderUtils.newContainerId(attemptId1, 1), attemptState.getMasterContainer().getId()); // launch the AM @@ -303,9 +305,9 @@ public void testRMRestart() throws Exception { // assert app2 info is saved appState = rmAppState.get(app2.getApplicationId()); - Assert.assertNotNull(appState); - Assert.assertEquals(0, appState.getAttemptCount()); - Assert.assertEquals(appState.getApplicationSubmissionContext() + Assertions.assertNotNull(appState); + Assertions.assertEquals(0, appState.getAttemptCount()); + Assertions.assertEquals(appState.getApplicationSubmissionContext() .getApplicationId(), app2.getApplicationSubmissionContext() .getApplicationId()); @@ -327,13 +329,13 @@ public void testRMRestart() throws Exception { // assert appUnmanaged info is saved ApplicationId unmanagedAppId = appUnmanaged.getApplicationId(); appState = rmAppState.get(unmanagedAppId); - Assert.assertNotNull(appState); + Assertions.assertNotNull(appState); // wait for attempt to reach LAUNCHED state rm1.waitForState(unmanagedAttemptId, RMAppAttemptState.LAUNCHED); rm1.waitForState(unmanagedAppId, RMAppState.ACCEPTED); // assert unmanaged attempt info is saved - Assert.assertEquals(1, appState.getAttemptCount()); - Assert.assertEquals(appState.getApplicationSubmissionContext() + Assertions.assertEquals(1, appState.getAttemptCount()); + Assertions.assertEquals(appState.getApplicationSubmissionContext() .getApplicationId(), appUnmanaged.getApplicationSubmissionContext() .getApplicationId()); @@ -355,7 +357,7 @@ public void testRMRestart() throws Exception { // Unmanaged app state is still loaded back but it cannot be restarted by // the RM. this will change with work preserving RM restart in which AMs/NMs // are not rebooted. - Assert.assertEquals(4, rm2.getRMContext().getRMApps().size()); + Assertions.assertEquals(4, rm2.getRMContext().getRMApps().size()); // check that earlier finished app and attempt is also loaded back and move // to finished state. rm2.waitForState(app0.getApplicationId(), RMAppState.FINISHED); @@ -363,16 +365,16 @@ public void testRMRestart() throws Exception { // verify correct number of attempts and other data RMApp loadedApp1 = rm2.getRMContext().getRMApps().get(app1.getApplicationId()); - Assert.assertNotNull(loadedApp1); - Assert.assertEquals(1, loadedApp1.getAppAttempts().size()); - Assert.assertEquals(app1.getApplicationSubmissionContext() + Assertions.assertNotNull(loadedApp1); + Assertions.assertEquals(1, loadedApp1.getAppAttempts().size()); + Assertions.assertEquals(app1.getApplicationSubmissionContext() .getApplicationId(), loadedApp1.getApplicationSubmissionContext() .getApplicationId()); RMApp loadedApp2 = rm2.getRMContext().getRMApps().get(app2.getApplicationId()); - Assert.assertNotNull(loadedApp2); - //Assert.assertEquals(0, loadedApp2.getAppAttempts().size()); - Assert.assertEquals(app2.getApplicationSubmissionContext() + Assertions.assertNotNull(loadedApp2); + //Assertions.assertEquals(0, loadedApp2.getAppAttempts().size()); + Assertions.assertEquals(app2.getApplicationSubmissionContext() .getApplicationId(), loadedApp2.getApplicationSubmissionContext() .getApplicationId()); @@ -384,8 +386,8 @@ public void testRMRestart() throws Exception { // The app for which AM was started will wait for previous am // container finish event to arrive. However for an application for which // no am container was running will start new application attempt. - Assert.assertEquals(1, loadedApp1.getAppAttempts().size()); - Assert.assertEquals(1, loadedApp2.getAppAttempts().size()); + Assertions.assertEquals(1, loadedApp1.getAppAttempts().size()); + Assertions.assertEquals(1, loadedApp2.getAppAttempts().size()); // verify old AM is not accepted // change running AM to talk to new RM @@ -393,16 +395,16 @@ public void testRMRestart() throws Exception { try { am1.allocate(new ArrayList(), new ArrayList()); - Assert.fail(); + Assertions.fail(); } catch (ApplicationAttemptNotFoundException e) { - Assert.assertTrue(e instanceof ApplicationAttemptNotFoundException); + Assertions.assertTrue(e instanceof ApplicationAttemptNotFoundException); } // NM should be rebooted on heartbeat, even first heartbeat for nm2 NodeHeartbeatResponse hbResponse = nm1.nodeHeartbeat(true); - Assert.assertEquals(NodeAction.RESYNC, hbResponse.getNodeAction()); + Assertions.assertEquals(NodeAction.RESYNC, hbResponse.getNodeAction()); hbResponse = nm2.nodeHeartbeat(true); - Assert.assertEquals(NodeAction.RESYNC, hbResponse.getNodeAction()); + Assertions.assertEquals(NodeAction.RESYNC, hbResponse.getNodeAction()); // new NM to represent NM re-register nm1 = new MockNM("127.0.0.1:1234", 15120, rm2.getResourceTrackerService()); @@ -424,9 +426,9 @@ public void testRMRestart() throws Exception { // verify no more reboot response sent hbResponse = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.RESYNC != hbResponse.getNodeAction()); + Assertions.assertTrue(NodeAction.RESYNC != hbResponse.getNodeAction()); hbResponse = nm2.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.RESYNC != hbResponse.getNodeAction()); + Assertions.assertTrue(NodeAction.RESYNC != hbResponse.getNodeAction()); // assert app1 attempt is saved attempt1 = loadedApp1.getCurrentAppAttempt(); @@ -435,8 +437,8 @@ public void testRMRestart() throws Exception { rm2.waitForState(attemptId1, RMAppAttemptState.ALLOCATED); appState = rmAppState.get(loadedApp1.getApplicationId()); attemptState = appState.getAttempt(attemptId1); - Assert.assertNotNull(attemptState); - Assert.assertEquals(BuilderUtils.newContainerId(attemptId1, 1), + Assertions.assertNotNull(attemptState); + Assertions.assertEquals(BuilderUtils.newContainerId(attemptId1, 1), attemptState.getMasterContainer().getId()); // Nodes on which the AM's run @@ -452,8 +454,8 @@ public void testRMRestart() throws Exception { rm2.waitForState(attemptId2, RMAppAttemptState.ALLOCATED); appState = rmAppState.get(loadedApp2.getApplicationId()); attemptState = appState.getAttempt(attemptId2); - Assert.assertNotNull(attemptState); - Assert.assertEquals(BuilderUtils.newContainerId(attemptId2, 1), + Assertions.assertNotNull(attemptState); + Assertions.assertEquals(BuilderUtils.newContainerId(attemptId2, 1), attemptState.getMasterContainer().getId()); MockNM am2Node = nm1; @@ -495,10 +497,11 @@ public void testRMRestart() throws Exception { // completed apps are not removed immediately after app finish // And finished app is also loaded back. - Assert.assertEquals(4, rmAppState.size()); + Assertions.assertEquals(4, rmAppState.size()); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAppReportNodeLabelRMRestart() throws Exception { if (getSchedulerType() != SchedulerType.CAPACITY) { return; @@ -529,19 +532,19 @@ public void testAppReportNodeLabelRMRestart() throws Exception { // start new RM MockRM rm2 = createMockRM(conf, memStore); rm2.start(); - Assert.assertEquals(1, rm2.getRMContext().getRMApps().size()); + Assertions.assertEquals(1, rm2.getRMContext().getRMApps().size()); ApplicationReport appReport = rm2.getClientRMService().getApplicationReport( GetApplicationReportRequest.newInstance(app0.getApplicationId())) .getApplicationReport(); - Assert - .assertEquals(amLabel.getName(), appReport.getAmNodeLabelExpression()); - Assert.assertEquals(appLabel.getName(), + Assertions.assertEquals(amLabel.getName(), appReport.getAmNodeLabelExpression()); + Assertions.assertEquals(appLabel.getName(), appReport.getAppNodeLabelExpression()); rm1.stop(); rm2.stop(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testUnManagedRMRestart() throws Exception { // Create RM MockRM rm1 = createMockRM(conf); @@ -562,16 +565,17 @@ public void testUnManagedRMRestart() throws Exception { // start new RM MockRM rm2 = createMockRM(conf, memStore); rm2.start(); - Assert.assertEquals(1, rm2.getRMContext().getRMApps().size()); + Assertions.assertEquals(1, rm2.getRMContext().getRMApps().size()); ApplicationReport appReport = rm2.getClientRMService().getApplicationReport( GetApplicationReportRequest.newInstance(app0.getApplicationId())) .getApplicationReport(); - Assert.assertEquals(true, appReport.isUnmanagedApp()); + Assertions.assertEquals(true, appReport.isUnmanagedApp()); rm1.stop(); rm2.stop(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartAppRunningAMFailed() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS); @@ -610,11 +614,11 @@ public void testRMRestartAppRunningAMFailed() throws Exception { ApplicationStateData appState = rmAppState.get(app0.getApplicationId()); // assert the AM failed state is saved. - Assert.assertEquals(RMAppAttemptState.FAILED, + Assertions.assertEquals(RMAppAttemptState.FAILED, appState.getAttempt(am0.getApplicationAttemptId()).getState()); // assert app state has not been saved. - Assert.assertNull(rmAppState.get(app0.getApplicationId()).getState()); + Assertions.assertNull(rmAppState.get(app0.getApplicationId()).getState()); // new AM started but not registered, app still stays at ACCECPTED state. rm1.waitForState(app0.getApplicationId(), RMAppState.ACCEPTED); @@ -627,7 +631,8 @@ public void testRMRestartAppRunningAMFailed() throws Exception { rm2.waitForState(am0.getApplicationAttemptId(), RMAppAttemptState.FAILED); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartWaitForPreviousAMToFinish() throws Exception { // testing 3 cases // After RM restarts @@ -667,9 +672,9 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception { // launch another AM. MockAM am2 = launchAM(app1, rm1, nm1); - Assert.assertEquals(1, rmAppState.size()); + Assertions.assertEquals(1, rmAppState.size()); assertThat(app1.getState()).isEqualTo(RMAppState.RUNNING); - Assert.assertEquals(app1.getAppAttempts() + Assertions.assertEquals(app1.getAppAttempts() .get(app1.getCurrentAppAttempt().getAppAttemptId()) .getAppAttemptState(), RMAppAttemptState.RUNNING); @@ -679,23 +684,23 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception { nm1.setResourceTrackerService(rm2.getResourceTrackerService()); NodeHeartbeatResponse res = nm1.nodeHeartbeat(true); - Assert.assertEquals(NodeAction.RESYNC, res.getNodeAction()); + Assertions.assertEquals(NodeAction.RESYNC, res.getNodeAction()); RMApp rmApp = rm2.getRMContext().getRMApps().get(app1.getApplicationId()); // application should be in ACCEPTED state rm2.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); - Assert.assertEquals(RMAppState.ACCEPTED, rmApp.getState()); + Assertions.assertEquals(RMAppState.ACCEPTED, rmApp.getState()); // new attempt should not be started - Assert.assertEquals(2, rmApp.getAppAttempts().size()); + Assertions.assertEquals(2, rmApp.getAppAttempts().size()); // am1 attempt should be in FAILED state where as am2 attempt should be in // LAUNCHED state rm2.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.FAILED); rm2.waitForState(am2.getApplicationAttemptId(), RMAppAttemptState.LAUNCHED); - Assert.assertEquals(RMAppAttemptState.FAILED, + Assertions.assertEquals(RMAppAttemptState.FAILED, rmApp.getAppAttempts().get(am1.getApplicationAttemptId()) .getAppAttemptState()); - Assert.assertEquals(RMAppAttemptState.LAUNCHED, + Assertions.assertEquals(RMAppAttemptState.LAUNCHED, rmApp.getAppAttempts().get(am2.getApplicationAttemptId()) .getAppAttemptState()); @@ -709,7 +714,7 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception { am2.getApplicationAttemptId()); launchAM(rmApp, rm2, nm1); - Assert.assertEquals(3, rmApp.getAppAttempts().size()); + Assertions.assertEquals(3, rmApp.getAppAttempts().size()); rm2.waitForState(rmApp.getCurrentAppAttempt().getAppAttemptId(), RMAppAttemptState.RUNNING); // Now restart RM ... @@ -726,7 +731,7 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception { rm3.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); assertThat(rmApp.getState()).isEqualTo(RMAppState.ACCEPTED); // new attempt should not be started - Assert.assertEquals(3, rmApp.getAppAttempts().size()); + Assertions.assertEquals(3, rmApp.getAppAttempts().size()); // am1 and am2 attempts should be in FAILED state where as am3 should be // in LAUNCHED state rm3.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.FAILED); @@ -734,13 +739,13 @@ public void testRMRestartWaitForPreviousAMToFinish() throws Exception { ApplicationAttemptId latestAppAttemptId = rmApp.getCurrentAppAttempt().getAppAttemptId(); rm3.waitForState(latestAppAttemptId, RMAppAttemptState.LAUNCHED); - Assert.assertEquals(RMAppAttemptState.FAILED, + Assertions.assertEquals(RMAppAttemptState.FAILED, rmApp.getAppAttempts().get(am1.getApplicationAttemptId()) .getAppAttemptState()); - Assert.assertEquals(RMAppAttemptState.FAILED, + Assertions.assertEquals(RMAppAttemptState.FAILED, rmApp.getAppAttempts().get(am2.getApplicationAttemptId()) .getAppAttemptState()); - Assert.assertEquals(RMAppAttemptState.LAUNCHED,rmApp.getAppAttempts() + Assertions.assertEquals(RMAppAttemptState.LAUNCHED,rmApp.getAppAttempts() .get(latestAppAttemptId).getAppAttemptState()); rm3.waitForState(latestAppAttemptId, RMAppAttemptState.FAILED); @@ -755,7 +760,7 @@ public Boolean get() { } }, 100, maxRetry * 100); - Assert.assertEquals(RMAppAttemptState.FAILED, + Assertions.assertEquals(RMAppAttemptState.FAILED, rmApp.getAppAttempts().get(latestAppAttemptId).getAppAttemptState()); latestAppAttemptId = rmApp.getCurrentAppAttempt().getAppAttemptId(); @@ -766,8 +771,8 @@ public Boolean get() { // submitting app but not starting AM for it. RMApp app2 = MockRMAppSubmitter.submitWithMemory(200, rm3); rm3.waitForState(app2.getApplicationId(), RMAppState.ACCEPTED); - Assert.assertEquals(1, app2.getAppAttempts().size()); - Assert.assertEquals(0, + Assertions.assertEquals(1, app2.getAppAttempts().size()); + Assertions.assertEquals(0, memStore.getState().getApplicationState().get(app2.getApplicationId()) .getAttemptCount()); @@ -781,21 +786,21 @@ public Boolean get() { while (rmApp.getAppAttempts().size() != 2 && timeoutSecs++ < 40) { Thread.sleep(200); } - Assert.assertEquals(4, rmApp.getAppAttempts().size()); - Assert.assertEquals(RMAppState.ACCEPTED, rmApp.getState()); + Assertions.assertEquals(4, rmApp.getAppAttempts().size()); + Assertions.assertEquals(RMAppState.ACCEPTED, rmApp.getState()); rm4.waitForState(latestAppAttemptId, RMAppAttemptState.SCHEDULED); - Assert.assertEquals(RMAppAttemptState.SCHEDULED, rmApp.getAppAttempts() + Assertions.assertEquals(RMAppAttemptState.SCHEDULED, rmApp.getAppAttempts() .get(latestAppAttemptId).getAppAttemptState()); // The initial application for which an AM was not started should be in // ACCEPTED state with one application attempt started. app2 = rm4.getRMContext().getRMApps().get(app2.getApplicationId()); rm4.waitForState(app2.getApplicationId(), RMAppState.ACCEPTED); - Assert.assertEquals(RMAppState.ACCEPTED, app2.getState()); - Assert.assertEquals(1, app2.getAppAttempts().size()); + Assertions.assertEquals(RMAppState.ACCEPTED, app2.getState()); + Assertions.assertEquals(1, app2.getAppAttempts().size()); rm4.waitForState(app2.getCurrentAppAttempt().getAppAttemptId(), RMAppAttemptState.SCHEDULED); - Assert.assertEquals(RMAppAttemptState.SCHEDULED, app2 + Assertions.assertEquals(RMAppAttemptState.SCHEDULED, app2 .getCurrentAppAttempt().getAppAttemptState()); } @@ -803,7 +808,8 @@ public Boolean get() { // store but before the RMAppAttempt notifies RMApp that it has succeeded. On // recovery, RMAppAttempt should send the AttemptFinished event to RMApp so // that RMApp can recover its state. - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartWaitForPreviousSucceededAttempt() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2); MemoryRMStateStore memStore = new MockMemoryRMStateStore() { @@ -841,7 +847,7 @@ public void updateApplicationStateInternal(ApplicationId appId, // app final state is not saved. This guarantees that RMApp cannot be // recovered via its own saved state, but only via the event notification // from the RMAppAttempt on recovery. - Assert.assertNull(rmAppState.get(app0.getApplicationId()).getState()); + Assertions.assertNull(rmAppState.get(app0.getApplicationId()).getState()); // start RM MockRM rm2 = createMockRM(conf, memStore); @@ -852,11 +858,12 @@ public void updateApplicationStateInternal(ApplicationId appId, RMAppAttemptState.FINISHED); rm2.waitForState(app0.getApplicationId(), RMAppState.FINISHED); // app final state is saved via the finish event from attempt. - Assert.assertEquals(RMAppState.FINISHED, + Assertions.assertEquals(RMAppState.FINISHED, rmAppState.get(app0.getApplicationId()).getState()); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartFailedApp() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); // create RM @@ -882,8 +889,8 @@ public void testRMRestartFailedApp() throws Exception { // assert the app/attempt failed state is saved. ApplicationStateData appState = rmAppState.get(app0.getApplicationId()); - Assert.assertEquals(RMAppState.FAILED, appState.getState()); - Assert.assertEquals(RMAppAttemptState.FAILED, + Assertions.assertEquals(RMAppState.FAILED, appState.getState()); + Assertions.assertEquals(RMAppAttemptState.FAILED, appState.getAttempt(am0.getApplicationAttemptId()).getState()); // start new RM @@ -892,18 +899,19 @@ public void testRMRestartFailedApp() throws Exception { RMApp loadedApp0 = rm2.getRMContext().getRMApps().get(app0.getApplicationId()); rm2.waitForState(app0.getApplicationId(), RMAppState.FAILED); rm2.waitForState(am0.getApplicationAttemptId(), RMAppAttemptState.FAILED); - Assert.assertEquals(app0.getUser(), loadedApp0.getUser()); + Assertions.assertEquals(app0.getUser(), loadedApp0.getUser()); // no new attempt is created. - Assert.assertEquals(1, loadedApp0.getAppAttempts().size()); + Assertions.assertEquals(1, loadedApp0.getAppAttempts().size()); verifyAppReportAfterRMRestart(app0, rm2); - Assert.assertTrue(app0.getDiagnostics().toString() + Assertions.assertTrue(app0.getDiagnostics().toString() .contains("Failing the application.")); // failed diagnostics from attempt is lost because the diagnostics from // attempt is not yet available by the time app is saving the app state. } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartKilledApp() throws Exception{ conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS); @@ -930,11 +938,11 @@ public void testRMRestartKilledApp() throws Exception{ // killed state is saved. ApplicationStateData appState = rmAppState.get(app0.getApplicationId()); - Assert.assertEquals(RMAppState.KILLED, appState.getState()); - Assert.assertEquals(RMAppAttemptState.KILLED, + Assertions.assertEquals(RMAppState.KILLED, appState.getState()); + Assertions.assertEquals(RMAppAttemptState.KILLED, appState.getAttempt(am0.getApplicationAttemptId()).getState()); String trackingUrl = app0.getCurrentAppAttempt().getOriginalTrackingUrl(); - Assert.assertNotNull(trackingUrl); + Assertions.assertNotNull(trackingUrl); // restart rm MockRM rm2 = createMockRM(conf, memStore); @@ -943,16 +951,17 @@ public void testRMRestartKilledApp() throws Exception{ rm2.waitForState(app0.getApplicationId(), RMAppState.KILLED); rm2.waitForState(am0.getApplicationAttemptId(), RMAppAttemptState.KILLED); // no new attempt is created. - Assert.assertEquals(1, loadedApp0.getAppAttempts().size()); + Assertions.assertEquals(1, loadedApp0.getAppAttempts().size()); ApplicationReport appReport = verifyAppReportAfterRMRestart(app0, rm2); - Assert.assertEquals(app0.getDiagnostics().toString(), + Assertions.assertEquals(app0.getDiagnostics().toString(), appReport.getDiagnostics()); - Assert.assertEquals(trackingUrl, loadedApp0.getCurrentAppAttempt() + Assertions.assertEquals(trackingUrl, loadedApp0.getCurrentAppAttempt() .getOriginalTrackingUrl()); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartKilledAppWithNoAttempts() throws Exception { MockMemoryRMStateStore memStore = new MockMemoryRMStateStore() { @Override @@ -998,10 +1007,11 @@ public synchronized void updateApplicationAttemptStateInternal( RMApp loadedApp0 = rm2.getRMContext().getRMApps().get(app0.getApplicationId()); rm2.waitForState(loadedApp0.getApplicationId(), RMAppState.KILLED); - Assert.assertTrue(loadedApp0.getAppAttempts().size() == 0); + Assertions.assertTrue(loadedApp0.getAppAttempts().size() == 0); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartSucceededApp() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS); @@ -1032,11 +1042,11 @@ public void testRMRestartSucceededApp() throws Exception { ApplicationStateData appState = rmAppState.get(app0.getApplicationId()); ApplicationAttemptStateData attemptState0 = appState.getAttempt(am0.getApplicationAttemptId()); - Assert.assertEquals("diagnostics", attemptState0.getDiagnostics()); - Assert.assertEquals(FinalApplicationStatus.SUCCEEDED, + Assertions.assertEquals("diagnostics", attemptState0.getDiagnostics()); + Assertions.assertEquals(FinalApplicationStatus.SUCCEEDED, attemptState0.getFinalApplicationStatus()); - Assert.assertEquals("trackingUrl", attemptState0.getFinalTrackingUrl()); - Assert.assertEquals(app0.getFinishTime(), appState.getFinishTime()); + Assertions.assertEquals("trackingUrl", attemptState0.getFinalTrackingUrl()); + Assertions.assertEquals(app0.getFinishTime(), appState.getFinishTime()); // restart rm MockRM rm2 = createMockRM(conf, memStore); @@ -1045,12 +1055,13 @@ public void testRMRestartSucceededApp() throws Exception { // verify application report returns the same app info as the app info // before RM restarts. ApplicationReport appReport = verifyAppReportAfterRMRestart(app0, rm2); - Assert.assertEquals(FinalApplicationStatus.SUCCEEDED, + Assertions.assertEquals(FinalApplicationStatus.SUCCEEDED, appReport.getFinalApplicationStatus()); - Assert.assertEquals("trackingUrl", appReport.getOriginalTrackingUrl()); + Assertions.assertEquals("trackingUrl", appReport.getOriginalTrackingUrl()); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartGetApplicationList() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); // start RM @@ -1153,22 +1164,22 @@ protected SystemMetricsPublisher createSystemMetricsPublisher() { boolean forApp0 = false, forApp1 = false, forApp2 = false; for (ApplicationReport report : appList1) { if (report.getApplicationId().equals(app0.getApplicationId())) { - Assert.assertEquals(YarnApplicationState.FINISHED, + Assertions.assertEquals(YarnApplicationState.FINISHED, report.getYarnApplicationState()); forApp0 = true; } if (report.getApplicationId().equals(app1.getApplicationId())) { - Assert.assertEquals(YarnApplicationState.FAILED, + Assertions.assertEquals(YarnApplicationState.FAILED, report.getYarnApplicationState()); forApp1 = true; } if (report.getApplicationId().equals(app2.getApplicationId())) { - Assert.assertEquals(YarnApplicationState.KILLED, + Assertions.assertEquals(YarnApplicationState.KILLED, report.getYarnApplicationState()); forApp2 = true; } } - Assert.assertTrue(forApp0 && forApp1 && forApp2); + Assertions.assertTrue(forApp0 && forApp1 && forApp2); // assert all applications exist according to application type after RM // restarts. @@ -1179,7 +1190,7 @@ protected SystemMetricsPublisher createSystemMetricsPublisher() { GetApplicationsResponse response2 = rm2.getClientRMService().getApplications(request2); List appList2 = response2.getApplicationList(); - Assert.assertTrue(3 == appList2.size()); + Assertions.assertTrue(3 == appList2.size()); // check application summary is logged for the completed apps with timeout // to make sure APP_COMPLETED events are processed, after RM restart. @@ -1204,11 +1215,11 @@ private ApplicationReport verifyAppReportAfterRMRestart(RMApp app, MockRM rm) GetApplicationReportResponse response = rm.getClientRMService().getApplicationReport(reportRequest); ApplicationReport report = response.getApplicationReport(); - Assert.assertEquals(app.getStartTime(), report.getStartTime()); - Assert.assertEquals(app.getFinishTime(), report.getFinishTime()); - Assert.assertEquals(app.createApplicationState(), + Assertions.assertEquals(app.getStartTime(), report.getStartTime()); + Assertions.assertEquals(app.getFinishTime(), report.getFinishTime()); + Assertions.assertEquals(app.createApplicationState(), report.getYarnApplicationState()); - Assert.assertTrue(1 == report.getProgress()); + Assertions.assertTrue(1 == report.getProgress()); return response.getApplicationReport(); } @@ -1233,13 +1244,13 @@ private void finishApplicationMaster(RMApp rmApp, MockRM rm, MockNM nm, rm.waitForState(rmApp.getApplicationId(), RMAppState.FINISHED); // check that app/attempt is saved with the final state ApplicationStateData appState = rmAppState.get(rmApp.getApplicationId()); - Assert - .assertEquals(RMAppState.FINISHED, appState.getState()); - Assert.assertEquals(RMAppAttemptState.FINISHED, + Assertions.assertEquals(RMAppState.FINISHED, appState.getState()); + Assertions.assertEquals(RMAppAttemptState.FINISHED, appState.getAttempt(am.getApplicationAttemptId()).getState()); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartOnMaxAppAttempts() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS); @@ -1280,9 +1291,9 @@ public void testRMRestartOnMaxAppAttempts() throws Exception { // assert app1 info is saved ApplicationStateData appState = rmAppState.get(app1.getApplicationId()); - Assert.assertNotNull(appState); - Assert.assertEquals(0, appState.getAttemptCount()); - Assert.assertEquals(appState.getApplicationSubmissionContext() + Assertions.assertNotNull(appState); + Assertions.assertEquals(0, appState.getAttemptCount()); + Assertions.assertEquals(appState.getApplicationSubmissionContext() .getApplicationId(), app1.getApplicationSubmissionContext() .getApplicationId()); @@ -1291,11 +1302,11 @@ public void testRMRestartOnMaxAppAttempts() throws Exception { RMAppAttempt attempt = app1.getCurrentAppAttempt(); ApplicationAttemptId attemptId1 = attempt.getAppAttemptId(); rm1.waitForState(attemptId1, RMAppAttemptState.ALLOCATED); - Assert.assertEquals(1, appState.getAttemptCount()); + Assertions.assertEquals(1, appState.getAttemptCount()); ApplicationAttemptStateData attemptState = appState.getAttempt(attemptId1); - Assert.assertNotNull(attemptState); - Assert.assertEquals(BuilderUtils.newContainerId(attemptId1, 1), + Assertions.assertNotNull(attemptState); + Assertions.assertEquals(BuilderUtils.newContainerId(attemptId1, 1), attemptState.getMasterContainer().getId()); // Setting AMLivelinessMonitor interval to be 3 Secs. @@ -1305,24 +1316,25 @@ public void testRMRestartOnMaxAppAttempts() throws Exception { rm2.start(); // verify that maxAppAttempts is set to global value - Assert.assertEquals(2, + Assertions.assertEquals(2, rm2.getRMContext().getRMApps().get(app2.getApplicationId()) .getMaxAppAttempts()); // app1 and app2 are loaded back, but app1 failed because it's // hitting max-retry. - Assert.assertEquals(2, rm2.getRMContext().getRMApps().size()); + Assertions.assertEquals(2, rm2.getRMContext().getRMApps().size()); rm2.waitForState(app1.getApplicationId(), RMAppState.FAILED); rm2.waitForState(app2.getApplicationId(), RMAppState.ACCEPTED); // app1 failed state is saved in state store. app2 final saved state is not // determined yet. - Assert.assertEquals(RMAppState.FAILED, + Assertions.assertEquals(RMAppState.FAILED, rmAppState.get(app1.getApplicationId()).getState()); - Assert.assertNull(rmAppState.get(app2.getApplicationId()).getState()); + Assertions.assertNull(rmAppState.get(app2.getApplicationId()).getState()); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartTimelineCollectorContext() throws Exception { conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true); conf.setFloat(YarnConfiguration.TIMELINE_SERVICE_VERSION, 2.0f); @@ -1352,9 +1364,9 @@ public void testRMRestartTimelineCollectorContext() throws Exception { .build()); // Check if app info has been saved. ApplicationStateData appState = rmAppState.get(app.getApplicationId()); - Assert.assertNotNull(appState); - Assert.assertEquals(0, appState.getAttemptCount()); - Assert.assertEquals(appState.getApplicationSubmissionContext() + Assertions.assertNotNull(appState); + Assertions.assertEquals(0, appState.getAttemptCount()); + Assertions.assertEquals(appState.getApplicationSubmissionContext() .getApplicationId(), app.getApplicationSubmissionContext() .getApplicationId()); @@ -1372,13 +1384,13 @@ public void testRMRestartTimelineCollectorContext() throws Exception { // Restart RM. rm2 = createMockRM(conf, memStore); rm2.start(); - Assert.assertEquals(1, rm2.getRMContext().getRMApps().size()); + Assertions.assertEquals(1, rm2.getRMContext().getRMApps().size()); rm2.waitForState(app.getApplicationId(), RMAppState.ACCEPTED); TimelineCollectorContext contextAfterRestart = rm2.getRMContext().getRMTimelineCollectorManager().get(appId). getTimelineEntityContext(); - Assert.assertEquals("Collector contexts for an app should be same " + - "across restarts", contextBeforeRestart, contextAfterRestart); + Assertions.assertEquals(contextBeforeRestart, contextAfterRestart, "Collector contexts for an app should be same " + + "across restarts"); } finally { conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, false); if (rm1 != null) { @@ -1390,7 +1402,8 @@ public void testRMRestartTimelineCollectorContext() throws Exception { } } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testDelegationTokenRestoredInDelegationTokenRenewer() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2); @@ -1449,10 +1462,10 @@ public void testDelegationTokenRestoredInDelegationTokenRenewer() // assert app info is saved ApplicationStateData appState = rmAppState.get(app.getApplicationId()); - Assert.assertNotNull(appState); + Assertions.assertNotNull(appState); // assert delegation tokens exist in rm1 DelegationTokenRenewr - Assert.assertEquals(tokenSet, rm1.getRMContext() + Assertions.assertEquals(tokenSet, rm1.getRMContext() .getDelegationTokenRenewer().getDelegationTokens()); // assert delegation tokens are saved @@ -1461,7 +1474,7 @@ public void testDelegationTokenRestoredInDelegationTokenRenewer() ByteBuffer securityTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength()); securityTokens.rewind(); - Assert.assertEquals(securityTokens, appState + Assertions.assertEquals(securityTokens, appState .getApplicationSubmissionContext().getAMContainerSpec() .getTokens()); @@ -1474,7 +1487,7 @@ public void testDelegationTokenRestoredInDelegationTokenRenewer() waitForTokensToBeRenewed(rm2, tokenSet); // verify tokens are properly populated back to rm2 DelegationTokenRenewer - Assert.assertEquals(tokenSet, rm2.getRMContext() + Assertions.assertEquals(tokenSet, rm2.getRMContext() .getDelegationTokenRenewer().getDelegationTokens()); } @@ -1493,7 +1506,8 @@ private void waitForTokensToBeRenewed(MockRM rm2, } } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testAppAttemptTokensRestoredOnRMRestart() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2); conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, @@ -1525,7 +1539,7 @@ public void testAppAttemptTokensRestoredOnRMRestart() throws Exception { // assert app info is saved ApplicationStateData appState = rmAppState.get(app1.getApplicationId()); - Assert.assertNotNull(appState); + Assertions.assertNotNull(appState); // Allocate the AM nm1.nodeHeartbeat(true); @@ -1535,8 +1549,8 @@ public void testAppAttemptTokensRestoredOnRMRestart() throws Exception { // assert attempt info is saved ApplicationAttemptStateData attemptState = appState.getAttempt(attemptId1); - Assert.assertNotNull(attemptState); - Assert.assertEquals(BuilderUtils.newContainerId(attemptId1, 1), + Assertions.assertNotNull(attemptState); + Assertions.assertEquals(BuilderUtils.newContainerId(attemptId1, 1), attemptState.getMasterContainer().getId()); // the clientTokenMasterKey that are generated when @@ -1546,9 +1560,9 @@ public void testAppAttemptTokensRestoredOnRMRestart() throws Exception { // assert application credentials are saved Credentials savedCredentials = attemptState.getAppAttemptTokens(); - Assert.assertArrayEquals("client token master key not saved", - clientTokenMasterKey, savedCredentials.getSecretKey( - RMStateStore.AM_CLIENT_TOKEN_MASTER_KEY_NAME)); + Assertions.assertArrayEquals( + clientTokenMasterKey, savedCredentials.getSecretKey( + RMStateStore.AM_CLIENT_TOKEN_MASTER_KEY_NAME), "client token master key not saved"); // start new RM MockRM rm2 = new TestSecurityMockRM(conf, memStore); @@ -1559,27 +1573,28 @@ public void testAppAttemptTokensRestoredOnRMRestart() throws Exception { RMAppAttempt loadedAttempt1 = loadedApp1.getRMAppAttempt(attemptId1); // assert loaded attempt recovered - Assert.assertNotNull(loadedAttempt1); + Assertions.assertNotNull(loadedAttempt1); // assert client token master key is recovered back to api-versioned // client token master key - Assert.assertEquals("client token master key not restored", - attempt1.getClientTokenMasterKey(), - loadedAttempt1.getClientTokenMasterKey()); + Assertions.assertEquals( + attempt1.getClientTokenMasterKey() +, loadedAttempt1.getClientTokenMasterKey(), "client token master key not restored"); // assert ClientTokenSecretManager also knows about the key - Assert.assertArrayEquals(clientTokenMasterKey, + Assertions.assertArrayEquals(clientTokenMasterKey, rm2.getClientToAMTokenSecretManager().getMasterKey(attemptId1) .getEncoded()); // assert AMRMTokenSecretManager also knows about the AMRMToken password Token amrmToken = loadedAttempt1.getAMRMToken(); - Assert.assertArrayEquals(amrmToken.getPassword(), + Assertions.assertArrayEquals(amrmToken.getPassword(), rm2.getRMContext().getAMRMTokenSecretManager().retrievePassword( amrmToken.decodeIdentifier())); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMDelegationTokenRestoredOnRMRestart() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2); conf.set( @@ -1635,21 +1650,21 @@ public void testRMDelegationTokenRestoredOnRMRestart() throws Exception { // assert app info is saved ApplicationStateData appState = rmAppState.get(app.getApplicationId()); - Assert.assertNotNull(appState); + Assertions.assertNotNull(appState); // assert all master keys are saved Set allKeysRM1 = rm1.getRMContext() .getRMDelegationTokenSecretManager().getAllMasterKeys(); - Assert.assertEquals(allKeysRM1, rmDTMasterKeyState); + Assertions.assertEquals(allKeysRM1, rmDTMasterKeyState); // assert all tokens are saved Map allTokensRM1 = rm1.getRMContext().getRMDelegationTokenSecretManager().getAllTokens(); - Assert.assertEquals(tokenIdentSet, allTokensRM1.keySet()); - Assert.assertEquals(allTokensRM1, rmDTState); + Assertions.assertEquals(tokenIdentSet, allTokensRM1.keySet()); + Assertions.assertEquals(allTokensRM1, rmDTState); // assert sequence number is saved - Assert.assertEquals(rm1.getRMContext().getRMDelegationTokenSecretManager() + Assertions.assertEquals(rm1.getRMContext().getRMDelegationTokenSecretManager() .getLatestDTSequenceNumber(), rmState.getRMDTSecretManagerState() .getDTSequenceNumber()); @@ -1669,13 +1684,13 @@ public void testRMDelegationTokenRestoredOnRMRestart() throws Exception { rm1.getRMContext().getRMDelegationTokenSecretManager().cancelToken(token2, UserGroupInformation.getCurrentUser().getUserName()); } catch(Exception e) { - Assert.fail(); + Assertions.fail(); } // Assert the token which has the latest delegationTokenSequenceNumber is removed - Assert.assertEquals(rm1.getRMContext().getRMDelegationTokenSecretManager() + Assertions.assertEquals(rm1.getRMContext().getRMDelegationTokenSecretManager() .getLatestDTSequenceNumber(), dtId2.getSequenceNumber()); - Assert.assertFalse(rmDTState.containsKey(dtId2)); + Assertions.assertFalse(rmDTState.containsKey(dtId2)); // start new RM MockRM rm2 = new TestSecurityMockRM(conf, memStore); @@ -1684,14 +1699,14 @@ public void testRMDelegationTokenRestoredOnRMRestart() throws Exception { // assert master keys and tokens are populated back to DTSecretManager Map allTokensRM2 = rm2.getRMContext().getRMDelegationTokenSecretManager().getAllTokens(); - Assert.assertEquals(allTokensRM2.keySet(), allTokensRM1.keySet()); + Assertions.assertEquals(allTokensRM2.keySet(), allTokensRM1.keySet()); // rm2 has its own master keys when it starts, we use containsAll here - Assert.assertTrue(rm2.getRMContext().getRMDelegationTokenSecretManager() + Assertions.assertTrue(rm2.getRMContext().getRMDelegationTokenSecretManager() .getAllMasterKeys().containsAll(allKeysRM1)); // assert sequenceNumber is properly recovered, // even though the token which has max sequenceNumber is not stored - Assert.assertEquals(rm1.getRMContext().getRMDelegationTokenSecretManager() + Assertions.assertEquals(rm1.getRMContext().getRMDelegationTokenSecretManager() .getLatestDTSequenceNumber(), rm2.getRMContext() .getRMDelegationTokenSecretManager().getLatestDTSequenceNumber()); @@ -1704,37 +1719,38 @@ public void testRMDelegationTokenRestoredOnRMRestart() throws Exception { rm2.getRMContext().getRMDelegationTokenSecretManager().renewToken( token1, "renewer1"); } catch(Exception e) { - Assert.fail(); + Assertions.fail(); } allTokensRM2 = rm2.getRMContext().getRMDelegationTokenSecretManager() .getAllTokens(); Long renewDateAfterRenew = allTokensRM2.get(dtId1); // assert token is renewed - Assert.assertTrue(renewDateAfterRenew > renewDateBeforeRenew); + Assertions.assertTrue(renewDateAfterRenew > renewDateBeforeRenew); // assert new token is added into state store - Assert.assertTrue(rmDTState.containsValue(renewDateAfterRenew)); + Assertions.assertTrue(rmDTState.containsValue(renewDateAfterRenew)); // assert old token is removed from state store - Assert.assertFalse(rmDTState.containsValue(renewDateBeforeRenew)); + Assertions.assertFalse(rmDTState.containsValue(renewDateBeforeRenew)); try{ rm2.getRMContext().getRMDelegationTokenSecretManager().cancelToken(token1, UserGroupInformation.getCurrentUser().getUserName()); } catch(Exception e) { - Assert.fail(); + Assertions.fail(); } // assert token is removed from state after its cancelled allTokensRM2 = rm2.getRMContext().getRMDelegationTokenSecretManager() .getAllTokens(); - Assert.assertFalse(allTokensRM2.containsKey(dtId1)); - Assert.assertFalse(rmDTState.containsKey(dtId1)); + Assertions.assertFalse(allTokensRM2.containsKey(dtId1)); + Assertions.assertFalse(rmDTState.containsKey(dtId1)); } // This is to test submit an application to the new RM with the old delegation // token got from previous RM. - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testAppSubmissionWithOldDelegationTokenAfterRMRestart() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2); @@ -1775,7 +1791,8 @@ public void testAppSubmissionWithOldDelegationTokenAfterRMRestart() rm2.waitForState(app.getApplicationId(), RMAppState.ACCEPTED); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testRMStateStoreDispatcherDrainedOnRMStop() throws Exception { MemoryRMStateStore memStore = new MemoryRMStateStore() { volatile boolean wait = true; @@ -1832,7 +1849,7 @@ protected void handleStoreEvent(RMStateStoreEvent event) { // Nothing exist in state store before stop is called. Map rmAppState = memStore.getState().getApplicationState(); - Assert.assertTrue(rmAppState.size() == 0); + Assertions.assertTrue(rmAppState.size() == 0); // stop rm rm1.stop(); @@ -1841,16 +1858,17 @@ protected void handleStoreEvent(RMStateStoreEvent event) { // request on dispatcher. for (RMApp app : appList) { ApplicationStateData appState = rmAppState.get(app.getApplicationId()); - Assert.assertNotNull(appState); - Assert.assertEquals(0, appState.getAttemptCount()); - Assert.assertEquals(appState.getApplicationSubmissionContext() + Assertions.assertNotNull(appState); + Assertions.assertEquals(0, appState.getAttemptCount()); + Assertions.assertEquals(appState.getApplicationSubmissionContext() .getApplicationId(), app.getApplicationSubmissionContext() .getApplicationId()); } - Assert.assertTrue(rmAppState.size() == NUM_APPS); + Assertions.assertTrue(rmAppState.size() == NUM_APPS); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testFinishedAppRemovalAfterRMRestart() throws Exception { conf.setInt(YarnConfiguration.RM_MAX_COMPLETED_APPLICATIONS, 1); @@ -1878,7 +1896,7 @@ public void testFinishedAppRemovalAfterRMRestart() throws Exception { rmState.getApplicationState(); // app0 exits in both state store and rmContext - Assert.assertEquals(RMAppState.FINISHED, + Assertions.assertEquals(RMAppState.FINISHED, rmAppState.get(app0.getApplicationId()).getState()); rm2.waitForState(app0.getApplicationId(), RMAppState.FINISHED); @@ -1889,13 +1907,14 @@ public void testFinishedAppRemovalAfterRMRestart() throws Exception { rm2.drainEvents(); // the first app0 get kicked out from both rmContext and state store - Assert.assertNull(rm2.getRMContext().getRMApps() + Assertions.assertNull(rm2.getRMContext().getRMApps() .get(app0.getApplicationId())); - Assert.assertNull(rmAppState.get(app0.getApplicationId())); + Assertions.assertNull(rmAppState.get(app0.getApplicationId())); } // This is to test RM does not get hang on shutdown. - @Test (timeout = 10000) + @Test + @Timeout(value = 10) public void testRMShutdown() throws Exception { MemoryRMStateStore memStore = new MockMemoryRMStateStore() { @Override @@ -1910,17 +1929,18 @@ public synchronized void checkVersion() try { rm1 = createMockRM(conf, memStore); rm1.start(); - Assert.fail(); + Assertions.fail(); } catch (Exception e) { - Assert.assertTrue(e.getMessage().contains("Invalid version.")); + Assertions.assertTrue(e.getMessage().contains("Invalid version.")); } - Assert.assertTrue(rm1.getServiceState() == STATE.STOPPED); + Assertions.assertTrue(rm1.getServiceState() == STATE.STOPPED); } // This is to test Killing application should be able to wait until app // reaches killed state and also check that attempt state is saved before app // state is saved. - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testClientRetryOnKillingApplication() throws Exception { MemoryRMStateStore memStore = new TestMemoryRMStateStore(); memStore.init(conf); @@ -1958,19 +1978,20 @@ public void testClientRetryOnKillingApplication() throws Exception { } // we expect at least 2 calls for killApp as the first killApp always return // false. - Assert.assertTrue(count >= 1); + Assertions.assertTrue(count >= 1); rm1.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.KILLED); rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED); // count = 1 on storing RMApp launchTime // count = 2 on storing attempt state on kill // count = 3 on storing app state on kill - Assert.assertEquals(2, ((TestMemoryRMStateStore) memStore).updateAttempt); - Assert.assertEquals(3, ((TestMemoryRMStateStore) memStore).updateApp); + Assertions.assertEquals(2, ((TestMemoryRMStateStore) memStore).updateAttempt); + Assertions.assertEquals(3, ((TestMemoryRMStateStore) memStore).updateApp); } // Test Application that fails on submission is saved in state store. - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testAppFailedOnSubmissionSavedInStateStore() throws Exception { conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); @@ -2004,14 +2025,14 @@ protected DelegationTokenRenewer createDelegationTokenRenewer() { .withAppType("MAPREDUCE") .withWaitForAppAcceptedState(false) .build()); - Assert.fail(); + Assertions.fail(); } catch (Exception e) { } app1 = rm1.getRMContext().getRMApps().values().iterator().next(); rm1.waitForState(app1.getApplicationId(), RMAppState.FAILED); // Check app staet is saved in state store. - Assert.assertEquals(RMAppState.FAILED, memStore.getState() + Assertions.assertEquals(RMAppState.FAILED, memStore.getState() .getApplicationState().get(app1.getApplicationId()).getState()); MockRM rm2 = new TestSecurityMockRM(conf, memStore); @@ -2020,7 +2041,8 @@ protected DelegationTokenRenewer createDelegationTokenRenewer() { rm2.waitForState(app1.getApplicationId(), RMAppState.FAILED); } - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testAppRecoveredInOrderOnRMRestart() throws Exception { MemoryRMStateStore memStore = new MemoryRMStateStore(); memStore.init(conf); @@ -2057,8 +2079,8 @@ public TestRMAppManager(RMContext context, YarnScheduler scheduler, protected void recoverApplication(ApplicationStateData appState, RMState rmState) throws Exception { // check application is recovered in order. - Assert.assertTrue(rmState.getApplicationState().size() > 0); - Assert.assertTrue(appState.getApplicationSubmissionContext() + Assertions.assertTrue(rmState.getApplicationState().size() > 0); + Assertions.assertTrue(appState.getApplicationSubmissionContext() .getApplicationId().compareTo(prevId) > 0); prevId = appState.getApplicationSubmissionContext().getApplicationId(); @@ -2073,7 +2095,8 @@ protected void recoverApplication(ApplicationStateData appState, } @SuppressWarnings("resource") - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testQueueMetricsOnRMRestart() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS); @@ -2185,17 +2208,18 @@ private void resetQueueMetrics(QueueMetrics qm) { private void assertQueueMetrics(QueueMetrics qm, int appsSubmitted, int appsPending, int appsRunning, int appsCompleted) { - Assert.assertEquals(appsSubmitted + appsSubmittedCarryOn, + Assertions.assertEquals(appsSubmitted + appsSubmittedCarryOn, qm.getAppsSubmitted()); - Assert.assertEquals(appsPending + appsPendingCarryOn, + Assertions.assertEquals(appsPending + appsPendingCarryOn, qm.getAppsPending()); - Assert.assertEquals(appsRunning + appsRunningCarryOn, + Assertions.assertEquals(appsRunning + appsRunningCarryOn, qm.getAppsRunning()); - Assert.assertEquals(appsCompleted + appsCompletedCarryOn, + Assertions.assertEquals(appsCompleted + appsCompletedCarryOn, qm.getAppsCompleted()); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testDecommissionedNMsMetricsOnRMRestart() throws Exception { conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, hostFile.getAbsolutePath()); @@ -2209,8 +2233,7 @@ public void testDecommissionedNMsMetricsOnRMRestart() throws Exception { Resource expectedCapability = Resource.newInstance(nm1.getMemory(), nm1.getvCores()); String expectedVersion = nm1.getVersion(); - Assert - .assertEquals(0, + Assertions.assertEquals(0, ClusterMetrics.getMetrics().getNumDecommisionedNMs()); String ip = NetUtils.normalizeHostName("localhost"); // Add 2 hosts to exclude list. @@ -2219,30 +2242,26 @@ public void testDecommissionedNMsMetricsOnRMRestart() throws Exception { // refresh nodes rm1.getNodesListManager().refreshNodes(conf); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert - .assertTrue( + Assertions.assertTrue( NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertTrue("The decommisioned metrics are not updated", - NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue( + NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction()), "The decommisioned metrics are not updated"); rm1.drainEvents(); - Assert - .assertEquals(2, - ClusterMetrics.getMetrics().getNumDecommisionedNMs()); + Assertions.assertEquals(2, + ClusterMetrics.getMetrics().getNumDecommisionedNMs()); verifyNodesAfterDecom(rm1, 2, expectedCapability, expectedVersion); rm1.stop(); rm1 = null; - Assert - .assertEquals(0, - ClusterMetrics.getMetrics().getNumDecommisionedNMs()); + Assertions.assertEquals(0, + ClusterMetrics.getMetrics().getNumDecommisionedNMs()); // restart RM. rm2 = new MockRM(conf); rm2.start(); rm2.drainEvents(); - Assert - .assertEquals(2, + Assertions.assertEquals(2, ClusterMetrics.getMetrics().getNumDecommisionedNMs()); verifyNodesAfterDecom(rm2, 2, Resource.newInstance(0, 0), "unknown"); } finally { @@ -2260,17 +2279,18 @@ private void verifyNodesAfterDecom(MockRM rm, int numNodes, String expectedVersion) { ConcurrentMap inactiveRMNodes = rm.getRMContext().getInactiveRMNodes(); - Assert.assertEquals(numNodes, inactiveRMNodes.size()); + Assertions.assertEquals(numNodes, inactiveRMNodes.size()); for (RMNode rmNode : inactiveRMNodes.values()) { - Assert.assertEquals(expectedCapability, rmNode.getTotalCapability()); - Assert.assertEquals(expectedVersion, rmNode.getNodeManagerVersion()); + Assertions.assertEquals(expectedCapability, rmNode.getTotalCapability()); + Assertions.assertEquals(expectedVersion, rmNode.getNodeManagerVersion()); } } // Test Delegation token is renewed synchronously so that recover events // can be processed before any other external incoming events, specifically // the ContainerFinished event on NM re-registraton. - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testSynchronouslyRenewDTOnRecovery() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2); conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, @@ -2433,7 +2453,8 @@ protected void doSecureLogin() throws IOException { // 2. Add/remove/replace labels to cluster and node lable and verify // 3. Start RM2 with store patch /tmp only // 4. Get cluster and node lobel, it should be present by recovering it - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testRMRestartRecoveringNodeLabelManager() throws Exception { // Initial FS node label store root dir to a random tmp dir File nodeLabelFsStoreDir = @@ -2492,12 +2513,12 @@ protected RMNodeLabelsManager createNodeLabelManager() { Thread.sleep(500); } - Assert.assertEquals(clusterNodeLabels.size(), nodeLabelManager + Assertions.assertEquals(clusterNodeLabels.size(), nodeLabelManager .getClusterNodeLabelNames().size()); Map> nodeLabels = nodeLabelManager.getNodeLabels(); - Assert.assertEquals(1, nodeLabelManager.getNodeLabels().size()); - Assert.assertTrue(nodeLabels.get(n1).equals(toSet("y"))); + Assertions.assertEquals(1, nodeLabelManager.getNodeLabels().size()); + Assertions.assertTrue(nodeLabels.get(n1).equals(toSet("y"))); MockRM rm2 = new MockRM(conf, rm1.getRMStateStore()) { @Override @@ -2511,17 +2532,18 @@ protected RMNodeLabelsManager createNodeLabelManager() { rm2.start(); nodeLabelManager = rm2.getRMContext().getNodeLabelManager(); - Assert.assertEquals(clusterNodeLabels.size(), + Assertions.assertEquals(clusterNodeLabels.size(), nodeLabelManager.getClusterNodeLabelNames().size()); nodeLabels = nodeLabelManager.getNodeLabels(); - Assert.assertEquals(1, nodeLabelManager.getNodeLabels().size()); - Assert.assertTrue(nodeLabels.get(n1).equals(toSet("y"))); + Assertions.assertEquals(1, nodeLabelManager.getNodeLabels().size()); + Assertions.assertTrue(nodeLabels.get(n1).equals(toSet("y"))); rm1.stop(); rm2.stop(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartFailAppAttempt() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS); @@ -2546,7 +2568,7 @@ public void testRMRestartFailAppAttempt() throws Exception { ApplicationId applicationId = app0.getApplicationId(); ApplicationAttemptId appAttemptId1 = app0.getCurrentAppAttempt().getAppAttemptId(); - Assert.assertEquals(1, appAttemptId1.getAttemptId()); + Assertions.assertEquals(1, appAttemptId1.getAttemptId()); // fail the 1st app attempt. rm1.failApplicationAttempt(appAttemptId1); @@ -2556,7 +2578,7 @@ public void testRMRestartFailAppAttempt() throws Exception { ApplicationAttemptId appAttemptId2 = app0.getCurrentAppAttempt().getAppAttemptId(); - Assert.assertEquals(2, appAttemptId2.getAttemptId()); + Assertions.assertEquals(2, appAttemptId2.getAttemptId()); rm1.waitForState(appAttemptId2, RMAppAttemptState.SCHEDULED); // restart rm @@ -2569,18 +2591,18 @@ public void testRMRestartFailAppAttempt() throws Exception { //Wait to make sure the loadedApp0 has the right number of attempts //TODO explore a better way than sleeping for a while (YARN-4929) Thread.sleep(1000); - Assert.assertEquals(2, loadedApp0.getAppAttempts().size()); + Assertions.assertEquals(2, loadedApp0.getAppAttempts().size()); rm2.waitForState(appAttemptId2, RMAppAttemptState.SCHEDULED); appAttemptId2 = loadedApp0.getCurrentAppAttempt().getAppAttemptId(); - Assert.assertEquals(2, appAttemptId2.getAttemptId()); + Assertions.assertEquals(2, appAttemptId2.getAttemptId()); // fail 2nd attempt rm2.failApplicationAttempt(appAttemptId2); rm2.waitForState(appAttemptId2, RMAppAttemptState.FAILED); rm2.waitForState(applicationId, RMAppState.FAILED); - Assert.assertEquals(maxAttempt, loadedApp0.getAppAttempts().size()); + Assertions.assertEquals(maxAttempt, loadedApp0.getAppAttempts().size()); } private Set toSet(E... elements) { @@ -2588,7 +2610,8 @@ private Set toSet(E... elements) { return set; } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testRMRestartNodeMapping() throws Exception { // Initial FS node label store root dir to a random tmp dir File nodeLabelFsStoreDir = new File("target", @@ -2644,14 +2667,15 @@ protected RMNodeLabelsManager createNodeLabelManager() { nodeLabelManager = rm2.getRMContext().getNodeLabelManager(); Map> labelsToNodes = nodeLabelManager.getLabelsToNodes(toSet("x")); - Assert.assertEquals(1, + Assertions.assertEquals(1, null == labelsToNodes.get("x") ? 0 : labelsToNodes.get("x").size()); } rm1.stop(); rm2.stop(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testRMRestartAfterPreemption() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2); if (!getSchedulerType().equals(SchedulerType.CAPACITY)) { @@ -2701,16 +2725,17 @@ public void testRMRestartAfterPreemption() throws Exception { try { rm2 = new MockRM(conf, memStore); rm2.start(); - Assert.assertTrue("RM start successfully", true); + Assertions.assertTrue(true, "RM start successfully"); } catch (Exception e) { LOG.debug("Exception on start", e); - Assert.fail("RM should start with out any issue"); + Assertions.fail("RM should start with out any issue"); } finally { rm1.stop(); } } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartOnMissingAttempts() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 5); // create RM @@ -2744,22 +2769,22 @@ public void testRMRestartOnMissingAttempts() throws Exception { MockRM rm2 = createMockRM(conf, memStore); rm2.start(); - Assert.assertEquals(1, rm2.getRMContext().getRMApps().size()); + Assertions.assertEquals(1, rm2.getRMContext().getRMApps().size()); RMApp recoveredApp0 = rm2.getRMContext().getRMApps().values() .iterator().next(); Map recoveredAppAttempts = recoveredApp0.getAppAttempts(); - Assert.assertEquals(3, recoveredAppAttempts.size()); - Assert.assertEquals(RMAppAttemptState.FAILED, + Assertions.assertEquals(3, recoveredAppAttempts.size()); + Assertions.assertEquals(RMAppAttemptState.FAILED, recoveredAppAttempts.get( am0.getApplicationAttemptId()).getAppAttemptState()); - Assert.assertEquals(RMAppAttemptState.FAILED, + Assertions.assertEquals(RMAppAttemptState.FAILED, recoveredAppAttempts.get( am2.getApplicationAttemptId()).getAppAttemptState()); - Assert.assertEquals(RMAppAttemptState.LAUNCHED, + Assertions.assertEquals(RMAppAttemptState.LAUNCHED, recoveredAppAttempts.get( am3.getApplicationAttemptId()).getAppAttemptState()); - Assert.assertEquals(5, ((RMAppImpl)app0).getNextAttemptId()); + Assertions.assertEquals(5, ((RMAppImpl)app0).getNextAttemptId()); } private MockAM launchAndFailAM(RMApp app, MockRM rm, MockNM nm) @@ -2770,7 +2795,8 @@ private MockAM launchAndFailAM(RMApp app, MockRM rm, MockNM nm) return am; } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testRMRestartAfterNodeLabelDisabled() throws Exception { if (getSchedulerType() != SchedulerType.CAPACITY) { return; @@ -2828,7 +2854,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1); ContainerId amContainerId1 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 1); - Assert.assertEquals("x", rm1.getRMContext().getScheduler(). + Assertions.assertEquals("x", rm1.getRMContext().getScheduler(). getRMContainer(amContainerId1).getNodeLabelExpression()); finishApplicationMaster(app1, rm1, nm1, am1); @@ -2851,18 +2877,19 @@ protected RMNodeLabelsManager createNodeLabelManager() { try { rm2.start(); - Assert.assertTrue("RM start successfully", true); - Assert.assertEquals(1, rm2.getRMContext().getRMApps().size()); + Assertions.assertTrue(true, "RM start successfully"); + Assertions.assertEquals(1, rm2.getRMContext().getRMApps().size()); } catch (Exception e) { LOG.debug("Exception on start", e); - Assert.fail("RM should start without any issue"); + Assertions.fail("RM should start without any issue"); } finally { rm1.stop(); rm2.stop(); } } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testRMRestartAfterPriorityChangesInAllocatedResponse() throws Exception { conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, @@ -2909,7 +2936,7 @@ public void testRMRestartAfterPriorityChangesInAllocatedResponse() allocateRequest.setAskList(ask); AllocateResponse response1 = am1.allocate(allocateRequest); - Assert.assertEquals(appPriority1, response1.getApplicationPriority()); + Assertions.assertEquals(appPriority1, response1.getApplicationPriority()); // Change the priority of App1 to 8 Priority appPriority2 = Priority.newInstance(8); @@ -2919,7 +2946,7 @@ public void testRMRestartAfterPriorityChangesInAllocatedResponse() app1.getApplicationId(), appPriority2); AllocateResponse response2 = am1.allocate(allocateRequest); - Assert.assertEquals(appPriority2, response2.getApplicationPriority()); + Assertions.assertEquals(appPriority2, response2.getApplicationPriority()); /* * Ensure tokensConf has been retained even after UPDATE_APP event in @@ -2930,7 +2957,7 @@ public void testRMRestartAfterPriorityChangesInAllocatedResponse() memStore.getState().getApplicationState(); ApplicationStateData appState = rmAppState.get(app1.getApplicationId()); - Assert.assertEquals(getTokensConf(), + Assertions.assertEquals(getTokensConf(), appState.getApplicationSubmissionContext(). getAMContainerSpec().getTokensConf()); @@ -2939,7 +2966,7 @@ public void testRMRestartAfterPriorityChangesInAllocatedResponse() rm2.start(); AllocateResponse response3 = am1.allocate(allocateRequest); - Assert.assertEquals(appPriority2, response3.getApplicationPriority()); + Assertions.assertEquals(appPriority2, response3.getApplicationPriority()); /* * Ensure tokensConf has been retained even after RECOVER event in @@ -2949,7 +2976,7 @@ public void testRMRestartAfterPriorityChangesInAllocatedResponse() memStore.getState().getApplicationState(); ApplicationStateData appStateNew = rmAppStateNew.get(app1.getApplicationId()); - Assert.assertEquals(getTokensConf(), + Assertions.assertEquals(getTokensConf(), appStateNew.getApplicationSubmissionContext(). getAMContainerSpec().getTokensConf()); @@ -2957,7 +2984,8 @@ public void testRMRestartAfterPriorityChangesInAllocatedResponse() rm2.stop(); } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testRMRestartAfterUpdateTrackingUrl() throws Exception { MockRM rm = new MockRM(conf); rm.start(); @@ -2980,21 +3008,21 @@ public void testRMRestartAfterUpdateTrackingUrl() throws Exception { am1.allocate(allocateRequest); // Check in-memory and stored tracking url - Assert.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( + Assertions.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( app1.getApplicationId()).getOriginalTrackingUrl()); - Assert.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( + Assertions.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( app1.getApplicationId()).getCurrentAppAttempt() .getOriginalTrackingUrl()); - Assert.assertEquals(newTrackingUrl, memStore.getState() + Assertions.assertEquals(newTrackingUrl, memStore.getState() .getApplicationState().get(app1.getApplicationId()) .getAttempt(attempt1.getAppAttemptId()).getFinalTrackingUrl()); // Start new RM, should recover updated tracking url MockRM rm2 = new MockRM(conf, memStore); rm2.start(); - Assert.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( + Assertions.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( app1.getApplicationId()).getOriginalTrackingUrl()); - Assert.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( + Assertions.assertEquals(newTrackingUrl, rm.getRMContext().getRMApps().get( app1.getApplicationId()).getCurrentAppAttempt() .getOriginalTrackingUrl()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMServerUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMServerUtils.java index 95cc98339296e..c165a74ca003c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMServerUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMServerUtils.java @@ -53,8 +53,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -112,22 +112,22 @@ public void testValidateAndSplitUpdateResourceRequests() { ContainerUpdates containerUpdates = RMServerUtils.validateAndSplitUpdateResourceRequests(rmContext, allocateRequest, maxAllocation, updateErrors); - Assert.assertEquals(1, updateErrors.size()); - Assert.assertEquals(resource + 1, updateErrors.get(0) + Assertions.assertEquals(1, updateErrors.size()); + Assertions.assertEquals(resource + 1, updateErrors.get(0) .getUpdateContainerRequest().getCapability().getMemorySize()); - Assert.assertEquals(resource + 1, updateErrors.get(0) + Assertions.assertEquals(resource + 1, updateErrors.get(0) .getUpdateContainerRequest().getCapability().getVirtualCores()); - Assert.assertEquals(RESOURCE_OUTSIDE_ALLOWED_RANGE, + Assertions.assertEquals(RESOURCE_OUTSIDE_ALLOWED_RANGE, updateErrors.get(0).getReason()); - Assert.assertEquals(1, containerUpdates.getIncreaseRequests().size()); + Assertions.assertEquals(1, containerUpdates.getIncreaseRequests().size()); UpdateContainerRequest increaseRequest = containerUpdates.getIncreaseRequests().get(0); - Assert.assertEquals(capabilityOk.getVirtualCores(), + Assertions.assertEquals(capabilityOk.getVirtualCores(), increaseRequest.getCapability().getVirtualCores()); - Assert.assertEquals(capabilityOk.getMemorySize(), + Assertions.assertEquals(capabilityOk.getMemorySize(), increaseRequest.getCapability().getMemorySize()); - Assert.assertEquals(containerIdOk, increaseRequest.getContainerId()); + Assertions.assertEquals(containerIdOk, increaseRequest.getContainerId()); } @Test @@ -142,22 +142,22 @@ public void testQueryRMNodes() throws Exception { when(rmContext.getInactiveRMNodes()).thenReturn(inactiveList); List result = RMServerUtils.queryRMNodes(rmContext, EnumSet.of(NodeState.SHUTDOWN)); - Assert.assertTrue(result.size() != 0); + Assertions.assertTrue(result.size() != 0); assertThat(result.get(0)).isEqualTo(rmNode1); when(rmNode1.getState()).thenReturn(NodeState.DECOMMISSIONED); result = RMServerUtils.queryRMNodes(rmContext, EnumSet.of(NodeState.DECOMMISSIONED)); - Assert.assertTrue(result.size() != 0); + Assertions.assertTrue(result.size() != 0); assertThat(result.get(0)).isEqualTo(rmNode1); when(rmNode1.getState()).thenReturn(NodeState.LOST); result = RMServerUtils.queryRMNodes(rmContext, EnumSet.of(NodeState.LOST)); - Assert.assertTrue(result.size() != 0); + Assertions.assertTrue(result.size() != 0); assertThat(result.get(0)).isEqualTo(rmNode1); when(rmNode1.getState()).thenReturn(NodeState.REBOOTED); result = RMServerUtils.queryRMNodes(rmContext, EnumSet.of(NodeState.REBOOTED)); - Assert.assertTrue(result.size() != 0); + Assertions.assertTrue(result.size() != 0); assertThat(result.get(0)).isEqualTo(rmNode1); } @@ -187,46 +187,46 @@ public void testGetApplicableNodeCountForAMLocality() throws Exception { true, null); List reqs = new ArrayList<>(); reqs.add(anyReq); - Assert.assertEquals(100, + Assertions.assertEquals(100, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); ResourceRequest rackReq = createResourceRequest("/rack1", true, null); reqs.add(rackReq); - Assert.assertEquals(30, + Assertions.assertEquals(30, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); anyReq.setRelaxLocality(false); - Assert.assertEquals(30, + Assertions.assertEquals(30, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(false); - Assert.assertEquals(100, + Assertions.assertEquals(100, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); ResourceRequest node1Req = createResourceRequest("node1", false, null); reqs.add(node1Req); - Assert.assertEquals(100, + Assertions.assertEquals(100, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node1Req.setRelaxLocality(true); - Assert.assertEquals(1, + Assertions.assertEquals(1, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(true); - Assert.assertEquals(31, + Assertions.assertEquals(31, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); ResourceRequest node2Req = createResourceRequest("node2", false, null); reqs.add(node2Req); - Assert.assertEquals(31, + Assertions.assertEquals(31, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node2Req.setRelaxLocality(true); - Assert.assertEquals(31, + Assertions.assertEquals(31, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(false); - Assert.assertEquals(2, + Assertions.assertEquals(2, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node1Req.setRelaxLocality(false); - Assert.assertEquals(1, + Assertions.assertEquals(1, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node2Req.setRelaxLocality(false); - Assert.assertEquals(100, + Assertions.assertEquals(100, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); } @@ -261,10 +261,10 @@ public void testGetApplicableNodeCountForAMLabels() throws Exception { true, null); List reqs = new ArrayList<>(); reqs.add(anyReq); - Assert.assertEquals(80, + Assertions.assertEquals(80, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); anyReq.setNodeLabelExpression("label1"); - Assert.assertEquals(10, + Assertions.assertEquals(10, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); } @@ -320,46 +320,46 @@ public void testGetApplicableNodeCountForAMLocalityAndLabels() true, null); List reqs = new ArrayList<>(); reqs.add(anyReq); - Assert.assertEquals(80, + Assertions.assertEquals(80, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); ResourceRequest rackReq = createResourceRequest("/rack1", true, null); reqs.add(rackReq); - Assert.assertEquals(20, + Assertions.assertEquals(20, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); anyReq.setRelaxLocality(false); - Assert.assertEquals(20, + Assertions.assertEquals(20, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(false); - Assert.assertEquals(80, + Assertions.assertEquals(80, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); ResourceRequest node1Req = createResourceRequest("node1", false, null); reqs.add(node1Req); - Assert.assertEquals(80, + Assertions.assertEquals(80, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node1Req.setRelaxLocality(true); - Assert.assertEquals(0, + Assertions.assertEquals(0, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(true); - Assert.assertEquals(20, + Assertions.assertEquals(20, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); ResourceRequest node2Req = createResourceRequest("node2", false, null); reqs.add(node2Req); - Assert.assertEquals(20, + Assertions.assertEquals(20, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node2Req.setRelaxLocality(true); - Assert.assertEquals(20, + Assertions.assertEquals(20, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(false); - Assert.assertEquals(1, + Assertions.assertEquals(1, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node1Req.setRelaxLocality(false); - Assert.assertEquals(1, + Assertions.assertEquals(1, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node2Req.setRelaxLocality(false); - Assert.assertEquals(80, + Assertions.assertEquals(80, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); anyReq.setNodeLabelExpression("label1"); @@ -369,65 +369,65 @@ public void testGetApplicableNodeCountForAMLocalityAndLabels() anyReq.setRelaxLocality(true); reqs = new ArrayList<>(); reqs.add(anyReq); - Assert.assertEquals(15, + Assertions.assertEquals(15, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(true); reqs.add(rackReq); - Assert.assertEquals(10, + Assertions.assertEquals(10, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); anyReq.setRelaxLocality(false); - Assert.assertEquals(10, + Assertions.assertEquals(10, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(false); - Assert.assertEquals(15, + Assertions.assertEquals(15, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node1Req.setRelaxLocality(false); reqs.add(node1Req); - Assert.assertEquals(15, + Assertions.assertEquals(15, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node1Req.setRelaxLocality(true); - Assert.assertEquals(1, + Assertions.assertEquals(1, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(true); - Assert.assertEquals(11, + Assertions.assertEquals(11, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node2Req.setRelaxLocality(false); reqs.add(node2Req); - Assert.assertEquals(11, + Assertions.assertEquals(11, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node2Req.setRelaxLocality(true); - Assert.assertEquals(11, + Assertions.assertEquals(11, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); rackReq.setRelaxLocality(false); - Assert.assertEquals(1, + Assertions.assertEquals(1, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node1Req.setRelaxLocality(false); - Assert.assertEquals(0, + Assertions.assertEquals(0, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); node2Req.setRelaxLocality(false); - Assert.assertEquals(15, + Assertions.assertEquals(15, RMServerUtils.getApplicableNodeCountForAM(rmContext, conf, reqs)); } @Test public void testConvertRmAppAttemptStateToYarnApplicationAttemptState() { - Assert.assertEquals( + Assertions.assertEquals( YarnApplicationAttemptState.FAILED, RMServerUtils.convertRmAppAttemptStateToYarnApplicationAttemptState( RMAppAttemptState.FINAL_SAVING, RMAppAttemptState.FAILED ) ); - Assert.assertEquals( + Assertions.assertEquals( YarnApplicationAttemptState.SCHEDULED, RMServerUtils.convertRmAppAttemptStateToYarnApplicationAttemptState( RMAppAttemptState.FINAL_SAVING, RMAppAttemptState.SCHEDULED ) ); - Assert.assertEquals( + Assertions.assertEquals( YarnApplicationAttemptState.NEW, RMServerUtils.convertRmAppAttemptStateToYarnApplicationAttemptState( RMAppAttemptState.NEW, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMStoreCommands.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMStoreCommands.java index e2c78345d533b..25523485f3cf5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMStoreCommands.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMStoreCommands.java @@ -18,11 +18,11 @@ package org.apache.hadoop.yarn.server.resourcemanager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -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.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 org.apache.curator.framework.CuratorFramework; import org.apache.curator.test.TestingServer; @@ -34,7 +34,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.recovery.RMStateStore; import org.apache.hadoop.yarn.server.resourcemanager.recovery.TestZKRMStateStore; import org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestRMStoreCommands { @@ -52,9 +52,9 @@ public void testFormatStateStoreCmdForZK() throws Exception { rm.start(); rm.getRMContext().getRMAdminService().transitionToActive(req); String zkStateRoot = ZKRMStateStore.ROOT_ZNODE_NAME; - assertEquals("RM State store parent path should have a child node " + - zkStateRoot, zkStateRoot, curatorFramework.getChildren().forPath( - YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH).get(0)); + assertEquals(zkStateRoot, curatorFramework.getChildren().forPath( + YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH).get(0), "RM State store parent path should have a child node " + + zkStateRoot); rm.close(); try { ResourceManager.deleteRMStateStore(conf); @@ -62,9 +62,9 @@ public void testFormatStateStoreCmdForZK() throws Exception { fail("Exception should not be thrown during format rm state store" + " operation."); } - assertTrue("After store format parent path should have no child nodes", - curatorFramework.getChildren().forPath( - YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH).isEmpty()); + assertTrue( + curatorFramework.getChildren().forPath( + YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH).isEmpty(), "After store format parent path should have no child nodes"); } } @@ -86,8 +86,8 @@ public void testFormatConfStoreCmdForZK() throws Exception { YarnConfiguration.RM_SCHEDCONF_STORE_ZK_PARENT_PATH, YarnConfiguration.DEFAULT_RM_SCHEDCONF_STORE_ZK_PARENT_PATH) + "/CONF_STORE"; - assertNotNull("Failed to initialize ZKConfigurationStore", - curatorFramework.checkExists().forPath(confStorePath)); + assertNotNull( + curatorFramework.checkExists().forPath(confStorePath), "Failed to initialize ZKConfigurationStore"); rm.close(); try { @@ -96,8 +96,8 @@ public void testFormatConfStoreCmdForZK() throws Exception { fail("Exception should not be thrown during format rm conf store" + " operation."); } - assertNull("Failed to format ZKConfigurationStore", - curatorFramework.checkExists().forPath(confStorePath)); + assertNull( + curatorFramework.checkExists().forPath(confStorePath), "Failed to format ZKConfigurationStore"); } } @@ -126,8 +126,8 @@ public void testRemoveApplicationFromStateStoreCmdForZK() throws Exception { if (path.equals(ZKRMStateStore.RM_APP_ROOT_HIERARCHIES)) { continue; } - assertEquals("Application node for " + appId + " should exist", - appId, path); + assertEquals( + appId, path, "Application node for " + appId + " should exist"); } try { ResourceManager.removeApplication(conf, appId); @@ -135,11 +135,11 @@ public void testRemoveApplicationFromStateStoreCmdForZK() throws Exception { fail("Exception should not be thrown while removing app from " + "rm state store."); } - assertTrue("After remove app from store there should be no child nodes" + - " for application in app root path", - curatorFramework.getChildren().forPath(appRootPath).size() == 1 && + assertTrue( + curatorFramework.getChildren().forPath(appRootPath).size() == 1 && curatorFramework.getChildren().forPath(appRootPath).get(0).equals( - ZKRMStateStore.RM_APP_ROOT_HIERARCHIES)); + ZKRMStateStore.RM_APP_ROOT_HIERARCHIES), "After remove app from store there should be no child nodes" + + " for application in app root path"); } } } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMTimelineService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMTimelineService.java index 795979cd1cea1..4aa011dee2a8c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMTimelineService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMTimelineService.java @@ -28,8 +28,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore; import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineWriterImpl; import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineWriter; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Tests that the RM creates timeline services (v1/v2) as specified by the @@ -41,7 +41,7 @@ public class TestRMTimelineService { private void setup(boolean v1Enabled, boolean v2Enabled, boolean systemMetricEnabled) { Configuration conf = new YarnConfiguration(new Configuration(false)); - Assert.assertFalse(YarnConfiguration.timelineServiceEnabled(conf)); + Assertions.assertFalse(YarnConfiguration.timelineServiceEnabled(conf)); conf.setBoolean(YarnConfiguration.SYSTEM_METRICS_PUBLISHER_ENABLED, systemMetricEnabled); @@ -87,11 +87,11 @@ private void validate(boolean v1Enabled, boolean v2Enabled, } if(systemMetricEnabled) { - Assert.assertEquals(v1Enabled, v1PublisherServiceFound); - Assert.assertEquals(v2Enabled, v2PublisherServiceFound); + Assertions.assertEquals(v1Enabled, v1PublisherServiceFound); + Assertions.assertEquals(v2Enabled, v2PublisherServiceFound); } else { - Assert.assertEquals(false, v1PublisherServiceFound); - Assert.assertEquals(false, v2PublisherServiceFound); + Assertions.assertEquals(false, v1PublisherServiceFound); + Assertions.assertEquals(false, v2PublisherServiceFound); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestReservationSystemWithRMHA.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestReservationSystemWithRMHA.java index 239fbf3832f21..05c3d4828eab1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestReservationSystemWithRMHA.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestReservationSystemWithRMHA.java @@ -39,8 +39,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.UTCClock; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -75,10 +75,10 @@ public void testSubmitReservationAndCheckAfterFailover() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(reservationID); + Assertions.assertNotNull(response); + Assertions.assertNotNull(reservationID); LOG.info("Submit reservation response: " + reservationID); // Do the failover @@ -89,8 +89,8 @@ public void testSubmitReservationAndCheckAfterFailover() throws Exception { RMState state = rm2.getRMContext().getStateStore().loadState(); Map reservationStateMap = state.getReservationState().get(ReservationSystemTestUtil.reservationQ); - Assert.assertNotNull(reservationStateMap); - Assert.assertNotNull(reservationStateMap.get(reservationID)); + Assertions.assertNotNull(reservationStateMap); + Assertions.assertNotNull(reservationStateMap.get(reservationID)); } @Test @@ -111,10 +111,10 @@ public void testUpdateReservationAndCheckAfterFailover() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(reservationID); + Assertions.assertNotNull(response); + Assertions.assertNotNull(reservationID); LOG.info("Submit reservation response: " + reservationID); ReservationDefinition reservationDefinition = request.getReservationDefinition(); @@ -135,10 +135,10 @@ public void testUpdateReservationAndCheckAfterFailover() throws Exception { RMState state = rm2.getRMContext().getStateStore().loadState(); Map reservationStateMap = state.getReservationState().get(ReservationSystemTestUtil.reservationQ); - Assert.assertNotNull(reservationStateMap); + Assertions.assertNotNull(reservationStateMap); ReservationAllocationStateProto reservationState = reservationStateMap.get(reservationID); - Assert.assertEquals(newDeadline, + Assertions.assertEquals(newDeadline, reservationState.getReservationDefinition().getDeadline()); } @@ -160,10 +160,10 @@ public void testDeleteReservationAndCheckAfterFailover() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(reservationID); + Assertions.assertNotNull(response); + Assertions.assertNotNull(reservationID); // Delete the reservation ReservationDeleteRequest deleteRequest = @@ -176,7 +176,7 @@ public void testDeleteReservationAndCheckAfterFailover() throws Exception { rm2.registerNode("127.0.0.1:1", 102400, 100); RMState state = rm2.getRMContext().getStateStore().loadState(); - Assert.assertNull(state.getReservationState() + Assertions.assertNull(state.getReservationState() .get(ReservationSystemTestUtil.reservationQ)); } @@ -197,12 +197,12 @@ private void addNodeCapacityToPlan(MockRM rm, int memory, int vCores) { Thread.sleep(1000); } while (attempts-- > 0); if (attempts <= 0) { - Assert.fail("Exhausted attempts in checking if node capacity was " + Assertions.fail("Exhausted attempts in checking if node capacity was " + "added to the plan"); } } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } @@ -219,8 +219,8 @@ private ReservationSubmissionRequest createReservationSubmissionRequest( private void validateReservation(Plan plan, ReservationId resId, ReservationDefinition rDef) { ReservationAllocation reservation = plan.getReservationById(resId); - Assert.assertNotNull(reservation); - Assert.assertEquals(rDef.getDeadline(), + Assertions.assertNotNull(reservation); + Assertions.assertEquals(rDef.getDeadline(), reservation.getReservationDefinition().getDeadline()); } @@ -242,10 +242,10 @@ public void testSubmitReservationFailoverAndDelete() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(reservationID); + Assertions.assertNotNull(response); + Assertions.assertNotNull(reservationID); LOG.info("Submit reservation response: " + reservationID); ReservationDefinition reservationDefinition = request.getReservationDefinition(); @@ -268,10 +268,10 @@ public void testSubmitReservationFailoverAndDelete() throws Exception { try { deleteResponse = clientService.deleteReservation(deleteRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(deleteResponse); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNotNull(deleteResponse); + Assertions.assertNull(plan.getReservationById(reservationID)); } @Test @@ -296,10 +296,10 @@ public void testFailoverAndSubmitReservation() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(reservationID); + Assertions.assertNotNull(response); + Assertions.assertNotNull(reservationID); LOG.info("Submit reservation response: " + reservationID); ReservationDefinition reservationDefinition = request.getReservationDefinition(); @@ -328,10 +328,10 @@ public void testSubmitReservationFailoverAndUpdate() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(reservationID); + Assertions.assertNotNull(response); + Assertions.assertNotNull(reservationID); LOG.info("Submit reservation response: " + reservationID); ReservationDefinition reservationDefinition = request.getReservationDefinition(); @@ -356,9 +356,9 @@ public void testSubmitReservationFailoverAndUpdate() throws Exception { try { updateResponse = clientService.updateReservation(updateRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(updateResponse); + Assertions.assertNotNull(updateResponse); validateReservation(plan, reservationID, reservationDefinition); } @@ -380,10 +380,10 @@ public void testSubmitUpdateReservationFailoverAndDelete() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(reservationID); + Assertions.assertNotNull(response); + Assertions.assertNotNull(reservationID); LOG.info("Submit reservation response: " + reservationID); ReservationDefinition reservationDefinition = request.getReservationDefinition(); @@ -402,9 +402,9 @@ public void testSubmitUpdateReservationFailoverAndDelete() throws Exception { try { updateResponse = clientService.updateReservation(updateRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(updateResponse); + Assertions.assertNotNull(updateResponse); validateReservation(plan, reservationID, reservationDefinition); // Do the failover @@ -425,10 +425,10 @@ public void testSubmitUpdateReservationFailoverAndDelete() throws Exception { try { deleteResponse = clientService.deleteReservation(deleteRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(deleteResponse); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNotNull(deleteResponse); + Assertions.assertNull(plan.getReservationById(reservationID)); } @Test @@ -451,10 +451,10 @@ public void testReservationResizeAfterFailover() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(resID1); + Assertions.assertNotNull(response); + Assertions.assertNotNull(resID1); LOG.info("Submit reservation response: " + resID1); ReservationId resID2 = getNewReservation(clientService) @@ -463,10 +463,10 @@ public void testReservationResizeAfterFailover() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(resID2); + Assertions.assertNotNull(response); + Assertions.assertNotNull(resID2); LOG.info("Submit reservation response: " + resID2); ReservationId resID3 = getNewReservation(clientService) @@ -475,10 +475,10 @@ public void testReservationResizeAfterFailover() throws Exception { try { response = clientService.submitReservation(request); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(response); - Assert.assertNotNull(resID3); + Assertions.assertNotNull(response); + Assertions.assertNotNull(resID3); LOG.info("Submit reservation response: " + resID3); // allow the reservations to become active @@ -493,11 +493,11 @@ public void testReservationResizeAfterFailover() throws Exception { validateReservation(plan, resID3, reservationDefinition); ResourceScheduler scheduler = rm1.getResourceScheduler(); QueueInfo resQ1 = scheduler.getQueueInfo(resID1.toString(), false, false); - Assert.assertEquals(0.05, resQ1.getCapacity(), 0.001f); + Assertions.assertEquals(0.05, resQ1.getCapacity(), 0.001f); QueueInfo resQ2 = scheduler.getQueueInfo(resID2.toString(), false, false); - Assert.assertEquals(0.05, resQ2.getCapacity(), 0.001f); + Assertions.assertEquals(0.05, resQ2.getCapacity(), 0.001f); QueueInfo resQ3 = scheduler.getQueueInfo(resID3.toString(), false, false); - Assert.assertEquals(0.05, resQ3.getCapacity(), 0.001f); + Assertions.assertEquals(0.05, resQ3.getCapacity(), 0.001f); // Do the failover explicitFailover(); @@ -513,11 +513,11 @@ public void testReservationResizeAfterFailover() throws Exception { // verify if the reservations have been resized scheduler = rm2.getResourceScheduler(); resQ1 = scheduler.getQueueInfo(resID1.toString(), false, false); - Assert.assertEquals(1f / 3f, resQ1.getCapacity(), 0.001f); + Assertions.assertEquals(1f / 3f, resQ1.getCapacity(), 0.001f); resQ2 = scheduler.getQueueInfo(resID2.toString(), false, false); - Assert.assertEquals(1f / 3f, resQ2.getCapacity(), 0.001f); + Assertions.assertEquals(1f / 3f, resQ2.getCapacity(), 0.001f); resQ3 = scheduler.getQueueInfo(resID3.toString(), false, false); - Assert.assertEquals(1f / 3f, resQ3.getCapacity(), 0.001f); + Assertions.assertEquals(1f / 3f, resQ3.getCapacity(), 0.001f); } private void waitForReservationActivation(MockRM rm, @@ -536,11 +536,11 @@ private void waitForReservationActivation(MockRM rm, Thread.sleep(100); } while (attempts-- > 0); if (attempts <= 0) { - Assert + Assertions .fail("Exceeded attempts in waiting for reservation to be active"); } } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } @@ -553,7 +553,7 @@ private GetNewReservationResponse getNewReservation(ClientRMService getNewReservationResponse = clientRMService.getNewReservation( newReservationRequest); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } return getNewReservationResponse; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceManager.java index b9c5500a7d20b..966e86cf22f5e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceManager.java @@ -19,8 +19,8 @@ package org.apache.hadoop.yarn.server.resourcemanager; import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.Collection; @@ -51,11 +51,12 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.converter.FSConfigConverterTestCommons; import org.apache.hadoop.yarn.server.security.http.RMAuthenticationFilterInitializer; 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.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.rules.ExpectedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,7 +71,7 @@ public class TestResourceManager { public ExpectedException thrown = ExpectedException.none(); private FSConfigConverterTestCommons converterTestCommons; - @Before + @BeforeEach public void setUp() throws Exception { YarnConfiguration conf = new YarnConfiguration(); UserGroupInformation.setConfiguration(conf); @@ -84,7 +85,7 @@ public void setUp() throws Exception { converterTestCommons.setUp(); } - @After + @AfterEach public void tearDown() throws Exception { resourceManager.stop(); converterTestCommons.tearDown(); @@ -245,7 +246,8 @@ private void checkResourceUsage( } } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testResourceManagerInitConfigValidation() throws Exception { Configuration conf = new YarnConfiguration(); conf.setInt(YarnConfiguration.GLOBAL_RM_AM_MAX_ATTEMPTS, -1); @@ -287,7 +289,8 @@ public void testNMExpiryAndHeartbeatIntervalsValidation() throws Exception { } } - @Test(timeout = 50000) + @Test + @Timeout(value = 50) public void testFilterOverrides() throws Exception { String filterInitializerConfKey = "hadoop.http.filter.initializers"; String[] filterInitializers = @@ -326,10 +329,10 @@ protected void doSecureLogin() throws IOException { // just want to test filter settings String tmp = resourceManager.getConfig().get(filterInitializerConfKey); if (filterInitializer.contains(this.getClass().getName())) { - Assert.assertEquals(RMAuthenticationFilterInitializer.class.getName() + Assertions.assertEquals(RMAuthenticationFilterInitializer.class.getName() + "," + this.getClass().getName(), tmp); } else { - Assert.assertEquals( + Assertions.assertEquals( RMAuthenticationFilterInitializer.class.getName(), tmp); } resourceManager.stop(); @@ -352,10 +355,10 @@ protected void doSecureLogin() throws IOException { // just want to test filter settings String tmp = resourceManager.getConfig().get(filterInitializerConfKey); if (filterInitializer.equals(StaticUserWebFilter.class.getName())) { - Assert.assertEquals(RMAuthenticationFilterInitializer.class.getName() + Assertions.assertEquals(RMAuthenticationFilterInitializer.class.getName() + "," + StaticUserWebFilter.class.getName(), tmp); } else { - Assert.assertEquals( + Assertions.assertEquals( RMAuthenticationFilterInitializer.class.getName(), tmp); } resourceManager.stop(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceManagerMXBean.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceManagerMXBean.java index 0e70b5f1c3897..3ceaf53958383 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceManagerMXBean.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceManagerMXBean.java @@ -22,8 +22,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.management.MBeanServer; import javax.management.ObjectName; @@ -50,7 +50,7 @@ public void testResourceManagerMXBean() throws Exception { // Get attribute "SecurityEnabled" boolean securityEnabled = (boolean) mbs.getAttribute(mxbeanName, "SecurityEnabled"); - Assert.assertEquals(resourceManager.isSecurityEnabled(), securityEnabled); + Assertions.assertEquals(resourceManager.isSecurityEnabled(), securityEnabled); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java index bd7548081fde4..6f52d768a1d94 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestResourceTrackerService.java @@ -36,7 +36,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.FileSystemNodeAttributeStore; import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -148,9 +148,10 @@ import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.util.YarnVersionInfo; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -174,7 +175,8 @@ public class TestResourceTrackerService extends NodeLabelTestBase { * Test RM read NM next heartBeat Interval correctly from Configuration file, * and NM get next heartBeat Interval from RM correctly */ - @Test (timeout = 50000) + @Test + @Timeout(value = 50) public void testGetNextHeartBeatInterval() throws Exception { Configuration conf = new Configuration(); conf.set(YarnConfiguration.RM_NM_HEARTBEAT_INTERVAL_MS, "4000"); @@ -186,10 +188,10 @@ public void testGetNextHeartBeatInterval() throws Exception { MockNM nm2 = rm.registerNode("host2:5678", 10240); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertEquals(4000, nodeHeartbeat.getNextHeartBeatInterval()); + Assertions.assertEquals(4000, nodeHeartbeat.getNextHeartBeatInterval()); NodeHeartbeatResponse nodeHeartbeat2 = nm2.nodeHeartbeat(true); - Assert.assertEquals(4000, nodeHeartbeat2.getNextHeartBeatInterval()); + Assertions.assertEquals(4000, nodeHeartbeat2.getNextHeartBeatInterval()); } @@ -216,11 +218,11 @@ public void testDecommissionWithIncludeHosts() throws Exception { int metricCount = metrics.getNumDecommisionedNMs(); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm3.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); // To test that IPs also work String ip = NetUtils.normalizeHostName("localhost"); @@ -231,17 +233,17 @@ public void testDecommissionWithIncludeHosts() throws Exception { checkShutdownNMCount(rm, ++metricCount); nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); - Assert + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions .assertEquals(1, ClusterMetrics.getMetrics().getNumShutdownNMs()); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertTrue("Node is not decommisioned.", NodeAction.SHUTDOWN - .equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.SHUTDOWN + .equals(nodeHeartbeat.getNodeAction()), "Node is not decommisioned."); nodeHeartbeat = nm3.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); - Assert.assertEquals(metricCount, ClusterMetrics.getMetrics() + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertEquals(metricCount, ClusterMetrics.getMetrics() .getNumShutdownNMs()); rm.stop(); } @@ -266,9 +268,9 @@ public void testDecommissionWithExcludeHosts() throws Exception { int metricCount = ClusterMetrics.getMetrics().getNumDecommisionedNMs(); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); rm.drainEvents(); // To test that IPs also work @@ -280,14 +282,14 @@ public void testDecommissionWithExcludeHosts() throws Exception { checkDecommissionedNMCount(rm, metricCount + 2); nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertTrue("The decommisioned metrics are not updated", - NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue( + NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction()), "The decommisioned metrics are not updated"); nodeHeartbeat = nm3.nodeHeartbeat(true); - Assert.assertTrue("The decommisioned metrics are not updated", - NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue( + NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction()), "The decommisioned metrics are not updated"); rm.drainEvents(); writeToHostsFile(""); @@ -296,7 +298,7 @@ public void testDecommissionWithExcludeHosts() throws Exception { nm3 = rm.registerNode("localhost:4433", 1024); nodeHeartbeat = nm3.nodeHeartbeat(true); rm.drainEvents(); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); // decommissined node is 1 since 1 node is rejoined after updating exclude // file checkDecommissionedNMCount(rm, metricCount + 1); @@ -324,9 +326,9 @@ public void testGracefulDecommissionNoApp() throws Exception { NodeHeartbeatResponse nodeHeartbeat2 = nm2.nodeHeartbeat(true); NodeHeartbeatResponse nodeHeartbeat3 = nm3.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat1.getNodeAction())); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat2.getNodeAction())); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat3.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat1.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat2.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat3.getNodeAction())); rm.waitForState(nm2.getNodeId(), NodeState.RUNNING); rm.waitForState(nm3.getNodeId(), NodeState.RUNNING); @@ -346,9 +348,9 @@ public void testGracefulDecommissionNoApp() throws Exception { rm.waitForState(nm2.getNodeId(), NodeState.DECOMMISSIONED); rm.waitForState(nm3.getNodeId(), NodeState.DECOMMISSIONED); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat1.getNodeAction())); - Assert.assertEquals(NodeAction.SHUTDOWN, nodeHeartbeat2.getNodeAction()); - Assert.assertEquals(NodeAction.SHUTDOWN, nodeHeartbeat3.getNodeAction()); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat1.getNodeAction())); + Assertions.assertEquals(NodeAction.SHUTDOWN, nodeHeartbeat2.getNodeAction()); + Assertions.assertEquals(NodeAction.SHUTDOWN, nodeHeartbeat3.getNodeAction()); } @Test @@ -371,11 +373,11 @@ public void testGracefulDecommissionDefaultTimeoutResolution() NodeHeartbeatResponse nodeHeartbeat2 = nm2.nodeHeartbeat(true); NodeHeartbeatResponse nodeHeartbeat3 = nm3.nodeHeartbeat(true); - Assert.assertTrue( + Assertions.assertTrue( NodeAction.NORMAL.equals(nodeHeartbeat1.getNodeAction())); - Assert.assertTrue( + Assertions.assertTrue( NodeAction.NORMAL.equals(nodeHeartbeat2.getNodeAction())); - Assert.assertTrue( + Assertions.assertTrue( NodeAction.NORMAL.equals(nodeHeartbeat3.getNodeAction())); rm.waitForState(nm1.getNodeId(), NodeState.RUNNING); @@ -392,12 +394,12 @@ public void testGracefulDecommissionDefaultTimeoutResolution() rm.getNodesListManager().refreshNodes(conf, true); rm.waitForState(nm1.getNodeId(), NodeState.DECOMMISSIONING); rm.waitForState(nm2.getNodeId(), NodeState.DECOMMISSIONING); - Assert.assertEquals( + Assertions.assertEquals( nm1DecommissionTimeout, rm.getDecommissioningTimeout(nm1.getNodeId())); Integer defaultDecTimeout = conf.getInt(YarnConfiguration.RM_NODE_GRACEFUL_DECOMMISSION_TIMEOUT, YarnConfiguration.DEFAULT_RM_NODE_GRACEFUL_DECOMMISSION_TIMEOUT); - Assert.assertEquals( + Assertions.assertEquals( defaultDecTimeout, rm.getDecommissioningTimeout(nm2.getNodeId())); // Graceful decommission host3 with a new default timeout @@ -408,7 +410,7 @@ public void testGracefulDecommissionDefaultTimeoutResolution() newDefaultDecTimeout); rm.getNodesListManager().refreshNodes(conf, true); rm.waitForState(nm3.getNodeId(), NodeState.DECOMMISSIONING); - Assert.assertEquals( + Assertions.assertEquals( newDefaultDecTimeout, rm.getDecommissioningTimeout(nm3.getNodeId())); } @@ -458,13 +460,13 @@ public void testGracefulDecommissionWithApp() throws Exception { // Since the app is still RUNNING, expect NodeAction.NORMAL. NodeHeartbeatResponse nodeHeartbeat1 = nm1.nodeHeartbeat(aaid, 2, ContainerState.COMPLETE); - Assert.assertEquals(NodeAction.NORMAL, nodeHeartbeat1.getNodeAction()); + Assertions.assertEquals(NodeAction.NORMAL, nodeHeartbeat1.getNodeAction()); // Finish the app and verified DECOMMISSIONED. MockRM.finishAMAndVerifyAppState(app, rm, nm1, am); rm.waitForState(app.getApplicationId(), RMAppState.FINISHED); nodeHeartbeat1 = nm1.nodeHeartbeat(aaid, 2, ContainerState.COMPLETE); - Assert.assertEquals(NodeAction.SHUTDOWN, nodeHeartbeat1.getNodeAction()); + Assertions.assertEquals(NodeAction.SHUTDOWN, nodeHeartbeat1.getNodeAction()); rm.waitForState(id1, NodeState.DECOMMISSIONED); } @@ -472,7 +474,8 @@ public void testGracefulDecommissionWithApp() throws Exception { * Test graceful decommission of node when an AM container is scheduled on a * node just before it is gracefully decommissioned. */ - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testGracefulDecommissionAfterAMContainerAlloc() throws Exception { Configuration conf = new Configuration(); conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, hostFile @@ -540,11 +543,11 @@ public void testAddNewIncludePathToConfiguration() throws Exception { assert(metrics != null); int initialMetricCount = metrics.getNumShutdownNMs(); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertEquals( + Assertions.assertEquals( NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertEquals( + Assertions.assertEquals( NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); writeToHostsFile("host1"); @@ -553,14 +556,14 @@ public void testAddNewIncludePathToConfiguration() throws Exception { rm.getNodesListManager().refreshNodes(conf); checkShutdownNMCount(rm, ++initialMetricCount); nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertEquals( - "Node should not have been shutdown.", - NodeAction.NORMAL, - nodeHeartbeat.getNodeAction()); + Assertions.assertEquals( + + NodeAction.NORMAL +, nodeHeartbeat.getNodeAction(), "Node should not have been shutdown."); NodeState nodeState = rm.getRMContext().getInactiveRMNodes().get(nm2.getNodeId()).getState(); - Assert.assertEquals("Node should have been shutdown but is in state" + - nodeState, NodeState.SHUTDOWN, nodeState); + Assertions.assertEquals(NodeState.SHUTDOWN, nodeState, "Node should have been shutdown but is in state" + + nodeState); } /** @@ -577,11 +580,11 @@ public void testAddNewExcludePathToConfiguration() throws Exception { assert(metrics != null); int initialMetricCount = metrics.getNumDecommisionedNMs(); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertEquals( + Assertions.assertEquals( NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertEquals( + Assertions.assertEquals( NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); writeToHostsFile("host2"); @@ -590,15 +593,15 @@ public void testAddNewExcludePathToConfiguration() throws Exception { rm.getNodesListManager().refreshNodes(conf); checkDecommissionedNMCount(rm, ++initialMetricCount); nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertEquals( - "Node should not have been decommissioned.", - NodeAction.NORMAL, - nodeHeartbeat.getNodeAction()); + Assertions.assertEquals( + + NodeAction.NORMAL +, nodeHeartbeat.getNodeAction(), "Node should not have been decommissioned."); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertEquals( - "Node should have been decommissioned but is in state" - + nodeHeartbeat.getNodeAction(), - NodeAction.SHUTDOWN, nodeHeartbeat.getNodeAction()); + Assertions.assertEquals( + + NodeAction.SHUTDOWN, nodeHeartbeat.getNodeAction(), "Node should have been decommissioned but is in state" + + nodeHeartbeat.getNodeAction()); } @Test @@ -622,7 +625,7 @@ public void testNodeRegistrationSuccess() throws Exception { // trying to register a invalid node. RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(NodeAction.NORMAL, response.getNodeAction()); + Assertions.assertEquals(NodeAction.NORMAL, response.getNodeAction()); } @Test @@ -647,7 +650,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { try { nodeLabelsMgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("A", "B", "C")); } catch (IOException e) { - Assert.fail("Caught Exception while initializing"); + Assertions.fail("Caught Exception while initializing"); e.printStackTrace(); } @@ -665,12 +668,12 @@ protected RMNodeLabelsManager createNodeLabelManager() { RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(registerReq); - Assert.assertEquals("Action should be normal on valid Node Labels", - NodeAction.NORMAL, response.getNodeAction()); + Assertions.assertEquals( + NodeAction.NORMAL, response.getNodeAction(), "Action should be normal on valid Node Labels"); assertCollectionEquals(nodeLabelsMgr.getNodeLabels().get(nodeId), NodeLabelsUtils.convertToStringSet(registerReq.getNodeLabels())); - Assert.assertTrue("Valid Node Labels were not accepted by RM", - response.getAreNodeLabelsAcceptedByRM()); + Assertions.assertTrue( + response.getAreNodeLabelsAcceptedByRM(), "Valid Node Labels were not accepted by RM"); rm.stop(); } @@ -696,7 +699,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { try { nodeLabelsMgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("X", "Y", "Z")); } catch (IOException e) { - Assert.fail("Caught Exception while initializing"); + Assertions.fail("Caught Exception while initializing"); e.printStackTrace(); } @@ -714,13 +717,13 @@ protected RMNodeLabelsManager createNodeLabelManager() { RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(registerReq); - Assert.assertEquals( - "On Invalid Node Labels action is expected to be normal", - NodeAction.NORMAL, response.getNodeAction()); - Assert.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId)); - Assert.assertNotNull(response.getDiagnosticsMessage()); - Assert.assertFalse("Node Labels should not accepted by RM If Invalid", - response.getAreNodeLabelsAcceptedByRM()); + Assertions.assertEquals( + + NodeAction.NORMAL, response.getNodeAction(), "On Invalid Node Labels action is expected to be normal"); + Assertions.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId)); + Assertions.assertNotNull(response.getDiagnosticsMessage()); + Assertions.assertFalse( + response.getAreNodeLabelsAcceptedByRM(), "Node Labels should not accepted by RM If Invalid"); if (rm != null) { rm.stop(); @@ -749,7 +752,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { try { nodeLabelsMgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("X", "Y", "Z")); } catch (IOException e) { - Assert.fail("Caught Exception while initializing"); + Assertions.fail("Caught Exception while initializing"); e.printStackTrace(); } @@ -767,13 +770,13 @@ protected RMNodeLabelsManager createNodeLabelManager() { RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals( - "On Invalid Node Labels action is expected to be normal", - NodeAction.NORMAL, response.getNodeAction()); - Assert.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId)); - Assert.assertNotNull(response.getDiagnosticsMessage()); - Assert.assertFalse("Node Labels should not accepted by RM If Invalid", - response.getAreNodeLabelsAcceptedByRM()); + Assertions.assertEquals( + + NodeAction.NORMAL, response.getNodeAction(), "On Invalid Node Labels action is expected to be normal"); + Assertions.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId)); + Assertions.assertNotNull(response.getDiagnosticsMessage()); + Assertions.assertFalse( + response.getAreNodeLabelsAcceptedByRM(), "Node Labels should not accepted by RM If Invalid"); if (rm != null) { rm.stop(); @@ -801,7 +804,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { try { nodeLabelsMgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("A", "B", "C")); } catch (IOException e) { - Assert.fail("Caught Exception while initializing"); + Assertions.fail("Caught Exception while initializing"); e.printStackTrace(); } ResourceTrackerService resourceTrackerService = @@ -818,13 +821,13 @@ protected RMNodeLabelsManager createNodeLabelManager() { RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(req); // registered to RM with central label config - Assert.assertEquals(NodeAction.NORMAL, response.getNodeAction()); - Assert.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId)); - Assert + Assertions.assertEquals(NodeAction.NORMAL, response.getNodeAction()); + Assertions.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId)); + Assertions .assertFalse( - "Node Labels should not accepted by RM If its configured with " + - "Central configuration", - response.getAreNodeLabelsAcceptedByRM()); + + response.getAreNodeLabelsAcceptedByRM(), "Node Labels should not accepted by RM If its configured with " + + "Central configuration"); if (rm != null) { rm.stop(); } @@ -867,14 +870,14 @@ public void testNodeRegistrationWithAttributes() throws Exception { RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(registerReq); - Assert.assertEquals("Action should be normal on valid Node Attributes", - NodeAction.NORMAL, response.getNodeAction()); - Assert.assertTrue(NodeLabelUtil.isNodeAttributesEquals( + Assertions.assertEquals( + NodeAction.NORMAL, response.getNodeAction(), "Action should be normal on valid Node Attributes"); + Assertions.assertTrue(NodeLabelUtil.isNodeAttributesEquals( rm.getRMContext().getNodeAttributesManager() .getAttributesForNode(nodeId.getHost()).keySet(), registerReq.getNodeAttributes())); - Assert.assertTrue("Valid Node Attributes were not accepted by RM", - response.getAreNodeAttributesAcceptedByRM()); + Assertions.assertTrue( + response.getAreNodeAttributesAcceptedByRM(), "Valid Node Attributes were not accepted by RM"); if (rm != null) { rm.stop(); @@ -922,28 +925,28 @@ public void testNodeRegistrationWithInvalidAttributes() throws Exception { toSet(validNodeAttribute, invalidPrefixNodeAttribute)); RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(0, rm.getRMContext().getNodeAttributesManager() + Assertions.assertEquals(0, rm.getRMContext().getNodeAttributesManager() .getAttributesForNode(nodeId.getHost()).size()); assertRegisterResponseForInvalidAttributes(response); - Assert.assertTrue(response.getDiagnosticsMessage() + Assertions.assertTrue(response.getDiagnosticsMessage() .endsWith("attributes in HB must have prefix nm.yarn.io")); // check invalid name req.setNodeAttributes(toSet(validNodeAttribute, invalidNameNodeAttribute)); response = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(0, rm.getRMContext().getNodeAttributesManager() + Assertions.assertEquals(0, rm.getRMContext().getNodeAttributesManager() .getAttributesForNode(nodeId.getHost()).size()); assertRegisterResponseForInvalidAttributes(response); - Assert.assertTrue(response.getDiagnosticsMessage() + Assertions.assertTrue(response.getDiagnosticsMessage() .startsWith("attribute name should only contains")); // check invalid value req.setNodeAttributes(toSet(validNodeAttribute, invalidValueNodeAttribute)); response = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(0, rm.getRMContext().getNodeAttributesManager() + Assertions.assertEquals(0, rm.getRMContext().getNodeAttributesManager() .getAttributesForNode(nodeId.getHost()).size()); assertRegisterResponseForInvalidAttributes(response); - Assert.assertTrue(response.getDiagnosticsMessage() + Assertions.assertTrue(response.getDiagnosticsMessage() .startsWith("attribute value should only contains")); if (rm != null) { @@ -953,12 +956,12 @@ public void testNodeRegistrationWithInvalidAttributes() throws Exception { private void assertRegisterResponseForInvalidAttributes( RegisterNodeManagerResponse response) { - Assert.assertEquals( - "On Invalid Node Labels action is expected to be normal", - NodeAction.NORMAL, response.getNodeAction()); - Assert.assertNotNull(response.getDiagnosticsMessage()); - Assert.assertFalse("Node Labels should not accepted by RM If Invalid", - response.getAreNodeLabelsAcceptedByRM()); + Assertions.assertEquals( + + NodeAction.NORMAL, response.getNodeAction(), "On Invalid Node Labels action is expected to be normal"); + Assertions.assertNotNull(response.getDiagnosticsMessage()); + Assertions.assertFalse( + response.getAreNodeLabelsAcceptedByRM(), "Node Labels should not accepted by RM If Invalid"); } private NodeStatus getNodeStatusObject(NodeId nodeId) { @@ -992,7 +995,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { try { nodeLabelsMgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("A", "B", "C")); } catch (IOException e) { - Assert.fail("Caught Exception while initializing"); + Assertions.fail("Caught Exception while initializing"); e.printStackTrace(); } @@ -1024,12 +1027,12 @@ protected RMNodeLabelsManager createNodeLabelManager() { NodeHeartbeatResponse nodeHeartbeatResponse = resourceTrackerService.nodeHeartbeat(heartbeatReq); - Assert.assertEquals("InValid Node Labels were not accepted by RM", - NodeAction.NORMAL, nodeHeartbeatResponse.getNodeAction()); + Assertions.assertEquals( + NodeAction.NORMAL, nodeHeartbeatResponse.getNodeAction(), "InValid Node Labels were not accepted by RM"); assertCollectionEquals(nodeLabelsMgr.getNodeLabels().get(nodeId), NodeLabelsUtils.convertToStringSet(heartbeatReq.getNodeLabels())); - Assert.assertTrue("Valid Node Labels were not accepted by RM", - nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM()); + Assertions.assertTrue( + nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM(), "Valid Node Labels were not accepted by RM"); // After modification of labels next heartbeat sends null informing no update Set oldLabels = nodeLabelsMgr.getNodeLabels().get(nodeId); @@ -1046,12 +1049,12 @@ protected RMNodeLabelsManager createNodeLabelManager() { .getContainerTokenMasterKey()); nodeHeartbeatResponse = resourceTrackerService.nodeHeartbeat(heartbeatReq); - Assert.assertEquals("InValid Node Labels were not accepted by RM", - NodeAction.NORMAL, nodeHeartbeatResponse.getNodeAction()); + Assertions.assertEquals( + NodeAction.NORMAL, nodeHeartbeatResponse.getNodeAction(), "InValid Node Labels were not accepted by RM"); assertCollectionEquals(nodeLabelsMgr.getNodeLabels().get(nodeId), oldLabels); - Assert.assertFalse("Node Labels should not accepted by RM", - nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM()); + Assertions.assertFalse( + nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM(), "Node Labels should not accepted by RM"); rm.stop(); } @@ -1105,11 +1108,11 @@ public void testNodeHeartbeatWithNodeAttributes() throws Exception { rm.getRMContext().getNodeAttributesManager(); Map attrs = attributeManager .getAttributesForNode(nodeId.getHost()); - Assert.assertEquals(1, attrs.size()); + Assertions.assertEquals(1, attrs.size()); NodeAttribute na = attrs.keySet().iterator().next(); - Assert.assertEquals("host", na.getAttributeKey().getAttributeName()); - Assert.assertEquals("host2", na.getAttributeValue()); - Assert.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); + Assertions.assertEquals("host", na.getAttributeKey().getAttributeName()); + Assertions.assertEquals("host2", na.getAttributeValue()); + Assertions.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); // Send another HB to RM with updated node atrribute @@ -1125,11 +1128,11 @@ public void testNodeHeartbeatWithNodeAttributes() throws Exception { // Make sure RM gets the updated attribute attrs = attributeManager.getAttributesForNode(nodeId.getHost()); - Assert.assertEquals(1, attrs.size()); + Assertions.assertEquals(1, attrs.size()); na = attrs.keySet().iterator().next(); - Assert.assertEquals("host", na.getAttributeKey().getAttributeName()); - Assert.assertEquals("host3", na.getAttributeValue()); - Assert.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); + Assertions.assertEquals("host", na.getAttributeKey().getAttributeName()); + Assertions.assertEquals("host3", na.getAttributeValue()); + Assertions.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); } @Test @@ -1189,10 +1192,10 @@ public void testNodeHeartbeatWithInvalidNodeAttributes() throws Exception { toSet(validNodeAttribute, invalidPrefixNodeAttribute)); NodeHeartbeatResponse response = resourceTrackerService.nodeHeartbeat(heartbeatReq); - Assert.assertEquals(0, rm.getRMContext().getNodeAttributesManager() + Assertions.assertEquals(0, rm.getRMContext().getNodeAttributesManager() .getAttributesForNode(nodeId.getHost()).size()); assertNodeHeartbeatResponseForInvalidAttributes(response); - Assert.assertTrue(response.getDiagnosticsMessage() + Assertions.assertTrue(response.getDiagnosticsMessage() .endsWith("attributes in HB must have prefix nm.yarn.io")); // Send another HB to RM with invalid name node attributes @@ -1200,10 +1203,10 @@ public void testNodeHeartbeatWithInvalidNodeAttributes() throws Exception { heartbeatReq .setNodeAttributes(toSet(validNodeAttribute, invalidNameNodeAttribute)); response = resourceTrackerService.nodeHeartbeat(heartbeatReq); - Assert.assertEquals(0, rm.getRMContext().getNodeAttributesManager() + Assertions.assertEquals(0, rm.getRMContext().getNodeAttributesManager() .getAttributesForNode(nodeId.getHost()).size()); assertNodeHeartbeatResponseForInvalidAttributes(response); - Assert.assertTrue(response.getDiagnosticsMessage() + Assertions.assertTrue(response.getDiagnosticsMessage() .startsWith("attribute name should only contains")); // Send another HB to RM with invalid value node attributes @@ -1211,10 +1214,10 @@ public void testNodeHeartbeatWithInvalidNodeAttributes() throws Exception { heartbeatReq.setNodeAttributes( toSet(validNodeAttribute, invalidValueNodeAttribute)); response = resourceTrackerService.nodeHeartbeat(heartbeatReq); - Assert.assertEquals(0, rm.getRMContext().getNodeAttributesManager() + Assertions.assertEquals(0, rm.getRMContext().getNodeAttributesManager() .getAttributesForNode(nodeId.getHost()).size()); assertNodeHeartbeatResponseForInvalidAttributes(response); - Assert.assertTrue(response.getDiagnosticsMessage() + Assertions.assertTrue(response.getDiagnosticsMessage() .startsWith("attribute value should only contains")); // Send another HB to RM with updated node attribute @@ -1230,21 +1233,21 @@ public void testNodeHeartbeatWithInvalidNodeAttributes() throws Exception { rm.getRMContext().getNodeAttributesManager(); Map attrs = attributeManager.getAttributesForNode(nodeId.getHost()); - Assert.assertEquals(1, attrs.size()); + Assertions.assertEquals(1, attrs.size()); NodeAttribute na = attrs.keySet().iterator().next(); - Assert.assertEquals("host", na.getAttributeKey().getAttributeName()); - Assert.assertEquals("host3", na.getAttributeValue()); - Assert.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); + Assertions.assertEquals("host", na.getAttributeKey().getAttributeName()); + Assertions.assertEquals("host3", na.getAttributeValue()); + Assertions.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); } private void assertNodeHeartbeatResponseForInvalidAttributes( NodeHeartbeatResponse response) { - Assert.assertEquals( - "On Invalid Node Labels action is expected to be normal", - NodeAction.NORMAL, response.getNodeAction()); - Assert.assertNotNull(response.getDiagnosticsMessage()); - Assert.assertFalse("Node Labels should not accepted by RM If Invalid", - response.getAreNodeLabelsAcceptedByRM()); + Assertions.assertEquals( + + NodeAction.NORMAL, response.getNodeAction(), "On Invalid Node Labels action is expected to be normal"); + Assertions.assertNotNull(response.getDiagnosticsMessage()); + Assertions.assertFalse( + response.getAreNodeLabelsAcceptedByRM(), "Node Labels should not accepted by RM If Invalid"); } @Test @@ -1315,12 +1318,12 @@ public Object answer(InvocationOnMock invocation) throws Exception { Map attrs = spyAttributeManager .getAttributesForNode(nodeId.getHost()); spyAttributeManager.getNodesToAttributes(ImmutableSet.of(nodeId.getHost())); - Assert.assertEquals(1, attrs.size()); + Assertions.assertEquals(1, attrs.size()); NodeAttribute na = attrs.keySet().iterator().next(); - Assert.assertEquals("host", na.getAttributeKey().getAttributeName()); - Assert.assertEquals("host2", na.getAttributeValue()); - Assert.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); - Assert.assertEquals(1, count.get()); + Assertions.assertEquals("host", na.getAttributeKey().getAttributeName()); + Assertions.assertEquals("host2", na.getAttributeValue()); + Assertions.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); + Assertions.assertEquals(1, count.get()); // Send HBs to RM with the same node attributes nodeStatusObject.setResponseId(++responseId); @@ -1332,7 +1335,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { resourceTrackerService.nodeHeartbeat(heartbeatReq); // Make sure RM updated node attributes once - Assert.assertEquals(1, count.get()); + Assertions.assertEquals(1, count.get()); // Send another HB to RM with updated node attributes nodeAttributes.clear(); @@ -1346,14 +1349,14 @@ public Object answer(InvocationOnMock invocation) throws Exception { // Make sure RM gets the updated attribute attrs = spyAttributeManager.getAttributesForNode(nodeId.getHost()); - Assert.assertEquals(1, attrs.size()); + Assertions.assertEquals(1, attrs.size()); na = attrs.keySet().iterator().next(); - Assert.assertEquals("host", na.getAttributeKey().getAttributeName()); - Assert.assertEquals("host3", na.getAttributeValue()); - Assert.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); + Assertions.assertEquals("host", na.getAttributeKey().getAttributeName()); + Assertions.assertEquals("host3", na.getAttributeValue()); + Assertions.assertEquals(NodeAttributeType.STRING, na.getAttributeType()); // Make sure RM updated node attributes twice - Assert.assertEquals(2, count.get()); + Assertions.assertEquals(2, count.get()); // Add centralized attributes Map> nodeAttributeMapping = ImmutableMap @@ -1364,7 +1367,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { nodeAttributeMapping); // Make sure RM updated node attributes three times - Assert.assertEquals(3, count.get()); + Assertions.assertEquals(3, count.get()); // Send another HB to RM with non-updated node attributes nodeAttributes.clear(); @@ -1377,7 +1380,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { resourceTrackerService.nodeHeartbeat(heartbeatReq); // Make sure RM still updated node attributes three times - Assert.assertEquals(3, count.get()); + Assertions.assertEquals(3, count.get()); // Send another HB to RM with updated node attributes nodeAttributes.clear(); @@ -1391,20 +1394,20 @@ public Object answer(InvocationOnMock invocation) throws Exception { // Make sure RM gets the updated attribute attrs = spyAttributeManager.getAttributesForNode(nodeId.getHost()); - Assert.assertEquals(2, attrs.size()); + Assertions.assertEquals(2, attrs.size()); attrs.keySet().stream().forEach(e -> { - Assert.assertEquals(NodeAttributeType.STRING, e.getAttributeType()); + Assertions.assertEquals(NodeAttributeType.STRING, e.getAttributeType()); if (e.getAttributeKey().getAttributePrefix() == NodeAttribute.PREFIX_DISTRIBUTED) { - Assert.assertEquals("host", e.getAttributeKey().getAttributeName()); - Assert.assertEquals("host4", e.getAttributeValue()); + Assertions.assertEquals("host", e.getAttributeKey().getAttributeName()); + Assertions.assertEquals("host4", e.getAttributeValue()); } else if (e.getAttributeKey().getAttributePrefix() == NodeAttribute.PREFIX_CENTRALIZED) { - Assert.assertEquals("centAttr", e.getAttributeKey().getAttributeName()); - Assert.assertEquals("x", e.getAttributeValue()); + Assertions.assertEquals("centAttr", e.getAttributeKey().getAttributeName()); + Assertions.assertEquals("x", e.getAttributeValue()); } }); // Make sure RM updated node attributes four times - Assert.assertEquals(4, count.get()); + Assertions.assertEquals(4, count.get()); if (rm != null) { rm.stop(); @@ -1433,7 +1436,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { try { nodeLabelsMgr.addToCluserNodeLabelsWithDefaultExclusivity(toSet("A", "B", "C")); } catch (IOException e) { - Assert.fail("Caught Exception while initializing"); + Assertions.fail("Caught Exception while initializing"); e.printStackTrace(); } @@ -1463,11 +1466,11 @@ protected RMNodeLabelsManager createNodeLabelManager() { resourceTrackerService.nodeHeartbeat(heartbeatReq); // response should be NORMAL when RM heartbeat labels are rejected - Assert.assertEquals("Response should be NORMAL when RM heartbeat labels" - + " are rejected", NodeAction.NORMAL, - nodeHeartbeatResponse.getNodeAction()); - Assert.assertFalse(nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM()); - Assert.assertNotNull(nodeHeartbeatResponse.getDiagnosticsMessage()); + Assertions.assertEquals(NodeAction.NORMAL +, nodeHeartbeatResponse.getNodeAction(), "Response should be NORMAL when RM heartbeat labels" + + " are rejected"); + Assertions.assertFalse(nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM()); + Assertions.assertNotNull(nodeHeartbeatResponse.getDiagnosticsMessage()); rm.stop(); } @@ -1516,13 +1519,13 @@ protected RMNodeLabelsManager createNodeLabelManager() { resourceTrackerService.nodeHeartbeat(heartbeatReq); // response should be ok but the RMacceptNodeLabelsUpdate should be false - Assert.assertEquals(NodeAction.NORMAL, + Assertions.assertEquals(NodeAction.NORMAL, nodeHeartbeatResponse.getNodeAction()); // no change in the labels, - Assert.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId)); + Assertions.assertNull(nodeLabelsMgr.getNodeLabels().get(nodeId)); // heartbeat labels rejected - Assert.assertFalse("Invalid Node Labels should not accepted by RM", - nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM()); + Assertions.assertFalse( + nodeHeartbeatResponse.getAreNodeLabelsAcceptedByRM(), "Invalid Node Labels should not accepted by RM"); if (rm != null) { rm.stop(); } @@ -1550,11 +1553,11 @@ public void testNodeRegistrationVersionLessThanRM() throws Exception { req.setNMVersion(nmVersion); // trying to register a invalid node. RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(NodeAction.SHUTDOWN,response.getNodeAction()); - Assert.assertTrue("Diagnostic message did not contain: 'Disallowed NodeManager " + - "Version "+ nmVersion + ", is less than the minimum version'", - response.getDiagnosticsMessage().contains("Disallowed NodeManager Version " + - nmVersion + ", is less than the minimum version ")); + Assertions.assertEquals(NodeAction.SHUTDOWN,response.getNodeAction()); + Assertions.assertTrue( + response.getDiagnosticsMessage().contains("Disallowed NodeManager Version " + + nmVersion + ", is less than the minimum version "), "Diagnostic message did not contain: 'Disallowed NodeManager " + + "Version "+ nmVersion + ", is less than the minimum version'"); } @@ -1575,8 +1578,8 @@ public void testNodeRegistrationFailure() throws Exception { req.setHttpPort(1234); // trying to register a invalid node. RegisterNodeManagerResponse response = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(NodeAction.SHUTDOWN,response.getNodeAction()); - Assert + Assertions.assertEquals(NodeAction.SHUTDOWN,response.getNodeAction()); + Assertions .assertEquals( "Disallowed NodeManager from host2, Sending SHUTDOWN signal to the NodeManager.", response.getDiagnosticsMessage()); @@ -1593,7 +1596,7 @@ public void testSetRMIdentifierInRegistration() throws Exception { RegisterNodeManagerResponse response = nm.registerNode(); // Verify the RMIdentifier is correctly set in RegisterNodeManagerResponse - Assert.assertEquals(ResourceManager.getClusterTimeStamp(), + Assertions.assertEquals(ResourceManager.getClusterTimeStamp(), response.getRMIdentifier()); } @@ -1616,28 +1619,28 @@ public void testNodeRegistrationWithMinimumAllocations() throws Exception { req.setResource(capability); RegisterNodeManagerResponse response1 = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(NodeAction.SHUTDOWN,response1.getNodeAction()); + Assertions.assertEquals(NodeAction.SHUTDOWN,response1.getNodeAction()); capability.setMemorySize(2048); capability.setVirtualCores(1); req.setResource(capability); RegisterNodeManagerResponse response2 = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(NodeAction.SHUTDOWN,response2.getNodeAction()); + Assertions.assertEquals(NodeAction.SHUTDOWN,response2.getNodeAction()); capability.setMemorySize(1024); capability.setVirtualCores(4); req.setResource(capability); RegisterNodeManagerResponse response3 = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(NodeAction.SHUTDOWN,response3.getNodeAction()); + Assertions.assertEquals(NodeAction.SHUTDOWN,response3.getNodeAction()); capability.setMemorySize(2048); capability.setVirtualCores(4); req.setResource(capability); RegisterNodeManagerResponse response4 = resourceTrackerService.registerNodeManager(req); - Assert.assertEquals(NodeAction.NORMAL,response4.getNodeAction()); + Assertions.assertEquals(NodeAction.NORMAL,response4.getNodeAction()); } @Test @@ -1651,12 +1654,12 @@ public void testReboot() throws Exception { int initialMetricCount = ClusterMetrics.getMetrics().getNumRebootedNMs(); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm2.nodeHeartbeat( new HashMap>(), true, -100); - Assert.assertTrue(NodeAction.RESYNC.equals(nodeHeartbeat.getNodeAction())); - Assert.assertEquals("Too far behind rm response id:0 nm response id:-100", + Assertions.assertTrue(NodeAction.RESYNC.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertEquals("Too far behind rm response id:0 nm response id:-100", nodeHeartbeat.getDiagnosticsMessage()); checkRebootedNMCount(rm, ++initialMetricCount); } @@ -1723,8 +1726,8 @@ public void testNodeHeartbeatForAppCollectorsMap() throws Exception { statusList, null, nodeHealth, null, null, null); node1.handle(new RMNodeStatusEvent(nm1.getNodeId(), nodeStatus)); - Assert.assertEquals(1, node1.getRunningApps().size()); - Assert.assertEquals(app1.getApplicationId(), node1.getRunningApps().get(0)); + Assertions.assertEquals(1, node1.getRunningApps().size()); + Assertions.assertEquals(app1.getApplicationId(), node1.getRunningApps().get(0)); // Create a running container for app2 running on nm2 ContainerId runningContainerId2 = BuilderUtils.newContainerId( @@ -1738,21 +1741,21 @@ public void testNodeHeartbeatForAppCollectorsMap() throws Exception { nodeStatus = NodeStatus.newInstance(nm1.getNodeId(), 0, statusList, null, nodeHealth, null, null, null); node2.handle(new RMNodeStatusEvent(nm2.getNodeId(), nodeStatus)); - Assert.assertEquals(1, node2.getRunningApps().size()); - Assert.assertEquals(app2.getApplicationId(), node2.getRunningApps().get(0)); + Assertions.assertEquals(1, node2.getRunningApps().size()); + Assertions.assertEquals(app2.getApplicationId(), node2.getRunningApps().get(0)); nodeHeartbeat1 = nm1.nodeHeartbeat(true); Map map1 = nodeHeartbeat1.getAppCollectors(); - Assert.assertEquals(1, map1.size()); - Assert.assertEquals(collectorAddr1, + Assertions.assertEquals(1, map1.size()); + Assertions.assertEquals(collectorAddr1, map1.get(app1.getApplicationId()).getCollectorAddr()); nodeHeartbeat2 = nm2.nodeHeartbeat(true); Map map2 = nodeHeartbeat2.getAppCollectors(); - Assert.assertEquals(1, map2.size()); - Assert.assertEquals(collectorAddr4, + Assertions.assertEquals(1, map2.size()); + Assertions.assertEquals(collectorAddr4, map2.get(app2.getApplicationId()).getCollectorAddr()); } @@ -1766,8 +1769,8 @@ private void checkRebootedNMCount(MockRM rm2, int count) wait(100); } } - Assert.assertEquals("The rebooted metrics are not updated", count, - ClusterMetrics.getMetrics().getNumRebootedNMs()); + Assertions.assertEquals(count +, ClusterMetrics.getMetrics().getNumRebootedNMs(), "The rebooted metrics are not updated"); } @Test @@ -1780,7 +1783,7 @@ public void testUnhealthyNodeStatus() throws Exception { rm.start(); MockNM nm1 = rm.registerNode("host1:1234", 5120); - Assert.assertEquals(0, ClusterMetrics.getMetrics().getUnhealthyNMs()); + Assertions.assertEquals(0, ClusterMetrics.getMetrics().getUnhealthyNMs()); // node healthy nm1.nodeHeartbeat(true); @@ -1804,10 +1807,10 @@ private void checkUnhealthyNMCount(MockRM rm, MockNM nm1, boolean health, wait(100); } } - Assert.assertFalse((rm.getRMContext().getRMNodes().get(nm1.getNodeId()) + Assertions.assertFalse((rm.getRMContext().getRMNodes().get(nm1.getNodeId()) .getState() != NodeState.UNHEALTHY) == health); - Assert.assertEquals("Unhealthy metrics not incremented", count, - ClusterMetrics.getMetrics().getUnhealthyNMs()); + Assertions.assertEquals(count +, ClusterMetrics.getMetrics().getUnhealthyNMs(), "Unhealthy metrics not incremented"); } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -1904,22 +1907,22 @@ public void handle(SchedulerEvent event) { final int expectedNMs = ClusterMetrics.getMetrics().getNumActiveNMs(); QueueMetrics metrics = rm.getResourceScheduler().getRootQueueMetrics(); // TODO Metrics incorrect in case of the FifoScheduler - Assert.assertEquals(5120, metrics.getAvailableMB()); + Assertions.assertEquals(5120, metrics.getAvailableMB()); // reconnect of healthy node nm1 = rm.registerNode("host1:1234", 5120); NodeHeartbeatResponse response = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(response.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(response.getNodeAction())); rm.drainEvents(); - Assert.assertEquals(expectedNMs, ClusterMetrics.getMetrics().getNumActiveNMs()); + Assertions.assertEquals(expectedNMs, ClusterMetrics.getMetrics().getNumActiveNMs()); checkUnhealthyNMCount(rm, nm2, true, 1); // reconnect of unhealthy node nm2 = rm.registerNode("host2:5678", 5120); response = nm2.nodeHeartbeat(false); - Assert.assertTrue(NodeAction.NORMAL.equals(response.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(response.getNodeAction())); rm.drainEvents(); - Assert.assertEquals(expectedNMs, ClusterMetrics.getMetrics().getNumActiveNMs()); + Assertions.assertEquals(expectedNMs, ClusterMetrics.getMetrics().getNumActiveNMs()); checkUnhealthyNMCount(rm, nm2, true, 1); // unhealthy node changed back to healthy @@ -1927,14 +1930,14 @@ public void handle(SchedulerEvent event) { response = nm2.nodeHeartbeat(true); response = nm2.nodeHeartbeat(true); rm.drainEvents(); - Assert.assertEquals(5120 + 5120, metrics.getAvailableMB()); + Assertions.assertEquals(5120 + 5120, metrics.getAvailableMB()); // reconnect of node with changed capability nm1 = rm.registerNode("host2:5678", 10240); response = nm1.nodeHeartbeat(true); rm.drainEvents(); - Assert.assertTrue(NodeAction.NORMAL.equals(response.getNodeAction())); - Assert.assertEquals(5120 + 10240, metrics.getAvailableMB()); + Assertions.assertTrue(NodeAction.NORMAL.equals(response.getNodeAction())); + Assertions.assertEquals(5120 + 10240, metrics.getAvailableMB()); // reconnect of node with changed capability and running applications List runningApps = new ArrayList(); @@ -1942,8 +1945,8 @@ public void handle(SchedulerEvent event) { nm1 = rm.registerNode("host2:5678", 15360, 2, runningApps); response = nm1.nodeHeartbeat(true); rm.drainEvents(); - Assert.assertTrue(NodeAction.NORMAL.equals(response.getNodeAction())); - Assert.assertEquals(5120 + 15360, metrics.getAvailableMB()); + Assertions.assertTrue(NodeAction.NORMAL.equals(response.getNodeAction())); + Assertions.assertEquals(5120 + 15360, metrics.getAvailableMB()); // reconnect healthy node changing http port nm1 = new MockNM("host1:1234", 5120, rm.getResourceTrackerService()); @@ -1953,9 +1956,9 @@ public void handle(SchedulerEvent event) { response = nm1.nodeHeartbeat(true); rm.drainEvents(); RMNode rmNode = rm.getRMContext().getRMNodes().get(nm1.getNodeId()); - Assert.assertEquals(3, rmNode.getHttpPort()); - Assert.assertEquals(5120, rmNode.getTotalCapability().getMemorySize()); - Assert.assertEquals(5120 + 15360, metrics.getAvailableMB()); + Assertions.assertEquals(3, rmNode.getHttpPort()); + Assertions.assertEquals(5120, rmNode.getTotalCapability().getMemorySize()); + Assertions.assertEquals(5120 + 15360, metrics.getAvailableMB()); } @@ -1972,7 +1975,7 @@ public void testNMUnregistration() throws Exception { int shutdownNMsCount = ClusterMetrics.getMetrics() .getNumShutdownNMs(); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); UnRegisterNodeManagerRequest request = Records .newRecord(UnRegisterNodeManagerRequest.class); @@ -1983,7 +1986,7 @@ public void testNMUnregistration() throws Exception { // The RM should remove the node after unregistration, hence send a reboot // command. nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.RESYNC.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.RESYNC.equals(nodeHeartbeat.getNodeAction())); } @Test @@ -1995,7 +1998,7 @@ public void testUnhealthyNMUnregistration() throws Exception { ResourceTrackerService resourceTrackerService = rm .getResourceTrackerService(); MockNM nm1 = rm.registerNode("host1:1234", 5120); - Assert.assertEquals(0, ClusterMetrics.getMetrics().getUnhealthyNMs()); + Assertions.assertEquals(0, ClusterMetrics.getMetrics().getUnhealthyNMs()); // node healthy nm1.nodeHeartbeat(true); int shutdownNMsCount = ClusterMetrics.getMetrics().getNumShutdownNMs(); @@ -2034,14 +2037,14 @@ public void testInvalidNMUnregistration() throws Exception { // 4. Unregister the Node Manager MockNM nm1 = new MockNM("host1:1234", 5120, resourceTrackerService); RegisterNodeManagerResponse response = nm1.registerNode(); - Assert.assertEquals(NodeAction.NORMAL, response.getNodeAction()); + Assertions.assertEquals(NodeAction.NORMAL, response.getNodeAction()); int shutdownNMsCount = ClusterMetrics.getMetrics().getNumShutdownNMs(); writeToHostsFile("host2"); conf.set(YarnConfiguration.RM_NODES_INCLUDE_FILE_PATH, hostFile.getAbsolutePath()); rm.getNodesListManager().refreshNodes(conf); NodeHeartbeatResponse heartbeatResponse = nm1.nodeHeartbeat(true); - Assert.assertEquals(NodeAction.SHUTDOWN, heartbeatResponse.getNodeAction()); + Assertions.assertEquals(NodeAction.SHUTDOWN, heartbeatResponse.getNodeAction()); checkDecommissionedNMCount(rm, decommisionedNMsCount); request.setNodeId(nm1.getNodeId()); resourceTrackerService.unRegisterNodeManager(request); @@ -2053,7 +2056,7 @@ public void testInvalidNMUnregistration() throws Exception { // 3. Unregister the Node Manager MockNM nm2 = new MockNM("host2:1234", 5120, resourceTrackerService); RegisterNodeManagerResponse response2 = nm2.registerNode(); - Assert.assertEquals(NodeAction.NORMAL, response2.getNodeAction()); + Assertions.assertEquals(NodeAction.NORMAL, response2.getNodeAction()); writeToHostsFile("host1"); conf.set(YarnConfiguration.RM_NODES_INCLUDE_FILE_PATH, hostFile.getAbsolutePath()); @@ -2065,7 +2068,8 @@ public void testInvalidNMUnregistration() throws Exception { rm.stop(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testInitDecommMetric() throws Exception { testInitDecommMetricHelper(true); testInitDecommMetricHelper(false); @@ -2101,11 +2105,11 @@ public void testInitDecommMetricHelper(boolean hasIncludeList) nm1.nodeHeartbeat(true); nm2.nodeHeartbeat(true); rm1.drainEvents(); - Assert.assertEquals("Number of Decommissioned nodes should be 1", - 1, ClusterMetrics.getMetrics().getNumDecommisionedNMs()); - Assert.assertEquals("The inactiveRMNodes should contain an entry for the" + - "decommissioned node", - 1, rm1.getRMContext().getInactiveRMNodes().size()); + Assertions.assertEquals( + 1, ClusterMetrics.getMetrics().getNumDecommisionedNMs(), "Number of Decommissioned nodes should be 1"); + Assertions.assertEquals( + 1, rm1.getRMContext().getInactiveRMNodes().size(), "The inactiveRMNodes should contain an entry for the" + + "decommissioned node"); writeToHostsFile(excludeHostFile, ""); conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, excludeHostFile.getAbsolutePath()); @@ -2114,18 +2118,19 @@ public void testInitDecommMetricHelper(boolean hasIncludeList) nm1.nodeHeartbeat(true); nm2.nodeHeartbeat(true); rm1.drainEvents(); - Assert.assertEquals("The decommissioned nodes metric should have " + - "decremented to 0", - 0, ClusterMetrics.getMetrics().getNumDecommisionedNMs()); - Assert.assertEquals("The active nodes metric should be 2", - 2, ClusterMetrics.getMetrics().getNumActiveNMs()); - Assert.assertEquals("The inactive RMNodes entry should have been removed", - 0, rm1.getRMContext().getInactiveRMNodes().size()); + Assertions.assertEquals( + 0, ClusterMetrics.getMetrics().getNumDecommisionedNMs(), "The decommissioned nodes metric should have " + + "decremented to 0"); + Assertions.assertEquals( + 2, ClusterMetrics.getMetrics().getNumActiveNMs(), "The active nodes metric should be 2"); + Assertions.assertEquals( + 0, rm1.getRMContext().getInactiveRMNodes().size(), "The inactive RMNodes entry should have been removed"); rm1.drainEvents(); rm1.stop(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testInitDecommMetricNoRegistration() throws Exception { Configuration conf = new Configuration(); rm = new MockRM(conf); @@ -2143,16 +2148,16 @@ public void testInitDecommMetricNoRegistration() throws Exception { hostFile.getAbsolutePath()); rm.getNodesListManager().refreshNodes(conf); rm.drainEvents(); - Assert.assertEquals("The decommissioned nodes metric should be 1 ", - 1, ClusterMetrics.getMetrics().getNumDecommisionedNMs()); + Assertions.assertEquals( + 1, ClusterMetrics.getMetrics().getNumDecommisionedNMs(), "The decommissioned nodes metric should be 1 "); rm.stop(); MockRM rm1 = new MockRM(conf); rm1.start(); rm1.getNodesListManager().refreshNodes(conf); rm1.drainEvents(); - Assert.assertEquals("The decommissioned nodes metric should be 2 ", - 2, ClusterMetrics.getMetrics().getNumDecommisionedNMs()); + Assertions.assertEquals( + 2, ClusterMetrics.getMetrics().getNumDecommisionedNMs(), "The decommissioned nodes metric should be 2 "); rm1.stop(); } @@ -2175,17 +2180,17 @@ public void testIncorrectRecommission() throws Exception { rm.drainEvents(); nm1.nodeHeartbeat(true); rm.drainEvents(); - Assert.assertTrue("Node " + nm1.getNodeId().getHost() + - " should be Decommissioned", rm.getRMContext() + Assertions.assertTrue(rm.getRMContext() .getInactiveRMNodes().get(nm1.getNodeId()).getState() == NodeState - .DECOMMISSIONED); + .DECOMMISSIONED, "Node " + nm1.getNodeId().getHost() + + " should be Decommissioned"); writeToHostsFile(excludeHostFile, ""); rm.getNodesListManager().refreshNodesGracefully(conf, null); rm.drainEvents(); - Assert.assertTrue("Node " + nm1.getNodeId().getHost() + - " should be Decommissioned", rm.getRMContext() + Assertions.assertTrue(rm.getRMContext() .getInactiveRMNodes().get(nm1.getNodeId()).getState() == NodeState - .DECOMMISSIONED); + .DECOMMISSIONED, "Node " + nm1.getNodeId().getHost() + + " should be Decommissioned"); rm.stop(); } @@ -2238,14 +2243,14 @@ public void testNodeRemovalUtil(boolean doGraceful) throws Exception { //check all 3 nodes joined in as NORMAL NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm3.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); rm.drainEvents(); - Assert.assertEquals("All 3 nodes should be active", - metrics.getNumActiveNMs(), 3); + Assertions.assertEquals( + metrics.getNumActiveNMs(), 3, "All 3 nodes should be active"); //Remove nm2 from include list, should now be shutdown with timer test String ip = NetUtils.normalizeHostName("localhost"); @@ -2259,17 +2264,17 @@ public void testNodeRemovalUtil(boolean doGraceful) throws Exception { nm1.nodeHeartbeat(true); nm2.nodeHeartbeat(true); rm.drainEvents(); - Assert.assertTrue("Node should not be in active node list", - !rmContext.getRMNodes().containsKey(nm2.getNodeId())); + Assertions.assertTrue( + !rmContext.getRMNodes().containsKey(nm2.getNodeId()), "Node should not be in active node list"); RMNode rmNode = rmContext.getInactiveRMNodes().get(nm2.getNodeId()); - Assert.assertEquals("Node should be in inactive node list", - rmNode.getState(), - doGraceful? NodeState.DECOMMISSIONED : NodeState.SHUTDOWN); - Assert.assertEquals("Active nodes should be 2", - metrics.getNumActiveNMs(), 2); - Assert.assertEquals("Shutdown nodes should be expected", - metrics.getNumShutdownNMs(), doGraceful? 0 : 1); + Assertions.assertEquals( + rmNode.getState() +, doGraceful? NodeState.DECOMMISSIONED : NodeState.SHUTDOWN, "Node should be in inactive node list"); + Assertions.assertEquals( + metrics.getNumActiveNMs(), 2, "Active nodes should be 2"); + Assertions.assertEquals( + metrics.getNumShutdownNMs(), doGraceful? 0 : 1, "Shutdown nodes should be expected"); int nodeRemovalTimeout = conf.getInt( @@ -2282,10 +2287,10 @@ public void testNodeRemovalUtil(boolean doGraceful) throws Exception { latch.await(maxThreadSleeptime, TimeUnit.MILLISECONDS); rmNode = rmContext.getInactiveRMNodes().get(nm2.getNodeId()); - Assert.assertEquals("Node should have been forgotten!", - rmNode, null); - Assert.assertEquals("Shutdown nodes should be 0 now", - metrics.getNumShutdownNMs(), 0); + Assertions.assertEquals( + rmNode, null, "Node should have been forgotten!"); + Assertions.assertEquals( + metrics.getNumShutdownNMs(), 0, "Shutdown nodes should be 0 now"); //Check node removal and re-addition before timer expires writeToHostsFile("host1", ip, "host2"); @@ -2299,13 +2304,13 @@ public void testNodeRemovalUtil(boolean doGraceful) throws Exception { nm2.nodeHeartbeat(true); rm.drainEvents(); rmNode = rmContext.getInactiveRMNodes().get(nm2.getNodeId()); - Assert.assertEquals("Node should be shutdown", - rmNode.getState(), - doGraceful? NodeState.DECOMMISSIONED : NodeState.SHUTDOWN); - Assert.assertEquals("Active nodes should be 2", - metrics.getNumActiveNMs(), 2); - Assert.assertEquals("Shutdown nodes should be expected", - metrics.getNumShutdownNMs(), doGraceful? 0 : 1); + Assertions.assertEquals( + rmNode.getState() +, doGraceful? NodeState.DECOMMISSIONED : NodeState.SHUTDOWN, "Node should be shutdown"); + Assertions.assertEquals( + metrics.getNumActiveNMs(), 2, "Active nodes should be 2"); + Assertions.assertEquals( + metrics.getNumShutdownNMs(), doGraceful? 0 : 1, "Shutdown nodes should be expected"); //add back the node before timer expires latch.await(maxThreadSleeptime - 2000, TimeUnit.MILLISECONDS); @@ -2314,11 +2319,11 @@ public void testNodeRemovalUtil(boolean doGraceful) throws Exception { nm2 = rm.registerNode("host2:5678", 10240); nodeHeartbeat = nm2.nodeHeartbeat(true); rm.drainEvents(); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); - Assert.assertEquals("Shutdown nodes should be 0 now", - metrics.getNumShutdownNMs(), 0); - Assert.assertEquals("All 3 nodes should be active", - metrics.getNumActiveNMs(), 3); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertEquals( + metrics.getNumShutdownNMs(), 0, "Shutdown nodes should be 0 now"); + Assertions.assertEquals( + metrics.getNumActiveNMs(), 3, "All 3 nodes should be active"); //Decommission this node, check timer doesn't remove it writeToHostsFile("host1", "host2", ip); @@ -2329,23 +2334,23 @@ public void testNodeRemovalUtil(boolean doGraceful) throws Exception { rm.drainEvents(); rmNode = doGraceful ? rmContext.getRMNodes().get(nm2.getNodeId()) : rmContext.getInactiveRMNodes().get(nm2.getNodeId()); - Assert.assertTrue("Node should be DECOMMISSIONED or DECOMMISSIONING", - (rmNode.getState() == NodeState.DECOMMISSIONED) || - (rmNode.getState() == NodeState.DECOMMISSIONING)); + Assertions.assertTrue( + (rmNode.getState() == NodeState.DECOMMISSIONED) || + (rmNode.getState() == NodeState.DECOMMISSIONING), "Node should be DECOMMISSIONED or DECOMMISSIONING"); if (rmNode.getState() == NodeState.DECOMMISSIONED) { - Assert.assertEquals("Decommissioned/ing nodes should be 1 now", - metrics.getNumDecommisionedNMs(), 1); + Assertions.assertEquals( + metrics.getNumDecommisionedNMs(), 1, "Decommissioned/ing nodes should be 1 now"); } latch.await(maxThreadSleeptime, TimeUnit.MILLISECONDS); rmNode = doGraceful ? rmContext.getRMNodes().get(nm2.getNodeId()) : rmContext.getInactiveRMNodes().get(nm2.getNodeId()); - Assert.assertTrue("Node should be DECOMMISSIONED or DECOMMISSIONING", - (rmNode.getState() == NodeState.DECOMMISSIONED) || - (rmNode.getState() == NodeState.DECOMMISSIONING)); + Assertions.assertTrue( + (rmNode.getState() == NodeState.DECOMMISSIONED) || + (rmNode.getState() == NodeState.DECOMMISSIONING), "Node should be DECOMMISSIONED or DECOMMISSIONING"); if (rmNode.getState() == NodeState.DECOMMISSIONED) { - Assert.assertEquals("Decommissioned/ing nodes should be 1 now", - metrics.getNumDecommisionedNMs(), 1); + Assertions.assertEquals( + metrics.getNumDecommisionedNMs(), 1, "Decommissioned/ing nodes should be 1 now"); } //Test decommed/ing node that transitions to untracked,timer should remove @@ -2421,14 +2426,14 @@ private void testNodeRemovalUtilLost(boolean doGraceful) throws Exception { rm.drainEvents(); //check all 3 nodes joined in as NORMAL NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm3.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); rm.drainEvents(); - Assert.assertEquals("All 3 nodes should be active", - metrics.getNumActiveNMs(), 3); + Assertions.assertEquals( + metrics.getNumActiveNMs(), 3, "All 3 nodes should be active"); int waitCount = 0; while(waitCount++ < 20){ synchronized (this) { @@ -2437,15 +2442,15 @@ private void testNodeRemovalUtilLost(boolean doGraceful) throws Exception { nm3.nodeHeartbeat(true); nm1.nodeHeartbeat(true); } - Assert.assertNotEquals("host2 should be a lost NM!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null); - Assert.assertEquals("host2 should be a lost NM!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()).getState(), - NodeState.LOST); - Assert.assertEquals("There should be 1 Lost NM!", - clusterMetrics.getNumLostNMs(), 1); - Assert.assertEquals("There should be 2 Active NM!", - clusterMetrics.getNumActiveNMs(), 2); + Assertions.assertNotEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null, "host2 should be a lost NM!"); + Assertions.assertEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()).getState() +, NodeState.LOST, "host2 should be a lost NM!"); + Assertions.assertEquals( + clusterMetrics.getNumLostNMs(), 1, "There should be 1 Lost NM!"); + Assertions.assertEquals( + clusterMetrics.getNumActiveNMs(), 2, "There should be 2 Active NM!"); int nodeRemovalTimeout = conf.getInt( YarnConfiguration.RM_NODEMANAGER_UNTRACKED_REMOVAL_TIMEOUT_MSEC, @@ -2469,12 +2474,12 @@ private void testNodeRemovalUtilLost(boolean doGraceful) throws Exception { nm2.nodeHeartbeat(true); } } - Assert.assertEquals("host2 should have been forgotten!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null); - Assert.assertEquals("There should be no Lost NMs!", - clusterMetrics.getNumLostNMs(), 0); - Assert.assertEquals("There should be 2 Active NM!", - clusterMetrics.getNumActiveNMs(), 2); + Assertions.assertEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null, "host2 should have been forgotten!"); + Assertions.assertEquals( + clusterMetrics.getNumLostNMs(), 0, "There should be no Lost NMs!"); + Assertions.assertEquals( + clusterMetrics.getNumActiveNMs(), 2, "There should be 2 Active NM!"); rm.stop(); } @@ -2507,15 +2512,15 @@ private void testNodeRemovalUtilRebooted(boolean doGraceful) rm.drainEvents(); rm.drainEvents(); - Assert.assertNotEquals("host2 should be a rebooted NM!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null); - Assert.assertEquals("host2 should be a rebooted NM!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()).getState(), - NodeState.REBOOTED); - Assert.assertEquals("There should be 1 Rebooted NM!", - clusterMetrics.getNumRebootedNMs(), 1); - Assert.assertEquals("There should be 2 Active NM!", - clusterMetrics.getNumActiveNMs(), 2); + Assertions.assertNotEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null, "host2 should be a rebooted NM!"); + Assertions.assertEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()).getState() +, NodeState.REBOOTED, "host2 should be a rebooted NM!"); + Assertions.assertEquals( + clusterMetrics.getNumRebootedNMs(), 1, "There should be 1 Rebooted NM!"); + Assertions.assertEquals( + clusterMetrics.getNumActiveNMs(), 2, "There should be 2 Active NM!"); int nodeRemovalTimeout = conf.getInt( @@ -2539,12 +2544,12 @@ private void testNodeRemovalUtilRebooted(boolean doGraceful) wait(maxThreadSleeptime); } } - Assert.assertEquals("host2 should have been forgotten!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null); - Assert.assertEquals("There should be no Rebooted NMs!", - clusterMetrics.getNumRebootedNMs(), 0); - Assert.assertEquals("There should be 2 Active NM!", - clusterMetrics.getNumActiveNMs(), 2); + Assertions.assertEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null, "host2 should have been forgotten!"); + Assertions.assertEquals( + clusterMetrics.getNumRebootedNMs(), 0, "There should be no Rebooted NMs!"); + Assertions.assertEquals( + clusterMetrics.getNumActiveNMs(), 2, "There should be 2 Active NM!"); rm.stop(); } @@ -2575,14 +2580,14 @@ private void testNodeRemovalUtilUnhealthy(boolean doGraceful) rm.drainEvents(); //check all 3 nodes joined in as NORMAL NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm2.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); nodeHeartbeat = nm3.nodeHeartbeat(true); - Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); + Assertions.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction())); rm.drainEvents(); - Assert.assertEquals("All 3 nodes should be active", - metrics.getNumActiveNMs(), 3); + Assertions.assertEquals( + metrics.getNumActiveNMs(), 3, "All 3 nodes should be active"); // node healthy nm1.nodeHeartbeat(true); nm2.nodeHeartbeat(false); @@ -2596,20 +2601,20 @@ private void testNodeRemovalUtilUnhealthy(boolean doGraceful) nm3.nodeHeartbeat(true); rm.drainEvents(); if (!doGraceful) { - Assert.assertNotEquals("host2 should be a shutdown NM!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null); - Assert.assertEquals("host2 should be a shutdown NM!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()).getState(), - NodeState.SHUTDOWN); + Assertions.assertNotEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null, "host2 should be a shutdown NM!"); + Assertions.assertEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()).getState() +, NodeState.SHUTDOWN, "host2 should be a shutdown NM!"); } - Assert.assertEquals("There should be 2 Active NM!", - clusterMetrics.getNumActiveNMs(), 2); + Assertions.assertEquals( + clusterMetrics.getNumActiveNMs(), 2, "There should be 2 Active NM!"); if (!doGraceful) { - Assert.assertEquals("There should be 1 Shutdown NM!", - clusterMetrics.getNumShutdownNMs(), 1); + Assertions.assertEquals( + clusterMetrics.getNumShutdownNMs(), 1, "There should be 1 Shutdown NM!"); } - Assert.assertEquals("There should be 0 Unhealthy NM!", - clusterMetrics.getUnhealthyNMs(), 0); + Assertions.assertEquals( + clusterMetrics.getUnhealthyNMs(), 0, "There should be 0 Unhealthy NM!"); int nodeRemovalTimeout = conf.getInt( YarnConfiguration.RM_NODEMANAGER_UNTRACKED_REMOVAL_TIMEOUT_MSEC, @@ -2625,12 +2630,12 @@ private void testNodeRemovalUtilUnhealthy(boolean doGraceful) wait(maxThreadSleeptime); } } - Assert.assertEquals("host2 should have been forgotten!", - rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null); - Assert.assertEquals("There should be no Shutdown NMs!", - clusterMetrics.getNumRebootedNMs(), 0); - Assert.assertEquals("There should be 2 Active NM!", - clusterMetrics.getNumActiveNMs(), 2); + Assertions.assertEquals( + rmContext.getInactiveRMNodes().get(nm2.getNodeId()), null, "host2 should have been forgotten!"); + Assertions.assertEquals( + clusterMetrics.getNumRebootedNMs(), 0, "There should be no Shutdown NMs!"); + Assertions.assertEquals( + clusterMetrics.getNumActiveNMs(), 2, "There should be 2 Active NM!"); rm.stop(); } @@ -2699,10 +2704,10 @@ private void checkDecommissionedNMCount(MockRM rm, int count) wait(100); } } - Assert.assertEquals(count, ClusterMetrics.getMetrics() + Assertions.assertEquals(count, ClusterMetrics.getMetrics() .getNumDecommisionedNMs()); - Assert.assertEquals("The decommisioned metrics are not updated", count, - ClusterMetrics.getMetrics().getNumDecommisionedNMs()); + Assertions.assertEquals(count +, ClusterMetrics.getMetrics().getNumDecommisionedNMs(), "The decommisioned metrics are not updated"); } private void checkShutdownNMCount(MockRM rm, int count) @@ -2714,11 +2719,11 @@ private void checkShutdownNMCount(MockRM rm, int count) wait(100); } } - Assert.assertEquals("The shutdown metrics are not updated", count, - ClusterMetrics.getMetrics().getNumShutdownNMs()); + Assertions.assertEquals(count +, ClusterMetrics.getMetrics().getNumShutdownNMs(), "The shutdown metrics are not updated"); } - @After + @AfterEach public void tearDown() { if (hostFile != null && hostFile.exists()) { hostFile.delete(); @@ -2770,10 +2775,10 @@ protected Dispatcher createDispatcher() { } Resource currentConsumption = applicationAttempt.getCurrentConsumption(); - Assert.assertEquals(Resource.newInstance(0, 0), currentConsumption); + Assertions.assertEquals(Resource.newInstance(0, 0), currentConsumption); Resource allocResources = applicationAttempt.getQueue().getMetrics().getAllocatedResources(); - Assert.assertEquals(Resource.newInstance(0, 0), allocResources); + Assertions.assertEquals(Resource.newInstance(0, 0), allocResources); RegisterNodeManagerRequest req = Records.newRecord( RegisterNodeManagerRequest.class); @@ -2812,15 +2817,15 @@ protected Dispatcher createDispatcher() { dispatcher.await(); Thread.sleep(2000); dispatcher.await(); - Assert.assertEquals(NodeAction.NORMAL, response.getNodeAction()); + Assertions.assertEquals(NodeAction.NORMAL, response.getNodeAction()); Collection liveContainers = applicationAttempt .getLiveContainers(); - Assert.assertEquals(3, liveContainers.size()); + Assertions.assertEquals(3, liveContainers.size()); Iterator iter = liveContainers.iterator(); while (iter.hasNext()) { RMContainer rc = iter.next(); - Assert.assertEquals( + Assertions.assertEquals( rc.getContainerId().equals(c3) ? ExecutionType.GUARANTEED : ExecutionType.OPPORTUNISTIC, rc.getExecutionType()); @@ -2828,19 +2833,20 @@ protected Dispatcher createDispatcher() { // Should only include GUARANTEED resources currentConsumption = applicationAttempt.getCurrentConsumption(); - Assert.assertEquals(Resource.newInstance(2048, 1), currentConsumption); + Assertions.assertEquals(Resource.newInstance(2048, 1), currentConsumption); allocResources = applicationAttempt.getQueue().getMetrics().getAllocatedResources(); - Assert.assertEquals(Resource.newInstance(2048, 1), allocResources); + Assertions.assertEquals(Resource.newInstance(2048, 1), allocResources); SchedulerNode schedulerNode = rm.getRMContext().getScheduler().getSchedulerNode(nodeId); - Assert.assertNotNull(schedulerNode); + Assertions.assertNotNull(schedulerNode); Resource nodeResources = schedulerNode.getAllocatedResource(); - Assert.assertEquals(Resource.newInstance(2048, 1), nodeResources); + Assertions.assertEquals(Resource.newInstance(2048, 1), nodeResources); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testNodeHeartBeatResponseForUnknownContainerCleanUp() throws Exception { Configuration conf = new Configuration(); @@ -2902,7 +2908,7 @@ public void testResponseIdOverflow() throws Exception { MockNM nm1 = rm.registerNode("host1:1234", 5120); NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); + Assertions.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); // prepare the responseId that's about to overflow RMNode node = rm.getRMContext().getRMNodes().get(nm1.getNodeId()); @@ -2912,12 +2918,12 @@ public void testResponseIdOverflow() throws Exception { // heartbeat twice and check responseId nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); - Assert.assertEquals(0, nodeHeartbeat.getResponseId()); + Assertions.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); + Assertions.assertEquals(0, nodeHeartbeat.getResponseId()); nodeHeartbeat = nm1.nodeHeartbeat(true); - Assert.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); - Assert.assertEquals(1, nodeHeartbeat.getResponseId()); + Assertions.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction()); + Assertions.assertEquals(1, nodeHeartbeat.getResponseId()); } @Test @@ -2945,11 +2951,11 @@ protected ResourceTrackerService createResourceTrackerService() { NodeId.newInstance("host1" + System.currentTimeMillis(), 1234), 1236, Resource.newInstance(10000, 10), "2", new ArrayList<>(), new ArrayList<>())); - Assert - .assertEquals("Shutdown signal should be received", NodeAction.SHUTDOWN, - response.getNodeAction()); - Assert.assertTrue("Diagnostic Message", response.getDiagnosticsMessage() - .contains("hostname cannot be resolved ")); + Assertions + .assertEquals(NodeAction.SHUTDOWN +, response.getNodeAction(), "Shutdown signal should be received"); + Assertions.assertTrue(response.getDiagnosticsMessage() + .contains("hostname cannot be resolved "), "Diagnostic Message"); // Test success rmTracker = ServerRMProxy.createRMProxy(mockRM.getConfig(), ResourceTracker.class); @@ -2957,8 +2963,8 @@ protected ResourceTrackerService createResourceTrackerService() { .newInstance(NodeId.newInstance("localhost", 1234), 1236, Resource.newInstance(10000, 10), "2", new ArrayList<>(), new ArrayList<>())); - Assert.assertEquals("Successfull registration", NodeAction.NORMAL, - response.getNodeAction()); + Assertions.assertEquals(NodeAction.NORMAL +, response.getNodeAction(), "Successfull registration"); mockRM.stop(); } @@ -3004,7 +3010,8 @@ public void close() { } } - @Test(timeout = 5000) + @Test + @Timeout(value = 5) public void testSystemCredentialsAfterTokenSequenceNoChange() throws Exception { @@ -3340,20 +3347,20 @@ public void testMarkUnregisteredNodesAsLost() throws Exception { TimeUnit.MILLISECONDS.sleep(50); // Allow some time for event processing // Step 5: Validate that test_host3 is marked as a LOST node - Assert.assertNotNull(clusterMetrics); // Ensure metrics are not null - assertEquals("test_host3 should be a lost NM!", - NodeState.LOST, - rmContext.getInactiveRMNodes().get( - rm.getNodesListManager().createLostNodeId("test_host3")).getState()); + Assertions.assertNotNull(clusterMetrics); // Ensure metrics are not null + assertEquals( + NodeState.LOST +, rmContext.getInactiveRMNodes().get( + rm.getNodesListManager().createLostNodeId("test_host3")).getState(), "test_host3 should be a lost NM!"); // Step 6: Validate node metrics for lost, active, and decommissioned nodes // Two nodes are lost - assertEquals("There should be 2 Lost NM!", 2, clusterMetrics.getNumLostNMs()); + assertEquals(2, clusterMetrics.getNumLostNMs(), "There should be 2 Lost NM!"); // One node is active - assertEquals("There should be 1 Active NM!", 1, clusterMetrics.getNumActiveNMs()); + assertEquals(1, clusterMetrics.getNumActiveNMs(), "There should be 1 Active NM!"); // One node is decommissioned - assertEquals("There should be 1 Decommissioned NM!", 1, - clusterMetrics.getNumDecommisionedNMs()); + assertEquals(1 +, clusterMetrics.getNumDecommisionedNMs(), "There should be 1 Decommissioned NM!"); // Step 7: Register and simulate node activity for "test_host3" MockNM nm3 = rm.registerNode("test_host3:5678", 10240); // Register test_host3 with 10240MB @@ -3361,9 +3368,9 @@ public void testMarkUnregisteredNodesAsLost() throws Exception { TimeUnit.MILLISECONDS.sleep(50); // Allow some time for event dispatch and processing // Step 8: Validate updated node metrics after registering test_host3 - assertEquals("There should be 1 Lost NM!", 1, - clusterMetrics.getNumLostNMs()); // Only one node is lost now - assertEquals("There should be 2 Active NM!", 2, - clusterMetrics.getNumActiveNMs()); // Two nodes are now active + assertEquals(1 +, clusterMetrics.getNumLostNMs(), "There should be 1 Lost NM!"); // Only one node is lost now + assertEquals(2 +, clusterMetrics.getNumActiveNMs(), "There should be 2 Active NM!"); // Two nodes are now active } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestSignalContainer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestSignalContainer.java index 9f03a7226f971..700684863adc8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestSignalContainer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestSignalContainer.java @@ -23,7 +23,7 @@ import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +38,7 @@ 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.rmapp.attempt.RMAppAttemptState; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestSignalContainer { @@ -85,7 +85,7 @@ public void testSignalRequestDeliveryToNM() throws Exception { nm1.nodeHeartbeat(true); } } - Assert.assertEquals(request, conts.size()); + Assertions.assertEquals(request, conts.size()); for(Container container : conts) { rm.signalToContainer(container.getId(), @@ -107,7 +107,7 @@ public void testSignalRequestDeliveryToNM() throws Exception { } // Verify NM receives the expected number of signal container requests. - Assert.assertEquals(request, signaledConts); + Assertions.assertEquals(request, signaledConts); am.unregisterAppAttempt(); nm1.nodeHeartbeat(attempt.getAppAttemptId(), 1, ContainerState.COMPLETE); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestSubmitApplicationWithRMHA.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestSubmitApplicationWithRMHA.java index cb599ca3f416b..d7e4d02f7d611 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestSubmitApplicationWithRMHA.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestSubmitApplicationWithRMHA.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +29,8 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; public class TestSubmitApplicationWithRMHA extends RMHATestBase{ @@ -91,9 +92,9 @@ private void verifySubmitApp(MockRM rm, RMApp app, YarnApplicationState state = rm.getApplicationReport(app.getApplicationId()) .getYarnApplicationState(); - Assert.assertTrue(state == YarnApplicationState.ACCEPTED + Assertions.assertTrue(state == YarnApplicationState.ACCEPTED || state == YarnApplicationState.SUBMITTED); - Assert.assertEquals(expectedAppId, app.getApplicationId()); + Assertions.assertEquals(expectedAppId, app.getApplicationId()); } // There are two scenarios when RM failover happens @@ -124,7 +125,7 @@ private void verifySubmitApp(MockRM rm, RMApp app, rm2.getApplicationReport(app0.getApplicationId()); // verify previous submission is successful. - Assert.assertTrue(appReport.getYarnApplicationState() + Assertions.assertTrue(appReport.getYarnApplicationState() == YarnApplicationState.ACCEPTED || appReport.getYarnApplicationState() == YarnApplicationState.SUBMITTED); @@ -171,7 +172,7 @@ private void verifySubmitApp(MockRM rm, RMApp app, // Expect ApplicationNotFoundException by calling getApplicationReport(). try { rm2.getApplicationReport(app0.getApplicationId()); - Assert.fail("Should get ApplicationNotFoundException here"); + Assertions.fail("Should get ApplicationNotFoundException here"); } catch (ApplicationNotFoundException ex) { // expected ApplicationNotFoundException } @@ -217,7 +218,7 @@ public void testGetApplicationReportIdempotent() throws Exception{ ApplicationReport appReport1 = rm1.getApplicationReport(app.getApplicationId()); - Assert.assertTrue(appReport1.getYarnApplicationState() == + Assertions.assertTrue(appReport1.getYarnApplicationState() == YarnApplicationState.ACCEPTED || appReport1.getYarnApplicationState() == YarnApplicationState.SUBMITTED); @@ -225,9 +226,9 @@ public void testGetApplicationReportIdempotent() throws Exception{ // call getApplicationReport again ApplicationReport appReport2 = rm1.getApplicationReport(app.getApplicationId()); - Assert.assertEquals(appReport1.getApplicationId(), + Assertions.assertEquals(appReport1.getApplicationId(), appReport2.getApplicationId()); - Assert.assertEquals(appReport1.getYarnApplicationState(), + Assertions.assertEquals(appReport1.getYarnApplicationState(), appReport2.getYarnApplicationState()); // Do the failover @@ -236,17 +237,17 @@ public void testGetApplicationReportIdempotent() throws Exception{ // call getApplicationReport ApplicationReport appReport3 = rm2.getApplicationReport(app.getApplicationId()); - Assert.assertEquals(appReport1.getApplicationId(), + Assertions.assertEquals(appReport1.getApplicationId(), appReport3.getApplicationId()); - Assert.assertEquals(appReport1.getYarnApplicationState(), + Assertions.assertEquals(appReport1.getYarnApplicationState(), appReport3.getYarnApplicationState()); // call getApplicationReport again ApplicationReport appReport4 = rm2.getApplicationReport(app.getApplicationId()); - Assert.assertEquals(appReport3.getApplicationId(), + Assertions.assertEquals(appReport3.getApplicationId(), appReport4.getApplicationId()); - Assert.assertEquals(appReport3.getYarnApplicationState(), + Assertions.assertEquals(appReport3.getYarnApplicationState(), appReport4.getYarnApplicationState()); } @@ -254,7 +255,8 @@ public void testGetApplicationReportIdempotent() throws Exception{ // during SubmitApplication Call: // 1) RMStateStore already saved the ApplicationState when failover happens // 2) RMStateStore did not save the ApplicationState when failover happens - @Test (timeout = 50000) + @Test + @Timeout(value = 50) public void testHandleRMHADuringSubmitApplicationCallWithSavedApplicationState() throws Exception { @@ -274,7 +276,7 @@ public void testGetApplicationReportIdempotent() throws Exception{ // before failover happens, the current active rm can load the previous // applicationState. // This RMApp should exist in the RMContext of current active RM - Assert.assertTrue(rm2.getRMContext().getRMApps() + Assertions.assertTrue(rm2.getRMContext().getRMApps() .containsKey(app0.getApplicationId())); // When we re-submit the application with same applicationId, it will @@ -298,10 +300,11 @@ public void testGetApplicationReportIdempotent() throws Exception{ .withApplicationId(app0.getApplicationId()) .build()); - Assert.assertEquals(app1.getApplicationId(), app0.getApplicationId()); + Assertions.assertEquals(app1.getApplicationId(), app0.getApplicationId()); } - @Test (timeout = 50000) + @Test + @Timeout(value = 50) public void testHandleRMHADuringSubmitApplicationCallWithoutSavedApplicationState() throws Exception { @@ -339,7 +342,7 @@ public void testGetApplicationReportIdempotent() throws Exception{ // When failover happens, the RMStateStore has not saved applicationState. // The applicationState of this RMApp is lost. // We should not find the RMApp in the RMContext of current active rm. - Assert.assertFalse(rm2.getRMContext().getRMApps() + Assertions.assertFalse(rm2.getRMContext().getRMApps() .containsKey(app0.getApplicationId())); // Submit the application with previous ApplicationId to current active RM @@ -366,7 +369,7 @@ public void testGetApplicationReportIdempotent() throws Exception{ .build()); verifySubmitApp(rm2, app1, app0.getApplicationId()); - Assert.assertTrue(rm2.getRMContext().getRMApps() + Assertions.assertTrue(rm2.getRMContext().getRMApps() .containsKey(app0.getApplicationId())); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestTokenClientRMService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestTokenClientRMService.java index 3e1ede9cd4681..766f1ea482671 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestTokenClientRMService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestTokenClientRMService.java @@ -39,10 +39,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.RMDelegationTokenSecretManager; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.Records; -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.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TestTokenClientRMService { @@ -69,7 +69,7 @@ public class TestTokenClientRMService { private static final UserGroupInformation otherKerb = UserGroupInformation .createRemoteUser(otherPrincipal, AuthMethod.KERBEROS); - @BeforeClass + @BeforeAll public static void setupSecretManager() throws IOException { ResourceManager rm = mock(ResourceManager.class); RMContext rmContext = mock(RMContext.class); @@ -88,7 +88,7 @@ public static void setupSecretManager() throws IOException { .setAuthenticationMethod(AuthenticationMethod.KERBEROS); } - @AfterClass + @AfterAll public static void teardownSecretManager() { if (dtsm != null) { dtsm.stopThreads(); @@ -128,9 +128,9 @@ public Void run() throws Exception { checkTokenRenewal(owner, other); return null; } catch (YarnException ex) { - Assert.assertTrue(ex.getMessage().contains( + Assertions.assertTrue(ex.getMessage().contains( owner.getUserName() + " tries to renew a token")); - Assert.assertTrue(ex.getMessage().contains( + Assertions.assertTrue(ex.getMessage().contains( "with non-matching renewer " + other.getUserName())); throw ex; } @@ -139,7 +139,7 @@ public Void run() throws Exception { } catch (Exception e) { return; } - Assert.fail("renew should have failed"); + Assertions.fail("renew should have failed"); } @Test @@ -219,12 +219,12 @@ public void testTokenCancellationByWrongUser() { public Void run() throws Exception { try { checkTokenCancellation(rmService, tokOwner, tokRenewer); - Assert.fail("We should not reach here; token owner = " + Assertions.fail("We should not reach here; token owner = " + tokOwner.getUserName() + ", renewer = " + tokRenewer.getUserName()); return null; } catch (YarnException e) { - Assert.assertTrue(e.getMessage().contains( + Assertions.assertTrue(e.getMessage().contains( testerKerb.getUserName() + " is not authorized to cancel the token")); return null; @@ -232,7 +232,7 @@ public Void run() throws Exception { } }); } catch (Exception e) { - Assert.fail("Unexpected exception; " + e.getMessage()); + Assertions.fail("Unexpected exception; " + e.getMessage()); } } } @@ -249,12 +249,12 @@ public Void run() throws Exception { public Void run() throws Exception { try { checkTokenCancellation(tokOwner, tokRenewer); - Assert.fail("We should not reach here; token owner = " + Assertions.fail("We should not reach here; token owner = " + tokOwner.getUserName() + ", renewer = " + tokRenewer.getUserName()); return null; } catch (YarnException ex) { - Assert.assertTrue(ex.getMessage().contains( + Assertions.assertTrue(ex.getMessage().contains( tester.getUserName() + " is not authorized to cancel the token")); return null; @@ -262,7 +262,7 @@ public Void run() throws Exception { } }); } catch (Exception e) { - Assert.fail("Unexpected exception; " + e.getMessage()); + Assertions.fail("Unexpected exception; " + e.getMessage()); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java index 76cf0db9a02b5..95ae8036a7224 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingRMRestart.java @@ -87,10 +87,11 @@ 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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.io.File; import java.io.IOException; @@ -110,7 +111,7 @@ .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.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -127,7 +128,7 @@ public TestWorkPreservingRMRestart(SchedulerType type) throws IOException { super(type); } - @Before + @BeforeEach public void setup() throws UnknownHostException { GenericTestUtils.setRootLogLevel(Level.DEBUG); conf = getConf(); @@ -139,7 +140,7 @@ public void setup() throws UnknownHostException { DefaultMetricsSystem.setMiniClusterMode(true); } - @After + @AfterEach public void tearDown() { if (rm1 != null) { rm1.stop(); @@ -158,7 +159,8 @@ public void tearDown() { // 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) + @Test + @Timeout(value = 20) public void testSchedulerRecovery() throws Exception { conf.setBoolean(CapacitySchedulerConfiguration.ENABLE_USER_METRICS, true); conf.set(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS, @@ -219,13 +221,13 @@ public void testSchedulerRecovery() throws Exception { (AbstractYarnScheduler) rm2.getResourceScheduler(); SchedulerNode schedulerNode1 = scheduler.getSchedulerNode(nm1.getNodeId()); assertTrue( - "SchedulerNode#toString is not in expected format", - schedulerNode1 - .toString().contains(schedulerNode1.getUnallocatedResource().toString())); + + 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.getAllocatedResource().toString())); + + schedulerNode1 + .toString().contains(schedulerNode1.getAllocatedResource().toString()), "SchedulerNode#toString is not in expected format"); // ********* check scheduler node state.******* // 2 running containers. @@ -322,7 +324,8 @@ private Configuration getSchedulerDynamicConfiguration() throws IOException { // 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) + @Test + @Timeout(value = 30) public void testDynamicQueueRecovery() throws Exception { conf.setBoolean(CapacitySchedulerConfiguration.ENABLE_USER_METRICS, true); conf.set(CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS, @@ -512,7 +515,7 @@ private void checkFSQueue(ResourceManager rm, } retry++; if (retry > 30) { - Assert.fail("Apps are not scheduled within assumed timeout"); + Assertions.fail("Apps are not scheduled within assumed timeout"); } } @@ -622,7 +625,8 @@ private void setupQueueConfigurationChildOfB(CapacitySchedulerConfiguration conf // 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) + @Test + @Timeout(value = 30) public void testRMRestartWithRemovedQueue() throws Exception{ conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true); conf.set(YarnConfiguration.YARN_ADMIN_ACL, ""); @@ -659,7 +663,7 @@ public ApplicationReport run() throws Exception { return rm2.getApplicationReport(app1.getApplicationId()); } }); - Assert.assertNotNull(report); + Assertions.assertNotNull(report); } // Test CS recovery with multi-level queues and multi-users: @@ -673,7 +677,8 @@ public ApplicationReport run() throws Exception { // 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) + @Test + @Timeout(value = 30) public void testCapacitySchedulerRecovery() throws Exception { if (getSchedulerType() != SchedulerType.CAPACITY) { return; @@ -852,7 +857,7 @@ private void verifyAppRecoveryWithWrongQueueConfig( MockRM rm = new MockRM(csConf, memStore2); try { rm.start(); - Assert.fail("QueueException must have been thrown"); + Assertions.fail("QueueException must have been thrown"); } catch (QueueInvalidException e) { } finally { rm.close(); @@ -866,7 +871,8 @@ private void verifyAppRecoveryWithWrongQueueConfig( // 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) + @Test + @Timeout(value = 30) public void testCapacityLeafQueueBecomesParentOnRecovery() throws Exception { if (getSchedulerType() != SchedulerType.CAPACITY) { return; @@ -922,7 +928,8 @@ public void testCapacityLeafQueueBecomesParentOnRecovery() throws Exception { // 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) + @Test + @Timeout(value = 30) public void testCapacitySchedulerQueueRemovedRecovery() throws Exception { if (getSchedulerType() != SchedulerType.CAPACITY) { return; @@ -1016,7 +1023,8 @@ private void checkParentQueue(ParentQueue parentQueue, int numContainers, // 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) + @Test + @Timeout(value = 20) public void testAMfailedBetweenRMRestart() throws Exception { conf.setLong(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_SCHEDULING_WAIT_MS, 0); rm1 = new MockRM(conf); @@ -1068,7 +1076,8 @@ public void testAMfailedBetweenRMRestart() throws Exception { // Apps already completed before RM restart. Restarted RM scheduler should not // recover containers for completed apps. - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testContainersNotRecoveredForCompletedApps() throws Exception { rm1 = new MockRM(conf); rm1.start(); @@ -1105,7 +1114,8 @@ public void testContainersNotRecoveredForCompletedApps() throws Exception { assertNull(scheduler.getRMContainer(completedContainer.getContainerId())); } - @Test (timeout = 600000) + @Test + @Timeout(value = 600) public void testAppReregisterOnRMWorkPreservingRestart() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -1137,7 +1147,8 @@ public void testAppReregisterOnRMWorkPreservingRestart() throws Exception { rm2.waitForState(am0.getApplicationAttemptId(), RMAppAttemptState.RUNNING); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAMContainerStatusWithRMRestart() throws Exception { rm1 = new MockRM(conf); rm1.start(); @@ -1150,7 +1161,7 @@ public void testAMContainerStatusWithRMRestart() throws Exception { RMAppAttempt attempt0 = app1_1.getCurrentAppAttempt(); YarnScheduler scheduler = rm1.getResourceScheduler(); - Assert.assertTrue(scheduler.getRMContainer( + Assertions.assertTrue(scheduler.getRMContainer( attempt0.getMasterContainer().getId()).isAMContainer()); // Re-start RM @@ -1166,11 +1177,12 @@ public void testAMContainerStatusWithRMRestart() throws Exception { waitForNumContainersToRecover(2, rm2, am1_1.getApplicationAttemptId()); scheduler = rm2.getResourceScheduler(); - Assert.assertTrue(scheduler.getRMContainer( + Assertions.assertTrue(scheduler.getRMContainer( attempt0.getMasterContainer().getId()).isAMContainer()); } - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testRecoverSchedulerAppAndAttemptSynchronously() throws Exception { // start RM rm1 = new MockRM(conf); @@ -1187,7 +1199,7 @@ public void testRecoverSchedulerAppAndAttemptSynchronously() throws Exception { rm2.start(); nm1.setResourceTrackerService(rm2.getResourceTrackerService()); // scheduler app/attempt is immediately available after RM is re-started. - Assert.assertNotNull(rm2.getResourceScheduler().getSchedulerAppInfo( + Assertions.assertNotNull(rm2.getResourceScheduler().getSchedulerAppInfo( am0.getApplicationAttemptId())); // getTransferredContainers should not throw NPE. @@ -1202,7 +1214,8 @@ public void testRecoverSchedulerAppAndAttemptSynchronously() throws Exception { // 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) + @Test + @Timeout(value = 50) public void testReleasedContainerNotRecovered() throws Exception { rm1 = new MockRM(conf); MockNM nm1 = new MockNM("h1:1234", 15120, rm1.getResourceTrackerService()); @@ -1295,7 +1308,8 @@ public static void waitForNumContainersToRecover(int num, MockRM rm, } } - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testNewContainersNotAllocatedDuringSchedulerRecovery() throws Exception { conf.setLong( @@ -1332,7 +1346,7 @@ public void testNewContainersNotAllocatedDuringSchedulerRecovery() containers.addAll(am1.allocate(new ArrayList(), new ArrayList()).getAllocatedContainers()); // container is not allocated during scheduling recovery. - Assert.assertTrue(containers.isEmpty()); + Assertions.assertTrue(containers.isEmpty()); clock.setTime(startTime + 8000); nm1.nodeHeartbeat(true); @@ -1348,7 +1362,8 @@ public void testNewContainersNotAllocatedDuringSchedulerRecovery() * Testing to confirm that retried finishApplicationMaster() doesn't throw * InvalidApplicationMasterRequest before and after RM restart. */ - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testRetriedFinishApplicationMasterRequest() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -1383,7 +1398,8 @@ public void testRetriedFinishApplicationMasterRequest() am0.unregisterAppAttempt(false); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppFailedToRenewTokenOnRecovery() throws Exception { conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); @@ -1432,7 +1448,8 @@ public void addApplicationSync(ApplicationId applicationId, * Test validateAndCreateResourceRequest fails on recovery, app should ignore * this Exception and continue */ - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppFailToValidateResourceRequestOnRecovery() throws Exception{ rm1 = new MockRM(conf); rm1.start(); @@ -1452,7 +1469,8 @@ public void testAppFailToValidateResourceRequestOnRecovery() throws Exception{ rm2.start(); } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testContainerCompleteMsgNotLostAfterAMFailedAndRMRestart() throws Exception { rm1 = new MockRM(conf); rm1.start(); @@ -1516,7 +1534,8 @@ public void testContainerCompleteMsgNotLostAfterAMFailedAndRMRestart() throws Ex // Test that if application state was saved, but attempt state was not saved. // RM should start correctly. - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testAppStateSavedButAttemptStateNotSaved() throws Exception { MockMemoryRMStateStore memStore = new MockMemoryRMStateStore() { @Override public synchronized void updateApplicationAttemptStateInternal( @@ -1555,7 +1574,8 @@ public void testAppStateSavedButAttemptStateNotSaved() throws Exception { assertEquals(RMAppAttemptState.FINISHED, recoveredApp1.getCurrentAppAttempt().getState()); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testUAMRecoveryOnRMWorkPreservingRestart() throws Exception { conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -1635,18 +1655,18 @@ public void testUAMRecoveryOnRMWorkPreservingRestart() throws Exception { schedulerApps.get(recoveredApp.getApplicationId()); SchedulerApplicationAttempt schedulerAttempt = schedulerApp.getCurrentAppAttempt(); - Assert.assertEquals(numContainers, + Assertions.assertEquals(numContainers, schedulerAttempt.getLiveContainers().size()); // Check if UAM is able to heart beat - Assert.assertNotNull(am0.doHeartbeat()); + Assertions.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, + Assertions.assertEquals(FinalApplicationStatus.SUCCEEDED, recoveredApp.getFinalApplicationStatus()); assertUnmanagedAMQueueMetrics(qm2, 1, 0, 0, 1); @@ -1655,7 +1675,7 @@ public void testUAMRecoveryOnRMWorkPreservingRestart() throws Exception { rm3.start(); recoveredApp = rm3.getRMContext().getRMApps().get(app0.getApplicationId()); QueueMetrics qm3 = rm3.getResourceScheduler().getRootQueueMetrics(); - Assert.assertEquals(RMAppState.FINISHED, recoveredApp.getState()); + Assertions.assertEquals(RMAppState.FINISHED, recoveredApp.getState()); assertUnmanagedAMQueueMetrics(qm2, 1, 0, 0, 1); } @@ -1666,7 +1686,8 @@ public void testUAMRecoveryOnRMWorkPreservingRestart() throws Exception { //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) + @Test + @Timeout(value = 60) public void testQueueRecoveryOnRMWorkPreservingRestart() throws Exception { if (getSchedulerType() != SchedulerType.CAPACITY) { return; @@ -1742,19 +1763,20 @@ ApplicationPlacementContext placeApplication( am.registerAppAttempt(true); rm2.waitForState(recoveredApp0.getApplicationId(), RMAppState.RUNNING); - Assert.assertEquals("root.joe.test", recoveredApp0.getQueue()); + Assertions.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()); + Assertions.assertEquals(appsSubmitted, qm.getUnmanagedAppsSubmitted()); + Assertions.assertEquals(appsPending, qm.getUnmanagedAppsPending()); + Assertions.assertEquals(appsRunning, qm.getUnmanagedAppsRunning()); + Assertions.assertEquals(appsCompleted, qm.getUnmanagedAppsCompleted()); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testUnknownUserOnRecovery() throws Exception { MockRM rm1 = new MockRM(conf); @@ -1797,30 +1819,34 @@ ApplicationPlacementContext placeApplication( rm2.start(); RMApp recoveredApp = rm2.getRMContext().getRMApps().get(app0.getApplicationId()); - Assert.assertEquals(RMAppState.KILLED, recoveredApp.getState()); + Assertions.assertEquals(RMAppState.KILLED, recoveredApp.getState()); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testDynamicFlexibleAutoCreatedQueueRecoveryWithDefaultQueue() throws Exception { //if queue name is not specified, it should submit to 'default' queue testDynamicAutoCreatedQueueRecovery(USER1, null, true); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testDynamicAutoCreatedQueueRecoveryWithDefaultQueue() throws Exception { //if queue name is not specified, it should submit to 'default' queue testDynamicAutoCreatedQueueRecovery(USER1, null, false); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testDynamicFlexibleAutoCreatedQueueRecoveryWithOverrideQueueMappingFlag() throws Exception { testDynamicAutoCreatedQueueRecovery(USER1, USER1, true); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testDynamicAutoCreatedQueueRecoveryWithOverrideQueueMappingFlag() throws Exception { testDynamicAutoCreatedQueueRecovery(USER1, USER1, false); @@ -1962,7 +1988,8 @@ public void testDynamicAutoCreatedQueueRecovery( // Apps already completed before RM restart. Make sure we restore the queue // correctly - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testFairSchedulerCompletedAppsQueue() throws Exception { if (getSchedulerType() != SchedulerType.FAIR) { return; @@ -1979,10 +2006,10 @@ public void testFairSchedulerCompletedAppsQueue() throws Exception { 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 +2017,12 @@ public void testFairSchedulerCompletedAppsQueue() throws Exception { 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"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingUnmanagedAM.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingUnmanagedAM.java index 3c57dfc19e61c..221bb3341358d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingUnmanagedAM.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestWorkPreservingUnmanagedAM.java @@ -39,9 +39,10 @@ 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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; /** * Test UAM handling in RM. @@ -55,7 +56,7 @@ public TestWorkPreservingUnmanagedAM(SchedulerType type) throws IOException { super(type); } - @Before + @BeforeEach public void setup() { GenericTestUtils.setRootLogLevel(Level.DEBUG); conf = getConf(); @@ -142,15 +143,15 @@ protected void testUAMRestart(boolean keepContainers) throws Exception { response.getNMTokensFromPreviousAttempts() .forEach(token -> tokenCacheClientSide.add(token.getNodeId())); } catch (InvalidApplicationMasterRequestException e) { - Assert.assertEquals(false, keepContainers); + Assertions.assertEquals(false, keepContainers); return; } - Assert.assertEquals("RM should not allow second register" - + " for UAM without keep container flag ", true, keepContainers); + Assertions.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()); + Assertions.assertEquals(2, response.getContainersFromPreviousAttempts().size()); + Assertions.assertEquals(1, response.getNMTokensFromPreviousAttempts().size()); // Allocate one more containers to UAM, just to be safe numContainers = 1; @@ -248,15 +249,15 @@ protected void testUAMRestartWithoutTransferContainer(boolean keepContainers) th response.getNMTokensFromPreviousAttempts() .forEach(token -> tokenCacheClientSide.add(token.getNodeId())); } catch (InvalidApplicationMasterRequestException e) { - Assert.assertEquals(false, keepContainers); + Assertions.assertEquals(false, keepContainers); return; } - Assert.assertEquals("RM should not allow second register" - + " for UAM without keep container flag ", true, keepContainers); + Assertions.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()); + Assertions.assertEquals(0, response.getContainersFromPreviousAttempts().size()); + Assertions.assertEquals(0, response.getNMTokensFromPreviousAttempts().size()); // Allocate one more containers to UAM, just to be safe numContainers = 1; @@ -278,29 +279,33 @@ protected void testUAMRestartWithoutTransferContainer(boolean keepContainers) th rm.stop(); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testUAMRestartKeepContainers() throws Exception { testUAMRestart(true); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testUAMRestartNoKeepContainers() throws Exception { testUAMRestart(false); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testUAMRestartKeepContainersWithoutTransferContainer() throws Exception { testUAMRestartWithoutTransferContainer(true); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testUAMRestartNoKeepContainersWithoutTransferContainer() throws Exception { testUAMRestartWithoutTransferContainer(false); } private void checkNMTokenForContainer(Set cacheToken, List containers) { for (Container container : containers) { - Assert.assertTrue(cacheToken.contains(container.getNodeId())); + Assertions.assertTrue(cacheToken.contains(container.getNodeId())); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/webapp/TestRMWithCSRFFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/webapp/TestRMWithCSRFFilter.java index 0f827a7e8899a..b8161479d9379 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/webapp/TestRMWithCSRFFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/webapp/TestRMWithCSRFFilter.java @@ -36,8 +36,8 @@ import org.glassfish.jersey.jettison.JettisonFeature; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.TestProperties; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -55,8 +55,8 @@ import java.util.HashMap; import java.util.Map; -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.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -108,7 +108,7 @@ protected void configure() { } } - @Before + @BeforeEach @Override public void setUp() throws Exception { super.setUp(); @@ -137,8 +137,8 @@ public void testIncludeCustomHeaderFromBrowser() throws Exception { .header(RestCsrfPreventionFilter.HEADER_USER_AGENT,"Mozilla/5.0") .header("X-XSRF-HEADER", "") .get(Response.class); - assertTrue("Should have been accepted", response.getStatus() == - Response.Status.OK.getStatusCode()); + assertTrue(response.getStatus() == + Response.Status.OK.getStatusCode(), "Should have been accepted"); assertEquals(MediaType.APPLICATION_XML_TYPE + ";" + JettyUtils.UTF_8, response.getMediaType().toString()); String xml = response.readEntity(String.class); @@ -152,8 +152,8 @@ public void testAllowedMethod() throws Exception { .path("info").request("application/xml") .header(RestCsrfPreventionFilter.HEADER_USER_AGENT,"Mozilla/5.0") .head(); - assertTrue("Should have been allowed", response.getStatus() == - Response.Status.OK.getStatusCode()); + assertTrue(response.getStatus() == + Response.Status.OK.getStatusCode(), "Should have been allowed"); } @Test @@ -162,8 +162,8 @@ public void testAllowNonBrowserInteractionWithoutHeader() throws Exception { Response response = r.path("ws").path("v1").path("cluster") .path("info").request("application/xml") .get(Response.class); - assertTrue("Should have been accepted", response.getStatus() == - Response.Status.OK.getStatusCode()); + assertTrue(response.getStatus() == + Response.Status.OK.getStatusCode(), "Should have been accepted"); assertEquals(MediaType.APPLICATION_XML_TYPE + ";" + JettyUtils.UTF_8, response.getMediaType().toString()); String xml = response.readEntity(String.class); @@ -177,7 +177,7 @@ public void verifyClusterInfoXML(String xml) throws Exception { is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList nodes = dom.getElementsByTagName("clusterInfo"); - assertEquals("incorrect number of elements", 1, nodes.getLength()); + assertEquals(1, nodes.getLength(), "incorrect number of elements"); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); @@ -209,14 +209,14 @@ public void verifyClusterGeneric(long clusterid, long startedon, String resourceManagerBuildVersion, String resourceManagerVersion) { - assertEquals("clusterId doesn't match: ", - ResourceManager.getClusterTimeStamp(), clusterid); - assertEquals("startedOn doesn't match: ", - ResourceManager.getClusterTimeStamp(), startedon); - assertTrue("stated doesn't match: " + state, - state.matches(STATE.INITED.toString())); - assertTrue("HA state doesn't match: " + haState, - haState.matches("INITIALIZING")); + assertEquals( + ResourceManager.getClusterTimeStamp(), clusterid, "clusterId doesn't match: "); + assertEquals( + ResourceManager.getClusterTimeStamp(), startedon, "startedOn doesn't match: "); + assertTrue( + state.matches(STATE.INITED.toString()), "stated doesn't match: " + state); + assertTrue( + haState.matches("INITIALIZING"), "HA state doesn't match: " + haState); WebServicesTestUtils.checkStringMatch("hadoopVersionBuiltOn", VersionInfo.getDate(), hadoopVersionBuiltOn); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/webapp/TestRMWithXFSFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/webapp/TestRMWithXFSFilter.java index 2054754760d71..216edb5c4b3af 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/webapp/TestRMWithXFSFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/webapp/TestRMWithXFSFilter.java @@ -24,9 +24,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRM; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.HttpURLConnection; @@ -62,7 +62,7 @@ public void testXFrameOptionsDefaultBehaviour() throws Exception { URL url = new URL("http://localhost:8088/ws/v1/cluster/info"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); String xfoHeader = conn.getHeaderField("X-FRAME-OPTIONS"); - Assert.assertTrue(xfoHeader.endsWith(HttpServer2.XFrameOption + Assertions.assertTrue(xfoHeader.endsWith(HttpServer2.XFrameOption .SAMEORIGIN.toString())); } @@ -74,7 +74,7 @@ public void testXFrameOptionsExplicitlyEnabled() throws Exception { URL url = new URL("http://localhost:8088/ws/v1/cluster/info"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); String xfoHeader = conn.getHeaderField("X-FRAME-OPTIONS"); - Assert.assertTrue(xfoHeader.endsWith(HttpServer2.XFrameOption + Assertions.assertTrue(xfoHeader.endsWith(HttpServer2.XFrameOption .SAMEORIGIN.toString())); } @@ -86,7 +86,7 @@ public void testXFrameOptionsEnabledDefaultApps() throws Exception { URL url = new URL("http://localhost:8088/logs"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); String xfoHeader = conn.getHeaderField("X-FRAME-OPTIONS"); - Assert.assertTrue(xfoHeader.endsWith(HttpServer2.XFrameOption + Assertions.assertTrue(xfoHeader.endsWith(HttpServer2.XFrameOption .SAMEORIGIN.toString())); } @@ -97,17 +97,17 @@ public void testXFrameOptionsDisabled() throws Exception { URL url = new URL("http://localhost:8088/ws/v1/cluster/info"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); String xfoHeader = conn.getHeaderField("X-FRAME-OPTIONS"); - Assert.assertNull("Unexpected X-FRAME-OPTION in header", xfoHeader); + Assertions.assertNull(xfoHeader, "Unexpected X-FRAME-OPTION in header"); } @Test public void testXFrameOptionsIllegalOption() { - IllegalArgumentException e = Assert.assertThrows( + IllegalArgumentException e = Assertions.assertThrows( IllegalArgumentException.class, () -> createMockRm(true, "otherValue")); } - @After + @AfterEach public void tearDown() throws IOException { rm.close(); }