From 2b3c0d9385a1b365e542f5d6511fab6c75dee160 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sat, 8 Mar 2025 22:26:42 +0800 Subject: [PATCH 1/2] YARN-11262. Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcemanager Part3. --- .../activities/TestActivitiesManager.java | 64 ++- .../CapacitySchedulerPreemptionTestBase.java | 14 +- ...citySchedulerQueueCalculationTestBase.java | 4 +- .../CapacitySchedulerQueueHelpers.java | 16 +- .../CapacitySchedulerTestUtilities.java | 10 +- .../capacity/QueueAssertionBuilder.java | 14 +- ...estAMAllocatedToNonExclusivePartition.java | 10 +- .../TestAbsoluteResourceConfiguration.java | 528 +++++++++--------- .../TestAbsoluteResourceWithAutoQueue.java | 41 +- .../capacity/TestApplicationLimits.java | 28 +- .../TestApplicationLimitsByPartition.java | 163 +++--- .../capacity/TestApplicationPriority.java | 141 ++--- ...stApplicationPriorityACLConfiguration.java | 10 +- .../capacity/TestApplicationPriorityACLs.java | 12 +- .../TestAutoCreatedQueueDeletionPolicy.java | 76 +-- .../TestAutoCreatedQueueTemplate.java | 83 ++- .../TestCSAllocateCustomResource.java | 56 +- .../TestCSMaxRunningAppsEnforcer.java | 8 +- .../scheduler/capacity/TestCSQueueStore.java | 8 +- .../capacity/TestCapacityScheduler.java | 415 +++++++------- .../TestCapacitySchedulerAmbiguousLeafs.java | 2 +- .../capacity/TestCapacitySchedulerApps.java | 280 +++++----- .../TestCapacitySchedulerAsyncScheduling.java | 144 ++--- ...CapacitySchedulerAutoCreatedQueueBase.java | 20 +- ...tySchedulerAutoCreatedQueuePreemption.java | 13 +- ...estCapacitySchedulerAutoQueueCreation.java | 104 ++-- .../TestCapacitySchedulerConfigValidator.java | 186 +++--- .../TestCapacitySchedulerConfiguration.java | 8 +- .../TestCapacitySchedulerDynamicBehavior.java | 22 +- .../TestCapacitySchedulerLazyPreemption.java | 121 ++-- .../TestCapacitySchedulerMaxParallelApps.java | 49 +- .../TestCapacitySchedulerMultiNodes.java | 107 ++-- ...citySchedulerMultiNodesWithPreemption.java | 36 +- ...CapacitySchedulerNewQueueAutoCreation.java | 509 ++++++++--------- ...wQueueAutoCreationWithCapacityVectors.java | 100 ++-- .../TestCapacitySchedulerNodeLabelUpdate.java | 130 +++-- .../capacity/TestCapacitySchedulerNodes.java | 60 +- .../capacity/TestCapacitySchedulerPerf.java | 24 +- .../TestCapacitySchedulerQueueACLs.java | 8 +- ...tCapacitySchedulerQueueMappingFactory.java | 9 +- .../capacity/TestCapacitySchedulerQueues.java | 430 +++++++------- ...acitySchedulerSchedulingRequestUpdate.java | 2 +- ...stCapacitySchedulerSurgicalPreemption.java | 137 ++--- .../TestCapacitySchedulerWeightMode.java | 64 ++- ...pacitySchedulerWithMultiResourceTypes.java | 74 +-- ...acitySchedulerWorkflowPriorityMapping.java | 8 +- .../capacity/TestChildQueueOrder.java | 12 +- .../capacity/TestConfigurationProperties.java | 86 +-- .../capacity/TestContainerAllocation.java | 263 ++++----- .../capacity/TestContainerResizing.java | 212 +++---- .../TestIncreaseAllocationExpirer.java | 76 +-- .../scheduler/capacity/TestLeafQueue.java | 154 ++--- .../TestMixedQueueResourceCalculation.java | 24 +- .../TestNodeLabelContainerAllocation.java | 360 ++++++------ .../scheduler/capacity/TestParentQueue.java | 131 ++--- .../capacity/TestQueueCapacities.java | 16 +- .../capacity/TestQueueCapacityVector.java | 42 +- ...stQueueConfigurationAutoRefreshPolicy.java | 32 +- .../TestQueueManagementDynamicEditPolicy.java | 8 +- .../scheduler/capacity/TestQueueMappings.java | 40 +- .../scheduler/capacity/TestQueueParsing.java | 384 +++++++------ .../scheduler/capacity/TestQueuePath.java | 100 ++-- .../scheduler/capacity/TestQueueState.java | 76 +-- .../capacity/TestQueueStateManager.java | 50 +- .../capacity/TestReservationQueue.java | 16 +- .../scheduler/capacity/TestReservations.java | 16 +- .../capacity/TestResourceVector.java | 54 +- ...tSchedulingRequestContainerAllocation.java | 163 +++--- ...dulingRequestContainerAllocationAsync.java | 28 +- .../TestUniformQueueResourceCalculation.java | 2 +- .../scheduler/capacity/TestUsersManager.java | 10 +- ...stWorkPreservingRMRestartForNodeLabel.java | 22 +- .../conf/ConfigurationStoreBaseTest.java | 14 +- .../PersistentConfigurationStoreBaseTest.java | 6 +- .../TestConfigurationUpdateAssembler.java | 14 +- .../TestFSSchedulerConfigurationStore.java | 22 +- .../conf/TestInMemoryConfigurationStore.java | 4 +- .../conf/TestLeveldbConfigurationStore.java | 42 +- .../TestMutableCSConfigurationProvider.java | 16 +- .../conf/TestQueueCapacityConfigParser.java | 80 +-- .../conf/TestZKConfigurationStore.java | 184 +++--- .../placement/TestMappingRuleCreator.java | 30 +- .../TestLegacyMappingRuleToJson.java | 8 +- ...riorityUtilizationQueueOrderingPolicy.java | 6 +- .../TestDeactivatedLeafQueuesByLabel.java | 4 +- 85 files changed, 3676 insertions(+), 3479 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/activities/TestActivitiesManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/activities/TestActivitiesManager.java index 9e3ff635ee57d..06f4765abe199 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/activities/TestActivitiesManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/activities/TestActivitiesManager.java @@ -56,9 +56,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppActivitiesInfo; import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey; import org.apache.hadoop.yarn.util.SystemClock; -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.apache.hadoop.yarn.util.resource.Resources; @@ -89,7 +90,7 @@ public class TestActivitiesManager { private ThreadPoolExecutor threadPoolExecutor; - @Before + @BeforeEach public void setup() { rmContext = Mockito.mock(RMContext.class); Configuration conf = new Configuration(); @@ -163,12 +164,12 @@ public void testRecordingDifferentNodeActivitiesInMultiThreads() } // Check activities for all nodes should be recorded and every node should // have only one allocation information. - Assert.assertEquals(NUM_NODES, + Assertions.assertEquals(NUM_NODES, activitiesManager.historyNodeAllocations.size()); for (List> nodeAllocationsForThisNode : activitiesManager.historyNodeAllocations.values()) { - Assert.assertEquals(1, nodeAllocationsForThisNode.size()); - Assert.assertEquals(1, nodeAllocationsForThisNode.get(0).size()); + Assertions.assertEquals(1, nodeAllocationsForThisNode.size()); + Assertions.assertEquals(1, nodeAllocationsForThisNode.get(0).size()); } } @@ -207,7 +208,7 @@ public void testRecordingSchedulerActivitiesForMultiNodesInMultiThreads() future.get(); } // Check activities for multi-nodes should be recorded only once - Assert.assertEquals(1, activitiesManager.historyNodeAllocations.size()); + Assertions.assertEquals(1, activitiesManager.historyNodeAllocations.size()); } @@ -254,13 +255,14 @@ public void testRecordingAppActivitiesInMultiThreads() Queue appAllocations = activitiesManager.completedAppAllocations .get(randomApp.getApplicationId()); - Assert.assertEquals(nTasks, appAllocations.size()); + Assertions.assertEquals(nTasks, appAllocations.size()); for(AppAllocation aa : appAllocations) { - Assert.assertEquals(NUM_NODES, aa.getAllocationAttempts().size()); + Assertions.assertEquals(NUM_NODES, aa.getAllocationAttempts().size()); } } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppActivitiesTTL() throws Exception { long cleanupIntervalMs = 100; long appActivitiesTTL = 1000; @@ -295,7 +297,7 @@ public void testAppActivitiesTTL() throws Exception { AppActivitiesInfo appActivitiesInfo = newActivitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1, false, 3); - Assert.assertEquals(numActivities, + Assertions.assertEquals(numActivities, appActivitiesInfo.getAllocations().size()); // sleep until all app activities expired Thread.sleep(cleanupIntervalMs + appActivitiesTTL); @@ -303,11 +305,12 @@ public void testAppActivitiesTTL() throws Exception { appActivitiesInfo = newActivitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1, false, 3); - Assert.assertEquals(0, + Assertions.assertEquals(0, appActivitiesInfo.getAllocations().size()); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppActivitiesPerformance() { // start recording activities for first app SchedulerApplicationAttempt app = apps.get(0); @@ -343,12 +346,12 @@ public void testAppActivitiesPerformance() { AppActivitiesInfo appActivitiesInfo = activitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1, false, 100); - Assert.assertEquals(numActivities, + Assertions.assertEquals(numActivities, appActivitiesInfo.getAllocations().size()); - Assert.assertEquals(1, + Assertions.assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .size()); - Assert.assertEquals(numNodes, + Assertions.assertEquals(numNodes, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().size()); return null; @@ -361,15 +364,15 @@ public void testAppActivitiesPerformance() { AppActivitiesInfo appActivitiesInfo = activitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, RMWSConsts.ActivitiesGroupBy.DIAGNOSTIC, -1, false, 100); - Assert.assertEquals(numActivities, + Assertions.assertEquals(numActivities, appActivitiesInfo.getAllocations().size()); - Assert.assertEquals(1, + Assertions.assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .size()); - Assert.assertEquals(1, + Assertions.assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().size()); - Assert.assertEquals(numNodes, + Assertions.assertEquals(numNodes, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().get(0).getNodeIds().size()); return null; @@ -382,14 +385,14 @@ public void testAppActivitiesPerformance() { AppActivitiesInfo appActivitiesInfo = activitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, RMWSConsts.ActivitiesGroupBy.DIAGNOSTIC, -1, true, 100); - Assert.assertEquals(1, appActivitiesInfo.getAllocations().size()); - Assert.assertEquals(1, + Assertions.assertEquals(1, appActivitiesInfo.getAllocations().size()); + Assertions.assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .size()); - Assert.assertEquals(1, + Assertions.assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().size()); - Assert.assertEquals(numNodes, + Assertions.assertEquals(numNodes, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().get(0).getNodeIds().size()); return null; @@ -398,7 +401,8 @@ public void testAppActivitiesPerformance() { testingTimes); } - @Test (timeout = 10000) + @Test + @Timeout(value = 10) public void testAppActivitiesMaxQueueLengthUpdate() throws TimeoutException, InterruptedException { Configuration conf = new Configuration(); @@ -427,14 +431,14 @@ public void testAppActivitiesMaxQueueLengthUpdate() .thenReturn(numAsyncSchedulerThreads); ActivitiesManager newActivitiesManager = new ActivitiesManager(mockRMContext); - Assert.assertEquals(1, + Assertions.assertEquals(1, newActivitiesManager.getAppActivitiesMaxQueueLength()); newActivitiesManager.init(conf); newActivitiesManager.start(); GenericTestUtils.waitFor( () -> newActivitiesManager.getAppActivitiesMaxQueueLength() == numNodes * numAsyncSchedulerThreads, 100, 3000); - Assert.assertEquals(15, + Assertions.assertEquals(15, newActivitiesManager.getAppActivitiesMaxQueueLength()); /* * Test for HB-driven scheduling with multi-node placement disabled @@ -443,7 +447,7 @@ public void testAppActivitiesMaxQueueLengthUpdate() GenericTestUtils.waitFor( () -> newActivitiesManager.getAppActivitiesMaxQueueLength() == numNodes * 1.2, 100, 3000); - Assert.assertEquals(6, + Assertions.assertEquals(6, newActivitiesManager.getAppActivitiesMaxQueueLength()); /* * Test for scheduling with multi-node placement enabled @@ -452,7 +456,7 @@ public void testAppActivitiesMaxQueueLengthUpdate() GenericTestUtils.waitFor( () -> newActivitiesManager.getAppActivitiesMaxQueueLength() == configuredAppActivitiesMaxQueueLength, 100, 3000); - Assert.assertEquals(1, + Assertions.assertEquals(1, newActivitiesManager.getAppActivitiesMaxQueueLength()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerPreemptionTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerPreemptionTestBase.java index 41ee40ebcd2bc..19cf6e8d45a5c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerPreemptionTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerPreemptionTestBase.java @@ -33,8 +33,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode; import org.apache.hadoop.yarn.util.Clock; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -49,7 +49,7 @@ public class CapacitySchedulerPreemptionTestBase { Clock clock; - @Before + @BeforeEach void setUp() throws Exception { conf = new CapacitySchedulerConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -106,7 +106,7 @@ public void waitNumberOfLiveContainersFromApp(FiCaSchedulerApp app, waitNum++; } - Assert.fail(); + Assertions.fail(); } public void waitNumberOfReservedContainersFromApp(FiCaSchedulerApp app, @@ -122,7 +122,7 @@ public void waitNumberOfReservedContainersFromApp(FiCaSchedulerApp app, waitNum++; } - Assert.fail(); + Assertions.fail(); } public void waitNumberOfLiveContainersOnNodeFromApp(FiCaSchedulerNode node, @@ -144,7 +144,7 @@ public void waitNumberOfLiveContainersOnNodeFromApp(FiCaSchedulerNode node, waitNum++; } - Assert.fail( + Assertions.fail( "Check #live-container-on-node-from-app, actual=" + total + " expected=" + expected); } @@ -160,6 +160,6 @@ public void checkNumberOfPreemptionCandidateFromApp( } } - Assert.assertEquals(expected, total); + Assertions.assertEquals(expected, total); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueCalculationTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueCalculationTestBase.java index 0f539f8b74e63..f2e8d6e361f86 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueCalculationTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueCalculationTestBase.java @@ -26,7 +26,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import java.io.IOException; @@ -52,7 +52,7 @@ public class CapacitySchedulerQueueCalculationTestBase { protected CapacitySchedulerConfiguration csConf; protected NullRMNodeLabelsManager mgr; - @Before + @BeforeEach public void setUp() throws Exception { csConf = new CapacitySchedulerConfiguration(); csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.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/scheduler/capacity/CapacitySchedulerQueueHelpers.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueHelpers.java index 757c86de305d1..57310bf0dd3d2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueHelpers.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueHelpers.java @@ -21,9 +21,9 @@ import java.util.List; import java.util.Map; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public final class CapacitySchedulerQueueHelpers { @@ -386,18 +386,18 @@ public static void checkQueueStructureCapacities(CapacityScheduler cs, CSQueue rootQueue = cs.getRootQueue(); for (Map.Entry entry : capacities.entrySet()) { CSQueue queue = findQueue(rootQueue, entry.getKey()); - Assert.assertNotNull(queue); + Assertions.assertNotNull(queue); assertQueueCapacities(queue, entry.getValue()); } } public static void assertQueueCapacities(CSQueue q, ExpectedCapacities capacities) { final float epsilon = 1e-4f; - assertEquals("capacity", capacities.getCapacity(), q.getCapacity(), epsilon); - assertEquals("absolute capacity", capacities.getAbsCapacity(), - q.getAbsoluteCapacity(), epsilon); - assertEquals("maximum capacity", 1.0f, q.getMaximumCapacity(), epsilon); - assertEquals("absolute maximum capacity", 1.0f, q.getAbsoluteMaximumCapacity(), epsilon); + assertEquals(capacities.getCapacity(), q.getCapacity(), epsilon, "capacity"); + assertEquals(capacities.getAbsCapacity(), + q.getAbsoluteCapacity(), epsilon, "absolute capacity"); + assertEquals(1.0f, q.getMaximumCapacity(), epsilon, "maximum capacity"); + assertEquals(1.0f, q.getAbsoluteMaximumCapacity(), epsilon, "absolute maximum capacity"); } public static CSQueue findQueue(CSQueue root, String queuePath) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerTestUtilities.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerTestUtilities.java index e7781b7108af8..a0dc43102d71f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerTestUtilities.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerTestUtilities.java @@ -52,7 +52,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.AppPriorityACLsManager; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import java.io.IOException; import java.util.Set; @@ -84,7 +84,7 @@ public static void checkPendingResource(MockRM rm, String queueName, int memory, String label) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queueName); - Assert.assertEquals( + Assertions.assertEquals( memory, queue.getQueueResourceUsage() .getPending(label == null ? RMNodeLabelsManager.NO_LABEL : label) @@ -96,7 +96,7 @@ public static void checkPendingResourceGreaterThanZero(MockRM rm, String queueNa String label) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queueName); - Assert.assertTrue(queue.getQueueResourceUsage() + Assertions.assertTrue(queue.getQueueResourceUsage() .getPending(label == null ? RMNodeLabelsManager.NO_LABEL : label) .getMemorySize() > 0); } @@ -230,11 +230,11 @@ public static NodeManager registerNode(ResourceManager rm, String hostName, } public static void checkApplicationResourceUsage(int expected, Application application) { - Assert.assertEquals(expected, application.getUsedResources().getMemorySize()); + Assertions.assertEquals(expected, application.getUsedResources().getMemorySize()); } public static void checkNodeResourceUsage(int expected, NodeManager node) { - Assert.assertEquals(expected, node.getUsed().getMemorySize()); + Assertions.assertEquals(expected, node.getUsed().getMemorySize()); node.checkResourceUsage(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAssertionBuilder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAssertionBuilder.java index 329d8b1bedbd2..170285bff2027 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAssertionBuilder.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAssertionBuilder.java @@ -20,7 +20,7 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueResourceQuotas; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -141,7 +141,7 @@ public void withResourceSupplier( BiFunction assertion, String messageInfo) { CSQueue queue = cs.getQueue(queuePath.getFullPath()); if (queue == null) { - Assert.fail("Queue " + queuePath + " is not found"); + Assertions.fail("Queue " + queuePath + " is not found"); } assertionType = messageInfo; @@ -152,7 +152,7 @@ public void withCapacitySupplier( BiFunction assertion, String messageInfo) { CSQueue queue = cs.getQueue(queuePath.getFullPath()); if (queue == null) { - Assert.fail("Queue " + queuePath + " is not found"); + Assertions.fail("Queue " + queuePath + " is not found"); } assertionType = messageInfo; valueSupplier = () -> assertion.apply(queue.getQueueCapacities(), label); @@ -187,14 +187,14 @@ public void finishAssertion() { String errorMessage = String.format(RESOURCE_ASSERTION_ERROR_MESSAGE, assertion.assertionType, assertionEntry.getKey(), assertion.expectedResource.toString(), assertion.label); - Assert.assertEquals(errorMessage, assertion.expectedResource, - assertion.resourceSupplier.get()); + Assertions.assertEquals(assertion.expectedResource, + assertion.resourceSupplier.get(), errorMessage); } else { String errorMessage = String.format(ASSERTION_ERROR_MESSAGE, assertion.assertionType, assertionEntry.getKey(), assertion.expectedValue, assertion.label); - Assert.assertEquals(errorMessage, assertion.expectedValue, - assertion.valueSupplier.get(), EPSILON); + Assertions.assertEquals(assertion.expectedValue, + assertion.valueSupplier.get(), EPSILON, errorMessage); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAMAllocatedToNonExclusivePartition.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAMAllocatedToNonExclusivePartition.java index 9b498011439e1..650afb66ef01f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAMAllocatedToNonExclusivePartition.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAMAllocatedToNonExclusivePartition.java @@ -42,9 +42,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; -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.ImmutableMap; @@ -52,7 +52,7 @@ public class TestAMAllocatedToNonExclusivePartition { private Configuration conf; private RMNodeLabelsManager mgr; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -120,7 +120,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // Request a container and it also should be allocated to non-partition node of h1 am1.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); + Assertions.assertTrue(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); rm1.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/scheduler/capacity/TestAbsoluteResourceConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceConfiguration.java index 2443f723653cc..87b51d0c8acc7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceConfiguration.java @@ -32,8 +32,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeRemovedSchedulerEvent; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TestAbsoluteResourceConfiguration { @@ -225,24 +225,24 @@ public void testSimpleMinMaxResourceConfigurartionPerQueue() CapacitySchedulerConfiguration csConf = setupSimpleQueueConfiguration(false); setupMinMaxResourceConfiguration(csConf); - Assert.assertEquals("Min resource configured for QUEUEA is not correct", - QUEUE_A_MINRES, - csConf.getMinimumResourceRequirement("", QUEUEA_FULL, resourceTypes)); - Assert.assertEquals("Max resource configured for QUEUEA is not correct", - QUEUE_A_MAXRES, - csConf.getMaximumResourceRequirement("", QUEUEA_FULL, resourceTypes)); - Assert.assertEquals("Min resource configured for QUEUEB is not correct", - QUEUE_B_MINRES, - csConf.getMinimumResourceRequirement("", QUEUEB_FULL, resourceTypes)); - Assert.assertEquals("Max resource configured for QUEUEB is not correct", - QUEUE_B_MAXRES, - csConf.getMaximumResourceRequirement("", QUEUEB_FULL, resourceTypes)); - Assert.assertEquals("Min resource configured for QUEUEC is not correct", - QUEUE_C_MINRES, - csConf.getMinimumResourceRequirement("", QUEUEC_FULL, resourceTypes)); - Assert.assertEquals("Max resource configured for QUEUEC is not correct", - QUEUE_C_MAXRES, - csConf.getMaximumResourceRequirement("", QUEUEC_FULL, resourceTypes)); + Assertions.assertEquals( + QUEUE_A_MINRES +, csConf.getMinimumResourceRequirement("", QUEUEA_FULL, resourceTypes), "Min resource configured for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES +, csConf.getMaximumResourceRequirement("", QUEUEA_FULL, resourceTypes), "Max resource configured for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_B_MINRES +, csConf.getMinimumResourceRequirement("", QUEUEB_FULL, resourceTypes), "Min resource configured for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES +, csConf.getMaximumResourceRequirement("", QUEUEB_FULL, resourceTypes), "Max resource configured for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_C_MINRES +, csConf.getMinimumResourceRequirement("", QUEUEC_FULL, resourceTypes), "Min resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES +, csConf.getMaximumResourceRequirement("", QUEUEC_FULL, resourceTypes), "Max resource configured for QUEUEC is not correct"); csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class); @@ -268,13 +268,13 @@ public void testSimpleMinMaxResourceConfigurartionPerQueue() cs.getRootQueue().updateClusterResource(cs.getClusterResource(), new ResourceLimits(cs.getClusterResource())); - Assert.assertEquals(QUEUE_D_TEMPL_MINRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MINRES, d1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MINRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MINRES, d1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MAXRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, d1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MAXRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, d1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); /** @@ -289,22 +289,22 @@ public void testSimpleMinMaxResourceConfigurartionPerQueue() cs.getRootQueue().updateClusterResource(cs.getClusterResource(), new ResourceLimits(cs.getClusterResource())); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), d2.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), d2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MAXRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, d2.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MAXRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, d2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MINRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MINRES, d1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MINRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MINRES, d1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MAXRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, d1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals(QUEUE_D_TEMPL_MAXRES, + Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, d1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); rm.close(); @@ -336,9 +336,9 @@ public void testNormalizationAfterNodeRemoval() throws Exception { Resource resParent = cs.getQueue(QUEUEA_FULL.getFullPath()).getEffectiveCapacity(""); // Check if there is no overcommitment on behalf of the child queues - Assert.assertTrue(String.format("Summarized resource %s of all children is greater than " + - "their parent's %s", res, resParent), - Resources.lessThan(cs.getResourceCalculator(), cs.getClusterResource(), res, resParent)); + Assertions.assertTrue( + Resources.lessThan(cs.getResourceCalculator(), cs.getClusterResource(), res, resParent), String.format("Summarized resource %s of all children is greater than " + + "their parent's %s", res, resParent)); rm.stop(); } @@ -364,37 +364,37 @@ public void testEffectiveMinMaxResourceConfigurartionPerQueue() CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue qA = (LeafQueue) cs.getQueue(QUEUEA); - Assert.assertNotNull(qA); - Assert.assertEquals("Min resource configured for QUEUEA is not correct", - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEA is not correct", - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEA is not correct", - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA is not correct", - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertNotNull(qA); + Assertions.assertEquals( + QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); LeafQueue qB = (LeafQueue) cs.getQueue(QUEUEB); - Assert.assertNotNull(qB); - Assert.assertEquals("Min resource configured for QUEUEB is not correct", - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEB is not correct", - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEB is not correct", - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEB is not correct", - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertNotNull(qB); + Assertions.assertEquals( + QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); LeafQueue qC = (LeafQueue) cs.getQueue(QUEUEC); - Assert.assertNotNull(qC); - Assert.assertEquals("Min resource configured for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertNotNull(qC); + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); rm.stop(); } @@ -440,7 +440,7 @@ public void testSimpleValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf1, rm.getRMContext()); } catch (IOException e) { - Assert.fail(); + Assertions.fail(); } rm.stop(); @@ -456,38 +456,38 @@ public void testSimpleValidateAbsoluteResourceConfig() throws Exception { cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue qA1 = (LeafQueue) cs.getQueue(QUEUEA1); - Assert.assertEquals("Effective Min resource for QUEUEA1 is not correct", - QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA1 is not correct", - QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertEquals( + QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA1 is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA1 is not correct"); LeafQueue qA2 = (LeafQueue) cs.getQueue(QUEUEA2); - Assert.assertEquals("Effective Min resource for QUEUEA2 is not correct", - QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA2 is not correct", - QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertEquals( + QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA2 is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA2 is not correct"); LeafQueue qB1 = (LeafQueue) cs.getQueue(QUEUEB1); - Assert.assertNotNull(qB1); - Assert.assertEquals("Min resource configured for QUEUEB1 is not correct", - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEB1 is not correct", - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEB1 is not correct", - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEB1 is not correct", - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertNotNull(qB1); + Assertions.assertEquals( + QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB1 is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB1 is not correct"); + Assertions.assertEquals( + QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB1 is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB1 is not correct"); LeafQueue qC = (LeafQueue) cs.getQueue(QUEUEC); - Assert.assertNotNull(qC); - Assert.assertEquals("Min resource configured for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertNotNull(qC); + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); // 3. Create a new config and make sure one queue's min resource is more // than its max resource configured. @@ -500,10 +500,10 @@ public void testSimpleValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf3, rm.getRMContext()); - Assert.fail(); + Assertions.fail(); } catch (IOException e) { - Assert.assertTrue(e instanceof IOException); - Assert.assertEquals( + Assertions.assertTrue(e instanceof IOException); + Assertions.assertEquals( "Failed to re-init queues : Min resource configuration " + " is greater than its " + "max value: " @@ -521,10 +521,10 @@ public void testSimpleValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf4, rm.getRMContext()); - Assert.fail(); + Assertions.fail(); } catch (IOException e) { - Assert.assertTrue(e instanceof IOException); - Assert + Assertions.assertTrue(e instanceof IOException); + Assertions .assertEquals( "Failed to re-init queues : Max resource configuration " + " is greater than parents max value:" @@ -575,13 +575,13 @@ public void testComplexValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf, rm.getRMContext()); if (csConf.isLegacyQueueMode()) { - Assert.fail("legacy queue mode does not support mixed queue modes"); + Assertions.fail("legacy queue mode does not support mixed queue modes"); } } catch (IOException e) { if (!csConf.isLegacyQueueMode()) { - Assert.fail("new queue mode supports mixed queue modes"); + Assertions.fail("new queue mode supports mixed queue modes"); } - Assert.assertTrue(e.getMessage().contains("Failed to re-init queues")); + Assertions.assertTrue(e.getMessage().contains("Failed to re-init queues")); } // 2. Create a new config and make sure one queue's min resource is more @@ -596,13 +596,13 @@ public void testComplexValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf1, rm.getRMContext()); if (csConf.isLegacyQueueMode()) { - Assert.fail("legacy queue mode enforces that parent.capacity >= sum(children.capacity)"); + Assertions.fail("legacy queue mode enforces that parent.capacity >= sum(children.capacity)"); } } catch (IOException e) { if (!csConf.isLegacyQueueMode()) { - Assert.fail("new queue mode allows that parent.capacity >= sum(children.capacity)"); + Assertions.fail("new queue mode allows that parent.capacity >= sum(children.capacity)"); } - Assert.assertEquals("Failed to re-init queues : Parent Queues capacity: " + Assertions.assertEquals("Failed to re-init queues : Parent Queues capacity: " + " is less than to its children:" + " for queue:queueA", e.getMessage()); } @@ -656,7 +656,7 @@ public void testValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf, rm.getRMContext()); } catch (IOException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } rm.stop(); } @@ -692,9 +692,9 @@ public void testDownscalingForLabels() throws Exception { Resource childrenResource = root.getChildQueues().stream().map(q -> q.getEffectiveCapacity( X_LABEL)).reduce(Resources::add).orElse(Resource.newInstance(0, 0)); - Assert.assertTrue("Children of root have more resource than overall cluster resource", - Resources.greaterThan(cs.getResourceCalculator(), cs.getClusterResource(), - root.getEffectiveCapacity(X_LABEL), childrenResource)); + Assertions.assertTrue( + Resources.greaterThan(cs.getResourceCalculator(), cs.getClusterResource(), + root.getEffectiveCapacity(X_LABEL), childrenResource), "Children of root have more resource than overall cluster resource"); rm.stop(); } @@ -721,37 +721,37 @@ public void testEffectiveResourceAfterReducingClusterResource() CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue qA = (LeafQueue) cs.getQueue(QUEUEA); - Assert.assertNotNull(qA); - Assert.assertEquals("Min resource configured for QUEUEA is not correct", - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEA is not correct", - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEA is not correct", - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA is not correct", - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertNotNull(qA); + Assertions.assertEquals( + QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); LeafQueue qB = (LeafQueue) cs.getQueue(QUEUEB); - Assert.assertNotNull(qB); - Assert.assertEquals("Min resource configured for QUEUEB is not correct", - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEB is not correct", - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEB is not correct", - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEB is not correct", - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertNotNull(qB); + Assertions.assertEquals( + QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); LeafQueue qC = (LeafQueue) cs.getQueue(QUEUEC); - Assert.assertNotNull(qC); - Assert.assertEquals("Min resource configured for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertNotNull(qC); + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); // unregister one NM. rm.unRegisterNode(nm1); @@ -759,20 +759,20 @@ public void testEffectiveResourceAfterReducingClusterResource() // After loosing one NM, effective min res of queueA will become just // above half. Hence A's min will be 60Gi and 6 cores and max will be // 128GB and 20 cores. - Assert.assertEquals("Effective Min resource for QUEUEA is not correct", - QUEUEA_REDUCED, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA is not correct", - QUEUEMAX_REDUCED, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertEquals( + QUEUEA_REDUCED, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUEMAX_REDUCED, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); - Assert.assertEquals("Effective Min resource for QUEUEB is not correct", - QUEUEB_REDUCED, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEB is not correct", - QUEUEMAX_REDUCED, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertEquals( + QUEUEB_REDUCED, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUEMAX_REDUCED, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); - Assert.assertEquals("Effective Min resource for QUEUEC is not correct", - QUEUEC_REDUCED, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEC is not correct", - QUEUEMAX_REDUCED, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); + Assertions.assertEquals( + QUEUEC_REDUCED, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUEMAX_REDUCED, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); rm.stop(); } @@ -800,83 +800,83 @@ public void testEffectiveResourceAfterIncreasingClusterResource() CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); ParentQueue qA = (ParentQueue) cs.getQueue(QUEUEA); - Assert.assertNotNull(qA); - Assert.assertEquals("Min resource configured for QUEUEA is not correct", - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEA is not correct", - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEA is not correct", - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA is not correct", - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEA is not correct", - 0.4, qA.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEA is not correct", - 0.8, qA.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(qA); + Assertions.assertEquals( + QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); + Assertions.assertEquals( + 0.4, qA.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA is not correct"); + Assertions.assertEquals( + 0.8, qA.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA is not correct"); ParentQueue qB = (ParentQueue) cs.getQueue(QUEUEB); - Assert.assertNotNull(qB); - Assert.assertEquals("Min resource configured for QUEUEB is not correct", - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEB is not correct", - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEB is not correct", - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEB is not correct", - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEB is not correct", - 0.2, qB.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEB is not correct", - 0.6, qB.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(qB); + Assertions.assertEquals( + QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); + Assertions.assertEquals( + 0.2, qB.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB is not correct"); + Assertions.assertEquals( + 0.6, qB.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEB is not correct"); LeafQueue qC = (LeafQueue) cs.getQueue(QUEUEC); - Assert.assertNotNull(qC); - Assert.assertEquals("Min resource configured for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEC is not correct", - 0.1, qC.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEC is not correct", - 0.6, qC.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(qC); + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); + Assertions.assertEquals( + 0.1, qC.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEC is not correct"); + Assertions.assertEquals( + 0.6, qC.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEC is not correct"); LeafQueue qA1 = (LeafQueue) cs.getQueue(QUEUEA1); - Assert.assertEquals("Effective Min resource for QUEUEA1 is not correct", - QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA1 is not correct", - QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEA1 is not correct", - 0.2, qA1.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEA1 is not correct", - 0.8, qA1.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals( + QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA1 is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA1 is not correct"); + Assertions.assertEquals( + 0.2, qA1.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA1 is not correct"); + Assertions.assertEquals( + 0.8, qA1.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA1 is not correct"); LeafQueue qA2 = (LeafQueue) cs.getQueue(QUEUEA2); - Assert.assertEquals("Effective Min resource for QUEUEA2 is not correct", - QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA2 is not correct", - QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEA2 is not correct", - 0.2, qA2.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEA2 is not correct", - 0.8, qA2.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals( + QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA2 is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA2 is not correct"); + Assertions.assertEquals( + 0.2, qA2.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA2 is not correct"); + Assertions.assertEquals( + 0.8, qA2.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA2 is not correct"); LeafQueue qB1 = (LeafQueue) cs.getQueue(QUEUEB1); - Assert.assertEquals("Min resource configured for QUEUEB1 is not correct", - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals("Max resource configured for QUEUEB1 is not correct", - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assert.assertEquals("Effective Min resource for QUEUEB1 is not correct", - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEB1 is not correct", - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEB1 is not correct", - 0.16, qB1.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEB1 is not correct", - 0.6, qB1.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals( + QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB1 is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB1 is not correct"); + Assertions.assertEquals( + QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB1 is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB1 is not correct"); + Assertions.assertEquals( + 0.16, qB1.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB1 is not correct"); + Assertions.assertEquals( + 0.6, qB1.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEB1 is not correct"); // add new NM. rm.registerNode("127.0.0.3:1234", 125 * GB, 20); @@ -884,59 +884,59 @@ public void testEffectiveResourceAfterIncreasingClusterResource() // There will be no change in effective resource when nodes are added. // Since configured capacity was based on initial node capacity, a // re configurations is needed to use this added capacity. - Assert.assertEquals("Effective Min resource for QUEUEA is not correct", - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA is not correct", - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEA is not correct", - 0.266, qA.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEA is not correct", - 0.533, qA.getAbsoluteMaximumCapacity(), DELTA); - - Assert.assertEquals("Effective Min resource for QUEUEB is not correct", - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEB is not correct", - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEB is not correct", - 0.133, qB.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEB is not correct", - 0.4, qB.getAbsoluteMaximumCapacity(), DELTA); - - Assert.assertEquals("Effective Min resource for QUEUEC is not correct", - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEC is not correct", - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEC is not correct", - 0.066, qC.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEC is not correct", - 0.4, qC.getAbsoluteMaximumCapacity(), DELTA); - - Assert.assertEquals("Effective Min resource for QUEUEB1 is not correct", - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEB1 is not correct", - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEB1 is not correct", - 0.106, qB1.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEB1 is not correct", - 0.4, qB1.getAbsoluteMaximumCapacity(), DELTA); - - Assert.assertEquals("Effective Min resource for QUEUEA1 is not correct", - QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA1 is not correct", - QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEA1 is not correct", - 0.133, qA1.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEA1 is not correct", - 0.533, qA1.getAbsoluteMaximumCapacity(), DELTA); - - Assert.assertEquals("Effective Min resource for QUEUEA2 is not correct", - QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for QUEUEA2 is not correct", - QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assert.assertEquals("Absolute capacity for QUEUEA2 is not correct", - 0.133, qA2.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Absolute Max capacity for QUEUEA2 is not correct", - 0.533, qA2.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals( + QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); + Assertions.assertEquals( + 0.266, qA.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA is not correct"); + Assertions.assertEquals( + 0.533, qA.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA is not correct"); + + Assertions.assertEquals( + QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); + Assertions.assertEquals( + 0.133, qB.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB is not correct"); + Assertions.assertEquals( + 0.4, qB.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEB is not correct"); + + Assertions.assertEquals( + QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); + Assertions.assertEquals( + QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); + Assertions.assertEquals( + 0.066, qC.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEC is not correct"); + Assertions.assertEquals( + 0.4, qC.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEC is not correct"); + + Assertions.assertEquals( + QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB1 is not correct"); + Assertions.assertEquals( + QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB1 is not correct"); + Assertions.assertEquals( + 0.106, qB1.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB1 is not correct"); + Assertions.assertEquals( + 0.4, qB1.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEB1 is not correct"); + + Assertions.assertEquals( + QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA1 is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA1 is not correct"); + Assertions.assertEquals( + 0.133, qA1.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA1 is not correct"); + Assertions.assertEquals( + 0.533, qA1.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA1 is not correct"); + + Assertions.assertEquals( + QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA2 is not correct"); + Assertions.assertEquals( + QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA2 is not correct"); + Assertions.assertEquals( + 0.133, qA2.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA2 is not correct"); + Assertions.assertEquals( + 0.533, qA2.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA2 is not correct"); 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/scheduler/capacity/TestAbsoluteResourceWithAutoQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceWithAutoQueue.java index 66ab96308f982..6932a6b641772 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceWithAutoQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceWithAutoQueue.java @@ -20,10 +20,7 @@ import static org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager.NO_LABEL; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueueUtils.EPSILON; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; import java.util.HashMap; import java.util.HashSet; @@ -45,9 +42,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.queuemanagement.GuaranteedOrZeroCapacityOverTimePolicy; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.policy.FifoOrderingPolicy; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; -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 org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -95,13 +93,13 @@ public class TestAbsoluteResourceWithAutoQueue private static final Resource QUEUE_D_MAXRES = Resource.newInstance(150 * GB, 20); - @Before + @BeforeEach public void setUp() throws Exception { accessibleNodeLabelsOnC.add(NO_LABEL); } - @After + @AfterEach public void tearDown() { if (mockRM != null) { mockRM.stop(); @@ -163,7 +161,8 @@ private CapacitySchedulerConfiguration setupSimpleQueueConfiguration( return csConf; } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testAutoCreateLeafQueueCreation() throws Exception { try { @@ -287,20 +286,24 @@ public void testAutoCreateLeafQueueCreation() throws Exception { } } - @Test(expected = Exception.class) + @Test public void testValidateLeafQueueTemplateConfigurations() { - CapacitySchedulerConfiguration csConf = setupSimpleQueueConfiguration(true); + assertThrows(Exception.class, ()->{ + CapacitySchedulerConfiguration csConf = setupSimpleQueueConfiguration(true); - csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, - ResourceScheduler.class); + csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, + ResourceScheduler.class); + + mockRM = new MockRM(csConf); + fail("Exception should be thrown as leaf queue template configuration is " + + "not same as Parent configuration"); + }); - mockRM = new MockRM(csConf); - fail("Exception should be thrown as leaf queue template configuration is " - + "not same as Parent configuration"); } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testApplicationRunningWithDRF() throws Exception { CapacitySchedulerConfiguration csConf = setupSimpleQueueConfiguration(false); @@ -329,7 +332,7 @@ public void testApplicationRunningWithDRF() throws Exception { cs = (CapacityScheduler) mockRM.getResourceScheduler(); AutoCreatedLeafQueue autoCreatedLeafQueue = (AutoCreatedLeafQueue) cs.getQueue(TEST_GROUPUSER); - assertNotNull("Auto Creation of Queue failed", autoCreatedLeafQueue); + assertNotNull(autoCreatedLeafQueue, "Auto Creation of Queue failed"); ManagedParentQueue parentQueue = (ManagedParentQueue) cs.getQueue(QUEUED); assertEquals(parentQueue, autoCreatedLeafQueue.getParent()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java index ed5ff571e028a..0d9649de8e2a2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java @@ -19,9 +19,9 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.setQueueHandler; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -75,8 +75,9 @@ import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.apache.hadoop.yarn.util.resource.Resources; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -100,7 +101,7 @@ public class TestApplicationLimits { private CapacitySchedulerContext csContext; - @Before + @BeforeEach public void setUp() throws IOException { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); @@ -781,7 +782,8 @@ private Set toSet(String... elements) { return set; } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testApplicationLimitSubmit() throws Exception { YarnConfiguration conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -985,14 +987,14 @@ public void testAMResourceLimitWithDRCAndFullParent() throws Exception { Resource expectedAmLimit = Resources.multiply(capacity, queueA.getMaxAMResourcePerQueuePercent()); Resource amLimit = queueA.calculateAndGetAMResourceLimit(); - assertTrue("AM memory limit is less than expected: Expected: " + + assertTrue( + amLimit.getMemorySize() >= expectedAmLimit.getMemorySize(), "AM memory limit is less than expected: Expected: " + expectedAmLimit.getMemorySize() + "; Computed: " - + amLimit.getMemorySize(), - amLimit.getMemorySize() >= expectedAmLimit.getMemorySize()); - assertTrue("AM vCore limit is less than expected: Expected: " + + + amLimit.getMemorySize()); + assertTrue( + amLimit.getVirtualCores() >= expectedAmLimit.getVirtualCores(), "AM vCore limit is less than expected: Expected: " + expectedAmLimit.getVirtualCores() + "; Computed: " - + amLimit.getVirtualCores(), - amLimit.getVirtualCores() >= expectedAmLimit.getVirtualCores()); + + amLimit.getVirtualCores()); } private CapacitySchedulerContext createCSContext(CapacitySchedulerConfiguration csConf, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java index 6e8c0b02f9473..0adc93cd9edec 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -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.spy; @@ -66,9 +66,10 @@ 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.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.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -94,7 +95,7 @@ public class TestApplicationLimitsByPartition { private final ResourceCalculator resourceCalculator = new DefaultResourceCalculator(); - @Before + @BeforeEach public void setUp() throws IOException { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -123,7 +124,8 @@ private void complexNodeLabelMappingToManager() throws IOException { RMNodeLabelsManager.EMPTY_STRING_SET)); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testAMResourceLimitWithLabels() throws Exception { /* * Test Case: @@ -198,22 +200,22 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assert.assertNotNull(leafQueue); + Assertions.assertNotNull(leafQueue); // Only one AM will be activated here and second AM will be still // pending. - Assert.assertEquals(2, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumPendingApplications()); - Assert.assertTrue("AM diagnostics not set properly", app1.getDiagnostics() - .toString().contains(AMState.ACTIVATED.getDiagnosticMessage())); - Assert.assertTrue("AM diagnostics not set properly", app2.getDiagnostics() - .toString().contains(AMState.ACTIVATED.getDiagnosticMessage())); - Assert.assertTrue("AM diagnostics not set properly", - pendingApp.getDiagnostics().toString() - .contains(AMState.INACTIVATED.getDiagnosticMessage())); - Assert.assertTrue("AM diagnostics not set properly", - pendingApp.getDiagnostics().toString().contains( - CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED)); + Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); + Assertions.assertTrue(app1.getDiagnostics() + .toString().contains(AMState.ACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); + Assertions.assertTrue(app2.getDiagnostics() + .toString().contains(AMState.ACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); + Assertions.assertTrue( + pendingApp.getDiagnostics().toString() + .contains(AMState.INACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); + Assertions.assertTrue( + pendingApp.getDiagnostics().toString().contains( + CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), "AM diagnostics not set properly"); // Now verify the same test case in Queue C1 where label is not configured. // Submit an app to Queue C1 with empty label @@ -253,29 +255,30 @@ public RMNodeLabelsManager createNodeLabelManager() { pendingApp = MockRMAppSubmitter.submit(rm1, data); leafQueue = (LeafQueue) cs.getQueue("c1"); - Assert.assertNotNull(leafQueue); + Assertions.assertNotNull(leafQueue); // 2 apps will be activated, third one will be pending as am-limit // is reached. - Assert.assertEquals(2, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumPendingApplications()); - Assert.assertTrue("AM diagnostics not set properly", - pendingApp.getDiagnostics().toString() - .contains(AMState.INACTIVATED.getDiagnosticMessage())); - Assert.assertTrue("AM diagnostics not set properly", - pendingApp.getDiagnostics().toString().contains( - CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED)); + Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); + Assertions.assertTrue( + pendingApp.getDiagnostics().toString() + .contains(AMState.INACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); + Assertions.assertTrue( + pendingApp.getDiagnostics().toString().contains( + CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), "AM diagnostics not set properly"); rm1.killApp(app3.getApplicationId()); Thread.sleep(1000); // After killing one running app, pending app will also get activated. - Assert.assertEquals(2, leafQueue.getNumActiveApplications()); - Assert.assertEquals(0, leafQueue.getNumPendingApplications()); + Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(0, leafQueue.getNumPendingApplications()); rm1.close(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testAtleastOneAMRunPerPartition() throws Exception { /* * Test Case: @@ -343,11 +346,11 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assert.assertNotNull(leafQueue); + Assertions.assertNotNull(leafQueue); // Only 1 app will be activated as am-limit for partition "x" is 0.15 - Assert.assertEquals(1, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumPendingApplications()); + Assertions.assertEquals(1, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); // Now verify the same test case in Queue C1 which takes default label // to see queue level am-resource-limit is still working as expected. @@ -379,15 +382,16 @@ public RMNodeLabelsManager createNodeLabelManager() { MockRMAppSubmitter.submit(rm1, data); leafQueue = (LeafQueue) cs.getQueue("c1"); - Assert.assertNotNull(leafQueue); + Assertions.assertNotNull(leafQueue); // 1 app will be activated (and it has AM resource more than queue limit) - Assert.assertEquals(1, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumPendingApplications()); + Assertions.assertEquals(1, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); rm1.close(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testDefaultAMLimitFromQueueForPartition() throws Exception { /* * Test Case: @@ -446,24 +450,25 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assert.assertNotNull(leafQueue); + Assertions.assertNotNull(leafQueue); // Only 1 app will be activated as am-limit for queue is 0.2 and same is // used for partition "x" also. - Assert.assertEquals(1, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumPendingApplications()); - Assert.assertTrue("AM diagnostics not set properly", app1.getDiagnostics() - .toString().contains(AMState.ACTIVATED.getDiagnosticMessage())); - Assert.assertTrue("AM diagnostics not set properly", - pendingApp.getDiagnostics().toString() - .contains(AMState.INACTIVATED.getDiagnosticMessage())); - Assert.assertTrue("AM diagnostics not set properly", - pendingApp.getDiagnostics().toString() - .contains(CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED)); + Assertions.assertEquals(1, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); + Assertions.assertTrue(app1.getDiagnostics() + .toString().contains(AMState.ACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); + Assertions.assertTrue( + pendingApp.getDiagnostics().toString() + .contains(AMState.INACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); + Assertions.assertTrue( + pendingApp.getDiagnostics().toString() + .contains(CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), "AM diagnostics not set properly"); rm1.close(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testUserAMResourceLimitWithLabels() throws Exception { /* * Test Case: @@ -533,12 +538,12 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assert.assertNotNull(leafQueue); + Assertions.assertNotNull(leafQueue); // Verify active applications count in this queue. - Assert.assertEquals(2, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumActiveApplications(user_0)); - Assert.assertEquals(0, leafQueue.getNumPendingApplications()); + Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumActiveApplications(user_0)); + Assertions.assertEquals(0, leafQueue.getNumPendingApplications()); // Submit 3rd app to Queue A1 for label X for user1. Now user1 will have // 2 applications (2 GB resource) and user0 will have one app (1GB). @@ -573,19 +578,19 @@ public RMNodeLabelsManager createNodeLabelManager() { RMApp pendingApp = MockRMAppSubmitter.submit(rm1, data); // Verify active applications count per user and also in queue level. - Assert.assertEquals(3, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumActiveApplications(user_0)); - Assert.assertEquals(2, leafQueue.getNumActiveApplications(user_1)); - Assert.assertEquals(1, leafQueue.getNumPendingApplications(user_1)); - Assert.assertEquals(1, leafQueue.getNumPendingApplications()); + Assertions.assertEquals(3, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumActiveApplications(user_0)); + Assertions.assertEquals(2, leafQueue.getNumActiveApplications(user_1)); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications(user_1)); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); //verify Diagnostic messages - Assert.assertTrue("AM diagnostics not set properly", - pendingApp.getDiagnostics().toString() - .contains(AMState.INACTIVATED.getDiagnosticMessage())); - Assert.assertTrue("AM diagnostics not set properly", - pendingApp.getDiagnostics().toString().contains( - CSAMContainerLaunchDiagnosticsConstants.USER_AM_RESOURCE_LIMIT_EXCEED)); + Assertions.assertTrue( + pendingApp.getDiagnostics().toString() + .contains(AMState.INACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); + Assertions.assertTrue( + pendingApp.getDiagnostics().toString().contains( + CSAMContainerLaunchDiagnosticsConstants.USER_AM_RESOURCE_LIMIT_EXCEED), "AM diagnostics not set properly"); rm1.close(); } @@ -684,7 +689,7 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assert.assertNotNull(leafQueue); + Assertions.assertNotNull(leafQueue); /* * capacity of queue A -> 50% for label Y @@ -696,8 +701,8 @@ public RMNodeLabelsManager createNodeLabelManager() { * AM resource percent config for queue A1 -> 0.25 * ==> 2.5Gb (3 Gb) is max-am-resource-limit */ - Assert.assertEquals(2, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumPendingApplications()); + Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); // Submit app3 with 1Gb AM resource to Queue B1 (no_label) MockRMAppSubmissionData data1 = @@ -723,7 +728,7 @@ public RMNodeLabelsManager createNodeLabelManager() { MockRMAppSubmitter.submit(rm1, data); leafQueue = (LeafQueue) cs.getQueue("b1"); - Assert.assertNotNull(leafQueue); + Assertions.assertNotNull(leafQueue); /* * capacity of queue B -> 90% for queue @@ -738,8 +743,8 @@ public RMNodeLabelsManager createNodeLabelManager() { * * Only one app will be activated and all othe will be pending. */ - Assert.assertEquals(1, leafQueue.getNumActiveApplications()); - Assert.assertEquals(1, leafQueue.getNumPendingApplications()); + Assertions.assertEquals(1, leafQueue.getNumActiveApplications()); + Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); rm1.close(); } @@ -1008,19 +1013,19 @@ public void testAMLimitByAllResources() throws Exception { .withQueue(queueName) .build()); - Assert.assertEquals("PendingApplications should be 1", 1, - queueA.getNumPendingApplications()); - Assert.assertEquals("Active applications should be 2", 2, - queueA.getNumActiveApplications()); + Assertions.assertEquals(1 +, queueA.getNumPendingApplications(), "PendingApplications should be 1"); + Assertions.assertEquals(2 +, queueA.getNumActiveApplications(), "Active applications should be 2"); // AMLimit is 2048,7 - Assert.assertEquals(2048, + Assertions.assertEquals(2048, queueA.getQueueResourceUsage().getAMLimit().getMemorySize()); - Assert.assertEquals(7, + Assertions.assertEquals(7, queueA.getQueueResourceUsage().getAMLimit().getVirtualCores()); // Used AM Resource is 2048,2 - Assert.assertEquals(2048, + Assertions.assertEquals(2048, queueA.getQueueResourceUsage().getAMUsed().getMemorySize()); - Assert.assertEquals(2, + Assertions.assertEquals(2, queueA.getQueueResourceUsage().getAMUsed().getVirtualCores()); 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/scheduler/capacity/TestApplicationPriority.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java index f91526c457053..45c652bcd3ca5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java @@ -58,16 +58,17 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeAddedSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; 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 TestApplicationPriority { private final int GB = 1024; private YarnConfiguration conf; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -85,7 +86,7 @@ public void testApplicationOrderingWithPriority() throws Exception { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue q = (LeafQueue) cs.getQueue("default"); - Assert.assertNotNull(q); + Assertions.assertNotNull(q); String host = "127.0.0.1"; RMNode node = MockNodes.newNodeInfo(0, MockNodes.newResource(16 * GB), 1, @@ -176,14 +177,14 @@ public void testApplicationPriorityAllocation() throws Exception { List allocated1 = am1.allocateAndWaitForContainers("127.0.0.1", 7, 2 * GB, nm1); - Assert.assertEquals(7, allocated1.size()); - Assert.assertEquals(2 * GB, allocated1.get(0).getResource().getMemorySize()); + Assertions.assertEquals(7, allocated1.size()); + Assertions.assertEquals(2 * GB, allocated1.get(0).getResource().getMemorySize()); // check node report, 15 GB used (1 AM and 7 containers) and 1 GB available SchedulerNodeReport report_nm1 = rm.getResourceScheduler().getNodeReport( nm1.getNodeId()); - Assert.assertEquals(15 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(1 * GB, + Assertions.assertEquals(15 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(1 * GB, report_nm1.getAvailableResource().getMemorySize()); // Submit the second app App2 with priority 8 (Higher than App1) @@ -200,8 +201,8 @@ public void testApplicationPriorityAllocation() throws Exception { // check node report, 16 GB used and 0 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); // get scheduler @@ -223,8 +224,8 @@ public void testApplicationPriorityAllocation() throws Exception { // check node report, 12 GB used and 4 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(12 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(12 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(4 * GB, report_nm1.getAvailableResource().getMemorySize()); // send updated request for App1 @@ -236,12 +237,12 @@ public void testApplicationPriorityAllocation() throws Exception { 2, 2 * GB, nm1); // App2 has got 2 containers now. - Assert.assertEquals(2, allocated2.size()); + Assertions.assertEquals(2, allocated2.size()); // check node report, 16 GB used and 0 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); rm.stop(); @@ -274,14 +275,14 @@ public void testPriorityWithPendingApplications() throws Exception { List allocated1 = am1.allocateAndWaitForContainers("127.0.0.1", 7, 1 * GB, nm1); - Assert.assertEquals(7, allocated1.size()); - Assert.assertEquals(1 * GB, allocated1.get(0).getResource().getMemorySize()); + Assertions.assertEquals(7, allocated1.size()); + Assertions.assertEquals(1 * GB, allocated1.get(0).getResource().getMemorySize()); // check node report, 8 GB used (1 AM and 7 containers) and 0 GB available SchedulerNodeReport report_nm1 = rm.getResourceScheduler().getNodeReport( nm1.getNodeId()); - Assert.assertEquals(8 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(8 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); // Submit the second app App2 with priority 7 @@ -316,8 +317,8 @@ public void testPriorityWithPendingApplications() throws Exception { // check node report, 1 GB used and 7 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(1 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(7 * GB, + Assertions.assertEquals(1 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(7 * GB, report_nm1.getAvailableResource().getMemorySize()); rm.stop(); @@ -342,7 +343,7 @@ public void testMaxPriorityValidation() throws Exception { RMApp app1 = MockRMAppSubmitter.submit(rm, data); // Application submission should be successful and verify priority - Assert.assertEquals(app1.getApplicationSubmissionContext().getPriority(), + Assertions.assertEquals(app1.getApplicationSubmissionContext().getPriority(), maxPriority); rm.stop(); } @@ -383,7 +384,7 @@ public void testUpdatePriorityAtRuntime() throws Exception { .get(app1.getApplicationId()).getCurrentAppAttempt(); // Verify whether the new priority is updated - Assert.assertEquals(appPriority2, schedulerAppAttempt.getPriority()); + Assertions.assertEquals(appPriority2, schedulerAppAttempt.getPriority()); } @Test @@ -425,11 +426,12 @@ public void testUpdateInvalidPriorityAtRuntime() throws Exception { // Verify whether priority 15 is reset to 10 Priority appPriority3 = Priority.newInstance(10); - Assert.assertEquals(appPriority3, schedulerAppAttempt.getPriority()); + Assertions.assertEquals(appPriority3, schedulerAppAttempt.getPriority()); rm.stop(); } - @Test(timeout = 180000) + @Test + @Timeout(value = 180) public void testRMRestartWithChangeInPriority() throws Exception { conf.setBoolean(YarnConfiguration.RECOVERY_ENABLED, true); conf.setBoolean(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, @@ -481,14 +483,14 @@ public void testRMRestartWithChangeInPriority() throws Exception { nm1.setResourceTrackerService(rm2.getResourceTrackerService()); // Verify RM Apps after this restart - Assert.assertEquals(1, rm2.getRMContext().getRMApps().size()); + Assertions.assertEquals(1, rm2.getRMContext().getRMApps().size()); // get scheduler app RMApp loadedApp = rm2.getRMContext().getRMApps() .get(app1.getApplicationId()); // Verify whether priority 15 is reset to 10 - Assert.assertEquals(appPriority2, loadedApp.getApplicationPriority()); + Assertions.assertEquals(appPriority2, loadedApp.getApplicationPriority()); rm2.stop(); rm1.stop(); @@ -521,15 +523,15 @@ public void testApplicationPriorityAllocationWithChangeInPriority() List allocated1 = am1.allocateAndWaitForContainers("127.0.0.1", NUM_CONTAINERS, 2 * GB, nm1); - Assert.assertEquals(7, allocated1.size()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(7, allocated1.size()); + Assertions.assertEquals(2 * GB, allocated1.get(0).getResource().getMemorySize()); // check node report, 15 GB used (1 AM and 7 containers) and 1 GB available SchedulerNodeReport report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(15 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(1 * GB, + Assertions.assertEquals(15 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(1 * GB, report_nm1.getAvailableResource().getMemorySize()); // Submit the second app App2 with priority 8 (Higher than App1) @@ -546,8 +548,8 @@ public void testApplicationPriorityAllocationWithChangeInPriority() // check node report, 16 GB used and 0 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); // get scheduler @@ -571,8 +573,8 @@ public void testApplicationPriorityAllocationWithChangeInPriority() // check node report, 12 GB used and 4 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(12 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(12 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(4 * GB, report_nm1.getAvailableResource().getMemorySize()); // add request for containers App1 @@ -582,11 +584,11 @@ public void testApplicationPriorityAllocationWithChangeInPriority() List allocated2 = am2.allocateAndWaitForContainers("127.0.0.1", 2, 2 * GB, nm1); - Assert.assertEquals(2, allocated2.size()); + Assertions.assertEquals(2, allocated2.size()); // check node report, 16 GB used and 0 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); // kill 1 more @@ -604,8 +606,8 @@ public void testApplicationPriorityAllocationWithChangeInPriority() // check node report, 14 GB used and 2 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(14 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(14 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(2 * GB, report_nm1.getAvailableResource().getMemorySize()); // Change the priority of App1 to 3 (lowest) @@ -623,9 +625,9 @@ public void testApplicationPriorityAllocationWithChangeInPriority() List allocated3 = am1.allocateAndWaitForContainers("127.0.0.1", 1, 2 * GB, nm1); - Assert.assertEquals(1, allocated3.size()); + Assertions.assertEquals(1, allocated3.size()); // Now App1 will have 5 containers and 1 AM. App2 will have 2 containers. - Assert.assertEquals(6, schedulerAppAttemptApp1.getLiveContainers().size()); + Assertions.assertEquals(6, schedulerAppAttemptApp1.getLiveContainers().size()); rm.stop(); } @@ -689,8 +691,8 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() am2.registerAppAttempt(); rm1.drainEvents(); - Assert.assertEquals(2, defaultQueue.getNumActiveApplications()); - Assert.assertEquals(0, defaultQueue.getNumPendingApplications()); + Assertions.assertEquals(2, defaultQueue.getNumActiveApplications()); + Assertions.assertEquals(0, defaultQueue.getNumPendingApplications()); // App-3 with priority 7 submitted and scheduled. But not activated since // AMResourceLimit threshold @@ -702,22 +704,22 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() RMApp app3 = MockRMAppSubmitter.submit(rm1, data); rm1.drainEvents(); - Assert.assertEquals(2, defaultQueue.getNumActiveApplications()); - Assert.assertEquals(1, defaultQueue.getNumPendingApplications()); + Assertions.assertEquals(2, defaultQueue.getNumActiveApplications()); + Assertions.assertEquals(1, defaultQueue.getNumPendingApplications()); Iterator iterator = defaultQueue.getOrderingPolicy().getSchedulableEntities().iterator(); FiCaSchedulerApp fcApp2 = iterator.next(); - Assert.assertEquals(app2.getCurrentAppAttempt().getAppAttemptId(), + Assertions.assertEquals(app2.getCurrentAppAttempt().getAppAttemptId(), fcApp2.getApplicationAttemptId()); FiCaSchedulerApp fcApp1 = iterator.next(); - Assert.assertEquals(app1.getCurrentAppAttempt().getAppAttemptId(), + Assertions.assertEquals(app1.getCurrentAppAttempt().getAppAttemptId(), fcApp1.getApplicationAttemptId()); iterator = defaultQueue.getPendingApplications().iterator(); FiCaSchedulerApp fcApp3 = iterator.next(); - Assert.assertEquals(app3.getCurrentAppAttempt().getAppAttemptId(), + Assertions.assertEquals(app3.getCurrentAppAttempt().getAppAttemptId(), fcApp3.getApplicationAttemptId()); // create new RM to represent restart and recover state @@ -729,7 +731,7 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() nm1.setResourceTrackerService(rm2.getResourceTrackerService()); // Verify RM Apps after this restart - Assert.assertEquals(3, rm2.getRMContext().getRMApps().size()); + Assertions.assertEquals(3, rm2.getRMContext().getRMApps().size()); rm2.drainEvents(); scheduler = rm2.getRMContext().getScheduler(); @@ -747,8 +749,8 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() // Before NM registration, AMResourceLimit threshold is 0. So no // applications get activated. - Assert.assertEquals(0, defaultQueue.getNumActiveApplications()); - Assert.assertEquals(3, defaultQueue.getNumPendingApplications()); + Assertions.assertEquals(0, defaultQueue.getNumActiveApplications()); + Assertions.assertEquals(3, defaultQueue.getNumPendingApplications()); // NM resync to new RM nm1.registerNode(); @@ -763,31 +765,32 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() Thread.sleep(50); } - Assert.assertEquals(2, defaultQueue.getNumActiveApplications()); - Assert.assertEquals(1, defaultQueue.getNumPendingApplications()); + Assertions.assertEquals(2, defaultQueue.getNumActiveApplications()); + Assertions.assertEquals(1, defaultQueue.getNumPendingApplications()); // verify for order of activated applications iterator iterator = defaultQueue.getOrderingPolicy().getSchedulableEntities().iterator(); fcApp2 = iterator.next(); - Assert.assertEquals(app2.getCurrentAppAttempt().getAppAttemptId(), + Assertions.assertEquals(app2.getCurrentAppAttempt().getAppAttemptId(), fcApp2.getApplicationAttemptId()); fcApp1 = iterator.next(); - Assert.assertEquals(app1.getCurrentAppAttempt().getAppAttemptId(), + Assertions.assertEquals(app1.getCurrentAppAttempt().getAppAttemptId(), fcApp1.getApplicationAttemptId()); // verify for pending application iterator. It should be app-3 attempt iterator = defaultQueue.getPendingApplications().iterator(); fcApp3 = iterator.next(); - Assert.assertEquals(app3.getCurrentAppAttempt().getAppAttemptId(), + Assertions.assertEquals(app3.getCurrentAppAttempt().getAppAttemptId(), fcApp3.getApplicationAttemptId()); rm2.stop(); rm1.stop(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testUpdatePriorityOnPendingAppAndKillAttempt() throws Exception { int maxPriority = 10; int appPriority = 5; @@ -812,8 +815,8 @@ public void testUpdatePriorityOnPendingAppAndKillAttempt() throws Exception { ((LeafQueue) defaultQueue).getOrderingPolicy().getSchedulableEntities(); // Verify app is in pending state - Assert.assertEquals("Pending apps should be 1", 1, appsPending.size()); - Assert.assertEquals("Active apps should be 0", 0, activeApps.size()); + Assertions.assertEquals(1, appsPending.size(), "Pending apps should be 1"); + Assertions.assertEquals(0, activeApps.size(), "Active apps should be 0"); // kill app1 which is pending killAppAndVerifyOrderingPolicy(rm, defaultQueue, 0, 0, app1); @@ -826,8 +829,8 @@ public void testUpdatePriorityOnPendingAppAndKillAttempt() throws Exception { MockRMAppSubmissionData.Builder.createWithMemory(1024, rm) .withAppPriority(Priority.newInstance(appPriority)).build(); RMApp app2 = MockRMAppSubmitter.submit(rm, data2); - Assert.assertEquals("Pending apps should be 0", 0, appsPending.size()); - Assert.assertEquals("Active apps should be 1", 1, activeApps.size()); + Assertions.assertEquals(0, appsPending.size(), "Pending apps should be 0"); + Assertions.assertEquals(1, activeApps.size(), "Active apps should be 1"); MockRMAppSubmissionData data1 = MockRMAppSubmissionData.Builder.createWithMemory(1024, rm) .withAppPriority(Priority.newInstance(appPriority)).build(); @@ -836,8 +839,8 @@ public void testUpdatePriorityOnPendingAppAndKillAttempt() throws Exception { MockRMAppSubmissionData.Builder.createWithMemory(1024, rm) .withAppPriority(Priority.newInstance(appPriority)).build(); RMApp app4 = MockRMAppSubmitter.submit(rm, data); - Assert.assertEquals("Pending apps should be 2", 2, appsPending.size()); - Assert.assertEquals("Active apps should be 1", 1, activeApps.size()); + Assertions.assertEquals(2, appsPending.size(), "Pending apps should be 2"); + Assertions.assertEquals(1, activeApps.size(), "Active apps should be 1"); // kill app3, pending apps should reduce to 1 killAppAndVerifyOrderingPolicy(rm, defaultQueue, 1, 1, app3); // kill app2, running apps is killed and pending added to running @@ -865,10 +868,10 @@ private void killAppAndVerifyOrderingPolicy(MockRM rm, CSQueue defaultQueue, ((LeafQueue) defaultQueue).getPendingApplications(); Collection activeApps = ((LeafQueue) defaultQueue).getApplications(); - Assert.assertEquals("Pending apps should be " + appsPendingExpected, - appsPendingExpected, appsPending.size()); - Assert.assertEquals("Active apps should be " + activeAppsExpected, - activeAppsExpected, activeApps.size()); + Assertions.assertEquals( + appsPendingExpected, appsPending.size(), "Pending apps should be " + appsPendingExpected); + Assertions.assertEquals( + activeAppsExpected, activeApps.size(), "Active apps should be " + activeAppsExpected); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLConfiguration.java index e2011ff9cdb98..097a8a80656c0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLConfiguration.java @@ -20,8 +20,8 @@ import java.util.List; import org.apache.hadoop.yarn.api.records.Priority; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TestApplicationPriorityACLConfiguration { @@ -117,10 +117,10 @@ private void verifyACLs(List pGroup, String queueUser, AppPriorityACLGroup group = pGroup.get(0); String aclString = queueUser + " " + queueGroup; - Assert.assertEquals(aclString.trim(), + Assertions.assertEquals(aclString.trim(), group.getACLList().getAclString().trim()); - Assert.assertEquals(maxPriority, group.getMaxPriority().getPriority()); - Assert.assertEquals(defaultPriority, + Assertions.assertEquals(maxPriority, group.getMaxPriority().getPriority()); + Assertions.assertEquals(defaultPriority, group.getDefaultPriority().getPriority()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLs.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLs.java index 674bb5c8c1eba..581c73957e300 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLs.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLs.java @@ -37,8 +37,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.ACLsTestBase; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TestApplicationPriorityACLs extends ACLsTestBase { @@ -143,9 +143,9 @@ private void submitAppToRMWithInValidAcl(String submitter, .newInstance(appSubmissionContext); try { submitterClient.submitApplication(submitRequest); - Assert.fail(); + Assertions.fail(); } catch (YarnException ex) { - Assert.assertTrue(ex.getCause() instanceof RemoteException); + Assertions.assertTrue(ex.getCause() instanceof RemoteException); } } @@ -167,10 +167,10 @@ private void verifyAppPriorityIsAccepted(String submitter, try { GetApplicationReportResponse response = submitterClient .getApplicationReport(request); - Assert.assertEquals(response.getApplicationReport().getPriority(), + Assertions.assertEquals(response.getApplicationReport().getPriority(), Priority.newInstance(priority)); } catch (YarnException e) { - Assert.fail("Application submission should not fail."); + Assertions.fail("Application submission should not fail."); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueDeletionPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueDeletionPolicy.java index 6ed76b6341c82..2e0e7f8f08f75 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueDeletionPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueDeletionPolicy.java @@ -32,10 +32,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAttemptRemovedSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppRemovedSchedulerEvent; -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 static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerNewQueueAutoCreation.MAX_MEMORY; @@ -61,7 +61,7 @@ public class TestAutoCreatedQueueDeletionPolicy / a1 */ - @Before + @BeforeEach public void setUp() throws Exception { csConf = new CapacitySchedulerConfiguration(); csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -81,7 +81,7 @@ public void setUp() throws Exception { csConf.setAutoExpiredDeletionTime(1); } - @After + @AfterEach public void tearDown() { if (mockRM != null) { mockRM.stop(); @@ -94,14 +94,14 @@ public void testEditSchedule() throws Exception { // Make sure e not null AbstractCSQueue e = (AbstractCSQueue) cs. getQueue("root.e"); - Assert.assertNotNull(e); - Assert.assertTrue(e.isDynamicQueue()); + Assertions.assertNotNull(e); + Assertions.assertTrue(e.isDynamicQueue()); // Make sure e1 not null AbstractCSQueue e1 = (AbstractCSQueue)cs. getQueue("root.e.e1"); - Assert.assertNotNull(e1); - Assert.assertTrue(e1.isDynamicQueue()); + Assertions.assertNotNull(e1); + Assertions.assertTrue(e1.isDynamicQueue()); // signal it because of without submit created e1.setLastSubmittedTimestamp(Time.monotonicNow()); @@ -115,8 +115,8 @@ public void testEditSchedule() throws Exception { // Make sure user0 not null AbstractCSQueue user0 = (AbstractCSQueue) cs .getQueue("root.e.user_0"); - Assert.assertNotNull(user0); - Assert.assertTrue(user0.isDynamicQueue()); + Assertions.assertNotNull(user0); + Assertions.assertTrue(user0.isDynamicQueue()); // Make app finished AppAttemptRemovedSchedulerEvent event = new AppAttemptRemovedSchedulerEvent(user0AppAttemptId, @@ -127,7 +127,7 @@ public void testEditSchedule() throws Exception { cs.handle(rEvent); // There are no apps in user0 - Assert.assertEquals(user0.getNumApplications(), 0); + Assertions.assertEquals(user0.getNumApplications(), 0); // Wait the time expired. long l1 = user0.getLastSubmittedTimestamp(); @@ -148,29 +148,29 @@ public void testEditSchedule() throws Exception { // Make sure user_0 , e1 queue // will be scheduled to mark for deletion // because it is expired for deletion. - Assert.assertEquals(policy.getMarkedForDeletion().size(), 2); - Assert.assertTrue(policy. + Assertions.assertEquals(policy.getMarkedForDeletion().size(), 2); + Assertions.assertTrue(policy. getMarkedForDeletion().contains("root.e.user_0")); - Assert.assertTrue(policy. + Assertions.assertTrue(policy. getMarkedForDeletion().contains("root.e.e1")); // Make sure the send for deletion is empty for first mark. - Assert.assertEquals(policy.getSentForDeletion().size(), 0); + Assertions.assertEquals(policy.getSentForDeletion().size(), 0); // Make sure user_0 , e1 queue will be scheduled to send for deletion policy.prepareForAutoDeletion(); - Assert.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assert.assertEquals(policy.getSentForDeletion().size(), 2); + Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); + Assertions.assertEquals(policy.getSentForDeletion().size(), 2); // Make sure e1, user0 not null before trigger remove. e1 = (AbstractCSQueue) cs.getQueue("root.e.e1"); - Assert.assertNotNull(e1); + Assertions.assertNotNull(e1); user0 = (AbstractCSQueue)cs.getQueue("root.e.user_0"); - Assert.assertNotNull(user0); + Assertions.assertNotNull(user0); // Make sure e1, user0 will be null after trigger remove. policy.triggerAutoDeletionForExpiredQueues(); - Assert.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assert.assertEquals(policy.getSentForDeletion().size(), 0); + Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); + Assertions.assertEquals(policy.getSentForDeletion().size(), 0); // Wait e1, user0 auto deleted. GenericTestUtils.waitFor(()-> cs.getQueue( @@ -180,13 +180,13 @@ public void testEditSchedule() throws Exception { "root.e.user_0") == null, 100, 2000); e1 = (AbstractCSQueue) cs.getQueue("root.e.e1"); - Assert.assertNull(e1); + Assertions.assertNull(e1); user0 = (AbstractCSQueue)cs.getQueue("root.e.user_0"); - Assert.assertNull(user0); + Assertions.assertNull(user0); // Make sure e is not null, before schedule. e = (AbstractCSQueue) cs.getQueue("root.e"); - Assert.assertNotNull(e); + Assertions.assertNotNull(e); // Expired for e // Wait e marked for deletion. @@ -198,29 +198,29 @@ public void testEditSchedule() throws Exception { }, 100, 2000); policy.editSchedule(); e = (AbstractCSQueue) cs.getQueue("root.e"); - Assert.assertNotNull(e); - Assert.assertEquals(policy.getMarkedForDeletion().size(), 1); - Assert.assertEquals(policy.getSentForDeletion().size(), 0); - Assert.assertTrue(policy.getMarkedForDeletion().contains("root.e")); + Assertions.assertNotNull(e); + Assertions.assertEquals(policy.getMarkedForDeletion().size(), 1); + Assertions.assertEquals(policy.getSentForDeletion().size(), 0); + Assertions.assertTrue(policy.getMarkedForDeletion().contains("root.e")); // Make sure e queue will be scheduled to send for deletion policy.prepareForAutoDeletion(); - Assert.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assert.assertEquals(policy.getSentForDeletion().size(), 1); + Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); + Assertions.assertEquals(policy.getSentForDeletion().size(), 1); // Make sure e not null before trigger remove. e = (AbstractCSQueue) cs.getQueue("root.e"); - Assert.assertNotNull(e); + Assertions.assertNotNull(e); // Make sure e will be null after trigger remove. policy.triggerAutoDeletionForExpiredQueues(); // Wait e1 auto deleted. GenericTestUtils.waitFor(()-> cs.getQueue( "root.e") == null, 100, 2000); - Assert.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assert.assertEquals(policy.getSentForDeletion().size(), 0); + Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); + Assertions.assertEquals(policy.getSentForDeletion().size(), 0); e = (AbstractCSQueue) cs.getQueue("root.e"); - Assert.assertNull(e); + Assertions.assertNull(e); } public void prepareForSchedule() throws Exception{ @@ -228,8 +228,8 @@ public void prepareForSchedule() throws Exception{ policy.editSchedule(); // There are no queues should be scheduled - Assert.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assert.assertEquals(policy.getSentForDeletion().size(), 0); + Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); + Assertions.assertEquals(policy.getSentForDeletion().size(), 0); createQueue("root.e.e1"); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueTemplate.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueTemplate.java index 5b3acf11c4fdd..2f6d999945609 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueTemplate.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueTemplate.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -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 static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.AUTO_CREATE_CHILD_QUEUE_AUTO_REMOVAL_ENABLE; @@ -37,7 +37,7 @@ public class TestAutoCreatedQueueTemplate { private CapacitySchedulerConfiguration conf; - @Before + @BeforeEach public void setUp() throws Exception { conf = new CapacitySchedulerConfiguration(); conf.setQueues(ROOT, new String[]{"a"}); @@ -53,8 +53,8 @@ public void testNonWildCardTemplate() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB); template.setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assert.assertEquals("weight is not set", 6f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6); + Assertions.assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), + 10e-6, "weight is not set"); } @@ -65,8 +65,8 @@ public void testOneLevelWildcardTemplate() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB); template.setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assert.assertEquals("weight is not set", 6f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6); + Assertions.assertEquals(6f, + conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is not set"); } @@ -80,10 +80,10 @@ public void testTwoLevelWildcardTemplate() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB) .setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assert.assertEquals("weight is not set", 6f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6); - Assert.assertEquals("weight is not set", 5f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6); + Assertions.assertEquals(6f, + conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, "weight is not set"); + Assertions.assertEquals(5f, + conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is not set"); } @Test @@ -93,8 +93,8 @@ public void testIgnoredWhenRootWildcarded() { new AutoCreatedQueueTemplate(conf, ROOT); template.setTemplateEntriesForChild(conf, TEST_QUEUE_A); - Assert.assertEquals("weight is set", -1f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6); + Assertions.assertEquals(-1f, + conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, "weight is set"); } @Test @@ -104,8 +104,8 @@ public void testIgnoredWhenNoParent() { new AutoCreatedQueueTemplate(conf, ROOT); template.setTemplateEntriesForChild(conf, ROOT); - Assert.assertEquals("weight is set", -1f, - conf.getNonLabeledQueueWeight(ROOT), 10e-6); + Assertions.assertEquals(-1f, + conf.getNonLabeledQueueWeight(ROOT), 10e-6, "weight is set"); } @Test @@ -115,7 +115,7 @@ public void testWildcardAfterRoot() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_A); template.setTemplateEntriesForChild(conf, TEST_QUEUE_A); - Assert.assertEquals("acl_submit_applications is set", "user", + Assertions.assertEquals("acl_submit_applications is set", "user", template.getTemplateProperties().get("acl_submit_applications")); } @@ -129,9 +129,8 @@ public void testTemplatePrecedence() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB); template.setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assert.assertEquals( - "explicit template does not have the highest precedence", 6f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6); + Assertions.assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, + "explicit template does not have the highest precedence"); CapacitySchedulerConfiguration newConf = new CapacitySchedulerConfiguration(); @@ -140,8 +139,8 @@ public void testTemplatePrecedence() { new AutoCreatedQueueTemplate(newConf, TEST_QUEUE_AB); template.setTemplateEntriesForChild(newConf, TEST_QUEUE_ABC); - Assert.assertEquals("precedence is invalid", 4f, - newConf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6); + Assertions.assertEquals(4f, newConf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), + 10e-6, "precedence is invalid"); } @Test @@ -151,8 +150,8 @@ public void testRootTemplate() { AutoCreatedQueueTemplate template = new AutoCreatedQueueTemplate(conf, ROOT); template.setTemplateEntriesForChild(conf, TEST_QUEUE_A); - Assert.assertEquals("root property is not set", 2f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6); + Assertions.assertEquals(2f, conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, + "root property is not set"); } @Test @@ -169,17 +168,17 @@ public void testQueueSpecificTemplates() { template.setTemplateEntriesForChild(conf, TEST_QUEUE_A); template.setTemplateEntriesForChild(conf, TEST_QUEUE_B, true); - Assert.assertNull("default-node-label-expression is set for parent", - conf.getDefaultNodeLabelExpression(TEST_QUEUE_A)); - Assert.assertEquals("default-node-label-expression is not set for leaf", + Assertions.assertNull( + conf.getDefaultNodeLabelExpression(TEST_QUEUE_A), "default-node-label-expression is set for parent"); + Assertions.assertEquals("default-node-label-expression is not set for leaf", "test", conf.getDefaultNodeLabelExpression(TEST_QUEUE_B)); - Assert.assertFalse("auto queue removal is not disabled for parent", - conf.isAutoExpiredDeletionEnabled(TEST_QUEUE_A)); - Assert.assertEquals("weight should not be overridden when set by " + - "queue type specific template", - 10f, conf.getNonLabeledQueueWeight(TEST_QUEUE_B), 10e-6); - Assert.assertEquals("weight should be set by common template", - 2f, conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6); + Assertions.assertFalse( + conf.isAutoExpiredDeletionEnabled(TEST_QUEUE_A), "auto queue removal is not disabled for parent"); + Assertions.assertEquals(10f, conf.getNonLabeledQueueWeight(TEST_QUEUE_B), + 10e-6, "weight should not be overridden when set by " + + "queue type specific template"); + Assertions.assertEquals(2f, conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, + "weight should be set by common template"); } @@ -195,10 +194,10 @@ public void testWildcardTemplateWithLimitedAutoCreatedQueueDepth() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB) .setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assert.assertEquals("weight is not set", 6f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6); - Assert.assertEquals("weight is not set", 5f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6); + Assertions.assertEquals(6f, + conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, "weight is not set"); + Assertions.assertEquals(5f, + conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is not set"); } @Test @@ -209,8 +208,8 @@ public void testIgnoredTemplateWithLimitedAutoCreatedQueueDepth() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB) .setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assert.assertEquals("weight is set incorrectly", -1f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6); + Assertions.assertEquals(-1f, + conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is set incorrectly"); } @Test @@ -221,8 +220,8 @@ public void testIgnoredTemplateWhenQueuePathIsInvalid() { new AutoCreatedQueueTemplate(conf, invalidPath); template.setTemplateEntriesForChild(conf, TEST_QUEUE_AB); - Assert.assertEquals("weight is set using invalid queue path", -1f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6); + Assertions.assertEquals( -1f, + conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, "weight is set using invalid queue path"); } private String getTemplateKey(QueuePath queuePath, String entryKey) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java index 5c0f5d1d318f6..fb9ba64ae61fb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java @@ -44,10 +44,10 @@ import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceUtils; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.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 java.io.File; import java.io.IOException; @@ -63,7 +63,7 @@ import static org.apache.hadoop.yarn.api.records.ResourceInformation.FPGA_URI; import static org.apache.hadoop.yarn.api.records.ResourceInformation.GPU_URI; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_MB; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test case for custom resource container allocation. @@ -85,7 +85,7 @@ public class TestCSAllocateCustomResource { private ClusterNodeTracker nodeTracker; private ClusterMetrics metrics; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -94,7 +94,7 @@ public void setUp() throws Exception { mgr.init(conf); } - @After + @AfterEach public void tearDown() { if (resourceTypesFile != null && resourceTypesFile.exists()) { resourceTypesFile.delete(); @@ -162,7 +162,7 @@ public void testCapacitySchedulerJobWhenConfigureCustomResourceType() // Do nm heartbeats 1 times, will allocate a container on nm1 cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); rm.drainEvents(); - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); rm.close(); } @@ -193,12 +193,12 @@ public void testCapacitySchedulerInitWithCustomResourceType() // Ensure the method can get custom resource type from // CapacitySchedulerConfiguration - Assert.assertNotEquals(0, + Assertions.assertNotEquals(0, ResourceUtils .fetchMaximumAllocationFromConfig(cs.getConfiguration()) .getResourceValue("yarn.io/gpu")); // Ensure custom resource type exists in queue's maximumAllocation - Assert.assertNotEquals(0, + Assertions.assertNotEquals(0, cs.getMaximumResourceCapability("a") .getResourceValue("yarn.io/gpu")); rm.close(); @@ -236,26 +236,26 @@ public void testClusterMetricsWithGPU() } // Check GPU inc related cluster metrics. - assertEquals("Cluster Capability Memory incorrect", - metrics.getCapabilityMB(), (4096 * 8)); - assertEquals("Cluster Capability Vcores incorrect", - metrics.getCapabilityVirtualCores(), 4 * 8); - assertEquals("Cluster Capability GPUs incorrect", - (metrics.getCustomResourceCapability() - .get(GPU_URI)).longValue(), 4 * 8); + assertEquals( + metrics.getCapabilityMB(), (4096 * 8), "Cluster Capability Memory incorrect"); + assertEquals( + metrics.getCapabilityVirtualCores(), 4 * 8, "Cluster Capability Vcores incorrect"); + assertEquals( + (metrics.getCustomResourceCapability() + .get(GPU_URI)).longValue(), 4 * 8, "Cluster Capability GPUs incorrect"); for (RMNode rmNode : rmNodes) { nodeTracker.removeNode(rmNode.getNodeID()); } // Check GPU dec related cluster metrics. - assertEquals("Cluster Capability Memory incorrect", - metrics.getCapabilityMB(), 0); - assertEquals("Cluster Capability Vcores incorrect", - metrics.getCapabilityVirtualCores(), 0); - assertEquals("Cluster Capability GPUs incorrect", - (metrics.getCustomResourceCapability() - .get(GPU_URI)).longValue(), 0); + assertEquals( + metrics.getCapabilityMB(), 0, "Cluster Capability Memory incorrect"); + assertEquals( + metrics.getCapabilityVirtualCores(), 0, "Cluster Capability Vcores incorrect"); + assertEquals( + (metrics.getCustomResourceCapability() + .get(GPU_URI)).longValue(), 0, "Cluster Capability GPUs incorrect"); ClusterMetrics.destroy(); rm.stop(); } @@ -317,17 +317,17 @@ public void testCapacitySchedulerAbsoluteConfWithCustomResourceType() // Check the gpu resource conf is right. CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); - Assert.assertEquals(aMINRES, + Assertions.assertEquals(aMINRES, cs.getConfiguration(). getMinimumResourceRequirement("", A, resourceTypes)); - Assert.assertEquals(aMAXRES, + Assertions.assertEquals(aMAXRES, cs.getConfiguration(). getMaximumResourceRequirement("", A, resourceTypes)); // Check the gpu resource of queue is right. - Assert.assertEquals(aMINRES, cs.getQueue("root.a"). + Assertions.assertEquals(aMINRES, cs.getQueue("root.a"). getQueueResourceQuotas().getConfiguredMinResource()); - Assert.assertEquals(aMAXRES, cs.getQueue("root.a"). + Assertions.assertEquals(aMAXRES, cs.getQueue("root.a"). getQueueResourceQuotas().getConfiguredMaxResource()); 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/scheduler/capacity/TestCSMaxRunningAppsEnforcer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSMaxRunningAppsEnforcer.java index 768768e95dbf9..5d002a3cd4691 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSMaxRunningAppsEnforcer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSMaxRunningAppsEnforcer.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -43,8 +43,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.AppPriorityACLsManager; import org.apache.hadoop.yarn.util.ControlledClock; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TestCSMaxRunningAppsEnforcer { private CapacitySchedulerQueueManager queueManager; @@ -56,7 +56,7 @@ public class TestCSMaxRunningAppsEnforcer { private ActivitiesManager activitiesManager; private CapacitySchedulerConfiguration csConfig; - @Before + @BeforeEach public void setup() throws IOException { csConfig = new CapacitySchedulerConfiguration(); rmContext = mock(RMContext.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/scheduler/capacity/TestCSQueueStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSQueueStore.java index 8ec8d62e74454..953119be63d24 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSQueueStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSQueueStore.java @@ -24,12 +24,12 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; 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 java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; public class TestCSQueueStore { @@ -41,7 +41,7 @@ public class TestCSQueueStore { private CapacitySchedulerContext csContext; private CapacitySchedulerQueueContext queueContext; - @Before + @BeforeEach public void setUp() throws IOException { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java index d6b83cca388d8..6f7ef9c5381c1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java @@ -65,10 +65,10 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerOvercommit.updateNodeResource; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerOvercommit.waitMemory; -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 static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -195,10 +195,11 @@ import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceUtils; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.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; @@ -217,18 +218,19 @@ public class TestCapacityScheduler { private static final double DELTA = 0.0001; - @Before + @BeforeEach public void setUp() throws Exception { resourceManager = createResourceManager(); mockContext = createMockRMContext(); } - @After + @AfterEach public void tearDown() throws Exception { stopResourceManager(resourceManager); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testConfValidation() throws Exception { CapacityScheduler scheduler = new CapacityScheduler(); scheduler.setRMContext(resourceManager.getRMContext()); @@ -242,9 +244,9 @@ public void testConfValidation() throws Exception { " larger than the max memory allocation."); } catch (YarnRuntimeException e) { // Exception is expected. - assertTrue("The thrown exception is not the expected one.", - e.getMessage().startsWith( - "Invalid resource scheduler memory")); + assertTrue( + e.getMessage().startsWith( + "Invalid resource scheduler memory"), "The thrown exception is not the expected one."); } conf = new YarnConfiguration(); @@ -256,9 +258,9 @@ public void testConfValidation() throws Exception { " larger than the max vcores allocation."); } catch (YarnRuntimeException e) { // Exception is expected. - assertTrue("The thrown exception is not the expected one.", - e.getMessage().startsWith( - "Invalid resource scheduler vcores")); + assertTrue( + e.getMessage().startsWith( + "Invalid resource scheduler vcores"), "The thrown exception is not the expected one."); } } @@ -623,17 +625,17 @@ public void testQueueMaximumAllocations() { Resource maxAllocation2 = scheduler.getMaximumResourceCapability(null); Resource maxAllocation3 = scheduler.getMaximumResourceCapability(); - Assert.assertEquals(maxAllocation1, maxAllocation2); - Assert.assertEquals(maxAllocation1, maxAllocation3); - Assert.assertEquals( + Assertions.assertEquals(maxAllocation1, maxAllocation2); + Assertions.assertEquals(maxAllocation1, maxAllocation3); + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, maxAllocation1.getMemorySize()); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, maxAllocation1.getVirtualCores()); - Assert.assertEquals(1024, maxAllocationForQueue.getMemorySize()); - Assert.assertEquals(1, maxAllocationForQueue.getVirtualCores()); + Assertions.assertEquals(1024, maxAllocationForQueue.getMemorySize()); + Assertions.assertEquals(1, maxAllocationForQueue.getVirtualCores()); scheduler.stop(); } @@ -681,17 +683,17 @@ public void testParseQueueWithAbsoluteResource() { @Test public void testCapacitySchedulerInfo() throws Exception { QueueInfo queueInfo = resourceManager.getResourceScheduler().getQueueInfo("a", true, true); - Assert.assertEquals("Queue Name should be a", "a", + Assertions.assertEquals("Queue Name should be a", "a", queueInfo.getQueueName()); - Assert.assertEquals("Queue Path should be root.a", "root.a", + Assertions.assertEquals("Queue Path should be root.a", "root.a", queueInfo.getQueuePath()); - Assert.assertEquals("Child Queues size should be 2", 2, - queueInfo.getChildQueues().size()); + Assertions.assertEquals(2 +, queueInfo.getChildQueues().size(), "Child Queues size should be 2"); List userACLInfo = resourceManager.getResourceScheduler().getQueueUserAclInfo(); - Assert.assertNotNull(userACLInfo); + Assertions.assertNotNull(userACLInfo); for (QueueUserACLInfo queueUserACLInfo : userACLInfo) { - Assert.assertEquals(1, getQueueCount(userACLInfo, + Assertions.assertEquals(1, getQueueCount(userACLInfo, queueUserACLInfo.getQueueName())); } @@ -721,7 +723,7 @@ public void testAllocateReorder() throws Exception { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue q = (LeafQueue) cs.getQueue("default"); - Assert.assertNotNull(q); + Assertions.assertNotNull(q); FairOrderingPolicy fop = new FairOrderingPolicy(); fop.setSizeBasedWeight(true); @@ -841,14 +843,14 @@ public void testResourceOverCommit() throws Exception { // verify no NPE is trigger in schedule after resource is updated am.addRequests(new String[] {"127.0.0.1", "127.0.0.2"}, 3 * GB, 1, 1); AllocateResponse allocResponse2 = am.schedule(); - assertTrue("Shouldn't have enough resource to allocate containers", - allocResponse2.getAllocatedContainers().isEmpty()); + assertTrue( + allocResponse2.getAllocatedContainers().isEmpty(), "Shouldn't have enough resource to allocate containers"); // try 10 times as scheduling is an async process for (int i = 0; i < 10; i++) { Thread.sleep(100); allocResponse2 = am.schedule(); - assertTrue("Shouldn't have enough resource to allocate containers", - allocResponse2.getAllocatedContainers().isEmpty()); + assertTrue( + allocResponse2.getAllocatedContainers().isEmpty(), "Shouldn't have enough resource to allocate containers"); } // increase the resources again to 5 GB to schedule the 3GB container @@ -968,7 +970,8 @@ private void waitForNewAttemptCreated(RMApp app, } } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAllocateDoesNotBlockOnSchedulerLock() throws Exception { final YarnConfiguration conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -1004,7 +1007,7 @@ public void testAllocateDoesNotBlockOnSchedulerLock() throws Exception { Thread.sleep(msecToSleep); msecToWait -= msecToSleep; } - Assert.assertEquals(attempt.getAppAttemptState(), + Assertions.assertEquals(attempt.getAppAttemptState(), RMAppAttemptState.LAUNCHED); // Create a client to the RM. @@ -1044,7 +1047,7 @@ public ApplicationMasterProtocol run() { nm1.nodeHeartbeat(true); ContainerId containerId2 = ContainerId.newContainerId(applicationAttemptId, 2); - Assert.assertTrue(rm.waitForState(nm1, containerId2, + Assertions.assertTrue(rm.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire the container @@ -1085,7 +1088,8 @@ public void run() { rm.stop(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testPreemptionInfo() throws Exception { Configuration conf = new Configuration(); conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 3); @@ -1162,7 +1166,8 @@ public void testPreemptionInfo() throws Exception { rm1.stop(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testRecoverRequestAfterPreemption() throws Exception { Configuration conf = new Configuration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -1196,7 +1201,7 @@ public void testRecoverRequestAfterPreemption() throws Exception { // Already the node local resource request is cleared from RM after // allocation. - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getOutstandingAsksCount(SchedulerRequestKey.create(request), request.getResourceName())); } @@ -1204,11 +1209,11 @@ public void testRecoverRequestAfterPreemption() throws Exception { // Call killContainer to preempt the container cs.markContainerForKillable(rmContainer); - Assert.assertEquals(3, requests.size()); + Assertions.assertEquals(3, requests.size()); for (ResourceRequest request : requests) { // Resource request must have added back in RM after preempt event // handling. - Assert.assertEquals(1, + Assertions.assertEquals(1, app.getOutstandingAsksCount(SchedulerRequestKey.create(request), request.getResourceName())); } @@ -1223,7 +1228,7 @@ public void testRecoverRequestAfterPreemption() throws Exception { new ArrayList()).getAllocatedContainers(); // Now with updated ResourceRequest, a container is allocated for AM. - Assert.assertTrue(containers.size() == 1); + Assertions.assertTrue(containers.size() == 1); rm1.stop(); } @@ -1250,8 +1255,8 @@ null, new RMContainerTokenSecretManager(conf), // When preemption turned on for the whole system // (yarn.resourcemanager.scheduler.monitor.enable=true), and with no other // preemption properties set, queue root.b.b2 should be preemptable. - assertFalse("queue " + B2 + " should default to preemptable", - queueB2.getPreemptionDisabled()); + assertFalse( + queueB2.getPreemptionDisabled(), "queue " + B2 + " should default to preemptable"); // Disable preemption at the root queue level. // The preemption property should be inherited from root all the @@ -1259,8 +1264,8 @@ null, new RMContainerTokenSecretManager(conf), conf.setPreemptionDisabled(rootQueue.getQueuePathObject(), true); cs.reinitialize(conf, rmContext); assertTrue( - "queue " + B2 + " should have inherited non-preemptability from root", - queueB2.getPreemptionDisabled()); + + queueB2.getPreemptionDisabled(), "queue " + B2 + " should have inherited non-preemptability from root"); // Enable preemption for root (grandparent) but disable for root.b (parent). // root.b.b2 should inherit property from parent and NOT be preemptable @@ -1268,15 +1273,15 @@ null, new RMContainerTokenSecretManager(conf), conf.setPreemptionDisabled(queueB.getQueuePathObject(), true); cs.reinitialize(conf, rmContext); assertTrue( - "queue " + B2 + " should have inherited non-preemptability from parent", - queueB2.getPreemptionDisabled()); + + queueB2.getPreemptionDisabled(), "queue " + B2 + " should have inherited non-preemptability from parent"); // When preemption is turned on for root.b.b2, it should be preemptable // even though preemption is disabled on root.b (parent). conf.setPreemptionDisabled(queueB2.getQueuePathObject(), false); cs.reinitialize(conf, rmContext); - assertFalse("queue " + B2 + " should have been preemptable", - queueB2.getPreemptionDisabled()); + assertFalse( + queueB2.getPreemptionDisabled(), "queue " + B2 + " should have been preemptable"); cs.stop(); } @@ -1286,7 +1291,7 @@ private void waitContainerAllocated(MockAM am, int mem, int nContainer, am.allocate("*", mem, 1, new ArrayList()); ContainerId containerId = ContainerId.newContainerId(am.getApplicationAttemptId(), cId); - Assert.assertTrue(rm.waitForState(nm, containerId, + Assertions.assertTrue(rm.waitForState(nm, containerId, RMContainerState.ALLOCATED)); } } @@ -1354,12 +1359,12 @@ public void testSchedulerKeyGarbageCollection() throws Exception { null); List allocatedContainers = allocateResponse .getAllocatedContainers(); - Assert.assertEquals(0, allocatedContainers.size()); + Assertions.assertEquals(0, allocatedContainers.size()); Collection schedulerKeys = ((CapacityScheduler) scheduler).getApplicationAttempt(attemptId) .getAppSchedulingInfo().getSchedulerKeys(); - Assert.assertEquals(4, schedulerKeys.size()); + Assertions.assertEquals(4, schedulerKeys.size()); // Get a Node to HB... at which point 1 container should be // allocated @@ -1367,10 +1372,10 @@ public void testSchedulerKeyGarbageCollection() throws Exception { Thread.sleep(200); allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); allocatedContainers = allocateResponse.getAllocatedContainers(); - Assert.assertEquals(1, allocatedContainers.size()); + Assertions.assertEquals(1, allocatedContainers.size()); // Verify 1 outstanding schedulerKey is removed - Assert.assertEquals(3, schedulerKeys.size()); + Assertions.assertEquals(3, schedulerKeys.size()); List resReqs = ((CapacityScheduler) scheduler).getApplicationAttempt(attemptId) @@ -1378,7 +1383,7 @@ public void testSchedulerKeyGarbageCollection() throws Exception { // Verify 1 outstanding schedulerKey is removed from the // rrMap as well - Assert.assertEquals(3, resReqs.size()); + Assertions.assertEquals(3, resReqs.size()); // Verify One more container Allocation on node nm2 // And ensure the outstanding schedulerKeys go down.. @@ -1396,15 +1401,15 @@ public void testSchedulerKeyGarbageCollection() throws Exception { ), new ArrayList<>()); allocatedContainers = allocateResponse.getAllocatedContainers(); - Assert.assertEquals(1, allocatedContainers.size()); + Assertions.assertEquals(1, allocatedContainers.size()); // Verify 1 outstanding schedulerKey is removed - Assert.assertEquals(2, schedulerKeys.size()); + Assertions.assertEquals(2, schedulerKeys.size()); resReqs = ((CapacityScheduler) scheduler).getApplicationAttempt(attemptId) .getAppSchedulingInfo().getAllResourceRequests(); // Verify the map size is not increased due to 0 req - Assert.assertEquals(2, resReqs.size()); + Assertions.assertEquals(2, resReqs.size()); // Now Verify that the AM can cancel 1 Ask: SchedulerRequestKey sk = schedulerKeys.iterator().next(); @@ -1425,7 +1430,7 @@ public void testSchedulerKeyGarbageCollection() throws Exception { // Verify 1 outstanding schedulerKey is removed because of the // cancel ask - Assert.assertEquals(1, schedulerKeys.size()); + Assertions.assertEquals(1, schedulerKeys.size()); // Now verify that after the next node heartbeat, we allocate // the last schedulerKey @@ -1433,14 +1438,14 @@ public void testSchedulerKeyGarbageCollection() throws Exception { Thread.sleep(200); allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); allocatedContainers = allocateResponse.getAllocatedContainers(); - Assert.assertEquals(1, allocatedContainers.size()); + Assertions.assertEquals(1, allocatedContainers.size()); // Verify no more outstanding schedulerKeys.. - Assert.assertEquals(0, schedulerKeys.size()); + Assertions.assertEquals(0, schedulerKeys.size()); resReqs = ((CapacityScheduler) scheduler).getApplicationAttempt(attemptId) .getAppSchedulingInfo().getAllResourceRequests(); - Assert.assertEquals(0, resReqs.size()); + Assertions.assertEquals(0, resReqs.size()); rm.stop(); } @@ -1489,7 +1494,7 @@ public void testHierarchyQueuesCurrentLimits() throws Exception { // Maximum resource of b1 is 100 * 0.895 * 0.792 = 71 GB // 2 GBs used by am, so it's 71 - 2 = 69G. - Assert.assertEquals(69 * GB, + Assertions.assertEquals(69 * GB, am1.doHeartbeat().getAvailableResources().getMemorySize()); MockRMAppSubmissionData data1 = @@ -1513,7 +1518,7 @@ public void testHierarchyQueuesCurrentLimits() throws Exception { // B2 uses 41 GB (5 * 8GB containers and 1 AM container) // B1 uses 3 GB (2 * 1GB containers and 1 AM container) // Available is 100 - 41 - 3 = 56 GB - Assert.assertEquals(56 * GB, + Assertions.assertEquals(56 * GB, am1.doHeartbeat().getAvailableResources().getMemorySize()); // Now we submit app3 to a1 (in higher level hierarchy), to see if headroom @@ -1540,7 +1545,7 @@ public void testHierarchyQueuesCurrentLimits() throws Exception { // B1 uses 4 GB (3 * 1GB containers and 1 AM container) // A1 uses 25 GB (3 * 8GB containers and 1 AM container) // Available is 100 - 41 - 4 - 25 = 30 GB - Assert.assertEquals(30 * GB, + Assertions.assertEquals(30 * GB, am1.doHeartbeat().getAvailableResources().getMemorySize()); rm1.stop(); } @@ -1613,7 +1618,7 @@ public void testParentQueueMaxCapsAreRespected() throws Exception { // Expected, return; return; } - Assert.fail("Shouldn't successfully allocate containers for am2, " + Assertions.fail("Shouldn't successfully allocate containers for am2, " + "queue-a's max capacity will be violated if container allocated"); rm1.stop(); } @@ -1731,10 +1736,10 @@ protected RMNodeLabelsManager createNodeLabelManager() { // some containers allocated for am1, pending resource should decrease ContainerId containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm.waitForState(nm1, containerId, + Assertions.assertTrue(rm.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 3); - Assert.assertTrue(rm.waitForState(nm2, containerId, + Assertions.assertTrue(rm.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); checkPendingResource(rm, "a1", 0 * GB, null); @@ -1768,7 +1773,8 @@ protected RMNodeLabelsManager createNodeLabelManager() { // Test verifies AM Used resource for LeafQueue when AM ResourceRequest is // lesser than minimumAllocation - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAMUsedResource() throws Exception { MockRM rm = setUpMove(); rm.registerNode("127.0.0.1:1234", 4 * GB); @@ -1778,8 +1784,8 @@ public void testAMUsedResource() throws Exception { conf.getInt(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB); int amMemory = 50; - assertTrue("AM memory is greater than or equal to minAllocation", - amMemory < minAllocMb); + assertTrue( + amMemory < minAllocMb, "AM memory is greater than or equal to minAllocation"); Resource minAllocResource = Resource.newInstance(minAllocMb, 1); String queueName = "a1"; MockRMAppSubmissionData data = @@ -1792,14 +1798,14 @@ public void testAMUsedResource() throws Exception { .build(); RMApp rmApp = MockRMAppSubmitter.submit(rm, data); - assertEquals("RMApp does not containes minimum allocation", - minAllocResource, rmApp.getAMResourceRequests().get(0).getCapability()); + assertEquals( + minAllocResource, rmApp.getAMResourceRequests().get(0).getCapability(), "RMApp does not containes minimum allocation"); ResourceScheduler scheduler = rm.getRMContext().getScheduler(); LeafQueue queueA = (LeafQueue) ((CapacityScheduler) scheduler).getQueue(queueName); - assertEquals("Minimum Resource for AM is incorrect", minAllocResource, - queueA.getUser("user_0").getResourceUsage().getAMUsed()); + assertEquals(minAllocResource +, queueA.getUser("user_0").getResourceUsage().getAMUsed(), "Minimum Resource for AM is incorrect"); rm.stop(); } @@ -1846,11 +1852,11 @@ public void testApplicationHeadRoom() throws Exception { null, Collections. emptyList(), null, null, NULL_UPDATE_REQUESTS); - Assert.assertNotNull(attempt); + Assertions.assertNotNull(attempt); - Assert + Assertions .assertEquals(Resource.newInstance(0, 0), allocate.getResourceLimit()); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), attemptMetric.getApplicationAttemptHeadroom()); // Add a node to cluster @@ -1864,8 +1870,8 @@ null, Collections. emptyList(), null, null, NULL_UPDATE_REQUESTS); // All resources should be sent as headroom - Assert.assertEquals(newResource, allocate.getResourceLimit()); - Assert.assertEquals(newResource, + Assertions.assertEquals(newResource, allocate.getResourceLimit()); + Assertions.assertEquals(newResource, attemptMetric.getApplicationAttemptHeadroom()); rm.stop(); @@ -1941,7 +1947,8 @@ public void testHeadRoomCalculationWithDRC() throws Exception { rm.stop(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAMLimitUsage() throws Exception { CapacitySchedulerConfiguration config = @@ -2008,7 +2015,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); ContainerId containerId3 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 3); - Assert.assertTrue(rm.waitForState(nm1, containerId3, + Assertions.assertTrue(rm.waitForState(nm1, containerId3, RMContainerState.ALLOCATED)); // Acquire them am1.allocate(null, null); @@ -2028,7 +2035,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { FiCaSchedulerApp app = getFiCaSchedulerApp(rm, app1.getApplicationId()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); checkPendingResource(rm, "a1", 2 * GB, null); checkPendingResource(rm, "a", 2 * GB, null); @@ -2045,7 +2052,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { ContainerUpdateType.INCREASE_RESOURCE, Resources.createResource(5 * GB), null))); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); checkPendingResource(rm, "a1", 6 * GB, null); checkPendingResource(rm, "a", 6 * GB, null); @@ -2066,7 +2073,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { .newInstance(0, containerId3, ContainerUpdateType.INCREASE_RESOURCE, Resources.createResource(2 * GB), null))); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(4 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); checkPendingResource(rm, "a1", 4 * GB, null); checkPendingResource(rm, "a", 4 * GB, null); @@ -2122,15 +2129,15 @@ public Boolean get() { // When AM limit is exceeded, 1 applications will be activated.Rest all // applications will be in pending - Assert.assertEquals("PendingApplications should be 1", 1, - queueA.getNumPendingApplications()); - Assert.assertEquals("Active applications should be 1", 1, - queueA.getNumActiveApplications()); - - Assert.assertEquals("User PendingApplications should be 1", 1, queueA - .getUser(userName).getPendingApplications()); - Assert.assertEquals("User Active applications should be 1", 1, queueA - .getUser(userName).getActiveApplications()); + Assertions.assertEquals(1 +, queueA.getNumPendingApplications(), "PendingApplications should be 1"); + Assertions.assertEquals(1 +, queueA.getNumActiveApplications(), "Active applications should be 1"); + + Assertions.assertEquals(1, queueA + .getUser(userName).getPendingApplications(), "User PendingApplications should be 1"); + Assertions.assertEquals(1, queueA + .getUser(userName).getActiveApplications(), "User Active applications should be 1"); rm.stop(); } @@ -2141,7 +2148,7 @@ private void sentRMContainerLaunched(MockRM rm, ContainerId containerId) { rmContainer.handle( new RMContainerEvent(containerId, RMContainerEventType.LAUNCHED)); } else { - Assert.fail("Cannot find RMContainer"); + Assertions.fail("Cannot find RMContainer"); } } @@ -2157,7 +2164,7 @@ public void testCSReservationWithRootUnblocked() throws Exception { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); ParentQueue q = (ParentQueue) cs.getQueue("p1"); - Assert.assertNotNull(q); + Assertions.assertNotNull(q); String host = "127.0.0.1"; String host1 = "test"; RMNode node = @@ -2187,10 +2194,10 @@ public void testCSReservationWithRootUnblocked() throws Exception { null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); } - assertEquals("Y1 Used Resource should be 4 GB", 4 * GB, - cs.getQueue("y1").getUsedResources().getMemorySize()); - assertEquals("P2 Used Resource should be 4 GB", 4 * GB, - cs.getQueue("p2").getUsedResources().getMemorySize()); + assertEquals(4 * GB +, cs.getQueue("y1").getUsedResources().getMemorySize(), "Y1 Used Resource should be 4 GB"); + assertEquals(4 * GB +, cs.getQueue("p2").getUsedResources().getMemorySize(), "P2 Used Resource should be 4 GB"); for(int i=0; i < 7; i++) { x1Req = TestUtils.createResourceRequest( @@ -2200,10 +2207,10 @@ public void testCSReservationWithRootUnblocked() throws Exception { null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); } - assertEquals("X1 Used Resource should be 7 GB", 7 * GB, - cs.getQueue("x1").getUsedResources().getMemorySize()); - assertEquals("P1 Used Resource should be 7 GB", 7 * GB, - cs.getQueue("p1").getUsedResources().getMemorySize()); + assertEquals(7 * GB +, cs.getQueue("x1").getUsedResources().getMemorySize(), "X1 Used Resource should be 7 GB"); + assertEquals(7 * GB +, cs.getQueue("p1").getUsedResources().getMemorySize(), "P1 Used Resource should be 7 GB"); x2Req = TestUtils.createResourceRequest( ResourceRequest.ANY, 2 * GB, 1, true, priority, recordFactory); @@ -2211,10 +2218,10 @@ public void testCSReservationWithRootUnblocked() throws Exception { Collections.singletonList(x2Req), null, Collections.emptyList(), null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); - assertEquals("X2 Used Resource should be 0", 0, - cs.getQueue("x2").getUsedResources().getMemorySize()); - assertEquals("P1 Used Resource should be 7 GB", 7 * GB, - cs.getQueue("p1").getUsedResources().getMemorySize()); + assertEquals(0 +, cs.getQueue("x2").getUsedResources().getMemorySize(), "X2 Used Resource should be 0"); + assertEquals(7 * GB +, cs.getQueue("p1").getUsedResources().getMemorySize(), "P1 Used Resource should be 7 GB"); //this assign should fail x1Req = TestUtils.createResourceRequest( ResourceRequest.ANY, 1 * GB, 1, true, priority, recordFactory); @@ -2222,10 +2229,10 @@ public void testCSReservationWithRootUnblocked() throws Exception { Collections.singletonList(x1Req), null, Collections.emptyList(), null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); - assertEquals("X1 Used Resource should be 7 GB", 7 * GB, - cs.getQueue("x1").getUsedResources().getMemorySize()); - assertEquals("P1 Used Resource should be 7 GB", 7 * GB, - cs.getQueue("p1").getUsedResources().getMemorySize()); + assertEquals(7 * GB +, cs.getQueue("x1").getUsedResources().getMemorySize(), "X1 Used Resource should be 7 GB"); + assertEquals(7 * GB +, cs.getQueue("p1").getUsedResources().getMemorySize(), "P1 Used Resource should be 7 GB"); //this should get thru for (int i=0; i < 4; i++) { @@ -2236,8 +2243,8 @@ public void testCSReservationWithRootUnblocked() throws Exception { null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); } - assertEquals("P2 Used Resource should be 8 GB", 8 * GB, - cs.getQueue("p2").getUsedResources().getMemorySize()); + assertEquals(8 * GB +, cs.getQueue("p2").getUsedResources().getMemorySize(), "P2 Used Resource should be 8 GB"); //Free a container from X1 ContainerId containerId = ContainerId.newContainerId(appAttemptId1, 2); @@ -2245,14 +2252,14 @@ public void testCSReservationWithRootUnblocked() throws Exception { //Schedule pending request CapacityScheduler.schedule(cs); - assertEquals("X2 Used Resource should be 2 GB", 2 * GB, - cs.getQueue("x2").getUsedResources().getMemorySize()); - assertEquals("P1 Used Resource should be 8 GB", 8 * GB, - cs.getQueue("p1").getUsedResources().getMemorySize()); - assertEquals("P2 Used Resource should be 8 GB", 8 * GB, - cs.getQueue("p2").getUsedResources().getMemorySize()); - assertEquals("Root Used Resource should be 16 GB", 16 * GB, - cs.getRootQueue().getUsedResources().getMemorySize()); + assertEquals(2 * GB +, cs.getQueue("x2").getUsedResources().getMemorySize(), "X2 Used Resource should be 2 GB"); + assertEquals(8 * GB +, cs.getQueue("p1").getUsedResources().getMemorySize(), "P1 Used Resource should be 8 GB"); + assertEquals(8 * GB +, cs.getQueue("p2").getUsedResources().getMemorySize(), "P2 Used Resource should be 8 GB"); + assertEquals(16 * GB +, cs.getRootQueue().getUsedResources().getMemorySize(), "Root Used Resource should be 16 GB"); rm.stop(); } @@ -2267,7 +2274,7 @@ public void testCSQueueBlocked() throws Exception { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue q = (LeafQueue) cs.getQueue("a"); - Assert.assertNotNull(q); + Assertions.assertNotNull(q); String host = "127.0.0.1"; String host1 = "test"; RMNode node = @@ -2303,10 +2310,10 @@ public void testCSQueueBlocked() throws Exception { null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); } - assertEquals("A Used Resource should be 2 GB", 2 * GB, - cs.getQueue("a").getUsedResources().getMemorySize()); - assertEquals("B Used Resource should be 13 GB", 13 * GB, - cs.getQueue("b").getUsedResources().getMemorySize()); + assertEquals(2 * GB +, cs.getQueue("a").getUsedResources().getMemorySize(), "A Used Resource should be 2 GB"); + assertEquals(13 * GB +, cs.getQueue("b").getUsedResources().getMemorySize(), "B Used Resource should be 13 GB"); r1 = TestUtils.createResourceRequest( ResourceRequest.ANY, 2 * GB, 1, true, priority, recordFactory); r2 = TestUtils.createResourceRequest( @@ -2320,10 +2327,10 @@ public void testCSQueueBlocked() throws Exception { null, Collections.emptyList(), null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); //Check blocked Resource - assertEquals("A Used Resource should be 2 GB", 2 * GB, - cs.getQueue("a").getUsedResources().getMemorySize()); - assertEquals("B Used Resource should be 13 GB", 13 * GB, - cs.getQueue("b").getUsedResources().getMemorySize()); + assertEquals(2 * GB +, cs.getQueue("a").getUsedResources().getMemorySize(), "A Used Resource should be 2 GB"); + assertEquals(13 * GB +, cs.getQueue("b").getUsedResources().getMemorySize(), "B Used Resource should be 13 GB"); ContainerId containerId1 = ContainerId.newContainerId(appAttemptId2, 10); ContainerId containerId2 =ContainerId.newContainerId(appAttemptId2, 11); @@ -2336,12 +2343,12 @@ public void testCSQueueBlocked() throws Exception { CapacityScheduler.schedule(cs); rm.drainEvents(); - assertEquals("A Used Resource should be 4 GB", 4 * GB, - cs.getQueue("a").getUsedResources().getMemorySize()); - assertEquals("B Used Resource should be 12 GB", 12 * GB, - cs.getQueue("b").getUsedResources().getMemorySize()); - assertEquals("Used Resource on Root should be 16 GB", 16 * GB, - cs.getRootQueue().getUsedResources().getMemorySize()); + assertEquals(4 * GB +, cs.getQueue("a").getUsedResources().getMemorySize(), "A Used Resource should be 4 GB"); + assertEquals(12 * GB +, cs.getQueue("b").getUsedResources().getMemorySize(), "B Used Resource should be 12 GB"); + assertEquals(16 * GB +, cs.getRootQueue().getUsedResources().getMemorySize(), "Used Resource on Root should be 16 GB"); rm.stop(); } @@ -2402,13 +2409,14 @@ protected RMNodeLabelsManager createNodeLabelManager() { // We should get one node-local allocation, one rack-local allocation // And one off-switch allocation - Assert.assertArrayEquals(new int[][] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, + Assertions.assertArrayEquals(new int[][] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, attemptMetrics.getLocalityStatistics()); rm.stop(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAMLimitDouble() throws Exception { CapacitySchedulerConfiguration config = new CapacitySchedulerConfiguration(); @@ -2431,8 +2439,8 @@ public void testAMLimitDouble() throws Exception { LeafQueue queueA = (LeafQueue) ((CapacityScheduler) scheduler).getQueue("default"); Resource amResourceLimit = queueA.getAMResourceLimit(); - Assert.assertEquals(4096, amResourceLimit.getMemorySize()); - Assert.assertEquals(4, amResourceLimit.getVirtualCores()); + Assertions.assertEquals(4096, amResourceLimit.getMemorySize()); + Assertions.assertEquals(4, amResourceLimit.getVirtualCores()); rm.stop(); } @@ -2475,84 +2483,85 @@ public void testQueueMappingWithCurrentUserQueueMappingForaGroup() throws rm.stop(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testcheckAndGetApplicationLifetime() throws Exception { long maxLifetime = 10; long defaultLifetime = 5; // positive integer value CapacityScheduler cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assert.assertEquals(maxLifetime, + Assertions.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assert.assertEquals(9, cs.checkAndGetApplicationLifetime("default", 9, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(9, cs.checkAndGetApplicationLifetime("default", 9, null)); + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); - Assert.assertEquals(maxLifetime, + Assertions.assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = -1; defaultLifetime = -1; // test for default values cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); - Assert.assertEquals(maxLifetime, + Assertions.assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = 10; defaultLifetime = 10; cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assert.assertEquals(maxLifetime, + Assertions.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); - Assert.assertEquals(maxLifetime, + Assertions.assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = 0; defaultLifetime = 0; cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assert.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); maxLifetime = 10; defaultLifetime = -1; cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assert.assertEquals(maxLifetime, + Assertions.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assert.assertEquals(maxLifetime, + Assertions.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assert.assertEquals(maxLifetime, + Assertions.assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); maxLifetime = 5; defaultLifetime = 10; try { setUpCSQueue(maxLifetime, defaultLifetime); - Assert.fail("Expected to fails since maxLifetime < defaultLifetime."); + Assertions.fail("Expected to fails since maxLifetime < defaultLifetime."); } catch (ServiceStateException sse) { Throwable rootCause = sse.getCause().getCause(); - Assert.assertTrue( + Assertions.assertTrue( rootCause.getMessage().contains("can't exceed maximum lifetime")); } maxLifetime = -1; defaultLifetime = 10; cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assert.assertEquals(100, + Assertions.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assert.assertEquals(defaultLifetime, + Assertions.assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); } @@ -2577,7 +2586,8 @@ private CapacityScheduler setUpCSQueue(long maxLifetime, return cs; } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testClearRequestsBeforeApplyTheProposal() throws Exception { // init RM & NMs & Nodes @@ -2614,9 +2624,9 @@ public Object answer(InvocationOnMock invocation) throws Exception { (ResourceCommitRequest) invocation.getArguments()[1], (Boolean) invocation.getArguments()[2]); // the proposal of removed request should be rejected - Assert.assertEquals(1, schedulerApp.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp.getLiveContainers().size()); } catch (Throwable e) { - Assert.fail(); + Assertions.fail(); } return null; } @@ -2638,13 +2648,13 @@ public Object answer(InvocationOnMock invocation) throws Exception { // values during scheduling. @Test public void testContainerAllocationLocalitySkipped() throws Exception { - Assert.assertEquals(AllocationState.APP_SKIPPED, + Assertions.assertEquals(AllocationState.APP_SKIPPED, ContainerAllocation.APP_SKIPPED.getAllocationState()); - Assert.assertEquals(AllocationState.LOCALITY_SKIPPED, + Assertions.assertEquals(AllocationState.LOCALITY_SKIPPED, ContainerAllocation.LOCALITY_SKIPPED.getAllocationState()); - Assert.assertEquals(AllocationState.PRIORITY_SKIPPED, + Assertions.assertEquals(AllocationState.PRIORITY_SKIPPED, ContainerAllocation.PRIORITY_SKIPPED.getAllocationState()); - Assert.assertEquals(AllocationState.QUEUE_SKIPPED, + Assertions.assertEquals(AllocationState.QUEUE_SKIPPED, ContainerAllocation.QUEUE_SKIPPED.getAllocationState()); // init RM & NMs & Nodes @@ -2673,15 +2683,15 @@ public void testContainerAllocationLocalitySkipped() throws Exception { assertThat(cs.getRMContainer(cid).getState()). isEqualTo(RMContainerState.ACQUIRED); cid = ContainerId.newContainerId(am.getApplicationAttemptId(), 2l); - Assert.assertNull(cs.getRMContainer(cid)); + Assertions.assertNull(cs.getRMContainer(cid)); - Assert.assertEquals(AllocationState.APP_SKIPPED, + Assertions.assertEquals(AllocationState.APP_SKIPPED, ContainerAllocation.APP_SKIPPED.getAllocationState()); - Assert.assertEquals(AllocationState.LOCALITY_SKIPPED, + Assertions.assertEquals(AllocationState.LOCALITY_SKIPPED, ContainerAllocation.LOCALITY_SKIPPED.getAllocationState()); - Assert.assertEquals(AllocationState.PRIORITY_SKIPPED, + Assertions.assertEquals(AllocationState.PRIORITY_SKIPPED, ContainerAllocation.PRIORITY_SKIPPED.getAllocationState()); - Assert.assertEquals(AllocationState.QUEUE_SKIPPED, + Assertions.assertEquals(AllocationState.QUEUE_SKIPPED, ContainerAllocation.QUEUE_SKIPPED.getAllocationState()); rm.stop(); } @@ -2735,13 +2745,13 @@ public void testCSQueueMetricsDoesNotLeakOnReinit() throws Exception { QueueMetrics a3DefaultPartitionMetrics = QueueMetrics.getQueueMetrics().get( "default.root.a.a3"); - Assert.assertSame("Different ParentQueue of siblings is a sign of a memory leak", - QueueMetrics.getQueueMetrics().get("root.a.a1").getParentQueue(), - QueueMetrics.getQueueMetrics().get("root.a.a3").getParentQueue()); + Assertions.assertSame( + QueueMetrics.getQueueMetrics().get("root.a.a1").getParentQueue() +, QueueMetrics.getQueueMetrics().get("root.a.a3").getParentQueue(), "Different ParentQueue of siblings is a sign of a memory leak"); - Assert.assertSame("Different ParentQueue of partition metrics is a sign of a memory leak", - QueueMetrics.getQueueMetrics().get("root.a.a1").getParentQueue(), - a3DefaultPartitionMetrics.getParentQueue()); + Assertions.assertSame( + QueueMetrics.getQueueMetrics().get("root.a.a1").getParentQueue() +, a3DefaultPartitionMetrics.getParentQueue(), "Different ParentQueue of partition metrics is a sign of a memory leak"); rm.stop(); } @@ -3012,28 +3022,28 @@ public void testReservedContainerLeakWhenMoveApplication() throws Exception { FiCaSchedulerApp schedulerApp2 = scheduler.getApplicationAttempt(am2.getApplicationAttemptId()); // APP1: 1 AM, 1 allocatedContainer - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); // APP2: 1 AM,1 reservedContainer - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getReservedContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getReservedContainers().size()); //before,move app2 which has one reservedContainer LeafQueue srcQueue = (LeafQueue) scheduler.getQueue("a"); LeafQueue desQueue = (LeafQueue) scheduler.getQueue("b"); - Assert.assertEquals(4, srcQueue.getNumContainers()); - Assert.assertEquals(10*GB, srcQueue.getUsedResources().getMemorySize()); - Assert.assertEquals(0, desQueue.getNumContainers()); - Assert.assertEquals(0, desQueue.getUsedResources().getMemorySize()); + Assertions.assertEquals(4, srcQueue.getNumContainers()); + Assertions.assertEquals(10*GB, srcQueue.getUsedResources().getMemorySize()); + Assertions.assertEquals(0, desQueue.getNumContainers()); + Assertions.assertEquals(0, desQueue.getUsedResources().getMemorySize()); //app1 ResourceUsage (0 reserved) - Assert.assertEquals(5*GB, + Assertions.assertEquals(5*GB, schedulerApp1 .getAppAttemptResourceUsage().getAllUsed().getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, schedulerApp1.getCurrentReservation().getMemorySize()); //app2 ResourceUsage (4GB reserved) - Assert.assertEquals(1*GB, + Assertions.assertEquals(1*GB, schedulerApp2 .getAppAttemptResourceUsage().getAllUsed().getMemorySize()); - Assert.assertEquals(4*GB, + Assertions.assertEquals(4*GB, schedulerApp2.getCurrentReservation().getMemorySize()); //move app2 which has one reservedContainer scheduler.moveApplication(app2.getApplicationId(), "b"); @@ -3042,10 +3052,10 @@ public void testReservedContainerLeakWhenMoveApplication() throws Exception { rm1.killApp(app2.getApplicationId()); rm1.killApp(app1.getApplicationId()); //after,moved app2 which has one reservedContainer - Assert.assertEquals(0, srcQueue.getNumContainers()); - Assert.assertEquals(0, desQueue.getNumContainers()); - Assert.assertEquals(0, srcQueue.getUsedResources().getMemorySize()); - Assert.assertEquals(0, desQueue.getUsedResources().getMemorySize()); + Assertions.assertEquals(0, srcQueue.getNumContainers()); + Assertions.assertEquals(0, desQueue.getNumContainers()); + Assertions.assertEquals(0, srcQueue.getUsedResources().getMemorySize()); + Assertions.assertEquals(0, desQueue.getUsedResources().getMemorySize()); rm1.close(); } @@ -3056,7 +3066,8 @@ public void testReservedContainerLeakWhenMoveApplication() throws Exception { * * @throws Exception TestTimedOutException means deadlock */ - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testRefreshQueueWithOpenPreemption() throws Exception { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); csConf.setQueues(new QueuePath(CapacitySchedulerConfiguration.ROOT), new String[]{"a"}); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAmbiguousLeafs.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAmbiguousLeafs.java index a3500943f59e1..c3612e7635125 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAmbiguousLeafs.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAmbiguousLeafs.java @@ -25,7 +25,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRM; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerApps.java index e881c3327b672..f26ec8e8b2155 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerApps.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerApps.java @@ -86,10 +86,11 @@ import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; 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 static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.A; @@ -110,9 +111,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.setUpMove; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.setUpMoveAmbiguousQueue; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.stopResourceManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -123,13 +122,13 @@ public class TestCapacitySchedulerApps { private ResourceManager resourceManager = null; private RMContext mockContext; - @Before + @BeforeEach public void setUp() throws Exception { resourceManager = createResourceManager(); mockContext = createMockRMContext(); } - @After + @AfterEach public void tearDown() throws Exception { stopResourceManager(resourceManager); } @@ -161,7 +160,7 @@ public void testGetAppsInQueue() throws Exception { assertTrue(appsInRoot.contains(application2.getApplicationAttemptId())); assertEquals(3, appsInRoot.size()); - Assert.assertNull(scheduler.getAppsInQueue("nonexistentqueue")); + Assertions.assertNull(scheduler.getAppsInQueue("nonexistentqueue")); } @Test @@ -178,7 +177,7 @@ public void testAddAndRemoveAppFromCapacityScheduler() throws Exception { SchedulerApplication app = TestSchedulerUtils.verifyAppAddedAndRemovedFromScheduler( cs.getSchedulerApplications(), cs, "a1"); - Assert.assertEquals("a1", app.getQueue().getQueueName()); + Assertions.assertEquals("a1", app.getQueue().getQueueName()); } @Test @@ -211,7 +210,7 @@ public void testKillAllAppsInQueue() throws Exception { String queue = scheduler.getApplicationAttempt(appsInA1.get(0)).getQueue() .getQueueName(); - Assert.assertEquals("a1", queue); + Assertions.assertEquals("a1", queue); List appsInRoot = scheduler.getAppsInQueue("root"); assertTrue(appsInRoot.contains(appAttemptId)); @@ -258,7 +257,7 @@ public void testKillAllAppsInvalidSource() throws Exception { // now kill the app try { scheduler.killAllAppsInQueue("DOES_NOT_EXIST"); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { // expected } @@ -280,7 +279,8 @@ public void testKillAllAppsInvalidSource() throws Exception { // Test to ensure that we don't carry out reservation on nodes // that have no CPU available when using the DominantResourceCalculator - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAppReservationWithDominantResourceCalculator() throws Exception { CapacitySchedulerConfiguration csconf = new CapacitySchedulerConfiguration(); @@ -309,8 +309,8 @@ public void testAppReservationWithDominantResourceCalculator() throws Exception rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); // check node report - Assert.assertEquals(1 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(9 * GB, reportNm1.getAvailableResource().getMemorySize()); + Assertions.assertEquals(1 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(9 * GB, reportNm1.getAvailableResource().getMemorySize()); // add request for containers am1.addRequests(new String[]{"127.0.0.1", "127.0.0.2"}, 1 * GB, 1, 1); @@ -323,8 +323,8 @@ public void testAppReservationWithDominantResourceCalculator() throws Exception ApplicationResourceUsageReport report = rm.getResourceScheduler().getAppResourceUsageReport( attempt1.getAppAttemptId()); - Assert.assertEquals(0, allocResponse.getAllocatedContainers().size()); - Assert.assertEquals(0, report.getNumReservedContainers()); + Assertions.assertEquals(0, allocResponse.getAllocatedContainers().size()); + Assertions.assertEquals(0, report.getNumReservedContainers()); // container should get allocated on this node nm2.nodeHeartbeat(true); @@ -336,8 +336,8 @@ public void testAppReservationWithDominantResourceCalculator() throws Exception report = rm.getResourceScheduler().getAppResourceUsageReport( attempt1.getAppAttemptId()); - Assert.assertEquals(1, allocResponse.getAllocatedContainers().size()); - Assert.assertEquals(0, report.getNumReservedContainers()); + Assertions.assertEquals(1, allocResponse.getAllocatedContainers().size()); + Assertions.assertEquals(0, report.getNumReservedContainers()); rm.stop(); } @@ -347,7 +347,7 @@ public void testMoveAppAmbiguousQueue() throws Exception { AbstractYarnScheduler scheduler = (AbstractYarnScheduler) rm.getResourceScheduler(); QueueMetrics metrics = scheduler.getRootQueueMetrics(); - Assert.assertEquals(0, metrics.getAppsPending()); + Assertions.assertEquals(0, metrics.getAppsPending()); // submit an app MockRMAppSubmissionData data = MockRMAppSubmissionData.Builder.createWithMemory(GB, rm) @@ -364,7 +364,7 @@ public void testMoveAppAmbiguousQueue() throws Exception { String queue = scheduler.getApplicationAttempt(appsInA.get(0)).getQueue() .getQueueName(); - Assert.assertEquals("a", queue); + Assertions.assertEquals("a", queue); // now move the app scheduler.moveApplication(app.getApplicationId(), "a1"); @@ -373,7 +373,7 @@ public void testMoveAppAmbiguousQueue() throws Exception { queue = scheduler.getApplicationAttempt(appsInA1.get(0)).getQueue() .getQueueName(); - Assert.assertEquals("a1", queue); + Assertions.assertEquals("a1", queue); appsInA = scheduler.getAppsInQueue("root.a.a"); assertTrue(appsInA.isEmpty()); @@ -387,7 +387,7 @@ public void testMoveAppBasic() throws Exception { AbstractYarnScheduler scheduler = (AbstractYarnScheduler) rm.getResourceScheduler(); QueueMetrics metrics = scheduler.getRootQueueMetrics(); - Assert.assertEquals(0, metrics.getAppsPending()); + Assertions.assertEquals(0, metrics.getAppsPending()); // submit an app MockRMAppSubmissionData data = MockRMAppSubmissionData.Builder.createWithMemory(GB, rm) @@ -407,7 +407,7 @@ public void testMoveAppBasic() throws Exception { String queue = scheduler.getApplicationAttempt(appsInA1.get(0)).getQueue() .getQueueName(); - Assert.assertEquals("a1", queue); + Assertions.assertEquals("a1", queue); List appsInA = scheduler.getAppsInQueue("a"); assertTrue(appsInA.contains(appAttemptId)); @@ -434,7 +434,7 @@ public void testMoveAppBasic() throws Exception { queue = scheduler.getApplicationAttempt(appsInB1.get(0)).getQueue() .getQueueName(); - Assert.assertEquals("b1", queue); + Assertions.assertEquals("b1", queue); appsInB = scheduler.getAppsInQueue("b"); assertTrue(appsInB.contains(appAttemptId)); @@ -562,7 +562,7 @@ private void assertApps(ResourceScheduler scheduler, private void assertOneAppInQueue(AbstractYarnScheduler scheduler, String queueName) { List apps = scheduler.getAppsInQueue(queueName); assertEquals(1, apps.size()); - Assert.assertEquals(queueName, + Assertions.assertEquals(queueName, scheduler.getApplicationAttempt(apps.get(0)).getQueue().getQueueName()); } @@ -780,82 +780,83 @@ public void testMoveAppSuccess() throws Exception { } - @Test(expected = YarnException.class) + @Test public void testMoveAppViolateQueueState() throws Exception { - resourceManager = new ResourceManager() { - @Override - protected RMNodeLabelsManager createNodeLabelManager() { - RMNodeLabelsManager mgr = new NullRMNodeLabelsManager(); - mgr.init(getConfig()); - return mgr; - } - }; - CapacitySchedulerConfiguration csConf = - new CapacitySchedulerConfiguration(); - setupQueueConfiguration(csConf); - StringBuilder qState = new StringBuilder(); - qState.append(CapacitySchedulerConfiguration.PREFIX).append(B) - .append(CapacitySchedulerConfiguration.DOT) - .append(CapacitySchedulerConfiguration.STATE); - csConf.set(qState.toString(), QueueState.STOPPED.name()); - YarnConfiguration conf = new YarnConfiguration(csConf); - conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, - ResourceScheduler.class); - resourceManager.init(conf); - resourceManager.getRMContext().getContainerTokenSecretManager() - .rollMasterKey(); - resourceManager.getRMContext().getNMTokenSecretManager().rollMasterKey(); - ((AsyncDispatcher) resourceManager.getRMContext().getDispatcher()).start(); - mockContext = mock(RMContext.class); - when(mockContext.getConfigurationProvider()).thenReturn( - new LocalConfigurationProvider()); - - ResourceScheduler scheduler = resourceManager.getResourceScheduler(); - - NodeStatus mockNodeStatus = createMockNodeStatus(); - - // Register node1 - String host0 = "host_0"; - NodeManager nm0 = - registerNode(resourceManager, host0, 1234, 2345, NetworkTopology.DEFAULT_RACK, - Resources.createResource(6 * GB, 1), mockNodeStatus); - - // ResourceRequest priorities - Priority priority0 = Priority.newInstance(0); - Priority priority1 = Priority.newInstance(1); - - // Submit application_0 - Application application0 = - new Application("user_0", "a1", resourceManager); - application0.submit(); // app + app attempt event sent to scheduler - - application0.addNodeManager(host0, 1234, nm0); - - Resource capability00 = Resources.createResource(3 * GB, 1); - application0.addResourceRequestSpec(priority1, capability00); - - Resource capability01 = Resources.createResource(2 * GB, 1); - application0.addResourceRequestSpec(priority0, capability01); - - Task task00 = - new Task(application0, priority1, new String[]{host0}); - application0.addTask(task00); - - // Send resource requests to the scheduler - application0.schedule(); // allocate - - // task_0_0 allocated - nodeUpdate(resourceManager, nm0); - - // Get allocations from the scheduler - application0.schedule(); // task_0_0 - checkApplicationResourceUsage(3 * GB, application0); - - checkNodeResourceUsage(3 * GB, nm0); - // b2 queue contains 3GB consumption app, - // add another 3GB will hit max capacity limit on queue b - scheduler.moveApplication(application0.getApplicationId(), "b1"); - + assertThrows(YarnException.class, ()->{ + resourceManager = new ResourceManager() { + @Override + protected RMNodeLabelsManager createNodeLabelManager() { + RMNodeLabelsManager mgr = new NullRMNodeLabelsManager(); + mgr.init(getConfig()); + return mgr; + } + }; + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + setupQueueConfiguration(csConf); + StringBuilder qState = new StringBuilder(); + qState.append(CapacitySchedulerConfiguration.PREFIX).append(B) + .append(CapacitySchedulerConfiguration.DOT) + .append(CapacitySchedulerConfiguration.STATE); + csConf.set(qState.toString(), QueueState.STOPPED.name()); + YarnConfiguration conf = new YarnConfiguration(csConf); + conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, + ResourceScheduler.class); + resourceManager.init(conf); + resourceManager.getRMContext().getContainerTokenSecretManager() + .rollMasterKey(); + resourceManager.getRMContext().getNMTokenSecretManager().rollMasterKey(); + ((AsyncDispatcher) resourceManager.getRMContext().getDispatcher()).start(); + mockContext = mock(RMContext.class); + when(mockContext.getConfigurationProvider()).thenReturn( + new LocalConfigurationProvider()); + + ResourceScheduler scheduler = resourceManager.getResourceScheduler(); + + NodeStatus mockNodeStatus = createMockNodeStatus(); + + // Register node1 + String host0 = "host_0"; + NodeManager nm0 = + registerNode(resourceManager, host0, 1234, 2345, NetworkTopology.DEFAULT_RACK, + Resources.createResource(6 * GB, 1), mockNodeStatus); + + // ResourceRequest priorities + Priority priority0 = Priority.newInstance(0); + Priority priority1 = Priority.newInstance(1); + + // Submit application_0 + Application application0 = + new Application("user_0", "a1", resourceManager); + application0.submit(); // app + app attempt event sent to scheduler + + application0.addNodeManager(host0, 1234, nm0); + + Resource capability00 = Resources.createResource(3 * GB, 1); + application0.addResourceRequestSpec(priority1, capability00); + + Resource capability01 = Resources.createResource(2 * GB, 1); + application0.addResourceRequestSpec(priority0, capability01); + + Task task00 = + new Task(application0, priority1, new String[]{host0}); + application0.addTask(task00); + + // Send resource requests to the scheduler + application0.schedule(); // allocate + + // task_0_0 allocated + nodeUpdate(resourceManager, nm0); + + // Get allocations from the scheduler + application0.schedule(); // task_0_0 + checkApplicationResourceUsage(3 * GB, application0); + + checkNodeResourceUsage(3 * GB, nm0); + // b2 queue contains 3GB consumption app, + // add another 3GB will hit max capacity limit on queue b + scheduler.moveApplication(application0.getApplicationId(), "b1"); + }); } @Test @@ -1064,10 +1065,10 @@ public void testMaxParallelAppsPendingQueueMetrics() throws Exception { RMAppAttemptState.FINISHED, true)); } - Assert.assertEquals("No pending app should remain for root queue", 0, - cs.getRootQueueMetrics().getAppsPending()); - Assert.assertEquals("No running application should remain for root queue", 0, - cs.getRootQueueMetrics().getAppsRunning()); + Assertions.assertEquals(0 +, cs.getRootQueueMetrics().getAppsPending(), "No pending app should remain for root queue"); + Assertions.assertEquals(0 +, cs.getRootQueueMetrics().getAppsRunning(), "No running application should remain for root queue"); rm.stop(); } @@ -1105,7 +1106,7 @@ public void testMoveAllAppsInvalidDestination() throws Exception { // now move the app try { scheduler.moveAllApps("a1", "DOES_NOT_EXIST"); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { // expected } @@ -1149,7 +1150,7 @@ public void testMoveAllAppsInvalidSource() throws Exception { // now move the app try { scheduler.moveAllApps("DOES_NOT_EXIST", "b1"); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { // expected } @@ -1315,7 +1316,8 @@ public void testMoveAppWithActiveUsersWithOnlyPendingApps() throws Exception { rm.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testMoveAttemptNotAdded() throws Exception { Configuration conf = new Configuration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -1363,11 +1365,11 @@ public void testMoveAttemptNotAdded() throws Exception { CSQueue queueA = cs.getQueue("a"); CSQueue queueA1 = cs.getQueue("a1"); CSQueue queueB1 = cs.getQueue("b1"); - Assert.assertEquals(1, rootQ.getNumApplications()); - Assert.assertEquals(0, queueA.getNumApplications()); - Assert.assertEquals(1, queueB.getNumApplications()); - Assert.assertEquals(0, queueA1.getNumApplications()); - Assert.assertEquals(1, queueB1.getNumApplications()); + Assertions.assertEquals(1, rootQ.getNumApplications()); + Assertions.assertEquals(0, queueA.getNumApplications()); + Assertions.assertEquals(1, queueB.getNumApplications()); + Assertions.assertEquals(0, queueA1.getNumApplications()); + Assertions.assertEquals(1, queueB1.getNumApplications()); rm.close(); } @@ -1421,9 +1423,9 @@ public void testRemoveAttemptMoveAdded() throws Exception { // Move application to queue b1 sch.moveApplication(appAttemptId.getApplicationId(), "b1"); // Check queue metrics after move - Assert.assertEquals(0, queueA1.getNumApplications()); - Assert.assertEquals(1, queueB.getNumApplications()); - Assert.assertEquals(0, queueB1.getNumApplications()); + Assertions.assertEquals(0, queueA1.getNumApplications()); + Assertions.assertEquals(1, queueB.getNumApplications()); + Assertions.assertEquals(0, queueB1.getNumApplications()); // Release attempt add event ApplicationAttemptId appAttemptId2 = @@ -1433,27 +1435,27 @@ public void testRemoveAttemptMoveAdded() throws Exception { sch.handle(addAttemptEvent2); // Check metrics after attempt added - Assert.assertEquals(0, queueA1.getNumApplications()); - Assert.assertEquals(1, queueB.getNumApplications()); - Assert.assertEquals(1, queueB1.getNumApplications()); + Assertions.assertEquals(0, queueA1.getNumApplications()); + Assertions.assertEquals(1, queueB.getNumApplications()); + Assertions.assertEquals(1, queueB1.getNumApplications()); QueueMetrics queueB1M = queueB1.getMetrics(); QueueMetrics queueBM = queueB.getMetrics(); // Verify allocation MB of current state - Assert.assertEquals(0, queueA1M.getAllocatedMB()); - Assert.assertEquals(0, queueA1M.getAllocatedVirtualCores()); - Assert.assertEquals(1024, queueB1M.getAllocatedMB()); - Assert.assertEquals(1, queueB1M.getAllocatedVirtualCores()); + Assertions.assertEquals(0, queueA1M.getAllocatedMB()); + Assertions.assertEquals(0, queueA1M.getAllocatedVirtualCores()); + Assertions.assertEquals(1024, queueB1M.getAllocatedMB()); + Assertions.assertEquals(1, queueB1M.getAllocatedVirtualCores()); // remove attempt sch.handle(new AppAttemptRemovedSchedulerEvent(appAttemptId2, RMAppAttemptState.FINISHED, false)); - Assert.assertEquals(0, queueA1M.getAllocatedMB()); - Assert.assertEquals(0, queueA1M.getAllocatedVirtualCores()); - Assert.assertEquals(0, queueB1M.getAllocatedMB()); - Assert.assertEquals(0, queueB1M.getAllocatedVirtualCores()); + Assertions.assertEquals(0, queueA1M.getAllocatedMB()); + Assertions.assertEquals(0, queueA1M.getAllocatedVirtualCores()); + Assertions.assertEquals(0, queueB1M.getAllocatedMB()); + Assertions.assertEquals(0, queueB1M.getAllocatedVirtualCores()); verifyQueueMetrics(queueB1M); verifyQueueMetrics(queueBM); @@ -1475,16 +1477,16 @@ public void testAppSubmission() throws Exception { rm.start(); RMApp noParentQueueApp = submitAppAndWaitForState(rm, "q", RMAppState.FAILED); - Assert.assertEquals(RMAppState.FAILED, noParentQueueApp.getState()); + Assertions.assertEquals(RMAppState.FAILED, noParentQueueApp.getState()); RMApp ambiguousQueueApp = submitAppAndWaitForState(rm, "b", RMAppState.FAILED); - Assert.assertEquals(RMAppState.FAILED, ambiguousQueueApp.getState()); + Assertions.assertEquals(RMAppState.FAILED, ambiguousQueueApp.getState()); RMApp emptyPartQueueApp = submitAppAndWaitForState(rm, "root..a1", RMAppState.FAILED); - Assert.assertEquals(RMAppState.FAILED, emptyPartQueueApp.getState()); + Assertions.assertEquals(RMAppState.FAILED, emptyPartQueueApp.getState()); RMApp failedAutoQueue = submitAppAndWaitForState(rm, "root.a.b.c.d", RMAppState.FAILED); - Assert.assertEquals(RMAppState.FAILED, failedAutoQueue.getState()); + Assertions.assertEquals(RMAppState.FAILED, failedAutoQueue.getState()); } private RMApp submitAppAndWaitForState(MockRM rm, String b, RMAppState state) throws Exception { @@ -1531,13 +1533,13 @@ private CapacitySchedulerQueueInfo getQueueInfo(String name, } private void verifyQueueMetrics(QueueMetrics queue) { - Assert.assertEquals(0, queue.getPendingMB()); - Assert.assertEquals(0, queue.getActiveUsers()); - Assert.assertEquals(0, queue.getActiveApps()); - Assert.assertEquals(0, queue.getAppsPending()); - Assert.assertEquals(0, queue.getAppsRunning()); - Assert.assertEquals(0, queue.getAllocatedMB()); - Assert.assertEquals(0, queue.getAllocatedVirtualCores()); + Assertions.assertEquals(0, queue.getPendingMB()); + Assertions.assertEquals(0, queue.getActiveUsers()); + Assertions.assertEquals(0, queue.getActiveApps()); + Assertions.assertEquals(0, queue.getAppsPending()); + Assertions.assertEquals(0, queue.getAppsRunning()); + Assertions.assertEquals(0, queue.getAllocatedMB()); + Assertions.assertEquals(0, queue.getAllocatedVirtualCores()); } private Configuration getCapacityConfiguration(Configuration config) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java index 8f7f6660a0c39..cecc3ae9ef0ec 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java @@ -65,9 +65,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.SimpleCandidateNodeSet; import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey; 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; import org.junit.contrib.java.lang.system.internal.NoExitSecurityManager; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -91,7 +92,7 @@ public class TestCapacitySchedulerAsyncScheduling { "org.apache.hadoop.yarn.server.resourcemanager.scheduler" + ".placement.ResourceUsageMultiNodeLookupPolicy"; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -102,22 +103,26 @@ public void setUp() throws Exception { mgr.init(conf); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testSingleThreadAsyncContainerAllocation() throws Exception { testAsyncContainerAllocation(1); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testTwoThreadsAsyncContainerAllocation() throws Exception { testAsyncContainerAllocation(2); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testThreeThreadsAsyncContainerAllocation() throws Exception { testAsyncContainerAllocation(3); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testAsyncContainerAllocationWithMultiNode() throws Exception { conf.set(CapacitySchedulerConfiguration.MULTI_NODE_SORTING_POLICIES, "resource-based"); @@ -132,7 +137,8 @@ public void testAsyncContainerAllocationWithMultiNode() throws Exception { testAsyncContainerAllocation(2); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testAsyncThreadNames() throws Exception { conf.setInt( CapacitySchedulerConfiguration.SCHEDULE_ASYNCHRONOUSLY_MAXIMUM_THREAD, @@ -156,7 +162,7 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); for (CapacityScheduler.AsyncScheduleThread thread : cs.getAsyncSchedulerThreads()) { - Assert.assertTrue(thread.getName() + Assertions.assertTrue(thread.getName() .startsWith("AsyncCapacitySchedulerThread")); } } @@ -228,7 +234,7 @@ public RMNodeLabelsManager createNodeLabelManager() { waitTime -= 50; } - Assert.assertEquals( + Assertions.assertEquals( rm.getResourceScheduler().getRootQueueMetrics().getAllocatedMB(), totalAsked); @@ -236,7 +242,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // required waitTime = 2000; // ms while (waitTime > 0) { - Assert.assertEquals( + Assertions.assertEquals( rm.getResourceScheduler().getRootQueueMetrics().getAllocatedMB(), totalAsked); waitTime -= 50; @@ -247,7 +253,8 @@ public RMNodeLabelsManager createNodeLabelManager() { } // Testcase for YARN-6714 - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testCommitProposalForFailedAppAttempt() throws Exception { // disable async-scheduling for simulating complex since scene @@ -270,7 +277,7 @@ public void testCommitProposalForFailedAppAttempt() .nodeCount() < 2) { Thread.sleep(10); } - Assert.assertEquals(2, + Assertions.assertEquals(2, ((AbstractYarnScheduler) rm.getRMContext().getScheduler()) .getNodeTracker().nodeCount()); CapacityScheduler scheduler = @@ -303,8 +310,8 @@ public void testCommitProposalForFailedAppAttempt() // nm1 runs 1 container(app1-container_01/AM) // nm2 runs 1 container(app1-container_02) - Assert.assertEquals(1, sn1.getNumContainers()); - Assert.assertEquals(1, sn2.getNumContainers()); + Assertions.assertEquals(1, sn1.getNumContainers()); + Assertions.assertEquals(1, sn2.getNumContainers()); // kill app attempt1 scheduler.handle( @@ -345,14 +352,15 @@ public void testCommitProposalForFailedAppAttempt() ResourceCommitRequest request = new ResourceCommitRequest(null, reservedProposals, null); scheduler.tryCommit(scheduler.getClusterResource(), request, true); - Assert.assertNull("Outdated proposal should not be accepted!", - sn2.getReservedContainer()); + Assertions.assertNull( + sn2.getReservedContainer(), "Outdated proposal should not be accepted!"); rm.stop(); } // Testcase for YARN-6678 - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testCommitOutdatedReservedProposal() throws Exception { // disable async-scheduling for simulating complex since scene Configuration disableAsyncConf = new Configuration(conf); @@ -373,7 +381,7 @@ public void testCommitOutdatedReservedProposal() throws Exception { waitTime -= 10; Thread.sleep(10); } - Assert.assertEquals(2, + Assertions.assertEquals(2, ((AbstractYarnScheduler) rm.getRMContext().getScheduler()) .getNodeTracker().nodeCount()); @@ -415,8 +423,8 @@ public void testCommitOutdatedReservedProposal() throws Exception { // nm1 runs 3 containers(app1-container_01/AM, app1-container_02, // app2-container_01/AM) // nm2 runs 1 container(app1-container_03) - Assert.assertEquals(3, sn1.getNumContainers()); - Assert.assertEquals(1, sn2.getNumContainers()); + Assertions.assertEquals(3, sn1.getNumContainers()); + Assertions.assertEquals(1, sn2.getNumContainers()); // reserve 1 container(app1-container_04) for app1 on nm1 ResourceRequest rr2 = ResourceRequest @@ -430,7 +438,7 @@ public void testCommitOutdatedReservedProposal() throws Exception { waitTime -= 10; Thread.sleep(10); } - Assert.assertNotNull(sn1.getReservedContainer()); + Assertions.assertNotNull(sn1.getReservedContainer()); final CapacityScheduler cs = (CapacityScheduler) scheduler; final CapacityScheduler spyCs = Mockito.spy(cs); @@ -452,7 +460,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { ContainerState.COMPLETE, "", ContainerExitStatus.KILLED_BY_RESOURCEMANAGER), RMContainerEventType.KILL); - Assert.assertEquals(0, sn2.getCopiedListOfRunningContainers().size()); + Assertions.assertEquals(0, sn2.getCopiedListOfRunningContainers().size()); // unreserve app1-container_04 on nm1 // and allocate app1-container_05 on nm2 cs.handle(new NodeUpdateSchedulerEvent(sn2.getRMNode())); @@ -462,8 +470,8 @@ public Object answer(InvocationOnMock invocation) throws Exception { waitTime -= 10; Thread.sleep(10); } - Assert.assertEquals(1, sn2.getCopiedListOfRunningContainers().size()); - Assert.assertNull(sn1.getReservedContainer()); + Assertions.assertEquals(1, sn2.getCopiedListOfRunningContainers().size()); + Assertions.assertNull(sn1.getReservedContainer()); // reserve app2-container_02 on nm1 ResourceRequest rr3 = ResourceRequest @@ -476,7 +484,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { waitTime -= 10; Thread.sleep(10); } - Assert.assertNotNull(sn1.getReservedContainer()); + Assertions.assertNotNull(sn1.getReservedContainer()); // call real apply try { @@ -484,7 +492,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { (ResourceCommitRequest) invocation.getArguments()[1], true); } catch (Exception e) { e.printStackTrace(); - Assert.fail(); + Assertions.fail(); } isChecked.set(true); } else { @@ -506,7 +514,8 @@ public Object answer(InvocationOnMock invocation) throws Exception { rm.stop(); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testNodeResourceOverAllocated() throws Exception { // disable async-scheduling for simulating complex scene @@ -529,7 +538,7 @@ public void testNodeResourceOverAllocated() .nodeCount() < 2) { Thread.sleep(10); } - Assert.assertEquals(2, + Assertions.assertEquals(2, ((AbstractYarnScheduler) rm.getRMContext().getScheduler()) .getNodeTracker().nodeCount()); CapacityScheduler scheduler = @@ -584,8 +593,8 @@ public void testNodeResourceOverAllocated() scheduler.tryCommit(scheduler.getClusterResource(), request, true); } // make sure node resource can't be over-allocated! - Assert.assertTrue("Node resource is Over-allocated!", - sn1.getUnallocatedResource().getMemorySize() > 0); + Assertions.assertTrue( + sn1.getUnallocatedResource().getMemorySize() > 0, "Node resource is Over-allocated!"); rm.stop(); } @@ -666,9 +675,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // Make sure that NM5-9 don't have non-AM containers. for (int i = 0; i < 9; i++) { if (i < 5) { - Assert.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) > 0); + Assertions.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) > 0); } else { - Assert.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) == 0); + Assertions.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) == 0); } } @@ -741,12 +750,12 @@ public RMNodeLabelsManager createNodeLabelManager() { new RMNodeEvent(rmNode.getNodeID(), RMNodeEventType.GRACEFUL_DECOMMISSION)); rm.drainEvents(); - Assert.assertEquals(NodeState.DECOMMISSIONING, rmNode.getState()); + Assertions.assertEquals(NodeState.DECOMMISSIONING, rmNode.getState()); boolean shouldSkip = cs.shouldSkipNodeSchedule(cs.getNode(nms.get(i).getNodeId()), cs, true); // make sure should skip - Assert.assertTrue(shouldSkip); + Assertions.assertTrue(shouldSkip); } for (int i = 5; i < 9; i++) { @@ -754,7 +763,7 @@ public RMNodeLabelsManager createNodeLabelManager() { cs.shouldSkipNodeSchedule(cs.getNode(nms.get(i).getNodeId()), cs, true); // make sure should not skip - Assert.assertFalse(shouldSkip); + Assertions.assertFalse(shouldSkip); } pauseNMHeartbeat(); @@ -773,9 +782,9 @@ public RMNodeLabelsManager createNodeLabelManager() { //Make sure that NM 0-5 don't have non-AM containers. for (int i = 0; i < 9; i++) { if (i < 5) { - Assert.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) == 0); + Assertions.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) == 0); } else { - Assert.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) > 0); + Assertions.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) > 0); } } rm.close(); @@ -817,7 +826,8 @@ public void setShouldStop() { } // Testcase for YARN-8127 - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testCommitDuplicatedAllocateFromReservedProposals() throws Exception { // disable async-scheduling for simulating complex scene @@ -837,7 +847,7 @@ public void testCommitDuplicatedAllocateFromReservedProposals() .nodeCount() < 2) { Thread.sleep(10); } - Assert.assertEquals(2, + Assertions.assertEquals(2, ((AbstractYarnScheduler) rm.getRMContext().getScheduler()) .getNodeTracker().nodeCount()); CapacityScheduler cs = @@ -867,8 +877,8 @@ public void testCommitDuplicatedAllocateFromReservedProposals() // nm1 runs 2 container(container_01/AM, container_02) allocateAndLaunchContainers(am, nm1, rm, 1, Resources.createResource(6 * GB), 0, 2); - Assert.assertEquals(2, sn1.getNumContainers()); - Assert.assertEquals(1 * GB, sn1.getUnallocatedResource().getMemorySize()); + Assertions.assertEquals(2, sn1.getNumContainers()); + Assertions.assertEquals(1 * GB, sn1.getUnallocatedResource().getMemorySize()); // app asks 5 * 2G container // nm1 reserves 1 * 2G containers @@ -876,7 +886,7 @@ public void testCommitDuplicatedAllocateFromReservedProposals() .newInstance(Priority.newInstance(0), "*", Resources.createResource(2 * GB), 5)), null); cs.handle(new NodeUpdateSchedulerEvent(sn1.getRMNode())); - Assert.assertEquals(1, schedulerApp.getReservedContainers().size()); + Assertions.assertEquals(1, schedulerApp.getReservedContainers().size()); // rm kills 1 * 6G container_02 for (RMContainer rmContainer : sn1.getCopiedListOfRunningContainers()) { @@ -888,7 +898,7 @@ public void testCommitDuplicatedAllocateFromReservedProposals() RMContainerEventType.KILL); } } - Assert.assertEquals(7 * GB, sn1.getUnallocatedResource().getMemorySize()); + Assertions.assertEquals(7 * GB, sn1.getUnallocatedResource().getMemorySize()); final CapacityScheduler spyCs = Mockito.spy(cs); // handle CapacityScheduler#tryCommit, submit duplicated proposals @@ -905,8 +915,8 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { (ResourceCommitRequest) invocation.getArguments()[1], (Boolean) invocation.getArguments()[2]); } - Assert.assertEquals(2, sn1.getCopiedListOfRunningContainers().size()); - Assert.assertEquals(5 * GB, + Assertions.assertEquals(2, sn1.getCopiedListOfRunningContainers().size()); + Assertions.assertEquals(5 * GB, sn1.getUnallocatedResource().getMemorySize()); } return true; @@ -920,7 +930,8 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testReleaseOutdatedReservedContainer() throws Exception { /* * Submit a application, reserved container_02 on nm1, @@ -966,8 +977,8 @@ public void testReleaseOutdatedReservedContainer() throws Exception { cs.getApplicationAttempt(am1.getApplicationAttemptId()); cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); - Assert.assertEquals(9 * GB, + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(9 * GB, defaultQueue.getQueueResourceUsage().getUsed().getMemorySize()); RMContainer reservedContainer = @@ -977,19 +988,20 @@ public void testReleaseOutdatedReservedContainer() throws Exception { sn2, sn1, cs.getRMContext(), reservedContainer); boolean tryCommitResult = cs.tryCommit(cs.getClusterResource(), allocateFromSameReservedContainerProposal1, true); - Assert.assertTrue(tryCommitResult); + Assertions.assertTrue(tryCommitResult); ResourceCommitRequest allocateFromSameReservedContainerProposal2 = createAllocateFromReservedProposal(4, allocateResource, schedulerApp1, sn3, sn1, cs.getRMContext(), reservedContainer); tryCommitResult = cs.tryCommit(cs.getClusterResource(), allocateFromSameReservedContainerProposal2, true); - Assert.assertFalse("This proposal should be rejected because " - + "it try to release an outdated reserved container", tryCommitResult); + Assertions.assertFalse(tryCommitResult, "This proposal should be rejected because " + + "it try to release an outdated reserved container"); rm1.close(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testCommitProposalsForUnusableNode() throws Exception { // disable async-scheduling for simulating complex scene Configuration disableAsyncConf = new Configuration(conf); @@ -1066,19 +1078,20 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { cs.getRMContext().getDispatcher().getEventHandler().handle( new RMNodeEvent(nm1.getNodeId(), RMNodeEventType.DECOMMISSION)); rm.drainEvents(); - Assert.assertEquals(NodeState.DECOMMISSIONED, rmNode1.getState()); - Assert.assertNull(cs.getNode(nm1.getNodeId())); + Assertions.assertEquals(NodeState.DECOMMISSIONED, rmNode1.getState()); + Assertions.assertNull(cs.getNode(nm1.getNodeId())); // try commit after nm1 decommissioned boolean isSuccess = cs.tryCommit((Resource) reservedProposalParts.get(0), (ResourceCommitRequest) reservedProposalParts.get(1), (Boolean) reservedProposalParts.get(2)); - Assert.assertFalse(isSuccess); + Assertions.assertFalse(isSuccess); rm.stop(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAsyncScheduleThreadExit() throws Exception { // init RM & NM final MockRM rm = new MockRM(conf); @@ -1138,7 +1151,8 @@ private ResourceCommitRequest createAllocateFromReservedProposal( return new ResourceCommitRequest(allocateProposals, null, null); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testReturnNullWhenGetSchedulerContainer() throws Exception { // disable async-scheduling for simulating complex scenario Configuration disableAsyncConf = new Configuration(conf); @@ -1192,8 +1206,8 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { cs.getRMContext().getDispatcher().getEventHandler().handle( new RMNodeEvent(nm1.getNodeId(), RMNodeEventType.DECOMMISSION)); rm.drainEvents(); - Assert.assertEquals(NodeState.DECOMMISSIONED, rmNode1.getState()); - Assert.assertNull(cs.getNode(nm1.getNodeId())); + Assertions.assertEquals(NodeState.DECOMMISSIONED, rmNode1.getState()); + Assertions.assertNull(cs.getNode(nm1.getNodeId())); assignmentSnapshots.add(assignment); } else { // add am container on nm1 to containersToKill @@ -1213,7 +1227,7 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { new SimpleCandidateNodeSet(sn1); spyCs.allocateContainersToNode(candidateNodeSet, false); // make sure unconfirmed resource is decreased correctly - Assert.assertTrue(spyCs.getApplicationAttempt(am1.getApplicationAttemptId()) + Assertions.assertTrue(spyCs.getApplicationAttempt(am1.getApplicationAttemptId()) .hasPendingResourceRequest(RMNodeLabelsManager.NO_LABEL, SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY)); @@ -1223,7 +1237,7 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { new SimpleCandidateNodeSet(sn2); spyCs.allocateContainersToNode(candidateNodeSet, false); // make sure unconfirmed resource is decreased correctly - Assert.assertTrue(spyCs.getApplicationAttempt(am1.getApplicationAttemptId()) + Assertions.assertTrue(spyCs.getApplicationAttempt(am1.getApplicationAttemptId()) .hasPendingResourceRequest(RMNodeLabelsManager.NO_LABEL, SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY)); @@ -1266,7 +1280,7 @@ private void allocateAndLaunchContainers(MockAM am, MockNM nm, MockRM rm, ContainerId lastContainerId = ContainerId .newContainerId(am.getApplicationAttemptId(), startContainerId + nContainer - 1); - Assert.assertTrue( + Assertions.assertTrue( rm.waitForState(nm, lastContainerId, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am.allocate(null, null); @@ -1281,7 +1295,7 @@ private void allocateAndLaunchContainers(MockAM am, MockNM nm, MockRM rm, rmContainer.handle( new RMContainerEvent(containerId, RMContainerEventType.LAUNCHED)); } else { - Assert.fail("Cannot find RMContainer"); + Assertions.fail("Cannot find RMContainer"); } rm.waitForState(nm, ContainerId.newContainerId(am.getApplicationAttemptId(), cId), diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueueBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueueBase.java index e03e59d2512c8..f2ec1ed0b3224 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueueBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueueBase.java @@ -72,9 +72,9 @@ import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.YarnVersionInfo; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.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 java.io.IOException; import java.util.ArrayList; @@ -96,10 +96,10 @@ .capacity.CapacitySchedulerConfiguration.DOT; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler .capacity.CapacitySchedulerConfiguration.FAIR_APP_ORDERING_POLICY; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestCapacitySchedulerAutoCreatedQueueBase { @@ -226,7 +226,7 @@ void spyOnNextEvent(Event expectedEvent, long timeout) } } - @Before + @BeforeEach public void setUp() throws Exception { QueueMetrics.clearQueueMetrics(); CapacitySchedulerConfiguration conf = setupSchedulerConfiguration(); @@ -521,7 +521,7 @@ public static void setupQueueConfigurationForSingleFlexibleAutoCreatedLeafQueue( conf.setAutoQueueCreationV2Enabled(C, true); } - @After + @AfterEach public void tearDown() throws Exception { if (mockRM != null) { mockRM.stop(); @@ -696,7 +696,7 @@ protected RMApp submitApp(String user, String queue, String nodeLabel) .withAmLabel(nodeLabel) .build(); RMApp app = MockRMAppSubmitter.submit(mockRM, data); - Assert.assertEquals(app.getAmNodeLabelExpression(), nodeLabel); + Assertions.assertEquals(app.getAmNodeLabelExpression(), nodeLabel); // check preconditions List appsInC = cs.getAppsInQueue(PARENT_QUEUE); assertEquals(1, appsInC.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/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueuePreemption.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueuePreemption.java index 09724b7d8d6ce..93b6c0e137028 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueuePreemption.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueuePreemption.java @@ -17,8 +17,9 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler .capacity.TestCapacitySchedulerAutoCreatedQueueBase.C; @@ -47,7 +48,7 @@ public class TestCapacitySchedulerAutoCreatedQueuePreemption extends TestCapacitySchedulerSurgicalPreemption { @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); } @@ -128,7 +129,8 @@ public void setUp() throws Exception { return conf; } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testSimpleSurgicalPreemptionOnAutoCreatedLeafQueues() throws Exception { /** @@ -162,7 +164,8 @@ public void testSimpleSurgicalPreemptionOnAutoCreatedLeafQueues() testSimpleSurgicalPreemption(USER1, USER2, USER1, USER2); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testPreemptionFromHighestPriorityManagedParentQueueAndOldestContainer() throws Exception { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoQueueCreation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoQueueCreation.java index f97d45d9d2b23..738d638acf51d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoQueueCreation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoQueueCreation.java @@ -73,8 +73,9 @@ .RMContainerTokenSecretManager; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,11 +91,11 @@ .NO_LABEL; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueueUtils.EPSILON; -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 static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -119,7 +120,8 @@ public class TestCapacitySchedulerAutoQueueCreation 4); - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testAutoCreateLeafQueueCreation() throws Exception { try { @@ -176,7 +178,8 @@ public void testAutoCreateLeafQueueCreation() throws Exception { } } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testAutoCreateLeafQueueCreationSchedulerMaximumAllocation() throws Exception { try { @@ -205,7 +208,8 @@ public void testAutoCreateLeafQueueCreationSchedulerMaximumAllocation() } } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testAutoCreateLeafQueueCreationUsingFullParentPath() throws Exception { @@ -429,7 +433,8 @@ public void testConvertFailsFromParentQueueToManagedParentQueue() } } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testAutoCreateLeafQueueFailsWithNoQueueMapping() throws Exception { @@ -450,7 +455,8 @@ public void testAutoCreateLeafQueueFailsWithNoQueueMapping() assertEquals(RMAppState.FAILED, app.getState()); } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testQueueMappingValidationFailsWithInvalidParentQueueInMapping() throws Exception { @@ -497,7 +503,8 @@ public void testQueueMappingValidationFailsWithInvalidParentQueueInMapping() } } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testQueueMappingUpdatesFailsOnRemovalOfParentQueueInMapping() throws Exception { @@ -654,18 +661,18 @@ public void testAutoQueueCreationWithWeightModeAndMaxAppLifetimeFirstSubmittedAp .build(); RMApp app1 = MockRMAppSubmitter.submit(newMockRM, app); - Assert.assertEquals(newCS.getMaximumApplicationLifetime("root.test.user"), 20L); + Assertions.assertEquals(newCS.getMaximumApplicationLifetime("root.test.user"), 20L); try { newMockRM.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); - Assert.assertEquals(RMAppState.KILLED, app1.getState()); - Assert.assertTrue("Application killed before default lifetime value", - totalTimeRun > (defaultRootLifetime * 1000)); - Assert.assertTrue( - "Application killed after max lifetime value " + totalTimeRun, - totalTimeRun < (maxRootLifetime * 1000)); + Assertions.assertEquals(RMAppState.KILLED, app1.getState()); + Assertions.assertTrue( + totalTimeRun > (defaultRootLifetime * 1000), "Application killed before default lifetime value"); + Assertions.assertTrue( + + totalTimeRun < (maxRootLifetime * 1000), "Application killed after max lifetime value " + totalTimeRun); } finally { ((CapacityScheduler) newMockRM.getResourceScheduler()).stop(); newMockRM.stop(); @@ -912,28 +919,28 @@ public void testClusterResourceUpdationOnAutoCreatedLeafQueues() throws Resource MIN_RES = Resources.createResource(14438, 6); - Assert.assertEquals("Effective Min resource for USER3 is not correct", - Resources.none(), user3LeafQueue.getQueueResourceQuotas() - .getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for USER3 is not correct", - MAX_RES, user3LeafQueue + Assertions.assertEquals( + Resources.none(), user3LeafQueue.getQueueResourceQuotas() + .getEffectiveMinResource(), "Effective Min resource for USER3 is not correct"); + Assertions.assertEquals( + MAX_RES, user3LeafQueue .getQueueResourceQuotas() - .getEffectiveMaxResource()); + .getEffectiveMaxResource(), "Effective Max resource for USER3 is not correct"); CSQueue user1LeafQueue = newCS.getQueue(USER1); CSQueue user2LeafQueue = newCS.getQueue(USER2); - Assert.assertEquals("Effective Min resource for USER2 is not correct", - MIN_RES, user1LeafQueue.getQueueResourceQuotas() - .getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for USER2 is not correct", - MAX_RES, user1LeafQueue.getQueueResourceQuotas().getEffectiveMaxResource()); - - Assert.assertEquals("Effective Min resource for USER1 is not correct", - MIN_RES, user2LeafQueue.getQueueResourceQuotas() - .getEffectiveMinResource()); - Assert.assertEquals("Effective Max resource for USER1 is not correct", - MAX_RES, user2LeafQueue.getQueueResourceQuotas() - .getEffectiveMaxResource()); + Assertions.assertEquals( + MIN_RES, user1LeafQueue.getQueueResourceQuotas() + .getEffectiveMinResource(), "Effective Min resource for USER2 is not correct"); + Assertions.assertEquals( + MAX_RES, user1LeafQueue.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for USER2 is not correct"); + + Assertions.assertEquals( + MIN_RES, user2LeafQueue.getQueueResourceQuotas() + .getEffectiveMinResource(), "Effective Min resource for USER1 is not correct"); + Assertions.assertEquals( + MAX_RES, user2LeafQueue.getQueueResourceQuotas() + .getEffectiveMaxResource(), "Effective Max resource for USER1 is not correct"); // unregister one NM. newMockRM.unRegisterNode(nm3); @@ -941,12 +948,12 @@ public void testClusterResourceUpdationOnAutoCreatedLeafQueues() throws Resource MAX_RES_UPDATED = Resources.createResource(128000, 20); // After loosing one NM, resources will reduce - Assert.assertEquals("Effective Min resource for USER2 is not correct", - MIN_RES_UPDATED, user1LeafQueue.getQueueResourceQuotas().getEffectiveMinResource - ()); - Assert.assertEquals("Effective Max resource for USER2 is not correct", - MAX_RES_UPDATED, user2LeafQueue.getQueueResourceQuotas() - .getEffectiveMaxResource()); + Assertions.assertEquals( + MIN_RES_UPDATED, user1LeafQueue.getQueueResourceQuotas().getEffectiveMinResource + (), "Effective Min resource for USER2 is not correct"); + Assertions.assertEquals( + MAX_RES_UPDATED, user2LeafQueue.getQueueResourceQuotas() + .getEffectiveMaxResource(), "Effective Max resource for USER2 is not correct"); } finally { cleanupQueue(USER1); @@ -1099,9 +1106,9 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) mockRM.getResourceScheduler(); CSQueue queue = cs.getQueue("root.a.testuser"); - assertNotNull("Leaf queue has not been auto-created", queue); - assertEquals("Number of running applications", 1, - queue.getNumApplications()); + assertNotNull(queue, "Leaf queue has not been auto-created"); + assertEquals(1 +, queue.getNumApplications(), "Number of running applications"); } finally { if (mockRM != null) { mockRM.close(); @@ -1109,7 +1116,8 @@ public RMNodeLabelsManager createNodeLabelManager() { } } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testAutoCreateLeafQueueFailsWithSpecifiedEmptyStringLeafQueue() throws Exception { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfigValidator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfigValidator.java index 8c9f518fcfbeb..b9ccb808e2a90 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfigValidator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfigValidator.java @@ -40,8 +40,8 @@ import org.apache.hadoop.yarn.util.YarnVersionInfo; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -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 java.io.IOException; @@ -49,7 +49,8 @@ import java.util.Map; import static org.apache.hadoop.yarn.api.records.ResourceInformation.GPU_URI; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; public class TestCapacitySchedulerConfigValidator { public static final int NODE_MEMORY = 16; @@ -117,32 +118,36 @@ public static void setupResources(boolean useGpu) { /** * Test for the case when the scheduler.minimum-allocation-mb == 0. */ - @Test (expected = YarnRuntimeException.class) + @Test public void testValidateMemoryAllocationInvalidMinMem() { - Map configs = new HashMap(); - configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, "0"); - Configuration config = CapacitySchedulerConfigGeneratorForTest - .createConfiguration(configs); - CapacitySchedulerConfigValidator.validateMemoryAllocation(config); - fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB + - " should be > 0"); + assertThrows(YarnRuntimeException.class, ()->{ + Map configs = new HashMap(); + configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, "0"); + Configuration config = CapacitySchedulerConfigGeneratorForTest + .createConfiguration(configs); + CapacitySchedulerConfigValidator.validateMemoryAllocation(config); + fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB + + " should be > 0"); + }); } /** * Test for the case when the scheduler.minimum-allocation-mb is greater than * scheduler.maximum-allocation-mb. */ - @Test (expected = YarnRuntimeException.class) + @Test public void testValidateMemoryAllocationHIgherMinThanMaxMem() { - Map configs = new HashMap(); - configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, "8192"); - configs.put(YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, "1024"); - Configuration config = CapacitySchedulerConfigGeneratorForTest - .createConfiguration(configs); - CapacitySchedulerConfigValidator.validateMemoryAllocation(config); - fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB + " should be > " - + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB); - + assertThrows(YarnRuntimeException.class, ()->{ + Map configs = new HashMap(); + configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, "8192"); + configs.put(YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, "1024"); + Configuration config = CapacitySchedulerConfigGeneratorForTest + .createConfiguration(configs); + CapacitySchedulerConfigValidator.validateMemoryAllocation(config); + fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB + " should be > " + + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB); + + }); } @Test @@ -161,33 +166,36 @@ public void testValidateMemoryAllocation() { /** * Test for the case when the scheduler.minimum-allocation-vcores == 0. */ - @Test (expected = YarnRuntimeException.class) + @Test public void testValidateVCoresInvalidMinVCore() { - Map configs = new HashMap(); - configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES, "0"); - Configuration config = CapacitySchedulerConfigGeneratorForTest - .createConfiguration(configs); - CapacitySchedulerConfigValidator.validateVCores(config); - fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES - + " should be > 0"); + assertThrows(YarnRuntimeException.class, ()->{ + Map configs = new HashMap(); + configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES, "0"); + Configuration config = CapacitySchedulerConfigGeneratorForTest + .createConfiguration(configs); + CapacitySchedulerConfigValidator.validateVCores(config); + fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES + + " should be > 0"); + }); } /** * Test for the case when the scheduler.minimum-allocation-vcores is greater * than scheduler.maximum-allocation-vcores. */ - @Test (expected = YarnRuntimeException.class) + @Test public void testValidateVCoresHigherMinThanMaxVCore() { - Map configs = new HashMap(); - configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES, "4"); - configs.put(YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, "1"); - Configuration config = CapacitySchedulerConfigGeneratorForTest - .createConfiguration(configs); - CapacitySchedulerConfigValidator.validateVCores(config); - fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES + - " should be > " - + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB); - + assertThrows(YarnRuntimeException.class, ()->{ + Map configs = new HashMap(); + configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES, "4"); + configs.put(YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, "1"); + Configuration config = CapacitySchedulerConfigGeneratorForTest + .createConfiguration(configs); + CapacitySchedulerConfigValidator.validateVCores(config); + fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES + + " should be > " + + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB); + }); } @Test @@ -216,7 +224,7 @@ public void testValidateCSConfigInvalidCapacity() { .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("Invalid capacity"); } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .startsWith("Illegal capacity")); } } @@ -236,7 +244,7 @@ public void testValidateCSConfigDefaultRCAbsoluteModeParentMaxMemoryExceeded() .validateCSConfiguration(oldConfiguration, newConfiguration, rmContext); fail("Parent maximum capacity exceeded"); } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .startsWith("Max resource configuration")); } finally { mockRM.stop(); @@ -277,7 +285,7 @@ public void testValidateCSConfigDominantRCAbsoluteModeParentMaxMemoryExceeded() .validateCSConfiguration(oldConfiguration, newConfiguration, rmContext); fail("Parent maximum capacity exceeded"); } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .startsWith("Max resource configuration")); } finally { mockRM.stop(); @@ -298,7 +306,7 @@ public void testValidateCSConfigDominantRCAbsoluteModeParentMaxVcoreExceeded() t .validateCSConfiguration(oldConfiguration, newConfiguration, rmContext); fail("Parent maximum capacity exceeded"); } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .startsWith("Max resource configuration")); } finally { mockRM.stop(); @@ -319,7 +327,7 @@ public void testValidateCSConfigDominantRCAbsoluteModeParentMaxGPUExceeded() thr .validateCSConfiguration(oldConfiguration, newConfiguration, rmContext); fail("Parent maximum capacity exceeded"); } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .startsWith("Max resource configuration")); } finally { mockRM.stop(); @@ -336,7 +344,7 @@ public void testValidateCSConfigStopALeafQueue() throws IOException { RMContext rmContext = prepareRMContext(); boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assert.assertTrue(isValidConfig); + Assertions.assertTrue(isValidConfig); } /** @@ -355,7 +363,7 @@ public void testValidateCSConfigStopANonLeafQueueInvalid() { .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("There are child queues in running state"); } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .contains("The parent queue:root cannot be STOPPED")); } } @@ -374,7 +382,7 @@ public void testValidateCSConfigStopANonLeafQueue() throws IOException { RMContext rmContext = prepareRMContext(); Boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assert.assertTrue(isValidConfig); + Assertions.assertTrue(isValidConfig); } @@ -402,7 +410,7 @@ public void testValidateCSConfigAddALeafQueueInvalid() { fail("Invalid capacity for children of queue root"); } } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .startsWith("Illegal capacity")); } } @@ -428,7 +436,7 @@ public void testValidateCSConfigAddALeafQueueValid() throws IOException { RMContext rmContext = prepareRMContext(); Boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assert.assertTrue(isValidConfig); + Assertions.assertTrue(isValidConfig); } @Test @@ -451,33 +459,33 @@ public void testValidateDoesNotModifyTheDefaultMetricsSystem() throws Exception QueueMetrics origQM1 = cache.get("root.test1"); QueueMetrics origQM2 = cache.get("root.test2"); - Assert.assertNotNull("Original queues should be found in the cache", origQM1); - Assert.assertNotNull("Original queues should be found in the cache", origQM2); + Assertions.assertNotNull(origQM1, "Original queues should be found in the cache"); + Assertions.assertNotNull(origQM2, "Original queues should be found in the cache"); QueueMetrics origPQM1 = cache.get("default.root.test1"); QueueMetrics origPQM2 = cache.get("default.root.test2"); - Assert.assertNotNull("Original queues should be found in the cache (PartitionQueueMetrics)", - origPQM1); - Assert.assertNotNull("Original queues should be found in the cache (PartitionQueueMetrics)", - origPQM2); + Assertions.assertNotNull( + origPQM1, "Original queues should be found in the cache (PartitionQueueMetrics)"); + Assertions.assertNotNull( + origPQM2, "Original queues should be found in the cache (PartitionQueueMetrics)"); MetricsSource origMS1 = ms.getSource("QueueMetrics,q0=root,q1=test1"); MetricsSource origMS2 = ms.getSource("QueueMetrics,q0=root,q1=test2"); - Assert.assertNotNull("Original queues should be found in the Metrics System", - origMS1); - Assert.assertNotNull("Original queues should be found in the Metrics System", - origMS2); + Assertions.assertNotNull( + origMS1, "Original queues should be found in the Metrics System"); + Assertions.assertNotNull( + origMS2, "Original queues should be found in the Metrics System"); MetricsSource origPMS1 = ms .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test1"); MetricsSource origPMS2 = ms .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test2"); - Assert.assertNotNull( - "Original queues should be found in Metrics System (PartitionQueueMetrics)", origPMS1); - Assert.assertNotNull( - "Original queues should be found in Metrics System (PartitionQueueMetrics)", origPMS2); + Assertions.assertNotNull( + origPMS1, "Original queues should be found in Metrics System (PartitionQueueMetrics)"); + Assertions.assertNotNull( + origPMS2, "Original queues should be found in Metrics System (PartitionQueueMetrics)"); Configuration newConfig = new Configuration(oldConfig); newConfig @@ -491,32 +499,32 @@ public void testValidateDoesNotModifyTheDefaultMetricsSystem() throws Exception boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assert.assertTrue(isValidConfig); - - Assert.assertFalse("Validated new queue should not be in the cache", - cache.containsKey("root.test3")); - Assert.assertFalse("Validated new queue should not be in the cache (PartitionQueueMetrics)", - cache.containsKey("default.root.test3")); - Assert.assertNull("Validated new queue should not be in the Metrics System", - ms.getSource("QueueMetrics,q0=root,q1=test3")); - Assert.assertNull( - "Validated new queue should not be in Metrics System (PartitionQueueMetrics)", - ms - .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test3")); + Assertions.assertTrue(isValidConfig); + + Assertions.assertFalse( + cache.containsKey("root.test3"), "Validated new queue should not be in the cache"); + Assertions.assertFalse( + cache.containsKey("default.root.test3"), "Validated new queue should not be in the cache (PartitionQueueMetrics)"); + Assertions.assertNull( + ms.getSource("QueueMetrics,q0=root,q1=test3"), "Validated new queue should not be in the Metrics System"); + Assertions.assertNull( + + ms + .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test3"), "Validated new queue should not be in Metrics System (PartitionQueueMetrics)"); // Config validation should not change the existing // objects in the cache and the metrics system - Assert.assertEquals(origQM1, cache.get("root.test1")); - Assert.assertEquals(origQM2, cache.get("root.test2")); - Assert.assertEquals(origPQM1, cache.get("default.root.test1")); - Assert.assertEquals(origPQM1, cache.get("default.root.test1")); - Assert.assertEquals(origMS1, + Assertions.assertEquals(origQM1, cache.get("root.test1")); + Assertions.assertEquals(origQM2, cache.get("root.test2")); + Assertions.assertEquals(origPQM1, cache.get("default.root.test1")); + Assertions.assertEquals(origPQM1, cache.get("default.root.test1")); + Assertions.assertEquals(origMS1, ms.getSource("QueueMetrics,q0=root,q1=test1")); - Assert.assertEquals(origMS2, + Assertions.assertEquals(origMS2, ms.getSource("QueueMetrics,q0=root,q1=test2")); - Assert.assertEquals(origPMS1, + Assertions.assertEquals(origPMS1, ms.getSource("PartitionQueueMetrics,partition=,q0=root,q1=test1")); - Assert.assertEquals(origPMS2, + Assertions.assertEquals(origPMS2, ms.getSource("PartitionQueueMetrics,partition=,q0=root,q1=test2")); } finally { mockRM.stop(); @@ -543,9 +551,9 @@ public void testValidateCSConfigInvalidQueueDeletion() { .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("Invalid capacity for children of queue root"); } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .contains("root.test2 cannot be deleted")); - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .contains("the queue is not yet in stopped state")); } } @@ -572,7 +580,7 @@ public void testValidateCSConfigInvalidQueueDeletion2() { fail("Invalid capacity for children of queue root"); } } catch (IOException e) { - Assert.assertTrue(e.getCause().getMessage() + Assertions.assertTrue(e.getCause().getMessage() .contains("Illegal capacity")); } } @@ -595,7 +603,7 @@ public void testValidateCSConfigValidQueueDeletion() throws IOException { RMContext rmContext = prepareRMContext(); boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assert.assertTrue(isValidConfig); + Assertions.assertTrue(isValidConfig); } @@ -613,7 +621,7 @@ public void testAddQueueToALeafQueue() throws IOException { RMContext rmContext = prepareRMContext(); boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assert.assertTrue(isValidConfig); + Assertions.assertTrue(isValidConfig); } public static RMContext prepareRMContext() { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfiguration.java index 85e0ff494eb93..babb497181190 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfiguration.java @@ -20,13 +20,13 @@ import org.apache.hadoop.security.authorize.AccessControlList; import org.apache.hadoop.util.Sets; import org.apache.hadoop.yarn.api.records.QueueACL; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Set; -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; public class TestCapacitySchedulerConfiguration { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerDynamicBehavior.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerDynamicBehavior.java index e8577fba2c387..a52a54b27acc4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerDynamicBehavior.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerDynamicBehavior.java @@ -34,13 +34,13 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.ROOT; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.checkQueueStructureCapacities; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.getDefaultCapacities; -import static org.junit.Assert.assertEquals; -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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.List; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; @@ -54,9 +54,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerDynamicEditException; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.QueueEntitlement; -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; public class TestCapacitySchedulerDynamicBehavior { private static final Logger LOG = LoggerFactory @@ -66,7 +66,7 @@ public class TestCapacitySchedulerDynamicBehavior { private MockRM rm; - @Before + @BeforeEach public void setUp() throws Exception { CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration(); setupPlanQueueConfiguration(conf); @@ -78,7 +78,7 @@ public void setUp() throws Exception { rm.registerNode("n1:1234", 64 * GB, 64); } - @After + @AfterEach public void tearDown() { if (rm != null) { rm.stop(); @@ -249,7 +249,7 @@ public void testMoveAppToPlanQueue() throws Exception { String queue = scheduler.getApplicationAttempt(appsInB1.get(0)).getQueue() .getQueueName(); - Assert.assertEquals("b1", queue); + Assertions.assertEquals("b1", queue); List appsInRoot = scheduler.getAppsInQueue("root"); assertTrue(appsInRoot.contains(appAttemptId)); @@ -275,7 +275,7 @@ public void testMoveAppToPlanQueue() throws Exception { queue = scheduler.getApplicationAttempt(appsInDefQ.get(0)).getQueue() .getQueueName(); - Assert.assertTrue(queue.equals(defQName)); + Assertions.assertTrue(queue.equals(defQName)); appsInA = scheduler.getAppsInQueue("a"); assertTrue(appsInA.contains(appAttemptId)); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerLazyPreemption.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerLazyPreemption.java index 8f07668192dff..f5716a218ffd0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerLazyPreemption.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerLazyPreemption.java @@ -38,10 +38,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.ArrayList; import java.util.Arrays; @@ -52,14 +53,15 @@ public class TestCapacitySchedulerLazyPreemption extends CapacitySchedulerPreemptionTestBase { @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); conf.setBoolean(CapacitySchedulerConfiguration.LAZY_PREEMPTION_ENABLED, true); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testSimplePreemption() throws Exception { /** * Test case: Submit two application (app1/app2) to different queues, queue @@ -117,7 +119,7 @@ public void testSimplePreemption() throws Exception { // App1 should have 7 containers now, and no available resource for cluster FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); // Submit app2 to queue-c and asks for a 1G container for AM MockRMAppSubmissionData data = @@ -132,9 +134,9 @@ public void testSimplePreemption() throws Exception { MockAM am2 = MockRM.launchAndRegisterAM(app2, rm1, nm2); // NM1/NM2 has available resource = 0G - Assert.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertEquals(0 * GB, cs.getNode(nm2.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm2.getNodeId()) .getUnallocatedResource().getMemorySize()); // AM asks for a 1 * GB container @@ -158,8 +160,8 @@ public void testSimplePreemption() throws Exception { Map killableContainers = waitKillableContainersSize( pm, "root.a", RMNodeLabelsManager.NO_LABEL, 1); - Assert.assertEquals(1, killableContainers.size()); - Assert.assertEquals(killableContainers.entrySet().iterator().next().getKey() + Assertions.assertEquals(1, killableContainers.size()); + Assertions.assertEquals(killableContainers.entrySet().iterator().next().getKey() .getApplicationAttemptId(), am1.getApplicationAttemptId()); // Call CS.handle once to see if container preempted @@ -169,21 +171,22 @@ public void testSimplePreemption() throws Exception { am2.getApplicationAttemptId()); // App1 has 6 containers, and app2 has 2 containers - Assert.assertEquals(6, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(2, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(6, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp2.getLiveContainers().size()); // Ensure preemption metrics were recored. - Assert.assertEquals( - "Number of preempted containers incorrectly recorded:", 1, - cs.getQueue("a").getMetrics().getAggregatePreemptedContainers()); - Assert.assertEquals( - "Number of preempted containers incorrectly recorded:", 1, - cs.getRootQueue().getMetrics().getAggregatePreemptedContainers()); + Assertions.assertEquals( + 1 +, cs.getQueue("a").getMetrics().getAggregatePreemptedContainers(), "Number of preempted containers incorrectly recorded:"); + Assertions.assertEquals( + 1 +, cs.getRootQueue().getMetrics().getAggregatePreemptedContainers(), "Number of preempted containers incorrectly recorded:"); rm1.close(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testPreemptionConsidersNodeLocalityDelay() throws Exception { /** @@ -225,7 +228,7 @@ public void testPreemptionConsidersNodeLocalityDelay() // App1 should have 7 containers now, and no available resource for cluster FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); // Submit app2 to queue-c and asks for a 1G container for AM MockRMAppSubmissionData data = @@ -240,9 +243,9 @@ public void testPreemptionConsidersNodeLocalityDelay() MockAM am2 = MockRM.launchAndRegisterAM(app2, rm1, nm2); // NM1/NM2 has available resource = 0G - Assert.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertEquals(0 * GB, cs.getNode(nm2.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm2.getNodeId()) .getUnallocatedResource().getMemorySize()); // AM asks for a 1 * GB container with unknown host and unknown rack @@ -270,7 +273,7 @@ public void testPreemptionConsidersNodeLocalityDelay() Map killableContainers = waitKillableContainersSize( pm, "root.a", RMNodeLabelsManager.NO_LABEL, 1); - Assert.assertEquals(killableContainers.entrySet().iterator().next().getKey() + Assertions.assertEquals(killableContainers.entrySet().iterator().next().getKey() .getApplicationAttemptId(), am1.getApplicationAttemptId()); // Call CS.handle once to see if container preempted @@ -280,20 +283,21 @@ public void testPreemptionConsidersNodeLocalityDelay() am2.getApplicationAttemptId()); // App1 has 7 containers, and app2 has 1 containers (no container preempted) - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); // Do allocation again, one container will be preempted cs.handle(new NodeUpdateSchedulerEvent(rmNode2)); // App1 has 6 containers, and app2 has 2 containers (new container allocated) - Assert.assertEquals(6, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(2, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(6, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp2.getLiveContainers().size()); rm1.close(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testPreemptionConsidersHardNodeLocality() throws Exception { /** @@ -337,7 +341,7 @@ public void testPreemptionConsidersHardNodeLocality() // App1 should have 7 containers now, and no available resource for cluster FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); // Submit app2 to queue-c and asks for a 1G container for AM MockRMAppSubmissionData data = @@ -352,9 +356,9 @@ public void testPreemptionConsidersHardNodeLocality() MockAM am2 = MockRM.launchAndRegisterAM(app2, rm1, nm2); // NM1/NM2 has available resource = 0G - Assert.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertEquals(0 * GB, cs.getNode(nm2.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm2.getNodeId()) .getUnallocatedResource().getMemorySize()); // AM asks for a 1 * GB container for h3 with hard locality, @@ -383,7 +387,7 @@ public void testPreemptionConsidersHardNodeLocality() Map killableContainers = waitKillableContainersSize( pm, "root.a", RMNodeLabelsManager.NO_LABEL, 1); - Assert.assertEquals(killableContainers.entrySet().iterator().next().getKey() + Assertions.assertEquals(killableContainers.entrySet().iterator().next().getKey() .getApplicationAttemptId(), am1.getApplicationAttemptId()); // Call CS.handle once to see if container preempted @@ -393,20 +397,21 @@ public void testPreemptionConsidersHardNodeLocality() am2.getApplicationAttemptId()); // App1 has 7 containers, and app2 has 1 containers (no container preempted) - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); // Do allocation again, nothing will be preempted cs.handle(new NodeUpdateSchedulerEvent(rmNode2)); // App1 has 7 containers, and app2 has 1 containers (no container allocated) - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); rm1.close(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testPreemptionPolicyShouldRespectAlreadyMarkedKillableContainers() throws Exception { /** @@ -455,7 +460,7 @@ public void testPreemptionPolicyShouldRespectAlreadyMarkedKillableContainers() // App1 should have 7 containers now, and no available resource for cluster FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); // Submit app2 to queue-c and asks for a 1G container for AM MockRMAppSubmissionData data = @@ -470,7 +475,7 @@ public void testPreemptionPolicyShouldRespectAlreadyMarkedKillableContainers() MockAM am2 = MockRM.launchAndRegisterAM(app2, rm1, nm1); // NM1 has available resource = 0G - Assert.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); am2.allocate("*", 1 * GB, 1, new ArrayList()); @@ -490,11 +495,11 @@ public void testPreemptionPolicyShouldRespectAlreadyMarkedKillableContainers() waitKillableContainersSize(pm, "root.a", RMNodeLabelsManager.NO_LABEL, 1); // Check killable containers and to-be-preempted containers in edit policy - Assert.assertEquals(0, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(0, editPolicy.getToPreemptContainers().size()); // Run edit schedule again, confirm status doesn't changed editPolicy.editSchedule(); - Assert.assertEquals(0, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(0, editPolicy.getToPreemptContainers().size()); // Save current to kill containers Set previousKillableContainers = new HashSet<>( @@ -508,17 +513,17 @@ public void testPreemptionPolicyShouldRespectAlreadyMarkedKillableContainers() // Call editPolicy.editSchedule() once, we should have 1 container in to-preempt map // and 1 container in killable map editPolicy.editSchedule(); - Assert.assertEquals(1, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(1, editPolicy.getToPreemptContainers().size()); // Call editPolicy.editSchedule() once more, we should have 2 containers killable map editPolicy.editSchedule(); - Assert.assertEquals(0, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(0, editPolicy.getToPreemptContainers().size()); // Check if previous killable containers included by new killable containers Map killableContainers = waitKillableContainersSize( pm, "root.a", RMNodeLabelsManager.NO_LABEL, 2); - Assert.assertTrue( + Assertions.assertTrue( Sets.difference(previousKillableContainers, killableContainers.keySet()) .isEmpty()); } @@ -527,7 +532,8 @@ public void testPreemptionPolicyShouldRespectAlreadyMarkedKillableContainers() * Ignore this test now because it could be a premature optimization */ @Ignore - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testPreemptionPolicyCleanupKillableContainersWhenNoPreemptionNeeded() throws Exception { /** @@ -575,7 +581,7 @@ public void testPreemptionPolicyCleanupKillableContainersWhenNoPreemptionNeeded( // App1 should have 7 containers now, and no available resource for cluster FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); // Submit app2 to queue-c and asks for a 1G container for AM MockRMAppSubmissionData data = @@ -590,7 +596,7 @@ public void testPreemptionPolicyCleanupKillableContainersWhenNoPreemptionNeeded( MockAM am2 = MockRM.launchAndRegisterAM(app2, rm1, nm1); // NM1 has available resource = 0G - Assert.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); am2.allocate("*", 3 * GB, 1, new ArrayList()); @@ -612,17 +618,18 @@ public void testPreemptionPolicyCleanupKillableContainersWhenNoPreemptionNeeded( // Change reqeust from 3G to 2G, now we can preempt one less container. (3->2) am2.allocate("*", 2 * GB, 1, new ArrayList()); editPolicy.editSchedule(); - Assert.assertEquals(0, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(0, editPolicy.getToPreemptContainers().size()); waitKillableContainersSize(pm, "a", RMNodeLabelsManager.NO_LABEL, 2); // Call editSchedule once more to make sure still nothing happens editPolicy.editSchedule(); - Assert.assertEquals(0, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(0, editPolicy.getToPreemptContainers().size()); waitKillableContainersSize(pm, "a", RMNodeLabelsManager.NO_LABEL, 2); rm1.stop(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testPreemptionConsidersUserLimit() throws Exception { /** @@ -685,7 +692,7 @@ public void testPreemptionConsidersUserLimit() // App1 should have 7 containers now, and no available resource for cluster FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); // Submit app2 to queue-c and asks for a 1G container for AM MockRMAppSubmissionData data = @@ -700,9 +707,9 @@ public void testPreemptionConsidersUserLimit() MockAM am2 = MockRM.launchAndRegisterAM(app2, rm1, nm2); // NM1/NM2 has available resource = 0G - Assert.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertEquals(0 * GB, cs.getNode(nm2.getNodeId()) + Assertions.assertEquals(0 * GB, cs.getNode(nm2.getNodeId()) .getUnallocatedResource().getMemorySize()); // AM asks for a 1 * GB container @@ -726,7 +733,7 @@ public void testPreemptionConsidersUserLimit() PreemptionManager pm = cs.getPreemptionManager(); Map killableContainers = waitKillableContainersSize(pm, "a", RMNodeLabelsManager.NO_LABEL, 0); - Assert.assertEquals(0, killableContainers.size()); + Assertions.assertEquals(0, killableContainers.size()); // Call CS.handle once to see if container preempted cs.handle(new NodeUpdateSchedulerEvent(rmNode2)); @@ -735,8 +742,8 @@ public void testPreemptionConsidersUserLimit() am2.getApplicationAttemptId()); // App1 has 7 containers, and app2 has 1 containers (nothing preempted) - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); rm1.close(); } @@ -755,7 +762,7 @@ private Map waitKillableContainersSize( wait++; } - Assert.assertEquals(expectedSize, killableContainers.size()); + Assertions.assertEquals(expectedSize, killableContainers.size()); return killableContainers; } } \ 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/scheduler/capacity/TestCapacitySchedulerMaxParallelApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMaxParallelApps.java index 39bd38030f2a1..247de9de34552 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMaxParallelApps.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMaxParallelApps.java @@ -19,8 +19,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX; -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 java.util.Collections; import java.util.List; @@ -46,9 +46,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; -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 TestCapacitySchedulerMaxParallelApps { private CapacitySchedulerConfiguration conf; @@ -67,7 +68,7 @@ public class TestCapacitySchedulerMaxParallelApps { private ParentQueue rootQueue; private LeafQueue defaultQueue; - @Before + @BeforeEach public void setUp() { CapacitySchedulerConfiguration config = new CapacitySchedulerConfiguration(); @@ -77,21 +78,23 @@ public void setUp() { conf = new CapacitySchedulerConfiguration(config); } - @After + @AfterEach public void after() { if (rm != null) { rm.stop(); } } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testMaxParallelAppsExceedsQueueSetting() throws Exception { conf.setInt("yarn.scheduler.capacity.root.default.max-parallel-apps", 2); executeCommonStepsAndChecks(); testWhenSettingsExceeded(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testMaxParallelAppsExceedsDefaultQueueSetting() throws Exception { conf.setInt("yarn.scheduler.capacity.max-parallel-apps", 2); @@ -99,21 +102,24 @@ public void testMaxParallelAppsExceedsDefaultQueueSetting() testWhenSettingsExceeded(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testMaxParallelAppsExceedsUserSetting() throws Exception { conf.setInt("yarn.scheduler.capacity.user.testuser.max-parallel-apps", 2); executeCommonStepsAndChecks(); testWhenSettingsExceeded(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testMaxParallelAppsExceedsDefaultUserSetting() throws Exception { conf.setInt("yarn.scheduler.capacity.user.max-parallel-apps", 2); executeCommonStepsAndChecks(); testWhenSettingsExceeded(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testMaxParallelAppsWhenReloadingConfig() throws Exception { conf.setInt("yarn.scheduler.capacity.root.default.max-parallel-apps", 2); @@ -132,7 +138,8 @@ public void testMaxParallelAppsWhenReloadingConfig() throws Exception { verifyRunningAndAcceptedApps(4, 0); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testMaxAppsReachedWithNonRunnableApps() throws Exception { conf.setInt("yarn.scheduler.capacity.root.default.max-parallel-apps", 2); conf.setInt("yarn.scheduler.capacity.root.default.maximum-applications", 4); @@ -245,20 +252,20 @@ private ParentQueue getRootQueue() { private void verifyRunnableAppsInParent(ParentQueue queue, int expectedRunnable) { - assertEquals("Num of runnable apps", expectedRunnable, - queue.getNumRunnableApps()); + assertEquals(expectedRunnable +, queue.getNumRunnableApps(), "Num of runnable apps"); } private void verifyRunnableAppsInLeaf(LeafQueue queue, int expectedRunnable, Set nonRunnableIds) { - assertEquals("Num of runnable apps", expectedRunnable, - queue.getNumRunnableApps()); + assertEquals(expectedRunnable +, queue.getNumRunnableApps(), "Num of runnable apps"); queue.getCopyOfNonRunnableAppSchedulables() .stream() .map(fca -> fca.getApplicationAttemptId()) - .forEach(id -> assertTrue(id + " not found as non-runnable", - nonRunnableIds.contains(id))); + .forEach(id -> assertTrue( + nonRunnableIds.contains(id), id + " not found as non-runnable")); } private void verifyRunningAndAcceptedApps(int expectedRunning, @@ -282,8 +289,8 @@ private void verifyRunningAndAcceptedApps(int expectedRunning, report.getYarnApplicationState() == YarnApplicationState.ACCEPTED) .count(); - assertEquals("Running apps count", expectedRunning, runningCount); - assertEquals("Accepted apps count", expectedAccepted, acceptedCount); + assertEquals(expectedRunning, runningCount, "Running apps count"); + assertEquals(expectedAccepted, acceptedCount, "Accepted apps count"); } private void unregisterAMandWaitForFinish(RMApp app, MockAM am, MockNM nm) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMultiNodes.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMultiNodes.java index 484308442ff31..93f782fb2d566 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMultiNodes.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMultiNodes.java @@ -53,9 +53,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.MultiNodeSorter; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.MultiNodeSortingManager; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; -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 class for Multi Node scheduling related tests. @@ -69,7 +70,7 @@ public class TestCapacitySchedulerMultiNodes { private static final String POLICY_CLASS_NAME = "org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.ResourceUsageMultiNodeLookupPolicy"; - @Before + @BeforeEach public void setUp() { CapacitySchedulerConfiguration config = new CapacitySchedulerConfiguration(); @@ -109,7 +110,7 @@ public void testMultiNodeSorterForScheduling() throws Exception { sorter.reSortClusterNodes(); Set nodes = sorter.getMultiNodeLookupPolicy() .getNodesPerPartition(""); - Assert.assertEquals(4, nodes.size()); + Assertions.assertEquals(4, nodes.size()); rm.stop(); } @@ -132,7 +133,7 @@ public void testMultiNodeSorterForSchedulingWithOrdering() throws Exception { Set nodes = sorter.getMultiNodeLookupPolicy() .getNodesPerPartition(""); - Assert.assertEquals(4, nodes.size()); + Assertions.assertEquals(4, nodes.size()); MockRMAppSubmissionData data1 = MockRMAppSubmissionData.Builder.createWithMemory(2048, rm) @@ -148,8 +149,8 @@ public void testMultiNodeSorterForSchedulingWithOrdering() throws Exception { rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); // check node report - Assert.assertEquals(2 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(8 * GB, + Assertions.assertEquals(2 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(8 * GB, reportNm1.getAvailableResource().getMemorySize()); // Ideally thread will invoke this, but thread operates every 1sec. @@ -170,8 +171,8 @@ public void testMultiNodeSorterForSchedulingWithOrdering() throws Exception { rm.getResourceScheduler().getNodeReport(nm2.getNodeId()); // check node report - Assert.assertEquals(1 * GB, reportNm2.getUsedResource().getMemorySize()); - Assert.assertEquals(9 * GB, + Assertions.assertEquals(1 * GB, reportNm2.getUsedResource().getMemorySize()); + Assertions.assertEquals(9 * GB, reportNm2.getAvailableResource().getMemorySize()); // Ideally thread will invoke this, but thread operates every 1sec. @@ -192,12 +193,13 @@ public void testMultiNodeSorterForSchedulingWithOrdering() throws Exception { int i = 0; while (it.hasNext()) { current = it.next(); - Assert.assertEquals(current.getNodeID(), currentNodes.get(i++)); + Assertions.assertEquals(current.getNodeID(), currentNodes.get(i++)); } rm.stop(); } - @Test (timeout=30000) + @Test + @Timeout(value = 30) public void testExcessReservationWillBeUnreserved() throws Exception { CapacitySchedulerConfiguration newConf = new CapacitySchedulerConfiguration(conf); @@ -253,10 +255,10 @@ public void testExcessReservationWillBeUnreserved() throws Exception { cs.handle(new NodeUpdateSchedulerEvent(rmNode2)); // Check containers of app1 and app2. - Assert.assertNotNull(cs.getNode(nm2.getNodeId()).getReservedContainer()); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertNotNull(cs.getNode(nm2.getNodeId()).getReservedContainer()); + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); // Cancel ask of the reserved container. am1.allocate("*", 6 * GB, 0, new ArrayList<>()); @@ -266,24 +268,25 @@ public void testExcessReservationWillBeUnreserved() throws Exception { // Trigger scheduling to release reserved container // whose ask has been cancelled. cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(0, schedulerApp1.getReservedContainers().size()); - Assert.assertEquals(2, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(7 * GB, + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(0, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(2, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(7 * GB, cs.getNode(nm1.getNodeId()).getAllocatedResource().getMemorySize()); - Assert.assertEquals(12 * GB, + Assertions.assertEquals(12 * GB, cs.getRootQueue().getQueueResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, cs.getRootQueue().getQueueResourceUsage().getReserved() .getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, leafQueue.getQueueResourceUsage().getReserved().getMemorySize()); rm1.close(); } - @Test(timeout=30000) + @Test + @Timeout(value = 30) public void testAllocateForReservedContainer() throws Exception { CapacitySchedulerConfiguration newConf = new CapacitySchedulerConfiguration(conf); @@ -337,23 +340,24 @@ public void testAllocateForReservedContainer() throws Exception { cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); // Check containers of app1 and app2. - Assert.assertNotNull(cs.getNode(nm2.getNodeId()).getReservedContainer()); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getReservedContainers().size()); + Assertions.assertNotNull(cs.getNode(nm2.getNodeId()).getReservedContainer()); + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getReservedContainers().size()); // Kill app1 to release resource on nm1. rm1.killApp(app1.getApplicationId()); // Trigger scheduling to allocate for reserved container on nm1. cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); - Assert.assertEquals(2, schedulerApp2.getLiveContainers().size()); + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertEquals(2, schedulerApp2.getLiveContainers().size()); rm1.close(); } - @Test(timeout=30000) + @Test + @Timeout(value = 30) public void testAllocateOfReservedContainerFromAnotherNode() throws Exception { CapacitySchedulerConfiguration newConf = @@ -410,7 +414,7 @@ public void run() { MockAM am3 = MockRM.launchAndRegisterAM(app3, rm1, nm1); result.set(true); } catch (Exception e) { - Assert.fail("Failed to allocate the reserved container"); + Assertions.fail("Failed to allocate the reserved container"); } } }; @@ -420,8 +424,8 @@ public void run() { // Validate if app3 has got RESERVED container FiCaSchedulerApp schedulerApp = cs.getApplicationAttempt(app3.getCurrentAppAttempt().getAppAttemptId()); - Assert.assertEquals("App3 failed to get reserved container", 1, - schedulerApp.getReservedContainers().size()); + Assertions.assertEquals(1 +, schedulerApp.getReservedContainers().size(), "App3 failed to get reserved container"); // Free the Space on other node where Reservation has not happened if (cs.getNode(rmNode1.getNodeID()).getReservedContainer() != null) { @@ -441,10 +445,10 @@ public void run() { // Validate release of reserved containers schedulerApp = cs.getApplicationAttempt(app3.getCurrentAppAttempt().getAppAttemptId()); - Assert.assertEquals("App3 failed to release Reserved container", 0, - schedulerApp.getReservedContainers().size()); - Assert.assertNull(cs.getNode(rmNode1.getNodeID()).getReservedContainer()); - Assert.assertNull(cs.getNode(rmNode2.getNodeID()).getReservedContainer()); + Assertions.assertEquals(0 +, schedulerApp.getReservedContainers().size(), "App3 failed to release Reserved container"); + Assertions.assertNull(cs.getNode(rmNode1.getNodeID()).getReservedContainer()); + Assertions.assertNull(cs.getNode(rmNode2.getNodeID()).getReservedContainer()); rm1.close(); } @@ -471,19 +475,20 @@ public void testMultiNodeSorterAfterHeartbeatInterval() throws Exception { Iterator nodeIterator = mns.getMultiNodeSortIterator( nodes, partition, POLICY_CLASS_NAME); - Assert.assertEquals(4, Iterators.size(nodeIterator)); + Assertions.assertEquals(4, Iterators.size(nodeIterator)); // Validate the count after missing 3 node heartbeats Thread.sleep(YarnConfiguration.DEFAULT_RM_NM_HEARTBEAT_INTERVAL_MS * 3); nodeIterator = mns.getMultiNodeSortIterator( nodes, partition, POLICY_CLASS_NAME); - Assert.assertEquals(0, Iterators.size(nodeIterator)); + Assertions.assertEquals(0, Iterators.size(nodeIterator)); rm.stop(); } - @Test(timeout=30000) + @Test + @Timeout(value = 30) public void testSkipAllocationOnNodeReservedByAnotherApp() throws Exception { CapacitySchedulerConfiguration newConf = new CapacitySchedulerConfiguration(conf); @@ -533,7 +538,7 @@ public void testSkipAllocationOnNodeReservedByAnotherApp() throws Exception { // Check containers of app1 and app2. Set reservedContainers = checkReservedContainers(cs, rm1.getRMContext().getRMNodes(), 1); - Assert.assertEquals(1, reservedContainers.size()); + Assertions.assertEquals(1, reservedContainers.size()); RMNode nodeWithReservedContainer = reservedContainers.iterator().next(); LOG.debug("Reserved container on: {}", nodeWithReservedContainer); @@ -541,12 +546,12 @@ public void testSkipAllocationOnNodeReservedByAnotherApp() throws Exception { if (nodeWithReservedContainer.getNodeID().getHost().startsWith("127.0.0.2")) { moveReservation(cs, rm1, nm1, nm2, am1); } - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); - Assert.assertNull(cs.getNode(nm2.getNodeId()).getReservedContainer()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertNull(cs.getNode(nm2.getNodeId()).getReservedContainer()); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); //Make sure to have available headroom on the child queue, // see: RegularContainerAllocator#checkHeadroom, @@ -558,8 +563,8 @@ public void testSkipAllocationOnNodeReservedByAnotherApp() throws Exception { // nm1 has a reservation for another app am2.allocate("*", 4 * GB, 1, new ArrayList<>()); cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); - Assert.assertNotNull(cs.getNode(nm2.getNodeId()).getReservedContainer()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertNotNull(cs.getNode(nm2.getNodeId()).getReservedContainer()); rm1.close(); } @@ -586,7 +591,7 @@ private static Set checkReservedContainers(CapacityScheduler cs, } } - Assert.assertEquals(expectedNumberOfContainers, result.size()); + Assertions.assertEquals(expectedNumberOfContainers, result.size()); return result; } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMultiNodesWithPreemption.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMultiNodesWithPreemption.java index c895b58b2962a..38a3adaa35b75 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMultiNodesWithPreemption.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerMultiNodesWithPreemption.java @@ -19,8 +19,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.GB; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; @@ -44,9 +44,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.ProportionalCapacityPreemptionPolicy; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,7 +63,7 @@ public class TestCapacitySchedulerMultiNodesWithPreemption { "org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement." + "ResourceUsageMultiNodeLookupPolicy"; - @Before + @BeforeEach public void setUp() { CapacitySchedulerConfiguration config = new CapacitySchedulerConfiguration(); @@ -114,7 +115,8 @@ public void setUp() { conf.setLong(YarnConfiguration.RM_NM_HEARTBEAT_INTERVAL_MS, 60000); } - @Test(timeout=60000) + @Test + @Timeout(value = 60) public void testAllocateReservationFromOtherNode() throws Exception { MockRM rm = new MockRM(conf); rm.start(); @@ -174,7 +176,7 @@ public void run() { MockAM am2 = MockRM.launchAM(app2, rm, nm1); result.set(true); } catch (Exception e) { - Assert.fail("Failed to launch app-2"); + Assertions.fail("Failed to launch app-2"); } } }; @@ -226,13 +228,13 @@ public void run() { .getAppAttemptId(); FiCaSchedulerApp schedulerApp = cs.getApplicationAttempt(app2AttemptId); - assertEquals("App2 failed to get reserved container", 1, - schedulerApp.getReservedContainers().size()); + assertEquals(1 +, schedulerApp.getReservedContainers().size(), "App2 failed to get reserved container"); LOG.info("Reserved node is: " + schedulerApp.getReservedContainers().get(0).getReservedNode()); - assertNotEquals("Failed to reserve as per the Multi Node Itearor", - schedulerApp.getReservedContainers().get(0).getReservedNode(), - preemptedNode.get().getNodeId()); + assertNotEquals( + schedulerApp.getReservedContainers().get(0).getReservedNode() +, preemptedNode.get().getNodeId(), "Failed to reserve as per the Multi Node Itearor"); // Step 6: Okay, now preempted node is Node1 and reserved node is Node3 @@ -262,10 +264,10 @@ public void run() { // Step 8: Validate if app-2 has got 1 live container and // released the reserved container schedulerApp = cs.getApplicationAttempt(app2AttemptId); - assertEquals("App2 failed to get Allocated", 1, - schedulerApp.getLiveContainers().size()); - assertEquals("App2 failed to Unreserve", 0, - schedulerApp.getReservedContainers().size()); + assertEquals(1 +, schedulerApp.getLiveContainers().size(), "App2 failed to get Allocated"); + assertEquals(0 +, schedulerApp.getReservedContainers().size(), "App2 failed to Unreserve"); 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/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreation.java index 9e2134143b8a4..efa6984116e57 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreation.java @@ -39,10 +39,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAttemptRemovedSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppRemovedSchedulerEvent; import org.apache.hadoop.yarn.server.utils.BuilderUtils; -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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,6 +53,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assume.assumeThat; +import static org.junit.jupiter.api.Assertions.assertThrows; public class TestCapacitySchedulerNewQueueAutoCreation extends TestCapacitySchedulerAutoCreatedQueueBase { @@ -90,7 +91,7 @@ public AutoCreatedQueueDeletionPolicy getPolicy() { / a1 */ - @Before + @BeforeEach public void setUp() throws Exception { csConf = new CapacitySchedulerConfiguration(); csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -111,7 +112,7 @@ public void setUp() throws Exception { csConf.setAutoExpiredDeletionTime(1); } - @After + @AfterEach public void tearDown() { if (mockRM != null) { mockRM.stop(); @@ -160,12 +161,12 @@ private void createBasicQueueStructureAndValidate() throws Exception { // Check if queue c-auto got created CSQueue c = cs.getQueue("root.c-auto"); - Assert.assertEquals(1 / 3f, c.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(400 * GB, + Assertions.assertEquals(1 / 3f, c.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(400 * GB, c.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(((LeafQueue)c).getUserLimitFactor(), -1, 1e-6); - Assert.assertEquals(((LeafQueue)c).getMaxAMResourcePerQueuePercent(), 1, 1e-6); + Assertions.assertEquals(((LeafQueue)c).getUserLimitFactor(), -1, 1e-6); + Assertions.assertEquals(((LeafQueue)c).getMaxAMResourcePerQueuePercent(), 1, 1e-6); // Now add another queue-d, in the same hierarchy createQueue("root.d-auto"); @@ -173,15 +174,15 @@ private void createBasicQueueStructureAndValidate() throws Exception { // Because queue-d has the same weight of other sibling queue, its abs cap // become 1/4 CSQueue d = cs.getQueue("root.d-auto"); - Assert.assertEquals(1 / 4f, d.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, d.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(300 * GB, + Assertions.assertEquals(1 / 4f, d.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, d.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(300 * GB, d.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Now we check queue c again, it should also become 1/4 capacity - Assert.assertEquals(1 / 4f, c.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(300 * GB, + Assertions.assertEquals(1 / 4f, c.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(300 * GB, c.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Now we add a two-level queue, create leaf only @@ -191,9 +192,9 @@ private void createBasicQueueStructureAndValidate() throws Exception { // root.a has 1/4 abs resource, a2/a1 has the same weight, so a2 has 1/8 abs // capacity CSQueue a2 = cs.getQueue("root.a.a2-auto"); - Assert.assertEquals(1 / 8f, a2.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, a2.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(150 * GB, + Assertions.assertEquals(1 / 8f, a2.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, a2.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(150 * GB, a2.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // try, create leaf + parent, will success @@ -202,16 +203,16 @@ private void createBasicQueueStructureAndValidate() throws Exception { // Now check capacity of e and e1 (under root we have 5 queues, so e1 get // 1/5 capacity CSQueue e = cs.getQueue("root.e-auto"); - Assert.assertEquals(1 / 5f, e.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, e.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(240 * GB, + Assertions.assertEquals(1 / 5f, e.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, e.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(240 * GB, e.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Under e, there's only one queue, so e1/e have same capacity CSQueue e1 = cs.getQueue("root.e-auto.e1-auto"); - Assert.assertEquals(1 / 5f, e1.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, e1.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(240 * GB, + Assertions.assertEquals(1 / 5f, e1.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, e1.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(240 * GB, e1.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); } @@ -231,9 +232,9 @@ public void testAutoCreateQueueWithSiblingsUnderRoot() throws Exception { // Check if queue c-auto got created CSQueue c = cs.getQueue("root.c-auto"); - Assert.assertEquals(1 / 3f, c.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(400 * GB, + Assertions.assertEquals(1 / 3f, c.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(400 * GB, c.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Now add another queue-d, in the same hierarchy @@ -242,15 +243,15 @@ public void testAutoCreateQueueWithSiblingsUnderRoot() throws Exception { // Because queue-d has the same weight of other sibling queue, its abs cap // become 1/4 CSQueue d = cs.getQueue("root.d-auto"); - Assert.assertEquals(1 / 4f, d.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, d.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(300 * GB, + Assertions.assertEquals(1 / 4f, d.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, d.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(300 * GB, d.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Now we check queue c again, it should also become 1/4 capacity - Assert.assertEquals(1 / 4f, c.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(300 * GB, + Assertions.assertEquals(1 / 4f, c.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(300 * GB, c.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); } @@ -272,9 +273,9 @@ public void testAutoCreateQueueStaticParentOneLevel() throws Exception { // root.a has 1/2 abs resource, a2/a1 has the same weight, so a2 has 1/4 abs // capacity CSQueue a2 = cs.getQueue("root.a.a2-auto"); - Assert.assertEquals(1 / 4f, a2.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, a2.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(MAX_MEMORY * (1 / 4f) * GB, + Assertions.assertEquals(1 / 4f, a2.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, a2.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(MAX_MEMORY * (1 / 4f) * GB, a2.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize(), 1e-6); @@ -300,9 +301,9 @@ public void testAutoCreateQueueAutoParentTwoLevelsWithSiblings() // -> a3-auto is alone with weight 1/4 createQueue("root.a.a2-auto.a3-auto"); CSQueue a3 = cs.getQueue("root.a.a2-auto.a3-auto"); - Assert.assertEquals(1 / 4f, a3.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, a3.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(MAX_MEMORY * (1 / 4f) * GB, + Assertions.assertEquals(1 / 4f, a3.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, a3.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(MAX_MEMORY * (1 / 4f) * GB, a3.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize(), 1e-6); @@ -310,33 +311,37 @@ public void testAutoCreateQueueAutoParentTwoLevelsWithSiblings() // -> a3-auto and a4-auto same weight 1/8 createQueue("root.a.a2-auto.a4-auto"); CSQueue a4 = cs.getQueue("root.a.a2-auto.a4-auto"); - Assert.assertEquals(1 / 8f, a3.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, a3.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(MAX_MEMORY * (1 / 8f) * GB, + Assertions.assertEquals(1 / 8f, a3.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, a3.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(MAX_MEMORY * (1 / 8f) * GB, a4.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize(), 1e-6); } - @Test(expected = SchedulerDynamicEditException.class) + @Test public void testAutoCreateQueueShouldFailWhenNonParentQueue() throws Exception { - startScheduler(); - createQueue("root.a.a1.a2-auto"); + assertThrows(SchedulerDynamicEditException.class, ()->{ + startScheduler(); + createQueue("root.a.a1.a2-auto"); + }); } - @Test(expected = SchedulerDynamicEditException.class) + @Test public void testAutoCreateQueueWhenSiblingsNotInWeightMode() throws Exception { - startScheduler(); - // If the new queue mode is used it's allowed to - // create a new dynamic queue when the sibling is - // not in weight mode - assumeThat(csConf.isLegacyQueueMode(), is(true)); - csConf.setCapacity(A, 50f); - csConf.setCapacity(B, 50f); - csConf.setCapacity(A1, 100f); - cs.reinitialize(csConf, mockRM.getRMContext()); - createQueue("root.a.a2-auto"); + assertThrows(SchedulerDynamicEditException.class, ()->{ + startScheduler(); + // If the new queue mode is used it's allowed to + // create a new dynamic queue when the sibling is + // not in weight mode + assumeThat(csConf.isLegacyQueueMode(), is(true)); + csConf.setCapacity(A, 50f); + csConf.setCapacity(B, 50f); + csConf.setCapacity(A1, 100f); + cs.reinitialize(csConf, mockRM.getRMContext()); + createQueue("root.a.a2-auto"); + }); } @Test() @@ -344,7 +349,7 @@ public void testAutoCreateMaximumQueueDepth() throws Exception { startScheduler(); // By default, max depth is 2, therefore this is an invalid scenario - Assert.assertThrows(SchedulerDynamicEditException.class, + assertThrows(SchedulerDynamicEditException.class, () -> createQueue("root.a.a3-auto.a4-auto.a5-auto")); // Set depth 3 for root.a, making it a valid scenario @@ -354,7 +359,7 @@ public void testAutoCreateMaximumQueueDepth() createQueue("root.a.a3-auto.a4-auto.a5-auto"); } catch (SchedulerDynamicEditException sde) { LOG.error("%s", sde); - Assert.fail("Depth is set for root.a, exception should not be thrown"); + Assertions.fail("Depth is set for root.a, exception should not be thrown"); } // Set global depth to 3 @@ -366,22 +371,24 @@ public void testAutoCreateMaximumQueueDepth() createQueue("root.a.a6-auto.a7-auto.a8-auto"); } catch (SchedulerDynamicEditException sde) { LOG.error("%s", sde); - Assert.fail("Depth is set globally, exception should not be thrown"); + Assertions.fail("Depth is set globally, exception should not be thrown"); } // Set depth on a dynamic queue, which has no effect on auto queue creation validation csConf.setMaximumAutoCreatedQueueDepth(new QueuePath("root.a.a6-auto.a7-auto.a8-auto"), 10); - Assert.assertThrows(SchedulerDynamicEditException.class, + assertThrows(SchedulerDynamicEditException.class, () -> createQueue("root.a.a6-auto.a7-auto.a8-auto.a9-auto.a10-auto.a11-auto")); } - @Test(expected = SchedulerDynamicEditException.class) + @Test public void testAutoCreateQueueShouldFailIfNotEnabledForParent() throws Exception { - startScheduler(); - csConf.setAutoQueueCreationV2Enabled(ROOT, false); - cs.reinitialize(csConf, mockRM.getRMContext()); - createQueue("root.c-auto"); + assertThrows(SchedulerDynamicEditException.class, ()->{ + startScheduler(); + csConf.setAutoQueueCreationV2Enabled(ROOT, false); + cs.reinitialize(csConf, mockRM.getRMContext()); + createQueue("root.c-auto"); + }); } @Test @@ -396,8 +403,8 @@ public void testAutoCreateQueueRefresh() throws Exception { // Double confirm, after refresh, we should still see root queue has 5 // children. - Assert.assertEquals(5, cs.getQueue("root").getChildQueues().size()); - Assert.assertNotNull(cs.getQueue("root.c-auto")); + Assertions.assertEquals(5, cs.getQueue("root").getChildQueues().size()); + Assertions.assertNotNull(cs.getQueue("root.c-auto")); } @Test @@ -412,17 +419,17 @@ public void testConvertDynamicToStaticQueue() throws Exception { // Double confirm, after refresh, we should still see root queue has 5 // children. - Assert.assertEquals(5, cs.getQueue("root").getChildQueues().size()); + Assertions.assertEquals(5, cs.getQueue("root").getChildQueues().size()); // Get queue a CSQueue a = cs.getQueue("root.a"); // a's abs resource should be 6/10, (since a.weight=6, all other 4 peers // have weight=1). - Assert.assertEquals(6 / 10f, a.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(720 * GB, + Assertions.assertEquals(6 / 10f, a.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(720 * GB, a.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(6f, a.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(6f, a.getQueueCapacities().getWeight(), 1e-6); // Set queue c-auto's weight to 6, and mark c-auto to be static queue csConf.setQueues(ROOT, new String[]{"a", "b", "c-auto"}); @@ -434,10 +441,10 @@ public void testConvertDynamicToStaticQueue() throws Exception { // c's abs resource should be 6/15, (since a/c.weight=6, all other 3 peers // have weight=1). - Assert.assertEquals(6 / 15f, c.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(480 * GB, + Assertions.assertEquals(6 / 15f, c.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(480 * GB, c.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(6f, c.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(6f, c.getQueueCapacities().getWeight(), 1e-6); // First, create e2-auto queue createQueue("root.e-auto.e2-auto"); @@ -456,9 +463,9 @@ public void testConvertDynamicToStaticQueue() throws Exception { // (since a/c/e.weight=6, all other 2 peers // have weight=1, and e1's weight is 6, e2's weight is 1). float e1NormalizedWeight = (6 / 20f) * (6 / 7f); - Assert.assertEquals(e1NormalizedWeight, e1.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(e1NormalizedWeight, e1.getAbsoluteCapacity(), 1e-6); assertQueueMinResource(e1, MAX_MEMORY * e1NormalizedWeight); - Assert.assertEquals(6f, e1.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(6f, e1.getQueueCapacities().getWeight(), 1e-6); } /* @@ -480,14 +487,14 @@ public void testConvertDynamicParentToStaticParent() throws Exception { CSQueue d = cs.getQueue("root.d-auto"); - Assert.assertEquals(1 / 8f, d.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1 / 8f, d.getAbsoluteCapacity(), 1e-6); assertQueueMinResource(d, MAX_MEMORY * (1 / 8f)); - Assert.assertEquals(1f, d.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(1f, d.getQueueCapacities().getWeight(), 1e-6); CSQueue d1 = cs.getQueue("root.d-auto.d1-auto"); - Assert.assertEquals(1 / 8f, d1.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1 / 8f, d1.getAbsoluteCapacity(), 1e-6); assertQueueMinResource(d1, MAX_MEMORY * (1 / 8f)); - Assert.assertEquals(1f, d1.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(1f, d1.getQueueCapacities().getWeight(), 1e-6); } @Test @@ -497,13 +504,13 @@ public void testAutoQueueCreationOnAppSubmission() throws Exception { submitApp(cs, USER0, USER0, "root.e-auto"); AbstractCSQueue e = (AbstractCSQueue) cs.getQueue("root.e-auto"); - Assert.assertNotNull(e); - Assert.assertTrue(e.isDynamicQueue()); + Assertions.assertNotNull(e); + Assertions.assertTrue(e.isDynamicQueue()); AbstractCSQueue user0 = (AbstractCSQueue) cs.getQueue( "root.e-auto." + USER0); - Assert.assertNotNull(user0); - Assert.assertTrue(user0.isDynamicQueue()); + Assertions.assertNotNull(user0); + Assertions.assertTrue(user0.isDynamicQueue()); } @Test @@ -521,8 +528,8 @@ public void testChildlessParentQueueWhenAutoQueueCreationEnabled() cs.reinitialize(csConf, mockRM.getRMContext()); CSQueue empty = cs.getQueue("root.empty-auto-parent"); - Assert.assertTrue("empty-auto-parent is not a LeafQueue", - empty instanceof LeafQueue); + Assertions.assertTrue( + empty instanceof LeafQueue, "empty-auto-parent is not a LeafQueue"); empty.stopQueue(); csConf.setQueues(ROOT, new String[]{"a", "b", "empty-auto-parent"}); @@ -537,13 +544,13 @@ public void testChildlessParentQueueWhenAutoQueueCreationEnabled() cs.reinitialize(csConf, mockRM.getRMContext()); empty = cs.getQueue("root.empty-auto-parent"); - Assert.assertTrue("empty-auto-parent is not a ParentQueue", - empty instanceof AbstractParentQueue); - Assert.assertEquals("empty-auto-parent has children", - 0, empty.getChildQueues().size()); - Assert.assertTrue("empty-auto-parent is not eligible " + - "for auto queue creation", - ((AbstractParentQueue)empty).isEligibleForAutoQueueCreation()); + Assertions.assertTrue( + empty instanceof AbstractParentQueue, "empty-auto-parent is not a ParentQueue"); + Assertions.assertEquals( + 0, empty.getChildQueues().size(), "empty-auto-parent has children"); + Assertions.assertTrue( + ((AbstractParentQueue)empty).isEligibleForAutoQueueCreation(), "empty-auto-parent is not eligible " + + "for auto queue creation"); } @Test @@ -563,7 +570,7 @@ public void testAutoQueueCreationWithDisabledMappingRules() throws Exception { cs.handle(addAttemptEvent); CSQueue a2Auto = cs.getQueue("root.a.a1-auto.a2-auto"); - Assert.assertNotNull(a2Auto); + Assertions.assertNotNull(a2Auto); } @Test @@ -574,31 +581,31 @@ public void testAutoCreateQueueUserLimitDisabled() throws Exception { submitApp(cs, USER0, USER0, "root.e-auto"); AbstractCSQueue e = (AbstractCSQueue) cs.getQueue("root.e-auto"); - Assert.assertNotNull(e); - Assert.assertTrue(e.isDynamicQueue()); + Assertions.assertNotNull(e); + Assertions.assertTrue(e.isDynamicQueue()); AbstractCSQueue user0 = (AbstractCSQueue) cs.getQueue( "root.e-auto." + USER0); - Assert.assertNotNull(user0); - Assert.assertTrue(user0.isDynamicQueue()); - Assert.assertTrue(user0 instanceof LeafQueue); + Assertions.assertNotNull(user0); + Assertions.assertTrue(user0.isDynamicQueue()); + Assertions.assertTrue(user0 instanceof LeafQueue); LeafQueue user0LeafQueue = (LeafQueue) user0; // Assert user limit factor is -1 - Assert.assertTrue(user0LeafQueue.getUserLimitFactor() == -1); + Assertions.assertTrue(user0LeafQueue.getUserLimitFactor() == -1); // Assert user max applications not limited - Assert.assertEquals(user0LeafQueue.getMaxApplicationsPerUser(), + Assertions.assertEquals(user0LeafQueue.getMaxApplicationsPerUser(), user0LeafQueue.getMaxApplications()); // Assert AM Resource - Assert.assertEquals(user0LeafQueue.getAMResourceLimit().getMemorySize(), + Assertions.assertEquals(user0LeafQueue.getAMResourceLimit().getMemorySize(), user0LeafQueue. getMaxAMResourcePerQueuePercent() * MAX_MEMORY * GB, 1e-6); // Assert user limit (no limit) when limit factor is -1 - Assert.assertEquals(MAX_MEMORY * GB, + Assertions.assertEquals(MAX_MEMORY * GB, user0LeafQueue.getEffectiveMaxCapacityDown("", user0LeafQueue.getMinimumAllocation()).getMemorySize(), 1e-6); } @@ -610,14 +617,14 @@ public void testAutoQueueCreationMaxAppUpdate() throws Exception { // When no conf for max apps LeafQueue a1 = (LeafQueue)cs. getQueue("root.a.a1"); - Assert.assertNotNull(a1); - Assert.assertEquals(csConf.getMaximumSystemApplications() + Assertions.assertNotNull(a1); + Assertions.assertEquals(csConf.getMaximumSystemApplications() * a1.getAbsoluteCapacity(), a1.getMaxApplications(), 1); LeafQueue b = (LeafQueue)cs. getQueue("root.b"); - Assert.assertNotNull(b); - Assert.assertEquals(csConf.getMaximumSystemApplications() + Assertions.assertNotNull(b); + Assertions.assertEquals(csConf.getMaximumSystemApplications() * b.getAbsoluteCapacity(), b.getMaxApplications(), 1); createQueue("root.e"); @@ -626,47 +633,49 @@ public void testAutoQueueCreationMaxAppUpdate() throws Exception { // max app correct. LeafQueue e = (LeafQueue)cs. getQueue("root.e"); - Assert.assertNotNull(e); - Assert.assertEquals(csConf.getMaximumSystemApplications() + Assertions.assertNotNull(e); + Assertions.assertEquals(csConf.getMaximumSystemApplications() * e.getAbsoluteCapacity(), e.getMaxApplications(), 1); a1 = (LeafQueue)cs. getQueue("root.a.a1"); - Assert.assertNotNull(a1); - Assert.assertEquals(csConf.getMaximumSystemApplications() + Assertions.assertNotNull(a1); + Assertions.assertEquals(csConf.getMaximumSystemApplications() * a1.getAbsoluteCapacity(), a1.getMaxApplications(), 1); b = (LeafQueue)cs. getQueue("root.b"); - Assert.assertNotNull(b); - Assert.assertEquals(csConf.getMaximumSystemApplications() + Assertions.assertNotNull(b); + Assertions.assertEquals(csConf.getMaximumSystemApplications() * b.getAbsoluteCapacity(), b.getMaxApplications(), 1); // When update global max app per queue csConf.setGlobalMaximumApplicationsPerQueue(1000); cs.reinitialize(csConf, mockRM.getRMContext()); - Assert.assertEquals(1000, b.getMaxApplications()); - Assert.assertEquals(1000, a1.getMaxApplications()); - Assert.assertEquals(1000, e.getMaxApplications()); + Assertions.assertEquals(1000, b.getMaxApplications()); + Assertions.assertEquals(1000, a1.getMaxApplications()); + Assertions.assertEquals(1000, e.getMaxApplications()); // when set some queue for max apps csConf.setMaximumApplicationsPerQueue(new QueuePath("root.e1"), 50); createQueue("root.e1"); LeafQueue e1 = (LeafQueue)cs. getQueue("root.e1"); - Assert.assertNotNull(e1); + Assertions.assertNotNull(e1); cs.reinitialize(csConf, mockRM.getRMContext()); - Assert.assertEquals(50, e1.getMaxApplications()); + Assertions.assertEquals(50, e1.getMaxApplications()); } - @Test(expected = SchedulerDynamicEditException.class) + @Test public void testAutoCreateQueueWithAmbiguousNonFullPathParentName() throws Exception { - startScheduler(); + assertThrows(SchedulerDynamicEditException.class, ()->{ + startScheduler(); - createQueue("root.a.a"); - createQueue("a.a"); + createQueue("root.a.a"); + createQueue("a.a"); + }); } @Test @@ -676,7 +685,7 @@ public void testAutoCreateQueueIfFirstExistingParentQueueIsNotStatic() // create a dynamic ParentQueue createQueue("root.a.a-parent-auto.a1-leaf-auto"); - Assert.assertNotNull(cs.getQueue("root.a.a-parent-auto")); + Assertions.assertNotNull(cs.getQueue("root.a.a-parent-auto")); // create a new dynamic LeafQueue under the existing ParentQueue createQueue("root.a.a-parent-auto.a2-leaf-auto"); @@ -684,7 +693,7 @@ public void testAutoCreateQueueIfFirstExistingParentQueueIsNotStatic() CSQueue a2Leaf = cs.getQueue("a2-leaf-auto"); // Make sure a2-leaf-auto is under a-parent-auto - Assert.assertEquals("root.a.a-parent-auto", + Assertions.assertEquals("root.a.a-parent-auto", a2Leaf.getParent().getQueuePath()); } @@ -693,18 +702,18 @@ public void testAutoCreateQueueIfAmbiguousQueueNames() throws Exception { startScheduler(); AbstractCSQueue b = (AbstractCSQueue) cs.getQueue("root.b"); - Assert.assertFalse(b.isDynamicQueue()); + Assertions.assertFalse(b.isDynamicQueue()); createQueue("root.a.b.b"); AbstractCSQueue bAutoParent = (AbstractCSQueue) cs.getQueue("root.a.b"); - Assert.assertTrue(bAutoParent.isDynamicQueue()); - Assert.assertTrue(bAutoParent.hasChildQueues()); + Assertions.assertTrue(bAutoParent.isDynamicQueue()); + Assertions.assertTrue(bAutoParent.hasChildQueues()); AbstractCSQueue bAutoLeafQueue = (AbstractCSQueue) cs.getQueue("root.a.b.b"); - Assert.assertTrue(bAutoLeafQueue.isDynamicQueue()); - Assert.assertFalse(bAutoLeafQueue.hasChildQueues()); + Assertions.assertTrue(bAutoLeafQueue.isDynamicQueue()); + Assertions.assertFalse(bAutoLeafQueue.hasChildQueues()); } @Test @@ -721,9 +730,9 @@ public void testAutoCreateQueueMaxQueuesLimit() throws Exception { // Check if max queue limit can't be exceeded try { createQueue("root.e.q_6"); - Assert.fail("Can't exceed max queue limit."); + Assertions.fail("Can't exceed max queue limit."); } catch (Exception ex) { - Assert.assertTrue(ex + Assertions.assertTrue(ex instanceof SchedulerDynamicEditException); } } @@ -741,12 +750,12 @@ public void testAutoCreatedQueueTemplateConfig() throws Exception { cs.reinitialize(csConf, mockRM.getRMContext()); AbstractLeafQueue a2 = createQueue("root.a.a-auto.a2"); - Assert.assertEquals("weight is not set by template", 6f, - a2.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals("user limit factor should be disabled with dynamic queues", - -1f, a2.getUserLimitFactor(), 1e-6); - Assert.assertEquals("maximum AM resource percent should be 1 with dynamic queues", - 1f, a2.getMaxAMResourcePerQueuePercent(), 1e-6); + Assertions.assertEquals(6f, + a2.getQueueCapacities().getWeight(), 1e-6, "weight is not set by template"); + Assertions.assertEquals( + -1f, a2.getUserLimitFactor(), 1e-6, "user limit factor should be disabled with dynamic queues"); + Assertions.assertEquals( + 1f, a2.getMaxAMResourcePerQueuePercent(), 1e-6, "maximum AM resource percent should be 1 with dynamic queues"); // Set the user-limit-factor and maximum-am-resource-percent via templates to ensure their // modified defaults are indeed overridden @@ -757,26 +766,26 @@ public void testAutoCreatedQueueTemplateConfig() throws Exception { cs.reinitialize(csConf, mockRM.getRMContext()); a2 = (LeafQueue) cs.getQueue("root.a.a-auto.a2"); - Assert.assertEquals("weight is overridden", 6f, - a2.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals("user limit factor should be modified by templates", - 10f, a2.getUserLimitFactor(), 1e-6); - Assert.assertEquals("maximum AM resource percent should be modified by templates", - 0.8f, a2.getMaxAMResourcePerQueuePercent(), 1e-6); + Assertions.assertEquals(6f, + a2.getQueueCapacities().getWeight(), 1e-6, "weight is overridden"); + Assertions.assertEquals( + 10f, a2.getUserLimitFactor(), 1e-6, "user limit factor should be modified by templates"); + Assertions.assertEquals( + 0.8f, a2.getMaxAMResourcePerQueuePercent(), 1e-6, "maximum AM resource percent should be modified by templates"); csConf.setNonLabeledQueueWeight(new QueuePath("root.a.a-auto.a2"), 4f); cs.reinitialize(csConf, mockRM.getRMContext()); - Assert.assertEquals("weight is not explicitly set", 4f, - a2.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(4f, + a2.getQueueCapacities().getWeight(), 1e-6, "weight is not explicitly set"); csConf.setBoolean(AutoCreatedQueueTemplate.getAutoQueueTemplatePrefix( aQueuePath) + CapacitySchedulerConfiguration .AUTO_CREATE_CHILD_QUEUE_AUTO_REMOVAL_ENABLE, false); cs.reinitialize(csConf, mockRM.getRMContext()); AbstractLeafQueue a3 = createQueue("root.a.a3"); - Assert.assertFalse("auto queue deletion should be turned off on a3", - a3.isEligibleForAutoDeletion()); + Assertions.assertFalse( + a3.isEligibleForAutoDeletion(), "auto queue deletion should be turned off on a3"); // Set the capacity of label TEST csConf.set(AutoCreatedQueueTemplate.getAutoQueueTemplatePrefix( @@ -785,12 +794,12 @@ public void testAutoCreatedQueueTemplateConfig() throws Exception { csConf.setAutoQueueCreationV2Enabled(C, true); cs.reinitialize(csConf, mockRM.getRMContext()); AbstractLeafQueue c1 = createQueue("root.c.c1"); - Assert.assertEquals("weight is not set for label TEST", 6f, - c1.getQueueCapacities().getWeight("TEST"), 1e-6); + Assertions.assertEquals(6f, + c1.getQueueCapacities().getWeight("TEST"), 1e-6, "weight is not set for label TEST"); cs.reinitialize(csConf, mockRM.getRMContext()); c1 = (AbstractLeafQueue) cs.getQueue("root.c.c1"); - Assert.assertEquals("weight is not set for label TEST", 6f, - c1.getQueueCapacities().getWeight("TEST"), 1e-6); + Assertions.assertEquals(6f, + c1.getQueueCapacities().getWeight("TEST"), 1e-6, "weight is not set for label TEST"); } @Test @@ -800,19 +809,19 @@ public void testAutoCreatedQueueConfigChange() throws Exception { csConf.setNonLabeledQueueWeight(a2.getQueuePathObject(), 4f); cs.reinitialize(csConf, mockRM.getRMContext()); - Assert.assertEquals("weight is not explicitly set", 4f, - a2.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(4f, + a2.getQueueCapacities().getWeight(), 1e-6, "weight is not explicitly set"); a2 = (AbstractLeafQueue) cs.getQueue("root.a.a-auto.a2"); csConf.setState(A_A_AUTO_A2, QueueState.STOPPED); cs.reinitialize(csConf, mockRM.getRMContext()); - Assert.assertEquals("root.a.a-auto.a2 has not been stopped", - QueueState.STOPPED, a2.getState()); + Assertions.assertEquals( + QueueState.STOPPED, a2.getState(), "root.a.a-auto.a2 has not been stopped"); csConf.setState(A_A_AUTO_A2, QueueState.RUNNING); cs.reinitialize(csConf, mockRM.getRMContext()); - Assert.assertEquals("root.a.a-auto.a2 is not running", - QueueState.RUNNING, a2.getState()); + Assertions.assertEquals( + QueueState.RUNNING, a2.getState(), "root.a.a-auto.a2 is not running"); } @Test @@ -826,27 +835,27 @@ public void testAutoCreateQueueState() throws Exception { cs.reinitialize(csConf, mockRM.getRMContext()); // Make sure the static queue is stopped - Assert.assertEquals(cs.getQueue("root.a").getState(), + Assertions.assertEquals(cs.getQueue("root.a").getState(), QueueState.STOPPED); // If not set, default is the queue state of parent - Assert.assertEquals(cs.getQueue("root.a.a1").getState(), + Assertions.assertEquals(cs.getQueue("root.a.a1").getState(), QueueState.STOPPED); - Assert.assertEquals(cs.getQueue("root.e").getState(), + Assertions.assertEquals(cs.getQueue("root.e").getState(), QueueState.STOPPED); - Assert.assertEquals(cs.getQueue("root.e.e1").getState(), + Assertions.assertEquals(cs.getQueue("root.e.e1").getState(), QueueState.STOPPED); // Make root.e state to RUNNING csConf.setState(E, QueueState.RUNNING); cs.reinitialize(csConf, mockRM.getRMContext()); - Assert.assertEquals(cs.getQueue("root.e.e1").getState(), + Assertions.assertEquals(cs.getQueue("root.e.e1").getState(), QueueState.STOPPED); // Make root.e.e1 state to RUNNING csConf.setState(E_E1, QueueState.RUNNING); cs.reinitialize(csConf, mockRM.getRMContext()); - Assert.assertEquals(cs.getQueue("root.e.e1").getState(), + Assertions.assertEquals(cs.getQueue("root.e.e1").getState(), QueueState.RUNNING); } @@ -858,11 +867,11 @@ public void testAutoQueueCreationDepthLimitFromStaticParent() // a is the first existing queue here and it is static, therefore // the distance is 2 createQueue("root.a.a-auto.a1-auto"); - Assert.assertNotNull(cs.getQueue("root.a.a-auto.a1-auto")); + Assertions.assertNotNull(cs.getQueue("root.a.a-auto.a1-auto")); try { createQueue("root.a.a-auto.a2-auto.a3-auto"); - Assert.fail("Queue creation should not succeed because the distance " + + Assertions.fail("Queue creation should not succeed because the distance " + "from the first static parent is above limit"); } catch (SchedulerDynamicEditException ignored) { @@ -884,11 +893,11 @@ public void testCapacitySchedulerAutoQueueDeletion() throws Exception { policies.add( AutoCreatedQueueDeletionPolicy.class.getCanonicalName()); - Assert.assertTrue( - "No AutoCreatedQueueDeletionPolicy " + - "is present in running monitors", - cs.getSchedulingMonitorManager(). - isSameConfiguredPolicies(policies)); + Assertions.assertTrue( + + cs.getSchedulingMonitorManager(). + isSameConfiguredPolicies(policies), "No AutoCreatedQueueDeletionPolicy " + + "is present in running monitors"); ApplicationAttemptId a2App = submitApp(cs, USER0, "a2-auto", "root.a.a1-auto"); @@ -900,15 +909,15 @@ public void testCapacitySchedulerAutoQueueDeletion() throws Exception { AbstractCSQueue a1 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto"); - Assert.assertNotNull("a1 is not present", a1); + Assertions.assertNotNull(a1, "a1 is not present"); AbstractCSQueue a2 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto.a2-auto"); - Assert.assertNotNull("a2 is not present", a2); - Assert.assertTrue("a2 is not a dynamic queue", - a2.isDynamicQueue()); + Assertions.assertNotNull(a2, "a2 is not present"); + Assertions.assertTrue( + a2.isDynamicQueue(), "a2 is not a dynamic queue"); // Now there are still 1 app in a2 queue. - Assert.assertEquals(1, a2.getNumApplications()); + Assertions.assertEquals(1, a2.getNumApplications()); // Wait the time expired. long l1 = a2.getLastSubmittedTimestamp(); @@ -921,7 +930,7 @@ public void testCapacitySchedulerAutoQueueDeletion() throws Exception { // when expired with remaining apps. a2 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto.a2-auto"); - Assert.assertNotNull("a2 is not present", a2); + Assertions.assertNotNull(a2, "a2 is not present"); // Make app finished. AppAttemptRemovedSchedulerEvent event = @@ -933,7 +942,7 @@ public void testCapacitySchedulerAutoQueueDeletion() throws Exception { cs.handle(rEvent); // Now there are no apps in a2 queue. - Assert.assertEquals(0, a2.getNumApplications()); + Assertions.assertEquals(0, a2.getNumApplications()); // Wait the a2 deleted. GenericTestUtils.waitFor(() -> { @@ -944,12 +953,12 @@ public void testCapacitySchedulerAutoQueueDeletion() throws Exception { a2 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto.a2-auto"); - Assert.assertNull("a2 is not deleted", a2); + Assertions.assertNull(a2, "a2 is not deleted"); // The parent will not be deleted with child queues a1 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto"); - Assert.assertNotNull("a1 is not present", a1); + Assertions.assertNotNull(a1, "a1 is not present"); // Now the parent queue without child // will be deleted for expired. @@ -961,7 +970,7 @@ public void testCapacitySchedulerAutoQueueDeletion() throws Exception { }, 100, 3000); a1 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto"); - Assert.assertNull("a1 is not deleted", a1); + Assertions.assertNull(a1, "a1 is not deleted"); } @Test @@ -982,11 +991,11 @@ public void testCapacitySchedulerAutoQueueDeletionDisabled() policies.add( AutoCreatedQueueDeletionPolicy.class.getCanonicalName()); - Assert.assertTrue( - "No AutoCreatedQueueDeletionPolicy " + - "is present in running monitors", - cs.getSchedulingMonitorManager(). - isSameConfiguredPolicies(policies)); + Assertions.assertTrue( + + cs.getSchedulingMonitorManager(). + isSameConfiguredPolicies(policies), "No AutoCreatedQueueDeletionPolicy " + + "is present in running monitors"); ApplicationAttemptId a2App = submitApp(cs, USER0, "a2-auto", "root.a.a1-auto"); @@ -998,12 +1007,12 @@ public void testCapacitySchedulerAutoQueueDeletionDisabled() AbstractCSQueue a1 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto"); - Assert.assertNotNull("a1 is not present", a1); + Assertions.assertNotNull(a1, "a1 is not present"); AbstractCSQueue a2 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto.a2-auto"); - Assert.assertNotNull("a2 is not present", a2); - Assert.assertTrue("a2 is not a dynamic queue", - a2.isDynamicQueue()); + Assertions.assertNotNull(a2, "a2 is not present"); + Assertions.assertTrue( + a2.isDynamicQueue(), "a2 is not a dynamic queue"); // Make app finished. AppAttemptRemovedSchedulerEvent event = @@ -1015,7 +1024,7 @@ public void testCapacitySchedulerAutoQueueDeletionDisabled() cs.handle(rEvent); // Now there are no apps in a2 queue. - Assert.assertEquals(0, a2.getNumApplications()); + Assertions.assertEquals(0, a2.getNumApplications()); // Wait the time expired. long l1 = a2.getLastSubmittedTimestamp(); @@ -1027,12 +1036,12 @@ public void testCapacitySchedulerAutoQueueDeletionDisabled() // The auto deletion is no enabled for a2-auto a1 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto"); - Assert.assertNotNull("a1 is not present", a1); + Assertions.assertNotNull(a1, "a1 is not present"); a2 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto.a2-auto"); - Assert.assertNotNull("a2 is not present", a2); - Assert.assertTrue("a2 is not a dynamic queue", - a2.isDynamicQueue()); + Assertions.assertNotNull(a2, "a2 is not present"); + Assertions.assertTrue( + a2.isDynamicQueue(), "a2 is not a dynamic queue"); // Enabled now // The auto deletion will work. @@ -1049,11 +1058,11 @@ public void testCapacitySchedulerAutoQueueDeletionDisabled() a2 = (AbstractCSQueue) cs. getQueue("root.a.a1-auto.a2-auto"); - Assert.assertNull("a2 is not deleted", a2); + Assertions.assertNull(a2, "a2 is not deleted"); // The parent will not be deleted with child queues a1 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto"); - Assert.assertNotNull("a1 is not present", a1); + Assertions.assertNotNull(a1, "a1 is not present"); // Now the parent queue without child // will be deleted for expired. @@ -1065,7 +1074,7 @@ public void testCapacitySchedulerAutoQueueDeletionDisabled() }, 100, 3000); a1 = (AbstractCSQueue) cs.getQueue( "root.a.a1-auto"); - Assert.assertNull("a1 is not deleted", a1); + Assertions.assertNull(a1, "a1 is not deleted"); } @Test @@ -1084,56 +1093,56 @@ public void testAutoCreateQueueAfterRemoval() throws Exception { // Under e, there's only one queue, so e1/e have same capacity CSQueue e1 = cs.getQueue("root.e-auto.e1-auto"); - Assert.assertEquals(1 / 5f, e1.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, e1.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(240 * GB, + Assertions.assertEquals(1 / 5f, e1.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, e1.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(240 * GB, e1.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Check after removal e1. cs.removeQueue(e1); CSQueue e = cs.getQueue("root.e-auto"); - Assert.assertEquals(1 / 5f, e.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, e.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(240 * GB, + Assertions.assertEquals(1 / 5f, e.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, e.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(240 * GB, e.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Check after removal e. cs.removeQueue(e); CSQueue d = cs.getQueue("root.d-auto"); - Assert.assertEquals(1 / 4f, d.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, d.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(300 * GB, + Assertions.assertEquals(1 / 4f, d.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, d.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(300 * GB, d.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Check after removal d. cs.removeQueue(d); CSQueue c = cs.getQueue("root.c-auto"); - Assert.assertEquals(1 / 3f, c.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(400 * GB, + Assertions.assertEquals(1 / 3f, c.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, c.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(400 * GB, c.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Check after removal c. cs.removeQueue(c); CSQueue b = cs.getQueue("root.b"); - Assert.assertEquals(1 / 2f, b.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, b.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(600 * GB, + Assertions.assertEquals(1 / 2f, b.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, b.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(600 * GB, b.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); // Check can't remove static queue b. try { cs.removeQueue(b); - Assert.fail("Can't remove static queue b!"); + Assertions.fail("Can't remove static queue b!"); } catch (Exception ex) { - Assert.assertTrue(ex + Assertions.assertTrue(ex instanceof SchedulerDynamicEditException); } // Check a. CSQueue a = cs.getQueue("root.a"); - Assert.assertEquals(1 / 2f, a.getAbsoluteCapacity(), 1e-6); - Assert.assertEquals(1f, a.getQueueCapacities().getWeight(), 1e-6); - Assert.assertEquals(600 * GB, + Assertions.assertEquals(1 / 2f, a.getAbsoluteCapacity(), 1e-6); + Assertions.assertEquals(1f, a.getQueueCapacities().getWeight(), 1e-6); + Assertions.assertEquals(600 * GB, b.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); } @@ -1143,32 +1152,32 @@ public void testQueueInfoIfAmbiguousQueueNames() throws Exception { AbstractCSQueue b = (AbstractCSQueue) cs. getQueue("root.b"); - Assert.assertFalse(b.isDynamicQueue()); - Assert.assertEquals("root.b", + Assertions.assertFalse(b.isDynamicQueue()); + Assertions.assertEquals("root.b", b.getQueueInfo().getQueuePath()); createQueue("root.a.b.b"); AbstractCSQueue bAutoParent = (AbstractCSQueue) cs. getQueue("root.a.b"); - Assert.assertTrue(bAutoParent.isDynamicQueue()); - Assert.assertTrue(bAutoParent.hasChildQueues()); - Assert.assertEquals("root.a.b", + Assertions.assertTrue(bAutoParent.isDynamicQueue()); + Assertions.assertTrue(bAutoParent.hasChildQueues()); + Assertions.assertEquals("root.a.b", bAutoParent.getQueueInfo().getQueuePath()); AbstractCSQueue bAutoLeafQueue = (AbstractCSQueue) cs.getQueue("root.a.b.b"); - Assert.assertTrue(bAutoLeafQueue.isDynamicQueue()); - Assert.assertFalse(bAutoLeafQueue.hasChildQueues()); - Assert.assertEquals("root.a.b.b", + Assertions.assertTrue(bAutoLeafQueue.isDynamicQueue()); + Assertions.assertFalse(bAutoLeafQueue.hasChildQueues()); + Assertions.assertEquals("root.a.b.b", bAutoLeafQueue.getQueueInfo().getQueuePath()); // Make sure all queue name are ambiguous - Assert.assertEquals("b", + Assertions.assertEquals("b", b.getQueueInfo().getQueueName()); - Assert.assertEquals("b", + Assertions.assertEquals("b", bAutoParent.getQueueInfo().getQueueName()); - Assert.assertEquals("b", + Assertions.assertEquals("b", bAutoLeafQueue.getQueueInfo().getQueueName()); } @@ -1180,21 +1189,21 @@ public void testRemoveDanglingAutoCreatedQueuesOnReinit() throws Exception { createQueue("root.a.a-auto"); AbstractCSQueue aAuto = (AbstractCSQueue) cs. getQueue("root.a.a-auto"); - Assert.assertTrue(aAuto.isDynamicQueue()); + Assertions.assertTrue(aAuto.isDynamicQueue()); csConf.setState(A, QueueState.STOPPED); cs.reinitialize(csConf, mockRM.getRMContext()); aAuto = (AbstractCSQueue) cs. getQueue("root.a.a-auto"); - Assert.assertEquals("root.a.a-auto is not in STOPPED state", QueueState.STOPPED, aAuto.getState()); + Assertions.assertEquals(QueueState.STOPPED, aAuto.getState(), "root.a.a-auto is not in STOPPED state"); csConf.setQueues(ROOT, new String[]{"b"}); cs.reinitialize(csConf, mockRM.getRMContext()); CSQueue aAutoNew = cs.getQueue("root.a.a-auto"); - Assert.assertNull(aAutoNew); + Assertions.assertNull(aAutoNew); submitApp(cs, USER0, "a-auto", "root.a"); aAutoNew = cs.getQueue("root.a.a-auto"); - Assert.assertNotNull(aAutoNew); + Assertions.assertNotNull(aAutoNew); // Validate static grandparent deletion csConf.setQueues(ROOT, new String[]{"a", "b"}); @@ -1204,12 +1213,12 @@ public void testRemoveDanglingAutoCreatedQueuesOnReinit() throws Exception { createQueue("root.a.a1.a1-auto"); CSQueue a1Auto = cs.getQueue("root.a.a1.a1-auto"); - Assert.assertNotNull("a1-auto should exist", a1Auto); + Assertions.assertNotNull(a1Auto, "a1-auto should exist"); csConf.setQueues(ROOT, new String[]{"b"}); cs.reinitialize(csConf, mockRM.getRMContext()); a1Auto = cs.getQueue("root.a.a1.a1-auto"); - Assert.assertNull("a1-auto has no parent and should not exist", a1Auto); + Assertions.assertNull(a1Auto, "a1-auto has no parent and should not exist"); // Validate dynamic parent deletion csConf.setState(B, QueueState.STOPPED); @@ -1219,17 +1228,17 @@ public void testRemoveDanglingAutoCreatedQueuesOnReinit() throws Exception { createQueue("root.b.b-auto-parent.b-auto-leaf"); CSQueue bAutoParent = cs.getQueue("root.b.b-auto-parent"); - Assert.assertNotNull("b-auto-parent should exist", bAutoParent); + Assertions.assertNotNull(bAutoParent, "b-auto-parent should exist"); ParentQueue b = (ParentQueue) cs.getQueue("root.b"); b.removeChildQueue(bAutoParent); cs.reinitialize(csConf, mockRM.getRMContext()); bAutoParent = cs.getQueue("root.b.b-auto-parent"); - Assert.assertNull("b-auto-parent should not exist ", bAutoParent); + Assertions.assertNull(bAutoParent, "b-auto-parent should not exist "); CSQueue bAutoLeaf = cs.getQueue("root.b.b-auto-parent.b-auto-leaf"); - Assert.assertNull("b-auto-leaf should not exist " + - "when its dynamic parent is removed", bAutoLeaf); + Assertions.assertNull(bAutoLeaf, "b-auto-leaf should not exist " + + "when its dynamic parent is removed"); } @Test @@ -1240,20 +1249,20 @@ public void testParentQueueDynamicChildRemoval() throws Exception { createQueue("root.a.a-auto"); AbstractCSQueue aAuto = (AbstractCSQueue) cs. getQueue("root.a.a-auto"); - Assert.assertTrue(aAuto.isDynamicQueue()); + Assertions.assertTrue(aAuto.isDynamicQueue()); ParentQueue a = (ParentQueue) cs. getQueue("root.a"); createQueue("root.e.e1-auto"); AbstractCSQueue eAuto = (AbstractCSQueue) cs. getQueue("root.e.e1-auto"); - Assert.assertTrue(eAuto.isDynamicQueue()); + Assertions.assertTrue(eAuto.isDynamicQueue()); ParentQueue e = (ParentQueue) cs. getQueue("root.e"); // Try to remove a static child queue try { a.removeChildQueue(cs.getQueue("root.a.a1")); - Assert.fail("root.a.a1 is a static queue and should not be removed at " + + Assertions.fail("root.a.a1 is a static queue and should not be removed at " + "runtime"); } catch (SchedulerDynamicEditException ignored) { } @@ -1261,7 +1270,7 @@ public void testParentQueueDynamicChildRemoval() throws Exception { // Try to remove a dynamic queue with a different parent try { a.removeChildQueue(eAuto); - Assert.fail("root.a should not be able to remove root.e.e1-auto"); + Assertions.fail("root.a should not be able to remove root.e.e1-auto"); } catch (SchedulerDynamicEditException ignored) { } @@ -1273,18 +1282,18 @@ public void testParentQueueDynamicChildRemoval() throws Exception { eAuto = (AbstractCSQueue) cs. getQueue("root.e.e1-auto"); - Assert.assertNull("root.a.a-auto should have been removed", aAuto); - Assert.assertNull("root.e.e1-auto should have been removed", eAuto); + Assertions.assertNull(aAuto, "root.a.a-auto should have been removed"); + Assertions.assertNull(eAuto, "root.e.e1-auto should have been removed"); } @Test() public void testAutoCreateInvalidParent() throws Exception { startScheduler(); - Assert.assertThrows(SchedulerDynamicEditException.class, + assertThrows(SchedulerDynamicEditException.class, () -> createQueue("invalid.queue")); - Assert.assertThrows(SchedulerDynamicEditException.class, + assertThrows(SchedulerDynamicEditException.class, () -> createQueue("invalid.queue.longer")); - Assert.assertThrows(SchedulerDynamicEditException.class, + assertThrows(SchedulerDynamicEditException.class, () -> createQueue("invalidQueue")); } @@ -1294,7 +1303,7 @@ protected AbstractLeafQueue createQueue(String queuePath) throws YarnException, } private void assertQueueMinResource(CSQueue queue, float expected) { - Assert.assertEquals(Math.round(expected * GB), + Assertions.assertEquals(Math.round(expected * GB), queue.getQueueResourceQuotas().getEffectiveMinResource() .getMemorySize(), 1e-6); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreationWithCapacityVectors.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreationWithCapacityVectors.java index d7083b3ba0c35..9918683b2c9a2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreationWithCapacityVectors.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNewQueueAutoCreationWithCapacityVectors.java @@ -25,10 +25,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.NullRMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; -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 java.io.IOException; @@ -55,7 +55,7 @@ public CapacityScheduler getCs() { / a1 */ - @Before + @BeforeEach public void setUp() throws Exception { csConf = new CapacitySchedulerConfiguration(); csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -63,7 +63,7 @@ public void setUp() throws Exception { csConf.setLegacyQueueModeEnabled(false); } - @After + @AfterEach public void tearDown() { if (mockRM != null) { mockRM.stop(); @@ -186,36 +186,36 @@ public void testBasicAbsoluteConfiguration() throws Exception { private void validateBasicConfiguration() throws Exception { CSQueue a = cs.getQueue(A_PATH); - Assert.assertEquals(8 / 32f, a.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, a.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(8000, + Assertions.assertEquals(8 / 32f, a.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, a.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(8000, a.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(8, + Assertions.assertEquals(8, a.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); createQueue("root.b-auto"); CSQueue bAuto = cs.getQueue("root.b-auto"); - Assert.assertEquals(2 / 32f, bAuto.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, bAuto.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(2000, + Assertions.assertEquals(2 / 32f, bAuto.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, bAuto.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(2000, bAuto.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(2, + Assertions.assertEquals(2, bAuto.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); - Assert.assertEquals(((LeafQueue) bAuto).getUserLimitFactor(), -1, EPSILON); - Assert.assertEquals(((LeafQueue) bAuto).getMaxAMResourcePerQueuePercent(), 1, EPSILON); + Assertions.assertEquals(((LeafQueue) bAuto).getUserLimitFactor(), -1, EPSILON); + Assertions.assertEquals(((LeafQueue) bAuto).getMaxAMResourcePerQueuePercent(), 1, EPSILON); createQueue("root.a.a1-auto"); CSQueue a1Auto = cs.getQueue("root.a.a1-auto"); - Assert.assertEquals(2 / 32f, a1Auto.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, a1Auto.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(2000, + Assertions.assertEquals(2 / 32f, a1Auto.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, a1Auto.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(2000, a1Auto.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(4, + Assertions.assertEquals(4, a1Auto.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); - Assert.assertEquals(((LeafQueue) a1Auto).getUserLimitFactor(), -1, EPSILON); - Assert.assertEquals(((LeafQueue) a1Auto).getMaxAMResourcePerQueuePercent(), 1, EPSILON); + Assertions.assertEquals(((LeafQueue) a1Auto).getUserLimitFactor(), -1, EPSILON); + Assertions.assertEquals(((LeafQueue) a1Auto).getMaxAMResourcePerQueuePercent(), 1, EPSILON); } /* @@ -241,14 +241,14 @@ public void testMixedFlexibleConfiguration() throws Exception { // b takes 2000 MB from the cluster, a and d take up 10 + 10 = 20% (6000 MB, 6 vcore), // so c-auto should get the rest (24000 MB, 24 vcore) because it's the only one // with configured weights - Assert.assertEquals(24 / 32f, cAuto.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, cAuto.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(24000, + Assertions.assertEquals(24 / 32f, cAuto.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, cAuto.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(24000, cAuto.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(24, + Assertions.assertEquals(24, cAuto.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); - Assert.assertEquals(((LeafQueue) cAuto).getUserLimitFactor(), -1, EPSILON); - Assert.assertEquals(((LeafQueue) cAuto).getMaxAMResourcePerQueuePercent(), 1, EPSILON); + Assertions.assertEquals(((LeafQueue) cAuto).getUserLimitFactor(), -1, EPSILON); + Assertions.assertEquals(((LeafQueue) cAuto).getMaxAMResourcePerQueuePercent(), 1, EPSILON); // Now add another queue-d, in the same hierarchy createQueue("root.d.d1-auto"); @@ -257,57 +257,57 @@ public void testMixedFlexibleConfiguration() throws Exception { // become 1/4 CSQueue dAuto = cs.getQueue("root.d.d1-auto"); // d1-auto should get 1000 MB, 1 vcore - Assert.assertEquals(1 / 32f, dAuto.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, dAuto.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(1000, + Assertions.assertEquals(1 / 32f, dAuto.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, dAuto.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(1000, dAuto.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(1, + Assertions.assertEquals(1, dAuto.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); createQueue("root.a.a2-auto"); CSQueue a2Auto = cs.getQueue("root.a.a2-auto"); - Assert.assertEquals(2 / 32f, a2Auto.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, a2Auto.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(2000, + Assertions.assertEquals(2 / 32f, a2Auto.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, a2Auto.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(2000, a2Auto.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(2, + Assertions.assertEquals(2, a2Auto.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); // Absolute requests take precedence over percentage and weight, // hence a1 should have 1000 MB, 0 vcore CSQueue a1 = cs.getQueue("root.a.a1"); - Assert.assertEquals(1000, + Assertions.assertEquals(1000, a1.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, a1.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); createQueue("root.e-auto.e1-auto"); // e-auto has weights configured, so it will share the remaining resources with c-auto CSQueue eAuto = cs.getQueue("root.e-auto"); - Assert.assertEquals(12 / 32f, eAuto.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, eAuto.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(12000, + Assertions.assertEquals(12 / 32f, eAuto.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, eAuto.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(12000, eAuto.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(10, + Assertions.assertEquals(10, eAuto.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); // Now we check queue c-auto again, it should have shared its resources with e-auto - Assert.assertEquals(12 / 32f, cAuto.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, cAuto.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(12000, + Assertions.assertEquals(12 / 32f, cAuto.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, cAuto.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(12000, cAuto.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(16, + Assertions.assertEquals(16, cAuto.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); // Under e, there's only one queue, so e1 should have what it's asking for CSQueue e1Auto = cs.getQueue("root.e-auto.e1-auto"); - Assert.assertEquals(2 / 32f, e1Auto.getAbsoluteCapacity(), EPSILON); - Assert.assertEquals(-1f, e1Auto.getQueueCapacities().getWeight(), EPSILON); - Assert.assertEquals(2000, + Assertions.assertEquals(2 / 32f, e1Auto.getAbsoluteCapacity(), EPSILON); + Assertions.assertEquals(-1f, e1Auto.getQueueCapacities().getWeight(), EPSILON); + Assertions.assertEquals(2000, e1Auto.getQueueResourceQuotas().getEffectiveMinResource().getMemorySize()); - Assert.assertEquals(2, + Assertions.assertEquals(2, e1Auto.getQueueResourceQuotas().getEffectiveMinResource().getVirtualCores()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNodeLabelUpdate.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNodeLabelUpdate.java index 90a563245a183..01d21732f899e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNodeLabelUpdate.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNodeLabelUpdate.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.HashSet; @@ -51,9 +51,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeLabelsUpdateSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo; -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.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; @@ -66,7 +67,7 @@ public class TestCapacitySchedulerNodeLabelUpdate { RMNodeLabelsManager mgr; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -173,7 +174,7 @@ private void checkUsedResource(MockRM rm, String queueName, int memory, String label) { CapacityScheduler scheduler = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = scheduler.getQueue(queueName); - Assert.assertEquals(memory, queue.getQueueResourceUsage().getUsed(label) + Assertions.assertEquals(memory, queue.getQueueResourceUsage().getUsed(label) .getMemorySize()); } @@ -182,7 +183,7 @@ private void checkUsedCapacity(MockRM rm, String queueName, int capacity, float epsillon = 0.0001f; CapacityScheduler scheduler = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = scheduler.getQueue(queueName); - Assert.assertEquals((float)capacity/total, + Assertions.assertEquals((float)capacity/total, queue.getQueueCapacities().getUsedCapacity(label), epsillon); } @@ -190,7 +191,7 @@ private void checkAMUsedResource(MockRM rm, String queueName, int memory, String label) { CapacityScheduler scheduler = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = scheduler.getQueue(queueName); - Assert.assertEquals(memory, queue.getQueueResourceUsage().getAMUsed(label) + Assertions.assertEquals(memory, queue.getQueueResourceUsage().getAMUsed(label) .getMemorySize()); } @@ -199,11 +200,12 @@ private void checkUserUsedResource(MockRM rm, String queueName, CapacityScheduler scheduler = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue queue = (LeafQueue) scheduler.getQueue(queueName); UsersManager.User user = queue.getUser(userName); - Assert.assertEquals(memory, + Assertions.assertEquals(memory, user.getResourceUsage().getUsed(partition).getMemorySize()); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testRequestContainerAfterNodePartitionUpdated() throws Exception { // set node -> label @@ -245,9 +247,9 @@ public RMNodeLabelsManager createNodeLabelManager() { ApplicationResourceUsageReport appResourceUsageReport = rm.getResourceScheduler().getAppResourceUsageReport( am1.getApplicationAttemptId()); - Assert.assertEquals(1024, appResourceUsageReport.getUsedResources() + Assertions.assertEquals(1024, appResourceUsageReport.getUsedResources() .getMemorySize()); - Assert.assertEquals(1, appResourceUsageReport.getUsedResources() + Assertions.assertEquals(1, appResourceUsageReport.getUsedResources() .getVirtualCores()); // request a container. am1.allocate("*", GB, 1, new ArrayList(), "x"); @@ -256,9 +258,9 @@ public RMNodeLabelsManager createNodeLabelManager() { appResourceUsageReport = rm.getResourceScheduler().getAppResourceUsageReport( am1.getApplicationAttemptId()); - Assert.assertEquals(2048, appResourceUsageReport.getUsedResources() + Assertions.assertEquals(2048, appResourceUsageReport.getUsedResources() .getMemorySize()); - Assert.assertEquals(2, appResourceUsageReport.getUsedResources() + Assertions.assertEquals(2, appResourceUsageReport.getUsedResources() .getVirtualCores()); LeafQueue queue = (LeafQueue) ((CapacityScheduler) rm.getResourceScheduler()) @@ -267,8 +269,8 @@ public RMNodeLabelsManager createNodeLabelManager() { for (UserInfo userInfo : users) { if (userInfo.getUsername().equals("user")) { ResourceInfo resourcesUsed = userInfo.getResourcesUsed(); - Assert.assertEquals(2048, resourcesUsed.getMemorySize()); - Assert.assertEquals(2, resourcesUsed.getvCores()); + Assertions.assertEquals(2048, resourcesUsed.getMemorySize()); + Assertions.assertEquals(2, resourcesUsed.getvCores()); } } rm.stop(); @@ -320,7 +322,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate("*", GB, 1, new ArrayList(), "x"); containerId1 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 1); containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm.waitForState(nm1, containerId2, + Assertions.assertTrue(rm.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // check used resource: @@ -349,9 +351,9 @@ public RMNodeLabelsManager createNodeLabelManager() { checkUsedResource(rm, "root", 1024); checkUserUsedResource(rm, "a", "user", "x", 0); checkUserUsedResource(rm, "a", "user", "z", 1024); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(1024, + Assertions.assertEquals(1024, app.getAppAttemptResourceUsage().getUsed("z").getMemorySize()); // change h1's label to y @@ -374,11 +376,11 @@ public RMNodeLabelsManager createNodeLabelManager() { checkUserUsedResource(rm, "a", "user", "x", 0); checkUserUsedResource(rm, "a", "user", "y", 1024); checkUserUsedResource(rm, "a", "user", "z", 0); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(1024, + Assertions.assertEquals(1024, app.getAppAttemptResourceUsage().getUsed("y").getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getUsed("z").getMemorySize()); // change h1's label to no label @@ -404,13 +406,13 @@ public RMNodeLabelsManager createNodeLabelManager() { checkUserUsedResource(rm, "a", "user", "y", 0); checkUserUsedResource(rm, "a", "user", "z", 0); checkUserUsedResource(rm, "a", "user", "", 2048); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getUsed("y").getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getUsed("z").getMemorySize()); - Assert.assertEquals(2048, + Assertions.assertEquals(2048, app.getAppAttemptResourceUsage().getUsed("").getMemorySize()); // Finish the two containers, we should see used resource becomes 0 @@ -443,7 +445,8 @@ public RMNodeLabelsManager createNodeLabelManager() { rm.close(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testMoveApplicationWithLabel() throws Exception { // set node -> label mgr.addToCluserNodeLabelsWithDefaultExclusivity( @@ -500,9 +503,9 @@ public RMNodeLabelsManager createNodeLabelManager() { fail("Should throw exception since target queue doesnt have " + "required labels"); } catch (Exception e) { - Assert.assertTrue("Yarn Exception should be thrown", - e instanceof YarnException); - Assert.assertEquals("Specified queue=root.a.a2 can't satisfy " + Assertions.assertTrue( + e instanceof YarnException, "Yarn Exception should be thrown"); + Assertions.assertEquals("Specified queue=root.a.a2 can't satisfy " + "following apps label expressions =[x] accessible " + "node labels =[y]", e.getMessage()); } @@ -518,7 +521,8 @@ public RMNodeLabelsManager createNodeLabelManager() { rm.stop(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testComplexResourceUsageWhenNodeUpdatesPartition() throws Exception { /* @@ -575,12 +579,12 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate("*", GB, 1, new ArrayList(), "x"); ContainerId containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm.waitForState(nm1, containerId, + Assertions.assertTrue(rm.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); am1.allocate("*", GB, 1, new ArrayList()); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 3); - Assert.assertTrue(rm.waitForState(nm2, containerId, + Assertions.assertTrue(rm.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); // app2 @@ -599,7 +603,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am2.allocate("*", GB, 2, new ArrayList(), "x"); containerId = ContainerId.newContainerId(am2.getApplicationAttemptId(), 3); - Assert.assertTrue(rm.waitForState(nm1, containerId, + Assertions.assertTrue(rm.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); // check used resource: @@ -628,17 +632,17 @@ public RMNodeLabelsManager createNodeLabelManager() { checkUserUsedResource(rm, "a", "u2", "x", 0 * GB); checkUserUsedResource(rm, "a", "u2", "z", 2 * GB); checkUserUsedResource(rm, "a", "u2", "", 1 * GB); - Assert.assertEquals(0, + Assertions.assertEquals(0, application1.getAppAttemptResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(1 * GB, + Assertions.assertEquals(1 * GB, application1.getAppAttemptResourceUsage().getUsed("z").getMemorySize()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, application1.getAppAttemptResourceUsage().getUsed("").getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, application2.getAppAttemptResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, application2.getAppAttemptResourceUsage().getUsed("z").getMemorySize()); - Assert.assertEquals(1 * GB, + Assertions.assertEquals(1 * GB, application2.getAppAttemptResourceUsage().getUsed("").getMemorySize()); rm.close(); @@ -687,7 +691,8 @@ public RMNodeLabelsManager createNodeLabelManager() { rm.stop(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAMResourceUsageWhenNodeUpdatesPartition() throws Exception { // set node -> label @@ -732,7 +737,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate("*", GB, 1, new ArrayList(), "x"); ContainerId.newContainerId(am1.getApplicationAttemptId(), 1); containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm.waitForState(nm1, containerId2, + Assertions.assertTrue(rm.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // check used resource: @@ -755,9 +760,9 @@ public RMNodeLabelsManager createNodeLabelManager() { checkAMUsedResource(rm, "a", 1024, "z"); checkUserUsedResource(rm, "a", "user", "x", 0); checkUserUsedResource(rm, "a", "user", "z", 2048); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getAMUsed("x").getMemorySize()); - Assert.assertEquals(1024, + Assertions.assertEquals(1024, app.getAppAttemptResourceUsage().getAMUsed("z").getMemorySize()); // change h1's label to no label @@ -774,17 +779,18 @@ public RMNodeLabelsManager createNodeLabelManager() { checkUserUsedResource(rm, "a", "user", "x", 0); checkUserUsedResource(rm, "a", "user", "z", 0); checkUserUsedResource(rm, "a", "user", "", 2048); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getAMUsed("x").getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, app.getAppAttemptResourceUsage().getAMUsed("z").getMemorySize()); - Assert.assertEquals(1024, + Assertions.assertEquals(1024, app.getAppAttemptResourceUsage().getAMUsed("").getMemorySize()); rm.close(); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testBlacklistAMDisableLabel() throws Exception { conf.setBoolean(YarnConfiguration.AM_SCHEDULING_NODE_BLACKLISTING_ENABLED, true); @@ -836,13 +842,13 @@ public RMNodeLabelsManager createNodeLabelManager() { appAttempt.getAMBlacklistManager().addNode("h1"); ResourceBlacklistRequest blacklistUpdates = appAttempt.getAMBlacklistManager().getBlacklistUpdates(); - Assert.assertEquals(1, blacklistUpdates.getBlacklistAdditions().size()); - Assert.assertEquals(0, blacklistUpdates.getBlacklistRemovals().size()); + Assertions.assertEquals(1, blacklistUpdates.getBlacklistAdditions().size()); + Assertions.assertEquals(0, blacklistUpdates.getBlacklistRemovals().size()); // Adding second node from default parition appAttempt.getAMBlacklistManager().addNode("h8"); blacklistUpdates = appAttempt.getAMBlacklistManager().getBlacklistUpdates(); - Assert.assertEquals(0, blacklistUpdates.getBlacklistAdditions().size()); - Assert.assertEquals(2, blacklistUpdates.getBlacklistRemovals().size()); + Assertions.assertEquals(0, blacklistUpdates.getBlacklistAdditions().size()); + Assertions.assertEquals(2, blacklistUpdates.getBlacklistRemovals().size()); // Submission in label x MockRMAppSubmissionData data1 = @@ -859,21 +865,21 @@ public RMNodeLabelsManager createNodeLabelManager() { appAttemptlabelx.getAMBlacklistManager().addNode("h2"); ResourceBlacklistRequest blacklistUpdatesOnx = appAttemptlabelx.getAMBlacklistManager().getBlacklistUpdates(); - Assert.assertEquals(1, blacklistUpdatesOnx.getBlacklistAdditions().size()); - Assert.assertEquals(0, blacklistUpdatesOnx.getBlacklistRemovals().size()); + Assertions.assertEquals(1, blacklistUpdatesOnx.getBlacklistAdditions().size()); + Assertions.assertEquals(0, blacklistUpdatesOnx.getBlacklistRemovals().size()); // Adding second node from default parition appAttemptlabelx.getAMBlacklistManager().addNode("h3"); blacklistUpdatesOnx = appAttempt.getAMBlacklistManager().getBlacklistUpdates(); - Assert.assertEquals(0, blacklistUpdatesOnx.getBlacklistAdditions().size()); - Assert.assertEquals(2, blacklistUpdatesOnx.getBlacklistRemovals().size()); + Assertions.assertEquals(0, blacklistUpdatesOnx.getBlacklistAdditions().size()); + Assertions.assertEquals(2, blacklistUpdatesOnx.getBlacklistRemovals().size()); rm.close(); } private void checkAMResourceLimit(MockRM rm, String queuename, int memory, String label) throws InterruptedException { - Assert.assertEquals(memory, + Assertions.assertEquals(memory, waitForResourceUpdate(rm, queuename, memory, label, 3000L)); } @@ -944,24 +950,24 @@ public RMNodeLabelsManager createNodeLabelManager() { // Ensure that cluster node tracker is updated with correct set of node // after Node registration. - Assert.assertEquals(2, + Assertions.assertEquals(2, cs.getNodeTracker().getNodesPerPartition("x").size()); - Assert.assertEquals(1, cs.getNodeTracker().getNodesPerPartition("").size()); + Assertions.assertEquals(1, cs.getNodeTracker().getNodesPerPartition("").size()); rm.unRegisterNode(nm1); rm.registerNode("h4:1234", 8000); // Ensure that cluster node tracker is updated with correct set of node // after new Node registration and old node label change. - Assert.assertEquals(1, + Assertions.assertEquals(1, cs.getNodeTracker().getNodesPerPartition("x").size()); - Assert.assertEquals(2, cs.getNodeTracker().getNodesPerPartition("").size()); + Assertions.assertEquals(2, cs.getNodeTracker().getNodesPerPartition("").size()); mgr.replaceLabelsOnNode( ImmutableMap.of(NodeId.newInstance("h2", 1234), toSet(""))); // Last node with label x is replaced by CLI or REST. - Assert.assertEquals(0, + Assertions.assertEquals(0, waitForNodeLabelSchedulerEventUpdate(rm, "x", 0, 3000L)); 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/scheduler/capacity/TestCapacitySchedulerNodes.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNodes.java index be1645f27f449..26d4bbb7b5c1d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNodes.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerNodes.java @@ -61,10 +61,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM; import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus; @@ -76,7 +76,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.registerNode; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.stopResourceManager; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.NULL_UPDATE_REQUESTS; -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.times; import static org.mockito.Mockito.verify; @@ -86,12 +86,12 @@ public class TestCapacitySchedulerNodes { private ResourceManager resourceManager = null; - @Before + @BeforeEach public void setUp() throws Exception { resourceManager = createResourceManager(); } - @After + @AfterEach public void tearDown() throws Exception { stopResourceManager(resourceManager); } @@ -117,14 +117,14 @@ null, null, new RMContainerTokenSecretManager(csConf), cs.handle(new NodeAddedSchedulerEvent(n1)); cs.handle(new NodeAddedSchedulerEvent(n2)); - Assert.assertEquals(6 * GB, cs.getClusterResource().getMemorySize()); + Assertions.assertEquals(6 * GB, cs.getClusterResource().getMemorySize()); // reconnect n1 with downgraded memory n1 = MockNodes.newNodeInfo(0, MockNodes.newResource(2 * GB), 1); cs.handle(new NodeRemovedSchedulerEvent(n1)); cs.handle(new NodeAddedSchedulerEvent(n1)); - Assert.assertEquals(4 * GB, cs.getClusterResource().getMemorySize()); + Assertions.assertEquals(4 * GB, cs.getClusterResource().getMemorySize()); cs.stop(); } @@ -148,12 +148,12 @@ public void testBlackListNodes() throws Exception { cs.allocate(appAttemptId, Collections.emptyList(), null, Collections.emptyList(), Collections.singletonList(host), null, NULL_UPDATE_REQUESTS); - Assert.assertTrue(cs.getApplicationAttempt(appAttemptId) + Assertions.assertTrue(cs.getApplicationAttempt(appAttemptId) .isPlaceBlacklisted(host)); cs.allocate(appAttemptId, Collections.emptyList(), null, Collections.emptyList(), null, Collections.singletonList(host), NULL_UPDATE_REQUESTS); - Assert.assertFalse(cs.getApplicationAttempt(appAttemptId) + Assertions.assertFalse(cs.getApplicationAttempt(appAttemptId) .isPlaceBlacklisted(host)); rm.stop(); } @@ -202,19 +202,19 @@ public void testDefaultNodeLabelExpressionQueueConfig() throws Exception { cs.start(); QueueInfo queueInfoA = cs.getQueueInfo("a", true, false); - Assert.assertEquals("Queue Name should be a", "a", + Assertions.assertEquals("Queue Name should be a", "a", queueInfoA.getQueueName()); - Assert.assertEquals("Queue Path should be root.a", "root.a", + Assertions.assertEquals("Queue Path should be root.a", "root.a", queueInfoA.getQueuePath()); - Assert.assertEquals("Default Node Label Expression should be x", "x", + Assertions.assertEquals("Default Node Label Expression should be x", "x", queueInfoA.getDefaultNodeLabelExpression()); QueueInfo queueInfoB = cs.getQueueInfo("b", true, false); - Assert.assertEquals("Queue Name should be b", "b", + Assertions.assertEquals("Queue Name should be b", "b", queueInfoB.getQueueName()); - Assert.assertEquals("Queue Path should be root.b", "root.b", + Assertions.assertEquals("Queue Path should be root.b", "root.b", queueInfoB.getQueuePath()); - Assert.assertEquals("Default Node Label Expression should be y", "y", + Assertions.assertEquals("Default Node Label Expression should be y", "y", queueInfoB.getDefaultNodeLabelExpression()); cs.stop(); } @@ -311,30 +311,30 @@ public void handle(Event event) { application0.schedule(); // Check the used resource is 1 GB 1 core - Assert.assertEquals(1 * GB, nm0.getUsed().getMemorySize()); + Assertions.assertEquals(1 * GB, nm0.getUsed().getMemorySize()); Resource usedResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm0.getNodeId()).getAllocatedResource(); - Assert.assertEquals("Used Resource Memory Size should be 1GB", 1 * GB, - usedResource.getMemorySize()); - Assert.assertEquals("Used Resource Virtual Cores should be 1", 1, - usedResource.getVirtualCores()); + Assertions.assertEquals(1 * GB +, usedResource.getMemorySize(), "Used Resource Memory Size should be 1GB"); + Assertions.assertEquals(1 +, usedResource.getVirtualCores(), "Used Resource Virtual Cores should be 1"); // Check total resource of scheduler node is also changed to 1 GB 1 core Resource totalResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm0.getNodeId()).getTotalResource(); - Assert.assertEquals("Total Resource Memory Size should be 1GB", 1 * GB, - totalResource.getMemorySize()); - Assert.assertEquals("Total Resource Virtual Cores should be 1", 1, - totalResource.getVirtualCores()); + Assertions.assertEquals(1 * GB +, totalResource.getMemorySize(), "Total Resource Memory Size should be 1GB"); + Assertions.assertEquals(1 +, totalResource.getVirtualCores(), "Total Resource Virtual Cores should be 1"); // Check the available resource is 0/0 Resource availableResource = resourceManager.getResourceScheduler() .getSchedulerNode(nm0.getNodeId()).getUnallocatedResource(); - Assert.assertEquals("Available Resource Memory Size should be 0", 0, - availableResource.getMemorySize()); - Assert.assertEquals("Available Resource Memory Size should be 0", 0, - availableResource.getVirtualCores()); + Assertions.assertEquals(0 +, availableResource.getMemorySize(), "Available Resource Memory Size should be 0"); + Assertions.assertEquals(0 +, availableResource.getVirtualCores(), "Available Resource Memory Size should be 0"); // Kick off another heartbeat where the RMNodeResourceUpdateEvent would // be skipped for DECOMMISSIONING state since the total resource is // already equal to used resource from the previous heartbeat. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerPerf.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerPerf.java index 24038ebeb8f0b..fe8121007b1ea 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerPerf.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerPerf.java @@ -53,7 +53,8 @@ import org.apache.hadoop.yarn.util.resource.ResourceUtils; import org.slf4j.event.Level; import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.Collections; import java.util.HashMap; @@ -62,9 +63,9 @@ import java.util.concurrent.atomic.AtomicLong; import static org.apache.hadoop.yarn.server.resourcemanager.resource.TestResourceProfiles.TEST_CONF_RESET_RESOURCE_TYPES; -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.Mockito.mock; import static org.mockito.Mockito.when; @@ -415,27 +416,32 @@ private void testUserLimitThroughputWithNumberOfResourceTypes( rm.stop(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testUserLimitThroughputForTwoResources() throws Exception { testUserLimitThroughputWithNumberOfResourceTypes(2, 1, 100, 100); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testUserLimitThroughputForThreeResources() throws Exception { testUserLimitThroughputWithNumberOfResourceTypes(3, 1, 100, 100); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testUserLimitThroughputForFourResources() throws Exception { testUserLimitThroughputWithNumberOfResourceTypes(4, 1, 100, 100); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testUserLimitThroughputForFiveResources() throws Exception { testUserLimitThroughputWithNumberOfResourceTypes(5, 1, 100, 100); } - @Test(timeout = 1800000) + @Test + @Timeout(value = 1800) public void testUserLimitThroughputWithManyQueues() throws Exception { int numQueues = Integer.getInteger("NumberOfQueues", 40); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueueACLs.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueueACLs.java index 841b8f9193fba..125ca718e59a8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueueACLs.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueueACLs.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -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.when; @@ -32,7 +32,7 @@ import org.apache.hadoop.yarn.api.records.QueueACL; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.QueueACLsTestBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestCapacitySchedulerQueueACLs extends QueueACLsTestBase { @Override @@ -177,7 +177,7 @@ private void testCheckAccess(boolean expectedResult, String queueName) { (CapacityScheduler) resourceManager.getResourceScheduler(); cs.setQueueManager(qm); - assertEquals("checkAccess() failed", expectedResult, - cs.checkAccess(mockUGI, QueueACL.ADMINISTER_QUEUE, queueName)); + assertEquals(expectedResult +, cs.checkAccess(mockUGI, QueueACL.ADMINISTER_QUEUE, queueName), "checkAccess() failed"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueueMappingFactory.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueueMappingFactory.java index 6f9ca5c354085..b98a7ef5464a0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueueMappingFactory.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueueMappingFactory.java @@ -33,7 +33,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping; import org.apache.hadoop.yarn.util.Records; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -41,7 +41,8 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.getQueueMapping; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.setupQueueConfiguration; import static org.hamcrest.CoreMatchers.hasItems; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; public class TestCapacitySchedulerQueueMappingFactory { @@ -131,7 +132,7 @@ public void testUpdatePlacementRulesFactory() throws Exception { } // verify both placement rules were added successfully - assertThat(placementRuleNames, hasItems(QUEUE_MAPPING_RULE)); + assertThat(placementRuleNames).contains(QUEUE_MAPPING_RULE); } finally { if(mockRM != null) { mockRM.close(); @@ -352,7 +353,7 @@ private void testNestedUserQueueWithDynamicParentQueue( CSMappingPlacementRule r = (CSMappingPlacementRule) rules.get(0); ApplicationPlacementContext ctx = r.getPlacementForApp(asc, user); - assertEquals("Queue", user, ctx.getQueue()); + assertEquals(user, ctx.getQueue(), "Queue"); if (primary) { assertEquals( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueues.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueues.java index 2f445e636c8dc..cabc59df278c3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueues.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerQueues.java @@ -35,10 +35,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager; import org.apache.hadoop.yarn.util.resource.ResourceUtils; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.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 org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,11 +70,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.setupQueueConfigurationWithoutB; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.setupQueueConfigurationWithoutB1; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.GB; -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.*; import static org.mockito.Mockito.when; public class TestCapacitySchedulerQueues { @@ -84,7 +81,7 @@ public class TestCapacitySchedulerQueues { private NullRMNodeLabelsManager mgr; private CapacitySchedulerConfiguration conf; - @Before + @BeforeEach public void setUp() throws Exception { conf = new CapacitySchedulerConfiguration(); setupQueueConfiguration(conf); @@ -107,7 +104,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { new ResourceLimits(clusterResource)); } - @After + @AfterEach public void tearDown() throws Exception { if (rm != null) { rm.stop(); @@ -123,23 +120,25 @@ public void tearDown() throws Exception { * * @throws IOException */ - @Test(expected = IOException.class) + @Test public void testParseQueue() throws IOException { - CapacityScheduler cs = new CapacityScheduler(); - cs.setConf(new YarnConfiguration()); - cs.setRMContext(rm.getRMContext()); - cs.init(conf); - cs.start(); - - conf.setQueues(A1, new String[]{"b1"}); - conf.setCapacity(A1_B1, 100.0f); - conf.setUserLimitFactor(A1_B1, 100.0f); - - cs.reinitialize(conf, new RMContextImpl(null, null, null, null, null, - null, new RMContainerTokenSecretManager(conf), - new NMTokenSecretManagerInRM(conf), - new ClientToAMTokenSecretManagerInRM(), null)); - cs.stop(); + assertThrows(IOException.class, ()->{ + CapacityScheduler cs = new CapacityScheduler(); + cs.setConf(new YarnConfiguration()); + cs.setRMContext(rm.getRMContext()); + cs.init(conf); + cs.start(); + + conf.setQueues(A1, new String[]{"b1"}); + conf.setCapacity(A1_B1, 100.0f); + conf.setUserLimitFactor(A1_B1, 100.0f); + + cs.reinitialize(conf, new RMContextImpl(null, null, null, null, null, + null, new RMContainerTokenSecretManager(conf), + new NMTokenSecretManagerInRM(conf), + new ClientToAMTokenSecretManagerInRM(), null)); + cs.stop(); + }); } @Test @@ -218,21 +217,21 @@ public void testRefreshQueuesMaxAllocationRefresh() throws Exception { cs.reinitialize(conf, rm.getRMContext()); checkQueueStructureCapacities(cs); - assertEquals("max allocation in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("max allocation for A1", - Resources.none(), - conf.getQueueMaximumAllocation(A1)); - assertEquals("max allocation", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - ResourceUtils.fetchMaximumAllocationFromConfig(conf).getMemorySize()); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, cs.getMaximumResourceCapability().getMemorySize(), "max allocation in CS"); + assertEquals( + Resources.none() +, conf.getQueueMaximumAllocation(A1), "max allocation for A1"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, ResourceUtils.fetchMaximumAllocationFromConfig(conf).getMemorySize(), "max allocation"); CSQueue rootQueue = cs.getRootQueue(); CSQueue queueA = findQueue(rootQueue, A.getFullPath()); CSQueue queueA1 = findQueue(queueA, A1.getFullPath()); - assertEquals("queue max allocation", ((LeafQueue) queueA1) - .getMaximumAllocation().getMemorySize(), 8192); + assertEquals(((LeafQueue) queueA1) + .getMaximumAllocation().getMemorySize(), 8192, "queue max allocation"); setMaxAllocMb(conf, A1, 4096); @@ -240,8 +239,8 @@ public void testRefreshQueuesMaxAllocationRefresh() throws Exception { cs.reinitialize(conf, rm.getRMContext()); fail("should have thrown exception"); } catch (IOException e) { - assertTrue("max allocation exception", - e.getCause().toString().contains("not be decreased")); + assertTrue( + e.getCause().toString().contains("not be decreased"), "max allocation exception"); } setMaxAllocMb(conf, A1, 8192); @@ -253,8 +252,8 @@ public void testRefreshQueuesMaxAllocationRefresh() throws Exception { cs.reinitialize(conf, rm.getRMContext()); fail("should have thrown exception"); } catch (IOException e) { - assertTrue("max allocation exception", - e.getCause().toString().contains("not be decreased")); + assertTrue( + e.getCause().toString().contains("not be decreased"), "max allocation exception"); } cs.stop(); } @@ -274,8 +273,8 @@ public void testRefreshQueuesMaxAllocationPerQueueLarge() throws Exception { cs.reinitialize(conf, rm.getRMContext()); fail("should have thrown exception"); } catch (IOException e) { - assertTrue("maximum allocation exception", - e.getCause().getMessage().contains("maximum allocation")); + assertTrue( + e.getCause().getMessage().contains("maximum allocation"), "maximum allocation exception"); } setMaxAllocMb(conf, B3, @@ -288,8 +287,8 @@ public void testRefreshQueuesMaxAllocationPerQueueLarge() throws Exception { cs.reinitialize(conf, rm.getRMContext()); fail("should have thrown exception"); } catch (IOException e) { - assertTrue("maximum allocation exception", - e.getCause().getMessage().contains("maximum allocation")); + assertTrue( + e.getCause().getMessage().contains("maximum allocation"), "maximum allocation exception"); } cs.stop(); } @@ -315,53 +314,53 @@ public void testRefreshQueuesMaxAllocationRefreshLarger() throws Exception { CSQueue queueA = findQueue(rootQueue, A.getFullPath()); CSQueue queueA1 = findQueue(queueA, A1.getFullPath()); - assertEquals("max capability MB in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("max capability vcores in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - cs.getMaximumResourceCapability().getVirtualCores()); - assertEquals("max allocation MB A1", - 4096, - queueA1.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation vcores A1", - 2, - queueA1.getMaximumAllocation().getVirtualCores()); - assertEquals("cluster max allocation MB", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - ResourceUtils.fetchMaximumAllocationFromConfig(conf).getMemorySize()); - assertEquals("cluster max allocation vcores", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - ResourceUtils.fetchMaximumAllocationFromConfig(conf).getVirtualCores()); - - assertEquals("queue max allocation", 4096, - queueA1.getMaximumAllocation().getMemorySize()); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, cs.getMaximumResourceCapability().getMemorySize(), "max capability MB in CS"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, cs.getMaximumResourceCapability().getVirtualCores(), "max capability vcores in CS"); + assertEquals( + 4096 +, queueA1.getMaximumAllocation().getMemorySize(), "max allocation MB A1"); + assertEquals( + 2 +, queueA1.getMaximumAllocation().getVirtualCores(), "max allocation vcores A1"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, ResourceUtils.fetchMaximumAllocationFromConfig(conf).getMemorySize(), "cluster max allocation MB"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, ResourceUtils.fetchMaximumAllocationFromConfig(conf).getVirtualCores(), "cluster max allocation vcores"); + + assertEquals(4096 +, queueA1.getMaximumAllocation().getMemorySize(), "queue max allocation"); setMaxAllocMb(conf, A1, 6144); setMaxAllocVcores(conf, A1, 3); cs.reinitialize(conf, null); // conf will have changed but we shouldn't be able to change max allocation // for the actual queue - assertEquals("max allocation MB A1", 6144, - queueA1.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation vcores A1", 3, - queueA1.getMaximumAllocation().getVirtualCores()); - assertEquals("max allocation MB cluster", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - ResourceUtils.fetchMaximumAllocationFromConfig(conf).getMemorySize()); - assertEquals("max allocation vcores cluster", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - ResourceUtils.fetchMaximumAllocationFromConfig(conf).getVirtualCores()); - assertEquals("queue max allocation MB", 6144, - queueA1.getMaximumAllocation().getMemorySize()); - assertEquals("queue max allocation vcores", 3, - queueA1.getMaximumAllocation().getVirtualCores()); - assertEquals("max capability MB cluster", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("cluster max capability vcores", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - cs.getMaximumResourceCapability().getVirtualCores()); + assertEquals(6144 +, queueA1.getMaximumAllocation().getMemorySize(), "max allocation MB A1"); + assertEquals(3 +, queueA1.getMaximumAllocation().getVirtualCores(), "max allocation vcores A1"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, ResourceUtils.fetchMaximumAllocationFromConfig(conf).getMemorySize(), "max allocation MB cluster"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, ResourceUtils.fetchMaximumAllocationFromConfig(conf).getVirtualCores(), "max allocation vcores cluster"); + assertEquals(6144 +, queueA1.getMaximumAllocation().getMemorySize(), "queue max allocation MB"); + assertEquals(3 +, queueA1.getMaximumAllocation().getVirtualCores(), "queue max allocation vcores"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, cs.getMaximumResourceCapability().getMemorySize(), "max capability MB cluster"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, cs.getMaximumResourceCapability().getVirtualCores(), "cluster max capability vcores"); cs.stop(); } @@ -382,18 +381,18 @@ public void testRefreshQueuesMaxAllocationCSError() throws Exception { checkQueueStructureCapacities(cs); - assertEquals("max allocation MB in CS", 10240, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("max allocation vcores in CS", 10, - cs.getMaximumResourceCapability().getVirtualCores()); + assertEquals(10240 +, cs.getMaximumResourceCapability().getMemorySize(), "max allocation MB in CS"); + assertEquals(10 +, cs.getMaximumResourceCapability().getVirtualCores(), "max allocation vcores in CS"); setMaxAllocMb(conf, 6144); try { cs.reinitialize(conf, rm.getRMContext()); fail("should have thrown exception"); } catch (IOException e) { - assertTrue("max allocation exception", - e.getCause().toString().contains("not be decreased")); + assertTrue( + e.getCause().toString().contains("not be decreased"), "max allocation exception"); } setMaxAllocMb(conf, 10240); @@ -404,8 +403,8 @@ public void testRefreshQueuesMaxAllocationCSError() throws Exception { cs.reinitialize(conf, rm.getRMContext()); fail("should have thrown exception"); } catch (IOException e) { - assertTrue("max allocation exception", - e.getCause().toString().contains("not be decreased")); + assertTrue( + e.getCause().toString().contains("not be decreased"), "max allocation exception"); } cs.stop(); } @@ -427,10 +426,10 @@ public void testRefreshQueuesMaxAllocationCSLarger() throws Exception { cs.reinitialize(conf, rm.getRMContext()); checkQueueStructureCapacities(cs); - assertEquals("max allocation MB in CS", 10240, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("max allocation vcores in CS", 10, - cs.getMaximumResourceCapability().getVirtualCores()); + assertEquals(10240 +, cs.getMaximumResourceCapability().getMemorySize(), "max allocation MB in CS"); + assertEquals(10 +, cs.getMaximumResourceCapability().getVirtualCores(), "max allocation vcores in CS"); CSQueue rootQueue = cs.getRootQueue(); CSQueue queueA = findQueue(rootQueue, A.getFullPath()); @@ -439,40 +438,40 @@ public void testRefreshQueuesMaxAllocationCSLarger() throws Exception { CSQueue queueA2 = findQueue(queueA, A2.getFullPath()); CSQueue queueB2 = findQueue(queueB, B2.getFullPath()); - assertEquals("queue A1 max allocation MB", 4096, - queueA1.getMaximumAllocation().getMemorySize()); - assertEquals("queue A1 max allocation vcores", 4, - queueA1.getMaximumAllocation().getVirtualCores()); - assertEquals("queue A2 max allocation MB", 10240, - queueA2.getMaximumAllocation().getMemorySize()); - assertEquals("queue A2 max allocation vcores", 10, - queueA2.getMaximumAllocation().getVirtualCores()); - assertEquals("queue B2 max allocation MB", 10240, - queueB2.getMaximumAllocation().getMemorySize()); - assertEquals("queue B2 max allocation vcores", 10, - queueB2.getMaximumAllocation().getVirtualCores()); + assertEquals(4096 +, queueA1.getMaximumAllocation().getMemorySize(), "queue A1 max allocation MB"); + assertEquals(4 +, queueA1.getMaximumAllocation().getVirtualCores(), "queue A1 max allocation vcores"); + assertEquals(10240 +, queueA2.getMaximumAllocation().getMemorySize(), "queue A2 max allocation MB"); + assertEquals(10 +, queueA2.getMaximumAllocation().getVirtualCores(), "queue A2 max allocation vcores"); + assertEquals(10240 +, queueB2.getMaximumAllocation().getMemorySize(), "queue B2 max allocation MB"); + assertEquals(10 +, queueB2.getMaximumAllocation().getVirtualCores(), "queue B2 max allocation vcores"); setMaxAllocMb(conf, 12288); setMaxAllocVcores(conf, 12); cs.reinitialize(conf, null); // cluster level setting should change and any queues without // per queue setting - assertEquals("max allocation MB in CS", 12288, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("max allocation vcores in CS", 12, - cs.getMaximumResourceCapability().getVirtualCores()); - assertEquals("queue A1 max MB allocation", 4096, - queueA1.getMaximumAllocation().getMemorySize()); - assertEquals("queue A1 max vcores allocation", 4, - queueA1.getMaximumAllocation().getVirtualCores()); - assertEquals("queue A2 max MB allocation", 12288, - queueA2.getMaximumAllocation().getMemorySize()); - assertEquals("queue A2 max vcores allocation", 12, - queueA2.getMaximumAllocation().getVirtualCores()); - assertEquals("queue B2 max MB allocation", 12288, - queueB2.getMaximumAllocation().getMemorySize()); - assertEquals("queue B2 max vcores allocation", 12, - queueB2.getMaximumAllocation().getVirtualCores()); + assertEquals(12288 +, cs.getMaximumResourceCapability().getMemorySize(), "max allocation MB in CS"); + assertEquals(12 +, cs.getMaximumResourceCapability().getVirtualCores(), "max allocation vcores in CS"); + assertEquals(4096 +, queueA1.getMaximumAllocation().getMemorySize(), "queue A1 max MB allocation"); + assertEquals(4 +, queueA1.getMaximumAllocation().getVirtualCores(), "queue A1 max vcores allocation"); + assertEquals(12288 +, queueA2.getMaximumAllocation().getMemorySize(), "queue A2 max MB allocation"); + assertEquals(12 +, queueA2.getMaximumAllocation().getVirtualCores(), "queue A2 max vcores allocation"); + assertEquals(12288 +, queueB2.getMaximumAllocation().getMemorySize(), "queue B2 max MB allocation"); + assertEquals(12 +, queueB2.getMaximumAllocation().getVirtualCores(), "queue B2 max vcores allocation"); cs.stop(); } @@ -525,7 +524,7 @@ public void testRefreshQueuesWithQueueDelete() throws Exception { CSQueue rootQueue = cs.getRootQueue(); CSQueue queueB = findQueue(rootQueue, B.getFullPath()); CSQueue queueB3 = findQueue(queueB, B1.getFullPath()); - assertNull("Refresh needs to support delete of leaf queue ", queueB3); + assertNull(queueB3, "Refresh needs to support delete of leaf queue "); // reset back to default configuration for testing parent queue delete conf = new CapacitySchedulerConfiguration(); @@ -577,13 +576,13 @@ public void testRefreshQueuesWithQueueDelete() throws Exception { queueB = findQueue(rootQueue, B.getFullPath()); String message = "Refresh needs to support delete of Parent queue and its children."; - assertNull(message, queueB); - assertNull(message, - cs.getCapacitySchedulerQueueManager().getQueues().get("b")); - assertNull(message, - cs.getCapacitySchedulerQueueManager().getQueues().get("b1")); - assertNull(message, - cs.getCapacitySchedulerQueueManager().getQueues().get("b2")); + assertNull(queueB, message); + assertNull( + cs.getCapacitySchedulerQueueManager().getQueues().get("b"), message); + assertNull( + cs.getCapacitySchedulerQueueManager().getQueues().get("b1"), message); + assertNull( + cs.getCapacitySchedulerQueueManager().getQueues().get("b2"), message); cs.stop(); } @@ -644,18 +643,18 @@ public void testRefreshQueuesWithAllChildQueuesDeleted() throws Exception { } CSQueue rootQueue = cs.getRootQueue(); CSQueue queueB = findQueue(rootQueue, B.getFullPath()); - assertNotNull("Parent Queue B should not be deleted", queueB); - Assert.assertTrue("As Queue'B children are not deleted", - queueB instanceof LeafQueue); + assertNotNull(queueB, "Parent Queue B should not be deleted"); + Assertions.assertTrue( + queueB instanceof LeafQueue, "As Queue'B children are not deleted"); String message = "Refresh needs to support delete of all children of Parent queue."; - assertNull(message, - cs.getCapacitySchedulerQueueManager().getQueues().get("b3")); - assertNull(message, - cs.getCapacitySchedulerQueueManager().getQueues().get("b1")); - assertNull(message, - cs.getCapacitySchedulerQueueManager().getQueues().get("b2")); + assertNull( + cs.getCapacitySchedulerQueueManager().getQueues().get("b3"), message); + assertNull( + cs.getCapacitySchedulerQueueManager().getQueues().get("b1"), message); + assertNull( + cs.getCapacitySchedulerQueueManager().getQueues().get("b2"), message); cs.stop(); } @@ -665,7 +664,8 @@ public void testRefreshQueuesWithAllChildQueuesDeleted() throws Exception { * * @throws Exception */ - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testConvertLeafQueueToParentQueue() throws Exception { CapacityScheduler cs = new CapacityScheduler(); cs.setConf(new YarnConfiguration()); @@ -677,7 +677,7 @@ public void testConvertLeafQueueToParentQueue() throws Exception { String targetQueue = "b1"; CSQueue b1 = cs.getQueue(targetQueue); - Assert.assertEquals(QueueState.RUNNING, b1.getState()); + Assertions.assertEquals(QueueState.RUNNING, b1.getState()); // test if we can convert a leaf queue which is in RUNNING state conf = new CapacitySchedulerConfiguration(); @@ -695,7 +695,7 @@ public void testConvertLeafQueueToParentQueue() throws Exception { setupQueueConfiguration(conf); conf.set("yarn.scheduler.capacity.root.b.b1.state", "STOPPED"); cs.reinitialize(conf, rm.getRMContext()); - Assert.assertEquals(QueueState.STOPPED, b1.getState()); + Assertions.assertEquals(QueueState.STOPPED, b1.getState()); // test if we can convert a leaf queue which is in STOPPED state conf = new CapacitySchedulerConfiguration(); @@ -707,9 +707,9 @@ public void testConvertLeafQueueToParentQueue() throws Exception { + " to convert a leaf queue WITHOUT running apps"); } b1 = cs.getQueue(targetQueue); - Assert.assertTrue(b1 instanceof AbstractParentQueue); - Assert.assertEquals(QueueState.RUNNING, b1.getState()); - Assert.assertTrue(!b1.getChildQueues().isEmpty()); + Assertions.assertTrue(b1 instanceof AbstractParentQueue); + Assertions.assertEquals(QueueState.RUNNING, b1.getState()); + Assertions.assertTrue(!b1.getChildQueues().isEmpty()); cs.stop(); } @@ -746,29 +746,29 @@ public void testQueuesMaxAllocationInheritance() throws Exception { CSQueue queueB1 = findQueue(queueB, B1.getFullPath()); CSQueue queueB2 = findQueue(queueB, B2.getFullPath()); - assertEquals("max capability MB in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("max capability vcores in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - cs.getMaximumResourceCapability().getVirtualCores()); - assertEquals("max allocation MB A1", - 6144, - queueA1.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation vcores A1", - 2, - queueA1.getMaximumAllocation().getVirtualCores()); - assertEquals("max allocation MB A2", 4096, - queueA2.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation vcores A2", - 2, - queueA2.getMaximumAllocation().getVirtualCores()); - assertEquals("max allocation MB B", 5120, - queueB.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation MB B1", 5120, - queueB1.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation MB B2", 1024, - queueB2.getMaximumAllocation().getMemorySize()); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, cs.getMaximumResourceCapability().getMemorySize(), "max capability MB in CS"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, cs.getMaximumResourceCapability().getVirtualCores(), "max capability vcores in CS"); + assertEquals( + 6144 +, queueA1.getMaximumAllocation().getMemorySize(), "max allocation MB A1"); + assertEquals( + 2 +, queueA1.getMaximumAllocation().getVirtualCores(), "max allocation vcores A1"); + assertEquals(4096 +, queueA2.getMaximumAllocation().getMemorySize(), "max allocation MB A2"); + assertEquals( + 2 +, queueA2.getMaximumAllocation().getVirtualCores(), "max allocation vcores A2"); + assertEquals(5120 +, queueB.getMaximumAllocation().getMemorySize(), "max allocation MB B"); + assertEquals(5120 +, queueB1.getMaximumAllocation().getMemorySize(), "max allocation MB B1"); + assertEquals(1024 +, queueB2.getMaximumAllocation().getMemorySize(), "max allocation MB B2"); // Test get the max-allocation from different parent unsetMaxAllocation(conf, A1); @@ -780,24 +780,24 @@ public void testQueuesMaxAllocationInheritance() throws Exception { cs.reinitialize(conf, rm.getRMContext()); - assertEquals("max capability MB in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("max capability vcores in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - cs.getMaximumResourceCapability().getVirtualCores()); - assertEquals("max allocation MB A1", - 8192, - queueA1.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation vcores A1", - 2, - queueA1.getMaximumAllocation().getVirtualCores()); - assertEquals("max allocation MB B1", - 6144, - queueB1.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation vcores B1", - 2, - queueB1.getMaximumAllocation().getVirtualCores()); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, cs.getMaximumResourceCapability().getMemorySize(), "max capability MB in CS"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, cs.getMaximumResourceCapability().getVirtualCores(), "max capability vcores in CS"); + assertEquals( + 8192 +, queueA1.getMaximumAllocation().getMemorySize(), "max allocation MB A1"); + assertEquals( + 2 +, queueA1.getMaximumAllocation().getVirtualCores(), "max allocation vcores A1"); + assertEquals( + 6144 +, queueB1.getMaximumAllocation().getMemorySize(), "max allocation MB B1"); + assertEquals( + 2 +, queueB1.getMaximumAllocation().getVirtualCores(), "max allocation vcores B1"); // Test the default unsetMaxAllocation(conf, ROOT); @@ -805,24 +805,24 @@ public void testQueuesMaxAllocationInheritance() throws Exception { unsetMaxAllocation(conf, A1); cs.reinitialize(conf, rm.getRMContext()); - assertEquals("max capability MB in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - cs.getMaximumResourceCapability().getMemorySize()); - assertEquals("max capability vcores in CS", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - cs.getMaximumResourceCapability().getVirtualCores()); - assertEquals("max allocation MB A1", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - queueA1.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation vcores A1", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - queueA1.getMaximumAllocation().getVirtualCores()); - assertEquals("max allocation MB A2", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, - queueA2.getMaximumAllocation().getMemorySize()); - assertEquals("max allocation vcores A2", - YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, - queueA2.getMaximumAllocation().getVirtualCores()); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, cs.getMaximumResourceCapability().getMemorySize(), "max capability MB in CS"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, cs.getMaximumResourceCapability().getVirtualCores(), "max capability vcores in CS"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, queueA1.getMaximumAllocation().getMemorySize(), "max allocation MB A1"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, queueA1.getMaximumAllocation().getVirtualCores(), "max allocation vcores A1"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB +, queueA2.getMaximumAllocation().getMemorySize(), "max allocation MB A2"); + assertEquals( + YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES +, queueA2.getMaximumAllocation().getVirtualCores(), "max allocation vcores A2"); cs.stop(); } @@ -854,8 +854,8 @@ public void testVerifyQueuesMaxAllocationConf() throws Exception { cs.reinitialize(conf, rm.getRMContext()); fail("Queue Root maximum allocation can't exceed the cluster setting"); } catch (Exception e) { - assertTrue("maximum allocation exception", - e.getCause().getMessage().contains("maximum allocation")); + assertTrue( + e.getCause().getMessage().contains("maximum allocation"), "maximum allocation exception"); } setMaxAllocation(conf, ROOT, @@ -866,16 +866,16 @@ public void testVerifyQueuesMaxAllocationConf() throws Exception { cs.reinitialize(conf, rm.getRMContext()); fail("Queue A1 maximum allocation can't exceed the cluster setting"); } catch (Exception e) { - assertTrue("maximum allocation exception", - e.getCause().getMessage().contains("maximum allocation")); + assertTrue( + e.getCause().getMessage().contains("maximum allocation"), "maximum allocation exception"); } setMaxAllocation(conf, A1, "memory-mb=8192" + ",vcores=" + largerVcores); try { cs.reinitialize(conf, rm.getRMContext()); fail("Queue A1 maximum allocation can't exceed the cluster setting"); } catch (Exception e) { - assertTrue("maximum allocation exception", - e.getCause().getMessage().contains("maximum allocation")); + assertTrue( + e.getCause().getMessage().contains("maximum allocation"), "maximum allocation exception"); } cs.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/scheduler/capacity/TestCapacitySchedulerSchedulingRequestUpdate.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerSchedulingRequestUpdate.java index c202036abdfbf..72d6021ce7f7f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerSchedulingRequestUpdate.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerSchedulingRequestUpdate.java @@ -42,7 +42,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAttemptRemovedSchedulerEvent; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerSurgicalPreemption.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerSurgicalPreemption.java index 322b8f5b6cb36..5d4005bd80ba0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerSurgicalPreemption.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerSurgicalPreemption.java @@ -45,9 +45,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; import org.apache.hadoop.yarn.util.resource.Resources; import org.hamcrest.CoreMatchers; -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.ArrayList; @@ -56,7 +57,7 @@ import java.util.Set; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.PREFIX; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestCapacitySchedulerSurgicalPreemption extends CapacitySchedulerPreemptionTestBase { @@ -74,7 +75,7 @@ public class TestCapacitySchedulerSurgicalPreemption ".d"); @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); conf.setBoolean( @@ -82,7 +83,8 @@ public void setUp() throws Exception { true); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testSimpleSurgicalPreemption() throws Exception { /** @@ -156,7 +158,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { // App1 should have 33 containers now FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(33, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(33, schedulerApp1.getLiveContainers().size()); // 17 from n1 and 16 from n2 waitNumberOfLiveContainersOnNodeFromApp(cs.getNode(rmNode1.getNodeID()), am1.getApplicationAttemptId(), 17); @@ -177,9 +179,9 @@ protected RMNodeLabelsManager createNodeLabelManager() { MockAM am2 = MockRM.launchAndRegisterAM(app2, rm1, nm1); // NM1/NM2 has available resource = 2G/4G - Assert.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertEquals(4 * GB, cs.getNode(nm2.getNodeId()) + Assertions.assertEquals(4 * GB, cs.getNode(nm2.getNodeId()) .getUnallocatedResource().getMemorySize()); // AM asks for a 1 * GB container @@ -189,7 +191,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { // Call allocation once on n1, we should expect the container reserved on n1 cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Get edit policy and do one update SchedulingMonitorManager smm = ((CapacityScheduler) rm1. @@ -211,20 +213,21 @@ protected RMNodeLabelsManager createNodeLabelManager() { am1.getApplicationAttemptId(), 16); // Ensure preemption metrics were recored. - Assert.assertEquals("Number of preempted containers incorrectly recorded:", - 4, cs.getQueue("root").getMetrics().getAggregatePreemptedContainers()); + Assertions.assertEquals( + 4, cs.getQueue("root").getMetrics().getAggregatePreemptedContainers(), "Number of preempted containers incorrectly recorded:"); - Assert.assertEquals("Amount of preempted memory incorrectly recorded:", - 4 * GB, - cs.getQueue("root").getMetrics().getAggregateMemoryMBPreempted()); + Assertions.assertEquals( + 4 * GB +, cs.getQueue("root").getMetrics().getAggregateMemoryMBPreempted(), "Amount of preempted memory incorrectly recorded:"); - Assert.assertEquals("Number of preempted vcores incorrectly recorded:", 4, - cs.getQueue("root").getMetrics().getAggregateVcoresPreempted()); + Assertions.assertEquals(4 +, cs.getQueue("root").getMetrics().getAggregateVcoresPreempted(), "Number of preempted vcores incorrectly recorded:"); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testSurgicalPreemptionWithAvailableResource() throws Exception { /** @@ -280,7 +283,7 @@ public void testSurgicalPreemptionWithAvailableResource() // App1 should have 31 containers now FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(39, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(39, schedulerApp1.getLiveContainers().size()); // 17 from n1 and 16 from n2 waitNumberOfLiveContainersOnNodeFromApp(cs.getNode(rmNode1.getNodeID()), am1.getApplicationAttemptId(), 20); @@ -308,7 +311,7 @@ public void testSurgicalPreemptionWithAvailableResource() ProportionalCapacityPreemptionPolicy editPolicy = (ProportionalCapacityPreemptionPolicy) smon.getSchedulingEditPolicy(); editPolicy.editSchedule(); - Assert.assertEquals(3, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(3, editPolicy.getToPreemptContainers().size()); // Call editSchedule again: selected containers are killed editPolicy.editSchedule(); @@ -335,7 +338,8 @@ public void testSurgicalPreemptionWithAvailableResource() rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testPriorityPreemptionWhenAllQueuesAreBelowGuaranteedCapacities() throws Exception { /** @@ -401,7 +405,7 @@ public void testPriorityPreemptionWhenAllQueuesAreBelowGuaranteedCapacities() // 7 / 40 = 17.5% < 20% (guaranteed) FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(7, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(7, schedulerApp1.getLiveContainers().size()); // 4 from n1 and 3 from n2 waitNumberOfLiveContainersOnNodeFromApp(cs.getNode(rmNode1.getNodeID()), am1.getApplicationAttemptId(), 4); @@ -433,12 +437,12 @@ public void testPriorityPreemptionWhenAllQueuesAreBelowGuaranteedCapacities() ProportionalCapacityPreemptionPolicy editPolicy = (ProportionalCapacityPreemptionPolicy) smon.getSchedulingEditPolicy(); editPolicy.editSchedule(); - Assert.assertEquals(0, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(0, editPolicy.getToPreemptContainers().size()); // Sleep the timeout interval, we should be able to see containers selected Thread.sleep(1000); editPolicy.editSchedule(); - Assert.assertEquals(2, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(2, editPolicy.getToPreemptContainers().size()); // Call editSchedule again: selected containers are killed, and new AM // container launched @@ -455,7 +459,8 @@ public void testPriorityPreemptionWhenAllQueuesAreBelowGuaranteedCapacities() rm1.close(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testPriorityPreemptionRequiresMoveReservation() throws Exception { /** @@ -524,7 +529,7 @@ public void testPriorityPreemptionRequiresMoveReservation() FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); // 1 from n1 and 2 from n2 waitNumberOfLiveContainersOnNodeFromApp(cs.getNode(rmNode1.getNodeID()), @@ -553,7 +558,7 @@ public void testPriorityPreemptionRequiresMoveReservation() cs.handle(new NodeUpdateSchedulerEvent(rmNode3)); // Make sure container reserved on node3 - Assert.assertNotNull( + Assertions.assertNotNull( cs.getNode(rmNode3.getNodeID()).getReservedContainer()); // Call editSchedule immediately: nothing happens @@ -563,23 +568,23 @@ public void testPriorityPreemptionRequiresMoveReservation() ProportionalCapacityPreemptionPolicy editPolicy = (ProportionalCapacityPreemptionPolicy) smon.getSchedulingEditPolicy(); editPolicy.editSchedule(); - Assert.assertNotNull( + Assertions.assertNotNull( cs.getNode(rmNode3.getNodeID()).getReservedContainer()); // Sleep the timeout interval, we should be able to see reserved container // moved to n2 (n1 occupied by AM) Thread.sleep(1000); editPolicy.editSchedule(); - Assert.assertNull( + Assertions.assertNull( cs.getNode(rmNode3.getNodeID()).getReservedContainer()); - Assert.assertNotNull( + Assertions.assertNotNull( cs.getNode(rmNode2.getNodeID()).getReservedContainer()); - Assert.assertEquals(am2.getApplicationAttemptId(), cs.getNode( + Assertions.assertEquals(am2.getApplicationAttemptId(), cs.getNode( rmNode2.getNodeID()).getReservedContainer().getApplicationAttemptId()); // Do it again, we should see containers marked to be preempt editPolicy.editSchedule(); - Assert.assertEquals(2, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(2, editPolicy.getToPreemptContainers().size()); // Call editSchedule again: selected containers are killed editPolicy.editSchedule(); @@ -595,7 +600,8 @@ public void testPriorityPreemptionRequiresMoveReservation() rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testPriorityPreemptionOnlyTriggeredWhenDemandingQueueUnsatisfied() throws Exception { /** @@ -665,7 +671,7 @@ public void testPriorityPreemptionOnlyTriggeredWhenDemandingQueueUnsatisfied() // App1 should have 9 containers now, so the abs-used-cap of b is 9% FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(9, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(9, schedulerApp1.getLiveContainers().size()); for (int i = 0; i < 9; i++) { waitNumberOfLiveContainersOnNodeFromApp(cs.getNode(rmNodes[i].getNodeID()), am1.getApplicationAttemptId(), 1); @@ -696,8 +702,8 @@ public void testPriorityPreemptionOnlyTriggeredWhenDemandingQueueUnsatisfied() // Check am2 reserved resource from nm1-nm9 for (int i = 1; i < 9; i++) { - Assert.assertNotNull("Should reserve on nm-" + i, - cs.getNode(rmNodes[i].getNodeID()).getReservedContainer()); + Assertions.assertNotNull( + cs.getNode(rmNodes[i].getNodeID()).getReservedContainer(), "Should reserve on nm-" + i); } // Sleep the timeout interval, we should be able to see 6 containers selected @@ -728,7 +734,8 @@ public void testPriorityPreemptionOnlyTriggeredWhenDemandingQueueUnsatisfied() rm1.close(); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testPriorityPreemptionFromHighestPriorityQueueAndOldestContainer() throws Exception { /** @@ -825,7 +832,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { // App1 should have 5 containers now, one for each node FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(5, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(5, schedulerApp1.getLiveContainers().size()); for (int i = 0; i < 5; i++) { waitNumberOfLiveContainersOnNodeFromApp(cs.getNode(rmNodes[i].getNodeID()), am1.getApplicationAttemptId(), 1); @@ -855,9 +862,9 @@ protected RMNodeLabelsManager createNodeLabelManager() { // Check am2 reserved resource from nm0-nm1 for (int i = 0; i < 2; i++) { - Assert.assertNotNull("Should reserve on nm-" + i, - cs.getNode(rmNodes[i].getNodeID()).getReservedContainer()); - Assert.assertEquals(cs.getNode(rmNodes[i].getNodeID()) + Assertions.assertNotNull( + cs.getNode(rmNodes[i].getNodeID()).getReservedContainer(), "Should reserve on nm-" + i); + Assertions.assertEquals(cs.getNode(rmNodes[i].getNodeID()) .getReservedContainer() .getQueueName(), cs.normalizeQueueName(queues[0])); } @@ -886,9 +893,9 @@ protected RMNodeLabelsManager createNodeLabelManager() { // Check am2 reserved resource from nm2-nm3 for (int i = 2; i < 4; i++) { - Assert.assertNotNull("Should reserve on nm-" + i, - cs.getNode(rmNodes[i].getNodeID()).getReservedContainer()); - Assert.assertEquals(cs.getNode(rmNodes[i].getNodeID()) + Assertions.assertNotNull( + cs.getNode(rmNodes[i].getNodeID()).getReservedContainer(), "Should reserve on nm-" + i); + Assertions.assertEquals(cs.getNode(rmNodes[i].getNodeID()) .getReservedContainer() .getQueueName(), cs.normalizeQueueName(queues[1])); } @@ -907,8 +914,8 @@ protected RMNodeLabelsManager createNodeLabelManager() { // We should have one to-preempt container, on node[2] Set selectedToPreempt = editPolicy.getToPreemptContainers().keySet(); - Assert.assertEquals(1, selectedToPreempt.size()); - Assert.assertEquals(mockNMs[2].getNodeId(), + Assertions.assertEquals(1, selectedToPreempt.size()); + Assertions.assertEquals(mockNMs[2].getNodeId(), selectedToPreempt.iterator().next().getAllocatedNode()); // Call editSchedule again: selected containers are killed @@ -930,8 +937,8 @@ protected RMNodeLabelsManager createNodeLabelManager() { // We should have one to-preempt container, on node[3] selectedToPreempt = editPolicy.getToPreemptContainers().keySet(); - Assert.assertEquals(1, selectedToPreempt.size()); - Assert.assertEquals(mockNMs[3].getNodeId(), + Assertions.assertEquals(1, selectedToPreempt.size()); + Assertions.assertEquals(mockNMs[3].getNodeId(), selectedToPreempt.iterator().next().getAllocatedNode()); // Call editSchedule again: selected containers are killed @@ -953,8 +960,8 @@ protected RMNodeLabelsManager createNodeLabelManager() { // We should have one to-preempt container, on node[0] selectedToPreempt = editPolicy.getToPreemptContainers().keySet(); - Assert.assertEquals(1, selectedToPreempt.size()); - Assert.assertEquals(mockNMs[0].getNodeId(), + Assertions.assertEquals(1, selectedToPreempt.size()); + Assertions.assertEquals(mockNMs[0].getNodeId(), selectedToPreempt.iterator().next().getAllocatedNode()); // Call editSchedule again: selected containers are killed @@ -976,8 +983,8 @@ protected RMNodeLabelsManager createNodeLabelManager() { // We should have one to-preempt container, on node[0] selectedToPreempt = editPolicy.getToPreemptContainers().keySet(); - Assert.assertEquals(1, selectedToPreempt.size()); - Assert.assertEquals(mockNMs[1].getNodeId(), + Assertions.assertEquals(1, selectedToPreempt.size()); + Assertions.assertEquals(mockNMs[1].getNodeId(), selectedToPreempt.iterator().next().getAllocatedNode()); // Call editSchedule again: selected containers are killed @@ -1085,7 +1092,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { // App1 should have 5 containers now, one for each node FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(NUM_NM, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(NUM_NM, schedulerApp1.getLiveContainers().size()); for (int i = 0; i < NUM_NM; i++) { waitNumberOfLiveContainersOnNodeFromApp(cs.getNode( rmNodes[i].getNodeID()), am1.getApplicationAttemptId(), 1); @@ -1151,19 +1158,18 @@ protected RMNodeLabelsManager createNodeLabelManager() { // We should only allow to preempt 2 containers, on node1 and node2 Set selectedToPreempt = editPolicy.getToPreemptContainers().keySet(); - Assert.assertEquals(2, selectedToPreempt.size()); + Assertions.assertEquals(2, selectedToPreempt.size()); List selectedToPreemptNodeIds = new ArrayList<>(); for (RMContainer rmc : selectedToPreempt) { selectedToPreemptNodeIds.add(rmc.getAllocatedNode()); } - assertThat(selectedToPreemptNodeIds, CoreMatchers.hasItems( - mockNMs[1].getNodeId(), mockNMs[2].getNodeId())); - + assertThat(selectedToPreemptNodeIds).contains(mockNMs[1].getNodeId(), mockNMs[2].getNodeId()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testPreemptionForFragmentatedCluster() throws Exception { // Set additional_balance_queue_based_on_reserved_res to true to get // additional preemptions. @@ -1224,7 +1230,7 @@ public void testPreemptionForFragmentatedCluster() throws Exception { // App1 should have 5 containers now FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(5, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(5, schedulerApp1.getLiveContainers().size()); // launch an app to queue, AM container should be launched in nm1 MockRMAppSubmissionData data = @@ -1250,7 +1256,7 @@ public void testPreemptionForFragmentatedCluster() throws Exception { // App2 should have 2 containers now FiCaSchedulerApp schedulerApp2 = cs.getApplicationAttempt( am2.getApplicationAttemptId()); - Assert.assertEquals(2, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp2.getLiveContainers().size()); waitNumberOfReservedContainersFromApp(schedulerApp2, 1); @@ -1274,12 +1280,13 @@ public void testPreemptionForFragmentatedCluster() throws Exception { tick++; Thread.sleep(100); } - Assert.assertEquals(3, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(3, schedulerApp2.getLiveContainers().size()); rm1.close(); } - @Test(timeout = 600000) + @Test + @Timeout(value = 600) public void testPreemptionToBalanceWithCustomTimeout() throws Exception { /** * Test case: Submit two application (app1/app2) to different queues, queue @@ -1345,7 +1352,7 @@ public void testPreemptionToBalanceWithCustomTimeout() throws Exception { // App1 should have 39 containers now FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt( am1.getApplicationAttemptId()); - Assert.assertEquals(39, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(39, schedulerApp1.getLiveContainers().size()); // 20 from n1 and 19 from n2 waitNumberOfLiveContainersOnNodeFromApp(cs.getNode(rmNode1.getNodeID()), am1.getApplicationAttemptId(), 20); @@ -1373,10 +1380,10 @@ public void testPreemptionToBalanceWithCustomTimeout() throws Exception { ProportionalCapacityPreemptionPolicy editPolicy = (ProportionalCapacityPreemptionPolicy) smon.getSchedulingEditPolicy(); editPolicy.editSchedule(); - Assert.assertEquals(4, editPolicy.getToPreemptContainers().size()); + Assertions.assertEquals(4, editPolicy.getToPreemptContainers().size()); // check live containers immediately, nothing happen - Assert.assertEquals(39, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(39, schedulerApp1.getLiveContainers().size()); Thread.sleep(20*1000); // Call editSchedule again: selected containers are killed diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWeightMode.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWeightMode.java index 216ec0f9b9261..da78767c3318e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWeightMode.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWeightMode.java @@ -43,9 +43,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerAppReport; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler; -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.ArrayList; @@ -70,7 +71,7 @@ public class TestCapacitySchedulerWeightMode { RMNodeLabelsManager mgr; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -287,7 +288,8 @@ public static Configuration getCSConfWithLabelsParentUsePctChildUseWeight( * The only difference is, instead of using label, it uses weight mode * @throws Exception */ - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testContainerAllocateWithComplexLabelsWeightOnly() throws Exception { internalTestContainerAllocationWithNodeLabel( getCSConfWithQueueLabelsWeightOnly(conf)); @@ -300,7 +302,8 @@ public void testContainerAllocateWithComplexLabelsWeightOnly() throws Exception * Parent uses weight, child uses percent * @throws Exception */ - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testContainerAllocateWithComplexLabelsWeightAndPercentMixed1() throws Exception { internalTestContainerAllocationWithNodeLabel( getCSConfWithLabelsParentUseWeightChildUsePct(conf)); @@ -313,7 +316,8 @@ public void testContainerAllocateWithComplexLabelsWeightAndPercentMixed1() throw * Parent uses percent, child uses weight * @throws Exception */ - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testContainerAllocateWithComplexLabelsWeightAndPercentMixed2() throws Exception { internalTestContainerAllocationWithNodeLabel( getCSConfWithLabelsParentUsePctChildUseWeight(conf)); @@ -323,7 +327,8 @@ public void testContainerAllocateWithComplexLabelsWeightAndPercentMixed2() throw * This checks whether the parent prints the correct log about the * configured mode. */ - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testGetCapacityOrWeightStringUsingWeights() throws IOException { try (MockRM rm = new MockRM( getCSConfWithQueueLabelsWeightOnly(conf))) { @@ -348,7 +353,8 @@ public void testGetCapacityOrWeightStringUsingWeights() throws IOException { * This checks whether the parent prints the correct log about the * configured mode. */ - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testGetCapacityOrWeightStringParentPctLeafWeights() throws IOException { try (MockRM rm = new MockRM( @@ -389,13 +395,13 @@ public void testChildAccessibleNodeLabelsWeightMode() throws Exception { (CapacityScheduler) rm.getRMContext().getScheduler(); LeafQueue b1 = (LeafQueue) cs.getQueue(B1.getFullPath()); - Assert.assertNotNull(b1); - Assert.assertTrue(b1.getAccessibleNodeLabels().isEmpty()); + Assertions.assertNotNull(b1); + Assertions.assertTrue(b1.getAccessibleNodeLabels().isEmpty()); Set b1ExistingNodeLabels = ((CSQueue) b1).getQueueCapacities() .getExistingNodeLabels(); - Assert.assertEquals(1, b1ExistingNodeLabels.size()); - Assert.assertEquals("", b1ExistingNodeLabels.iterator().next()); + Assertions.assertEquals(1, b1ExistingNodeLabels.size()); + Assertions.assertEquals("", b1ExistingNodeLabels.iterator().next()); rm.close(); } @@ -418,7 +424,7 @@ public void testAccessibleNodeLabelsInheritanceNoWeightMode() throws IOException try { cs.reinitialize(newConf, rm.getRMContext()); } catch (Exception e) { - Assert.fail("Reinitialization failed with " + e); + Assertions.fail("Reinitialization failed with " + e); } } @@ -443,15 +449,15 @@ public void testQueueInfoWeight() throws Exception { LeafQueue a = (LeafQueue) cs.getQueue("root.a"); - Assert.assertNotNull(a); - Assert.assertEquals(a.getQueueCapacities().getWeight(), + Assertions.assertNotNull(a); + Assertions.assertEquals(a.getQueueCapacities().getWeight(), a.getQueueInfo(false, false).getWeight(), 1e-6); LeafQueue b = (LeafQueue) cs.getQueue("root.b"); - Assert.assertNotNull(b); - Assert.assertEquals(b.getQueueCapacities().getWeight(), + Assertions.assertNotNull(b); + Assertions.assertEquals(b.getQueueCapacities().getWeight(), b.getQueueInfo(false, false).getWeight(), 1e-6); rm.close(); @@ -534,7 +540,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate("*", 1024, 1, new ArrayList(), "y"); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2L); - Assert.assertTrue(rm1.waitForState(nm2, containerId, + Assertions.assertTrue(rm1.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am1.getApplicationAttemptId(), containerId, rm1, "h2"); @@ -557,9 +563,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // (Maximum capacity reached) am2.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am2.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm4, containerId, + Assertions.assertFalse(rm1.waitForState(nm4, containerId, RMContainerState.ALLOCATED)); - Assert.assertFalse(rm1.waitForState(nm5, containerId, + Assertions.assertFalse(rm1.waitForState(nm5, containerId, RMContainerState.ALLOCATED)); // launch an app to queue b2 @@ -578,9 +584,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // y,z). Will successfully allocate on nm3 am3.allocate("*", 1024, 1, new ArrayList(), "y"); containerId = ContainerId.newContainerId(am3.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm1, containerId, + Assertions.assertFalse(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); - Assert.assertTrue(rm1.waitForState(nm3, containerId, + Assertions.assertTrue(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am3.getApplicationAttemptId(), containerId, rm1, "h3"); @@ -589,7 +595,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // Will successfully allocate on nm4 only. am3.allocate("*", 1024, 1, new ArrayList(), "z"); containerId = ContainerId.newContainerId(am3.getApplicationAttemptId(), 3L); - Assert.assertTrue(rm1.waitForState(nm4, containerId, + Assertions.assertTrue(rm1.waitForState(nm4, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am3.getApplicationAttemptId(), containerId, rm1, "h4"); @@ -602,21 +608,21 @@ private void checkTaskContainersHost(ApplicationAttemptId attemptId, YarnScheduler scheduler = rm.getRMContext().getScheduler(); SchedulerAppReport appReport = scheduler.getSchedulerAppInfo(attemptId); - Assert.assertTrue(appReport.getLiveContainers().size() > 0); + Assertions.assertTrue(appReport.getLiveContainers().size() > 0); for (RMContainer c : appReport.getLiveContainers()) { if (c.getContainerId().equals(containerId)) { - Assert.assertEquals(host, c.getAllocatedNode().getHost()); + Assertions.assertEquals(host, c.getAllocatedNode().getHost()); } } } private void validateCapacityOrWeightString(String capacityOrWeightString, boolean shouldContainWeight) { - Assert.assertEquals(shouldContainWeight, + Assertions.assertEquals(shouldContainWeight, capacityOrWeightString.contains("weight")); - Assert.assertEquals(shouldContainWeight, + Assertions.assertEquals(shouldContainWeight, capacityOrWeightString.contains("normalizedWeight")); - Assert.assertEquals(!shouldContainWeight, + Assertions.assertEquals(!shouldContainWeight, capacityOrWeightString.contains("capacity")); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWithMultiResourceTypes.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWithMultiResourceTypes.java index deebe3d59be4c..838e61c6d486b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWithMultiResourceTypes.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWithMultiResourceTypes.java @@ -56,10 +56,11 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; -import static org.junit.Assert.assertEquals; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; @@ -142,23 +143,23 @@ public void testMaximumAllocationRefreshWithMultipleResourceTypes() throws Excep rm.start(); CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); - Assert.assertEquals(3333L, + Assertions.assertEquals(3333L, cs.getMaximumResourceCapability().getResourceValue(RESOURCE_1)); - Assert.assertEquals(3333L, + Assertions.assertEquals(3333L, cs.getMaximumAllocation().getResourceValue(RESOURCE_1)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, cs.getMaximumResourceCapability() .getResourceValue(ResourceInformation.MEMORY_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, cs.getMaximumAllocation() .getResourceValue(ResourceInformation.MEMORY_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, cs.getMaximumResourceCapability() .getResourceValue(ResourceInformation.VCORES_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, cs.getMaximumAllocation() .getResourceValue(ResourceInformation.VCORES_URI)); @@ -175,26 +176,26 @@ public void testMaximumAllocationRefreshWithMultipleResourceTypes() throws Excep exception = true; } - Assert.assertTrue("Should have exception in CS", exception); + Assertions.assertTrue(exception, "Should have exception in CS"); // Maximum allocation won't be updated - Assert.assertEquals(3333L, + Assertions.assertEquals(3333L, cs.getMaximumResourceCapability().getResourceValue(RESOURCE_1)); - Assert.assertEquals(3333L, + Assertions.assertEquals(3333L, cs.getMaximumAllocation().getResourceValue(RESOURCE_1)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, cs.getMaximumResourceCapability() .getResourceValue(ResourceInformation.MEMORY_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, cs.getMaximumAllocation() .getResourceValue(ResourceInformation.MEMORY_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, cs.getMaximumResourceCapability() .getResourceValue(ResourceInformation.VCORES_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, cs.getMaximumAllocation() .getResourceValue(ResourceInformation.VCORES_URI)); @@ -206,26 +207,26 @@ public void testMaximumAllocationRefreshWithMultipleResourceTypes() throws Excep cs.reinitialize(csconf, rm.getRMContext()); // Maximum allocation will be updated - Assert.assertEquals(3334, + Assertions.assertEquals(3334, cs.getMaximumResourceCapability().getResourceValue(RESOURCE_1)); // Since we haven't updated the real configuration of ResourceUtils, // cs.getMaximumAllocation won't be updated. - Assert.assertEquals(3333, + Assertions.assertEquals(3333, cs.getMaximumAllocation().getResourceValue(RESOURCE_1)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, cs.getMaximumResourceCapability() .getResourceValue(ResourceInformation.MEMORY_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, cs.getMaximumAllocation() .getResourceValue(ResourceInformation.MEMORY_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, cs.getMaximumResourceCapability() .getResourceValue(ResourceInformation.VCORES_URI)); - Assert.assertEquals( + Assertions.assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, cs.getMaximumAllocation() .getResourceValue(ResourceInformation.VCORES_URI)); @@ -265,7 +266,7 @@ public void testDefaultResourceCalculatorWithThirdResourceTypes() throws Excepti exception = true; } - Assert.assertTrue("Should have exception in CS", exception); + Assertions.assertTrue(exception, "Should have exception in CS"); } @Test @@ -327,12 +328,12 @@ public void testMaxLimitsOfQueueWithMultipleResources() throws Exception { rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); // check node report - Assert.assertEquals(1 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(9 * GB, + Assertions.assertEquals(1 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(9 * GB, report_nm1.getAvailableResource().getMemorySize()); - Assert.assertEquals(0, report_nm1.getUsedResource() + Assertions.assertEquals(0, report_nm1.getUsedResource() .getResourceInformation(ResourceInformation.GPU_URI).getValue()); - Assert.assertEquals(4, report_nm1.getAvailableResource() + Assertions.assertEquals(4, report_nm1.getAvailableResource() .getResourceInformation(ResourceInformation.GPU_URI).getValue()); nameToValues.put(ResourceInformation.GPU_URI, "4"); @@ -345,17 +346,17 @@ public void testMaxLimitsOfQueueWithMultipleResources() throws Exception { Priority.newInstance(1), "*", containerGpuResource, 1)), null); ContainerId containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm.waitForState(nm1, containerId2, + Assertions.assertTrue(rm.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire this container am1.allocate(null, null); report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(2 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(4, report_nm1.getUsedResource() + Assertions.assertEquals(2 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(4, report_nm1.getUsedResource() .getResourceInformation(ResourceInformation.GPU_URI).getValue()); - Assert.assertEquals(0, report_nm1.getAvailableResource() + Assertions.assertEquals(0, report_nm1.getAvailableResource() .getResourceInformation(ResourceInformation.GPU_URI).getValue()); nameToValues.clear(); @@ -367,20 +368,21 @@ public void testMaxLimitsOfQueueWithMultipleResources() throws Exception { Priority.newInstance(1), "*", containerResource, 1)), null); ContainerId containerId3 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 3); - Assert.assertTrue(rm.waitForState(nm1, containerId3, + Assertions.assertTrue(rm.waitForState(nm1, containerId3, RMContainerState.ALLOCATED)); report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(3 * GB, report_nm1.getUsedResource().getMemorySize()); - Assert.assertEquals(4, report_nm1.getUsedResource() + Assertions.assertEquals(3 * GB, report_nm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(4, report_nm1.getUsedResource() .getResourceInformation(ResourceInformation.GPU_URI).getValue()); - Assert.assertEquals(0, report_nm1.getAvailableResource() + Assertions.assertEquals(0, report_nm1.getAvailableResource() .getResourceInformation(ResourceInformation.GPU_URI).getValue()); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testConsumeAllExtendedResourcesWithSmallMinUserLimitPct() throws Exception { int GB = 1024; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWorkflowPriorityMapping.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWorkflowPriorityMapping.java index 1108e76a3ec1b..b17f7bb095807 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWorkflowPriorityMapping.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerWorkflowPriorityMapping.java @@ -34,7 +34,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.B_CAPACITY; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.ROOT; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.List; @@ -49,8 +49,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.WorkflowPriorityMappingsManager.WorkflowPriorityMapping; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; @@ -58,7 +58,7 @@ public class TestCapacitySchedulerWorkflowPriorityMapping { private MockRM mockRM = null; - @After + @AfterEach public void tearDown() { if (mockRM != null) { mockRM.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/scheduler/capacity/TestChildQueueOrder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestChildQueueOrder.java index c03392da11018..ce01edccb2542 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestChildQueueOrder.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestChildQueueOrder.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; @@ -58,9 +58,9 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.apache.hadoop.yarn.util.resource.Resources; -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.mockito.InOrder; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -82,7 +82,7 @@ public class TestChildQueueOrder { private final ResourceCalculator resourceComparator = new DefaultResourceCalculator(); - @Before + @BeforeEach public void setUp() throws Exception { rmContext = TestUtils.getMockRMContext(); conf = new YarnConfiguration(); @@ -444,7 +444,7 @@ public void testSortedQueues() throws Exception { ((ParentQueue)root).getChildQueuesToPrint()); } - @After + @AfterEach public void tearDown() throws Exception { } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestConfigurationProperties.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestConfigurationProperties.java index 3f046700ba3d0..16c4fdd51f9a9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestConfigurationProperties.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestConfigurationProperties.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; @@ -28,7 +28,7 @@ public class TestConfigurationProperties { private static final Map PROPERTIES = new HashMap<>(); - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { PROPERTIES.put("root.1.2.3", "TEST_VALUE_1"); PROPERTIES.put("root.1", "TEST_VALUE_2"); @@ -48,15 +48,15 @@ public void testGetPropertiesWithPrefix() { Map props = configurationProperties .getPropertiesWithPrefix("root.1.2"); - Assert.assertEquals(4, props.size()); - Assert.assertTrue(props.containsKey("")); - Assert.assertEquals("TEST_VALUE_3", props.get("")); - Assert.assertTrue(props.containsKey("4")); - Assert.assertEquals("TEST_VALUE_3_1", props.get("4")); - Assert.assertTrue(props.containsKey("3")); - Assert.assertEquals("TEST_VALUE_1", props.get("3")); - Assert.assertTrue(props.containsKey("4.5")); - Assert.assertEquals("TEST_VALUE_3_2", props.get("4.5")); + Assertions.assertEquals(4, props.size()); + Assertions.assertTrue(props.containsKey("")); + Assertions.assertEquals("TEST_VALUE_3", props.get("")); + Assertions.assertTrue(props.containsKey("4")); + Assertions.assertEquals("TEST_VALUE_3_1", props.get("4")); + Assertions.assertTrue(props.containsKey("3")); + Assertions.assertEquals("TEST_VALUE_1", props.get("3")); + Assertions.assertTrue(props.containsKey("4.5")); + Assertions.assertEquals("TEST_VALUE_3_2", props.get("4.5")); // Test the scenario where the prefix has a dot appended to it // (see CapacitySchedulerConfiguration.getQueuePrefix(String queue)). @@ -64,28 +64,28 @@ public void testGetPropertiesWithPrefix() { props = configurationProperties .getPropertiesWithPrefix("root.1.2.4."); - Assert.assertEquals(2, props.size()); - Assert.assertTrue(props.containsKey("")); - Assert.assertEquals("TEST_VALUE_3_1", props.get("")); - Assert.assertTrue(props.containsKey("5")); - Assert.assertEquals("TEST_VALUE_3_2", props.get("5")); + Assertions.assertEquals(2, props.size()); + Assertions.assertTrue(props.containsKey("")); + Assertions.assertEquals("TEST_VALUE_3_1", props.get("")); + Assertions.assertTrue(props.containsKey("5")); + Assertions.assertEquals("TEST_VALUE_3_2", props.get("5")); Map propsWithRootPrefix = configurationProperties .getPropertiesWithPrefix("root"); - Assert.assertEquals(6, propsWithRootPrefix.size()); - Assert.assertTrue(propsWithRootPrefix.containsKey("")); - Assert.assertEquals("TEST_VALUE_4", propsWithRootPrefix.get("")); - Assert.assertTrue(propsWithRootPrefix.containsKey("1.2.3")); - Assert.assertEquals("TEST_VALUE_1", propsWithRootPrefix.get("1.2.3")); - Assert.assertTrue(propsWithRootPrefix.containsKey("1")); - Assert.assertEquals("TEST_VALUE_2", propsWithRootPrefix.get("1")); - Assert.assertTrue(propsWithRootPrefix.containsKey("1.2")); - Assert.assertEquals("TEST_VALUE_3", propsWithRootPrefix.get("1.2")); - Assert.assertTrue(propsWithRootPrefix.containsKey("1.2.4")); - Assert.assertEquals("TEST_VALUE_3_1", propsWithRootPrefix.get("1.2.4")); - Assert.assertTrue(propsWithRootPrefix.containsKey("1.2.4.5")); - Assert.assertEquals("TEST_VALUE_3_2", propsWithRootPrefix.get("1.2.4.5")); + Assertions.assertEquals(6, propsWithRootPrefix.size()); + Assertions.assertTrue(propsWithRootPrefix.containsKey("")); + Assertions.assertEquals("TEST_VALUE_4", propsWithRootPrefix.get("")); + Assertions.assertTrue(propsWithRootPrefix.containsKey("1.2.3")); + Assertions.assertEquals("TEST_VALUE_1", propsWithRootPrefix.get("1.2.3")); + Assertions.assertTrue(propsWithRootPrefix.containsKey("1")); + Assertions.assertEquals("TEST_VALUE_2", propsWithRootPrefix.get("1")); + Assertions.assertTrue(propsWithRootPrefix.containsKey("1.2")); + Assertions.assertEquals("TEST_VALUE_3", propsWithRootPrefix.get("1.2")); + Assertions.assertTrue(propsWithRootPrefix.containsKey("1.2.4")); + Assertions.assertEquals("TEST_VALUE_3_1", propsWithRootPrefix.get("1.2.4")); + Assertions.assertTrue(propsWithRootPrefix.containsKey("1.2.4.5")); + Assertions.assertEquals("TEST_VALUE_3_2", propsWithRootPrefix.get("1.2.4.5")); } @Test @@ -96,15 +96,15 @@ public void testGetPropertiesWithFullyQualifiedName() { Map props = configurationProperties .getPropertiesWithPrefix("root.1.2", true); - Assert.assertEquals(4, props.size()); - Assert.assertTrue(props.containsKey("root.1.2.3")); - Assert.assertEquals("TEST_VALUE_1", props.get("root.1.2.3")); - Assert.assertTrue(props.containsKey("root.1.2")); - Assert.assertEquals("TEST_VALUE_3", props.get("root.1.2")); - Assert.assertTrue(props.containsKey("root.1.2.4.5")); - Assert.assertEquals("TEST_VALUE_3_2", props.get("root.1.2.4.5")); - Assert.assertTrue(props.containsKey("root.1.2.4")); - Assert.assertEquals("TEST_VALUE_3_1", props.get("root.1.2.4")); + Assertions.assertEquals(4, props.size()); + Assertions.assertTrue(props.containsKey("root.1.2.3")); + Assertions.assertEquals("TEST_VALUE_1", props.get("root.1.2.3")); + Assertions.assertTrue(props.containsKey("root.1.2")); + Assertions.assertEquals("TEST_VALUE_3", props.get("root.1.2")); + Assertions.assertTrue(props.containsKey("root.1.2.4.5")); + Assertions.assertEquals("TEST_VALUE_3_2", props.get("root.1.2.4.5")); + Assertions.assertTrue(props.containsKey("root.1.2.4")); + Assertions.assertEquals("TEST_VALUE_3_1", props.get("root.1.2.4")); } @Test @@ -118,8 +118,8 @@ public void testGetPropertiesWithPrefixEmptyResult() { Map propsNonExistingRootPrefix = configurationProperties .getPropertiesWithPrefix("3"); - Assert.assertEquals(0, propsEmptyPrefix.size()); - Assert.assertEquals(0, propsLongPrefix.size()); - Assert.assertEquals(0, propsNonExistingRootPrefix.size()); + Assertions.assertEquals(0, propsEmptyPrefix.size()); + Assertions.assertEquals(0, propsLongPrefix.size()); + Assertions.assertEquals(0, propsNonExistingRootPrefix.size()); } } \ 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/scheduler/capacity/TestContainerAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestContainerAllocation.java index df1db68f7d73d..9242ab8d1e76d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestContainerAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestContainerAllocation.java @@ -67,9 +67,10 @@ import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.apache.hadoop.yarn.util.resource.Resources; -import org.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 static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_MB; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAX_ASSIGN_PER_HEARTBEAT; @@ -97,7 +98,7 @@ public class TestContainerAllocation { RMNodeLabelsManager mgr; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -106,7 +107,8 @@ public void setUp() throws Exception { mgr.init(conf); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testExcessReservationThanNodeManagerCapacity() throws Exception { @SuppressWarnings("resource") MockRM rm = new MockRM(conf); @@ -127,7 +129,7 @@ public void testExcessReservationThanNodeManagerCapacity() throws Exception { LOG.info("Waiting for node managers to register : " + size); Thread.sleep(100); } - Assert.assertEquals(2, rm.getRMContext().getRMNodes().size()); + Assertions.assertEquals(2, rm.getRMContext().getRMNodes().size()); // Submit an application RMApp app1 = MockRMAppSubmitter.submitWithMemory(128, rm); @@ -156,7 +158,7 @@ public void testExcessReservationThanNodeManagerCapacity() throws Exception { // No container should be allocated. // Internally it should not been reserved. - Assert.assertTrue(alloc1Response.getAllocatedContainers().size() == 0); + Assertions.assertTrue(alloc1Response.getAllocatedContainers().size() == 0); LOG.info("heartbeating nm2"); waitCounter = 20; @@ -169,7 +171,7 @@ public void testExcessReservationThanNodeManagerCapacity() throws Exception { } LOG.info("received container : " + alloc1Response.getAllocatedContainers().size()); - Assert.assertTrue(alloc1Response.getAllocatedContainers().size() == 1); + Assertions.assertTrue(alloc1Response.getAllocatedContainers().size() == 1); rm.stop(); } @@ -192,16 +194,16 @@ public void testContainerTokenGeneratedOnPullRequest() throws Exception { RMContainer container = rm1.getResourceScheduler().getRMContainer(containerId2); // no container token is generated. - Assert.assertEquals(containerId2, container.getContainerId()); - Assert.assertNull(container.getContainer().getContainerToken()); + Assertions.assertEquals(containerId2, container.getContainerId()); + Assertions.assertNull(container.getContainer().getContainerToken()); // acquire the container. List containers = am1.allocate(new ArrayList(), new ArrayList()).getAllocatedContainers(); - Assert.assertEquals(containerId2, containers.get(0).getId()); + Assertions.assertEquals(containerId2, containers.get(0).getId()); // container token is generated. - Assert.assertNotNull(containers.get(0).getContainerToken()); + Assertions.assertNotNull(containers.get(0).getContainerToken()); rm1.stop(); } @@ -227,7 +229,7 @@ public void testNormalContainerAllocationWhenDNSUnavailable() throws Exception{ am1.allocate(new ArrayList(), new ArrayList()).getAllocatedContainers(); // not able to fetch the container; - Assert.assertEquals(0, containers.size()); + Assertions.assertEquals(0, containers.size()); } finally { SecurityUtilTestHelper.setTokenServiceUseIp(false); } @@ -235,7 +237,7 @@ public void testNormalContainerAllocationWhenDNSUnavailable() throws Exception{ am1.allocate(new ArrayList(), new ArrayList()).getAllocatedContainers(); // should be able to fetch the container; - Assert.assertEquals(1, containers.size()); + Assertions.assertEquals(1, containers.size()); rm1.stop(); } @@ -249,7 +251,7 @@ public void testLogAggregationContextPassedIntoContainerToken() MockNM nm1 = rm1.registerNode("127.0.0.1:1234", 8000); MockNM nm2 = rm1.registerNode("127.0.0.1:2345", 8000); // LogAggregationContext is set as null - Assert + Assertions .assertNull(getLogAggregationContextFromContainerToken(rm1, nm1, null)); // create a not-null LogAggregationContext @@ -263,15 +265,15 @@ public void testLogAggregationContextPassedIntoContainerToken() LogAggregationContext returned = getLogAggregationContextFromContainerToken(rm1, nm2, logAggregationContext); - Assert.assertEquals("includePattern", returned.getIncludePattern()); - Assert.assertEquals("excludePattern", returned.getExcludePattern()); - Assert.assertEquals("rolledLogsIncludePattern", + Assertions.assertEquals("includePattern", returned.getIncludePattern()); + Assertions.assertEquals("excludePattern", returned.getExcludePattern()); + Assertions.assertEquals("rolledLogsIncludePattern", returned.getRolledLogsIncludePattern()); - Assert.assertEquals("rolledLogsExcludePattern", + Assertions.assertEquals("rolledLogsExcludePattern", returned.getRolledLogsExcludePattern()); - Assert.assertEquals("policyClass", + Assertions.assertEquals("policyClass", returned.getLogAggregationPolicyClassName()); - Assert.assertEquals("policyParameters", + Assertions.assertEquals("policyParameters", returned.getLogAggregationPolicyParameters()); rm1.stop(); } @@ -295,9 +297,9 @@ private LogAggregationContext getLogAggregationContextFromContainerToken( List containers = am2.allocate(new ArrayList(), new ArrayList()).getAllocatedContainers(); - Assert.assertEquals(containerId, containers.get(0).getId()); + Assertions.assertEquals(containerId, containers.get(0).getId()); // container token is generated. - Assert.assertNotNull(containers.get(0).getContainerToken()); + Assertions.assertNotNull(containers.get(0).getContainerToken()); ContainerTokenIdentifier token = BuilderUtils.newContainerTokenIdentifier(containers.get(0) .getContainerToken()); @@ -336,7 +338,8 @@ public Token createContainerToken(ContainerId containerId, // This is to test fetching AM container will be retried, if AM container is // not fetchable since DNS is unavailable causing container token/NMtoken // creation failure. - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAMContainerAllocationWhenDNSUnavailable() throws Exception { MockRM rm1 = new MockRM(conf) { @Override @@ -358,7 +361,7 @@ protected RMSecretManagerService createRMSecretManagerService() { while (numRetries <= 5) { nm1.nodeHeartbeat(true); Thread.sleep(1000); - Assert.assertEquals(RMAppAttemptState.SCHEDULED, + Assertions.assertEquals(RMAppAttemptState.SCHEDULED, attempt.getAppAttemptState()); System.out.println("Waiting for am container to be allocated."); } @@ -369,7 +372,8 @@ protected RMSecretManagerService createRMSecretManagerService() { rm1.stop(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testExcessReservationWillBeUnreserved() throws Exception { /** * Test case: Submit two application (app1/app2) to a queue. And there's one @@ -433,20 +437,20 @@ public void testExcessReservationWillBeUnreserved() throws Exception { cs.getApplicationAttempt(am2.getApplicationAttemptId()); // Check if a 4G contaienr allocated for app1, and nothing allocated for app2 - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assert.assertTrue(schedulerApp2.getReservedContainers().size() > 0); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertTrue(schedulerApp2.getReservedContainers().size() > 0); // NM1 has available resource = 2G (8G - 2 * 1G - 4G) - Assert.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Usage of queue = 4G + 2 * 1G + 4G (reserved) - Assert.assertEquals(10 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(10 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed().getMemorySize()); - Assert.assertEquals(4 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(4 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved().getMemorySize()); - Assert.assertEquals(4 * GB, leafQueue.getQueueResourceUsage().getReserved() + Assertions.assertEquals(4 * GB, leafQueue.getQueueResourceUsage().getReserved() .getMemorySize()); // Cancel asks of app2 and re-kick RM @@ -454,21 +458,22 @@ public void testExcessReservationWillBeUnreserved() throws Exception { cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); // App2's reservation will be cancelled - Assert.assertTrue(schedulerApp2.getReservedContainers().size() == 0); - Assert.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertTrue(schedulerApp2.getReservedContainers().size() == 0); + Assertions.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); - Assert.assertEquals(6 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertEquals(6 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed().getMemorySize()); - Assert.assertEquals(0, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0, cs.getRootQueue().getQueueResourceUsage() .getReserved().getMemorySize()); - Assert.assertEquals(0, leafQueue.getQueueResourceUsage().getReserved() + Assertions.assertEquals(0, leafQueue.getQueueResourceUsage().getReserved() .getMemorySize()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAllocationForReservedContainer() throws Exception { /** * Test case: Submit two application (app1/app2) to a queue. And there's one @@ -532,20 +537,20 @@ public void testAllocationForReservedContainer() throws Exception { cs.getApplicationAttempt(am2.getApplicationAttemptId()); // Check if a 4G container allocated for app1, and nothing allocated for app2 - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assert.assertTrue(schedulerApp2.getReservedContainers().size() > 0); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertTrue(schedulerApp2.getReservedContainers().size() > 0); // NM1 has available resource = 2G (8G - 2 * 1G - 4G) - Assert.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Usage of queue = 4G + 2 * 1G + 4G (reserved) - Assert.assertEquals(10 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(10 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed().getMemorySize()); - Assert.assertEquals(4 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(4 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved().getMemorySize()); - Assert.assertEquals(4 * GB, leafQueue.getQueueResourceUsage().getReserved() + Assertions.assertEquals(4 * GB, leafQueue.getQueueResourceUsage().getReserved() .getMemorySize()); // Mark one app1 container as killed/completed and re-kick RM @@ -561,26 +566,27 @@ public void testAllocationForReservedContainer() throws Exception { // Check 4G container cancelled for app1, and one container allocated for // app2 - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(2, schedulerApp2.getLiveContainers().size()); - Assert.assertFalse(schedulerApp2.getReservedContainers().size() > 0); + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp2.getLiveContainers().size()); + Assertions.assertFalse(schedulerApp2.getReservedContainers().size() > 0); // NM1 has available resource = 2G (8G - 2 * 1G - 4G) - Assert.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Usage of queue = 4G + 2 * 1G - Assert.assertEquals(6 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(6 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved().getMemorySize()); - Assert.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved() + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved() .getMemorySize()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testReservedContainerMetricsOnDecommisionedNode() throws Exception { /** * Test case: Submit two application (app1/app2) to a queue. And there's one @@ -644,42 +650,43 @@ public void testReservedContainerMetricsOnDecommisionedNode() throws Exception { cs.getApplicationAttempt(am2.getApplicationAttemptId()); // Check if a 4G container allocated for app1, and nothing allocated for app2 - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assert.assertTrue(schedulerApp2.getReservedContainers().size() > 0); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertTrue(schedulerApp2.getReservedContainers().size() > 0); // NM1 has available resource = 2G (8G - 2 * 1G - 4G) - Assert.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) + Assertions.assertEquals(2 * GB, cs.getNode(nm1.getNodeId()) .getUnallocatedResource().getMemorySize()); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Usage of queue = 4G + 2 * 1G + 4G (reserved) - Assert.assertEquals(10 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(10 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed().getMemorySize()); - Assert.assertEquals(4 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(4 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved().getMemorySize()); - Assert.assertEquals(4 * GB, leafQueue.getQueueResourceUsage().getReserved() + Assertions.assertEquals(4 * GB, leafQueue.getQueueResourceUsage().getReserved() .getMemorySize()); // Remove the node cs.handle(new NodeRemovedSchedulerEvent(rmNode1)); // Check all container cancelled for app1 and app2 - Assert.assertEquals(0, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(0, schedulerApp2.getLiveContainers().size()); - Assert.assertFalse(schedulerApp2.getReservedContainers().size() > 0); + Assertions.assertEquals(0, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(0, schedulerApp2.getLiveContainers().size()); + Assertions.assertFalse(schedulerApp2.getReservedContainers().size() > 0); // Usage and Reserved capacity of queue is 0 - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved().getMemorySize()); - Assert.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved() + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved() .getMemorySize()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAssignMultipleOffswitchContainers() throws Exception { MockRM rm1 = new MockRM(); @@ -711,7 +718,7 @@ public void testAssignMultipleOffswitchContainers() throws Exception { cs.getApplicationAttempt(am1.getApplicationAttemptId()); // App1 will get one container allocated (plus AM container - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); // Set assign multiple off-switch containers to 3 CapacitySchedulerConfiguration newCSConf = new CapacitySchedulerConfiguration(); @@ -725,12 +732,13 @@ public void testAssignMultipleOffswitchContainers() throws Exception { // App1 will get 3 new container allocated (plus 2 previously allocated // container) - Assert.assertEquals(5, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(5, schedulerApp1.getLiveContainers().size()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testContinuousReservationLookingWhenUsedEqualsMax() throws Exception { CapacitySchedulerConfiguration newConf = (CapacitySchedulerConfiguration) TestUtils @@ -784,14 +792,14 @@ public void testContinuousReservationLookingWhenUsedEqualsMax() throws Exception cs.getApplicationAttempt(am1.getApplicationAttemptId()); // App1 will get 2 container allocated (plus AM container) - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); // Do node heartbeats on nm2, we expect one container allocated on nm2 and // one unreserved on nm1 cs.handle(new NodeUpdateSchedulerEvent(rmNode2)); - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(0, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(0, schedulerApp1.getReservedContainers().size()); rm1.close(); } @@ -851,7 +859,7 @@ public void testPendingResourcesConsideringUserLimit() throws Exception { cs.getApplicationAttempt(am1.getApplicationAttemptId()); // App1 will get 1 container reserved - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); /* * Note that the behavior of appAttemptResourceUsage is different from queue's @@ -861,23 +869,23 @@ public void testPendingResourcesConsideringUserLimit() throws Exception { * TODO (wangda): Need to make behaviors of queue/app's resource usage * consistent */ - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, schedulerApp1.getAppAttemptResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, schedulerApp1.getAppAttemptResourceUsage().getReserved() .getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, schedulerApp1.getAppAttemptResourceUsage().getPending() .getMemorySize()); FiCaSchedulerApp schedulerApp2 = cs.getApplicationAttempt(am2.getApplicationAttemptId()); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(4 * GB, schedulerApp2.getAppAttemptResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, schedulerApp2.getAppAttemptResourceUsage().getReserved() .getMemorySize()); - Assert.assertEquals(5 * 4 * GB, + Assertions.assertEquals(5 * 4 * GB, schedulerApp2.getAppAttemptResourceUsage().getPending() .getMemorySize()); @@ -887,15 +895,16 @@ public void testPendingResourcesConsideringUserLimit() throws Exception { // u2 = 8GB - 4GB = 4GB // When not deduct reserved, total-pending = 3G (u1) + 4G (u2) = 7G // deduct reserved, total-pending = 0G (u1) + 4G = 4G - Assert.assertEquals(7 * GB, lq.getTotalPendingResourcesConsideringUserLimit( + Assertions.assertEquals(7 * GB, lq.getTotalPendingResourcesConsideringUserLimit( Resources.createResource(20 * GB), "", false).getMemorySize()); - Assert.assertEquals(4 * GB, lq.getTotalPendingResourcesConsideringUserLimit( + Assertions.assertEquals(4 * GB, lq.getTotalPendingResourcesConsideringUserLimit( Resources.createResource(20 * GB), "", true).getMemorySize()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testQueuePriorityOrdering() throws Exception { CapacitySchedulerConfiguration newConf = (CapacitySchedulerConfiguration) TestUtils @@ -971,16 +980,16 @@ public void testQueuePriorityOrdering() throws Exception { // container will be allocated to am1 // App1 will get 2 container allocated (plus AM container) cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp3.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp3.getLiveContainers().size()); // container will be allocated to am1 again, // App1 will get 3 container allocated (plus AM container) cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp3.getLiveContainers().size()); + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp3.getLiveContainers().size()); // (Now usages of queues: a=12G (satisfied), b=2G, c=2G) @@ -988,9 +997,9 @@ public void testQueuePriorityOrdering() throws Exception { // capacity) // App2 will get 2 container allocated (plus AM container) cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(2, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp3.getLiveContainers().size()); + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp3.getLiveContainers().size()); // Do this 3 times // container will be allocated to am2 (since app1 reaches its guaranteed @@ -999,9 +1008,9 @@ public void testQueuePriorityOrdering() throws Exception { for (int i = 0; i < 3; i++) { cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); } - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(5, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp3.getLiveContainers().size()); + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(5, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp3.getLiveContainers().size()); // (Now usages of queues: a=12G (satisfied), b=22G (satisfied), c=2G)) @@ -1009,9 +1018,9 @@ public void testQueuePriorityOrdering() throws Exception { for (int i = 0; i < 10; i++) { cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); } - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(5, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(11, schedulerApp3.getLiveContainers().size()); + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(5, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(11, schedulerApp3.getLiveContainers().size()); // (Now usages of queues: a=12G (satisfied), b=22G (satisfied), // c=52G (satisfied and no pending)) @@ -1020,9 +1029,9 @@ public void testQueuePriorityOrdering() throws Exception { for (int i = 0; i < 20; i++) { cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); } - Assert.assertEquals(4, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(6, schedulerApp2.getLiveContainers().size()); - Assert.assertEquals(11, schedulerApp3.getLiveContainers().size()); + Assertions.assertEquals(4, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(6, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(11, schedulerApp3.getLiveContainers().size()); // (Now usages of queues: a=17G (satisfied), b=27G (satisfied), c=52G)) @@ -1031,7 +1040,8 @@ public void testQueuePriorityOrdering() throws Exception { - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testUserLimitAllocationMultipleContainers() throws Exception { CapacitySchedulerConfiguration newConf = (CapacitySchedulerConfiguration) TestUtils @@ -1091,8 +1101,8 @@ public void testUserLimitAllocationMultipleContainers() throws Exception { // container will be allocated to am1 // App1 will get 2 container allocated (plus AM container) cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertEquals(101, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(100, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(101, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(100, schedulerApp2.getLiveContainers().size()); rm1.close(); } @@ -1165,13 +1175,14 @@ public void testActiveUsersWithOnlyPendingApps() throws Exception { LeafQueue lq = (LeafQueue) cs.getQueue("default"); UsersManager um = (UsersManager) lq.getAbstractUsersManager(); - Assert.assertEquals(4, um.getNumActiveUsers()); - Assert.assertEquals(2, um.getNumActiveUsersWithOnlyPendingApps()); - Assert.assertEquals(2, lq.getMetrics().getAppsPending()); + Assertions.assertEquals(4, um.getNumActiveUsers()); + Assertions.assertEquals(2, um.getNumActiveUsersWithOnlyPendingApps()); + Assertions.assertEquals(2, lq.getMetrics().getAppsPending()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testUnreserveWhenClusterResourceHasEmptyResourceType() throws Exception { /** @@ -1240,19 +1251,20 @@ public void testUnreserveWhenClusterResourceHasEmptyResourceType() // Do nm1 heartbeats 1 times, will reserve a container on nm1 for app1 cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); // Do nm2 heartbeats 1 times, will unreserve a container on nm1 // and allocate a container on nm2 for app1 cs.handle(new NodeUpdateSchedulerEvent(rmNode2)); - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(0, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(0, schedulerApp1.getReservedContainers().size()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAllocationCannotBeBlockedWhenFormerQueueReachedItsLimit() throws Exception { /** @@ -1340,13 +1352,14 @@ public void testAllocationCannotBeBlockedWhenFormerQueueReachedItsLimit() // Do nm1 heartbeats 1 times, will allocate a container on nm1 for app2 cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); rm1.drainEvents(); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(2, schedulerApp2.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(2, schedulerApp2.getLiveContainers().size()); rm1.close(); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testContainerRejectionWhenAskBeyondDynamicMax() throws Exception { CapacitySchedulerConfiguration newConf = @@ -1379,7 +1392,7 @@ public void testContainerRejectionWhenAskBeyondDynamicMax() } catch (InvalidResourceRequestException e) { submitFailed = true; } - Assert.assertTrue(submitFailed); + Assertions.assertTrue(submitFailed); // Ask 4GB succeeded. am1.allocate("*", 4 * GB, 1, null); @@ -1396,7 +1409,7 @@ public void testContainerRejectionWhenAskBeyondDynamicMax() } catch (InvalidResourceRequestException e) { submitFailed = true; } - Assert.assertTrue(submitFailed); + Assertions.assertTrue(submitFailed); // But ask 3 GB succeeded. am1.allocate("*", 3 * GB, 1, 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/scheduler/capacity/TestContainerResizing.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestContainerResizing.java index e3c6e7c68b72b..ec7b605f476eb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestContainerResizing.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestContainerResizing.java @@ -64,9 +64,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.CandidateNodeSet; 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; public class TestContainerResizing { private static final Logger LOG = @@ -102,7 +103,7 @@ public CSAssignment allocateContainersToNode( } } - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -152,7 +153,7 @@ public RMNodeLabelsManager createNodeLabelManager() { rm1, app1.getApplicationId()); checkPendingResource(rm1, "default", 2 * GB, null); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // NM1 do 1 heartbeats @@ -162,7 +163,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // Pending resource should be deducted checkPendingResource(rm1, "default", 0 * GB, null); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); verifyContainerIncreased(am1.allocate(null, null), containerId1, 3 * GB); @@ -207,7 +208,7 @@ protected Dispatcher createDispatcher() { rm1, app1.getApplicationId()); checkUsedResource(rm1, "default", 3 * GB, null); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); ContainerId containerId1 = @@ -227,7 +228,7 @@ protected Dispatcher createDispatcher() { dispatcher.await(); checkUsedResource(rm1, "default", 1 * GB, null); - Assert.assertEquals(1 * GB, + Assertions.assertEquals(1 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); // Check if decreased containers added to RMNode @@ -242,7 +243,7 @@ protected Dispatcher createDispatcher() { rmNodeReceivedDecreaseContainer = true; } } - Assert.assertTrue(rmNodeReceivedDecreaseContainer); + Assertions.assertTrue(rmNodeReceivedDecreaseContainer); rm1.close(); } @@ -287,7 +288,7 @@ public RMNodeLabelsManager createNodeLabelManager() { null); ContainerId containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm1, containerId2, + Assertions.assertTrue(rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am1.allocate(null, null); @@ -306,7 +307,7 @@ public RMNodeLabelsManager createNodeLabelManager() { Resources.createResource(7 * GB), null))); checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // NM1 do 1 heartbeats @@ -316,19 +317,19 @@ public RMNodeLabelsManager createNodeLabelManager() { /* Check reservation statuses */ // Increase request should be reserved - Assert.assertFalse(app.getReservedContainers().isEmpty()); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertFalse(app.getReservedContainers().isEmpty()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will not be changed since it's not satisfied checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 9 * GB, null); - Assert.assertEquals(9 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(9 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); // Complete one container and do another allocation @@ -340,19 +341,19 @@ public RMNodeLabelsManager createNodeLabelManager() { /* Check statuses after reservation satisfied */ // Increase request should be unreserved - Assert.assertTrue(app.getReservedContainers().isEmpty()); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertTrue(app.getReservedContainers().isEmpty()); + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will be changed since it's satisfied checkPendingResource(rm1, "default", 0 * GB, null); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 7 * GB, null); - Assert.assertEquals(7 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(7 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); - Assert.assertEquals(7 * GB, + Assertions.assertEquals(7 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); verifyAvailableResourceOfSchedulerNode(rm1, nm1.getNodeId(), 1 * GB); @@ -396,7 +397,7 @@ public RMNodeLabelsManager createNodeLabelManager() { null); ContainerId containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm1, containerId2, + Assertions.assertTrue(rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am1.allocate(null, null); @@ -411,7 +412,7 @@ public RMNodeLabelsManager createNodeLabelManager() { Resources.createResource(8 * GB), null))); checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // NM1 do 1 heartbeats @@ -421,19 +422,19 @@ public RMNodeLabelsManager createNodeLabelManager() { /* Check reservation statuses */ // Increase request should *NOT* be reserved as it exceeds user limit - Assert.assertTrue(app.getReservedContainers().isEmpty()); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertTrue(app.getReservedContainers().isEmpty()); + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will not be changed since it's not satisfied checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will *NOT* be updated checkUsedResource(rm1, "default", 3 * GB, null); - Assert.assertEquals(3 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(3 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); rm1.close(); } @@ -479,7 +480,7 @@ public RMNodeLabelsManager createNodeLabelManager() { null); ContainerId containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm1, containerId2, + Assertions.assertTrue(rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am1.allocate(null, null); @@ -497,7 +498,7 @@ public RMNodeLabelsManager createNodeLabelManager() { Resources.createResource(7 * GB), null))); checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // NM1 do 1 heartbeats @@ -507,19 +508,19 @@ public RMNodeLabelsManager createNodeLabelManager() { /* Check reservation statuses */ // Increase request should be reserved - Assert.assertFalse(app.getReservedContainers().isEmpty()); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertFalse(app.getReservedContainers().isEmpty()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will not be changed since it's not satisfied checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 9 * GB, null); - Assert.assertEquals(9 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(9 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); // Complete one container and cancel increase request (via send a increase @@ -537,19 +538,19 @@ public RMNodeLabelsManager createNodeLabelManager() { /* Check statuses after reservation satisfied */ // Increase request should be unreserved - Assert.assertTrue(app.getReservedContainers().isEmpty()); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertTrue(app.getReservedContainers().isEmpty()); + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will be changed since it's satisfied checkPendingResource(rm1, "default", 0 * GB, null); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 1 * GB, null); - Assert.assertEquals(1 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(1 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); - Assert.assertEquals(1 * GB, + Assertions.assertEquals(1 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); rm1.close(); @@ -601,7 +602,7 @@ protected Dispatcher createDispatcher() { null); ContainerId containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm1, containerId2, + Assertions.assertTrue(rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am1.allocate(null, null); @@ -620,7 +621,7 @@ protected Dispatcher createDispatcher() { Resources.createResource(8 * GB), null))); checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // NM1 do 1 heartbeats @@ -630,19 +631,19 @@ protected Dispatcher createDispatcher() { /* Check reservation statuses */ // Increase request should be reserved - Assert.assertFalse(app.getReservedContainers().isEmpty()); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertFalse(app.getReservedContainers().isEmpty()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will not be changed since it's not satisfied checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 10 * GB, null); - Assert.assertEquals(10 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(10 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(4 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); // Complete one container and cancel increase request (via send a increase @@ -660,19 +661,19 @@ protected Dispatcher createDispatcher() { dispatcher.await(); /* Check statuses after reservation satisfied */ // Increase request should be unreserved - Assert.assertTrue(app.getReservedContainers().isEmpty()); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertTrue(app.getReservedContainers().isEmpty()); + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will be changed since it's satisfied checkPendingResource(rm1, "default", 0 * GB, null); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 1 * GB, null); - Assert.assertEquals(1 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(1 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); - Assert.assertEquals(1 * GB, + Assertions.assertEquals(1 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); rm1.close(); @@ -726,7 +727,7 @@ protected Dispatcher createDispatcher() { null); ContainerId containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm1, containerId2, + Assertions.assertTrue(rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am1.allocate(null, null); @@ -742,7 +743,7 @@ protected Dispatcher createDispatcher() { Resources.createResource(8 * GB), null))); checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // NM1 do 1 heartbeats @@ -752,19 +753,19 @@ protected Dispatcher createDispatcher() { /* Check reservation statuses */ // Increase request should be reserved - Assert.assertFalse(app.getReservedContainers().isEmpty()); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertFalse(app.getReservedContainers().isEmpty()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will not be changed since it's not satisfied checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 9 * GB, null); - Assert.assertEquals(9 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(9 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); // Complete container2, container will be unreserved and completed @@ -778,19 +779,19 @@ protected Dispatcher createDispatcher() { /* Check statuses after reservation satisfied */ // Increase request should be unreserved - Assert.assertTrue(app.getReservedContainers().isEmpty()); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertTrue(app.getReservedContainers().isEmpty()); + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will be changed since it's satisfied checkPendingResource(rm1, "default", 0 * GB, null); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 1 * GB, null); - Assert.assertEquals(1 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(1 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); - Assert.assertEquals(1 * GB, + Assertions.assertEquals(1 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); rm1.close(); @@ -838,7 +839,7 @@ public RMNodeLabelsManager createNodeLabelManager() { null); ContainerId containerId2 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue( + Assertions.assertTrue( rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am1.allocate(null, null); @@ -852,7 +853,7 @@ public RMNodeLabelsManager createNodeLabelManager() { Resources.createResource(8 * GB), null))); checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // NM1 do 1 heartbeats @@ -862,19 +863,19 @@ public RMNodeLabelsManager createNodeLabelManager() { /* Check reservation statuses */ // Increase request should be reserved - Assert.assertFalse(app.getReservedContainers().isEmpty()); - Assert.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertFalse(app.getReservedContainers().isEmpty()); + Assertions.assertNotNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will not be changed since it's not satisfied checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 9 * GB, null); - Assert.assertEquals(9 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(9 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); // Kill the application by killing the AM container @@ -888,8 +889,8 @@ public RMNodeLabelsManager createNodeLabelManager() { /* Check statuses after reservation satisfied */ // Increase request should be unreserved - Assert.assertTrue(app.getReservedContainers().isEmpty()); - Assert.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); + Assertions.assertTrue(app.getReservedContainers().isEmpty()); + Assertions.assertNull(cs.getNode(nm1.getNodeId()).getReservedContainer()); // Pending resource will be changed since it's satisfied cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); @@ -898,10 +899,10 @@ public RMNodeLabelsManager createNodeLabelManager() { // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 0 * GB, null); // User will be removed - Assert.assertNull(((LeafQueue) cs.getQueue("default")).getUser("user")); - Assert.assertEquals(0 * GB, + Assertions.assertNull(((LeafQueue) cs.getQueue("default")).getUser("user")); + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); rm1.close(); @@ -916,7 +917,7 @@ private void allocateAndLaunchContainers(MockAM am, MockNM nm, MockRM rm, null); ContainerId lastContainerId = ContainerId.newContainerId( am.getApplicationAttemptId(), startContainerId + nContainer - 1); - Assert.assertTrue(rm.waitForState(nm, lastContainerId, + Assertions.assertTrue(rm.waitForState(nm, lastContainerId, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am.allocate(null, null); @@ -986,7 +987,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.sendContainerResizingRequest(increaseRequests); checkPendingResource(rm1, "default", 6 * GB, null); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Get rmNode1 @@ -997,7 +998,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // earlier allocated) cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); AllocateResponse allocateResponse = am1.allocate(null, null); - Assert.assertEquals(3, allocateResponse.getUpdatedContainers().size()); + Assertions.assertEquals(3, allocateResponse.getUpdatedContainers().size()); verifyContainerIncreased(allocateResponse, ContainerId.newContainerId(attemptId, 4), 2 * GB); verifyContainerIncreased(allocateResponse, @@ -1008,21 +1009,22 @@ public RMNodeLabelsManager createNodeLabelManager() { /* Check statuses after allocation */ // There're still 3 pending increase requests checkPendingResource(rm1, "default", 3 * GB, null); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); // Queue/user/application's usage will be updated checkUsedResource(rm1, "default", 10 * GB, null); - Assert.assertEquals(10 * GB, ((LeafQueue) cs.getQueue("default")) + Assertions.assertEquals(10 * GB, ((LeafQueue) cs.getQueue("default")) .getUser("user").getUsed().getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, app.getAppAttemptResourceUsage().getReserved().getMemorySize()); - Assert.assertEquals(10 * GB, + Assertions.assertEquals(10 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); rm1.close(); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testDecreaseContainerWillNotDeadlockContainerAllocation() throws Exception { // create and start MockRM with our MyScheduler @@ -1052,7 +1054,7 @@ public ResourceScheduler createScheduler() { checkUsedResource(rm, "default", 3 * GB, null); FiCaSchedulerApp app = TestUtils.getFiCaSchedulerApp( rm, app1.getApplicationId()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); // making sure container is launched ContainerId containerId1 = @@ -1081,7 +1083,7 @@ private void checkPendingResource(MockRM rm, String queueName, int memory, String label) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queueName); - Assert.assertEquals(memory, + Assertions.assertEquals(memory, queue.getQueueResourceUsage() .getPending(label == null ? RMNodeLabelsManager.NO_LABEL : label) .getMemorySize()); @@ -1091,7 +1093,7 @@ private void checkUsedResource(MockRM rm, String queueName, int memory, String label) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queueName); - Assert.assertEquals(memory, + Assertions.assertEquals(memory, queue.getQueueResourceUsage() .getUsed(label == null ? RMNodeLabelsManager.NO_LABEL : label) .getMemorySize()); @@ -1105,14 +1107,14 @@ private void verifyContainerIncreased(AllocateResponse response, for (UpdatedContainer c : increasedContainers) { if (c.getContainer().getId().equals(containerId)) { found = true; - Assert.assertEquals(ContainerUpdateType.INCREASE_RESOURCE, + Assertions.assertEquals(ContainerUpdateType.INCREASE_RESOURCE, c.getUpdateType()); - Assert.assertEquals(mem, + Assertions.assertEquals(mem, c.getContainer().getResource().getMemorySize()); } } if (!found) { - Assert.fail("Container not increased: containerId=" + containerId); + Assertions.fail("Container not increased: containerId=" + containerId); } } @@ -1124,14 +1126,14 @@ private void verifyContainerDecreased(AllocateResponse response, for (UpdatedContainer c : decreasedContainers) { if (c.getContainer().getId().equals(containerId)) { found = true; - Assert.assertEquals(ContainerUpdateType.DECREASE_RESOURCE, + Assertions.assertEquals(ContainerUpdateType.DECREASE_RESOURCE, c.getUpdateType()); - Assert.assertEquals(mem, + Assertions.assertEquals(mem, c.getContainer().getResource().getMemorySize()); } } if (!found) { - Assert.fail("Container not decreased: containerId=" + containerId); + Assertions.fail("Container not decreased: containerId=" + containerId); } } @@ -1142,7 +1144,7 @@ private void sentRMContainerLaunched(MockRM rm, ContainerId containerId) { rmContainer.handle( new RMContainerEvent(containerId, RMContainerEventType.LAUNCHED)); } else { - Assert.fail("Cannot find RMContainer"); + Assertions.fail("Cannot find RMContainer"); } } @@ -1150,7 +1152,7 @@ private void verifyAvailableResourceOfSchedulerNode(MockRM rm, NodeId nodeId, int expectedMemory) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); SchedulerNode node = cs.getNode(nodeId); - Assert + Assertions .assertEquals(expectedMemory, node.getUnallocatedResource().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/scheduler/capacity/TestIncreaseAllocationExpirer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestIncreaseAllocationExpirer.java index ae8bbe3535a4b..60fd6684241f4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestIncreaseAllocationExpirer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestIncreaseAllocationExpirer.java @@ -44,9 +44,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNode; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; 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 java.util.ArrayList; import java.util.Collections; @@ -57,7 +57,7 @@ public class TestIncreaseAllocationExpirer { private YarnConfiguration conf; RMNodeLabelsManager mgr; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -106,12 +106,12 @@ public void testContainerIsRemovedFromAllocationExpirer() // AM acquire a new container to start container allocation expirer List containers = am1.allocate(null, null).getAllocatedContainers(); - Assert.assertEquals(containerId2, containers.get(0).getId()); - Assert.assertNotNull(containers.get(0).getContainerToken()); + Assertions.assertEquals(containerId2, containers.get(0).getId()); + Assertions.assertNotNull(containers.get(0).getContainerToken()); checkUsedResource(rm1, "default", 2 * GB, null); FiCaSchedulerApp app = TestUtils.getFiCaSchedulerApp( rm1, app1.getApplicationId()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); verifyAvailableResourceOfSchedulerNode(rm1, nm1.getNodeId(), 18 * GB); // Report container status @@ -139,15 +139,15 @@ public void testContainerIsRemovedFromAllocationExpirer() // Wait long enough and verify that the container was removed // from allocation expirer, and the container is still running Thread.sleep(10000); - Assert.assertEquals(RMContainerState.RUNNING, + Assertions.assertEquals(RMContainerState.RUNNING, rm1.getResourceScheduler().getRMContainer(containerId2).getState()); // Verify container size is 3G - Assert.assertEquals( + Assertions.assertEquals( 3 * GB, rm1.getResourceScheduler().getRMContainer(containerId2) .getAllocatedResource().getMemorySize()); // Verify total resource usage checkUsedResource(rm1, "default", 4 * GB, null); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(4 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); // Verify available resource verifyAvailableResourceOfSchedulerNode(rm1, nm1.getNodeId(), 16 * GB); @@ -195,12 +195,12 @@ protected Dispatcher createDispatcher() { rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED); List containers = am1.allocate(null, null).getAllocatedContainers(); - Assert.assertEquals(containerId2, containers.get(0).getId()); - Assert.assertNotNull(containers.get(0).getContainerToken()); + Assertions.assertEquals(containerId2, containers.get(0).getId()); + Assertions.assertNotNull(containers.get(0).getContainerToken()); checkUsedResource(rm1, "default", 2 * GB, null); FiCaSchedulerApp app = TestUtils.getFiCaSchedulerApp( rm1, app1.getApplicationId()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); verifyAvailableResourceOfSchedulerNode(rm1, nm1.getNodeId(), 18 * GB); nm1.nodeHeartbeat( @@ -219,7 +219,7 @@ protected Dispatcher createDispatcher() { am1.allocate(null, null); // Verify resource usage checkUsedResource(rm1, "default", 4 * GB, null); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(4 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); verifyAvailableResourceOfSchedulerNode(rm1, nm1.getNodeId(), 16 * GB); // Wait long enough for the increase token to expire, and for the roll @@ -228,13 +228,13 @@ protected Dispatcher createDispatcher() { // Verify container size is 1G am1.allocate(null, null); rm1.drainEvents(); - Assert.assertEquals( + Assertions.assertEquals( 1 * GB, rm1.getResourceScheduler().getRMContainer(containerId2) .getAllocatedResource().getMemorySize()); disp.waitForEventThreadToWait(); // Verify total resource usage is 2G checkUsedResource(rm1, "default", 2 * GB, null); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); // Verify available resource is rolled back to 18GB verifyAvailableResourceOfSchedulerNode(rm1, nm1.getNodeId(), 18 * GB); @@ -311,10 +311,10 @@ public void testConsecutiveContainerIncreaseAllocationExpiration() ContainerUpdateType.INCREASE_RESOURCE, Resources.createResource(5 * GB), null))); List updateErrors = response.getUpdateErrors(); - Assert.assertEquals(1, updateErrors.size()); - Assert.assertEquals("INCORRECT_CONTAINER_VERSION_ERROR", + Assertions.assertEquals(1, updateErrors.size()); + Assertions.assertEquals("INCORRECT_CONTAINER_VERSION_ERROR", updateErrors.get(0).getReason()); - Assert.assertEquals(1, + Assertions.assertEquals(1, updateErrors.get(0).getCurrentContainerVersion()); // am1 asks to change containerId2 from 3GB to 5GB @@ -332,7 +332,7 @@ public void testConsecutiveContainerIncreaseAllocationExpiration() checkUsedResource(rm1, "default", 6 * GB, null); FiCaSchedulerApp app = TestUtils.getFiCaSchedulerApp( rm1, app1.getApplicationId()); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); // Verify available resource is now reduced to 14GB verifyAvailableResourceOfSchedulerNode(rm1, nm1.getNodeId(), 14 * GB); @@ -344,20 +344,20 @@ public void testConsecutiveContainerIncreaseAllocationExpiration() am1.allocate(null, null); Thread.sleep(2000); // Verify container size is rolled back to 3G - Assert.assertEquals( + Assertions.assertEquals( 3 * GB, rm1.getResourceScheduler().getRMContainer(containerId2) .getAllocatedResource().getMemorySize()); // Verify total resource usage is 4G checkUsedResource(rm1, "default", 4 * GB, null); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(4 * GB, app.getAppAttemptResourceUsage().getUsed().getMemorySize()); // Verify available resource is rolled back to 14GB verifyAvailableResourceOfSchedulerNode(rm1, nm1.getNodeId(), 16 * GB); // Verify NM receives the decrease message (3G) List containersToDecrease = nm1.nodeHeartbeat(true).getContainersToUpdate(); - Assert.assertEquals(1, containersToDecrease.size()); - Assert.assertEquals( + Assertions.assertEquals(1, containersToDecrease.size()); + Assertions.assertEquals( 3 * GB, containersToDecrease.get(0).getResource().getMemorySize()); rm1.stop(); } @@ -413,10 +413,10 @@ public void testDecreaseAfterIncreaseWithAllocationExpiration() // AM acquires tokens to start container allocation expirer List containers = am1.allocate(null, null).getAllocatedContainers(); - Assert.assertEquals(3, containers.size()); - Assert.assertNotNull(containers.get(0).getContainerToken()); - Assert.assertNotNull(containers.get(1).getContainerToken()); - Assert.assertNotNull(containers.get(2).getContainerToken()); + Assertions.assertEquals(3, containers.size()); + Assertions.assertNotNull(containers.get(0).getContainerToken()); + Assertions.assertNotNull(containers.get(1).getContainerToken()); + Assertions.assertNotNull(containers.get(2).getContainerToken()); // Report container status nm1.nodeHeartbeat(app1.getCurrentAppAttempt().getAppAttemptId(), 2, ContainerState.RUNNING); @@ -458,7 +458,7 @@ public void testDecreaseAfterIncreaseWithAllocationExpiration() AllocateResponse response = am1.sendContainerResizingRequest(decreaseRequests); // Verify containers are decreased in scheduler - Assert.assertEquals(3, response.getUpdatedContainers().size()); + Assertions.assertEquals(3, response.getUpdatedContainers().size()); // Use the token for containerId4 on NM (6G). This should set the last // confirmed resource to 4G, and cancel the allocation expirer nm1.containerIncreaseStatus(getContainer( @@ -469,13 +469,13 @@ public void testDecreaseAfterIncreaseWithAllocationExpiration() am1.allocate(null, null); rm1.drainEvents(); - Assert.assertEquals( + Assertions.assertEquals( 2 * GB, rm1.getResourceScheduler().getRMContainer(containerId2) .getAllocatedResource().getMemorySize()); - Assert.assertEquals( + Assertions.assertEquals( 3 * GB, rm1.getResourceScheduler().getRMContainer(containerId3) .getAllocatedResource().getMemorySize()); - Assert.assertEquals( + Assertions.assertEquals( 4 * GB, rm1.getResourceScheduler().getRMContainer(containerId4) .getAllocatedResource().getMemorySize()); // Verify NM receives 2 decrease message @@ -483,18 +483,18 @@ public void testDecreaseAfterIncreaseWithAllocationExpiration() nm1.nodeHeartbeat(true).getContainersToUpdate(); // NOTE: Can be more that 2 depending on which event arrives first. // What is important is the final size of the containers. - Assert.assertTrue(containersToDecrease.size() >= 2); + Assertions.assertTrue(containersToDecrease.size() >= 2); // Sort the list to make sure containerId3 is the first Collections.sort(containersToDecrease); int i = 0; if (containersToDecrease.size() > 2) { - Assert.assertEquals( + Assertions.assertEquals( 2 * GB, containersToDecrease.get(i++).getResource().getMemorySize()); } - Assert.assertEquals( + Assertions.assertEquals( 3 * GB, containersToDecrease.get(i++).getResource().getMemorySize()); - Assert.assertEquals( + Assertions.assertEquals( 4 * GB, containersToDecrease.get(i++).getResource().getMemorySize()); rm1.stop(); } @@ -503,7 +503,7 @@ private void checkUsedResource(MockRM rm, String queueName, int memory, String label) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queueName); - Assert.assertEquals(memory, + Assertions.assertEquals(memory, queue.getQueueResourceUsage() .getUsed(label == null ? RMNodeLabelsManager.NO_LABEL : label) .getMemorySize()); @@ -513,7 +513,7 @@ private void verifyAvailableResourceOfSchedulerNode(MockRM rm, NodeId nodeId, int expectedMemory) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); SchedulerNode node = cs.getNode(nodeId); - Assert + Assertions .assertEquals(expectedMemory, node.getUnallocatedResource().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/scheduler/capacity/TestLeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java index 870d61539b02b..3f138093c450b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java @@ -26,10 +26,10 @@ .capacity.CapacitySchedulerConfiguration.DOT; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler .capacity.CapacitySchedulerConfiguration.ROOT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.doNothing; @@ -122,10 +122,11 @@ import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.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; @@ -160,7 +161,7 @@ public class TestLeafQueue { private final ResourceCalculator dominantResourceCalculator = new DominantResourceCalculator(); - @Before + @BeforeEach public void setUp() throws Exception { setUpInternal(resourceCalculator, false); } @@ -932,8 +933,8 @@ public void testDRFUsageRatioRounding() throws Exception { priority, recordFactory, NO_LABEL))); assign = b.assignContainers(clusterResource, node0, new ResourceLimits( clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY); - assertTrue("Still within limits, should assign", - assign.getResource().getMemorySize() > 0); + assertTrue( + assign.getResource().getMemorySize() > 0, "Still within limits, should assign"); } private void applyCSAssignment(Resource clusterResource, CSAssignment assign, @@ -1014,8 +1015,8 @@ public void testDRFUserLimits() throws Exception { User queueUser0 = b.getUser(user0); User queueUser1 = b.getUser(user1); - assertEquals("There should 2 active users!", 2, b - .getAbstractUsersManager().getNumActiveUsers()); + assertEquals(2, b + .getAbstractUsersManager().getNumActiveUsers(), "There should 2 active users!"); // Fill both Nodes as far as we can CSAssignment assign; do { @@ -1034,13 +1035,13 @@ public void testDRFUserLimits() throws Exception { } while (assign.getResource().getMemorySize() > 0 && assign.getAssignmentInformation().getNumReservations() == 0); - assertTrue("Verify user_0 got resources ", queueUser0.getUsed() - .getMemorySize() > 0); - assertTrue("Verify user_1 got resources ", queueUser1.getUsed() - .getMemorySize() > 0); + assertTrue(queueUser0.getUsed() + .getMemorySize() > 0, "Verify user_0 got resources "); + assertTrue(queueUser1.getUsed() + .getMemorySize() > 0, "Verify user_1 got resources "); assertTrue( - "Expected AbsoluteUsedCapacity > 0.95, got: " - + b.getAbsoluteUsedCapacity(), b.getAbsoluteUsedCapacity() > 0.95); + b.getAbsoluteUsedCapacity() > 0.95, "Expected AbsoluteUsedCapacity > 0.95, got: " + + b.getAbsoluteUsedCapacity()); // Verify consumedRatio is based on dominant resources float expectedRatio = @@ -1809,8 +1810,8 @@ public void testUserLimits() throws Exception { assertEquals(1*GB, app_1.getCurrentConsumption().getMemorySize()); // app_0 doesn't have outstanding resources, there's only one active user. - assertEquals("There should only be 1 active user!", - 1, a.getAbstractUsersManager().getNumActiveUsers()); + assertEquals( + 1, a.getAbstractUsersManager().getNumActiveUsers(), "There should only be 1 active user!"); } @Test @@ -1914,8 +1915,8 @@ public void testDecimalUserLimits() throws Exception { assertEquals(GB, app1.getCurrentConsumption().getMemorySize()); // app_0 doesn't have outstanding resources, there's only one active user. - assertEquals("There should only be 1 active user!", - 1, a.getAbstractUsersManager().getNumActiveUsers()); + assertEquals( + 1, a.getAbstractUsersManager().getNumActiveUsers(), "There should only be 1 active user!"); } @Test @@ -1941,7 +1942,7 @@ public void testUserSpecificUserLimits() throws Exception { when(csContext.getClusterResource()) .thenReturn(Resources.createResource(16 * GB, 32)); // Verify that configs were updated and parsed correctly. - Assert.assertEquals(UserWeights.DEFAULT_WEIGHT, a.getUserWeights().getByUser("user_0"), 0.0f); + Assertions.assertEquals(UserWeights.DEFAULT_WEIGHT, a.getUserWeights().getByUser("user_0"), 0.0f); a.reinitialize(a, csContext.getClusterResource()); assertEquals(1.5f, a.getUserWeights().getByUser("user_0"), 0.0f); assertEquals(0.7f, a.getUserWeights().getByUser("firstname.lastname"), 0.0f); @@ -2115,8 +2116,8 @@ public void testComputeUserLimitAndSetHeadroom() throws IOException { TestUtils.createResourceRequest(ResourceRequest.ANY, 4*GB, 1, true, u0Priority, recordFactory))); - assertEquals("There should only be 1 active user!", - 1, qb.getAbstractUsersManager().getNumActiveUsers()); + assertEquals( + 1, qb.getAbstractUsersManager().getNumActiveUsers(), "There should only be 1 active user!"); //get headroom applyCSAssignment(clusterResource, qb.assignContainers(clusterResource, node_0, @@ -2308,8 +2309,8 @@ public void testHeadroomWithMaxCap() throws Exception { // Now, only user_0 should be active since he is the only one with // outstanding requests - assertEquals("There should only be 1 active user!", - 1, a.getAbstractUsersManager().getNumActiveUsers()); + assertEquals( + 1, a.getAbstractUsersManager().getNumActiveUsers(), "There should only be 1 active user!"); // 1 container to user_0 applyCSAssignment(clusterResource, @@ -2992,17 +2993,17 @@ public void testReservationExchange() throws Exception { } private void verifyContainerAllocated(CSAssignment assignment, NodeType nodeType) { - Assert.assertTrue(Resources.greaterThan(resourceCalculator, null, + Assertions.assertTrue(Resources.greaterThan(resourceCalculator, null, assignment.getResource(), Resources.none())); - Assert + Assertions .assertTrue(assignment.getAssignmentInformation().getNumAllocations() > 0); - Assert.assertEquals(nodeType, assignment.getType()); + Assertions.assertEquals(nodeType, assignment.getType()); } private void verifyNoContainerAllocated(CSAssignment assignment) { - Assert.assertTrue(Resources.equals(assignment.getResource(), + Assertions.assertTrue(Resources.equals(assignment.getResource(), Resources.none())); - Assert + Assertions .assertTrue(assignment.getAssignmentInformation().getNumAllocations() == 0); } @@ -3629,7 +3630,8 @@ public void testSchedulingConstraints() throws Exception { assertEquals(0, app_0.getOutstandingAsksCount(schedulerKey)); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testActivateApplicationAfterQueueRefresh() throws Exception { // Manipulate queue 'e' @@ -3690,7 +3692,8 @@ public void testActivateApplicationAfterQueueRefresh() throws Exception { assertEquals(0, e.getNumPendingApplications()); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testLocalityDelaysAfterQueueRefresh() throws Exception { // Manipulate queue 'e' @@ -3718,7 +3721,8 @@ public void testLocalityDelaysAfterQueueRefresh() throws Exception { assertEquals(600, e.getRackLocalityAdditionalDelay()); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testActivateApplicationByUpdatingClusterResource() throws Exception { @@ -4154,7 +4158,7 @@ public void testAllocateContainerOnNodeWithoutOffSwitchSpecified() new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); } catch (NullPointerException e) { - Assert.fail("NPE when allocating container on node but " + Assertions.fail("NPE when allocating container on node but " + "forget to set off-switch request should be handled"); } } @@ -4221,12 +4225,12 @@ public void testFifoAssignment() throws Exception { a.assignContainers(clusterResource, node_0_0, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(1 * GB, app_1.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(1 * GB, app_1.getCurrentConsumption().getMemorySize()); applyCSAssignment(clusterResource, a.assignContainers(clusterResource, node_0_0, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(2 * GB, app_0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(2 * GB, app_0.getCurrentConsumption().getMemorySize()); app_0_requests_0.clear(); app_0_requests_0.add(TestUtils @@ -4245,15 +4249,15 @@ public void testFifoAssignment() throws Exception { a.assignContainers(clusterResource, node_0_0, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(2 * GB, app_1.getCurrentConsumption().getMemorySize()); - Assert.assertEquals(2 * GB, app_0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(2 * GB, app_1.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(2 * GB, app_0.getCurrentConsumption().getMemorySize()); //and only then will app_2 applyCSAssignment(clusterResource, a.assignContainers(clusterResource, node_0_0, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(3 * GB, app_0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(3 * GB, app_0.getCurrentConsumption().getMemorySize()); } @Test @@ -4325,7 +4329,7 @@ public void testFifoWithPartitionsAssignment() throws Exception { a.assignContainers(clusterResource, node00, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(1 * GB, app1.getSchedulingResourceUsage() + Assertions.assertEquals(1 * GB, app1.getSchedulingResourceUsage() .getUsed(LABEL).getMemorySize()); // app_0 should not get resources from node_0_0 since the labels // don't match @@ -4333,7 +4337,7 @@ public void testFifoWithPartitionsAssignment() throws Exception { a.assignContainers(clusterResource, node00, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(0 * GB, app0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(0 * GB, app0.getCurrentConsumption().getMemorySize()); app1Requests.clear(); app1Requests.add(TestUtils @@ -4346,8 +4350,8 @@ public void testFifoWithPartitionsAssignment() throws Exception { a.assignContainers(clusterResource, node01, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(2 * GB, app0.getCurrentConsumption().getMemorySize()); - Assert.assertEquals(1 * GB, app1.getSchedulingResourceUsage() + Assertions.assertEquals(2 * GB, app0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(1 * GB, app1.getSchedulingResourceUsage() .getUsed(LABEL).getMemorySize()); app0Requests.clear(); @@ -4361,8 +4365,8 @@ public void testFifoWithPartitionsAssignment() throws Exception { a.assignContainers(clusterResource, node00, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(2 * GB, app0.getCurrentConsumption().getMemorySize()); - Assert.assertEquals(2 * GB, app1.getSchedulingResourceUsage() + Assertions.assertEquals(2 * GB, app0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(2 * GB, app1.getSchedulingResourceUsage() .getUsed(LABEL).getMemorySize()); } @@ -4429,8 +4433,8 @@ public void run() { submitAndRemove.join(); getAppsInQueue.join(); - assertTrue("ConcurrentModificationException is thrown", - conException.isEmpty()); + assertTrue( + conException.isEmpty(), "ConcurrentModificationException is thrown"); rm.stop(); } @@ -4499,12 +4503,12 @@ public void testFairAssignment() throws Exception { a.assignContainers(clusterResource, node_0_0, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(2*GB, app_0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(2*GB, app_0.getCurrentConsumption().getMemorySize()); applyCSAssignment(clusterResource, a.assignContainers(clusterResource, node_0_0, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(1*GB, app_1.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(1*GB, app_1.getCurrentConsumption().getMemorySize()); app_0_requests_0.clear(); app_0_requests_0.add( @@ -4524,15 +4528,15 @@ public void testFairAssignment() throws Exception { a.assignContainers(clusterResource, node_0_0, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(2*GB, app_0.getCurrentConsumption().getMemorySize()); - Assert.assertEquals(2*GB, app_1.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(2*GB, app_0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(2*GB, app_1.getCurrentConsumption().getMemorySize()); //and only then will app_0 applyCSAssignment(clusterResource, a.assignContainers(clusterResource, node_0_0, new ResourceLimits(clusterResource), SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY), a, nodes, apps); - Assert.assertEquals(3*GB, app_0.getCurrentConsumption().getMemorySize()); + Assertions.assertEquals(3*GB, app_0.getCurrentConsumption().getMemorySize()); } @@ -5261,9 +5265,9 @@ public void testMaxApplicationsWithNodeLabels() throws IOException { LeafQueue e = (LeafQueue) cs.getQueue("e"); // Maximum application should be calculated with the default node label - Assert.assertEquals("Maximum application is not calculated properly", - (int)(conf.getMaximumSystemApplications() - * e.getAbsoluteCapacity()), e.getMaxApplications()); + Assertions.assertEquals( + (int)(conf.getMaximumSystemApplications() + * e.getAbsoluteCapacity()), e.getMaxApplications(), "Maximum application is not calculated properly"); conf.setCapacityByLabel(new QueuePath(rootChild, A), "test", 10); conf.setCapacityByLabel(new QueuePath(rootChild, B), "test", 10); @@ -5275,10 +5279,10 @@ public void testMaxApplicationsWithNodeLabels() throws IOException { e = (LeafQueue) cs.getQueue("e"); // Maximum application is now determined by test label, because that would // yield a higher value than with default node label - Assert.assertEquals("Maximum application is not calculated properly", - (int)(conf.getMaximumSystemApplications() * - e.getQueueCapacities().getAbsoluteCapacity("test")), - e.getMaxApplications()); + Assertions.assertEquals( + (int)(conf.getMaximumSystemApplications() * + e.getQueueCapacities().getAbsoluteCapacity("test")) +, e.getMaxApplications(), "Maximum application is not calculated properly"); } @Test @@ -5308,11 +5312,11 @@ public void testRootHasAllNodeLabelsOfItsDescendants() throws IOException { ParentQueue rootQueue = (ParentQueue) cs.getRootQueue(); - Assert.assertEquals(Sets.newHashSet("", "test", "test2"), + Assertions.assertEquals(Sets.newHashSet("", "test", "test2"), rootQueue.queueNodeLabelsSettings.getConfiguredNodeLabels()); } - @After + @AfterEach public void tearDown() throws Exception { if (cs != null) { cs.stop(); @@ -5388,12 +5392,12 @@ public void testSubmitUsingRealUserAcls() throws Exception { // USE_REAL_ACLS character prepended. try { testRmAppManager.submitApplication(asc, System.currentTimeMillis(), ugi0); - Assert.fail(user0 + " should not be allowed to submit to the " + Assertions.fail(user0 + " should not be allowed to submit to the " + queue + " queue when only admin user is in submit ACL."); } catch (YarnException e) { // This is the expected behavior. - assertTrue("Should have received an AccessControlException.", - e.getCause() instanceof AccessControlException); + assertTrue( + e.getCause() instanceof AccessControlException, "Should have received an AccessControlException."); } // With only user0 in the list of users authorized to submit apps to the @@ -5403,7 +5407,7 @@ public void testSubmitUsingRealUserAcls() throws Exception { try { testRmAppManager.submitApplication(asc, System.currentTimeMillis(), ugi0); } catch (YarnException e) { - Assert.fail(user0 + " should be allowed to submit to the " + Assertions.fail(user0 + " should be allowed to submit to the " + queue + " queue."); } @@ -5411,12 +5415,12 @@ public void testSubmitUsingRealUserAcls() throws Exception { // queue, ensure that user1 is NOT allowed to submit to the default queue try { testRmAppManager.submitApplication(asc, System.currentTimeMillis(), ugi1); - Assert.fail(user1 + " should not be allowed to submit to the " + Assertions.fail(user1 + " should not be allowed to submit to the " + queue + " queue."); } catch (YarnException e) { // This is the expected behavior. - assertTrue("Should have received an AccessControlException.", - e.getCause() instanceof AccessControlException); + assertTrue( + e.getCause() instanceof AccessControlException, "Should have received an AccessControlException."); } // Even though the admin user is in the list of users allowed to submit to @@ -5427,12 +5431,12 @@ public void testSubmitUsingRealUserAcls() throws Exception { new AccessControlList(user0 + "," + realUser)); try { testRmAppManager.submitApplication(asc, System.currentTimeMillis(), ugi1); - Assert.fail(user1 + " should not be allowed to submit to the " + Assertions.fail(user1 + " should not be allowed to submit to the " + queue + " queue."); } catch (YarnException e) { // This is the expected behavior. - assertTrue("Should have received an AccessControlException.", - e.getCause() instanceof AccessControlException); + assertTrue( + e.getCause() instanceof AccessControlException, "Should have received an AccessControlException."); } // user1 should now be allowed to submit to the default queue because the @@ -5446,7 +5450,7 @@ public void testSubmitUsingRealUserAcls() throws Exception { testRmAppManager.submitApplication(asc, System.currentTimeMillis(), ugi1); } catch (YarnException e) { LOG.error("failed to submit", e); - Assert.fail(user1 + " should be allowed to submit to the " + Assertions.fail(user1 + " should be allowed to submit to the " + queue + " queue when real user is" + realUser + "."); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestMixedQueueResourceCalculation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestMixedQueueResourceCalculation.java index d3084503e9305..f6f4767c2e37c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestMixedQueueResourceCalculation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestMixedQueueResourceCalculation.java @@ -26,8 +26,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueUpdateWarning.QueueUpdateWarningType; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Collection; @@ -323,10 +323,10 @@ public void testComplexHierarchyWithWarnings() throws IOException { Optional queueA11ZeroResourceWarning = getSpecificWarning( updateContext.getUpdateWarnings(), QueueUpdateWarningType.QUEUE_ZERO_RESOURCE, A11); - Assert.assertTrue(queueCZeroResourceWarning.isPresent()); - Assert.assertTrue(queueARemainingResourceWarning.isPresent()); - Assert.assertTrue(queueBDownscalingWarning.isPresent()); - Assert.assertTrue(queueA11ZeroResourceWarning.isPresent()); + Assertions.assertTrue(queueCZeroResourceWarning.isPresent()); + Assertions.assertTrue(queueARemainingResourceWarning.isPresent()); + Assertions.assertTrue(queueBDownscalingWarning.isPresent()); + Assertions.assertTrue(queueA11ZeroResourceWarning.isPresent()); } @Test @@ -346,8 +346,8 @@ public void testZeroResourceIfNoMemory() throws IOException { updateContext.getUpdateWarnings(), QueueUpdateWarningType.QUEUE_ZERO_RESOURCE, A); Optional rootUnderUtilizedWarning = getSpecificWarning( updateContext.getUpdateWarnings(), QueueUpdateWarningType.BRANCH_UNDERUTILIZED, ROOT); - Assert.assertTrue(queueAZeroResourceWarning.isPresent()); - Assert.assertTrue(rootUnderUtilizedWarning.isPresent()); + Assertions.assertTrue(queueAZeroResourceWarning.isPresent()); + Assertions.assertTrue(rootUnderUtilizedWarning.isPresent()); } @Test @@ -367,14 +367,14 @@ public void testDifferentMinimumAndMaximumCapacityTypes() throws IOException { .build(); QueueCapacityUpdateContext updateContext = update(assertionBuilder, UPDATE_RESOURCE); - Assert.assertEquals(0, updateContext.getUpdateWarnings().size()); + Assertions.assertEquals(0, updateContext.getUpdateWarnings().size()); // WEIGHT capacity type for maximum capacity is not supported csConf.setMaximumCapacityVector(B, NO_LABEL, B_INVALID_MAX_VECTOR); try { cs.reinitialize(csConf, mockRM.getRMContext()); update(assertionBuilder, UPDATE_RESOURCE); - Assert.fail("WEIGHT maximum capacity type is not supported, an error should be thrown when " + + Assertions.fail("WEIGHT maximum capacity type is not supported, an error should be thrown when " + "set up"); } catch (IOException ignored) { } @@ -402,8 +402,8 @@ public void testMaximumResourceWarnings() throws IOException { A11); Optional queueA11MinExceedsMaxWarning = getSpecificWarning( updateContext.getUpdateWarnings(), QueueUpdateWarningType.QUEUE_EXCEEDS_MAX_RESOURCE, A11); - Assert.assertTrue(queueA11ExceedsParentMaxResourceWarning.isPresent()); - Assert.assertTrue(queueA11MinExceedsMaxWarning.isPresent()); + Assertions.assertTrue(queueA11ExceedsParentMaxResourceWarning.isPresent()); + Assertions.assertTrue(queueA11MinExceedsMaxWarning.isPresent()); } @Test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestNodeLabelContainerAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestNodeLabelContainerAllocation.java index f960acd956116..e2ddb330a943a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestNodeLabelContainerAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestNodeLabelContainerAllocation.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.Arrays; @@ -68,9 +68,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.PendingAsk; import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey; -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.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; @@ -104,7 +105,7 @@ public class TestNodeLabelContainerAllocation { RMNodeLabelsManager mgr; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -161,10 +162,10 @@ private void checkTaskContainersHost(ApplicationAttemptId attemptId, YarnScheduler scheduler = rm.getRMContext().getScheduler(); SchedulerAppReport appReport = scheduler.getSchedulerAppInfo(attemptId); - Assert.assertTrue(appReport.getLiveContainers().size() > 0); + Assertions.assertTrue(appReport.getLiveContainers().size() > 0); for (RMContainer c : appReport.getLiveContainers()) { if (c.getContainerId().equals(containerId)) { - Assert.assertEquals(host, c.getAllocatedNode().getHost()); + Assertions.assertEquals(host, c.getAllocatedNode().getHost()); } } } @@ -176,7 +177,8 @@ private Set toSet(E... elements) { } - @Test (timeout = 300000) + @Test + @Timeout(value = 300) public void testContainerAllocationWithSingleUserLimits() throws Exception { final RMNodeLabelsManager mgr = new NullRMNodeLabelsManager(); mgr.init(conf); @@ -217,13 +219,13 @@ public RMNodeLabelsManager createNodeLabelManager() { ContainerId containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); am1.allocate("*", 1024, 1, new ArrayList(), ""); - Assert.assertTrue(rm1.waitForState(nm3, containerId, + Assertions.assertTrue(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); // Cannot allocate 2nd label=empty container containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 3); am1.allocate("*", 1024, 1, new ArrayList(), ""); - Assert.assertFalse(rm1.waitForState(nm3, containerId, + Assertions.assertFalse(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); // A has default user limit = 100, so it can use all resource in label = x @@ -232,13 +234,14 @@ public RMNodeLabelsManager createNodeLabelManager() { containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), id); am1.allocate("*", 1024, 1, new ArrayList(), "x"); - Assert.assertTrue(rm1.waitForState(nm1, containerId, + Assertions.assertTrue(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); } rm1.close(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testContainerAllocateWithComplexLabels() throws Exception { /* * Queue structure: @@ -315,7 +318,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate("*", 1024, 1, new ArrayList(), "y"); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2L); - Assert.assertTrue(rm1.waitForState(nm2, containerId, + Assertions.assertTrue(rm1.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am1.getApplicationAttemptId(), containerId, rm1, "h2"); @@ -338,9 +341,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // (Maximum capacity reached) am2.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am2.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm4, containerId, + Assertions.assertFalse(rm1.waitForState(nm4, containerId, RMContainerState.ALLOCATED)); - Assert.assertFalse(rm1.waitForState(nm5, containerId, + Assertions.assertFalse(rm1.waitForState(nm5, containerId, RMContainerState.ALLOCATED)); // launch an app to queue b2 @@ -359,9 +362,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // y,z). Will successfully allocate on nm3 am3.allocate("*", 1024, 1, new ArrayList(), "y"); containerId = ContainerId.newContainerId(am3.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm1, containerId, + Assertions.assertFalse(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); - Assert.assertTrue(rm1.waitForState(nm3, containerId, + Assertions.assertTrue(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am3.getApplicationAttemptId(), containerId, rm1, "h3"); @@ -370,7 +373,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // Will successfully allocate on nm4 only. am3.allocate("*", 1024, 1, new ArrayList(), "z"); containerId = ContainerId.newContainerId(am3.getApplicationAttemptId(), 3L); - Assert.assertTrue(rm1.waitForState(nm4, containerId, + Assertions.assertTrue(rm1.waitForState(nm4, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am3.getApplicationAttemptId(), containerId, rm1, "h4"); @@ -378,7 +381,8 @@ public RMNodeLabelsManager createNodeLabelManager() { rm1.close(); } - @Test (timeout = 120000) + @Test + @Timeout(value = 120) public void testContainerAllocateWithLabels() throws Exception { // set node -> label mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("x", "y")); @@ -418,9 +422,9 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate("*", 1024, 1, new ArrayList(), "x"); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm2, containerId, + Assertions.assertFalse(rm1.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); - Assert.assertTrue(rm1.waitForState(nm1, containerId, + Assertions.assertTrue(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am1.getApplicationAttemptId(), containerId, rm1, "h1"); @@ -441,9 +445,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // request a container. am2.allocate("*", 1024, 1, new ArrayList(), "y"); containerId = ContainerId.newContainerId(am2.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm1, containerId, + Assertions.assertFalse(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); - Assert.assertTrue(rm1.waitForState(nm2, containerId, + Assertions.assertTrue(rm1.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am2.getApplicationAttemptId(), containerId, rm1, "h2"); @@ -464,9 +468,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // request a container. am3.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am3.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm2, containerId, + Assertions.assertFalse(rm1.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); - Assert.assertTrue(rm1.waitForState(nm3, containerId, + Assertions.assertTrue(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am3.getApplicationAttemptId(), containerId, rm1, "h3"); @@ -474,7 +478,8 @@ public RMNodeLabelsManager createNodeLabelManager() { rm1.close(); } - @Test (timeout = 120000) + @Test + @Timeout(value = 120) public void testContainerAllocateWithDefaultQueueLabels() throws Exception { // This test is pretty much similar to testContainerAllocateWithLabel. // Difference is, this test doesn't specify label expression in ResourceRequest, @@ -518,9 +523,9 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm3, containerId, + Assertions.assertFalse(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); - Assert.assertTrue(rm1.waitForState(nm1, containerId, + Assertions.assertTrue(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am1.getApplicationAttemptId(), containerId, rm1, "h1"); @@ -541,9 +546,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // request a container. am2.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am2.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm3, containerId, + Assertions.assertFalse(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); - Assert.assertTrue(rm1.waitForState(nm2, containerId, + Assertions.assertTrue(rm1.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am2.getApplicationAttemptId(), containerId, rm1, "h2"); @@ -564,9 +569,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // request a container. am3.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am3.getApplicationAttemptId(), 2); - Assert.assertFalse(rm1.waitForState(nm2, containerId, + Assertions.assertFalse(rm1.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); - Assert.assertTrue(rm1.waitForState(nm3, containerId, + Assertions.assertTrue(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); checkTaskContainersHost(am3.getApplicationAttemptId(), containerId, rm1, "h3"); @@ -574,7 +579,8 @@ public RMNodeLabelsManager createNodeLabelManager() { rm1.close(); } - @Test (timeout = 120000) + @Test + @Timeout(value = 120) public void testContainerReservationWithLabels() throws Exception { // This test is pretty much similar to testContainerAllocateWithLabel. // Difference is, this test doesn't specify label expression in @@ -637,29 +643,30 @@ public RMNodeLabelsManager createNodeLabelManager() { // Check if a 4G container allocated for app1, and 4G is reserved FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt(am1 .getApplicationAttemptId()); - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertTrue(schedulerApp1.getReservedContainers().size() > 0); - Assert.assertEquals(9 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertTrue(schedulerApp1.getReservedContainers().size() > 0); + Assertions.assertEquals(9 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(4 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(4 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(4 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // Cancel asks of app2 and re-kick RM am1.allocate("*", 4 * GB, 0, new ArrayList()); cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertEquals(5 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(5 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(0, leafQueue.getQueueResourceUsage().getReserved("x") + Assertions.assertEquals(0, leafQueue.getQueueResourceUsage().getReserved("x") .getMemorySize()); rm1.close(); } - @Test (timeout = 120000) + @Test + @Timeout(value = 120) public void testContainerReservationContinueLookingWithLabels() throws Exception { // set node -> label @@ -708,15 +715,15 @@ public RMNodeLabelsManager createNodeLabelManager() { checkTaskContainersHost(am1.getApplicationAttemptId(), containerId, rm1, "h1"); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertFalse(schedulerApp1.getReservedContainers().size() > 0); - Assert.assertEquals(2 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertFalse(schedulerApp1.getReservedContainers().size() > 0); + Assertions.assertEquals(2 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // request map containers for app1. @@ -730,15 +737,15 @@ public RMNodeLabelsManager createNodeLabelManager() { checkTaskContainersHost(am1.getApplicationAttemptId(), containerId, rm1, "h1"); - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertFalse(schedulerApp1.getReservedContainers().size() > 0); - Assert.assertEquals(7 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertFalse(schedulerApp1.getReservedContainers().size() > 0); + Assertions.assertEquals(7 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(7 * GB, + Assertions.assertEquals(7 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // Do node heartbeat to allocate second mapper on node2 @@ -750,15 +757,15 @@ public RMNodeLabelsManager createNodeLabelManager() { "h2"); // node1 7 GB used, node2 5 GB used - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertFalse(schedulerApp1.getReservedContainers().size() > 0); - Assert.assertEquals(12 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertFalse(schedulerApp1.getReservedContainers().size() > 0); + Assertions.assertEquals(12 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(12 * GB, + Assertions.assertEquals(12 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // request reducer containers for app1. @@ -768,15 +775,15 @@ public RMNodeLabelsManager createNodeLabelManager() { cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); // node1 7 GB used and 3 GB reserved, node2 5 GB used - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); - Assert.assertEquals(15 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(15 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(3 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(3 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(15 * GB, + Assertions.assertEquals(15 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // Do node heartbeat to allocate container for second reducer on node2 @@ -789,21 +796,22 @@ public RMNodeLabelsManager createNodeLabelManager() { "h2"); // node1 7 GB used and 0 GB reserved, node2 8 GB used - Assert.assertEquals(4, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(0, schedulerApp1.getReservedContainers().size()); - Assert.assertEquals(15 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(4, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(0, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(15 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(15 * GB, + Assertions.assertEquals(15 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); rm1.close(); } - @Test (timeout = 120000) + @Test + @Timeout(value = 120) public void testContainerReservationContinueLookingWithDefaultLabels() throws Exception { // This is the same as testContainerReservationContinueLookingWithLabels, @@ -853,15 +861,15 @@ public RMNodeLabelsManager createNodeLabelManager() { checkTaskContainersHost(am1.getApplicationAttemptId(), containerId, rm1, "h1"); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertFalse(schedulerApp1.getReservedContainers().size() > 0); - Assert.assertEquals(2 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertFalse(schedulerApp1.getReservedContainers().size() > 0); + Assertions.assertEquals(2 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(2 * GB, + Assertions.assertEquals(2 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // request map containers for app1. @@ -875,15 +883,15 @@ public RMNodeLabelsManager createNodeLabelManager() { checkTaskContainersHost(am1.getApplicationAttemptId(), containerId, rm1, "h1"); - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertFalse(schedulerApp1.getReservedContainers().size() > 0); - Assert.assertEquals(7 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertFalse(schedulerApp1.getReservedContainers().size() > 0); + Assertions.assertEquals(7 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(7 * GB, + Assertions.assertEquals(7 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // Do node heartbeat to allocate second mapper on node2 @@ -895,15 +903,15 @@ public RMNodeLabelsManager createNodeLabelManager() { "h2"); // node1 7 GB used, node2 5 GB used - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertFalse(schedulerApp1.getReservedContainers().size() > 0); - Assert.assertEquals(12 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertFalse(schedulerApp1.getReservedContainers().size() > 0); + Assertions.assertEquals(12 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(12 * GB, + Assertions.assertEquals(12 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // request reducer containers for app1. @@ -913,15 +921,15 @@ public RMNodeLabelsManager createNodeLabelManager() { cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); // node1 7 GB used and 3 GB reserved, node2 5 GB used - Assert.assertEquals(3, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); - Assert.assertEquals(15 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(3, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(15 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(3 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(3 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(15 * GB, + Assertions.assertEquals(15 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(3 * GB, + Assertions.assertEquals(3 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); // Do node heartbeat to allocate container for second reducer on node2 @@ -934,21 +942,22 @@ public RMNodeLabelsManager createNodeLabelManager() { "h2"); // node1 7 GB used and 0 GB reserved, node2 8 GB used - Assert.assertEquals(4, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(0, schedulerApp1.getReservedContainers().size()); - Assert.assertEquals(15 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(4, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(0, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(15 * GB, cs.getRootQueue().getQueueResourceUsage() .getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() + Assertions.assertEquals(0 * GB, cs.getRootQueue().getQueueResourceUsage() .getReserved("x").getMemorySize()); - Assert.assertEquals(15 * GB, + Assertions.assertEquals(15 * GB, leafQueue.getQueueResourceUsage().getUsed("x").getMemorySize()); - Assert.assertEquals(0 * GB, + Assertions.assertEquals(0 * GB, leafQueue.getQueueResourceUsage().getReserved("x").getMemorySize()); rm1.close(); } - @Test (timeout = 120000) + @Test + @Timeout(value = 120) public void testRMContainerLeakInLeafQueue() throws Exception { // set node -> label mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("x")); @@ -1006,22 +1015,22 @@ public void testRMContainerLeakInLeafQueue() throws Exception { // Check if a 4G container allocated for app1, and 4G is reserved FiCaSchedulerApp schedulerApp1 = cs.getApplicationAttempt(am1.getApplicationAttemptId()); - Assert.assertEquals(1, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(1, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); // kill app2 then do node heartbeat 1 time // scheduler will allocate a container from the reserved container on nm1 rm1.killApp(app2.getApplicationId()); rm1.waitForState(app2.getApplicationId(), RMAppState.KILLED); cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assert.assertEquals(2, schedulerApp1.getLiveContainers().size()); - Assert.assertEquals(0, schedulerApp1.getReservedContainers().size()); + Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + Assertions.assertEquals(0, schedulerApp1.getReservedContainers().size()); // After kill app1, LeafQueue#ignorePartitionExclusivityRMContainers should // be clean, otherwise resource leak happened rm1.killApp(app1.getApplicationId()); rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED); - Assert.assertEquals(0, leafQueue.getIgnoreExclusivityRMContainers().size()); + Assertions.assertEquals(0, leafQueue.getIgnoreExclusivityRMContainers().size()); rm1.close(); } @@ -1033,7 +1042,7 @@ private void checkPendingResource(MockRM rm, int priority, PendingAsk ask = app.getAppSchedulingInfo().getPendingAsk( TestUtils.toSchedulerKey(priority), "*"); - Assert.assertEquals(memory, + Assertions.assertEquals(memory, ask.getPerAllocationResource().getMemorySize() * ask .getCount()); } @@ -1042,7 +1051,7 @@ private void checkLaunchedContainerNumOnNode(MockRM rm, NodeId nodeId, int numContainers) { CapacityScheduler cs = (CapacityScheduler) rm.getRMContext().getScheduler(); SchedulerNode node = cs.getSchedulerNode(nodeId); - Assert.assertEquals(numContainers, node.getNumContainers()); + Assertions.assertEquals(numContainers, node.getNumContainers()); } /** @@ -1142,10 +1151,10 @@ private void checkNodePartitionOfRequestedPriority(AppSchedulingInfo info, int priority, String expectedPartition) { for (SchedulerRequestKey key : info.getSchedulerKeys()) { if (key.getPriority().getPriority() == priority) { - Assert.assertEquals("Expected partition is " + expectedPartition, - expectedPartition, - info.getAppPlacementAllocator(key) - .getPrimaryRequestedNodePartition()); + Assertions.assertEquals( + expectedPartition +, info.getAppPlacementAllocator(key) + .getPrimaryRequestedNodePartition(), "Expected partition is " + expectedPartition); } } } @@ -1239,7 +1248,7 @@ private void checkNumOfContainersInAnAppOnGivenNode(int expectedNum, num++; } } - Assert.assertEquals(expectedNum, num); + Assertions.assertEquals(expectedNum, num); } @Test @@ -1352,7 +1361,7 @@ public RMNodeLabelsManager createNodeLabelManager() { for (int i = 2; i < 2 + 6; i++) { nextContainerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), i); - Assert.assertTrue(rm1.waitForState(Arrays.asList(nm1, nm2), + Assertions.assertTrue(rm1.waitForState(Arrays.asList(nm1, nm2), nextContainerId, RMContainerState.ALLOCATED)); } // no more container allocated on nm1 @@ -1638,7 +1647,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // NM2 can allocate 10 containers totally, exclude already allocated AM // container, we will wait 9 to fulfill non-partitioned node, and need wait // one more cycle before allocating to non-partitioned node - Assert.assertEquals(10, cycleWaited); + Assertions.assertEquals(10, cycleWaited); // Both NM1/NM2 launched 10 containers, cluster resource is exhausted checkLaunchedContainerNumOnNode(rm1, nm1.getNodeId(), 10); @@ -1695,23 +1704,24 @@ public RMNodeLabelsManager createNodeLabelManager() { cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); } - Assert.assertTrue( - "Scheduler diagnostics should have reason for not assigning the node", - app.getDiagnostics().toString().contains( - CSAMContainerLaunchDiagnosticsConstants.SKIP_AM_ALLOCATION_IN_IGNORE_EXCLUSIVE_MODE)); + Assertions.assertTrue( + + app.getDiagnostics().toString().contains( + CSAMContainerLaunchDiagnosticsConstants.SKIP_AM_ALLOCATION_IN_IGNORE_EXCLUSIVE_MODE), "Scheduler diagnostics should have reason for not assigning the node"); - Assert.assertTrue( - "Scheduler diagnostics should have last processed node information", - app.getDiagnostics().toString().contains( + Assertions.assertTrue( + + app.getDiagnostics().toString().contains( CSAMContainerLaunchDiagnosticsConstants.LAST_NODE_PROCESSED_MSG - + nodeIdStr + " ( Partition : [x]")); - Assert.assertEquals(0, cs.getSchedulerNode(nm1.getNodeId()) + + nodeIdStr + " ( Partition : [x]"), "Scheduler diagnostics should have last processed node information"); + Assertions.assertEquals(0, cs.getSchedulerNode(nm1.getNodeId()) .getNumContainers()); rm1.close(); } - @Test(timeout=60000) + @Test + @Timeout(value = 60) public void testQueueMaxCapacitiesWillNotBeHonoredWhenNotRespectingExclusivity() throws Exception { @@ -1795,20 +1805,20 @@ public RMNodeLabelsManager createNodeLabelManager() { } // app1 gets all resource in partition=x - Assert.assertEquals(10, schedulerNode1.getNumContainers()); + Assertions.assertEquals(10, schedulerNode1.getNumContainers()); // check non-exclusive containers of LeafQueue is correctly updated LeafQueue leafQueue = (LeafQueue) cs.getQueue("a"); - Assert.assertFalse(leafQueue.getIgnoreExclusivityRMContainers().containsKey( + Assertions.assertFalse(leafQueue.getIgnoreExclusivityRMContainers().containsKey( "y")); - Assert.assertEquals(10, + Assertions.assertEquals(10, leafQueue.getIgnoreExclusivityRMContainers().get("x").size()); // completes all containers of app1, ignoreExclusivityRMContainers should be // updated as well. cs.handle(new AppAttemptRemovedSchedulerEvent( am1.getApplicationAttemptId(), RMAppAttemptState.FINISHED, false)); - Assert.assertFalse(leafQueue.getIgnoreExclusivityRMContainers().containsKey( + Assertions.assertFalse(leafQueue.getIgnoreExclusivityRMContainers().containsKey( "x")); rm1.close(); @@ -1818,11 +1828,11 @@ private void checkQueueUsedCapacity(String queueName, CapacityScheduler cs, String nodePartition, float usedCapacity, float absoluteUsedCapacity) { float epsilon = 1e-6f; CSQueue queue = cs.getQueue(queueName); - Assert.assertNotNull("Failed to get queue=" + queueName, queue); + Assertions.assertNotNull(queue, "Failed to get queue=" + queueName); - Assert.assertEquals(usedCapacity, queue.getQueueCapacities() + Assertions.assertEquals(usedCapacity, queue.getQueueCapacities() .getUsedCapacity(nodePartition), epsilon); - Assert.assertEquals(absoluteUsedCapacity, queue.getQueueCapacities() + Assertions.assertEquals(absoluteUsedCapacity, queue.getQueueCapacities() .getAbsoluteUsedCapacity(nodePartition), epsilon); } @@ -2604,18 +2614,18 @@ public RMNodeLabelsManager createNodeLabelManager() { } // app1 gets all resource in partition=x - Assert.assertEquals(5, schedulerNode1.getNumContainers()); + Assertions.assertEquals(5, schedulerNode1.getNumContainers()); SchedulerNodeReport reportNm1 = rm1.getResourceScheduler() .getNodeReport(nm1.getNodeId()); - Assert.assertEquals(5 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(5 * GB, + Assertions.assertEquals(5 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(5 * GB, reportNm1.getAvailableResource().getMemorySize()); SchedulerNodeReport reportNm2 = rm1.getResourceScheduler() .getNodeReport(nm2.getNodeId()); - Assert.assertEquals(0 * GB, reportNm2.getUsedResource().getMemorySize()); - Assert.assertEquals(10 * GB, + Assertions.assertEquals(0 * GB, reportNm2.getUsedResource().getMemorySize()); + Assertions.assertEquals(10 * GB, reportNm2.getAvailableResource().getMemorySize()); assertEquals(0 * GB, leafQueueA.getMetrics().getAvailableMB()); @@ -2764,16 +2774,16 @@ public RMNodeLabelsManager createNodeLabelManager() { } // app1 gets all resource in partition=x (non-exclusive) - Assert.assertEquals(3, schedulerNode1.getNumContainers()); + Assertions.assertEquals(3, schedulerNode1.getNumContainers()); SchedulerNodeReport reportNm1 = rm1.getResourceScheduler() .getNodeReport(nm1.getNodeId()); - Assert.assertEquals(3 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(7 * GB, + Assertions.assertEquals(3 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(7 * GB, reportNm1.getAvailableResource().getMemorySize()); SchedulerNodeReport reportNm2 = rm1.getResourceScheduler() .getNodeReport(nm2.getNodeId()); - Assert.assertEquals(1 * GB, reportNm2.getUsedResource().getMemorySize()); - Assert.assertEquals(9 * GB, + Assertions.assertEquals(1 * GB, reportNm2.getUsedResource().getMemorySize()); + Assertions.assertEquals(9 * GB, reportNm2.getAvailableResource().getMemorySize()); assertEquals(7 * GB, partXMetrics.getAvailableMB(), delta); assertEquals(9 * GB, partDefaultMetrics.getAvailableMB(), delta); @@ -2821,8 +2831,8 @@ public RMNodeLabelsManager createNodeLabelManager() { cs.handle(new NodeUpdateSchedulerEvent(rmNode2)); - Assert.assertEquals(2, schedulerNode2.getNumContainers()); - Assert.assertEquals(3, schedulerNode1.getNumContainers()); + Assertions.assertEquals(2, schedulerNode2.getNumContainers()); + Assertions.assertEquals(3, schedulerNode1.getNumContainers()); // 3GB is used from label x quota. 2GB used from default label. // So 0.5 GB is remaining from default label. @@ -2996,18 +3006,18 @@ public RMNodeLabelsManager createNodeLabelManager() { } // app1 gets all resource in partition=x - Assert.assertEquals(6, schedulerNode1.getNumContainers()); + Assertions.assertEquals(6, schedulerNode1.getNumContainers()); SchedulerNodeReport reportNm1 = rm1.getResourceScheduler() .getNodeReport(nm1.getNodeId()); - Assert.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(4 * GB, reportNm1.getAvailableResource().getMemorySize()); SchedulerNodeReport reportNm2 = rm1.getResourceScheduler() .getNodeReport(nm2.getNodeId()); - Assert.assertEquals(0 * GB, reportNm2.getUsedResource().getMemorySize()); - Assert.assertEquals(12 * GB, + Assertions.assertEquals(0 * GB, reportNm2.getUsedResource().getMemorySize()); + Assertions.assertEquals(12 * GB, reportNm2.getAvailableResource().getMemorySize()); assertEquals(12 * GB, leafQueueA.getMetrics().getAvailableMB()); @@ -3036,16 +3046,16 @@ public RMNodeLabelsManager createNodeLabelManager() { } // app1 gets all resource in partition=x - Assert.assertEquals(6, schedulerNode2.getNumContainers()); + Assertions.assertEquals(6, schedulerNode2.getNumContainers()); reportNm1 = rm1.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(4 * GB, reportNm1.getAvailableResource().getMemorySize()); reportNm2 = rm1.getResourceScheduler().getNodeReport(nm2.getNodeId()); - Assert.assertEquals(6 * GB, reportNm2.getUsedResource().getMemorySize()); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, reportNm2.getUsedResource().getMemorySize()); + Assertions.assertEquals(6 * GB, reportNm2.getAvailableResource().getMemorySize()); assertEquals(6 * GB, leafQueueA.getMetrics().getAvailableMB()); @@ -3174,17 +3184,17 @@ public RMNodeLabelsManager createNodeLabelManager() { } // app1 gets all resource in partition=x - Assert.assertEquals(6, schedulerNode1.getNumContainers()); + Assertions.assertEquals(6, schedulerNode1.getNumContainers()); SchedulerNodeReport reportNm1 = rm1.getResourceScheduler() .getNodeReport(nm1.getNodeId()); - Assert.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(4 * GB, reportNm1.getAvailableResource().getMemorySize()); + Assertions.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(4 * GB, reportNm1.getAvailableResource().getMemorySize()); SchedulerNodeReport reportNm2 = rm1.getResourceScheduler() .getNodeReport(nm2.getNodeId()); - Assert.assertEquals(0 * GB, reportNm2.getUsedResource().getMemorySize()); - Assert.assertEquals(12 * GB, + Assertions.assertEquals(0 * GB, reportNm2.getUsedResource().getMemorySize()); + Assertions.assertEquals(12 * GB, reportNm2.getAvailableResource().getMemorySize()); assertEquals(0 * GB, queueAMetrics.getAllocatedMB()); @@ -3224,16 +3234,16 @@ public RMNodeLabelsManager createNodeLabelManager() { } // app1 gets all resource in partition=x - Assert.assertEquals(6, schedulerNode2.getNumContainers()); + Assertions.assertEquals(6, schedulerNode2.getNumContainers()); reportNm1 = rm1.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assert.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(4 * GB, + Assertions.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(4 * GB, reportNm1.getAvailableResource().getMemorySize()); reportNm2 = rm1.getResourceScheduler().getNodeReport(nm2.getNodeId()); - Assert.assertEquals(6 * GB, reportNm2.getUsedResource().getMemorySize()); - Assert.assertEquals(6 * GB, + Assertions.assertEquals(6 * GB, reportNm2.getUsedResource().getMemorySize()); + Assertions.assertEquals(6 * GB, reportNm2.getAvailableResource().getMemorySize()); assertEquals(6 * GB, leafQueueA.getMetrics().getAvailableMB()); @@ -3363,8 +3373,8 @@ public RMNodeLabelsManager createNodeLabelManager() { SchedulerNodeReport reportNm1 = rm1.getResourceScheduler() .getNodeReport(nm1.getNodeId()); - Assert.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(14 * GB, + Assertions.assertEquals(6 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(14 * GB, reportNm1.getAvailableResource().getMemorySize()); // Try to launch app2 in a2, asked 2GB, should success @@ -3390,8 +3400,8 @@ public RMNodeLabelsManager createNodeLabelManager() { reportNm1 = rm1.getResourceScheduler() .getNodeReport(nm1.getNodeId()); - Assert.assertEquals(10 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(10 * GB, + Assertions.assertEquals(10 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(10 * GB, reportNm1.getAvailableResource().getMemorySize()); // Kill all apps in queue a2 @@ -3419,8 +3429,8 @@ public RMNodeLabelsManager createNodeLabelManager() { checkNumOfContainersInAnAppOnGivenNode(4, nm1.getNodeId(), cs.getApplicationAttempt(am3.getApplicationAttemptId())); - Assert.assertEquals(10 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(10 * GB, + Assertions.assertEquals(10 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(10 * GB, reportNm1.getAvailableResource().getMemorySize()); // Kill all apps in queue a1 @@ -3450,8 +3460,8 @@ public RMNodeLabelsManager createNodeLabelManager() { checkNumOfContainersInAnAppOnGivenNode(6, nm1.getNodeId(), cs.getApplicationAttempt(am4.getApplicationAttemptId())); - Assert.assertEquals(10 * GB, reportNm1.getUsedResource().getMemorySize()); - Assert.assertEquals(10 * GB, + Assertions.assertEquals(10 * GB, reportNm1.getUsedResource().getMemorySize()); + Assertions.assertEquals(10 * GB, reportNm1.getAvailableResource().getMemorySize()); rm1.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/scheduler/capacity/TestParentQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestParentQueue.java index 73db7c1c11bce..0de8642d164c9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestParentQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestParentQueue.java @@ -19,11 +19,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; import static org.hamcrest.CoreMatchers.is; -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.Assume.assumeThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; @@ -59,10 +56,10 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; 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.mockito.InOrder; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -117,7 +114,7 @@ public class TestParentQueue { private static final QueuePath Q_C111 = Q_C11.createNewLeaf(C111); private static final QueuePath Q_C1111 = Q_C111.createNewLeaf(C1111); - @Before + @BeforeEach public void setUp() throws Exception { rmContext = TestUtils.getMockRMContext(); conf = new YarnConfiguration(); @@ -420,7 +417,7 @@ public void testSingleLevelQueuesPrecision() throws Exception { exceptionOccurred = true; } if (!exceptionOccurred) { - Assert.fail("Capacity is more then 100% so should be failed."); + Assertions.fail("Capacity is more then 100% so should be failed."); } csConf.setCapacity(Q_A, 30); csConf.setCapacity(Q_B, 70); @@ -435,7 +432,7 @@ public void testSingleLevelQueuesPrecision() throws Exception { exceptionOccurred = true; } if (exceptionOccurred) { - Assert.fail("Capacity is 100% so should not be failed."); + Assertions.fail("Capacity is 100% so should not be failed."); } csConf.setCapacity(Q_A, 30); csConf.setCapacity(Q_B, 70.005F); @@ -450,7 +447,7 @@ public void testSingleLevelQueuesPrecision() throws Exception { exceptionOccurred = true; } if (exceptionOccurred) { - Assert + Assertions .fail("Capacity is under PRECISION which is .05% so should not be failed."); } } @@ -669,45 +666,49 @@ public void testMultiLevelQueues() throws Exception { reset(a); reset(b); reset(c); } - @Test (expected=IOException.class) + @Test public void testQueueCapacitySettingChildZero() throws Exception { - // Setup queue configs - setupMultiLevelQueues(csConf); + assertThrows(IOException.class, ()->{ + // Setup queue configs + setupMultiLevelQueues(csConf); - // If the new queue mode is used it's allowed to have - // zero-capacity queues under a non-zero parent - assumeThat(csConf.isLegacyQueueMode(), is(true)); + // If the new queue mode is used it's allowed to have + // zero-capacity queues under a non-zero parent + assumeThat(csConf.isLegacyQueueMode(), is(true)); - // set child queues capacity to 0 when parents not 0 - csConf.setCapacity(Q_B1, 0); - csConf.setCapacity(Q_B2, 0); - csConf.setCapacity(Q_B3, 0); - queueContext.reinitialize(); + // set child queues capacity to 0 when parents not 0 + csConf.setCapacity(Q_B1, 0); + csConf.setCapacity(Q_B2, 0); + csConf.setCapacity(Q_B3, 0); + queueContext.reinitialize(); - CSQueueStore queues = new CSQueueStore(); - CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null, - CapacitySchedulerConfiguration.ROOT, queues, queues, - TestUtils.spyHook); + CSQueueStore queues = new CSQueueStore(); + CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null, + CapacitySchedulerConfiguration.ROOT, queues, queues, + TestUtils.spyHook); + }); } - @Test (expected=IOException.class) + @Test public void testQueueCapacitySettingParentZero() throws Exception { - // Setup queue configs - setupMultiLevelQueues(csConf); + assertThrows(IOException.class, ()->{ + // Setup queue configs + setupMultiLevelQueues(csConf); - // If the new queue mode is used it's allowed to have - // non-zero capacity queues under a zero capacity parent - assumeThat(csConf.isLegacyQueueMode(), is(true)); + // If the new queue mode is used it's allowed to have + // non-zero capacity queues under a zero capacity parent + assumeThat(csConf.isLegacyQueueMode(), is(true)); - // set parent capacity to 0 when child not 0 - csConf.setCapacity(Q_B, 0); - csConf.setCapacity(Q_A, 60); - queueContext.reinitialize(); + // set parent capacity to 0 when child not 0 + csConf.setCapacity(Q_B, 0); + csConf.setCapacity(Q_A, 60); + queueContext.reinitialize(); - CSQueueStore queues = new CSQueueStore(); - CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null, - CapacitySchedulerConfiguration.ROOT, queues, queues, - TestUtils.spyHook); + CSQueueStore queues = new CSQueueStore(); + CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null, + CapacitySchedulerConfiguration.ROOT, queues, queues, + TestUtils.spyHook); + }); } @Test @@ -728,29 +729,31 @@ public void testQueueCapacitySettingParentZeroChildren100pctZeroSumAllowed() TestUtils.spyHook); } - @Test(expected = IOException.class) + @Test public void testQueueCapacitySettingParentZeroChildren50pctZeroSumAllowed() throws Exception { - // Setup queue configs - setupMultiLevelQueues(csConf); - - // If the new queue mode is used it's allowed to have - // non-zero capacity queues under a zero capacity parent - assumeThat(csConf.isLegacyQueueMode(), is(true)); - - // set parent capacity to 0 when sum(children) is 50 - // and allow zero capacity sum - csConf.setCapacity(Q_B, 0); - csConf.setCapacity(Q_A, 100); - csConf.setCapacity(Q_B1, 10); - csConf.setCapacity(Q_B2, 20); - csConf.setCapacity(Q_B3, 20); - csConf.setAllowZeroCapacitySum(Q_B, true); - queueContext.reinitialize(); - CSQueueStore queues = new CSQueueStore(); - CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null, - CapacitySchedulerConfiguration.ROOT, queues, queues, - TestUtils.spyHook); + assertThrows(IOException.class, ()->{ + // Setup queue configs + setupMultiLevelQueues(csConf); + + // If the new queue mode is used it's allowed to have + // non-zero capacity queues under a zero capacity parent + assumeThat(csConf.isLegacyQueueMode(), is(true)); + + // set parent capacity to 0 when sum(children) is 50 + // and allow zero capacity sum + csConf.setCapacity(Q_B, 0); + csConf.setCapacity(Q_A, 100); + csConf.setCapacity(Q_B1, 10); + csConf.setCapacity(Q_B2, 20); + csConf.setCapacity(Q_B3, 20); + csConf.setAllowZeroCapacitySum(Q_B, true); + queueContext.reinitialize(); + CSQueueStore queues = new CSQueueStore(); + CapacitySchedulerQueueManager.parseQueue(queueContext, csConf, null, + CapacitySchedulerConfiguration.ROOT, queues, queues, + TestUtils.spyHook); + }); } @Test @@ -795,7 +798,7 @@ public void testQueueCapacityZero() throws Exception { } catch (IllegalArgumentException e) { fail("Failed to create queues with 0 capacity: " + e); } - assertTrue("Failed to create queues with 0 capacity", true); + assertTrue(true, "Failed to create queues with 0 capacity"); } @Test @@ -1248,7 +1251,7 @@ public void testDeriveCapacityFromAbsoluteConfigurations() throws Exception { } - @After + @AfterEach public void tearDown() throws Exception { } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueCapacities.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueCapacities.java index c3f505bdf085e..166e37b8c2ca8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueCapacities.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueCapacities.java @@ -24,8 +24,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -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; @@ -108,11 +108,11 @@ private void internalTestModifyAndRead(String label) throws Exception { // Set to 1, and check set(qc, suffix, label, 1f); - Assert.assertEquals(1f, get(qc, suffix, label), 1e-8); + Assertions.assertEquals(1f, get(qc, suffix, label), 1e-8); // Set to 2, and check set(qc, suffix, label, 2f); - Assert.assertEquals(2f, get(qc, suffix, label), 1e-8); + Assertions.assertEquals(2f, get(qc, suffix, label), 1e-8); } @Test @@ -125,9 +125,9 @@ public void testModifyAndRead() throws Exception { @Test public void testDefaultValues() { QueueCapacities qc = new QueueCapacities(false); - Assert.assertEquals(-1, qc.getWeight(""), 1e-6); - Assert.assertEquals(-1, qc.getWeight("x"), 1e-6); - Assert.assertEquals(0, qc.getCapacity(""), 1e-6); - Assert.assertEquals(0, qc.getCapacity("x"), 1e-6); + Assertions.assertEquals(-1, qc.getWeight(""), 1e-6); + Assertions.assertEquals(-1, qc.getWeight("x"), 1e-6); + Assertions.assertEquals(0, qc.getCapacity(""), 1e-6); + Assertions.assertEquals(0, qc.getCapacity("x"), 1e-6); } } \ 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/scheduler/capacity/TestQueueCapacityVector.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueCapacityVector.java index b7883614fe38c..c15b00905cccf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueCapacityVector.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueCapacityVector.java @@ -23,9 +23,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.QueueCapacityVectorEntry; 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 java.util.List; @@ -40,7 +40,7 @@ public class TestQueueCapacityVector { private final YarnConfiguration conf = new YarnConfiguration(); - @Before + @BeforeEach public void setUp() { conf.set(YarnConfiguration.RESOURCE_TYPES, CUSTOM_RESOURCE); ResourceUtils.resetResourceTypes(conf); @@ -54,19 +54,19 @@ public void getResourceNamesByCapacityType() { capacityVector.setResource(VCORES_URI, 6, ResourceUnitCapacityType.PERCENTAGE); // custom is not set, defaults to 0 - Assert.assertEquals(1, capacityVector.getResourceNamesByCapacityType( + Assertions.assertEquals(1, capacityVector.getResourceNamesByCapacityType( ResourceUnitCapacityType.ABSOLUTE).size()); - Assert.assertTrue(capacityVector.getResourceNamesByCapacityType( + Assertions.assertTrue(capacityVector.getResourceNamesByCapacityType( ResourceUnitCapacityType.ABSOLUTE).contains(CUSTOM_RESOURCE)); - Assert.assertEquals(2, capacityVector.getResourceNamesByCapacityType( + Assertions.assertEquals(2, capacityVector.getResourceNamesByCapacityType( ResourceUnitCapacityType.PERCENTAGE).size()); - Assert.assertTrue(capacityVector.getResourceNamesByCapacityType( + Assertions.assertTrue(capacityVector.getResourceNamesByCapacityType( ResourceUnitCapacityType.PERCENTAGE).contains(VCORES_URI)); - Assert.assertTrue(capacityVector.getResourceNamesByCapacityType( + Assertions.assertTrue(capacityVector.getResourceNamesByCapacityType( ResourceUnitCapacityType.PERCENTAGE).contains(MEMORY_URI)); - Assert.assertEquals(10, capacityVector.getResource(MEMORY_URI).getResourceValue(), EPSILON); - Assert.assertEquals(6, capacityVector.getResource(VCORES_URI).getResourceValue(), EPSILON); + Assertions.assertEquals(10, capacityVector.getResource(MEMORY_URI).getResourceValue(), EPSILON); + Assertions.assertEquals(6, capacityVector.getResource(VCORES_URI).getResourceValue(), EPSILON); } @Test @@ -77,10 +77,10 @@ public void isResourceOfType() { capacityVector.setResource(VCORES_URI, 6, ResourceUnitCapacityType.PERCENTAGE); capacityVector.setResource(CUSTOM_RESOURCE, 3, ResourceUnitCapacityType.ABSOLUTE); - Assert.assertTrue(capacityVector.isResourceOfType(MEMORY_URI, ResourceUnitCapacityType.WEIGHT)); - Assert.assertTrue(capacityVector.isResourceOfType(VCORES_URI, + Assertions.assertTrue(capacityVector.isResourceOfType(MEMORY_URI, ResourceUnitCapacityType.WEIGHT)); + Assertions.assertTrue(capacityVector.isResourceOfType(VCORES_URI, ResourceUnitCapacityType.PERCENTAGE)); - Assert.assertTrue(capacityVector.isResourceOfType(CUSTOM_RESOURCE, + Assertions.assertTrue(capacityVector.isResourceOfType(CUSTOM_RESOURCE, ResourceUnitCapacityType.ABSOLUTE)); } @@ -89,12 +89,12 @@ public void testIterator() { QueueCapacityVector capacityVector = QueueCapacityVector.newInstance(); List entries = Lists.newArrayList(capacityVector); - Assert.assertEquals(3, entries.size()); + Assertions.assertEquals(3, entries.size()); QueueCapacityVector emptyCapacityVector = new QueueCapacityVector(); List emptyEntries = Lists.newArrayList(emptyCapacityVector); - Assert.assertEquals(0, emptyEntries.size()); + Assertions.assertEquals(0, emptyEntries.size()); } @Test @@ -105,24 +105,24 @@ public void testToString() { capacityVector.setResource(VCORES_URI, 6, ResourceUnitCapacityType.PERCENTAGE); capacityVector.setResource(CUSTOM_RESOURCE, 3, ResourceUnitCapacityType.ABSOLUTE); - Assert.assertEquals(MIXED_CAPACITY_VECTOR_STRING, capacityVector.toString()); + Assertions.assertEquals(MIXED_CAPACITY_VECTOR_STRING, capacityVector.toString()); QueueCapacityVector emptyCapacityVector = new QueueCapacityVector(); - Assert.assertEquals("[]", emptyCapacityVector.toString()); + Assertions.assertEquals("[]", emptyCapacityVector.toString()); } @Test public void testIsMixedType() { // Starting from ABSOLUTE mode QueueCapacityVector capacityVector = QueueCapacityVector.newInstance(); - Assert.assertFalse(capacityVector.isMixedCapacityVector()); + Assertions.assertFalse(capacityVector.isMixedCapacityVector()); capacityVector.setResource(VCORES_URI, 6, ResourceUnitCapacityType.PERCENTAGE); capacityVector.setResource(MEMORY_URI, 10, ResourceUnitCapacityType.PERCENTAGE); capacityVector.setResource(CUSTOM_RESOURCE, 3, ResourceUnitCapacityType.PERCENTAGE); - Assert.assertFalse(capacityVector.isMixedCapacityVector()); + Assertions.assertFalse(capacityVector.isMixedCapacityVector()); capacityVector.setResource(VCORES_URI, 6, ResourceUnitCapacityType.WEIGHT); - Assert.assertTrue(capacityVector.isMixedCapacityVector()); + Assertions.assertTrue(capacityVector.isMixedCapacityVector()); } } \ 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/scheduler/capacity/TestQueueConfigurationAutoRefreshPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueConfigurationAutoRefreshPolicy.java index f4a5a2103d648..db519e5e6e70e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueConfigurationAutoRefreshPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueConfigurationAutoRefreshPolicy.java @@ -27,10 +27,10 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.MockRM; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics; -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 java.io.DataOutputStream; import java.io.File; @@ -55,7 +55,7 @@ public class TestQueueConfigurationAutoRefreshPolicy { YarnConfiguration.DR_CONFIGURATION_FILE); } - @Before + @BeforeEach public void setup() throws IOException { QueueMetrics.clearQueueMetrics(); DefaultMetricsSystem.setMiniClusterMode(true); @@ -94,7 +94,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)); @@ -249,15 +249,15 @@ public void testCommon(Boolean isFileSystemBased) throws Exception { policy.editSchedule(); // Make sure refresh successfully. - Assert.assertFalse(policy.getLastReloadAttemptFailed()); + Assertions.assertFalse(policy.getLastReloadAttemptFailed()); long oldModified = policy.getLastModified(); long oldSuccess = policy.getLastReloadAttempt(); - Assert.assertTrue(oldSuccess > oldModified); + Assertions.assertTrue(oldSuccess > oldModified); int maxAppsAfter = cs.getConfiguration().getMaximumSystemApplications(); - Assert.assertEquals(maxAppsAfter, 5000); - Assert.assertTrue(maxAppsAfter != maxAppsBefore); + Assertions.assertEquals(maxAppsAfter, 5000); + Assertions.assertTrue(maxAppsAfter != maxAppsBefore); // Trigger interval for refresh. GenericTestUtils.waitFor(() -> (policy.getClock().getTime() - @@ -277,11 +277,11 @@ public void testCommon(Boolean isFileSystemBased) throws Exception { 500, 3000); // Make sure refresh successfully. - Assert.assertFalse(policy.getLastReloadAttemptFailed()); + Assertions.assertFalse(policy.getLastReloadAttemptFailed()); oldModified = policy.getLastModified(); oldSuccess = policy.getLastReloadAttempt(); - Assert.assertTrue(oldSuccess > oldModified); - Assert.assertEquals(cs.getConfiguration(). + Assertions.assertTrue(oldSuccess > oldModified); + Assertions.assertEquals(cs.getConfiguration(). getMaximumSystemApplications(), 3000); // Trigger interval for refresh. @@ -291,13 +291,13 @@ public void testCommon(Boolean isFileSystemBased) throws Exception { // Without modified policy.editSchedule(); - Assert.assertEquals(oldModified, + Assertions.assertEquals(oldModified, policy.getLastModified()); - Assert.assertEquals(oldSuccess, + Assertions.assertEquals(oldSuccess, policy.getLastReloadAttempt()); } - @After + @AfterEach public void tearDown() throws IOException { 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/scheduler/capacity/TestQueueManagementDynamicEditPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueManagementDynamicEditPolicy.java index 733f04171577f..4cb0419362658 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueManagementDynamicEditPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueManagementDynamicEditPolicy.java @@ -21,8 +21,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity .queuemanagement.GuaranteedOrZeroCapacityOverTimePolicy; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -30,14 +30,14 @@ .NO_LABEL; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler .capacity.CSQueueUtils.EPSILON; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestQueueManagementDynamicEditPolicy extends TestCapacitySchedulerAutoCreatedQueueBase { private QueueManagementDynamicEditPolicy policy = new QueueManagementDynamicEditPolicy(); - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); policy.init(cs.getConfiguration(), cs.getRMContext(), cs); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueMappings.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueMappings.java index b30ea50bc9e57..3898172f3961c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueMappings.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueMappings.java @@ -22,14 +22,15 @@ import org.apache.hadoop.yarn.server.resourcemanager.placement.csmappingrule.MappingRule; import org.apache.hadoop.yarn.server.resourcemanager.placement.QueueMapping; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.RMContext; -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 TestQueueMappings { @@ -50,7 +51,7 @@ public class TestQueueMappings { private CapacityScheduler cs; private YarnConfiguration conf; - @Before + @BeforeEach public void setup() { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); @@ -65,7 +66,7 @@ public void setup() { cs.start(); } - @After + @AfterEach public void tearDown() { if (cs != null) { cs.stop(); @@ -94,7 +95,7 @@ public void testQueueMappingSpecifyingNotExistedQueue() { } catch (IOException ioex) { fail = true; } - Assert.assertTrue("queue initialization failed for non-existent q", fail); + Assertions.assertTrue(fail, "queue initialization failed for non-existent q"); } @Test @@ -117,28 +118,29 @@ public void testQueueMappingPathParsing() { .parsePathString("leaf") .build(); - Assert.assertEquals("leaf", leafOnly.getQueue()); - Assert.assertEquals(null, leafOnly.getParentQueue()); - Assert.assertEquals("leaf", leafOnly.getFullPath()); + Assertions.assertEquals("leaf", leafOnly.getQueue()); + Assertions.assertEquals(null, leafOnly.getParentQueue()); + Assertions.assertEquals("leaf", leafOnly.getFullPath()); QueueMapping twoLevels = QueueMapping.QueueMappingBuilder.create() .parsePathString("root.leaf") .build(); - Assert.assertEquals("leaf", twoLevels.getQueue()); - Assert.assertEquals("root", twoLevels.getParentQueue()); - Assert.assertEquals("root.leaf", twoLevels.getFullPath()); + Assertions.assertEquals("leaf", twoLevels.getQueue()); + Assertions.assertEquals("root", twoLevels.getParentQueue()); + Assertions.assertEquals("root.leaf", twoLevels.getFullPath()); QueueMapping deep = QueueMapping.QueueMappingBuilder.create() .parsePathString("root.a.b.c.d.e.leaf") .build(); - Assert.assertEquals("leaf", deep.getQueue()); - Assert.assertEquals("root.a.b.c.d.e", deep.getParentQueue()); - Assert.assertEquals("root.a.b.c.d.e.leaf", deep.getFullPath()); + Assertions.assertEquals("leaf", deep.getQueue()); + Assertions.assertEquals("root.a.b.c.d.e", deep.getParentQueue()); + Assertions.assertEquals("root.a.b.c.d.e.leaf", deep.getFullPath()); } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testQueueMappingParsingInvalidCases() throws Exception { // configuration parsing tests - negative test cases checkInvalidQMapping(conf, cs, "x:a:b", "invalid specifier"); @@ -163,7 +165,7 @@ private void checkInvalidQMapping(YarnConfiguration conf, } catch (IOException ex) { fail = true; } - Assert.assertTrue("invalid mapping did not throw exception for " + reason, - fail); + Assertions.assertTrue( + fail, "invalid mapping did not throw exception for " + reason); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueParsing.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueParsing.java index 65bce5c9318a8..c0e2e28b0b876 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueParsing.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueParsing.java @@ -39,9 +39,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.policy.PriorityUtilizationQueueOrderingPolicy; -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.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; @@ -49,6 +50,8 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestUtils.toSet; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assume.assumeThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestQueueParsing { @@ -99,7 +102,7 @@ public class TestQueueParsing { private RMNodeLabelsManager nodeLabelManager; - @Before + @BeforeEach public void setup() throws Exception{ YarnConfiguration conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -428,25 +431,27 @@ public void testQueueParsing() throws Exception { CapacityScheduler capacityScheduler = (CapacityScheduler) rm.getResourceScheduler(); CSQueue a = capacityScheduler.getQueue("a"); - Assert.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); CSQueue b1 = capacityScheduler.getQueue("b1"); - Assert.assertEquals(0.2 * 0.5, b1.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Parent B has no MAX_CAP", - 0.85, b1.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(0.2 * 0.5, b1.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals( + 0.85, b1.getAbsoluteMaximumCapacity(), DELTA, "Parent B has no MAX_CAP"); CSQueue c12 = capacityScheduler.getQueue("c12"); - Assert.assertEquals(0.7 * 0.5 * 0.45, c12.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.7 * 0.55 * 0.7, + Assertions.assertEquals(0.7 * 0.5 * 0.45, c12.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.7 * 0.55 * 0.7, c12.getAbsoluteMaximumCapacity(), DELTA); } - @Test (expected=java.lang.IllegalArgumentException.class) + @Test public void testRootQueueParsing() throws Exception { - CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); - // non-100 percent value will throw IllegalArgumentException - csConf.setCapacity(ROOT, 90); + assertThrows(IllegalArgumentException.class, ()->{ + CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); + // non-100 percent value will throw IllegalArgumentException + csConf.setCapacity(ROOT, 90); + }); } @Test @@ -483,42 +488,42 @@ public void testQueueParsingWithLabels() throws Exception { private void checkQueueLabels(CapacityScheduler capacityScheduler) { // queue-A is red, blue - Assert.assertTrue(capacityScheduler.getQueue("a").getAccessibleNodeLabels() + Assertions.assertTrue(capacityScheduler.getQueue("a").getAccessibleNodeLabels() .containsAll(ImmutableSet.of("red", "blue"))); // queue-A1 inherits A's configuration - Assert.assertTrue(capacityScheduler.getQueue("a1") + Assertions.assertTrue(capacityScheduler.getQueue("a1") .getAccessibleNodeLabels().containsAll(ImmutableSet.of("red", "blue"))); // queue-A2 is "red" - Assert.assertEquals(1, capacityScheduler.getQueue("a2") + Assertions.assertEquals(1, capacityScheduler.getQueue("a2") .getAccessibleNodeLabels().size()); - Assert.assertTrue(capacityScheduler.getQueue("a2") + Assertions.assertTrue(capacityScheduler.getQueue("a2") .getAccessibleNodeLabels().contains("red")); // queue-B is "red"/"blue" - Assert.assertTrue(capacityScheduler.getQueue("b").getAccessibleNodeLabels() + Assertions.assertTrue(capacityScheduler.getQueue("b").getAccessibleNodeLabels() .containsAll(ImmutableSet.of("red", "blue"))); // queue-B2 inherits "red"/"blue" - Assert.assertTrue(capacityScheduler.getQueue("b2") + Assertions.assertTrue(capacityScheduler.getQueue("b2") .getAccessibleNodeLabels().containsAll(ImmutableSet.of("red", "blue"))); // check capacity of A2 CSQueue qA2 = capacityScheduler.getQueue("a2"); - Assert.assertEquals(0.7, qA2.getCapacity(), DELTA); - Assert.assertEquals(0.5, qA2.getQueueCapacities().getCapacity("red"), DELTA); - Assert.assertEquals(0.07, qA2.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.25, qA2.getQueueCapacities().getAbsoluteCapacity("red"), DELTA); - Assert.assertEquals(0.1275, qA2.getAbsoluteMaximumCapacity(), DELTA); - Assert.assertEquals(0.3, qA2.getQueueCapacities().getAbsoluteMaximumCapacity("red"), DELTA); + Assertions.assertEquals(0.7, qA2.getCapacity(), DELTA); + Assertions.assertEquals(0.5, qA2.getQueueCapacities().getCapacity("red"), DELTA); + Assertions.assertEquals(0.07, qA2.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.25, qA2.getQueueCapacities().getAbsoluteCapacity("red"), DELTA); + Assertions.assertEquals(0.1275, qA2.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(0.3, qA2.getQueueCapacities().getAbsoluteMaximumCapacity("red"), DELTA); // check capacity of B3 CSQueue qB3 = capacityScheduler.getQueue("b3"); - Assert.assertEquals(0.18, qB3.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.125, qB3.getQueueCapacities().getAbsoluteCapacity("red"), DELTA); - Assert.assertEquals(0.35, qB3.getAbsoluteMaximumCapacity(), DELTA); - Assert.assertEquals(1, qB3.getQueueCapacities().getAbsoluteMaximumCapacity("red"), DELTA); + Assertions.assertEquals(0.18, qB3.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.125, qB3.getQueueCapacities().getAbsoluteCapacity("red"), DELTA); + Assertions.assertEquals(0.35, qB3.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(1, qB3.getQueueCapacities().getAbsoluteMaximumCapacity("red"), DELTA); } @Test @@ -538,64 +543,64 @@ public void testQueueParsingWithLeafQueueDisableElasticity() throws Exception { private void checkQueueLabelsWithLeafQueueDisableElasticity( CapacityScheduler capacityScheduler) { // queue-A is red, blue - Assert.assertTrue(capacityScheduler.getQueue("a").getAccessibleNodeLabels() + Assertions.assertTrue(capacityScheduler.getQueue("a").getAccessibleNodeLabels() .containsAll(ImmutableSet.of("red", "blue"))); // queue-A1 inherits A's configuration - Assert.assertTrue(capacityScheduler.getQueue("a1") + Assertions.assertTrue(capacityScheduler.getQueue("a1") .getAccessibleNodeLabels().containsAll(ImmutableSet.of("red", "blue"))); // queue-A2 is "red" - Assert.assertEquals(1, capacityScheduler.getQueue("a2") + Assertions.assertEquals(1, capacityScheduler.getQueue("a2") .getAccessibleNodeLabels().size()); - Assert.assertTrue(capacityScheduler.getQueue("a2") + Assertions.assertTrue(capacityScheduler.getQueue("a2") .getAccessibleNodeLabels().contains("red")); // queue-B is "red"/"blue" - Assert.assertTrue(capacityScheduler.getQueue("b").getAccessibleNodeLabels() + Assertions.assertTrue(capacityScheduler.getQueue("b").getAccessibleNodeLabels() .containsAll(ImmutableSet.of("red", "blue"))); // queue-B2 inherits "red"/"blue" - Assert.assertTrue(capacityScheduler.getQueue("b2") + Assertions.assertTrue(capacityScheduler.getQueue("b2") .getAccessibleNodeLabels().containsAll(ImmutableSet.of("red", "blue"))); // check capacity of A2 CSQueue qA2 = capacityScheduler.getQueue("a2"); - Assert.assertEquals(0.4, qA2.getCapacity(), DELTA); - Assert.assertEquals(0.4, qA2.getQueueCapacities() + Assertions.assertEquals(0.4, qA2.getCapacity(), DELTA); + Assertions.assertEquals(0.4, qA2.getQueueCapacities() .getCapacity("red"), DELTA); - Assert.assertEquals(0.2, qA2.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.2, qA2.getQueueCapacities() + Assertions.assertEquals(0.2, qA2.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.2, qA2.getQueueCapacities() .getAbsoluteCapacity("red"), DELTA); - Assert.assertEquals(0.85, qA2.getAbsoluteMaximumCapacity(), DELTA); - Assert.assertEquals(0.6, qA2.getQueueCapacities() + Assertions.assertEquals(0.85, qA2.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(0.6, qA2.getQueueCapacities() .getAbsoluteMaximumCapacity("red"), DELTA); // check disable elasticity at leaf queue level without label CSQueue qB2 = capacityScheduler.getQueue("b2"); - Assert.assertEquals(0.4, qB2.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.4, qB2.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(0.4, qB2.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.4, qB2.getAbsoluteMaximumCapacity(), DELTA); // check disable elasticity at leaf queue level with label CSQueue qA1 = capacityScheduler.getQueue("a1"); - Assert.assertEquals(0.3, qA1.getQueueCapacities(). + Assertions.assertEquals(0.3, qA1.getQueueCapacities(). getAbsoluteCapacity("red"), DELTA); - Assert.assertEquals(0.3, qA1.getQueueCapacities(). + Assertions.assertEquals(0.3, qA1.getQueueCapacities(). getAbsoluteMaximumCapacity("red"), DELTA); CSQueue qB1 = capacityScheduler.getQueue("b1"); - Assert.assertEquals(0.3, qB1.getQueueCapacities() + Assertions.assertEquals(0.3, qB1.getQueueCapacities() .getAbsoluteCapacity("red"), DELTA); - Assert.assertEquals(0.3, qB1.getQueueCapacities() + Assertions.assertEquals(0.3, qB1.getQueueCapacities() .getAbsoluteMaximumCapacity("red"), DELTA); // check capacity of B3 CSQueue qB3 = capacityScheduler.getQueue("b3"); - Assert.assertEquals(0.05, qB3.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.175, qB3.getQueueCapacities() + Assertions.assertEquals(0.05, qB3.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.175, qB3.getQueueCapacities() .getAbsoluteCapacity("blue"), DELTA); - Assert.assertEquals(0.25, qB3.getAbsoluteMaximumCapacity(), DELTA); - Assert.assertEquals(1, qB3.getQueueCapacities() + Assertions.assertEquals(0.25, qB3.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(1, qB3.getQueueCapacities() .getAbsoluteMaximumCapacity("blue"), DELTA); } @@ -615,21 +620,21 @@ public void testQueueParsingWithLabelsInherit() throws Exception { private void checkQueueLabelsInheritConfig(CapacityScheduler capacityScheduler) { // queue-A is red, blue - Assert.assertTrue(capacityScheduler.getQueue("a").getAccessibleNodeLabels() + Assertions.assertTrue(capacityScheduler.getQueue("a").getAccessibleNodeLabels() .containsAll(ImmutableSet.of("red", "blue"))); // queue-A1 inherits A's configuration - Assert.assertTrue(capacityScheduler.getQueue("a1") + Assertions.assertTrue(capacityScheduler.getQueue("a1") .getAccessibleNodeLabels().containsAll(ImmutableSet.of("red", "blue"))); // queue-A2 is "red" - Assert.assertEquals(1, capacityScheduler.getQueue("a2") + Assertions.assertEquals(1, capacityScheduler.getQueue("a2") .getAccessibleNodeLabels().size()); - Assert.assertTrue(capacityScheduler.getQueue("a2") + Assertions.assertTrue(capacityScheduler.getQueue("a2") .getAccessibleNodeLabels().contains("red")); // queue-B is "red"/"blue" - Assert.assertTrue(capacityScheduler.getQueue("b").getAccessibleNodeLabels() + Assertions.assertTrue(capacityScheduler.getQueue("b").getAccessibleNodeLabels() .isEmpty()); } @@ -699,21 +704,21 @@ public void testQueueParsingWithUnusedLabels() throws Exception { // check root queue's capacity by label -- they should be all zero CSQueue root = capacityScheduler.getQueue(CapacitySchedulerConfiguration.ROOT); - Assert.assertEquals(0, root.getQueueCapacities().getCapacity("red"), DELTA); - Assert.assertEquals(0, root.getQueueCapacities().getCapacity("blue"), DELTA); + Assertions.assertEquals(0, root.getQueueCapacities().getCapacity("red"), DELTA); + Assertions.assertEquals(0, root.getQueueCapacities().getCapacity("blue"), DELTA); CSQueue a = capacityScheduler.getQueue("a"); - Assert.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); CSQueue b1 = capacityScheduler.getQueue("b1"); - Assert.assertEquals(0.2 * 0.5, b1.getAbsoluteCapacity(), DELTA); - Assert.assertEquals("Parent B has no MAX_CAP", 0.85, - b1.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertEquals(0.2 * 0.5, b1.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.85, + b1.getAbsoluteMaximumCapacity(), DELTA, "Parent B has no MAX_CAP"); CSQueue c12 = capacityScheduler.getQueue("c12"); - Assert.assertEquals(0.7 * 0.5 * 0.45, c12.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.7 * 0.55 * 0.7, c12.getAbsoluteMaximumCapacity(), + Assertions.assertEquals(0.7 * 0.5 * 0.45, c12.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.7 * 0.55 * 0.7, c12.getAbsoluteMaximumCapacity(), DELTA); ServiceOperations.stopQuietly(rm); } @@ -729,14 +734,14 @@ public void testQueueParsingShouldTrimSpaces() throws Exception { CapacityScheduler capacityScheduler = (CapacityScheduler) rm.getResourceScheduler(); CSQueue a = capacityScheduler.getQueue("a"); - Assert.assertNotNull(a); - Assert.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(a); + Assertions.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); CSQueue c = capacityScheduler.getQueue("c"); - Assert.assertNotNull(c); - Assert.assertEquals(0.70, c.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.70, c.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(c); + Assertions.assertEquals(0.70, c.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.70, c.getAbsoluteMaximumCapacity(), DELTA); } @Test @@ -750,142 +755,156 @@ public void testNestedQueueParsingShouldTrimSpaces() throws Exception { CapacityScheduler capacityScheduler = (CapacityScheduler) rm.getResourceScheduler(); CSQueue a = capacityScheduler.getQueue("a"); - Assert.assertNotNull(a); - Assert.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(a); + Assertions.assertEquals(0.10, a.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.15, a.getAbsoluteMaximumCapacity(), DELTA); CSQueue c = capacityScheduler.getQueue("c"); - Assert.assertNotNull(c); - Assert.assertEquals(0.70, c.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.70, c.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(c); + Assertions.assertEquals(0.70, c.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.70, c.getAbsoluteMaximumCapacity(), DELTA); CSQueue a1 = capacityScheduler.getQueue("a1"); - Assert.assertNotNull(a1); - Assert.assertEquals(0.10 * 0.6, a1.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.15, a1.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(a1); + Assertions.assertEquals(0.10 * 0.6, a1.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.15, a1.getAbsoluteMaximumCapacity(), DELTA); CSQueue a2 = capacityScheduler.getQueue("a2"); - Assert.assertNotNull(a2); - Assert.assertEquals(0.10 * 0.4, a2.getAbsoluteCapacity(), DELTA); - Assert.assertEquals(0.15, a2.getAbsoluteMaximumCapacity(), DELTA); + Assertions.assertNotNull(a2); + Assertions.assertEquals(0.10 * 0.4, a2.getAbsoluteCapacity(), DELTA); + Assertions.assertEquals(0.15, a2.getAbsoluteMaximumCapacity(), DELTA); } /** * Test init a queue configuration, children's capacity for a given label * doesn't equals to 100%. This expect IllegalArgumentException thrown. */ - @Test(expected = ServiceStateException.class) + @Test public void testQueueParsingFailWhenSumOfChildrenNonLabeledCapacityNot100Percent() throws Exception { - CapacitySchedulerConfiguration csConf = - new CapacitySchedulerConfiguration(); - - // If the new queue mode is used it's allowed to leave - // some of the resources of a parent queue unallocated - assumeThat(csConf.isLegacyQueueMode(), is(true)); - setupQueueConfiguration(csConf); - csConf.setCapacity(C2, 5); - YarnConfiguration conf = new YarnConfiguration(csConf); - - MockRM rm = createMockRMWithLabels(conf, ImmutableSet.of("red", "blue")); - ServiceOperations.stopQuietly(rm); + assertThrows(ServiceStateException.class, ()->{ + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + + // If the new queue mode is used it's allowed to leave + // some of the resources of a parent queue unallocated + assumeThat(csConf.isLegacyQueueMode(), is(true)); + setupQueueConfiguration(csConf); + csConf.setCapacity(C2, 5); + YarnConfiguration conf = new YarnConfiguration(csConf); + + MockRM rm = createMockRMWithLabels(conf, ImmutableSet.of("red", "blue")); + ServiceOperations.stopQuietly(rm); + }); } /** * Test init a queue configuration, children's capacity for a given label * doesn't equals to 100%. This expect IllegalArgumentException thrown. */ - @Test(expected = ServiceStateException.class) + @Test public void testQueueParsingFailWhenSumOfChildrenLabeledCapacityNot100Percent() throws Exception { - CapacitySchedulerConfiguration csConf = - new CapacitySchedulerConfiguration(); - // If the new queue mode is used it's allowed to leave - // some of the resources of a parent queue unallocated - assumeThat(csConf.isLegacyQueueMode(), is(true)); + assertThrows(ServiceStateException.class, ()->{ + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + + // If the new queue mode is used it's allowed to leave + // some of the resources of a parent queue unallocated + assumeThat(csConf.isLegacyQueueMode(), is(true)); + + setupQueueConfigurationWithLabels(csConf); + csConf.setCapacityByLabel(B3, "red", 24); + YarnConfiguration conf = new YarnConfiguration(csConf); + + MockRM rm = createMockRMWithLabels(conf, ImmutableSet.of("red", "blue")); + ServiceOperations.stopQuietly(rm); + }); - setupQueueConfigurationWithLabels(csConf); - csConf.setCapacityByLabel(B3, "red", 24); - YarnConfiguration conf = new YarnConfiguration(csConf); - MockRM rm = createMockRMWithLabels(conf, ImmutableSet.of("red", "blue")); - ServiceOperations.stopQuietly(rm); } /** * Test init a queue configuration, children's capacity for a given label * doesn't equals to 100%. This expect IllegalArgumentException thrown. */ - @Test(expected = ServiceStateException.class) + @Test public void testQueueParsingWithSumOfChildLabelCapacityNot100PercentWithWildCard() throws Exception { - CapacitySchedulerConfiguration csConf = - new CapacitySchedulerConfiguration(); - - // If the new queue mode is used it's allowed to leave - // some of the resources of a parent queue unallocated - assumeThat(csConf.isLegacyQueueMode(), is(true)); - - setupQueueConfigurationWithLabels(csConf); - csConf.setCapacityByLabel(B3, "red", 24); - csConf.setAccessibleNodeLabels(ROOT, ImmutableSet.of(RMNodeLabelsManager.ANY)); - csConf.setAccessibleNodeLabels(B, ImmutableSet.of(RMNodeLabelsManager.ANY)); - YarnConfiguration conf = new YarnConfiguration(csConf); - - MockRM rm = createMockRMWithLabels(conf, ImmutableSet.of("red", "blue")); - ServiceOperations.stopQuietly(rm); + assertThrows(ServiceStateException.class, ()->{ + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + + // If the new queue mode is used it's allowed to leave + // some of the resources of a parent queue unallocated + assumeThat(csConf.isLegacyQueueMode(), is(true)); + + setupQueueConfigurationWithLabels(csConf); + csConf.setCapacityByLabel(B3, "red", 24); + csConf.setAccessibleNodeLabels(ROOT, ImmutableSet.of(RMNodeLabelsManager.ANY)); + csConf.setAccessibleNodeLabels(B, ImmutableSet.of(RMNodeLabelsManager.ANY)); + YarnConfiguration conf = new YarnConfiguration(csConf); + + MockRM rm = createMockRMWithLabels(conf, ImmutableSet.of("red", "blue")); + ServiceOperations.stopQuietly(rm); + }); } - @Test(expected = IOException.class) + @Test public void testQueueParsingWithMoveQueue() throws Exception { - CapacitySchedulerConfiguration csConf = - new CapacitySchedulerConfiguration(); - csConf.setQueues(ROOT, new String[] {"a"}); - csConf.setQueues(A, new String[] {"x", "y"}); - csConf.setCapacity(A, 100); - csConf.setCapacity(AX, 50); - csConf.setCapacity(AY, 50); - YarnConfiguration conf = new YarnConfiguration(csConf); - - MockRM rm = createMockRMWithoutLabels(conf); - CapacityScheduler capacityScheduler = (CapacityScheduler) rm.getResourceScheduler(); - - csConf.setQueues(ROOT, new String[] {"a", "x"}); - csConf.setQueues(A, new String[] {"y"}); - csConf.setCapacity(X, 50); - csConf.setCapacity(A, 50); - csConf.setCapacity(AY, 100); - - capacityScheduler.reinitialize(csConf, rm.getRMContext()); - ServiceOperations.stopQuietly(rm); + assertThrows(IOException.class, ()->{ + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + csConf.setQueues(ROOT, new String[] {"a"}); + csConf.setQueues(A, new String[] {"x", "y"}); + csConf.setCapacity(A, 100); + csConf.setCapacity(AX, 50); + csConf.setCapacity(AY, 50); + YarnConfiguration conf = new YarnConfiguration(csConf); + + MockRM rm = createMockRMWithoutLabels(conf); + CapacityScheduler capacityScheduler = (CapacityScheduler) rm.getResourceScheduler(); + + csConf.setQueues(ROOT, new String[] {"a", "x"}); + csConf.setQueues(A, new String[] {"y"}); + csConf.setCapacity(X, 50); + csConf.setCapacity(A, 50); + csConf.setCapacity(AY, 100); + + capacityScheduler.reinitialize(csConf, rm.getRMContext()); + ServiceOperations.stopQuietly(rm); + }); } - @Test(timeout = 60000, expected = ServiceStateException.class) + @Test + @Timeout(value = 60) public void testRMStartWrongNodeCapacity() throws Exception { - CapacitySchedulerConfiguration csConf = - new CapacitySchedulerConfiguration(); - Set labels = ImmutableSet.of("x", "y", "z"); - - // If the new queue mode is used it's allowed to leave - // some of the resources of a parent queue unallocated - assumeThat(csConf.isLegacyQueueMode(), is(true)); - - // Define top-level queues - csConf.setQueues(ROOT, new String[] {"a"}); - csConf.setCapacityByLabel(ROOT, "x", 100); - csConf.setCapacityByLabel(ROOT, "y", 100); - csConf.setCapacityByLabel(ROOT, "z", 100); - - csConf.setCapacity(A, 100); - csConf.setAccessibleNodeLabels(A, labels); - csConf.setCapacityByLabel(A, "x", 100); - csConf.setCapacityByLabel(A, "y", 100); - csConf.setCapacityByLabel(A, "z", 70); - - YarnConfiguration conf = new YarnConfiguration(csConf); - MockRM rm = createMockRMWithLabels(conf, labels); - ServiceOperations.stopQuietly(rm); + assertThrows(ServiceStateException.class, ()->{ + CapacitySchedulerConfiguration csConf = + new CapacitySchedulerConfiguration(); + Set labels = ImmutableSet.of("x", "y", "z"); + + // If the new queue mode is used it's allowed to leave + // some of the resources of a parent queue unallocated + assumeThat(csConf.isLegacyQueueMode(), is(true)); + + // Define top-level queues + csConf.setQueues(ROOT, new String[] {"a"}); + csConf.setCapacityByLabel(ROOT, "x", 100); + csConf.setCapacityByLabel(ROOT, "y", 100); + csConf.setCapacityByLabel(ROOT, "z", 100); + + csConf.setCapacity(A, 100); + csConf.setAccessibleNodeLabels(A, labels); + csConf.setCapacityByLabel(A, "x", 100); + csConf.setCapacityByLabel(A, "y", 100); + csConf.setCapacityByLabel(A, "z", 70); + + YarnConfiguration conf = new YarnConfiguration(csConf); + MockRM rm = createMockRMWithLabels(conf, labels); + ServiceOperations.stopQuietly(rm); + }); } @@ -920,7 +939,8 @@ public void testQueueOrderingPolicyUpdatedAfterReinitialize() throws Exception { ServiceOperations.stopQuietly(rm); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testQueueCapacityWithWeight() throws Exception { Set labels = ImmutableSet.of("x", "y", "z"); @@ -980,13 +1000,13 @@ public void testQueueParsingWithDefaultUserLimitValues() throws Exception { // Test CapacityScheduler capacityScheduler = (CapacityScheduler) rm.getResourceScheduler(); - Assert.assertEquals(15, + Assertions.assertEquals(15, ((LeafQueue)capacityScheduler.getQueue(A_PATH)).getUserLimit(), DELTA); - Assert.assertEquals(1.5, + Assertions.assertEquals(1.5, ((LeafQueue)capacityScheduler.getQueue(A_PATH)).getUserLimitFactor(), DELTA); - Assert.assertEquals(20, + Assertions.assertEquals(20, ((LeafQueue)capacityScheduler.getQueue(B_PATH)).getUserLimit(), DELTA); - Assert.assertEquals(2.0, + Assertions.assertEquals(2.0, ((LeafQueue)capacityScheduler.getQueue(B_PATH)).getUserLimitFactor(), DELTA); // Use hadoop default value @@ -1000,13 +1020,13 @@ public void testQueueParsingWithDefaultUserLimitValues() throws Exception { capacityScheduler.reinitialize(csConf, rm.getRMContext()); - Assert.assertEquals(15, + Assertions.assertEquals(15, ((LeafQueue)capacityScheduler.getQueue(A_PATH)).getUserLimit(), DELTA); - Assert.assertEquals(1.5, + Assertions.assertEquals(1.5, ((LeafQueue)capacityScheduler.getQueue(A_PATH)).getUserLimitFactor(), DELTA); - Assert.assertEquals(100, + Assertions.assertEquals(100, ((LeafQueue)capacityScheduler.getQueue(B_PATH)).getUserLimit(), DELTA); - Assert.assertEquals(1, + Assertions.assertEquals(1, ((LeafQueue)capacityScheduler.getQueue(B_PATH)).getUserLimitFactor(), DELTA); } @@ -1014,7 +1034,7 @@ private void verifyQueueAbsCapacity(MockRM rm, String queuePath, String label, float expectedAbsCapacity) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queuePath); - Assert.assertEquals(expectedAbsCapacity, + Assertions.assertEquals(expectedAbsCapacity, queue.getQueueCapacities().getAbsoluteCapacity(label), 1e-6); } @@ -1024,8 +1044,8 @@ private void checkEqualsToQueueSet(List queues, String[] queueNames) { existedQueues.add(q.getQueueShortName()); } for (String q : queueNames) { - Assert.assertTrue(existedQueues.remove(q)); + Assertions.assertTrue(existedQueues.remove(q)); } - Assert.assertTrue(existedQueues.isEmpty()); + Assertions.assertTrue(existedQueues.isEmpty()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueuePath.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueuePath.java index dc6437930676d..968ae6fed34df 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueuePath.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueuePath.java @@ -19,8 +19,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -41,34 +41,34 @@ public class TestQueuePath { @Test public void testCreation() { - Assert.assertEquals(TEST_QUEUE, TEST_QUEUE_PATH.getFullPath()); - Assert.assertEquals("root.level_1.level_2", TEST_QUEUE_PATH.getParent()); - Assert.assertEquals("level_3", TEST_QUEUE_PATH.getLeafName()); + Assertions.assertEquals(TEST_QUEUE, TEST_QUEUE_PATH.getFullPath()); + Assertions.assertEquals("root.level_1.level_2", TEST_QUEUE_PATH.getParent()); + Assertions.assertEquals("level_3", TEST_QUEUE_PATH.getLeafName()); - Assert.assertNull(ROOT_PATH.getParent()); + Assertions.assertNull(ROOT_PATH.getParent()); QueuePath appendedPath = TEST_QUEUE_PATH.createNewLeaf("level_4"); - Assert.assertEquals(TEST_QUEUE + CapacitySchedulerConfiguration.DOT + Assertions.assertEquals(TEST_QUEUE + CapacitySchedulerConfiguration.DOT + "level_4", appendedPath.getFullPath()); - Assert.assertEquals("root.level_1.level_2.level_3", appendedPath.getParent()); - Assert.assertEquals("level_4", appendedPath.getLeafName()); + Assertions.assertEquals("root.level_1.level_2.level_3", appendedPath.getParent()); + Assertions.assertEquals("level_4", appendedPath.getLeafName()); } @Test public void testEmptyPart() { - Assert.assertTrue(QUEUE_PATH_WITH_EMPTY_PART.hasEmptyPart()); - Assert.assertTrue(QUEUE_PATH_WITH_EMPTY_LEAF.hasEmptyPart()); - Assert.assertFalse(TEST_QUEUE_PATH.hasEmptyPart()); + Assertions.assertTrue(QUEUE_PATH_WITH_EMPTY_PART.hasEmptyPart()); + Assertions.assertTrue(QUEUE_PATH_WITH_EMPTY_LEAF.hasEmptyPart()); + Assertions.assertFalse(TEST_QUEUE_PATH.hasEmptyPart()); } @Test public void testNullPath() { QueuePath queuePathWithNullPath = new QueuePath(null); - Assert.assertNull(queuePathWithNullPath.getParent()); - Assert.assertEquals("", queuePathWithNullPath.getLeafName()); - Assert.assertEquals("", queuePathWithNullPath.getFullPath()); - Assert.assertFalse(queuePathWithNullPath.isRoot()); + Assertions.assertNull(queuePathWithNullPath.getParent()); + Assertions.assertEquals("", queuePathWithNullPath.getLeafName()); + Assertions.assertEquals("", queuePathWithNullPath.getFullPath()); + Assertions.assertFalse(queuePathWithNullPath.isRoot()); } @Test @@ -78,17 +78,17 @@ public void testIterator() { QUEUE_PATH_WITH_EMPTY_PART.iterator()); List rootPathCollection = ImmutableList.copyOf(ROOT_PATH.iterator()); - Assert.assertEquals(4, queuePathCollection.size()); - Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, queuePathCollection.get(0)); - Assert.assertEquals("level_3", queuePathCollection.get(3)); + Assertions.assertEquals(4, queuePathCollection.size()); + Assertions.assertEquals(CapacitySchedulerConfiguration.ROOT, queuePathCollection.get(0)); + Assertions.assertEquals("level_3", queuePathCollection.get(3)); - Assert.assertEquals(3, queuePathWithEmptyPartCollection.size()); - Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, + Assertions.assertEquals(3, queuePathWithEmptyPartCollection.size()); + Assertions.assertEquals(CapacitySchedulerConfiguration.ROOT, queuePathWithEmptyPartCollection.get(0)); - Assert.assertEquals("level_2", queuePathWithEmptyPartCollection.get(2)); + Assertions.assertEquals("level_2", queuePathWithEmptyPartCollection.get(2)); - Assert.assertEquals(1, rootPathCollection.size()); - Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, rootPathCollection.get(0)); + Assertions.assertEquals(1, rootPathCollection.size()); + Assertions.assertEquals(CapacitySchedulerConfiguration.ROOT, rootPathCollection.get(0)); } @Test @@ -98,18 +98,18 @@ public void testReversePathIterator() { QUEUE_PATH_WITH_EMPTY_PART.reverseIterator()); List rootPathCollection = ImmutableList.copyOf(ROOT_PATH.reverseIterator()); - Assert.assertEquals(4, queuePathCollection.size()); - Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, + Assertions.assertEquals(4, queuePathCollection.size()); + Assertions.assertEquals(CapacitySchedulerConfiguration.ROOT, queuePathCollection.get(3)); - Assert.assertEquals(TEST_QUEUE, queuePathCollection.get(0)); + Assertions.assertEquals(TEST_QUEUE, queuePathCollection.get(0)); - Assert.assertEquals(3, queuePathWithEmptyPartCollection.size()); - Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, + Assertions.assertEquals(3, queuePathWithEmptyPartCollection.size()); + Assertions.assertEquals(CapacitySchedulerConfiguration.ROOT, queuePathWithEmptyPartCollection.get(2)); - Assert.assertEquals("root..level_2", queuePathWithEmptyPartCollection.get(0)); + Assertions.assertEquals("root..level_2", queuePathWithEmptyPartCollection.get(0)); - Assert.assertEquals(1, rootPathCollection.size()); - Assert.assertEquals(CapacitySchedulerConfiguration.ROOT, + Assertions.assertEquals(1, rootPathCollection.size()); + Assertions.assertEquals(CapacitySchedulerConfiguration.ROOT, rootPathCollection.get(0)); } @@ -121,33 +121,33 @@ public void testEquals() { QueuePath empty = new QueuePath(""); QueuePath emptySame = new QueuePath(""); - Assert.assertEquals(queuePath, queuePathSame); - Assert.assertEquals(empty, emptySame); - Assert.assertNotEquals(null, queuePath); + Assertions.assertEquals(queuePath, queuePathSame); + Assertions.assertEquals(empty, emptySame); + Assertions.assertNotEquals(null, queuePath); } @Test public void testInvalidPath() { - Assert.assertFalse(TEST_QUEUE_PATH.isInvalid()); - Assert.assertFalse(ROOT_PATH.isInvalid()); - Assert.assertTrue(EMPTY_PATH.isInvalid()); - Assert.assertTrue(new QueuePath("invalidPath").isInvalid()); + Assertions.assertFalse(TEST_QUEUE_PATH.isInvalid()); + Assertions.assertFalse(ROOT_PATH.isInvalid()); + Assertions.assertTrue(EMPTY_PATH.isInvalid()); + Assertions.assertTrue(new QueuePath("invalidPath").isInvalid()); } @Test public void testGetParentObject() { - Assert.assertEquals(new QueuePath("root.level_1.level_2"), + Assertions.assertEquals(new QueuePath("root.level_1.level_2"), TEST_QUEUE_PATH.getParentObject()); - Assert.assertEquals(ROOT_PATH, new QueuePath("root.level_1").getParentObject()); - Assert.assertNull(ROOT_PATH.getParentObject()); + Assertions.assertEquals(ROOT_PATH, new QueuePath("root.level_1").getParentObject()); + Assertions.assertNull(ROOT_PATH.getParentObject()); } @Test public void testGetPathComponents() { - Assert.assertArrayEquals(TEST_QUEUE_PATH.getPathComponents(), + Assertions.assertArrayEquals(TEST_QUEUE_PATH.getPathComponents(), new String[] {"root", "level_1", "level_2", "level_3"}); - Assert.assertArrayEquals(ROOT_PATH.getPathComponents(), new String[] {"root"}); - Assert.assertArrayEquals(EMPTY_PATH.getPathComponents(), new String[] {""}); + Assertions.assertArrayEquals(ROOT_PATH.getPathComponents(), new String[] {"root"}); + Assertions.assertArrayEquals(EMPTY_PATH.getPathComponents(), new String[] {""}); } @Test @@ -161,7 +161,7 @@ public void testWildcardedQueuePathsWithOneLevelWildCard() { List wildcardedPaths = TEST_QUEUE_PATH .getWildcardedQueuePaths(maxAutoCreatedQueueDepth); - Assert.assertEquals(expectedPaths, wildcardedPaths); + Assertions.assertEquals(expectedPaths, wildcardedPaths); } @Test @@ -176,7 +176,7 @@ public void testWildcardedQueuePathsWithTwoLevelWildCard() { List wildcardedPaths = TEST_QUEUE_PATH .getWildcardedQueuePaths(maxAutoCreatedQueueDepth); - Assert.assertEquals(expectedPaths, wildcardedPaths); + Assertions.assertEquals(expectedPaths, wildcardedPaths); } @Test @@ -192,7 +192,7 @@ public void testWildcardedQueuePathsWithThreeLevelWildCard() { List wildcardedPaths = TEST_QUEUE_PATH .getWildcardedQueuePaths(maxAutoCreatedQueueDepth); - Assert.assertEquals(expectedPaths, wildcardedPaths); + Assertions.assertEquals(expectedPaths, wildcardedPaths); } @Test @@ -208,7 +208,7 @@ public void testWildcardingWhenMaxACQDepthIsGreaterThanQueuePathDepth() { List wildcardedPaths = TEST_QUEUE_PATH .getWildcardedQueuePaths(maxAutoCreatedQueueDepth); - Assert.assertEquals(expectedPaths, wildcardedPaths); + Assertions.assertEquals(expectedPaths, wildcardedPaths); } @Test @@ -220,6 +220,6 @@ public void testWildcardedQueuePathsWithRootPath() { List wildcardedPaths = ROOT_PATH.getWildcardedQueuePaths(maxAutoCreatedQueueDepth); - Assert.assertEquals(expectedPaths, wildcardedPaths); + Assertions.assertEquals(expectedPaths, wildcardedPaths); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueState.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueState.java index 482f7f332b48c..f318cf78d2b9f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueState.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueState.java @@ -41,8 +41,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; import org.apache.hadoop.yarn.util.resource.Resources; -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; /** * Test Queue States. @@ -65,7 +66,8 @@ public class TestQueueState { private CapacityScheduler cs; private YarnConfiguration conf; - @Test (timeout = 15000) + @Test + @Timeout(value = 15) public void testQueueState() throws IOException { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); @@ -84,16 +86,16 @@ public void testQueueState() throws IOException { cs.init(conf); //by default, the state of both queues should be RUNNING - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); // Change the state of Q1 to STOPPED, and re-initiate the CS csConf.setState(Q1_PATH, QueueState.STOPPED); conf = new YarnConfiguration(csConf); cs.reinitialize(conf, rmContext); // The state of Q1 and its child: Q2 should be STOPPED - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); // Change the state of Q1 to RUNNING, and change the state of Q2 to STOPPED csConf.setState(Q1_PATH, QueueState.RUNNING); @@ -101,8 +103,8 @@ public void testQueueState() throws IOException { conf = new YarnConfiguration(csConf); // reinitialize the CS, the operation should be successful cs.reinitialize(conf, rmContext); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); // Change the state of Q1 to STOPPED, and change the state of Q2 to RUNNING csConf.setState(Q1_PATH, QueueState.STOPPED); @@ -111,15 +113,16 @@ public void testQueueState() throws IOException { // reinitialize the CS, the operation should be failed. try { cs.reinitialize(conf, rmContext); - Assert.fail("Should throw an Exception."); + Assertions.fail("Should throw an Exception."); } catch (Exception ex) { - Assert.assertTrue(ex.getCause().getMessage().contains( + Assertions.assertTrue(ex.getCause().getMessage().contains( "The parent queue:root.q1 cannot be STOPPED as the child" + " queue:root.q1.q2 is in RUNNING state.")); } } - @Test(timeout = 15000) + @Test + @Timeout(value = 15) public void testQueueStateTransit() throws Exception { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); @@ -139,9 +142,9 @@ public void testQueueStateTransit() throws Exception { cs.init(conf); //by default, the state of ALL queues should be RUNNING - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); // submit an application to Q2 ApplicationId appId = ApplicationId.newInstance( @@ -156,41 +159,41 @@ public void testQueueStateTransit() throws Exception { csConf.setState(Q2_PATH, QueueState.STOPPED); conf = new YarnConfiguration(csConf); cs.reinitialize(conf, rmContext); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.DRAINING, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.DRAINING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); // set Q2 state to RUNNING and do reinitialize. // Q2 should transit from DRAINING to RUNNING csConf.setState(Q2_PATH, QueueState.RUNNING); conf = new YarnConfiguration(csConf); cs.reinitialize(conf, rmContext); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); // set Q2 state to stop and do reinitialize. csConf.setState(Q2_PATH, QueueState.STOPPED); conf = new YarnConfiguration(csConf); cs.reinitialize(conf, rmContext); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.DRAINING, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.DRAINING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); // set Q1 state to stop and do reinitialize. csConf.setState(Q1_PATH, QueueState.STOPPED); conf = new YarnConfiguration(csConf); cs.reinitialize(conf, rmContext); - Assert.assertEquals(QueueState.DRAINING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.DRAINING, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.DRAINING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.DRAINING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); // Active Q3, should fail csConf.setState(Q3_PATH, QueueState.RUNNING); conf = new YarnConfiguration(csConf); try { cs.reinitialize(conf, rmContext); - Assert.fail("Should throw an Exception."); + Assertions.fail("Should throw an Exception."); } catch (Exception ex) { // Do Nothing } @@ -198,9 +201,9 @@ public void testQueueStateTransit() throws Exception { // stop the app running in q2 cs.getQueue(Q2).finishApplicationAttempt(app, Q2); cs.getQueue(Q2).finishApplication(appId, userName); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); } @@ -225,7 +228,8 @@ private FiCaSchedulerApp getMockApplication(ApplicationId appId, String user, return application; } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testRecoverDrainingStateAfterRMRestart() throws Exception { // init conf CapacitySchedulerConfiguration newConf = @@ -266,9 +270,9 @@ public void testRecoverDrainingStateAfterRMRestart() throws Exception { (CapacityScheduler) rm.getRMContext().getScheduler(); capacityScheduler.reinitialize(newConf, rm.getRMContext()); // current queue state should be DRAINING - Assert.assertEquals(QueueState.DRAINING, + Assertions.assertEquals(QueueState.DRAINING, capacityScheduler.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.DRAINING, + Assertions.assertEquals(QueueState.DRAINING, capacityScheduler.getQueue(Q1).getState()); // RM restart @@ -279,9 +283,9 @@ public void testRecoverDrainingStateAfterRMRestart() throws Exception { // queue state should be DRAINING after app recovered rm.waitForState(app.getApplicationId(), RMAppState.ACCEPTED); capacityScheduler = (CapacityScheduler) rm.getRMContext().getScheduler(); - Assert.assertEquals(QueueState.DRAINING, + Assertions.assertEquals(QueueState.DRAINING, capacityScheduler.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.DRAINING, + Assertions.assertEquals(QueueState.DRAINING, capacityScheduler.getQueue(Q1).getState()); // close rm diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueStateManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueStateManager.java index 27ae3c3ae0187..3212248acb721 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueStateManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestQueueStateManager.java @@ -35,8 +35,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueStateManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Test QueueStateManager. @@ -86,44 +86,44 @@ public void testQueueStateManager() throws AccessControlException, .getQueueStateManager(); //by default, the state of both queues should be RUNNING - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); // Stop Q2, and verify that Q2 transmits to STOPPED STATE stateManager.stopQueue(Q2); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); // Stop Q1, and verify that Q1, as well as its child: Q3, // transmits to STOPPED STATE stateManager.stopQueue(Q1); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); - Assert.assertTrue(stateManager.canDelete(Q1)); - Assert.assertTrue(stateManager.canDelete(Q2)); - Assert.assertTrue(stateManager.canDelete(Q3)); + Assertions.assertTrue(stateManager.canDelete(Q1)); + Assertions.assertTrue(stateManager.canDelete(Q2)); + Assertions.assertTrue(stateManager.canDelete(Q3)); // Active Q2, it will fail. - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); // Now active Q1 stateManager.activateQueue(Q1); // Q1 should be in RUNNING state. Its children: Q2 and Q3 // should still be in STOPPED state. - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); // Now active Q2 and Q3 stateManager.activateQueue(Q2); stateManager.activateQueue(Q3); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.RUNNING, cs.getQueue(Q3).getState()); - Assert.assertFalse(stateManager.canDelete(Q1)); - Assert.assertFalse(stateManager.canDelete(Q2)); - Assert.assertFalse(stateManager.canDelete(Q3)); + Assertions.assertFalse(stateManager.canDelete(Q1)); + Assertions.assertFalse(stateManager.canDelete(Q2)); + Assertions.assertFalse(stateManager.canDelete(Q3)); ApplicationId appId = ApplicationId.newInstance( System.currentTimeMillis(), 1); @@ -134,15 +134,15 @@ public void testQueueStateManager() throws AccessControlException, cs.getQueue(Q2).submitApplicationAttempt(app, userName); stateManager.stopQueue(Q1); - Assert.assertEquals(QueueState.DRAINING, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.DRAINING, cs.getQueue(Q2).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); + Assertions.assertEquals(QueueState.DRAINING, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.DRAINING, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q3).getState()); cs.getQueue(Q2).finishApplicationAttempt(app, Q2); cs.getQueue(Q2).finishApplication(appId, userName); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q1).getState()); - Assert.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q1).getState()); + Assertions.assertEquals(QueueState.STOPPED, cs.getQueue(Q2).getState()); } private FiCaSchedulerApp getMockApplication(ApplicationId appId, String user, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservationQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservationQueue.java index dbda44c86a18b..9ea078eb1ac4e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservationQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservationQueue.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import static org.junit.Assert.assertEquals; -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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -38,8 +38,8 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; 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; /** * Test class for dynamic auto created leaf queues. @@ -58,7 +58,7 @@ public class TestReservationQueue { private PlanQueue planQueue; private final Resource clusterResource = Resources.createResource(100 * 16 * GB, 100 * 32); - @Before + @BeforeEach public void setup() throws IOException, SchedulerDynamicEditException { // setup a context / conf csConf = new CapacitySchedulerConfiguration(); @@ -97,8 +97,8 @@ public void setup() throws IOException, SchedulerDynamicEditException { } private void validateAutoCreatedLeafQueue(double capacity) { - assertTrue(" actual capacity: " + autoCreatedLeafQueue.getCapacity(), - autoCreatedLeafQueue.getCapacity() - capacity < CSQueueUtils.EPSILON); + assertTrue( + autoCreatedLeafQueue.getCapacity() - capacity < CSQueueUtils.EPSILON, " actual capacity: " + autoCreatedLeafQueue.getCapacity()); assertEquals(autoCreatedLeafQueue.maxApplications, DEF_MAX_APPS); assertEquals(autoCreatedLeafQueue.maxApplicationsPerUser, DEF_MAX_APPS); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java index ceab609f9e1fa..fa979e78dda9f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestReservations.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -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.doNothing; import static org.mockito.Mockito.doReturn; @@ -33,7 +33,7 @@ import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.event.Level; @@ -71,8 +71,8 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; 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.Mockito; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestUtils.toSchedulerKey; @@ -101,14 +101,14 @@ public class TestReservations { final static int GB = 1024; final static String DEFAULT_RACK = "/default"; - @Before + @BeforeEach public void setUp() throws Exception { CapacityScheduler spyCs = new CapacityScheduler(); cs = spy(spyCs); rmContext = TestUtils.getMockRMContext(); } - @After + @AfterEach public void tearDown() { if (cs != null) { cs.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/scheduler/capacity/TestResourceVector.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestResourceVector.java index c56b37dc99081..75f2bcd94b126 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestResourceVector.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestResourceVector.java @@ -21,9 +21,9 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.conf.YarnConfiguration; 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 java.util.HashMap; import java.util.Map; @@ -37,7 +37,7 @@ public class TestResourceVector { private final YarnConfiguration conf = new YarnConfiguration(); - @Before + @BeforeEach public void setUp() { conf.set(YarnConfiguration.RESOURCE_TYPES, CUSTOM_RESOURCE); ResourceUtils.resetResourceTypes(conf); @@ -46,22 +46,22 @@ public void setUp() { @Test public void testCreation() { ResourceVector zeroResourceVector = ResourceVector.newInstance(); - Assert.assertEquals(0, zeroResourceVector.getValue(MEMORY_URI), EPSILON); - Assert.assertEquals(0, zeroResourceVector.getValue(VCORES_URI), EPSILON); - Assert.assertEquals(0, zeroResourceVector.getValue(CUSTOM_RESOURCE), EPSILON); + Assertions.assertEquals(0, zeroResourceVector.getValue(MEMORY_URI), EPSILON); + Assertions.assertEquals(0, zeroResourceVector.getValue(VCORES_URI), EPSILON); + Assertions.assertEquals(0, zeroResourceVector.getValue(CUSTOM_RESOURCE), EPSILON); ResourceVector uniformResourceVector = ResourceVector.of(10); - Assert.assertEquals(10, uniformResourceVector.getValue(MEMORY_URI), EPSILON); - Assert.assertEquals(10, uniformResourceVector.getValue(VCORES_URI), EPSILON); - Assert.assertEquals(10, uniformResourceVector.getValue(CUSTOM_RESOURCE), EPSILON); + Assertions.assertEquals(10, uniformResourceVector.getValue(MEMORY_URI), EPSILON); + Assertions.assertEquals(10, uniformResourceVector.getValue(VCORES_URI), EPSILON); + Assertions.assertEquals(10, uniformResourceVector.getValue(CUSTOM_RESOURCE), EPSILON); Map customResources = new HashMap<>(); customResources.put(CUSTOM_RESOURCE, 2L); Resource resource = Resource.newInstance(10, 5, customResources); ResourceVector resourceVectorFromResource = ResourceVector.of(resource); - Assert.assertEquals(10, resourceVectorFromResource.getValue(MEMORY_URI), EPSILON); - Assert.assertEquals(5, resourceVectorFromResource.getValue(VCORES_URI), EPSILON); - Assert.assertEquals(2, resourceVectorFromResource.getValue(CUSTOM_RESOURCE), EPSILON); + Assertions.assertEquals(10, resourceVectorFromResource.getValue(MEMORY_URI), EPSILON); + Assertions.assertEquals(5, resourceVectorFromResource.getValue(VCORES_URI), EPSILON); + Assertions.assertEquals(2, resourceVectorFromResource.getValue(CUSTOM_RESOURCE), EPSILON); } @Test @@ -70,17 +70,17 @@ public void testSubtract() { ResourceVector rhsResourceVector = ResourceVector.of(5); lhsResourceVector.decrement(rhsResourceVector); - Assert.assertEquals(8, lhsResourceVector.getValue(MEMORY_URI), EPSILON); - Assert.assertEquals(8, lhsResourceVector.getValue(VCORES_URI), EPSILON); - Assert.assertEquals(8, lhsResourceVector.getValue(CUSTOM_RESOURCE), EPSILON); + Assertions.assertEquals(8, lhsResourceVector.getValue(MEMORY_URI), EPSILON); + Assertions.assertEquals(8, lhsResourceVector.getValue(VCORES_URI), EPSILON); + Assertions.assertEquals(8, lhsResourceVector.getValue(CUSTOM_RESOURCE), EPSILON); ResourceVector negativeResourceVector = ResourceVector.of(-100); // Check whether overflow causes any issues negativeResourceVector.decrement(ResourceVector.of(Float.MAX_VALUE)); - Assert.assertEquals(-Float.MAX_VALUE, negativeResourceVector.getValue(MEMORY_URI), EPSILON); - Assert.assertEquals(-Float.MAX_VALUE, negativeResourceVector.getValue(VCORES_URI), EPSILON); - Assert.assertEquals(-Float.MAX_VALUE, negativeResourceVector.getValue(CUSTOM_RESOURCE), + Assertions.assertEquals(-Float.MAX_VALUE, negativeResourceVector.getValue(MEMORY_URI), EPSILON); + Assertions.assertEquals(-Float.MAX_VALUE, negativeResourceVector.getValue(VCORES_URI), EPSILON); + Assertions.assertEquals(-Float.MAX_VALUE, negativeResourceVector.getValue(CUSTOM_RESOURCE), EPSILON); } @@ -90,14 +90,14 @@ public void testIncrement() { ResourceVector resourceVector = ResourceVector.of(13); resourceVector.increment(MEMORY_URI, 5); - Assert.assertEquals(18, resourceVector.getValue(MEMORY_URI), EPSILON); - Assert.assertEquals(13, resourceVector.getValue(VCORES_URI), EPSILON); - Assert.assertEquals(13, resourceVector.getValue(CUSTOM_RESOURCE), EPSILON); + Assertions.assertEquals(18, resourceVector.getValue(MEMORY_URI), EPSILON); + Assertions.assertEquals(13, resourceVector.getValue(VCORES_URI), EPSILON); + Assertions.assertEquals(13, resourceVector.getValue(CUSTOM_RESOURCE), EPSILON); // Check whether overflow causes any issues ResourceVector maxFloatResourceVector = ResourceVector.of(Float.MAX_VALUE); maxFloatResourceVector.increment(MEMORY_URI, 100); - Assert.assertEquals(Float.MAX_VALUE, maxFloatResourceVector.getValue(MEMORY_URI), EPSILON); + Assertions.assertEquals(Float.MAX_VALUE, maxFloatResourceVector.getValue(MEMORY_URI), EPSILON); } @Test @@ -106,13 +106,13 @@ public void testEquals() { ResourceVector resourceVectorOther = ResourceVector.of(14); Resource resource = Resource.newInstance(13, 13); - Assert.assertNotEquals(null, resourceVector); - Assert.assertNotEquals(resourceVectorOther, resourceVector); - Assert.assertNotEquals(resource, resourceVector); + Assertions.assertNotEquals(null, resourceVector); + Assertions.assertNotEquals(resourceVectorOther, resourceVector); + Assertions.assertNotEquals(resource, resourceVector); ResourceVector resourceVectorOne = ResourceVector.of(1); resourceVectorOther.decrement(resourceVectorOne); - Assert.assertEquals(resourceVectorOther, resourceVector); + Assertions.assertEquals(resourceVectorOther, resourceVector); } } \ 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/scheduler/capacity/TestSchedulingRequestContainerAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestSchedulingRequestContainerAllocation.java index a9b4c3c8f9556..c13466be13a32 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestSchedulingRequestContainerAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestSchedulingRequestContainerAllocation.java @@ -50,9 +50,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; -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.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @@ -99,7 +100,7 @@ public TestSchedulingRequestContainerAllocation( this.placementConstraintHandler = placementConstraintHandler; } - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -126,7 +127,8 @@ private RMApp submitApp(MockRM rm, int memory, Set appTags) return MockRMAppSubmitter.submit(rm, data); } - @Test(timeout = 30000L) + @Test + @Timeout(30) public void testIntraAppAntiAffinity() throws Exception { Configuration csConf = TestUtils.getConfigurationWithMultipleQueues(conf); @@ -168,8 +170,8 @@ public RMNodeLabelsManager createNodeLabelManager() { Priority.newInstance(1), 1L, ImmutableSet.of("mapper"), "mapper"); List allocated = waitForAllocation(4, 3000, am1, nms); - Assert.assertEquals(4, allocated.size()); - Assert.assertEquals(4, getContainerNodesNum(allocated)); + Assertions.assertEquals(4, allocated.size()); + Assertions.assertEquals(4, getContainerNodesNum(allocated)); // Similarly, app1 asks 10 anti-affinity containers at different priority, // it should be satisfied as well. @@ -180,8 +182,8 @@ public RMNodeLabelsManager createNodeLabelManager() { Priority.newInstance(2), 1L, ImmutableSet.of("reducer"), "reducer"); allocated = waitForAllocation(4, 3000, am1, nms); - Assert.assertEquals(4, allocated.size()); - Assert.assertEquals(4, getContainerNodesNum(allocated)); + Assertions.assertEquals(4, allocated.size()); + Assertions.assertEquals(4, getContainerNodesNum(allocated)); // Test anti-affinity to both of "mapper/reducer", we should only get no // container allocated @@ -195,12 +197,13 @@ public RMNodeLabelsManager createNodeLabelManager() { } catch (Exception e) { caughtException = true; } - Assert.assertTrue(caughtException); + Assertions.assertTrue(caughtException); rm1.close(); } - @Test(timeout = 30000L) + @Test + @Timeout(30) public void testIntraAppAntiAffinityWithMultipleTags() throws Exception { Configuration csConf = TestUtils.getConfigurationWithMultipleQueues(conf); @@ -242,8 +245,8 @@ public RMNodeLabelsManager createNodeLabelManager() { "tag_1_1", "tag_1_2"); List allocated = waitForAllocation(2, 3000, am1, nms); - Assert.assertEquals(2, allocated.size()); - Assert.assertEquals(2, getContainerNodesNum(allocated)); + Assertions.assertEquals(2, allocated.size()); + Assertions.assertEquals(2, getContainerNodesNum(allocated)); // app1 asks for 1 anti-affinity containers for the same app. anti-affinity // to tag_1_1/tag_1_2. With allocation_tag = tag_2_1/tag_2_2 @@ -253,9 +256,9 @@ public RMNodeLabelsManager createNodeLabelManager() { "tag_1_1", "tag_1_2"); List allocated1 = waitForAllocation(1, 3000, am1, nms); - Assert.assertEquals(1, allocated1.size()); + Assertions.assertEquals(1, allocated1.size()); allocated.addAll(allocated1); - Assert.assertEquals(3, getContainerNodesNum(allocated)); + Assertions.assertEquals(3, getContainerNodesNum(allocated)); // app1 asks for 1 anti-affinity containers for the same app. anti-affinity // to tag_1_1/tag_1_2/tag_2_1/tag_2_2. With allocation_tag = tag_3 @@ -265,9 +268,9 @@ public RMNodeLabelsManager createNodeLabelManager() { "tag_1_1", "tag_1_2", "tag_2_1", "tag_2_2"); allocated1 = waitForAllocation(1, 3000, am1, nms); - Assert.assertEquals(1, allocated1.size()); + Assertions.assertEquals(1, allocated1.size()); allocated.addAll(allocated1); - Assert.assertEquals(4, getContainerNodesNum(allocated)); + Assertions.assertEquals(4, getContainerNodesNum(allocated)); rm1.close(); } @@ -278,7 +281,8 @@ public RMNodeLabelsManager createNodeLabelManager() { * types, see more in TestPlacementConstraintsUtil. * @throws Exception */ - @Test(timeout = 30000L) + @Test + @Timeout(30) public void testInterAppAntiAffinity() throws Exception { Configuration csConf = TestUtils.getConfigurationWithMultipleQueues(conf); @@ -320,8 +324,8 @@ public RMNodeLabelsManager createNodeLabelManager() { Priority.newInstance(1), 1L, ImmutableSet.of("mapper"), "mapper"); List allocated = waitForAllocation(3, 3000, am1, nms); - Assert.assertEquals(3, allocated.size()); - Assert.assertEquals(3, getContainerNodesNum(allocated)); + Assertions.assertEquals(3, allocated.size()); + Assertions.assertEquals(3, getContainerNodesNum(allocated)); System.out.println("Mappers on HOST0: " + rmNodes[0].getAllocationTagsWithCount().get("mapper")); @@ -353,10 +357,10 @@ public RMNodeLabelsManager createNodeLabelManager() { ImmutableSet.of("foo"), "mapper"); List allocated1 = waitForAllocation(3, 3000, am2, nms); - Assert.assertEquals(3, allocated1.size()); - Assert.assertEquals(1, getContainerNodesNum(allocated1)); + Assertions.assertEquals(3, allocated1.size()); + Assertions.assertEquals(1, getContainerNodesNum(allocated1)); allocated.addAll(allocated1); - Assert.assertEquals(4, getContainerNodesNum(allocated)); + Assertions.assertEquals(4, getContainerNodesNum(allocated)); CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); @@ -364,7 +368,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am2.getApplicationAttemptId()); // The allocated node should not have mapper tag. - Assert.assertTrue(schedulerApp2.getLiveContainers() + Assertions.assertTrue(schedulerApp2.getLiveContainers() .stream().allMatch(rmContainer -> { // except the nm host if (!rmContainer.getContainer().getNodeId().equals(rmNodes[0])) { @@ -396,9 +400,9 @@ public RMNodeLabelsManager createNodeLabelManager() { allocated1 = waitForAllocation(1, 3000, am3, nms); - Assert.assertEquals(1, allocated1.size()); + Assertions.assertEquals(1, allocated1.size()); allocated.addAll(allocated1); - Assert.assertEquals(4, getContainerNodesNum(allocated)); + Assertions.assertEquals(4, getContainerNodesNum(allocated)); rm1.close(); } @@ -450,11 +454,12 @@ public RMNodeLabelsManager createNodeLabelManager() { } catch (Exception e) { caughtException = true; } - Assert.assertTrue(caughtException); + Assertions.assertTrue(caughtException); rm1.close(); } - @Test(timeout = 30000L) + @Test + @Timeout(30) public void testSchedulingRequestWithNullConstraint() throws Exception { Configuration csConf = TestUtils.getConfigurationWithMultipleQueues(conf); @@ -504,7 +509,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate(request); List allocated = waitForAllocation(1, 3000, am1, nms); - Assert.assertEquals(1, allocated.size()); + Assertions.assertEquals(1, allocated.size()); // Send another request with null placement constraint, // ensure there is no NPE while handling this request. @@ -519,12 +524,13 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate(request1); allocated = waitForAllocation(2, 3000, am1, nms); - Assert.assertEquals(2, allocated.size()); + Assertions.assertEquals(2, allocated.size()); rm1.close(); } - @Test(timeout = 30000L) + @Test + @Timeout(30) public void testInvalidSchedulingRequest() throws Exception { Configuration csConf = TestUtils.getConfigurationWithMultipleQueues(conf); @@ -580,7 +586,7 @@ public RMNodeLabelsManager createNodeLabelManager() { } }, 500, 20000); } catch (Exception e) { - Assert.fail("Failed to reject invalid scheduling request"); + Assertions.fail("Failed to reject invalid scheduling request"); } rm1.stop(); } @@ -649,7 +655,8 @@ public static int getContainerNodesNum(List containers) { return nodes.size(); } - @Test(timeout = 30000L) + @Test + @Timeout(30) public void testInterAppCompositeConstraints() throws Exception { // This test both intra and inter app constraints. // Including simple affinity, anti-affinity, cardinality constraints, @@ -682,9 +689,9 @@ public void testInterAppCompositeConstraints() throws Exception { List allocated = waitForAllocation(2, 3000, am1, nm1, nm2); // 2 containers allocated - Assert.assertEquals(2, allocated.size()); + Assertions.assertEquals(2, allocated.size()); // containers should be distributed on 2 different nodes - Assert.assertEquals(2, getContainerNodesNum(allocated)); + Assertions.assertEquals(2, getContainerNodesNum(allocated)); // App1 (hbase) // h1: hbase-rs(1), hbase-master(1) @@ -698,8 +705,8 @@ public void testInterAppCompositeConstraints() throws Exception { schedulingRequest(2, 4, 1, 1024, pc, "hbase-rs"))); allocated = waitForAllocation(4, 3000, am1, nm1, nm2, nm3, nm4, nm5); - Assert.assertEquals(4, allocated.size()); - Assert.assertEquals(4, getContainerNodesNum(allocated)); + Assertions.assertEquals(4, allocated.size()); + Assertions.assertEquals(4, getContainerNodesNum(allocated)); // App2 (web-server) // Web server instance has 2 instance and non of them can be co-allocated @@ -722,19 +729,19 @@ public void testInterAppCompositeConstraints() throws Exception { ImmutableList.of( schedulingRequest(1, 2, 1, 2048, pc, "ws-inst"))); allocated = waitForAllocation(2, 3000, am2, nm1, nm2, nm3, nm4, nm5); - Assert.assertEquals(2, allocated.size()); - Assert.assertEquals(2, getContainerNodesNum(allocated)); + Assertions.assertEquals(2, allocated.size()); + Assertions.assertEquals(2, getContainerNodesNum(allocated)); ConcurrentMap rmNodes = rm.getRMContext().getRMNodes(); for (Container c : allocated) { RMNode rmNode = rmNodes.get(c.getNodeId()); - Assert.assertNotNull(rmNode); - Assert.assertTrue("If ws-inst is allocated to a node," - + " this node should have inherited the ws-inst tag ", - rmNode.getAllocationTagsWithCount().get("ws-inst") == 1); - Assert.assertTrue("ws-inst should be co-allocated to " - + "hbase-master nodes", - rmNode.getAllocationTagsWithCount().get("hbase-master") == 1); + Assertions.assertNotNull(rmNode); + Assertions.assertTrue( + rmNode.getAllocationTagsWithCount().get("ws-inst") == 1, "If ws-inst is allocated to a node," + + " this node should have inherited the ws-inst tag "); + Assertions.assertTrue( + rmNode.getAllocationTagsWithCount().get("hbase-master") == 1, "ws-inst should be co-allocated to " + + "hbase-master nodes"); } // App3 (ws-servant) @@ -762,24 +769,25 @@ public void testInterAppCompositeConstraints() throws Exception { // total 6 containers can be allocated due to cardinality constraint // each round, 2 containers can be allocated allocated = waitForAllocation(6, 10000, am3, nm1, nm2, nm3, nm4, nm5); - Assert.assertEquals(6, allocated.size()); - Assert.assertEquals(2, getContainerNodesNum(allocated)); + Assertions.assertEquals(6, allocated.size()); + Assertions.assertEquals(2, getContainerNodesNum(allocated)); for (Container c : allocated) { RMNode rmNode = rmNodes.get(c.getNodeId()); - Assert.assertNotNull(rmNode); - Assert.assertTrue("Node has ws-servant allocated must have 3 instances", - rmNode.getAllocationTagsWithCount().get("ws-servant") == 3); - Assert.assertTrue("Every ws-servant container should be co-allocated" - + " with ws-inst", - rmNode.getAllocationTagsWithCount().get("ws-inst") == 1); + Assertions.assertNotNull(rmNode); + Assertions.assertTrue( + rmNode.getAllocationTagsWithCount().get("ws-servant") == 3, "Node has ws-servant allocated must have 3 instances"); + Assertions.assertTrue( + rmNode.getAllocationTagsWithCount().get("ws-inst") == 1, "Every ws-servant container should be co-allocated" + + " with ws-inst"); } } finally { rm.stop(); } } - @Test(timeout = 30000L) + @Test + @Timeout(30) public void testMultiAllocationTagsConstraints() throws Exception { // This test simulates to use PC to avoid port conflicts @@ -814,9 +822,9 @@ public void testMultiAllocationTagsConstraints() throws Exception { am1, nm1, nm2, nm3, nm4, nm5); // 2 containers allocated - Assert.assertEquals(2, allocated.size()); + Assertions.assertEquals(2, allocated.size()); // containers should be distributed on 2 different nodes - Assert.assertEquals(2, getContainerNodesNum(allocated)); + Assertions.assertEquals(2, getContainerNodesNum(allocated)); // App1 uses ports: 6000 String[] server2Ports = new String[] {"port_6000"}; @@ -835,19 +843,19 @@ public void testMultiAllocationTagsConstraints() throws Exception { ImmutableList.of( schedulingRequest(1, 3, 1, 1024, pc, server2Ports))); allocated = waitForAllocation(3, 3000, am2, nm1, nm2, nm3, nm4, nm5); - Assert.assertEquals(3, allocated.size()); - Assert.assertEquals(3, getContainerNodesNum(allocated)); + Assertions.assertEquals(3, allocated.size()); + Assertions.assertEquals(3, getContainerNodesNum(allocated)); ConcurrentMap rmNodes = rm.getRMContext().getRMNodes(); for (Container c : allocated) { RMNode rmNode = rmNodes.get(c.getNodeId()); - Assert.assertNotNull(rmNode); - Assert.assertTrue("server2 should not co-allocate to server1 as" - + " they both need to use port 6000", - rmNode.getAllocationTagsWithCount().get("port_6000") == 1); - Assert.assertFalse(rmNode.getAllocationTagsWithCount() + Assertions.assertNotNull(rmNode); + Assertions.assertTrue( + rmNode.getAllocationTagsWithCount().get("port_6000") == 1, "server2 should not co-allocate to server1 as" + + " they both need to use port 6000"); + Assertions.assertFalse(rmNode.getAllocationTagsWithCount() .containsKey("port_7000")); - Assert.assertFalse(rmNode.getAllocationTagsWithCount() + Assertions.assertFalse(rmNode.getAllocationTagsWithCount() .containsKey("port_8000")); } } finally { @@ -855,7 +863,8 @@ public void testMultiAllocationTagsConstraints() throws Exception { } } - @Test(timeout = 30000L) + @Test + @Timeout(30) public void testInterAppConstraintsWithNamespaces() throws Exception { // This test verifies inter-app constraints with namespaces // not-self/app-id/app-tag @@ -898,8 +907,8 @@ public void testInterAppConstraintsWithNamespaces() throws Exception { allocated); } - Assert.assertNotNull(app5Id); - Assert.assertEquals(3, getContainerNodesNum(allocMap.get(app5Id))); + Assertions.assertNotNull(app5Id); + Assertions.assertEquals(3, getContainerNodesNum(allocMap.get(app5Id))); // *** app-id // Submit another app, use app-id constraint against app5 @@ -925,11 +934,11 @@ public void testInterAppConstraintsWithNamespaces() throws Exception { List app5Alloc = allocMap.get(app5Id); for (Container c : allocated) { RMNode rmNode = rmNodes.get(c.getNodeId()); - Assert.assertNotNull(rmNode); - Assert.assertTrue("This app is affinity with app-id/app5/foo " - + "containers", - app5Alloc.stream().anyMatch( - c5 -> c5.getNodeId() == c.getNodeId())); + Assertions.assertNotNull(rmNode); + Assertions.assertTrue( + app5Alloc.stream().anyMatch( + c5 -> c5.getNodeId() == c.getNodeId()), "This app is affinity with app-id/app5/foo " + + "containers"); } // *** app-tag @@ -949,11 +958,11 @@ public void testInterAppConstraintsWithNamespaces() throws Exception { ImmutableList.of( schedulingRequest(1, 2, 1, 1024, pc, "foo"))); allocated = waitForAllocation(2, 3000, am2, nm1, nm2, nm3, nm4, nm5); - Assert.assertEquals(2, allocated.size()); + Assertions.assertEquals(2, allocated.size()); // none of them can be allocated to nodes that has app5 foo containers for (Container c : app5Alloc) { - Assert.assertNotEquals(c.getNodeId(), + Assertions.assertNotEquals(c.getNodeId(), allocated.iterator().next().getNodeId()); } @@ -972,9 +981,9 @@ public void testInterAppConstraintsWithNamespaces() throws Exception { ImmutableList.of( schedulingRequest(1, 1, 1, 1024, pc, "foo"))); allocated = waitForAllocation(1, 3000, am3, nm1, nm2, nm3, nm4, nm5); - Assert.assertEquals(1, allocated.size()); + Assertions.assertEquals(1, allocated.size()); // All 5 containers should be allocated - Assert.assertTrue(rmNodes.get(allocated.iterator().next().getNodeId()) + Assertions.assertTrue(rmNodes.get(allocated.iterator().next().getNodeId()) .getAllocationTagsWithCount().get("foo") == 2); } finally { 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/scheduler/capacity/TestSchedulingRequestContainerAllocationAsync.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestSchedulingRequestContainerAllocationAsync.java index 45a427b380b19..31fb2d3ed7231 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestSchedulingRequestContainerAllocationAsync.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestSchedulingRequestContainerAllocationAsync.java @@ -35,9 +35,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; -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.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @@ -71,7 +72,7 @@ public TestSchedulingRequestContainerAllocationAsync( this.placementConstraintHandler = placementConstraintHandler; } - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -132,34 +133,39 @@ public RMNodeLabelsManager createNodeLabelManager() { List allocated = TestSchedulingRequestContainerAllocation. waitForAllocation(nNMs, 6000, am1, nms); - Assert.assertEquals(nNMs, allocated.size()); - Assert.assertEquals(nNMs, TestSchedulingRequestContainerAllocation. + Assertions.assertEquals(nNMs, allocated.size()); + Assertions.assertEquals(nNMs, TestSchedulingRequestContainerAllocation. getContainerNodesNum(allocated)); rm1.close(); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testSingleThreadAsyncContainerAllocation() throws Exception { testIntraAppAntiAffinityAsync(1); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testTwoThreadsAsyncContainerAllocation() throws Exception { testIntraAppAntiAffinityAsync(2); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testThreeThreadsAsyncContainerAllocation() throws Exception { testIntraAppAntiAffinityAsync(3); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testFourThreadsAsyncContainerAllocation() throws Exception { testIntraAppAntiAffinityAsync(4); } - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testFiveThreadsAsyncContainerAllocation() throws Exception { testIntraAppAntiAffinityAsync(5); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUniformQueueResourceCalculation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUniformQueueResourceCalculation.java index 6125bd30d4941..8d96a735d176b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUniformQueueResourceCalculation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUniformQueueResourceCalculation.java @@ -20,7 +20,7 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUsersManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUsersManager.java index c71d862a32a02..e69fd9385745c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUsersManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestUsersManager.java @@ -21,7 +21,7 @@ import static org.mockito.Mockito.when; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager; @@ -29,8 +29,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; 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.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @@ -58,7 +58,7 @@ public class TestUsersManager { @Mock private QueueMetrics metrics; - @Before + @BeforeEach public void setup() { usersManager = new UsersManager(metrics, lQueue, @@ -100,6 +100,6 @@ private void checkLimit(Resource expectedLimit) { SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY, true); - assertEquals("User limit", expectedLimit, limit); + assertEquals(expectedLimit, limit, "User limit"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestWorkPreservingRMRestartForNodeLabel.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestWorkPreservingRMRestartForNodeLabel.java index a431d4700b7b7..913a8e12c72e2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestWorkPreservingRMRestartForNodeLabel.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestWorkPreservingRMRestartForNodeLabel.java @@ -47,9 +47,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerApplicationAttempt; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; -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.ImmutableMap; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; @@ -60,7 +60,7 @@ public class TestWorkPreservingRMRestartForNodeLabel { RMNodeLabelsManager mgr; - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, @@ -82,8 +82,8 @@ private void checkRMContainerLabelExpression(ContainerId containerId, MockRM rm, String labelExpression) { RMContainer container = rm.getRMContext().getScheduler().getRMContainer(containerId); - Assert.assertNotNull("Cannot find RMContainer=" + containerId, container); - Assert.assertEquals(labelExpression, + Assertions.assertNotNull(container, "Cannot find RMContainer=" + containerId); + Assertions.assertEquals(labelExpression, container.getNodeLabelExpression()); } @@ -113,14 +113,14 @@ private void checkAppResourceUsage(String partition, ApplicationId appId, CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); FiCaSchedulerApp app = cs.getSchedulerApplications().get(appId).getCurrentAppAttempt(); - Assert.assertEquals(expectedMemUsage, app.getAppAttemptResourceUsage() + Assertions.assertEquals(expectedMemUsage, app.getAppAttemptResourceUsage() .getUsed(partition).getMemorySize()); } private void checkQueueResourceUsage(String partition, String queueName, MockRM rm, int expectedMemUsage) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queueName); - Assert.assertEquals(expectedMemUsage, queue.getQueueResourceUsage() + Assertions.assertEquals(expectedMemUsage, queue.getQueueResourceUsage() .getUsed(partition).getMemorySize()); } @@ -171,7 +171,7 @@ public RMNodeLabelsManager createNodeLabelManager() { am1.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm1, containerId, + Assertions.assertTrue(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); checkRMContainerLabelExpression(ContainerId.newContainerId( am1.getApplicationAttemptId(), 1), rm1, "x"); @@ -194,7 +194,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // request a container. am2.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am2.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm2, containerId, + Assertions.assertTrue(rm1.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); checkRMContainerLabelExpression(ContainerId.newContainerId( am2.getApplicationAttemptId(), 1), rm1, "y"); @@ -217,7 +217,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // request a container. am3.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am3.getApplicationAttemptId(), 2); - Assert.assertTrue(rm1.waitForState(nm3, containerId, + Assertions.assertTrue(rm1.waitForState(nm3, containerId, RMContainerState.ALLOCATED)); checkRMContainerLabelExpression(ContainerId.newContainerId( am3.getApplicationAttemptId(), 1), rm1, ""); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ConfigurationStoreBaseTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ConfigurationStoreBaseTest.java index 2c363622d2157..0cce8cc038f8c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ConfigurationStoreBaseTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ConfigurationStoreBaseTest.java @@ -24,11 +24,11 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.RMContext; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Base class for {@link YarnConfigurationStore} implementations. @@ -42,7 +42,7 @@ public abstract class ConfigurationStoreBaseTest { abstract YarnConfigurationStore createConfStore(); - @Before + @BeforeEach public void setUp() throws Exception { this.conf = new Configuration(); this.conf.setClass(YarnConfiguration.RM_SCHEDULER, @@ -62,8 +62,8 @@ public void testConfigurationUpdate() throws Exception { confStore.confirmMutation(prepareLogMutation("keyUpdate2", "valUpdate2"), false); - assertNull("Configuration should not be updated", - confStore.retrieve().get("keyUpdate2")); + assertNull( + confStore.retrieve().get("keyUpdate2"), "Configuration should not be updated"); confStore.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/scheduler/capacity/conf/PersistentConfigurationStoreBaseTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/PersistentConfigurationStoreBaseTest.java index 5037921b18655..e84ee2116d5bc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/PersistentConfigurationStoreBaseTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/PersistentConfigurationStoreBaseTest.java @@ -19,12 +19,12 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.records.Version; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.LinkedList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.Assume.assumeFalse; /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestConfigurationUpdateAssembler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestConfigurationUpdateAssembler.java index fa767a5182652..31a8d59c26d72 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestConfigurationUpdateAssembler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestConfigurationUpdateAssembler.java @@ -22,17 +22,17 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath; import org.apache.hadoop.yarn.webapp.dao.QueueConfigInfo; import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests {@link ConfigurationUpdateAssembler}. @@ -62,7 +62,7 @@ public class TestConfigurationUpdateAssembler { private CapacitySchedulerConfiguration csConfig; - @Before + @BeforeEach public void setUp() { csConfig = crateInitialCSConfig(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestFSSchedulerConfigurationStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestFSSchedulerConfigurationStore.java index 5897741ca9322..223dfca31d73c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestFSSchedulerConfigurationStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestFSSchedulerConfigurationStore.java @@ -32,14 +32,14 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.records.Version; import org.hamcrest.CoreMatchers; -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 static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; /** @@ -49,7 +49,7 @@ public class TestFSSchedulerConfigurationStore extends PersistentConfigurationStoreBaseTest { private File testSchedulerConfigurationDir; - @Before + @BeforeEach @Override public void setUp() throws Exception { super.setUp(); @@ -73,7 +73,7 @@ private void writeConf(Configuration config) throws IOException { outputStream.close(); } - @After + @AfterEach public void tearDown() throws Exception { FileUtils.deleteDirectory(testSchedulerConfigurationDir); } @@ -163,9 +163,7 @@ public void testFormatConfiguration() throws Exception { fail("Expected an IOException with message containing \"no capacity " + "scheduler file in\" to be thrown"); } catch (IOException e) { - assertThat("Exception message should contain the predefined string.", - e.getMessage(), - CoreMatchers.containsString("no capacity scheduler file in")); + assertThat(e.getMessage()).contains("no capacity scheduler file in").as("Exception message should contain the predefined string."); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestInMemoryConfigurationStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestInMemoryConfigurationStore.java index 5ebad50fe62e4..7992c9fc6bf64 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestInMemoryConfigurationStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestInMemoryConfigurationStore.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests {@link InMemoryConfigurationStore}. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestLeveldbConfigurationStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestLeveldbConfigurationStore.java index 3565ed13270cf..2955122c95780 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestLeveldbConfigurationStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestLeveldbConfigurationStore.java @@ -31,8 +31,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.YarnConfigurationStore.LogMutation; import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.iq80.leveldb.DB; import org.iq80.leveldb.DBIterator; @@ -40,9 +40,7 @@ import java.nio.charset.StandardCharsets; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; /** * Tests {@link LeveldbConfigurationStore}. @@ -57,7 +55,7 @@ public class TestLeveldbConfigurationStore extends System.getProperty("java.io.tmpdir")), TestLeveldbConfigurationStore.class.getName()); - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); FileUtil.fullyDelete(TEST_DIR); @@ -66,21 +64,23 @@ public void setUp() throws Exception { conf.set(YarnConfiguration.RM_SCHEDCONF_STORE_PATH, TEST_DIR.toString()); } - @Test(expected = YarnConfStoreVersionIncompatibleException.class) + @Test public void testIncompatibleVersion() throws Exception { - try { - confStore.initialize(conf, schedConf, rmContext); - - Version otherVersion = Version.newInstance(1, 1); - ((LeveldbConfigurationStore) confStore).storeVersion(otherVersion); - - assertEquals("The configuration store should have stored the new" + - "version.", otherVersion, - confStore.getConfStoreVersion()); - confStore.checkVersion(); - } finally { - confStore.close(); - } + assertThrows(YarnConfStoreVersionIncompatibleException.class, ()->{ + try { + confStore.initialize(conf, schedConf, rmContext); + + Version otherVersion = Version.newInstance(1, 1); + ((LeveldbConfigurationStore) confStore).storeVersion(otherVersion); + + assertEquals(otherVersion + , confStore.getConfStoreVersion(), "The configuration store should have stored the new" + + "version."); + confStore.checkVersion(); + } finally { + confStore.close(); + } + }); } @Test @@ -102,7 +102,7 @@ public void testDisableAuditLogs() throws Exception { break; } } - assertFalse("Audit Log is not disabled", logKeyPresent); + assertFalse(logKeyPresent, "Audit Log is not disabled"); confStore.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/scheduler/capacity/conf/TestMutableCSConfigurationProvider.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestMutableCSConfigurationProvider.java index 89b7dc4b2ff84..607cf2c4132e1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestMutableCSConfigurationProvider.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestMutableCSConfigurationProvider.java @@ -33,16 +33,16 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.YarnConfigurationStore.LogMutation; import org.apache.hadoop.yarn.webapp.dao.QueueConfigInfo; import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -61,7 +61,7 @@ public class TestMutableCSConfigurationProvider { private static final UserGroupInformation TEST_USER = UserGroupInformation .createUserForTesting("testUser", new String[] {}); - @Before + @BeforeEach public void setUp() { cs = mock(CapacityScheduler.class); rmContext = mock(RMContext.class); @@ -142,9 +142,9 @@ public void testRemoveQueueConfig() throws Exception { log = confProvider.logAndApplyMutation(TEST_USER, updateInfo); confProvider.confirmPendingMutation(log, true); - assertNull("Failed to remove config", - confProvider.loadConfiguration(conf) - .get("yarn.scheduler.capacity.root.a.testkey1")); + assertNull( + confProvider.loadConfiguration(conf) + .get("yarn.scheduler.capacity.root.a.testkey1"), "Failed to remove config"); assertEquals("testval2", confProvider.loadConfiguration(conf) .get("yarn.scheduler.capacity.root.a.testkey2")); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestQueueCapacityConfigParser.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestQueueCapacityConfigParser.java index e0ad3a5446764..b9b1337e1d465 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestQueueCapacityConfigParser.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestQueueCapacityConfigParser.java @@ -26,8 +26,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacityVector.ResourceUnitCapacityType; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; @@ -78,11 +78,11 @@ public void testPercentageCapacityConfig() { QueueCapacityVectorEntry memory = percentageCapacityVector.getResource(MEMORY_URI); QueueCapacityVectorEntry vcore = percentageCapacityVector.getResource(VCORES_URI); - Assert.assertEquals(ResourceUnitCapacityType.PERCENTAGE, memory.getVectorResourceType()); - Assert.assertEquals(PERCENTAGE_VALUE, memory.getResourceValue(), EPSILON); + Assertions.assertEquals(ResourceUnitCapacityType.PERCENTAGE, memory.getVectorResourceType()); + Assertions.assertEquals(PERCENTAGE_VALUE, memory.getResourceValue(), EPSILON); - Assert.assertEquals(ResourceUnitCapacityType.PERCENTAGE, vcore.getVectorResourceType()); - Assert.assertEquals(PERCENTAGE_VALUE, vcore.getResourceValue(), EPSILON); + Assertions.assertEquals(ResourceUnitCapacityType.PERCENTAGE, vcore.getVectorResourceType()); + Assertions.assertEquals(PERCENTAGE_VALUE, vcore.getResourceValue(), EPSILON); QueueCapacityVector rootCapacityVector = capacityConfigParser.parse(Float.toString(PERCENTAGE_VALUE), ROOT); @@ -90,11 +90,11 @@ public void testPercentageCapacityConfig() { QueueCapacityVectorEntry memoryRoot = rootCapacityVector.getResource(MEMORY_URI); QueueCapacityVectorEntry vcoreRoot = rootCapacityVector.getResource(VCORES_URI); - Assert.assertEquals(ResourceUnitCapacityType.PERCENTAGE, memoryRoot.getVectorResourceType()); - Assert.assertEquals(100f, memoryRoot.getResourceValue(), EPSILON); + Assertions.assertEquals(ResourceUnitCapacityType.PERCENTAGE, memoryRoot.getVectorResourceType()); + Assertions.assertEquals(100f, memoryRoot.getResourceValue(), EPSILON); - Assert.assertEquals(ResourceUnitCapacityType.PERCENTAGE, vcoreRoot.getVectorResourceType()); - Assert.assertEquals(100f, vcoreRoot.getResourceValue(), EPSILON); + Assertions.assertEquals(ResourceUnitCapacityType.PERCENTAGE, vcoreRoot.getVectorResourceType()); + Assertions.assertEquals(100f, vcoreRoot.getResourceValue(), EPSILON); } @Test @@ -105,11 +105,11 @@ public void testWeightCapacityConfig() { QueueCapacityVectorEntry memory = weightCapacityVector.getResource(MEMORY_URI); QueueCapacityVectorEntry vcore = weightCapacityVector.getResource(VCORES_URI); - Assert.assertEquals(ResourceUnitCapacityType.WEIGHT, memory.getVectorResourceType()); - Assert.assertEquals(WEIGHT_VALUE, memory.getResourceValue(), EPSILON); + Assertions.assertEquals(ResourceUnitCapacityType.WEIGHT, memory.getVectorResourceType()); + Assertions.assertEquals(WEIGHT_VALUE, memory.getResourceValue(), EPSILON); - Assert.assertEquals(ResourceUnitCapacityType.WEIGHT, vcore.getVectorResourceType()); - Assert.assertEquals(WEIGHT_VALUE, vcore.getResourceValue(), EPSILON); + Assertions.assertEquals(ResourceUnitCapacityType.WEIGHT, vcore.getVectorResourceType()); + Assertions.assertEquals(WEIGHT_VALUE, vcore.getResourceValue(), EPSILON); } @Test @@ -123,26 +123,26 @@ public void testAbsoluteCapacityVectorConfig() { QueueCapacityVector absoluteCapacityVector = capacityConfigParser.parse(ABSOLUTE_RESOURCE, QUEUE_PATH); - Assert.assertEquals(ResourceUnitCapacityType.ABSOLUTE, + Assertions.assertEquals(ResourceUnitCapacityType.ABSOLUTE, absoluteCapacityVector.getResource(MEMORY_URI).getVectorResourceType()); - Assert.assertEquals(12 * GB, absoluteCapacityVector.getResource(MEMORY_URI) + Assertions.assertEquals(12 * GB, absoluteCapacityVector.getResource(MEMORY_URI) .getResourceValue(), EPSILON); - Assert.assertEquals(ResourceUnitCapacityType.ABSOLUTE, + Assertions.assertEquals(ResourceUnitCapacityType.ABSOLUTE, absoluteCapacityVector.getResource(VCORES_URI).getVectorResourceType()); - Assert.assertEquals(VCORE_ABSOLUTE, absoluteCapacityVector.getResource(VCORES_URI) + Assertions.assertEquals(VCORE_ABSOLUTE, absoluteCapacityVector.getResource(VCORES_URI) .getResourceValue(), EPSILON); - Assert.assertEquals(ResourceUnitCapacityType.ABSOLUTE, + Assertions.assertEquals(ResourceUnitCapacityType.ABSOLUTE, absoluteCapacityVector.getResource(GPU_URI).getVectorResourceType()); - Assert.assertEquals(GPU_ABSOLUTE, absoluteCapacityVector.getResource(GPU_URI) + Assertions.assertEquals(GPU_ABSOLUTE, absoluteCapacityVector.getResource(GPU_URI) .getResourceValue(), EPSILON); QueueCapacityVector withoutGpuVector = capacityConfigParser .parse(ABSOLUTE_RESOURCE_MEMORY_VCORE, QUEUE_PATH); - Assert.assertEquals(3, withoutGpuVector.getResourceCount()); - Assert.assertEquals(0f, withoutGpuVector.getResource(GPU_URI).getResourceValue(), EPSILON); + Assertions.assertEquals(3, withoutGpuVector.getResourceCount()); + Assertions.assertEquals(0f, withoutGpuVector.getResource(GPU_URI).getResourceValue(), EPSILON); } @Test @@ -154,27 +154,27 @@ public void testMixedCapacityConfig() { QueueCapacityVector mixedCapacityVector = capacityConfigParser.parse(MIXED_RESOURCE, QUEUE_PATH); - Assert.assertEquals(ResourceUnitCapacityType.ABSOLUTE, + Assertions.assertEquals(ResourceUnitCapacityType.ABSOLUTE, mixedCapacityVector.getResource(MEMORY_URI).getVectorResourceType()); - Assert.assertEquals(MEMORY_MIXED, mixedCapacityVector.getResource(MEMORY_URI) + Assertions.assertEquals(MEMORY_MIXED, mixedCapacityVector.getResource(MEMORY_URI) .getResourceValue(), EPSILON); - Assert.assertEquals(ResourceUnitCapacityType.PERCENTAGE, + Assertions.assertEquals(ResourceUnitCapacityType.PERCENTAGE, mixedCapacityVector.getResource(VCORES_URI).getVectorResourceType()); - Assert.assertEquals(PERCENTAGE_VALUE, + Assertions.assertEquals(PERCENTAGE_VALUE, mixedCapacityVector.getResource(VCORES_URI).getResourceValue(), EPSILON); - Assert.assertEquals(ResourceUnitCapacityType.WEIGHT, + Assertions.assertEquals(ResourceUnitCapacityType.WEIGHT, mixedCapacityVector.getResource(GPU_URI).getVectorResourceType()); - Assert.assertEquals(WEIGHT_VALUE, + Assertions.assertEquals(WEIGHT_VALUE, mixedCapacityVector.getResource(GPU_URI).getResourceValue(), EPSILON); // Test undefined capacity type default value QueueCapacityVector mixedCapacityVectorWithGpuUndefined = capacityConfigParser.parse(ABSOLUTE_RESOURCE_MEMORY_VCORE, QUEUE_PATH); - Assert.assertEquals(ResourceUnitCapacityType.ABSOLUTE, + Assertions.assertEquals(ResourceUnitCapacityType.ABSOLUTE, mixedCapacityVectorWithGpuUndefined.getResource(MEMORY_URI).getVectorResourceType()); - Assert.assertEquals(0, mixedCapacityVectorWithGpuUndefined.getResource(GPU_URI) + Assertions.assertEquals(0, mixedCapacityVectorWithGpuUndefined.getResource(GPU_URI) .getResourceValue(), EPSILON); } @@ -185,37 +185,37 @@ public void testInvalidCapacityConfigs() { capacityConfigParser.parse(NONEXISTINGSUFFIX, QUEUE_PATH); List entriesWithInvalidSuffix = Lists.newArrayList(capacityVectorWithInvalidSuffix.iterator()); - Assert.assertEquals(0, entriesWithInvalidSuffix.size()); + Assertions.assertEquals(0, entriesWithInvalidSuffix.size()); QueueCapacityVector invalidDelimiterCapacityVector = capacityConfigParser.parse(INVALID_CAPACITY_FORMAT, QUEUE_PATH); List invalidDelimiterEntries = Lists.newArrayList(invalidDelimiterCapacityVector.iterator()); - Assert.assertEquals(0, invalidDelimiterEntries.size()); + Assertions.assertEquals(0, invalidDelimiterEntries.size()); QueueCapacityVector invalidCapacityVector = capacityConfigParser.parse(INVALID_CAPACITY_BRACKET, QUEUE_PATH); List resources = Lists.newArrayList(invalidCapacityVector.iterator()); - Assert.assertEquals(0, resources.size()); + Assertions.assertEquals(0, resources.size()); QueueCapacityVector emptyBracketCapacityVector = capacityConfigParser.parse(EMPTY_BRACKET, QUEUE_PATH); List emptyEntries = Lists.newArrayList(emptyBracketCapacityVector.iterator()); - Assert.assertEquals(0, emptyEntries.size()); + Assertions.assertEquals(0, emptyEntries.size()); QueueCapacityVector emptyCapacity = capacityConfigParser.parse("", QUEUE_PATH); List emptyResources = Lists.newArrayList(emptyCapacity.iterator()); - Assert.assertEquals(emptyResources.size(), 0); + Assertions.assertEquals(emptyResources.size(), 0); QueueCapacityVector nonSetCapacity = capacityConfigParser.parse(null, QUEUE_PATH); List nonSetResources = Lists.newArrayList(nonSetCapacity.iterator()); - Assert.assertEquals(nonSetResources.size(), 0); + Assertions.assertEquals(nonSetResources.size(), 0); } @Test @@ -226,10 +226,10 @@ public void testZeroAbsoluteCapacityConfig() { QueueCapacityVectorEntry memory = weightCapacityVector.getResource(MEMORY_URI); QueueCapacityVectorEntry vcore = weightCapacityVector.getResource(VCORES_URI); - Assert.assertEquals(ResourceUnitCapacityType.ABSOLUTE, memory.getVectorResourceType()); - Assert.assertEquals(0, memory.getResourceValue(), EPSILON); + Assertions.assertEquals(ResourceUnitCapacityType.ABSOLUTE, memory.getVectorResourceType()); + Assertions.assertEquals(0, memory.getResourceValue(), EPSILON); - Assert.assertEquals(ResourceUnitCapacityType.ABSOLUTE, vcore.getVectorResourceType()); - Assert.assertEquals(0, vcore.getResourceValue(), EPSILON); + Assertions.assertEquals(ResourceUnitCapacityType.ABSOLUTE, vcore.getVectorResourceType()); + Assertions.assertEquals(0, vcore.getResourceValue(), EPSILON); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestZKConfigurationStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestZKConfigurationStore.java index fa55b51a1b0a2..9941b61488a32 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestZKConfigurationStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestZKConfigurationStore.java @@ -40,10 +40,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf.YarnConfigurationStore.LogMutation; import org.apache.hadoop.yarn.webapp.dao.QueueConfigInfo; import org.apache.hadoop.yarn.webapp.dao.SchedConfUpdateInfo; -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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,9 +57,7 @@ import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests {@link ZKConfigurationStore}. @@ -92,7 +91,7 @@ public static CuratorFramework setupCuratorFramework( return curatorFramework; } - @Before + @BeforeEach @Override public void setUp() throws Exception { super.setUp(); @@ -106,27 +105,29 @@ public void setUp() throws Exception { rmContext = rm.getRMContext(); } - @After + @AfterEach public void cleanup() throws IOException { rm.stop(); curatorFramework.close(); curatorTestingServer.stop(); } - @Test(expected = YarnConfStoreVersionIncompatibleException.class) + @Test public void testIncompatibleVersion() throws Exception { - confStore.initialize(conf, schedConf, rmContext); - - Version otherVersion = Version.newInstance(1, 1); - String zkVersionPath = getZkPath("VERSION"); - byte[] versionData = - ((VersionPBImpl) otherVersion).getProto().toByteArray(); - ((ZKConfigurationStore) confStore).safeCreateZkData(zkVersionPath, - versionData); - - assertEquals("The configuration store should have stored the new" + - "version.", otherVersion, confStore.getConfStoreVersion()); - confStore.checkVersion(); + assertThrows(YarnConfStoreVersionIncompatibleException.class, ()->{ + confStore.initialize(conf, schedConf, rmContext); + + Version otherVersion = Version.newInstance(1, 1); + String zkVersionPath = getZkPath("VERSION"); + byte[] versionData = + ((VersionPBImpl) otherVersion).getProto().toByteArray(); + ((ZKConfigurationStore) confStore).safeCreateZkData(zkVersionPath, + versionData); + + assertEquals(otherVersion, confStore.getConfStoreVersion(), "The configuration store should have stored the new" + + "version."); + confStore.checkVersion(); + }); } @Test @@ -138,13 +139,15 @@ public void testFormatConfiguration() throws Exception { assertNull(confStore.retrieve()); } - @Test(expected = IllegalStateException.class) + @Test public void testGetConfigurationVersionOnSerializedNullData() throws Exception { - confStore.initialize(conf, schedConf, rmContext); - String confVersionPath = getZkPath("CONF_VERSION"); - ((ZKConfigurationStore) confStore).setZkData(confVersionPath, null); - confStore.getConfigVersion(); + assertThrows(IllegalStateException.class, ()->{ + confStore.initialize(conf, schedConf, rmContext); + String confVersionPath = getZkPath("CONF_VERSION"); + ((ZKConfigurationStore) confStore).setZkData(confVersionPath, null); + confStore.getConfigVersion(); + }); } /** @@ -154,29 +157,31 @@ public void testGetConfigurationVersionOnSerializedNullData() * * @throws Exception */ - @Test(expected = ClassCastException.class) + @Test public void testLogMutationAfterSerializationError() throws Exception { - byte[] data = null; - String logs = "NOT_LINKED_LIST"; - confStore.initialize(conf, schedConf, rmContext); - - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos)) { - oos.writeObject(logs); - oos.flush(); - baos.flush(); - data = baos.toByteArray(); - } + assertThrows(ClassCastException.class, ()->{ + byte[] data = null; + String logs = "NOT_LINKED_LIST"; + confStore.initialize(conf, schedConf, rmContext); + + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(logs); + oos.flush(); + baos.flush(); + data = baos.toByteArray(); + } - String logsPath = getZkPath("LOGS"); - ((ZKConfigurationStore)confStore).setZkData(logsPath, data); + String logsPath = getZkPath("LOGS"); + ((ZKConfigurationStore)confStore).setZkData(logsPath, data); - Map update = new HashMap<>(); - update.put("valid_key", "valid_value"); + Map update = new HashMap<>(); + update.put("valid_key", "valid_value"); - confStore.logMutation(new LogMutation(update, TEST_USER)); + confStore.logMutation(new LogMutation(update, TEST_USER)); - assertEquals(data, ((ZKConfigurationStore)confStore).getZkData(logsPath)); + assertEquals(data, ((ZKConfigurationStore)confStore).getZkData(logsPath)); + }); } @Test @@ -190,7 +195,7 @@ public void testDisableAuditLogs() throws Exception { prepareLogMutation("key1", "val1"); data = ((ZKConfigurationStore) confStore).getZkData(logsPath); - assertNull("Failed to Disable Audit Logs", data); + assertNull(data, "Failed to Disable Audit Logs"); } public Configuration createRMHAConf(String rmIds, String rmId, @@ -235,20 +240,20 @@ public void testFailoverReadsFromUpdatedStore() throws Exception { ResourceManager rm1 = new MockRM(conf1); rm1.start(); rm1.getRMContext().getRMAdminService().transitionToActive(req); - assertEquals("RM with ZKStore didn't start", - Service.STATE.STARTED, rm1.getServiceState()); - assertEquals("RM should be Active", - HAServiceProtocol.HAServiceState.ACTIVE, - rm1.getRMContext().getRMAdminService().getServiceStatus().getState()); + assertEquals( + Service.STATE.STARTED, rm1.getServiceState(), "RM with ZKStore didn't start"); + assertEquals( + HAServiceProtocol.HAServiceState.ACTIVE +, rm1.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); assertNull(((MutableConfScheduler) rm1.getResourceScheduler()) .getConfiguration().get("key")); Configuration conf2 = createRMHAConf("rm1,rm2", "rm2", 5678); ResourceManager rm2 = new MockRM(conf2); rm2.start(); - assertEquals("RM should be Standby", - HAServiceProtocol.HAServiceState.STANDBY, - rm2.getRMContext().getRMAdminService().getServiceStatus().getState()); + assertEquals( + HAServiceProtocol.HAServiceState.STANDBY +, rm2.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Standby"); // Update configuration on RM1 SchedConfUpdateInfo schedConfUpdateInfo = new SchedConfUpdateInfo(); @@ -271,11 +276,11 @@ public void testFailoverReadsFromUpdatedStore() throws Exception { // Start RM2 and verifies it starts with updated configuration rm2.getRMContext().getRMAdminService().transitionToActive(req); - assertEquals("RM with ZKStore didn't start", - Service.STATE.STARTED, rm2.getServiceState()); - assertEquals("RM should be Active", - HAServiceProtocol.HAServiceState.ACTIVE, - rm2.getRMContext().getRMAdminService().getServiceStatus().getState()); + assertEquals( + Service.STATE.STARTED, rm2.getServiceState(), "RM with ZKStore didn't start"); + assertEquals( + HAServiceProtocol.HAServiceState.ACTIVE +, rm2.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); for (int i = 0; i < ZK_TIMEOUT_MS / 50; i++) { if (HAServiceProtocol.HAServiceState.ACTIVE == @@ -284,12 +289,12 @@ public void testFailoverReadsFromUpdatedStore() throws Exception { Thread.sleep(100); } } - assertEquals("RM should have been fenced", - HAServiceProtocol.HAServiceState.STANDBY, - rm1.getRMContext().getRMAdminService().getServiceStatus().getState()); - assertEquals("RM should be Active", - HAServiceProtocol.HAServiceState.ACTIVE, - rm2.getRMContext().getRMAdminService().getServiceStatus().getState()); + assertEquals( + HAServiceProtocol.HAServiceState.STANDBY +, rm1.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should have been fenced"); + assertEquals( + HAServiceProtocol.HAServiceState.ACTIVE +, rm2.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); assertEquals("val", ((MutableCSConfigurationProvider) ( (CapacityScheduler) rm2.getResourceScheduler()) @@ -321,18 +326,18 @@ public void testFailoverAfterRemoveQueue() throws Exception { ResourceManager rm1 = new MockRM(conf1); rm1.start(); rm1.getRMContext().getRMAdminService().transitionToActive(req); - assertEquals("RM with ZKStore didn't start", - Service.STATE.STARTED, rm1.getServiceState()); - assertEquals("RM should be Active", - HAServiceProtocol.HAServiceState.ACTIVE, - rm1.getRMContext().getRMAdminService().getServiceStatus().getState()); + assertEquals( + Service.STATE.STARTED, rm1.getServiceState(), "RM with ZKStore didn't start"); + assertEquals( + HAServiceProtocol.HAServiceState.ACTIVE +, rm1.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); Configuration conf2 = createRMHAConf("rm1,rm2", "rm2", 5678); ResourceManager rm2 = new MockRM(conf2); rm2.start(); - assertEquals("RM should be Standby", - HAServiceProtocol.HAServiceState.STANDBY, - rm2.getRMContext().getRMAdminService().getServiceStatus().getState()); + assertEquals( + HAServiceProtocol.HAServiceState.STANDBY +, rm2.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Standby"); UserGroupInformation user = UserGroupInformation .createUserForTesting(TEST_USER, new String[0]); @@ -370,11 +375,11 @@ public void testFailoverAfterRemoveQueue() throws Exception { // Start RM2 and verifies it starts with updated configuration rm2.getRMContext().getRMAdminService().transitionToActive(req); - assertEquals("RM with ZKStore didn't start", - Service.STATE.STARTED, rm2.getServiceState()); - assertEquals("RM should be Active", - HAServiceProtocol.HAServiceState.ACTIVE, - rm2.getRMContext().getRMAdminService().getServiceStatus().getState()); + assertEquals( + Service.STATE.STARTED, rm2.getServiceState(), "RM with ZKStore didn't start"); + assertEquals( + HAServiceProtocol.HAServiceState.ACTIVE +, rm2.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); for (int i = 0; i < ZK_TIMEOUT_MS / 50; i++) { if (HAServiceProtocol.HAServiceState.ACTIVE == @@ -383,12 +388,12 @@ public void testFailoverAfterRemoveQueue() throws Exception { Thread.sleep(100); } } - assertEquals("RM should have been fenced", - HAServiceProtocol.HAServiceState.STANDBY, - rm1.getRMContext().getRMAdminService().getServiceStatus().getState()); - assertEquals("RM should be Active", - HAServiceProtocol.HAServiceState.ACTIVE, - rm2.getRMContext().getRMAdminService().getServiceStatus().getState()); + assertEquals( + HAServiceProtocol.HAServiceState.STANDBY +, rm1.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should have been fenced"); + assertEquals( + HAServiceProtocol.HAServiceState.ACTIVE +, rm2.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); assertEquals("a", ((MutableCSConfigurationProvider) ( (CapacityScheduler) rm2.getResourceScheduler()) @@ -406,7 +411,8 @@ public void testFailoverAfterRemoveQueue() throws Exception { rm2.close(); } - @Test(timeout = 3000) + @Test + @Timeout(value = 3) @SuppressWarnings("checkstyle:linelength") public void testDeserializationIsNotVulnerable() throws Exception { confStore.initialize(conf, schedConf, rmContext); @@ -414,13 +420,13 @@ public void testDeserializationIsNotVulnerable() throws Exception { File flagFile = new File(DESERIALIZATION_VULNERABILITY_FILEPATH); if (flagFile.exists()) { - Assert.assertTrue(flagFile.delete()); + Assertions.assertTrue(flagFile.delete()); } // Generated using ysoserial (https://github.com/frohoff/ysoserial) // java -jar ysoserial.jar CommonsBeanutils1 'touch /tmp/ZK_DESERIALIZATION_VULNERABILITY' | base64 ((ZKConfigurationStore) confStore).setZkData(confStorePath, Base64.getDecoder().decode("rO0ABXNyABdqYXZhLnV0aWwuUHJpb3JpdHlRdWV1ZZTaMLT7P4KxAwACSQAEc2l6ZUwACmNvbXBhcmF0b3J0ABZMamF2YS91dGlsL0NvbXBhcmF0b3I7eHAAAAACc3IAK29yZy5hcGFjaGUuY29tbW9ucy5iZWFudXRpbHMuQmVhbkNvbXBhcmF0b3LjoYjqcyKkSAIAAkwACmNvbXBhcmF0b3JxAH4AAUwACHByb3BlcnR5dAASTGphdmEvbGFuZy9TdHJpbmc7eHBzcgA/b3JnLmFwYWNoZS5jb21tb25zLmNvbGxlY3Rpb25zLmNvbXBhcmF0b3JzLkNvbXBhcmFibGVDb21wYXJhdG9y+/SZJbhusTcCAAB4cHQAEG91dHB1dFByb3BlcnRpZXN3BAAAAANzcgA6Y29tLnN1bi5vcmcuYXBhY2hlLnhhbGFuLmludGVybmFsLnhzbHRjLnRyYXguVGVtcGxhdGVzSW1wbAlXT8FurKszAwAGSQANX2luZGVudE51bWJlckkADl90cmFuc2xldEluZGV4WwAKX2J5dGVjb2Rlc3QAA1tbQlsABl9jbGFzc3QAEltMamF2YS9sYW5nL0NsYXNzO0wABV9uYW1lcQB+AARMABFfb3V0cHV0UHJvcGVydGllc3QAFkxqYXZhL3V0aWwvUHJvcGVydGllczt4cAAAAAD/////dXIAA1tbQkv9GRVnZ9s3AgAAeHAAAAACdXIAAltCrPMX+AYIVOACAAB4cAAABsHK/rq+AAAAMgA5CgADACIHADcHACUHACYBABBzZXJpYWxWZXJzaW9uVUlEAQABSgEADUNvbnN0YW50VmFsdWUFrSCT85Hd7z4BAAY8aW5pdD4BAAMoKVYBAARDb2RlAQAPTGluZU51bWJlclRhYmxlAQASTG9jYWxWYXJpYWJsZVRhYmxlAQAEdGhpcwEAE1N0dWJUcmFuc2xldFBheWxvYWQBAAxJbm5lckNsYXNzZXMBADVMeXNvc2VyaWFsL3BheWxvYWRzL3V0aWwvR2FkZ2V0cyRTdHViVHJhbnNsZXRQYXlsb2FkOwEACXRyYW5zZm9ybQEAcihMY29tL3N1bi9vcmcvYXBhY2hlL3hhbGFuL2ludGVybmFsL3hzbHRjL0RPTTtbTGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvc2VyaWFsaXplci9TZXJpYWxpemF0aW9uSGFuZGxlcjspVgEACGRvY3VtZW50AQAtTGNvbS9zdW4vb3JnL2FwYWNoZS94YWxhbi9pbnRlcm5hbC94c2x0Yy9ET007AQAIaGFuZGxlcnMBAEJbTGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvc2VyaWFsaXplci9TZXJpYWxpemF0aW9uSGFuZGxlcjsBAApFeGNlcHRpb25zBwAnAQCmKExjb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvRE9NO0xjb20vc3VuL29yZy9hcGFjaGUveG1sL2ludGVybmFsL2R0bS9EVE1BeGlzSXRlcmF0b3I7TGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvc2VyaWFsaXplci9TZXJpYWxpemF0aW9uSGFuZGxlcjspVgEACGl0ZXJhdG9yAQA1TGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvZHRtL0RUTUF4aXNJdGVyYXRvcjsBAAdoYW5kbGVyAQBBTGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvc2VyaWFsaXplci9TZXJpYWxpemF0aW9uSGFuZGxlcjsBAApTb3VyY2VGaWxlAQAMR2FkZ2V0cy5qYXZhDAAKAAsHACgBADN5c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzJFN0dWJUcmFuc2xldFBheWxvYWQBAEBjb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvcnVudGltZS9BYnN0cmFjdFRyYW5zbGV0AQAUamF2YS9pby9TZXJpYWxpemFibGUBADljb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvVHJhbnNsZXRFeGNlcHRpb24BAB95c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzAQAIPGNsaW5pdD4BABFqYXZhL2xhbmcvUnVudGltZQcAKgEACmdldFJ1bnRpbWUBABUoKUxqYXZhL2xhbmcvUnVudGltZTsMACwALQoAKwAuAQArdG91Y2ggL3RtcC9aS19ERVNFUklBTElaQVRJT05fVlVMTkVSQUJJTElUWQgAMAEABGV4ZWMBACcoTGphdmEvbGFuZy9TdHJpbmc7KUxqYXZhL2xhbmcvUHJvY2VzczsMADIAMwoAKwA0AQANU3RhY2tNYXBUYWJsZQEAHnlzb3NlcmlhbC9Qd25lcjExNTM4MjYwNDMyOTA1MQEAIEx5c29zZXJpYWwvUHduZXIxMTUzODI2MDQzMjkwNTE7ACEAAgADAAEABAABABoABQAGAAEABwAAAAIACAAEAAEACgALAAEADAAAAC8AAQABAAAABSq3AAGxAAAAAgANAAAABgABAAAALwAOAAAADAABAAAABQAPADgAAAABABMAFAACAAwAAAA/AAAAAwAAAAGxAAAAAgANAAAABgABAAAANAAOAAAAIAADAAAAAQAPADgAAAAAAAEAFQAWAAEAAAABABcAGAACABkAAAAEAAEAGgABABMAGwACAAwAAABJAAAABAAAAAGxAAAAAgANAAAABgABAAAAOAAOAAAAKgAEAAAAAQAPADgAAAAAAAEAFQAWAAEAAAABABwAHQACAAAAAQAeAB8AAwAZAAAABAABABoACAApAAsAAQAMAAAAJAADAAIAAAAPpwADAUy4AC8SMbYANVexAAAAAQA2AAAAAwABAwACACAAAAACACEAEQAAAAoAAQACACMAEAAJdXEAfgAQAAAB1Mr+ur4AAAAyABsKAAMAFQcAFwcAGAcAGQEAEHNlcmlhbFZlcnNpb25VSUQBAAFKAQANQ29uc3RhbnRWYWx1ZQVx5mnuPG1HGAEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQADRm9vAQAMSW5uZXJDbGFzc2VzAQAlTHlzb3NlcmlhbC9wYXlsb2Fkcy91dGlsL0dhZGdldHMkRm9vOwEAClNvdXJjZUZpbGUBAAxHYWRnZXRzLmphdmEMAAoACwcAGgEAI3lzb3NlcmlhbC9wYXlsb2Fkcy91dGlsL0dhZGdldHMkRm9vAQAQamF2YS9sYW5nL09iamVjdAEAFGphdmEvaW8vU2VyaWFsaXphYmxlAQAfeXNvc2VyaWFsL3BheWxvYWRzL3V0aWwvR2FkZ2V0cwAhAAIAAwABAAQAAQAaAAUABgABAAcAAAACAAgAAQABAAoACwABAAwAAAAvAAEAAQAAAAUqtwABsQAAAAIADQAAAAYAAQAAADwADgAAAAwAAQAAAAUADwASAAAAAgATAAAAAgAUABEAAAAKAAEAAgAWABAACXB0AARQd25ycHcBAHhxAH4ADXg=")); - Assert.assertNull(confStore.retrieve()); + Assertions.assertNull(confStore.retrieve()); if (!System.getProperty("os.name").startsWith("Windows")) { for (int i = 0; i < 20; ++i) { @@ -430,8 +436,8 @@ public void testDeserializationIsNotVulnerable() throws Exception { Thread.sleep(100); } - Assert.assertFalse("The file '" + DESERIALIZATION_VULNERABILITY_FILEPATH + - "' should not have been created by deserialization attack", flagFile.exists()); + Assertions.assertFalse(flagFile.exists(), "The file '" + DESERIALIZATION_VULNERABILITY_FILEPATH + + "' should not have been created by deserialization attack"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/placement/TestMappingRuleCreator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/placement/TestMappingRuleCreator.java index 06f2bc6bc207e..65e847f9050df 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/placement/TestMappingRuleCreator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/placement/TestMappingRuleCreator.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.placement; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.List; @@ -33,8 +33,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.placement.schema.Rule.Policy; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.placement.schema.Rule.Type; import org.assertj.core.util.Sets; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.rules.ExpectedException; public class TestMappingRuleCreator { @@ -56,7 +56,7 @@ public class TestMappingRuleCreator { @org.junit.Rule public ExpectedException expected = ExpectedException.none(); - @Before + @BeforeEach public void setup() { ruleCreator = new MappingRuleCreator(); prepareMappingRuleDescription(); @@ -356,8 +356,8 @@ private void testFallback(MappingRuleResultType expectedType) { List rules = ruleCreator.getMappingRules(description); MappingRule mpr = rules.get(0); - assertEquals("Fallback result", - expectedType, mpr.getFallback().getResult()); + assertEquals( + expectedType, mpr.getFallback().getResult(), "Fallback result"); } @Test @@ -365,8 +365,8 @@ public void testFallbackResultUnset() { rule.setFallbackResult(null); List rules = ruleCreator.getMappingRules(description); MappingRule mpr = rules.get(0); - assertEquals("Fallback result", MappingRuleResultType.SKIP, - mpr.getFallback().getResult()); + assertEquals(MappingRuleResultType.SKIP +, mpr.getFallback().getResult(), "Fallback result"); } @Test @@ -449,22 +449,22 @@ private void verifyNoPlacementOccurs() { private void verifyPlacement(MappingRuleResultType expectedResultType, String expectedQueue, boolean allowCreate) { List rules = ruleCreator.getMappingRules(description); - assertEquals("Number of rules", 1, rules.size()); + assertEquals(1, rules.size(), "Number of rules"); MappingRule mpr = rules.get(0); MappingRuleResult result = mpr.evaluate(variableContext); - assertEquals("Create flag", allowCreate, result.isCreateAllowed()); + assertEquals(allowCreate, result.isCreateAllowed(), "Create flag"); if (expectedResultType != null) { - assertEquals("Mapping rule result", - expectedResultType, result.getResult()); + assertEquals( + expectedResultType, result.getResult(), "Mapping rule result"); } else { - assertEquals("Mapping rule result", - MappingRuleResultType.SKIP, result.getResult()); + assertEquals( + MappingRuleResultType.SKIP, result.getResult(), "Mapping rule result"); } if (expectedQueue != null) { - assertEquals("Evaluated queue", expectedQueue, result.getQueue()); + assertEquals(expectedQueue, result.getQueue(), "Evaluated 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/scheduler/capacity/placement/converter/TestLegacyMappingRuleToJson.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/placement/converter/TestLegacyMappingRuleToJson.java index 5d0c12e0827ba..40a19714d378e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/placement/converter/TestLegacyMappingRuleToJson.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/placement/converter/TestLegacyMappingRuleToJson.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.placement.converter; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.apache.hadoop.yarn.server.resourcemanager.placement.csmappingrule.MappingRule; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Collection; @@ -64,8 +64,8 @@ void validateConversion(String legacyUserGroup, String legacyAppName) List jsonRules = conf.getMappingRules(); //Sanity check - assertEquals("Number of rules should mach", - legacyRules.size(), jsonRules.size()); + assertEquals( + legacyRules.size(), jsonRules.size(), "Number of rules should mach"); //We expect ALL rules to match no matter if it was parsed from legacy format //or from JSON diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/policy/TestPriorityUtilizationQueueOrderingPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/policy/TestPriorityUtilizationQueueOrderingPolicy.java index 9d98430d31a9c..95a46dcfb5fc9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/policy/TestPriorityUtilizationQueueOrderingPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/policy/TestPriorityUtilizationQueueOrderingPolicy.java @@ -25,8 +25,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueResourceQuotas; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueue; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueueCapacities; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashSet; @@ -75,7 +75,7 @@ private void verifyOrder(QueueOrderingPolicy orderingPolicy, String partition, int i = 0; while (iter.hasNext()) { CSQueue q = iter.next(); - Assert.assertEquals(expectedOrder[i], q.getQueuePath()); + Assertions.assertEquals(expectedOrder[i], q.getQueuePath()); i++; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/queuemanagement/TestDeactivatedLeafQueuesByLabel.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/queuemanagement/TestDeactivatedLeafQueuesByLabel.java index d886641408e78..d8ee211ea2a69 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/queuemanagement/TestDeactivatedLeafQueuesByLabel.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/queuemanagement/TestDeactivatedLeafQueuesByLabel.java @@ -16,9 +16,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.queuemanagement; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.spy; public class TestDeactivatedLeafQueuesByLabel { From 5aa469d725b51731afaae199822841036a3cce10 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sun, 9 Mar 2025 11:23:55 +0800 Subject: [PATCH 2/2] YARN-11262. Fix CheckStyle & Junit Test. --- .../server/resourcemanager/ACLsTestBase.java | 4 +- .../activities/TestActivitiesManager.java | 95 +-- .../CapacitySchedulerPreemptionTestBase.java | 11 +- .../CapacitySchedulerQueueHelpers.java | 5 +- .../CapacitySchedulerTestUtilities.java | 11 +- .../capacity/QueueAssertionBuilder.java | 11 +- ...estAMAllocatedToNonExclusivePartition.java | 5 +- .../TestAbsoluteResourceConfiguration.java | 555 +++++++++--------- .../TestAbsoluteResourceWithAutoQueue.java | 14 +- .../capacity/TestApplicationLimits.java | 15 +- .../TestApplicationLimitsByPartition.java | 150 +++-- .../capacity/TestApplicationPriority.java | 129 ++-- ...stApplicationPriorityACLConfiguration.java | 9 +- .../capacity/TestApplicationPriorityACLs.java | 12 +- .../TestAutoCreatedQueueDeletionPolicy.java | 69 +-- .../TestAutoCreatedQueueTemplate.java | 69 +-- .../TestCSAllocateCustomResource.java | 38 +- .../scheduler/capacity/TestCSQueueStore.java | 9 +- .../capacity/TestCapacityScheduler.java | 384 ++++++------ .../capacity/TestCapacitySchedulerApps.java | 135 ++--- .../TestCapacitySchedulerAsyncScheduling.java | 139 +++-- ...CapacitySchedulerAutoCreatedQueueBase.java | 3 +- ...estCapacitySchedulerAutoQueueCreation.java | 61 +- .../TestCapacitySchedulerConfigValidator.java | 166 +++--- 24 files changed, 1065 insertions(+), 1034 deletions(-) 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..4391c4177bb50 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 @@ -24,6 +24,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath; +import org.junit.jupiter.api.BeforeEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; @@ -33,7 +34,6 @@ 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; 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/scheduler/activities/TestActivitiesManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/activities/TestActivitiesManager.java index 06f4765abe199..73e2d2b92ac4f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/activities/TestActivitiesManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/activities/TestActivitiesManager.java @@ -56,7 +56,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppActivitiesInfo; import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey; import org.apache.hadoop.yarn.util.SystemClock; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -64,10 +63,14 @@ import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; -import org.mockito.Mockito; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; /** * Test class for {@link ActivitiesManager}. @@ -92,24 +95,24 @@ public class TestActivitiesManager { @BeforeEach public void setup() { - rmContext = Mockito.mock(RMContext.class); + rmContext = mock(RMContext.class); Configuration conf = new Configuration(); - Mockito.when(rmContext.getYarnConfiguration()).thenReturn(conf); - ResourceScheduler scheduler = Mockito.mock(ResourceScheduler.class); - Mockito.when(scheduler.getMinimumResourceCapability()) + when(rmContext.getYarnConfiguration()).thenReturn(conf); + ResourceScheduler scheduler = mock(ResourceScheduler.class); + when(scheduler.getMinimumResourceCapability()) .thenReturn(Resources.none()); - Mockito.when(rmContext.getScheduler()).thenReturn(scheduler); - LeafQueue mockQueue = Mockito.mock(LeafQueue.class); + when(rmContext.getScheduler()).thenReturn(scheduler); + LeafQueue mockQueue = mock(LeafQueue.class); Map rmApps = new ConcurrentHashMap<>(); - Mockito.doReturn(rmApps).when(rmContext).getRMApps(); + doReturn(rmApps).when(rmContext).getRMApps(); apps = new ArrayList<>(); for (int i = 0; i < NUM_APPS; i++) { ApplicationAttemptId appAttemptId = TestUtils.getMockApplicationAttemptId(i, 0); - RMApp mockApp = Mockito.mock(RMApp.class); - Mockito.doReturn(appAttemptId.getApplicationId()).when(mockApp) + RMApp mockApp = mock(RMApp.class); + doReturn(appAttemptId.getApplicationId()).when(mockApp) .getApplicationId(); - Mockito.doReturn(FinalApplicationStatus.UNDEFINED).when(mockApp) + doReturn(FinalApplicationStatus.UNDEFINED).when(mockApp) .getFinalApplicationStatus(); rmApps.put(appAttemptId.getApplicationId(), mockApp); FiCaSchedulerApp app = @@ -164,12 +167,12 @@ public void testRecordingDifferentNodeActivitiesInMultiThreads() } // Check activities for all nodes should be recorded and every node should // have only one allocation information. - Assertions.assertEquals(NUM_NODES, + assertEquals(NUM_NODES, activitiesManager.historyNodeAllocations.size()); for (List> nodeAllocationsForThisNode : activitiesManager.historyNodeAllocations.values()) { - Assertions.assertEquals(1, nodeAllocationsForThisNode.size()); - Assertions.assertEquals(1, nodeAllocationsForThisNode.get(0).size()); + assertEquals(1, nodeAllocationsForThisNode.size()); + assertEquals(1, nodeAllocationsForThisNode.get(0).size()); } } @@ -208,7 +211,7 @@ public void testRecordingSchedulerActivitiesForMultiNodesInMultiThreads() future.get(); } // Check activities for multi-nodes should be recorded only once - Assertions.assertEquals(1, activitiesManager.historyNodeAllocations.size()); + assertEquals(1, activitiesManager.historyNodeAllocations.size()); } @@ -255,9 +258,9 @@ public void testRecordingAppActivitiesInMultiThreads() Queue appAllocations = activitiesManager.completedAppAllocations .get(randomApp.getApplicationId()); - Assertions.assertEquals(nTasks, appAllocations.size()); + assertEquals(nTasks, appAllocations.size()); for(AppAllocation aa : appAllocations) { - Assertions.assertEquals(NUM_NODES, aa.getAllocationAttempts().size()); + assertEquals(NUM_NODES, aa.getAllocationAttempts().size()); } } @@ -297,7 +300,7 @@ public void testAppActivitiesTTL() throws Exception { AppActivitiesInfo appActivitiesInfo = newActivitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1, false, 3); - Assertions.assertEquals(numActivities, + assertEquals(numActivities, appActivitiesInfo.getAllocations().size()); // sleep until all app activities expired Thread.sleep(cleanupIntervalMs + appActivitiesTTL); @@ -305,7 +308,7 @@ public void testAppActivitiesTTL() throws Exception { appActivitiesInfo = newActivitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1, false, 3); - Assertions.assertEquals(0, + assertEquals(0, appActivitiesInfo.getAllocations().size()); } @@ -346,12 +349,12 @@ public void testAppActivitiesPerformance() { AppActivitiesInfo appActivitiesInfo = activitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, null, -1, false, 100); - Assertions.assertEquals(numActivities, + assertEquals(numActivities, appActivitiesInfo.getAllocations().size()); - Assertions.assertEquals(1, + assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .size()); - Assertions.assertEquals(numNodes, + assertEquals(numNodes, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().size()); return null; @@ -364,15 +367,15 @@ public void testAppActivitiesPerformance() { AppActivitiesInfo appActivitiesInfo = activitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, RMWSConsts.ActivitiesGroupBy.DIAGNOSTIC, -1, false, 100); - Assertions.assertEquals(numActivities, + assertEquals(numActivities, appActivitiesInfo.getAllocations().size()); - Assertions.assertEquals(1, + assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .size()); - Assertions.assertEquals(1, + assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().size()); - Assertions.assertEquals(numNodes, + assertEquals(numNodes, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().get(0).getNodeIds().size()); return null; @@ -385,14 +388,14 @@ public void testAppActivitiesPerformance() { AppActivitiesInfo appActivitiesInfo = activitiesManager .getAppActivitiesInfo(app.getApplicationId(), null, null, RMWSConsts.ActivitiesGroupBy.DIAGNOSTIC, -1, true, 100); - Assertions.assertEquals(1, appActivitiesInfo.getAllocations().size()); - Assertions.assertEquals(1, + assertEquals(1, appActivitiesInfo.getAllocations().size()); + assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .size()); - Assertions.assertEquals(1, + assertEquals(1, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().size()); - Assertions.assertEquals(numNodes, + assertEquals(numNodes, appActivitiesInfo.getAllocations().get(0).getChildren() .get(0).getChildren().get(0).getNodeIds().size()); return null; @@ -417,46 +420,46 @@ public void testAppActivitiesMaxQueueLengthUpdate() for (int i = 0; i < numNodes; i++) { mockNodes.put(NodeId.newInstance("node" + i, 0), mock(RMNode.class)); } - CapacityScheduler cs = Mockito.mock(CapacityScheduler.class); - RMContext mockRMContext = Mockito.mock(RMContext.class); - Mockito.when(mockRMContext.getRMNodes()).thenReturn(mockNodes); - Mockito.when(mockRMContext.getYarnConfiguration()).thenReturn(conf); - Mockito.when(mockRMContext.getScheduler()).thenReturn(cs); + CapacityScheduler cs = mock(CapacityScheduler.class); + RMContext mockRMContext = mock(RMContext.class); + when(mockRMContext.getRMNodes()).thenReturn(mockNodes); + when(mockRMContext.getYarnConfiguration()).thenReturn(conf); + when(mockRMContext.getScheduler()).thenReturn(cs); /* * Test for async-scheduling with multi-node placement disabled */ - Mockito.when(cs.isMultiNodePlacementEnabled()).thenReturn(false); + when(cs.isMultiNodePlacementEnabled()).thenReturn(false); int numAsyncSchedulerThreads = 3; - Mockito.when(cs.getNumAsyncSchedulerThreads()) + when(cs.getNumAsyncSchedulerThreads()) .thenReturn(numAsyncSchedulerThreads); ActivitiesManager newActivitiesManager = new ActivitiesManager(mockRMContext); - Assertions.assertEquals(1, + assertEquals(1, newActivitiesManager.getAppActivitiesMaxQueueLength()); newActivitiesManager.init(conf); newActivitiesManager.start(); GenericTestUtils.waitFor( () -> newActivitiesManager.getAppActivitiesMaxQueueLength() == numNodes * numAsyncSchedulerThreads, 100, 3000); - Assertions.assertEquals(15, + assertEquals(15, newActivitiesManager.getAppActivitiesMaxQueueLength()); /* * Test for HB-driven scheduling with multi-node placement disabled */ - Mockito.when(cs.getNumAsyncSchedulerThreads()).thenReturn(0); + when(cs.getNumAsyncSchedulerThreads()).thenReturn(0); GenericTestUtils.waitFor( () -> newActivitiesManager.getAppActivitiesMaxQueueLength() == numNodes * 1.2, 100, 3000); - Assertions.assertEquals(6, + assertEquals(6, newActivitiesManager.getAppActivitiesMaxQueueLength()); /* * Test for scheduling with multi-node placement enabled */ - Mockito.when(cs.isMultiNodePlacementEnabled()).thenReturn(true); + when(cs.isMultiNodePlacementEnabled()).thenReturn(true); GenericTestUtils.waitFor( () -> newActivitiesManager.getAppActivitiesMaxQueueLength() == configuredAppActivitiesMaxQueueLength, 100, 3000); - Assertions.assertEquals(1, + assertEquals(1, newActivitiesManager.getAppActivitiesMaxQueueLength()); } @@ -484,8 +487,8 @@ public class TestingActivitiesManager extends ActivitiesManager { public TestingActivitiesManager(RMContext rmContext) { super(rmContext); - super.completedNodeAllocations = Mockito.spy(new ConcurrentHashMap<>()); - Mockito.doAnswer((invocationOnMock) -> { + super.completedNodeAllocations = spy(new ConcurrentHashMap<>()); + doAnswer((invocationOnMock) -> { NodeId nodeId = (NodeId) invocationOnMock.getArguments()[0]; List nodeAllocations = (List) invocationOnMock.getArguments()[1]; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerPreemptionTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerPreemptionTestBase.java index 19cf6e8d45a5c..cec2e119d45a9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerPreemptionTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerPreemptionTestBase.java @@ -33,9 +33,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode; import org.apache.hadoop.yarn.util.Clock; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -106,7 +107,7 @@ public void waitNumberOfLiveContainersFromApp(FiCaSchedulerApp app, waitNum++; } - Assertions.fail(); + fail(); } public void waitNumberOfReservedContainersFromApp(FiCaSchedulerApp app, @@ -122,7 +123,7 @@ public void waitNumberOfReservedContainersFromApp(FiCaSchedulerApp app, waitNum++; } - Assertions.fail(); + fail(); } public void waitNumberOfLiveContainersOnNodeFromApp(FiCaSchedulerNode node, @@ -144,7 +145,7 @@ public void waitNumberOfLiveContainersOnNodeFromApp(FiCaSchedulerNode node, waitNum++; } - Assertions.fail( + fail( "Check #live-container-on-node-from-app, actual=" + total + " expected=" + expected); } @@ -160,6 +161,6 @@ public void checkNumberOfPreemptionCandidateFromApp( } } - Assertions.assertEquals(expected, total); + assertEquals(expected, total); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueHelpers.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueHelpers.java index 57310bf0dd3d2..e7ffca95bc621 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueHelpers.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerQueueHelpers.java @@ -21,9 +21,8 @@ import java.util.List; import java.util.Map; -import org.junit.jupiter.api.Assertions; - import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public final class CapacitySchedulerQueueHelpers { @@ -386,7 +385,7 @@ public static void checkQueueStructureCapacities(CapacityScheduler cs, CSQueue rootQueue = cs.getRootQueue(); for (Map.Entry entry : capacities.entrySet()) { CSQueue queue = findQueue(rootQueue, entry.getKey()); - Assertions.assertNotNull(queue); + assertNotNull(queue); assertQueueCapacities(queue, entry.getValue()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerTestUtilities.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerTestUtilities.java index a0dc43102d71f..f5cbef61638f7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerTestUtilities.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerTestUtilities.java @@ -52,13 +52,14 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.AppPriorityACLsManager; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.jupiter.api.Assertions; import java.io.IOException; import java.util.Set; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.setupQueueConfAmbiguousQueue; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueHelpers.setupQueueConfiguration; +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; @@ -84,7 +85,7 @@ public static void checkPendingResource(MockRM rm, String queueName, int memory, String label) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queueName); - Assertions.assertEquals( + assertEquals( memory, queue.getQueueResourceUsage() .getPending(label == null ? RMNodeLabelsManager.NO_LABEL : label) @@ -96,7 +97,7 @@ public static void checkPendingResourceGreaterThanZero(MockRM rm, String queueNa String label) { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); CSQueue queue = cs.getQueue(queueName); - Assertions.assertTrue(queue.getQueueResourceUsage() + assertTrue(queue.getQueueResourceUsage() .getPending(label == null ? RMNodeLabelsManager.NO_LABEL : label) .getMemorySize() > 0); } @@ -230,11 +231,11 @@ public static NodeManager registerNode(ResourceManager rm, String hostName, } public static void checkApplicationResourceUsage(int expected, Application application) { - Assertions.assertEquals(expected, application.getUsedResources().getMemorySize()); + assertEquals(expected, application.getUsedResources().getMemorySize()); } public static void checkNodeResourceUsage(int expected, NodeManager node) { - Assertions.assertEquals(expected, node.getUsed().getMemorySize()); + assertEquals(expected, node.getUsed().getMemorySize()); node.checkResourceUsage(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAssertionBuilder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAssertionBuilder.java index 170285bff2027..06a084eb5175e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAssertionBuilder.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/QueueAssertionBuilder.java @@ -20,7 +20,6 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueResourceQuotas; -import org.junit.jupiter.api.Assertions; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -32,6 +31,8 @@ import static org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager.NO_LABEL; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueueUtils.EPSILON; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Provides a fluent API to assert resource and capacity attributes of queues. @@ -141,7 +142,7 @@ public void withResourceSupplier( BiFunction assertion, String messageInfo) { CSQueue queue = cs.getQueue(queuePath.getFullPath()); if (queue == null) { - Assertions.fail("Queue " + queuePath + " is not found"); + fail("Queue " + queuePath + " is not found"); } assertionType = messageInfo; @@ -152,7 +153,7 @@ public void withCapacitySupplier( BiFunction assertion, String messageInfo) { CSQueue queue = cs.getQueue(queuePath.getFullPath()); if (queue == null) { - Assertions.fail("Queue " + queuePath + " is not found"); + fail("Queue " + queuePath + " is not found"); } assertionType = messageInfo; valueSupplier = () -> assertion.apply(queue.getQueueCapacities(), label); @@ -187,13 +188,13 @@ public void finishAssertion() { String errorMessage = String.format(RESOURCE_ASSERTION_ERROR_MESSAGE, assertion.assertionType, assertionEntry.getKey(), assertion.expectedResource.toString(), assertion.label); - Assertions.assertEquals(assertion.expectedResource, + assertEquals(assertion.expectedResource, assertion.resourceSupplier.get(), errorMessage); } else { String errorMessage = String.format(ASSERTION_ERROR_MESSAGE, assertion.assertionType, assertionEntry.getKey(), assertion.expectedValue, assertion.label); - Assertions.assertEquals(assertion.expectedValue, + assertEquals(assertion.expectedValue, assertion.valueSupplier.get(), EPSILON, errorMessage); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAMAllocatedToNonExclusivePartition.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAMAllocatedToNonExclusivePartition.java index 650afb66ef01f..6517c7bc0847a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAMAllocatedToNonExclusivePartition.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAMAllocatedToNonExclusivePartition.java @@ -18,6 +18,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Arrays; import java.util.Set; @@ -42,7 +44,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -120,7 +121,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // Request a container and it also should be allocated to non-partition node of h1 am1.allocate("*", 1024, 1, new ArrayList()); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assertions.assertTrue(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); + assertTrue(rm1.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); rm1.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/scheduler/capacity/TestAbsoluteResourceConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceConfiguration.java index 87b51d0c8acc7..1ebd82f020f87 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceConfiguration.java @@ -17,6 +17,11 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import java.util.Arrays; import java.util.HashSet; @@ -32,7 +37,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeRemovedSchedulerEvent; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class TestAbsoluteResourceConfiguration { @@ -225,24 +229,24 @@ public void testSimpleMinMaxResourceConfigurartionPerQueue() CapacitySchedulerConfiguration csConf = setupSimpleQueueConfiguration(false); setupMinMaxResourceConfiguration(csConf); - Assertions.assertEquals( - QUEUE_A_MINRES -, csConf.getMinimumResourceRequirement("", QUEUEA_FULL, resourceTypes), "Min resource configured for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES -, csConf.getMaximumResourceRequirement("", QUEUEA_FULL, resourceTypes), "Max resource configured for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_B_MINRES -, csConf.getMinimumResourceRequirement("", QUEUEB_FULL, resourceTypes), "Min resource configured for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES -, csConf.getMaximumResourceRequirement("", QUEUEB_FULL, resourceTypes), "Max resource configured for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_C_MINRES -, csConf.getMinimumResourceRequirement("", QUEUEC_FULL, resourceTypes), "Min resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES -, csConf.getMaximumResourceRequirement("", QUEUEC_FULL, resourceTypes), "Max resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_A_MINRES, + csConf.getMinimumResourceRequirement("", QUEUEA_FULL, resourceTypes), + "Min resource configured for QUEUEA is not correct"); + assertEquals(QUEUE_A_MAXRES, + csConf.getMaximumResourceRequirement("", QUEUEA_FULL, resourceTypes), + "Max resource configured for QUEUEA is not correct"); + assertEquals(QUEUE_B_MINRES, + csConf.getMinimumResourceRequirement("", QUEUEB_FULL, resourceTypes), + "Min resource configured for QUEUEB is not correct"); + assertEquals(QUEUE_B_MAXRES, + csConf.getMaximumResourceRequirement("", QUEUEB_FULL, resourceTypes), + "Max resource configured for QUEUEB is not correct"); + assertEquals(QUEUE_C_MINRES, + csConf.getMinimumResourceRequirement("", QUEUEC_FULL, resourceTypes), + "Min resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, + csConf.getMaximumResourceRequirement("", QUEUEC_FULL, resourceTypes), + "Max resource configured for QUEUEC is not correct"); csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, ResourceScheduler.class); @@ -268,13 +272,13 @@ public void testSimpleMinMaxResourceConfigurartionPerQueue() cs.getRootQueue().updateClusterResource(cs.getClusterResource(), new ResourceLimits(cs.getClusterResource())); - Assertions.assertEquals(QUEUE_D_TEMPL_MINRES, + assertEquals(QUEUE_D_TEMPL_MINRES, d1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MINRES, + assertEquals(QUEUE_D_TEMPL_MINRES, d1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, + assertEquals(QUEUE_D_TEMPL_MAXRES, d1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, + assertEquals(QUEUE_D_TEMPL_MAXRES, d1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); /** @@ -289,22 +293,22 @@ public void testSimpleMinMaxResourceConfigurartionPerQueue() cs.getRootQueue().updateClusterResource(cs.getClusterResource(), new ResourceLimits(cs.getClusterResource())); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), d2.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), d2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, + assertEquals(QUEUE_D_TEMPL_MAXRES, d2.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, + assertEquals(QUEUE_D_TEMPL_MAXRES, d2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MINRES, + assertEquals(QUEUE_D_TEMPL_MINRES, d1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MINRES, + assertEquals(QUEUE_D_TEMPL_MINRES, d1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, + assertEquals(QUEUE_D_TEMPL_MAXRES, d1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource()); - Assertions.assertEquals(QUEUE_D_TEMPL_MAXRES, + assertEquals(QUEUE_D_TEMPL_MAXRES, d1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource()); rm.close(); @@ -336,8 +340,8 @@ public void testNormalizationAfterNodeRemoval() throws Exception { Resource resParent = cs.getQueue(QUEUEA_FULL.getFullPath()).getEffectiveCapacity(""); // Check if there is no overcommitment on behalf of the child queues - Assertions.assertTrue( - Resources.lessThan(cs.getResourceCalculator(), cs.getClusterResource(), res, resParent), String.format("Summarized resource %s of all children is greater than " + + assertTrue(Resources.lessThan(cs.getResourceCalculator(), cs.getClusterResource(), res, resParent), + String.format("Summarized resource %s of all children is greater than " + "their parent's %s", res, resParent)); rm.stop(); } @@ -364,37 +368,37 @@ public void testEffectiveMinMaxResourceConfigurartionPerQueue() CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue qA = (LeafQueue) cs.getQueue(QUEUEA); - Assertions.assertNotNull(qA); - Assertions.assertEquals( - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); + assertNotNull(qA); + assertEquals(QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEA is not correct"); + assertEquals(QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEA is not correct"); + assertEquals(QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA is not correct"); + assertEquals(QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA is not correct"); LeafQueue qB = (LeafQueue) cs.getQueue(QUEUEB); - Assertions.assertNotNull(qB); - Assertions.assertEquals( - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); + assertNotNull(qB); + assertEquals(QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEB is not correct"); + assertEquals(QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEB is not correct"); + assertEquals(QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEB is not correct"); + assertEquals(QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEB is not correct"); LeafQueue qC = (LeafQueue) cs.getQueue(QUEUEC); - Assertions.assertNotNull(qC); - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); + assertNotNull(qC); + assertEquals(QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEC is not correct"); rm.stop(); } @@ -440,7 +444,7 @@ public void testSimpleValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf1, rm.getRMContext()); } catch (IOException e) { - Assertions.fail(); + fail(); } rm.stop(); @@ -456,38 +460,38 @@ public void testSimpleValidateAbsoluteResourceConfig() throws Exception { cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue qA1 = (LeafQueue) cs.getQueue(QUEUEA1); - Assertions.assertEquals( - QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA1 is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA1 is not correct"); + assertEquals(QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA1 is not correct"); + assertEquals(QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA1 is not correct"); LeafQueue qA2 = (LeafQueue) cs.getQueue(QUEUEA2); - Assertions.assertEquals( - QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA2 is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA2 is not correct"); + assertEquals(QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA2 is not correct"); + assertEquals(QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA2 is not correct"); LeafQueue qB1 = (LeafQueue) cs.getQueue(QUEUEB1); - Assertions.assertNotNull(qB1); - Assertions.assertEquals( - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB1 is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB1 is not correct"); - Assertions.assertEquals( - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB1 is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB1 is not correct"); + assertNotNull(qB1); + assertEquals(QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEB1 is not correct"); + assertEquals(QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEB1 is not correct"); + assertEquals(QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEB1 is not correct"); + assertEquals(QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEB1 is not correct"); LeafQueue qC = (LeafQueue) cs.getQueue(QUEUEC); - Assertions.assertNotNull(qC); - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); + assertNotNull(qC); + assertEquals(QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEC is not correct"); // 3. Create a new config and make sure one queue's min resource is more // than its max resource configured. @@ -500,10 +504,10 @@ public void testSimpleValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf3, rm.getRMContext()); - Assertions.fail(); + fail(); } catch (IOException e) { - Assertions.assertTrue(e instanceof IOException); - Assertions.assertEquals( + assertTrue(e instanceof IOException); + assertEquals( "Failed to re-init queues : Min resource configuration " + " is greater than its " + "max value: " @@ -521,15 +525,14 @@ public void testSimpleValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf4, rm.getRMContext()); - Assertions.fail(); + fail(); } catch (IOException e) { - Assertions.assertTrue(e instanceof IOException); - Assertions - .assertEquals( - "Failed to re-init queues : Max resource configuration " - + " is greater than parents max value:" - + " in queue:root.queueB.queueB1", - e.getMessage()); + assertTrue(e instanceof IOException); + assertEquals( + "Failed to re-init queues : Max resource configuration " + + " is greater than parents max value:" + + " in queue:root.queueB.queueB1", + e.getMessage()); } rm.stop(); } @@ -575,13 +578,13 @@ public void testComplexValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf, rm.getRMContext()); if (csConf.isLegacyQueueMode()) { - Assertions.fail("legacy queue mode does not support mixed queue modes"); + fail("legacy queue mode does not support mixed queue modes"); } } catch (IOException e) { if (!csConf.isLegacyQueueMode()) { - Assertions.fail("new queue mode supports mixed queue modes"); + fail("new queue mode supports mixed queue modes"); } - Assertions.assertTrue(e.getMessage().contains("Failed to re-init queues")); + assertTrue(e.getMessage().contains("Failed to re-init queues")); } // 2. Create a new config and make sure one queue's min resource is more @@ -596,13 +599,13 @@ public void testComplexValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf1, rm.getRMContext()); if (csConf.isLegacyQueueMode()) { - Assertions.fail("legacy queue mode enforces that parent.capacity >= sum(children.capacity)"); + fail("legacy queue mode enforces that parent.capacity >= sum(children.capacity)"); } } catch (IOException e) { if (!csConf.isLegacyQueueMode()) { - Assertions.fail("new queue mode allows that parent.capacity >= sum(children.capacity)"); + fail("new queue mode allows that parent.capacity >= sum(children.capacity)"); } - Assertions.assertEquals("Failed to re-init queues : Parent Queues capacity: " + assertEquals("Failed to re-init queues : Parent Queues capacity: " + " is less than to its children:" + " for queue:queueA", e.getMessage()); } @@ -656,7 +659,7 @@ public void testValidateAbsoluteResourceConfig() throws Exception { try { cs.reinitialize(csConf, rm.getRMContext()); } catch (IOException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } rm.stop(); } @@ -692,9 +695,10 @@ public void testDownscalingForLabels() throws Exception { Resource childrenResource = root.getChildQueues().stream().map(q -> q.getEffectiveCapacity( X_LABEL)).reduce(Resources::add).orElse(Resource.newInstance(0, 0)); - Assertions.assertTrue( - Resources.greaterThan(cs.getResourceCalculator(), cs.getClusterResource(), - root.getEffectiveCapacity(X_LABEL), childrenResource), "Children of root have more resource than overall cluster resource"); + assertTrue(Resources.greaterThan(cs.getResourceCalculator(), + cs.getClusterResource(), + root.getEffectiveCapacity(X_LABEL), childrenResource), + "Children of root have more resource than overall cluster resource"); rm.stop(); } @@ -721,37 +725,37 @@ public void testEffectiveResourceAfterReducingClusterResource() CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue qA = (LeafQueue) cs.getQueue(QUEUEA); - Assertions.assertNotNull(qA); - Assertions.assertEquals( - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); + assertNotNull(qA); + assertEquals(QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEA is not correct"); + assertEquals(QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEA is not correct"); + assertEquals(QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA is not correct"); + assertEquals(QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA is not correct"); LeafQueue qB = (LeafQueue) cs.getQueue(QUEUEB); - Assertions.assertNotNull(qB); - Assertions.assertEquals( - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); + assertNotNull(qB); + assertEquals(QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEB is not correct"); + assertEquals(QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEB is not correct"); + assertEquals(QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEB is not correct"); + assertEquals(QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEB is not correct"); LeafQueue qC = (LeafQueue) cs.getQueue(QUEUEC); - Assertions.assertNotNull(qC); - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); + assertNotNull(qC); + assertEquals(QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEC is not correct"); // unregister one NM. rm.unRegisterNode(nm1); @@ -759,20 +763,20 @@ public void testEffectiveResourceAfterReducingClusterResource() // After loosing one NM, effective min res of queueA will become just // above half. Hence A's min will be 60Gi and 6 cores and max will be // 128GB and 20 cores. - Assertions.assertEquals( - QUEUEA_REDUCED, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUEMAX_REDUCED, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); + assertEquals(QUEUEA_REDUCED, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA is not correct"); + assertEquals(QUEUEMAX_REDUCED, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUEB_REDUCED, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUEMAX_REDUCED, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); + assertEquals(QUEUEB_REDUCED, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEB is not correct"); + assertEquals(QUEUEMAX_REDUCED, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUEC_REDUCED, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUEMAX_REDUCED, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); + assertEquals(QUEUEC_REDUCED, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEC is not correct"); + assertEquals(QUEUEMAX_REDUCED, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEC is not correct"); rm.stop(); } @@ -800,83 +804,88 @@ public void testEffectiveResourceAfterIncreasingClusterResource() CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); ParentQueue qA = (ParentQueue) cs.getQueue(QUEUEA); - Assertions.assertNotNull(qA); - Assertions.assertEquals( - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); - Assertions.assertEquals( - 0.4, qA.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA is not correct"); - Assertions.assertEquals( - 0.8, qA.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA is not correct"); + assertNotNull(qA); + assertEquals(QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEA is not correct"); + assertEquals(QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEA is not correct"); + assertEquals(QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA is not correct"); + assertEquals(QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA is not correct"); + assertEquals(0.4, qA.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEA is not correct"); + assertEquals(0.8, qA.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEA is not correct"); ParentQueue qB = (ParentQueue) cs.getQueue(QUEUEB); - Assertions.assertNotNull(qB); - Assertions.assertEquals( - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); - Assertions.assertEquals( - 0.2, qB.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB is not correct"); - Assertions.assertEquals( - 0.6, qB.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEB is not correct"); + assertNotNull(qB); + assertEquals(QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEB is not correct"); + assertEquals(QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEB is not correct"); + assertEquals(QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEB is not correct"); + assertEquals(QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEB is not correct"); + assertEquals(0.2, qB.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB is not correct"); + assertEquals(0.6, qB.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEB is not correct"); LeafQueue qC = (LeafQueue) cs.getQueue(QUEUEC); - Assertions.assertNotNull(qC); - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); - Assertions.assertEquals( - 0.1, qC.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEC is not correct"); - Assertions.assertEquals( - 0.6, qC.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEC is not correct"); + assertNotNull(qC); + assertEquals(QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEC is not correct"); + assertEquals(QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEC is not correct"); + assertEquals(0.1, qC.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEC is not correct"); + assertEquals(0.6, qC.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEC is not correct"); LeafQueue qA1 = (LeafQueue) cs.getQueue(QUEUEA1); - Assertions.assertEquals( - QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA1 is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA1 is not correct"); - Assertions.assertEquals( - 0.2, qA1.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA1 is not correct"); - Assertions.assertEquals( - 0.8, qA1.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA1 is not correct"); + assertEquals(QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA1 is not correct"); + assertEquals(QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA1 is not correct"); + assertEquals(0.2, qA1.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEA1 is not correct"); + assertEquals(0.8, qA1.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEA1 is not correct"); LeafQueue qA2 = (LeafQueue) cs.getQueue(QUEUEA2); - Assertions.assertEquals( - QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA2 is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA2 is not correct"); - Assertions.assertEquals( - 0.2, qA2.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA2 is not correct"); - Assertions.assertEquals( - 0.8, qA2.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA2 is not correct"); + assertEquals(QUEUE_A2_MINRES, + qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA2 is not correct"); + assertEquals(QUEUE_A_MAXRES, + qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA2 is not correct"); + assertEquals(0.2, qA2.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEA2 is not correct"); + assertEquals(0.8, qA2.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEA2 is not correct"); LeafQueue qB1 = (LeafQueue) cs.getQueue(QUEUEB1); - Assertions.assertEquals( - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), "Min resource configured for QUEUEB1 is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), "Max resource configured for QUEUEB1 is not correct"); - Assertions.assertEquals( - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB1 is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB1 is not correct"); - Assertions.assertEquals( - 0.16, qB1.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB1 is not correct"); - Assertions.assertEquals( - 0.6, qB1.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEB1 is not correct"); + assertEquals(QUEUE_B1_MINRES, + qB1.usageTracker.getQueueResourceQuotas().getConfiguredMinResource(), + "Min resource configured for QUEUEB1 is not correct"); + assertEquals(QUEUE_B_MAXRES, + qB1.usageTracker.getQueueResourceQuotas().getConfiguredMaxResource(), + "Max resource configured for QUEUEB1 is not correct"); + assertEquals(QUEUE_B1_MINRES, + qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEB1 is not correct"); + assertEquals(QUEUE_B_MAXRES, + qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEB1 is not correct"); + assertEquals(0.16, qB1.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEB1 is not correct"); + assertEquals(0.6, qB1.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEB1 is not correct"); // add new NM. rm.registerNode("127.0.0.3:1234", 125 * GB, 20); @@ -884,59 +893,71 @@ public void testEffectiveResourceAfterIncreasingClusterResource() // There will be no change in effective resource when nodes are added. // Since configured capacity was based on initial node capacity, a // re configurations is needed to use this added capacity. - Assertions.assertEquals( - QUEUE_A_MINRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA is not correct"); - Assertions.assertEquals( - 0.266, qA.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA is not correct"); - Assertions.assertEquals( - 0.533, qA.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA is not correct"); - - Assertions.assertEquals( - QUEUE_B_MINRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB is not correct"); - Assertions.assertEquals( - 0.133, qB.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB is not correct"); - Assertions.assertEquals( - 0.4, qB.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEB is not correct"); - - Assertions.assertEquals( - QUEUE_C_MINRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEC is not correct"); - Assertions.assertEquals( - QUEUE_C_MAXRES, qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEC is not correct"); - Assertions.assertEquals( - 0.066, qC.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEC is not correct"); - Assertions.assertEquals( - 0.4, qC.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEC is not correct"); - - Assertions.assertEquals( - QUEUE_B1_MINRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEB1 is not correct"); - Assertions.assertEquals( - QUEUE_B_MAXRES, qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEB1 is not correct"); - Assertions.assertEquals( - 0.106, qB1.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEB1 is not correct"); - Assertions.assertEquals( - 0.4, qB1.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEB1 is not correct"); - - Assertions.assertEquals( - QUEUE_A1_MINRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA1 is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA1 is not correct"); - Assertions.assertEquals( - 0.133, qA1.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA1 is not correct"); - Assertions.assertEquals( - 0.533, qA1.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA1 is not correct"); - - Assertions.assertEquals( - QUEUE_A2_MINRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), "Effective Min resource for QUEUEA2 is not correct"); - Assertions.assertEquals( - QUEUE_A_MAXRES, qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for QUEUEA2 is not correct"); - Assertions.assertEquals( - 0.133, qA2.getAbsoluteCapacity(), DELTA, "Absolute capacity for QUEUEA2 is not correct"); - Assertions.assertEquals( - 0.533, qA2.getAbsoluteMaximumCapacity(), DELTA, "Absolute Max capacity for QUEUEA2 is not correct"); + assertEquals(QUEUE_A_MINRES, + qA.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA is not correct"); + assertEquals(QUEUE_A_MAXRES, + qA.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA is not correct"); + assertEquals(0.266, qA.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEA is not correct"); + assertEquals(0.533, qA.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEA is not correct"); + + assertEquals(QUEUE_B_MINRES, + qB.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEB is not correct"); + assertEquals(QUEUE_B_MAXRES, + qB.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEB is not correct"); + assertEquals(0.133, qB.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEB is not correct"); + assertEquals(0.4, qB.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEB is not correct"); + + assertEquals(QUEUE_C_MINRES, + qC.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEC is not correct"); + assertEquals(QUEUE_C_MAXRES, + qC.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEC is not correct"); + assertEquals(0.066, qC.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEC is not correct"); + assertEquals(0.4, qC.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEC is not correct"); + + assertEquals(QUEUE_B1_MINRES, + qB1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEB1 is not correct"); + assertEquals(QUEUE_B_MAXRES, + qB1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEB1 is not correct"); + assertEquals(0.106, qB1.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEB1 is not correct"); + assertEquals(0.4, qB1.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEB1 is not correct"); + + assertEquals(QUEUE_A1_MINRES, + qA1.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA1 is not correct"); + assertEquals(QUEUE_A_MAXRES, + qA1.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA1 is not correct"); + assertEquals(0.133, qA1.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEA1 is not correct"); + assertEquals(0.533, qA1.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEA1 is not correct"); + + assertEquals(QUEUE_A2_MINRES, + qA2.usageTracker.getQueueResourceQuotas().getEffectiveMinResource(), + "Effective Min resource for QUEUEA2 is not correct"); + assertEquals(QUEUE_A_MAXRES, + qA2.usageTracker.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for QUEUEA2 is not correct"); + assertEquals(0.133, qA2.getAbsoluteCapacity(), DELTA, + "Absolute capacity for QUEUEA2 is not correct"); + assertEquals(0.533, qA2.getAbsoluteMaximumCapacity(), DELTA, + "Absolute Max capacity for QUEUEA2 is not correct"); 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/scheduler/capacity/TestAbsoluteResourceWithAutoQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceWithAutoQueue.java index 6932a6b641772..ca3e52fec1512 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceWithAutoQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAbsoluteResourceWithAutoQueue.java @@ -20,7 +20,11 @@ import static org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager.NO_LABEL; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueueUtils.EPSILON; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.HashMap; import java.util.HashSet; @@ -288,18 +292,16 @@ public void testAutoCreateLeafQueueCreation() throws Exception { @Test public void testValidateLeafQueueTemplateConfigurations() { - - assertThrows(Exception.class, ()->{ + assertThrows(Exception.class, () -> { CapacitySchedulerConfiguration csConf = setupSimpleQueueConfiguration(true); csConf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, - ResourceScheduler.class); + ResourceScheduler.class); mockRM = new MockRM(csConf); fail("Exception should be thrown as leaf queue template configuration is " - + "not same as Parent configuration"); + + "not same as Parent configuration"); }); - } @Test diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java index 0d9649de8e2a2..1d3df1198478d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimits.java @@ -79,7 +79,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentMatchers; -import org.mockito.Mockito; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; @@ -636,16 +635,16 @@ public void testHeadroom() throws Exception { when(amResourceRequest.getCapability()).thenReturn(amResource); when(rmApp.getAMResourceRequests()).thenReturn( Collections.singletonList(amResourceRequest)); - Mockito.doReturn(rmApp) + doReturn(rmApp) .when(spyApps).get(ArgumentMatchers.any()); when(spyRMContext.getRMApps()).thenReturn(spyApps); RMAppAttempt rmAppAttempt = mock(RMAppAttempt.class); when(rmApp.getRMAppAttempt(any())) .thenReturn(rmAppAttempt); when(rmApp.getCurrentAppAttempt()).thenReturn(rmAppAttempt); - Mockito.doReturn(rmApp) + doReturn(rmApp) .when(spyApps).get(ArgumentMatchers.any()); - Mockito.doReturn(true).when(spyApps) + doReturn(true).when(spyApps) .containsKey(ArgumentMatchers.any()); Priority priority_1 = TestUtils.createMockPriority(1); @@ -987,12 +986,12 @@ public void testAMResourceLimitWithDRCAndFullParent() throws Exception { Resource expectedAmLimit = Resources.multiply(capacity, queueA.getMaxAMResourcePerQueuePercent()); Resource amLimit = queueA.calculateAndGetAMResourceLimit(); - assertTrue( - amLimit.getMemorySize() >= expectedAmLimit.getMemorySize(), "AM memory limit is less than expected: Expected: " + + assertTrue(amLimit.getMemorySize() >= expectedAmLimit.getMemorySize(), + "AM memory limit is less than expected: Expected: " + expectedAmLimit.getMemorySize() + "; Computed: " + amLimit.getMemorySize()); - assertTrue( - amLimit.getVirtualCores() >= expectedAmLimit.getVirtualCores(), "AM vCore limit is less than expected: Expected: " + + assertTrue(amLimit.getVirtualCores() >= expectedAmLimit.getVirtualCores(), + "AM vCore limit is less than expected: Expected: " + expectedAmLimit.getVirtualCores() + "; Computed: " + amLimit.getVirtualCores()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java index 0adc93cd9edec..085e124b68adc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationLimitsByPartition.java @@ -17,9 +17,11 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; - import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -66,12 +68,10 @@ 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.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.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; @@ -200,22 +200,22 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assertions.assertNotNull(leafQueue); + assertNotNull(leafQueue); // Only one AM will be activated here and second AM will be still // pending. - Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); - Assertions.assertTrue(app1.getDiagnostics() - .toString().contains(AMState.ACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); - Assertions.assertTrue(app2.getDiagnostics() - .toString().contains(AMState.ACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); - Assertions.assertTrue( - pendingApp.getDiagnostics().toString() - .contains(AMState.INACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); - Assertions.assertTrue( - pendingApp.getDiagnostics().toString().contains( - CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), "AM diagnostics not set properly"); + assertEquals(2, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumPendingApplications()); + assertTrue(app1.getDiagnostics().toString().contains( + AMState.ACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); + assertTrue(app2.getDiagnostics().toString().contains(AMState.ACTIVATED.getDiagnosticMessage()), + "AM diagnostics not set properly"); + assertTrue(pendingApp.getDiagnostics().toString() + .contains(AMState.INACTIVATED.getDiagnosticMessage()), + "AM diagnostics not set properly"); + assertTrue(pendingApp.getDiagnostics().toString().contains( + CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), + "AM diagnostics not set properly"); // Now verify the same test case in Queue C1 where label is not configured. // Submit an app to Queue C1 with empty label @@ -255,25 +255,25 @@ public RMNodeLabelsManager createNodeLabelManager() { pendingApp = MockRMAppSubmitter.submit(rm1, data); leafQueue = (LeafQueue) cs.getQueue("c1"); - Assertions.assertNotNull(leafQueue); + assertNotNull(leafQueue); // 2 apps will be activated, third one will be pending as am-limit // is reached. - Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); - Assertions.assertTrue( - pendingApp.getDiagnostics().toString() - .contains(AMState.INACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); - Assertions.assertTrue( - pendingApp.getDiagnostics().toString().contains( - CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), "AM diagnostics not set properly"); + assertEquals(2, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumPendingApplications()); + assertTrue(pendingApp.getDiagnostics().toString() + .contains(AMState.INACTIVATED.getDiagnosticMessage()), + "AM diagnostics not set properly"); + assertTrue(pendingApp.getDiagnostics().toString().contains( + CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), + "AM diagnostics not set properly"); rm1.killApp(app3.getApplicationId()); Thread.sleep(1000); // After killing one running app, pending app will also get activated. - Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(0, leafQueue.getNumPendingApplications()); + assertEquals(2, leafQueue.getNumActiveApplications()); + assertEquals(0, leafQueue.getNumPendingApplications()); rm1.close(); } @@ -346,11 +346,11 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assertions.assertNotNull(leafQueue); + assertNotNull(leafQueue); // Only 1 app will be activated as am-limit for partition "x" is 0.15 - Assertions.assertEquals(1, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); + assertEquals(1, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumPendingApplications()); // Now verify the same test case in Queue C1 which takes default label // to see queue level am-resource-limit is still working as expected. @@ -382,11 +382,11 @@ public RMNodeLabelsManager createNodeLabelManager() { MockRMAppSubmitter.submit(rm1, data); leafQueue = (LeafQueue) cs.getQueue("c1"); - Assertions.assertNotNull(leafQueue); + assertNotNull(leafQueue); // 1 app will be activated (and it has AM resource more than queue limit) - Assertions.assertEquals(1, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); + assertEquals(1, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumPendingApplications()); rm1.close(); } @@ -450,20 +450,20 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assertions.assertNotNull(leafQueue); + assertNotNull(leafQueue); // Only 1 app will be activated as am-limit for queue is 0.2 and same is // used for partition "x" also. - Assertions.assertEquals(1, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); - Assertions.assertTrue(app1.getDiagnostics() - .toString().contains(AMState.ACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); - Assertions.assertTrue( - pendingApp.getDiagnostics().toString() - .contains(AMState.INACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); - Assertions.assertTrue( - pendingApp.getDiagnostics().toString() - .contains(CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), "AM diagnostics not set properly"); + assertEquals(1, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumPendingApplications()); + assertTrue(app1.getDiagnostics().toString().contains(AMState.ACTIVATED.getDiagnosticMessage()), + "AM diagnostics not set properly"); + assertTrue(pendingApp.getDiagnostics().toString() + .contains(AMState.INACTIVATED.getDiagnosticMessage()), + "AM diagnostics not set properly"); + assertTrue(pendingApp.getDiagnostics().toString() + .contains(CSAMContainerLaunchDiagnosticsConstants.QUEUE_AM_RESOURCE_LIMIT_EXCEED), + "AM diagnostics not set properly"); rm1.close(); } @@ -538,12 +538,12 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assertions.assertNotNull(leafQueue); + assertNotNull(leafQueue); // Verify active applications count in this queue. - Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumActiveApplications(user_0)); - Assertions.assertEquals(0, leafQueue.getNumPendingApplications()); + assertEquals(2, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumActiveApplications(user_0)); + assertEquals(0, leafQueue.getNumPendingApplications()); // Submit 3rd app to Queue A1 for label X for user1. Now user1 will have // 2 applications (2 GB resource) and user0 will have one app (1GB). @@ -578,19 +578,19 @@ public RMNodeLabelsManager createNodeLabelManager() { RMApp pendingApp = MockRMAppSubmitter.submit(rm1, data); // Verify active applications count per user and also in queue level. - Assertions.assertEquals(3, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumActiveApplications(user_0)); - Assertions.assertEquals(2, leafQueue.getNumActiveApplications(user_1)); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications(user_1)); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); + assertEquals(3, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumActiveApplications(user_0)); + assertEquals(2, leafQueue.getNumActiveApplications(user_1)); + assertEquals(1, leafQueue.getNumPendingApplications(user_1)); + assertEquals(1, leafQueue.getNumPendingApplications()); //verify Diagnostic messages - Assertions.assertTrue( - pendingApp.getDiagnostics().toString() - .contains(AMState.INACTIVATED.getDiagnosticMessage()), "AM diagnostics not set properly"); - Assertions.assertTrue( - pendingApp.getDiagnostics().toString().contains( - CSAMContainerLaunchDiagnosticsConstants.USER_AM_RESOURCE_LIMIT_EXCEED), "AM diagnostics not set properly"); + assertTrue(pendingApp.getDiagnostics().toString() + .contains(AMState.INACTIVATED.getDiagnosticMessage()), + "AM diagnostics not set properly"); + assertTrue(pendingApp.getDiagnostics().toString().contains( + CSAMContainerLaunchDiagnosticsConstants.USER_AM_RESOURCE_LIMIT_EXCEED), + "AM diagnostics not set properly"); rm1.close(); } @@ -689,7 +689,7 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm1.getResourceScheduler(); LeafQueue leafQueue = (LeafQueue) cs.getQueue("a1"); - Assertions.assertNotNull(leafQueue); + assertNotNull(leafQueue); /* * capacity of queue A -> 50% for label Y @@ -701,8 +701,8 @@ public RMNodeLabelsManager createNodeLabelManager() { * AM resource percent config for queue A1 -> 0.25 * ==> 2.5Gb (3 Gb) is max-am-resource-limit */ - Assertions.assertEquals(2, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); + assertEquals(2, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumPendingApplications()); // Submit app3 with 1Gb AM resource to Queue B1 (no_label) MockRMAppSubmissionData data1 = @@ -728,7 +728,7 @@ public RMNodeLabelsManager createNodeLabelManager() { MockRMAppSubmitter.submit(rm1, data); leafQueue = (LeafQueue) cs.getQueue("b1"); - Assertions.assertNotNull(leafQueue); + assertNotNull(leafQueue); /* * capacity of queue B -> 90% for queue @@ -743,8 +743,8 @@ public RMNodeLabelsManager createNodeLabelManager() { * * Only one app will be activated and all othe will be pending. */ - Assertions.assertEquals(1, leafQueue.getNumActiveApplications()); - Assertions.assertEquals(1, leafQueue.getNumPendingApplications()); + assertEquals(1, leafQueue.getNumActiveApplications()); + assertEquals(1, leafQueue.getNumPendingApplications()); rm1.close(); } @@ -829,16 +829,16 @@ public void testHeadroom() throws Exception { when(amResourceRequest.getCapability()).thenReturn(amResource); when(rmApp.getAMResourceRequests()).thenReturn( Collections.singletonList(amResourceRequest)); - Mockito.doReturn(rmApp) + doReturn(rmApp) .when(spyApps).get(ArgumentMatchers.any()); when(spyRMContext.getRMApps()).thenReturn(spyApps); RMAppAttempt rmAppAttempt = mock(RMAppAttempt.class); when(rmApp.getRMAppAttempt(any())) .thenReturn(rmAppAttempt); when(rmApp.getCurrentAppAttempt()).thenReturn(rmAppAttempt); - Mockito.doReturn(rmApp) + doReturn(rmApp) .when(spyApps).get(ArgumentMatchers.any()); - Mockito.doReturn(true).when(spyApps) + doReturn(true).when(spyApps) .containsKey(ArgumentMatchers.any()); Priority priority_1 = TestUtils.createMockPriority(1); @@ -1013,19 +1013,17 @@ public void testAMLimitByAllResources() throws Exception { .withQueue(queueName) .build()); - Assertions.assertEquals(1 -, queueA.getNumPendingApplications(), "PendingApplications should be 1"); - Assertions.assertEquals(2 -, queueA.getNumActiveApplications(), "Active applications should be 2"); + assertEquals(1, queueA.getNumPendingApplications(), "PendingApplications should be 1"); + assertEquals(2, queueA.getNumActiveApplications(), "Active applications should be 2"); // AMLimit is 2048,7 - Assertions.assertEquals(2048, + assertEquals(2048, queueA.getQueueResourceUsage().getAMLimit().getMemorySize()); - Assertions.assertEquals(7, + assertEquals(7, queueA.getQueueResourceUsage().getAMLimit().getVirtualCores()); // Used AM Resource is 2048,2 - Assertions.assertEquals(2048, + assertEquals(2048, queueA.getQueueResourceUsage().getAMUsed().getMemorySize()); - Assertions.assertEquals(2, + assertEquals(2, queueA.getQueueResourceUsage().getAMUsed().getVirtualCores()); 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/scheduler/capacity/TestApplicationPriority.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java index 45c652bcd3ca5..9d7f5c1692858 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriority.java @@ -19,6 +19,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -58,7 +60,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeAddedSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; import org.apache.hadoop.yarn.server.utils.BuilderUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -86,7 +87,7 @@ public void testApplicationOrderingWithPriority() throws Exception { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue q = (LeafQueue) cs.getQueue("default"); - Assertions.assertNotNull(q); + assertNotNull(q); String host = "127.0.0.1"; RMNode node = MockNodes.newNodeInfo(0, MockNodes.newResource(16 * GB), 1, @@ -177,14 +178,14 @@ public void testApplicationPriorityAllocation() throws Exception { List allocated1 = am1.allocateAndWaitForContainers("127.0.0.1", 7, 2 * GB, nm1); - Assertions.assertEquals(7, allocated1.size()); - Assertions.assertEquals(2 * GB, allocated1.get(0).getResource().getMemorySize()); + assertEquals(7, allocated1.size()); + assertEquals(2 * GB, allocated1.get(0).getResource().getMemorySize()); // check node report, 15 GB used (1 AM and 7 containers) and 1 GB available SchedulerNodeReport report_nm1 = rm.getResourceScheduler().getNodeReport( nm1.getNodeId()); - Assertions.assertEquals(15 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(1 * GB, + assertEquals(15 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(1 * GB, report_nm1.getAvailableResource().getMemorySize()); // Submit the second app App2 with priority 8 (Higher than App1) @@ -201,8 +202,8 @@ public void testApplicationPriorityAllocation() throws Exception { // check node report, 16 GB used and 0 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(0 * GB, + assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); // get scheduler @@ -224,8 +225,8 @@ public void testApplicationPriorityAllocation() throws Exception { // check node report, 12 GB used and 4 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(12 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(4 * GB, + assertEquals(12 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(4 * GB, report_nm1.getAvailableResource().getMemorySize()); // send updated request for App1 @@ -237,12 +238,12 @@ public void testApplicationPriorityAllocation() throws Exception { 2, 2 * GB, nm1); // App2 has got 2 containers now. - Assertions.assertEquals(2, allocated2.size()); + assertEquals(2, allocated2.size()); // check node report, 16 GB used and 0 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(0 * GB, + assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); rm.stop(); @@ -275,14 +276,14 @@ public void testPriorityWithPendingApplications() throws Exception { List allocated1 = am1.allocateAndWaitForContainers("127.0.0.1", 7, 1 * GB, nm1); - Assertions.assertEquals(7, allocated1.size()); - Assertions.assertEquals(1 * GB, allocated1.get(0).getResource().getMemorySize()); + assertEquals(7, allocated1.size()); + assertEquals(1 * GB, allocated1.get(0).getResource().getMemorySize()); // check node report, 8 GB used (1 AM and 7 containers) and 0 GB available SchedulerNodeReport report_nm1 = rm.getResourceScheduler().getNodeReport( nm1.getNodeId()); - Assertions.assertEquals(8 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(0 * GB, + assertEquals(8 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); // Submit the second app App2 with priority 7 @@ -317,8 +318,8 @@ public void testPriorityWithPendingApplications() throws Exception { // check node report, 1 GB used and 7 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(1 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(7 * GB, + assertEquals(1 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(7 * GB, report_nm1.getAvailableResource().getMemorySize()); rm.stop(); @@ -343,7 +344,7 @@ public void testMaxPriorityValidation() throws Exception { RMApp app1 = MockRMAppSubmitter.submit(rm, data); // Application submission should be successful and verify priority - Assertions.assertEquals(app1.getApplicationSubmissionContext().getPriority(), + assertEquals(app1.getApplicationSubmissionContext().getPriority(), maxPriority); rm.stop(); } @@ -384,7 +385,7 @@ public void testUpdatePriorityAtRuntime() throws Exception { .get(app1.getApplicationId()).getCurrentAppAttempt(); // Verify whether the new priority is updated - Assertions.assertEquals(appPriority2, schedulerAppAttempt.getPriority()); + assertEquals(appPriority2, schedulerAppAttempt.getPriority()); } @Test @@ -426,7 +427,7 @@ public void testUpdateInvalidPriorityAtRuntime() throws Exception { // Verify whether priority 15 is reset to 10 Priority appPriority3 = Priority.newInstance(10); - Assertions.assertEquals(appPriority3, schedulerAppAttempt.getPriority()); + assertEquals(appPriority3, schedulerAppAttempt.getPriority()); rm.stop(); } @@ -483,14 +484,14 @@ public void testRMRestartWithChangeInPriority() throws Exception { nm1.setResourceTrackerService(rm2.getResourceTrackerService()); // Verify RM Apps after this restart - Assertions.assertEquals(1, rm2.getRMContext().getRMApps().size()); + assertEquals(1, rm2.getRMContext().getRMApps().size()); // get scheduler app RMApp loadedApp = rm2.getRMContext().getRMApps() .get(app1.getApplicationId()); // Verify whether priority 15 is reset to 10 - Assertions.assertEquals(appPriority2, loadedApp.getApplicationPriority()); + assertEquals(appPriority2, loadedApp.getApplicationPriority()); rm2.stop(); rm1.stop(); @@ -523,15 +524,15 @@ public void testApplicationPriorityAllocationWithChangeInPriority() List allocated1 = am1.allocateAndWaitForContainers("127.0.0.1", NUM_CONTAINERS, 2 * GB, nm1); - Assertions.assertEquals(7, allocated1.size()); - Assertions.assertEquals(2 * GB, + assertEquals(7, allocated1.size()); + assertEquals(2 * GB, allocated1.get(0).getResource().getMemorySize()); // check node report, 15 GB used (1 AM and 7 containers) and 1 GB available SchedulerNodeReport report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(15 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(1 * GB, + assertEquals(15 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(1 * GB, report_nm1.getAvailableResource().getMemorySize()); // Submit the second app App2 with priority 8 (Higher than App1) @@ -548,8 +549,8 @@ public void testApplicationPriorityAllocationWithChangeInPriority() // check node report, 16 GB used and 0 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(0 * GB, + assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); // get scheduler @@ -573,8 +574,8 @@ public void testApplicationPriorityAllocationWithChangeInPriority() // check node report, 12 GB used and 4 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(12 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(4 * GB, + assertEquals(12 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(4 * GB, report_nm1.getAvailableResource().getMemorySize()); // add request for containers App1 @@ -584,11 +585,11 @@ public void testApplicationPriorityAllocationWithChangeInPriority() List allocated2 = am2.allocateAndWaitForContainers("127.0.0.1", 2, 2 * GB, nm1); - Assertions.assertEquals(2, allocated2.size()); + assertEquals(2, allocated2.size()); // check node report, 16 GB used and 0 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(0 * GB, + assertEquals(16 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(0 * GB, report_nm1.getAvailableResource().getMemorySize()); // kill 1 more @@ -606,8 +607,8 @@ public void testApplicationPriorityAllocationWithChangeInPriority() // check node report, 14 GB used and 2 GB available report_nm1 = rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); - Assertions.assertEquals(14 * GB, report_nm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(2 * GB, + assertEquals(14 * GB, report_nm1.getUsedResource().getMemorySize()); + assertEquals(2 * GB, report_nm1.getAvailableResource().getMemorySize()); // Change the priority of App1 to 3 (lowest) @@ -625,9 +626,9 @@ public void testApplicationPriorityAllocationWithChangeInPriority() List allocated3 = am1.allocateAndWaitForContainers("127.0.0.1", 1, 2 * GB, nm1); - Assertions.assertEquals(1, allocated3.size()); + assertEquals(1, allocated3.size()); // Now App1 will have 5 containers and 1 AM. App2 will have 2 containers. - Assertions.assertEquals(6, schedulerAppAttemptApp1.getLiveContainers().size()); + assertEquals(6, schedulerAppAttemptApp1.getLiveContainers().size()); rm.stop(); } @@ -691,8 +692,8 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() am2.registerAppAttempt(); rm1.drainEvents(); - Assertions.assertEquals(2, defaultQueue.getNumActiveApplications()); - Assertions.assertEquals(0, defaultQueue.getNumPendingApplications()); + assertEquals(2, defaultQueue.getNumActiveApplications()); + assertEquals(0, defaultQueue.getNumPendingApplications()); // App-3 with priority 7 submitted and scheduled. But not activated since // AMResourceLimit threshold @@ -704,22 +705,22 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() RMApp app3 = MockRMAppSubmitter.submit(rm1, data); rm1.drainEvents(); - Assertions.assertEquals(2, defaultQueue.getNumActiveApplications()); - Assertions.assertEquals(1, defaultQueue.getNumPendingApplications()); + assertEquals(2, defaultQueue.getNumActiveApplications()); + assertEquals(1, defaultQueue.getNumPendingApplications()); Iterator iterator = defaultQueue.getOrderingPolicy().getSchedulableEntities().iterator(); FiCaSchedulerApp fcApp2 = iterator.next(); - Assertions.assertEquals(app2.getCurrentAppAttempt().getAppAttemptId(), + assertEquals(app2.getCurrentAppAttempt().getAppAttemptId(), fcApp2.getApplicationAttemptId()); FiCaSchedulerApp fcApp1 = iterator.next(); - Assertions.assertEquals(app1.getCurrentAppAttempt().getAppAttemptId(), + assertEquals(app1.getCurrentAppAttempt().getAppAttemptId(), fcApp1.getApplicationAttemptId()); iterator = defaultQueue.getPendingApplications().iterator(); FiCaSchedulerApp fcApp3 = iterator.next(); - Assertions.assertEquals(app3.getCurrentAppAttempt().getAppAttemptId(), + assertEquals(app3.getCurrentAppAttempt().getAppAttemptId(), fcApp3.getApplicationAttemptId()); // create new RM to represent restart and recover state @@ -731,7 +732,7 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() nm1.setResourceTrackerService(rm2.getResourceTrackerService()); // Verify RM Apps after this restart - Assertions.assertEquals(3, rm2.getRMContext().getRMApps().size()); + assertEquals(3, rm2.getRMContext().getRMApps().size()); rm2.drainEvents(); scheduler = rm2.getRMContext().getScheduler(); @@ -749,8 +750,8 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() // Before NM registration, AMResourceLimit threshold is 0. So no // applications get activated. - Assertions.assertEquals(0, defaultQueue.getNumActiveApplications()); - Assertions.assertEquals(3, defaultQueue.getNumPendingApplications()); + assertEquals(0, defaultQueue.getNumActiveApplications()); + assertEquals(3, defaultQueue.getNumPendingApplications()); // NM resync to new RM nm1.registerNode(); @@ -765,24 +766,24 @@ public void testOrderOfActivatingThePriorityApplicationOnRMRestart() Thread.sleep(50); } - Assertions.assertEquals(2, defaultQueue.getNumActiveApplications()); - Assertions.assertEquals(1, defaultQueue.getNumPendingApplications()); + assertEquals(2, defaultQueue.getNumActiveApplications()); + assertEquals(1, defaultQueue.getNumPendingApplications()); // verify for order of activated applications iterator iterator = defaultQueue.getOrderingPolicy().getSchedulableEntities().iterator(); fcApp2 = iterator.next(); - Assertions.assertEquals(app2.getCurrentAppAttempt().getAppAttemptId(), + assertEquals(app2.getCurrentAppAttempt().getAppAttemptId(), fcApp2.getApplicationAttemptId()); fcApp1 = iterator.next(); - Assertions.assertEquals(app1.getCurrentAppAttempt().getAppAttemptId(), + assertEquals(app1.getCurrentAppAttempt().getAppAttemptId(), fcApp1.getApplicationAttemptId()); // verify for pending application iterator. It should be app-3 attempt iterator = defaultQueue.getPendingApplications().iterator(); fcApp3 = iterator.next(); - Assertions.assertEquals(app3.getCurrentAppAttempt().getAppAttemptId(), + assertEquals(app3.getCurrentAppAttempt().getAppAttemptId(), fcApp3.getApplicationAttemptId()); rm2.stop(); @@ -815,8 +816,8 @@ public void testUpdatePriorityOnPendingAppAndKillAttempt() throws Exception { ((LeafQueue) defaultQueue).getOrderingPolicy().getSchedulableEntities(); // Verify app is in pending state - Assertions.assertEquals(1, appsPending.size(), "Pending apps should be 1"); - Assertions.assertEquals(0, activeApps.size(), "Active apps should be 0"); + assertEquals(1, appsPending.size(), "Pending apps should be 1"); + assertEquals(0, activeApps.size(), "Active apps should be 0"); // kill app1 which is pending killAppAndVerifyOrderingPolicy(rm, defaultQueue, 0, 0, app1); @@ -829,8 +830,8 @@ public void testUpdatePriorityOnPendingAppAndKillAttempt() throws Exception { MockRMAppSubmissionData.Builder.createWithMemory(1024, rm) .withAppPriority(Priority.newInstance(appPriority)).build(); RMApp app2 = MockRMAppSubmitter.submit(rm, data2); - Assertions.assertEquals(0, appsPending.size(), "Pending apps should be 0"); - Assertions.assertEquals(1, activeApps.size(), "Active apps should be 1"); + assertEquals(0, appsPending.size(), "Pending apps should be 0"); + assertEquals(1, activeApps.size(), "Active apps should be 1"); MockRMAppSubmissionData data1 = MockRMAppSubmissionData.Builder.createWithMemory(1024, rm) .withAppPriority(Priority.newInstance(appPriority)).build(); @@ -839,8 +840,8 @@ public void testUpdatePriorityOnPendingAppAndKillAttempt() throws Exception { MockRMAppSubmissionData.Builder.createWithMemory(1024, rm) .withAppPriority(Priority.newInstance(appPriority)).build(); RMApp app4 = MockRMAppSubmitter.submit(rm, data); - Assertions.assertEquals(2, appsPending.size(), "Pending apps should be 2"); - Assertions.assertEquals(1, activeApps.size(), "Active apps should be 1"); + assertEquals(2, appsPending.size(), "Pending apps should be 2"); + assertEquals(1, activeApps.size(), "Active apps should be 1"); // kill app3, pending apps should reduce to 1 killAppAndVerifyOrderingPolicy(rm, defaultQueue, 1, 1, app3); // kill app2, running apps is killed and pending added to running @@ -868,10 +869,10 @@ private void killAppAndVerifyOrderingPolicy(MockRM rm, CSQueue defaultQueue, ((LeafQueue) defaultQueue).getPendingApplications(); Collection activeApps = ((LeafQueue) defaultQueue).getApplications(); - Assertions.assertEquals( - appsPendingExpected, appsPending.size(), "Pending apps should be " + appsPendingExpected); - Assertions.assertEquals( - activeAppsExpected, activeApps.size(), "Active apps should be " + activeAppsExpected); + assertEquals(appsPendingExpected, appsPending.size(), + "Pending apps should be " + appsPendingExpected); + assertEquals(activeAppsExpected, activeApps.size(), + "Active apps should be " + activeAppsExpected); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLConfiguration.java index 097a8a80656c0..37315bff2fa3a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLConfiguration.java @@ -17,10 +17,11 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.List; import org.apache.hadoop.yarn.api.records.Priority; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -117,10 +118,10 @@ private void verifyACLs(List pGroup, String queueUser, AppPriorityACLGroup group = pGroup.get(0); String aclString = queueUser + " " + queueGroup; - Assertions.assertEquals(aclString.trim(), + assertEquals(aclString.trim(), group.getACLList().getAclString().trim()); - Assertions.assertEquals(maxPriority, group.getMaxPriority().getPriority()); - Assertions.assertEquals(defaultPriority, + assertEquals(maxPriority, group.getMaxPriority().getPriority()); + assertEquals(defaultPriority, group.getDefaultPriority().getPriority()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLs.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLs.java index 581c73957e300..36be83e4fddc7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLs.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestApplicationPriorityACLs.java @@ -37,9 +37,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.ACLsTestBase; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestApplicationPriorityACLs extends ACLsTestBase { @@ -143,9 +145,9 @@ private void submitAppToRMWithInValidAcl(String submitter, .newInstance(appSubmissionContext); try { submitterClient.submitApplication(submitRequest); - Assertions.fail(); + fail(); } catch (YarnException ex) { - Assertions.assertTrue(ex.getCause() instanceof RemoteException); + assertTrue(ex.getCause() instanceof RemoteException); } } @@ -167,10 +169,10 @@ private void verifyAppPriorityIsAccepted(String submitter, try { GetApplicationReportResponse response = submitterClient .getApplicationReport(request); - Assertions.assertEquals(response.getApplicationReport().getPriority(), + assertEquals(response.getApplicationReport().getPriority(), Priority.newInstance(priority)); } catch (YarnException e) { - Assertions.fail("Application submission should not fail."); + fail("Application submission should not fail."); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueDeletionPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueDeletionPolicy.java index 2e0e7f8f08f75..a454f77cd1205 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueDeletionPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueDeletionPolicy.java @@ -33,11 +33,14 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppAttemptRemovedSchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.AppRemovedSchedulerEvent; 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 static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerNewQueueAutoCreation.MAX_MEMORY; +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; public class TestAutoCreatedQueueDeletionPolicy extends TestCapacitySchedulerAutoCreatedQueueBase { @@ -94,14 +97,14 @@ public void testEditSchedule() throws Exception { // Make sure e not null AbstractCSQueue e = (AbstractCSQueue) cs. getQueue("root.e"); - Assertions.assertNotNull(e); - Assertions.assertTrue(e.isDynamicQueue()); + assertNotNull(e); + assertTrue(e.isDynamicQueue()); // Make sure e1 not null AbstractCSQueue e1 = (AbstractCSQueue)cs. getQueue("root.e.e1"); - Assertions.assertNotNull(e1); - Assertions.assertTrue(e1.isDynamicQueue()); + assertNotNull(e1); + assertTrue(e1.isDynamicQueue()); // signal it because of without submit created e1.setLastSubmittedTimestamp(Time.monotonicNow()); @@ -115,8 +118,8 @@ public void testEditSchedule() throws Exception { // Make sure user0 not null AbstractCSQueue user0 = (AbstractCSQueue) cs .getQueue("root.e.user_0"); - Assertions.assertNotNull(user0); - Assertions.assertTrue(user0.isDynamicQueue()); + assertNotNull(user0); + assertTrue(user0.isDynamicQueue()); // Make app finished AppAttemptRemovedSchedulerEvent event = new AppAttemptRemovedSchedulerEvent(user0AppAttemptId, @@ -127,7 +130,7 @@ public void testEditSchedule() throws Exception { cs.handle(rEvent); // There are no apps in user0 - Assertions.assertEquals(user0.getNumApplications(), 0); + assertEquals(user0.getNumApplications(), 0); // Wait the time expired. long l1 = user0.getLastSubmittedTimestamp(); @@ -148,29 +151,29 @@ public void testEditSchedule() throws Exception { // Make sure user_0 , e1 queue // will be scheduled to mark for deletion // because it is expired for deletion. - Assertions.assertEquals(policy.getMarkedForDeletion().size(), 2); - Assertions.assertTrue(policy. + assertEquals(policy.getMarkedForDeletion().size(), 2); + assertTrue(policy. getMarkedForDeletion().contains("root.e.user_0")); - Assertions.assertTrue(policy. + assertTrue(policy. getMarkedForDeletion().contains("root.e.e1")); // Make sure the send for deletion is empty for first mark. - Assertions.assertEquals(policy.getSentForDeletion().size(), 0); + assertEquals(policy.getSentForDeletion().size(), 0); // Make sure user_0 , e1 queue will be scheduled to send for deletion policy.prepareForAutoDeletion(); - Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assertions.assertEquals(policy.getSentForDeletion().size(), 2); + assertEquals(policy.getMarkedForDeletion().size(), 0); + assertEquals(policy.getSentForDeletion().size(), 2); // Make sure e1, user0 not null before trigger remove. e1 = (AbstractCSQueue) cs.getQueue("root.e.e1"); - Assertions.assertNotNull(e1); + assertNotNull(e1); user0 = (AbstractCSQueue)cs.getQueue("root.e.user_0"); - Assertions.assertNotNull(user0); + assertNotNull(user0); // Make sure e1, user0 will be null after trigger remove. policy.triggerAutoDeletionForExpiredQueues(); - Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assertions.assertEquals(policy.getSentForDeletion().size(), 0); + assertEquals(policy.getMarkedForDeletion().size(), 0); + assertEquals(policy.getSentForDeletion().size(), 0); // Wait e1, user0 auto deleted. GenericTestUtils.waitFor(()-> cs.getQueue( @@ -180,13 +183,13 @@ public void testEditSchedule() throws Exception { "root.e.user_0") == null, 100, 2000); e1 = (AbstractCSQueue) cs.getQueue("root.e.e1"); - Assertions.assertNull(e1); + assertNull(e1); user0 = (AbstractCSQueue)cs.getQueue("root.e.user_0"); - Assertions.assertNull(user0); + assertNull(user0); // Make sure e is not null, before schedule. e = (AbstractCSQueue) cs.getQueue("root.e"); - Assertions.assertNotNull(e); + assertNotNull(e); // Expired for e // Wait e marked for deletion. @@ -198,29 +201,29 @@ public void testEditSchedule() throws Exception { }, 100, 2000); policy.editSchedule(); e = (AbstractCSQueue) cs.getQueue("root.e"); - Assertions.assertNotNull(e); - Assertions.assertEquals(policy.getMarkedForDeletion().size(), 1); - Assertions.assertEquals(policy.getSentForDeletion().size(), 0); - Assertions.assertTrue(policy.getMarkedForDeletion().contains("root.e")); + assertNotNull(e); + assertEquals(policy.getMarkedForDeletion().size(), 1); + assertEquals(policy.getSentForDeletion().size(), 0); + assertTrue(policy.getMarkedForDeletion().contains("root.e")); // Make sure e queue will be scheduled to send for deletion policy.prepareForAutoDeletion(); - Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assertions.assertEquals(policy.getSentForDeletion().size(), 1); + assertEquals(policy.getMarkedForDeletion().size(), 0); + assertEquals(policy.getSentForDeletion().size(), 1); // Make sure e not null before trigger remove. e = (AbstractCSQueue) cs.getQueue("root.e"); - Assertions.assertNotNull(e); + assertNotNull(e); // Make sure e will be null after trigger remove. policy.triggerAutoDeletionForExpiredQueues(); // Wait e1 auto deleted. GenericTestUtils.waitFor(()-> cs.getQueue( "root.e") == null, 100, 2000); - Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assertions.assertEquals(policy.getSentForDeletion().size(), 0); + assertEquals(policy.getMarkedForDeletion().size(), 0); + assertEquals(policy.getSentForDeletion().size(), 0); e = (AbstractCSQueue) cs.getQueue("root.e"); - Assertions.assertNull(e); + assertNull(e); } public void prepareForSchedule() throws Exception{ @@ -228,8 +231,8 @@ public void prepareForSchedule() throws Exception{ policy.editSchedule(); // There are no queues should be scheduled - Assertions.assertEquals(policy.getMarkedForDeletion().size(), 0); - Assertions.assertEquals(policy.getSentForDeletion().size(), 0); + assertEquals(policy.getMarkedForDeletion().size(), 0); + assertEquals(policy.getSentForDeletion().size(), 0); createQueue("root.e.e1"); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueTemplate.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueTemplate.java index 2f6d999945609..338ce741f665e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueTemplate.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestAutoCreatedQueueTemplate.java @@ -18,7 +18,10 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; -import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,7 +56,7 @@ public void testNonWildCardTemplate() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB); template.setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assertions.assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), + assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is not set"); } @@ -65,8 +68,8 @@ public void testOneLevelWildcardTemplate() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB); template.setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assertions.assertEquals(6f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is not set"); + assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, + "weight is not set"); } @@ -80,10 +83,10 @@ public void testTwoLevelWildcardTemplate() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB) .setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assertions.assertEquals(6f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, "weight is not set"); - Assertions.assertEquals(5f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is not set"); + assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, + "weight is not set"); + assertEquals(5f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, + "weight is not set"); } @Test @@ -93,8 +96,8 @@ public void testIgnoredWhenRootWildcarded() { new AutoCreatedQueueTemplate(conf, ROOT); template.setTemplateEntriesForChild(conf, TEST_QUEUE_A); - Assertions.assertEquals(-1f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, "weight is set"); + assertEquals(-1f, conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, + "weight is set"); } @Test @@ -104,8 +107,7 @@ public void testIgnoredWhenNoParent() { new AutoCreatedQueueTemplate(conf, ROOT); template.setTemplateEntriesForChild(conf, ROOT); - Assertions.assertEquals(-1f, - conf.getNonLabeledQueueWeight(ROOT), 10e-6, "weight is set"); + assertEquals(-1f, conf.getNonLabeledQueueWeight(ROOT), 10e-6, "weight is set"); } @Test @@ -115,8 +117,9 @@ public void testWildcardAfterRoot() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_A); template.setTemplateEntriesForChild(conf, TEST_QUEUE_A); - Assertions.assertEquals("acl_submit_applications is set", "user", - template.getTemplateProperties().get("acl_submit_applications")); + assertEquals("user", + template.getTemplateProperties().get("acl_submit_applications"), + "acl_submit_applications is set"); } @Test @@ -129,7 +132,7 @@ public void testTemplatePrecedence() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB); template.setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assertions.assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, + assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "explicit template does not have the highest precedence"); CapacitySchedulerConfiguration newConf = @@ -139,7 +142,7 @@ public void testTemplatePrecedence() { new AutoCreatedQueueTemplate(newConf, TEST_QUEUE_AB); template.setTemplateEntriesForChild(newConf, TEST_QUEUE_ABC); - Assertions.assertEquals(4f, newConf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), + assertEquals(4f, newConf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "precedence is invalid"); } @@ -150,7 +153,7 @@ public void testRootTemplate() { AutoCreatedQueueTemplate template = new AutoCreatedQueueTemplate(conf, ROOT); template.setTemplateEntriesForChild(conf, TEST_QUEUE_A); - Assertions.assertEquals(2f, conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, + assertEquals(2f, conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, "root property is not set"); } @@ -168,16 +171,16 @@ public void testQueueSpecificTemplates() { template.setTemplateEntriesForChild(conf, TEST_QUEUE_A); template.setTemplateEntriesForChild(conf, TEST_QUEUE_B, true); - Assertions.assertNull( - conf.getDefaultNodeLabelExpression(TEST_QUEUE_A), "default-node-label-expression is set for parent"); - Assertions.assertEquals("default-node-label-expression is not set for leaf", - "test", conf.getDefaultNodeLabelExpression(TEST_QUEUE_B)); - Assertions.assertFalse( - conf.isAutoExpiredDeletionEnabled(TEST_QUEUE_A), "auto queue removal is not disabled for parent"); - Assertions.assertEquals(10f, conf.getNonLabeledQueueWeight(TEST_QUEUE_B), + assertNull(conf.getDefaultNodeLabelExpression(TEST_QUEUE_A), + "default-node-label-expression is set for parent"); + assertEquals("test", conf.getDefaultNodeLabelExpression(TEST_QUEUE_B), + "default-node-label-expression is not set for leaf"); + assertFalse(conf.isAutoExpiredDeletionEnabled(TEST_QUEUE_A), + "auto queue removal is not disabled for parent"); + assertEquals(10f, conf.getNonLabeledQueueWeight(TEST_QUEUE_B), 10e-6, "weight should not be overridden when set by " + "queue type specific template"); - Assertions.assertEquals(2f, conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, + assertEquals(2f, conf.getNonLabeledQueueWeight(TEST_QUEUE_A), 10e-6, "weight should be set by common template"); } @@ -194,10 +197,10 @@ public void testWildcardTemplateWithLimitedAutoCreatedQueueDepth() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB) .setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assertions.assertEquals(6f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, "weight is not set"); - Assertions.assertEquals(5f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is not set"); + assertEquals(6f, conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, + "weight is not set"); + assertEquals(5f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, + "weight is not set"); } @Test @@ -208,8 +211,8 @@ public void testIgnoredTemplateWithLimitedAutoCreatedQueueDepth() { new AutoCreatedQueueTemplate(conf, TEST_QUEUE_AB) .setTemplateEntriesForChild(conf, TEST_QUEUE_ABC); - Assertions.assertEquals(-1f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, "weight is set incorrectly"); + assertEquals(-1f, conf.getNonLabeledQueueWeight(TEST_QUEUE_ABC), 10e-6, + "weight is set incorrectly"); } @Test @@ -220,8 +223,8 @@ public void testIgnoredTemplateWhenQueuePathIsInvalid() { new AutoCreatedQueueTemplate(conf, invalidPath); template.setTemplateEntriesForChild(conf, TEST_QUEUE_AB); - Assertions.assertEquals( -1f, - conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, "weight is set using invalid queue path"); + assertEquals( -1f, conf.getNonLabeledQueueWeight(TEST_QUEUE_AB), 10e-6, + "weight is set using invalid queue path"); } private String getTemplateKey(QueuePath queuePath, String entryKey) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java index fb9ba64ae61fb..2dfd17883daf4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSAllocateCustomResource.java @@ -45,7 +45,6 @@ import org.apache.hadoop.yarn.util.resource.ResourceUtils; import org.apache.hadoop.yarn.util.resource.Resources; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -64,6 +63,7 @@ import static org.apache.hadoop.yarn.api.records.ResourceInformation.GPU_URI; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.MAXIMUM_ALLOCATION_MB; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * Test case for custom resource container allocation. @@ -162,7 +162,7 @@ public void testCapacitySchedulerJobWhenConfigureCustomResourceType() // Do nm heartbeats 1 times, will allocate a container on nm1 cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); rm.drainEvents(); - Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + assertEquals(2, schedulerApp1.getLiveContainers().size()); rm.close(); } @@ -193,12 +193,12 @@ public void testCapacitySchedulerInitWithCustomResourceType() // Ensure the method can get custom resource type from // CapacitySchedulerConfiguration - Assertions.assertNotEquals(0, + assertNotEquals(0, ResourceUtils .fetchMaximumAllocationFromConfig(cs.getConfiguration()) .getResourceValue("yarn.io/gpu")); // Ensure custom resource type exists in queue's maximumAllocation - Assertions.assertNotEquals(0, + assertNotEquals(0, cs.getMaximumResourceCapability("a") .getResourceValue("yarn.io/gpu")); rm.close(); @@ -236,26 +236,20 @@ public void testClusterMetricsWithGPU() } // Check GPU inc related cluster metrics. - assertEquals( - metrics.getCapabilityMB(), (4096 * 8), "Cluster Capability Memory incorrect"); - assertEquals( - metrics.getCapabilityVirtualCores(), 4 * 8, "Cluster Capability Vcores incorrect"); - assertEquals( - (metrics.getCustomResourceCapability() - .get(GPU_URI)).longValue(), 4 * 8, "Cluster Capability GPUs incorrect"); + assertEquals(metrics.getCapabilityMB(), (4096 * 8), "Cluster Capability Memory incorrect"); + assertEquals(metrics.getCapabilityVirtualCores(), 4 * 8, "Cluster Capability Vcores incorrect"); + assertEquals((metrics.getCustomResourceCapability() + .get(GPU_URI)).longValue(), 4 * 8, "Cluster Capability GPUs incorrect"); for (RMNode rmNode : rmNodes) { nodeTracker.removeNode(rmNode.getNodeID()); } // Check GPU dec related cluster metrics. - assertEquals( - metrics.getCapabilityMB(), 0, "Cluster Capability Memory incorrect"); - assertEquals( - metrics.getCapabilityVirtualCores(), 0, "Cluster Capability Vcores incorrect"); - assertEquals( - (metrics.getCustomResourceCapability() - .get(GPU_URI)).longValue(), 0, "Cluster Capability GPUs incorrect"); + assertEquals(metrics.getCapabilityMB(), 0, "Cluster Capability Memory incorrect"); + assertEquals(metrics.getCapabilityVirtualCores(), 0, "Cluster Capability Vcores incorrect"); + assertEquals((metrics.getCustomResourceCapability() + .get(GPU_URI)).longValue(), 0, "Cluster Capability GPUs incorrect"); ClusterMetrics.destroy(); rm.stop(); } @@ -317,17 +311,17 @@ public void testCapacitySchedulerAbsoluteConfWithCustomResourceType() // Check the gpu resource conf is right. CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); - Assertions.assertEquals(aMINRES, + assertEquals(aMINRES, cs.getConfiguration(). getMinimumResourceRequirement("", A, resourceTypes)); - Assertions.assertEquals(aMAXRES, + assertEquals(aMAXRES, cs.getConfiguration(). getMaximumResourceRequirement("", A, resourceTypes)); // Check the gpu resource of queue is right. - Assertions.assertEquals(aMINRES, cs.getQueue("root.a"). + assertEquals(aMINRES, cs.getQueue("root.a"). getQueueResourceQuotas().getConfiguredMinResource()); - Assertions.assertEquals(aMAXRES, cs.getQueue("root.a"). + assertEquals(aMAXRES, cs.getQueue("root.a"). getQueueResourceQuotas().getConfiguredMaxResource()); 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/scheduler/capacity/TestCSQueueStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSQueueStore.java index 953119be63d24..ce3439eb1a10a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSQueueStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCSQueueStore.java @@ -29,8 +29,13 @@ import java.io.IOException; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestCSQueueStore { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java index 6f7ef9c5381c1..79b8199a30a24 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacityScheduler.java @@ -56,7 +56,6 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.stopResourceManager; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.toSet; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.waitforNMRegistered; -import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerOvercommit.assertContainerKilled; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerOvercommit.assertMemory; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerOvercommit.assertNoPreemption; @@ -65,11 +64,20 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerOvercommit.updateNodeResource; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerOvercommit.waitMemory; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.anyBoolean; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import java.net.InetSocketAddress; @@ -196,11 +204,9 @@ import org.apache.hadoop.yarn.util.resource.ResourceUtils; import org.apache.hadoop.yarn.util.resource.Resources; 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; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; @@ -244,9 +250,8 @@ public void testConfValidation() throws Exception { " larger than the max memory allocation."); } catch (YarnRuntimeException e) { // Exception is expected. - assertTrue( - e.getMessage().startsWith( - "Invalid resource scheduler memory"), "The thrown exception is not the expected one."); + assertTrue(e.getMessage().startsWith("Invalid resource scheduler memory"), + "The thrown exception is not the expected one."); } conf = new YarnConfiguration(); @@ -258,9 +263,8 @@ public void testConfValidation() throws Exception { " larger than the max vcores allocation."); } catch (YarnRuntimeException e) { // Exception is expected. - assertTrue( - e.getMessage().startsWith( - "Invalid resource scheduler vcores"), "The thrown exception is not the expected one."); + assertTrue(e.getMessage().startsWith("Invalid resource scheduler vcores"), + "The thrown exception is not the expected one."); } } @@ -625,17 +629,17 @@ public void testQueueMaximumAllocations() { Resource maxAllocation2 = scheduler.getMaximumResourceCapability(null); Resource maxAllocation3 = scheduler.getMaximumResourceCapability(); - Assertions.assertEquals(maxAllocation1, maxAllocation2); - Assertions.assertEquals(maxAllocation1, maxAllocation3); - Assertions.assertEquals( + assertEquals(maxAllocation1, maxAllocation2); + assertEquals(maxAllocation1, maxAllocation3); + assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, maxAllocation1.getMemorySize()); - Assertions.assertEquals( + assertEquals( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, maxAllocation1.getVirtualCores()); - Assertions.assertEquals(1024, maxAllocationForQueue.getMemorySize()); - Assertions.assertEquals(1, maxAllocationForQueue.getVirtualCores()); + assertEquals(1024, maxAllocationForQueue.getMemorySize()); + assertEquals(1, maxAllocationForQueue.getVirtualCores()); scheduler.stop(); } @@ -683,17 +687,14 @@ public void testParseQueueWithAbsoluteResource() { @Test public void testCapacitySchedulerInfo() throws Exception { QueueInfo queueInfo = resourceManager.getResourceScheduler().getQueueInfo("a", true, true); - Assertions.assertEquals("Queue Name should be a", "a", - queueInfo.getQueueName()); - Assertions.assertEquals("Queue Path should be root.a", "root.a", - queueInfo.getQueuePath()); - Assertions.assertEquals(2 -, queueInfo.getChildQueues().size(), "Child Queues size should be 2"); + assertEquals("a", queueInfo.getQueueName(), "Queue Name should be a"); + assertEquals("root.a", queueInfo.getQueuePath(), "Queue Path should be root.a"); + assertEquals(2, queueInfo.getChildQueues().size(), "Child Queues size should be 2"); List userACLInfo = resourceManager.getResourceScheduler().getQueueUserAclInfo(); - Assertions.assertNotNull(userACLInfo); + assertNotNull(userACLInfo); for (QueueUserACLInfo queueUserACLInfo : userACLInfo) { - Assertions.assertEquals(1, getQueueCount(userACLInfo, + assertEquals(1, getQueueCount(userACLInfo, queueUserACLInfo.getQueueName())); } @@ -723,7 +724,7 @@ public void testAllocateReorder() throws Exception { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue q = (LeafQueue) cs.getQueue("default"); - Assertions.assertNotNull(q); + assertNotNull(q); FairOrderingPolicy fop = new FairOrderingPolicy(); fop.setSizeBasedWeight(true); @@ -843,14 +844,14 @@ public void testResourceOverCommit() throws Exception { // verify no NPE is trigger in schedule after resource is updated am.addRequests(new String[] {"127.0.0.1", "127.0.0.2"}, 3 * GB, 1, 1); AllocateResponse allocResponse2 = am.schedule(); - assertTrue( - allocResponse2.getAllocatedContainers().isEmpty(), "Shouldn't have enough resource to allocate containers"); + assertTrue(allocResponse2.getAllocatedContainers().isEmpty(), + "Shouldn't have enough resource to allocate containers"); // try 10 times as scheduling is an async process for (int i = 0; i < 10; i++) { Thread.sleep(100); allocResponse2 = am.schedule(); - assertTrue( - allocResponse2.getAllocatedContainers().isEmpty(), "Shouldn't have enough resource to allocate containers"); + assertTrue(allocResponse2.getAllocatedContainers().isEmpty(), + "Shouldn't have enough resource to allocate containers"); } // increase the resources again to 5 GB to schedule the 3GB container @@ -1007,7 +1008,7 @@ public void testAllocateDoesNotBlockOnSchedulerLock() throws Exception { Thread.sleep(msecToSleep); msecToWait -= msecToSleep; } - Assertions.assertEquals(attempt.getAppAttemptState(), + assertEquals(attempt.getAppAttemptState(), RMAppAttemptState.LAUNCHED); // Create a client to the RM. @@ -1047,7 +1048,7 @@ public ApplicationMasterProtocol run() { nm1.nodeHeartbeat(true); ContainerId containerId2 = ContainerId.newContainerId(applicationAttemptId, 2); - Assertions.assertTrue(rm.waitForState(nm1, containerId2, + assertTrue(rm.waitForState(nm1, containerId2, RMContainerState.ALLOCATED)); // Acquire the container @@ -1201,7 +1202,7 @@ public void testRecoverRequestAfterPreemption() throws Exception { // Already the node local resource request is cleared from RM after // allocation. - Assertions.assertEquals(0, + assertEquals(0, app.getOutstandingAsksCount(SchedulerRequestKey.create(request), request.getResourceName())); } @@ -1209,11 +1210,11 @@ public void testRecoverRequestAfterPreemption() throws Exception { // Call killContainer to preempt the container cs.markContainerForKillable(rmContainer); - Assertions.assertEquals(3, requests.size()); + assertEquals(3, requests.size()); for (ResourceRequest request : requests) { // Resource request must have added back in RM after preempt event // handling. - Assertions.assertEquals(1, + assertEquals(1, app.getOutstandingAsksCount(SchedulerRequestKey.create(request), request.getResourceName())); } @@ -1228,7 +1229,7 @@ public void testRecoverRequestAfterPreemption() throws Exception { new ArrayList()).getAllocatedContainers(); // Now with updated ResourceRequest, a container is allocated for AM. - Assertions.assertTrue(containers.size() == 1); + assertTrue(containers.size() == 1); rm1.stop(); } @@ -1255,33 +1256,31 @@ null, new RMContainerTokenSecretManager(conf), // When preemption turned on for the whole system // (yarn.resourcemanager.scheduler.monitor.enable=true), and with no other // preemption properties set, queue root.b.b2 should be preemptable. - assertFalse( - queueB2.getPreemptionDisabled(), "queue " + B2 + " should default to preemptable"); + assertFalse(queueB2.getPreemptionDisabled(), + "queue " + B2 + " should default to preemptable"); // Disable preemption at the root queue level. // The preemption property should be inherited from root all the // way down so that root.b.b2 should NOT be preemptable. conf.setPreemptionDisabled(rootQueue.getQueuePathObject(), true); cs.reinitialize(conf, rmContext); - assertTrue( - - queueB2.getPreemptionDisabled(), "queue " + B2 + " should have inherited non-preemptability from root"); + assertTrue(queueB2.getPreemptionDisabled(), + "queue " + B2 + " should have inherited non-preemptability from root"); // Enable preemption for root (grandparent) but disable for root.b (parent). // root.b.b2 should inherit property from parent and NOT be preemptable conf.setPreemptionDisabled(rootQueue.getQueuePathObject(), false); conf.setPreemptionDisabled(queueB.getQueuePathObject(), true); cs.reinitialize(conf, rmContext); - assertTrue( - - queueB2.getPreemptionDisabled(), "queue " + B2 + " should have inherited non-preemptability from parent"); + assertTrue(queueB2.getPreemptionDisabled(), + "queue " + B2 + " should have inherited non-preemptability from parent"); // When preemption is turned on for root.b.b2, it should be preemptable // even though preemption is disabled on root.b (parent). conf.setPreemptionDisabled(queueB2.getQueuePathObject(), false); cs.reinitialize(conf, rmContext); - assertFalse( - queueB2.getPreemptionDisabled(), "queue " + B2 + " should have been preemptable"); + assertFalse(queueB2.getPreemptionDisabled(), + "queue " + B2 + " should have been preemptable"); cs.stop(); } @@ -1291,7 +1290,7 @@ private void waitContainerAllocated(MockAM am, int mem, int nContainer, am.allocate("*", mem, 1, new ArrayList()); ContainerId containerId = ContainerId.newContainerId(am.getApplicationAttemptId(), cId); - Assertions.assertTrue(rm.waitForState(nm, containerId, + assertTrue(rm.waitForState(nm, containerId, RMContainerState.ALLOCATED)); } } @@ -1359,12 +1358,12 @@ public void testSchedulerKeyGarbageCollection() throws Exception { null); List allocatedContainers = allocateResponse .getAllocatedContainers(); - Assertions.assertEquals(0, allocatedContainers.size()); + assertEquals(0, allocatedContainers.size()); Collection schedulerKeys = ((CapacityScheduler) scheduler).getApplicationAttempt(attemptId) .getAppSchedulingInfo().getSchedulerKeys(); - Assertions.assertEquals(4, schedulerKeys.size()); + assertEquals(4, schedulerKeys.size()); // Get a Node to HB... at which point 1 container should be // allocated @@ -1372,10 +1371,10 @@ public void testSchedulerKeyGarbageCollection() throws Exception { Thread.sleep(200); allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); allocatedContainers = allocateResponse.getAllocatedContainers(); - Assertions.assertEquals(1, allocatedContainers.size()); + assertEquals(1, allocatedContainers.size()); // Verify 1 outstanding schedulerKey is removed - Assertions.assertEquals(3, schedulerKeys.size()); + assertEquals(3, schedulerKeys.size()); List resReqs = ((CapacityScheduler) scheduler).getApplicationAttempt(attemptId) @@ -1383,7 +1382,7 @@ public void testSchedulerKeyGarbageCollection() throws Exception { // Verify 1 outstanding schedulerKey is removed from the // rrMap as well - Assertions.assertEquals(3, resReqs.size()); + assertEquals(3, resReqs.size()); // Verify One more container Allocation on node nm2 // And ensure the outstanding schedulerKeys go down.. @@ -1401,15 +1400,15 @@ public void testSchedulerKeyGarbageCollection() throws Exception { ), new ArrayList<>()); allocatedContainers = allocateResponse.getAllocatedContainers(); - Assertions.assertEquals(1, allocatedContainers.size()); + assertEquals(1, allocatedContainers.size()); // Verify 1 outstanding schedulerKey is removed - Assertions.assertEquals(2, schedulerKeys.size()); + assertEquals(2, schedulerKeys.size()); resReqs = ((CapacityScheduler) scheduler).getApplicationAttempt(attemptId) .getAppSchedulingInfo().getAllResourceRequests(); // Verify the map size is not increased due to 0 req - Assertions.assertEquals(2, resReqs.size()); + assertEquals(2, resReqs.size()); // Now Verify that the AM can cancel 1 Ask: SchedulerRequestKey sk = schedulerKeys.iterator().next(); @@ -1430,7 +1429,7 @@ public void testSchedulerKeyGarbageCollection() throws Exception { // Verify 1 outstanding schedulerKey is removed because of the // cancel ask - Assertions.assertEquals(1, schedulerKeys.size()); + assertEquals(1, schedulerKeys.size()); // Now verify that after the next node heartbeat, we allocate // the last schedulerKey @@ -1438,14 +1437,14 @@ public void testSchedulerKeyGarbageCollection() throws Exception { Thread.sleep(200); allocateResponse = am1.allocate(new ArrayList<>(), new ArrayList<>()); allocatedContainers = allocateResponse.getAllocatedContainers(); - Assertions.assertEquals(1, allocatedContainers.size()); + assertEquals(1, allocatedContainers.size()); // Verify no more outstanding schedulerKeys.. - Assertions.assertEquals(0, schedulerKeys.size()); + assertEquals(0, schedulerKeys.size()); resReqs = ((CapacityScheduler) scheduler).getApplicationAttempt(attemptId) .getAppSchedulingInfo().getAllResourceRequests(); - Assertions.assertEquals(0, resReqs.size()); + assertEquals(0, resReqs.size()); rm.stop(); } @@ -1494,7 +1493,7 @@ public void testHierarchyQueuesCurrentLimits() throws Exception { // Maximum resource of b1 is 100 * 0.895 * 0.792 = 71 GB // 2 GBs used by am, so it's 71 - 2 = 69G. - Assertions.assertEquals(69 * GB, + assertEquals(69 * GB, am1.doHeartbeat().getAvailableResources().getMemorySize()); MockRMAppSubmissionData data1 = @@ -1518,7 +1517,7 @@ public void testHierarchyQueuesCurrentLimits() throws Exception { // B2 uses 41 GB (5 * 8GB containers and 1 AM container) // B1 uses 3 GB (2 * 1GB containers and 1 AM container) // Available is 100 - 41 - 3 = 56 GB - Assertions.assertEquals(56 * GB, + assertEquals(56 * GB, am1.doHeartbeat().getAvailableResources().getMemorySize()); // Now we submit app3 to a1 (in higher level hierarchy), to see if headroom @@ -1545,7 +1544,7 @@ public void testHierarchyQueuesCurrentLimits() throws Exception { // B1 uses 4 GB (3 * 1GB containers and 1 AM container) // A1 uses 25 GB (3 * 8GB containers and 1 AM container) // Available is 100 - 41 - 4 - 25 = 30 GB - Assertions.assertEquals(30 * GB, + assertEquals(30 * GB, am1.doHeartbeat().getAvailableResources().getMemorySize()); rm1.stop(); } @@ -1618,7 +1617,7 @@ public void testParentQueueMaxCapsAreRespected() throws Exception { // Expected, return; return; } - Assertions.fail("Shouldn't successfully allocate containers for am2, " + fail("Shouldn't successfully allocate containers for am2, " + "queue-a's max capacity will be violated if container allocated"); rm1.stop(); } @@ -1736,10 +1735,10 @@ protected RMNodeLabelsManager createNodeLabelManager() { // some containers allocated for am1, pending resource should decrease ContainerId containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); - Assertions.assertTrue(rm.waitForState(nm1, containerId, + assertTrue(rm.waitForState(nm1, containerId, RMContainerState.ALLOCATED)); containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 3); - Assertions.assertTrue(rm.waitForState(nm2, containerId, + assertTrue(rm.waitForState(nm2, containerId, RMContainerState.ALLOCATED)); checkPendingResource(rm, "a1", 0 * GB, null); @@ -1784,8 +1783,8 @@ public void testAMUsedResource() throws Exception { conf.getInt(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB); int amMemory = 50; - assertTrue( - amMemory < minAllocMb, "AM memory is greater than or equal to minAllocation"); + assertTrue(amMemory < minAllocMb, + "AM memory is greater than or equal to minAllocation"); Resource minAllocResource = Resource.newInstance(minAllocMb, 1); String queueName = "a1"; MockRMAppSubmissionData data = @@ -1798,14 +1797,14 @@ public void testAMUsedResource() throws Exception { .build(); RMApp rmApp = MockRMAppSubmitter.submit(rm, data); - assertEquals( - minAllocResource, rmApp.getAMResourceRequests().get(0).getCapability(), "RMApp does not containes minimum allocation"); + assertEquals(minAllocResource, rmApp.getAMResourceRequests().get(0).getCapability(), + "RMApp does not containes minimum allocation"); ResourceScheduler scheduler = rm.getRMContext().getScheduler(); LeafQueue queueA = (LeafQueue) ((CapacityScheduler) scheduler).getQueue(queueName); - assertEquals(minAllocResource -, queueA.getUser("user_0").getResourceUsage().getAMUsed(), "Minimum Resource for AM is incorrect"); + assertEquals(minAllocResource, queueA.getUser("user_0").getResourceUsage().getAMUsed(), + "Minimum Resource for AM is incorrect"); rm.stop(); } @@ -1852,11 +1851,10 @@ public void testApplicationHeadRoom() throws Exception { null, Collections. emptyList(), null, null, NULL_UPDATE_REQUESTS); - Assertions.assertNotNull(attempt); + assertNotNull(attempt); - Assertions - .assertEquals(Resource.newInstance(0, 0), allocate.getResourceLimit()); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), allocate.getResourceLimit()); + assertEquals(Resource.newInstance(0, 0), attemptMetric.getApplicationAttemptHeadroom()); // Add a node to cluster @@ -1870,8 +1868,8 @@ null, Collections. emptyList(), null, null, NULL_UPDATE_REQUESTS); // All resources should be sent as headroom - Assertions.assertEquals(newResource, allocate.getResourceLimit()); - Assertions.assertEquals(newResource, + assertEquals(newResource, allocate.getResourceLimit()); + assertEquals(newResource, attemptMetric.getApplicationAttemptHeadroom()); rm.stop(); @@ -2015,7 +2013,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { ContainerId.newContainerId(am1.getApplicationAttemptId(), 2); ContainerId containerId3 = ContainerId.newContainerId(am1.getApplicationAttemptId(), 3); - Assertions.assertTrue(rm.waitForState(nm1, containerId3, + assertTrue(rm.waitForState(nm1, containerId3, RMContainerState.ALLOCATED)); // Acquire them am1.allocate(null, null); @@ -2035,7 +2033,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { FiCaSchedulerApp app = getFiCaSchedulerApp(rm, app1.getApplicationId()); - Assertions.assertEquals(2 * GB, + assertEquals(2 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); checkPendingResource(rm, "a1", 2 * GB, null); checkPendingResource(rm, "a", 2 * GB, null); @@ -2052,7 +2050,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { ContainerUpdateType.INCREASE_RESOURCE, Resources.createResource(5 * GB), null))); - Assertions.assertEquals(6 * GB, + assertEquals(6 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); checkPendingResource(rm, "a1", 6 * GB, null); checkPendingResource(rm, "a", 6 * GB, null); @@ -2073,7 +2071,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { .newInstance(0, containerId3, ContainerUpdateType.INCREASE_RESOURCE, Resources.createResource(2 * GB), null))); - Assertions.assertEquals(4 * GB, + assertEquals(4 * GB, app.getAppAttemptResourceUsage().getPending().getMemorySize()); checkPendingResource(rm, "a1", 4 * GB, null); checkPendingResource(rm, "a", 4 * GB, null); @@ -2129,15 +2127,13 @@ public Boolean get() { // When AM limit is exceeded, 1 applications will be activated.Rest all // applications will be in pending - Assertions.assertEquals(1 -, queueA.getNumPendingApplications(), "PendingApplications should be 1"); - Assertions.assertEquals(1 -, queueA.getNumActiveApplications(), "Active applications should be 1"); - - Assertions.assertEquals(1, queueA - .getUser(userName).getPendingApplications(), "User PendingApplications should be 1"); - Assertions.assertEquals(1, queueA - .getUser(userName).getActiveApplications(), "User Active applications should be 1"); + assertEquals(1, queueA.getNumPendingApplications(), "PendingApplications should be 1"); + assertEquals(1, queueA.getNumActiveApplications(), "Active applications should be 1"); + + assertEquals(1, queueA.getUser(userName).getPendingApplications(), + "User PendingApplications should be 1"); + assertEquals(1, queueA.getUser(userName).getActiveApplications(), + "User Active applications should be 1"); rm.stop(); } @@ -2148,7 +2144,7 @@ private void sentRMContainerLaunched(MockRM rm, ContainerId containerId) { rmContainer.handle( new RMContainerEvent(containerId, RMContainerEventType.LAUNCHED)); } else { - Assertions.fail("Cannot find RMContainer"); + fail("Cannot find RMContainer"); } } @@ -2164,7 +2160,7 @@ public void testCSReservationWithRootUnblocked() throws Exception { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); ParentQueue q = (ParentQueue) cs.getQueue("p1"); - Assertions.assertNotNull(q); + assertNotNull(q); String host = "127.0.0.1"; String host1 = "test"; RMNode node = @@ -2194,10 +2190,10 @@ public void testCSReservationWithRootUnblocked() throws Exception { null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); } - assertEquals(4 * GB -, cs.getQueue("y1").getUsedResources().getMemorySize(), "Y1 Used Resource should be 4 GB"); - assertEquals(4 * GB -, cs.getQueue("p2").getUsedResources().getMemorySize(), "P2 Used Resource should be 4 GB"); + assertEquals(4 * GB, cs.getQueue("y1").getUsedResources().getMemorySize(), + "Y1 Used Resource should be 4 GB"); + assertEquals(4 * GB, cs.getQueue("p2").getUsedResources().getMemorySize(), + "P2 Used Resource should be 4 GB"); for(int i=0; i < 7; i++) { x1Req = TestUtils.createResourceRequest( @@ -2207,10 +2203,10 @@ public void testCSReservationWithRootUnblocked() throws Exception { null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); } - assertEquals(7 * GB -, cs.getQueue("x1").getUsedResources().getMemorySize(), "X1 Used Resource should be 7 GB"); - assertEquals(7 * GB -, cs.getQueue("p1").getUsedResources().getMemorySize(), "P1 Used Resource should be 7 GB"); + assertEquals(7 * GB, cs.getQueue("x1").getUsedResources().getMemorySize(), + "X1 Used Resource should be 7 GB"); + assertEquals(7 * GB, cs.getQueue("p1").getUsedResources().getMemorySize(), + "P1 Used Resource should be 7 GB"); x2Req = TestUtils.createResourceRequest( ResourceRequest.ANY, 2 * GB, 1, true, priority, recordFactory); @@ -2218,10 +2214,10 @@ public void testCSReservationWithRootUnblocked() throws Exception { Collections.singletonList(x2Req), null, Collections.emptyList(), null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); - assertEquals(0 -, cs.getQueue("x2").getUsedResources().getMemorySize(), "X2 Used Resource should be 0"); - assertEquals(7 * GB -, cs.getQueue("p1").getUsedResources().getMemorySize(), "P1 Used Resource should be 7 GB"); + assertEquals(0, cs.getQueue("x2").getUsedResources().getMemorySize(), + "X2 Used Resource should be 0"); + assertEquals(7 * GB, cs.getQueue("p1").getUsedResources().getMemorySize(), + "P1 Used Resource should be 7 GB"); //this assign should fail x1Req = TestUtils.createResourceRequest( ResourceRequest.ANY, 1 * GB, 1, true, priority, recordFactory); @@ -2229,10 +2225,10 @@ public void testCSReservationWithRootUnblocked() throws Exception { Collections.singletonList(x1Req), null, Collections.emptyList(), null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); - assertEquals(7 * GB -, cs.getQueue("x1").getUsedResources().getMemorySize(), "X1 Used Resource should be 7 GB"); - assertEquals(7 * GB -, cs.getQueue("p1").getUsedResources().getMemorySize(), "P1 Used Resource should be 7 GB"); + assertEquals(7 * GB, cs.getQueue("x1").getUsedResources().getMemorySize(), + "X1 Used Resource should be 7 GB"); + assertEquals(7 * GB, cs.getQueue("p1").getUsedResources().getMemorySize(), + "P1 Used Resource should be 7 GB"); //this should get thru for (int i=0; i < 4; i++) { @@ -2243,8 +2239,8 @@ public void testCSReservationWithRootUnblocked() throws Exception { null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); } - assertEquals(8 * GB -, cs.getQueue("p2").getUsedResources().getMemorySize(), "P2 Used Resource should be 8 GB"); + assertEquals(8 * GB, cs.getQueue("p2").getUsedResources().getMemorySize(), + "P2 Used Resource should be 8 GB"); //Free a container from X1 ContainerId containerId = ContainerId.newContainerId(appAttemptId1, 2); @@ -2252,14 +2248,14 @@ public void testCSReservationWithRootUnblocked() throws Exception { //Schedule pending request CapacityScheduler.schedule(cs); - assertEquals(2 * GB -, cs.getQueue("x2").getUsedResources().getMemorySize(), "X2 Used Resource should be 2 GB"); - assertEquals(8 * GB -, cs.getQueue("p1").getUsedResources().getMemorySize(), "P1 Used Resource should be 8 GB"); - assertEquals(8 * GB -, cs.getQueue("p2").getUsedResources().getMemorySize(), "P2 Used Resource should be 8 GB"); - assertEquals(16 * GB -, cs.getRootQueue().getUsedResources().getMemorySize(), "Root Used Resource should be 16 GB"); + assertEquals(2 * GB, cs.getQueue("x2").getUsedResources().getMemorySize(), + "X2 Used Resource should be 2 GB"); + assertEquals(8 * GB, cs.getQueue("p1").getUsedResources().getMemorySize(), + "P1 Used Resource should be 8 GB"); + assertEquals(8 * GB, cs.getQueue("p2").getUsedResources().getMemorySize(), + "P2 Used Resource should be 8 GB"); + assertEquals(16 * GB, cs.getRootQueue().getUsedResources().getMemorySize(), + "Root Used Resource should be 16 GB"); rm.stop(); } @@ -2274,7 +2270,7 @@ public void testCSQueueBlocked() throws Exception { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); LeafQueue q = (LeafQueue) cs.getQueue("a"); - Assertions.assertNotNull(q); + assertNotNull(q); String host = "127.0.0.1"; String host1 = "test"; RMNode node = @@ -2310,10 +2306,10 @@ public void testCSQueueBlocked() throws Exception { null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); } - assertEquals(2 * GB -, cs.getQueue("a").getUsedResources().getMemorySize(), "A Used Resource should be 2 GB"); - assertEquals(13 * GB -, cs.getQueue("b").getUsedResources().getMemorySize(), "B Used Resource should be 13 GB"); + assertEquals(2 * GB, cs.getQueue("a").getUsedResources().getMemorySize(), + "A Used Resource should be 2 GB"); + assertEquals(13 * GB, cs.getQueue("b").getUsedResources().getMemorySize(), + "B Used Resource should be 13 GB"); r1 = TestUtils.createResourceRequest( ResourceRequest.ANY, 2 * GB, 1, true, priority, recordFactory); r2 = TestUtils.createResourceRequest( @@ -2327,10 +2323,10 @@ public void testCSQueueBlocked() throws Exception { null, Collections.emptyList(), null, null, NULL_UPDATE_REQUESTS); CapacityScheduler.schedule(cs); //Check blocked Resource - assertEquals(2 * GB -, cs.getQueue("a").getUsedResources().getMemorySize(), "A Used Resource should be 2 GB"); - assertEquals(13 * GB -, cs.getQueue("b").getUsedResources().getMemorySize(), "B Used Resource should be 13 GB"); + assertEquals(2 * GB, cs.getQueue("a").getUsedResources().getMemorySize(), + "A Used Resource should be 2 GB"); + assertEquals(13 * GB, cs.getQueue("b").getUsedResources().getMemorySize(), + "B Used Resource should be 13 GB"); ContainerId containerId1 = ContainerId.newContainerId(appAttemptId2, 10); ContainerId containerId2 =ContainerId.newContainerId(appAttemptId2, 11); @@ -2343,12 +2339,12 @@ public void testCSQueueBlocked() throws Exception { CapacityScheduler.schedule(cs); rm.drainEvents(); - assertEquals(4 * GB -, cs.getQueue("a").getUsedResources().getMemorySize(), "A Used Resource should be 4 GB"); - assertEquals(12 * GB -, cs.getQueue("b").getUsedResources().getMemorySize(), "B Used Resource should be 12 GB"); - assertEquals(16 * GB -, cs.getRootQueue().getUsedResources().getMemorySize(), "Used Resource on Root should be 16 GB"); + assertEquals(4 * GB, cs.getQueue("a").getUsedResources().getMemorySize(), + "A Used Resource should be 4 GB"); + assertEquals(12 * GB, cs.getQueue("b").getUsedResources().getMemorySize(), + "B Used Resource should be 12 GB"); + assertEquals(16 * GB, cs.getRootQueue().getUsedResources().getMemorySize(), + "Used Resource on Root should be 16 GB"); rm.stop(); } @@ -2409,7 +2405,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { // We should get one node-local allocation, one rack-local allocation // And one off-switch allocation - Assertions.assertArrayEquals(new int[][] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, + assertArrayEquals(new int[][] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, attemptMetrics.getLocalityStatistics()); rm.stop(); } @@ -2439,8 +2435,8 @@ public void testAMLimitDouble() throws Exception { LeafQueue queueA = (LeafQueue) ((CapacityScheduler) scheduler).getQueue("default"); Resource amResourceLimit = queueA.getAMResourceLimit(); - Assertions.assertEquals(4096, amResourceLimit.getMemorySize()); - Assertions.assertEquals(4, amResourceLimit.getVirtualCores()); + assertEquals(4096, amResourceLimit.getMemorySize()); + assertEquals(4, amResourceLimit.getVirtualCores()); rm.stop(); } @@ -2490,78 +2486,78 @@ public void testcheckAndGetApplicationLifetime() throws Exception { long defaultLifetime = 5; // positive integer value CapacityScheduler cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assertions.assertEquals(maxLifetime, + assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assertions.assertEquals(9, cs.checkAndGetApplicationLifetime("default", 9, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(9, cs.checkAndGetApplicationLifetime("default", 9, null)); + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); - Assertions.assertEquals(maxLifetime, + assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = -1; defaultLifetime = -1; // test for default values cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assertions.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); - Assertions.assertEquals(maxLifetime, + assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = 10; defaultLifetime = 10; cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assertions.assertEquals(maxLifetime, + assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); - Assertions.assertEquals(maxLifetime, + assertEquals(maxLifetime, cs.getMaximumApplicationLifetime("default")); maxLifetime = 0; defaultLifetime = 0; cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assertions.assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); maxLifetime = 10; defaultLifetime = -1; cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assertions.assertEquals(maxLifetime, + assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assertions.assertEquals(maxLifetime, + assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assertions.assertEquals(maxLifetime, + assertEquals(maxLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); maxLifetime = 5; defaultLifetime = 10; try { setUpCSQueue(maxLifetime, defaultLifetime); - Assertions.fail("Expected to fails since maxLifetime < defaultLifetime."); + fail("Expected to fails since maxLifetime < defaultLifetime."); } catch (ServiceStateException sse) { Throwable rootCause = sse.getCause().getCause(); - Assertions.assertTrue( + assertTrue( rootCause.getMessage().contains("can't exceed maximum lifetime")); } maxLifetime = -1; defaultLifetime = 10; cs = setUpCSQueue(maxLifetime, defaultLifetime); - Assertions.assertEquals(100, + assertEquals(100, cs.checkAndGetApplicationLifetime("default", 100, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", -1, null)); - Assertions.assertEquals(defaultLifetime, + assertEquals(defaultLifetime, cs.checkAndGetApplicationLifetime("default", 0, null)); } @@ -2607,8 +2603,8 @@ public void testClearRequestsBeforeApplyTheProposal() // spy capacity scheduler to handle CapacityScheduler#apply final Priority priority = Priority.newInstance(1); final CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); - final CapacityScheduler spyCs = Mockito.spy(cs); - Mockito.doAnswer(new Answer() { + final CapacityScheduler spyCs = spy(cs); + doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) throws Exception { // clear resource request before applying the proposal for container_2 spyCs.allocate(app.getCurrentAppAttempt().getAppAttemptId(), @@ -2624,14 +2620,14 @@ public Object answer(InvocationOnMock invocation) throws Exception { (ResourceCommitRequest) invocation.getArguments()[1], (Boolean) invocation.getArguments()[2]); // the proposal of removed request should be rejected - Assertions.assertEquals(1, schedulerApp.getLiveContainers().size()); + assertEquals(1, schedulerApp.getLiveContainers().size()); } catch (Throwable e) { - Assertions.fail(); + fail(); } return null; } - }).when(spyCs).tryCommit(Mockito.any(Resource.class), - Mockito.any(ResourceCommitRequest.class), Mockito.anyBoolean()); + }).when(spyCs).tryCommit(any(Resource.class), + any(ResourceCommitRequest.class), anyBoolean()); // rm allocates container_2 to reproduce the process that can raise NPE spyCs.allocate(app.getCurrentAppAttempt().getAppAttemptId(), @@ -2648,13 +2644,13 @@ public Object answer(InvocationOnMock invocation) throws Exception { // values during scheduling. @Test public void testContainerAllocationLocalitySkipped() throws Exception { - Assertions.assertEquals(AllocationState.APP_SKIPPED, + assertEquals(AllocationState.APP_SKIPPED, ContainerAllocation.APP_SKIPPED.getAllocationState()); - Assertions.assertEquals(AllocationState.LOCALITY_SKIPPED, + assertEquals(AllocationState.LOCALITY_SKIPPED, ContainerAllocation.LOCALITY_SKIPPED.getAllocationState()); - Assertions.assertEquals(AllocationState.PRIORITY_SKIPPED, + assertEquals(AllocationState.PRIORITY_SKIPPED, ContainerAllocation.PRIORITY_SKIPPED.getAllocationState()); - Assertions.assertEquals(AllocationState.QUEUE_SKIPPED, + assertEquals(AllocationState.QUEUE_SKIPPED, ContainerAllocation.QUEUE_SKIPPED.getAllocationState()); // init RM & NMs & Nodes @@ -2683,15 +2679,15 @@ public void testContainerAllocationLocalitySkipped() throws Exception { assertThat(cs.getRMContainer(cid).getState()). isEqualTo(RMContainerState.ACQUIRED); cid = ContainerId.newContainerId(am.getApplicationAttemptId(), 2l); - Assertions.assertNull(cs.getRMContainer(cid)); + assertNull(cs.getRMContainer(cid)); - Assertions.assertEquals(AllocationState.APP_SKIPPED, + assertEquals(AllocationState.APP_SKIPPED, ContainerAllocation.APP_SKIPPED.getAllocationState()); - Assertions.assertEquals(AllocationState.LOCALITY_SKIPPED, + assertEquals(AllocationState.LOCALITY_SKIPPED, ContainerAllocation.LOCALITY_SKIPPED.getAllocationState()); - Assertions.assertEquals(AllocationState.PRIORITY_SKIPPED, + assertEquals(AllocationState.PRIORITY_SKIPPED, ContainerAllocation.PRIORITY_SKIPPED.getAllocationState()); - Assertions.assertEquals(AllocationState.QUEUE_SKIPPED, + assertEquals(AllocationState.QUEUE_SKIPPED, ContainerAllocation.QUEUE_SKIPPED.getAllocationState()); rm.stop(); } @@ -2745,13 +2741,13 @@ public void testCSQueueMetricsDoesNotLeakOnReinit() throws Exception { QueueMetrics a3DefaultPartitionMetrics = QueueMetrics.getQueueMetrics().get( "default.root.a.a3"); - Assertions.assertSame( - QueueMetrics.getQueueMetrics().get("root.a.a1").getParentQueue() -, QueueMetrics.getQueueMetrics().get("root.a.a3").getParentQueue(), "Different ParentQueue of siblings is a sign of a memory leak"); + assertSame(QueueMetrics.getQueueMetrics().get("root.a.a1").getParentQueue(), + QueueMetrics.getQueueMetrics().get("root.a.a3").getParentQueue(), + "Different ParentQueue of siblings is a sign of a memory leak"); - Assertions.assertSame( - QueueMetrics.getQueueMetrics().get("root.a.a1").getParentQueue() -, a3DefaultPartitionMetrics.getParentQueue(), "Different ParentQueue of partition metrics is a sign of a memory leak"); + assertSame(QueueMetrics.getQueueMetrics().get("root.a.a1").getParentQueue(), + a3DefaultPartitionMetrics.getParentQueue(), + "Different ParentQueue of partition metrics is a sign of a memory leak"); rm.stop(); } @@ -3022,28 +3018,28 @@ public void testReservedContainerLeakWhenMoveApplication() throws Exception { FiCaSchedulerApp schedulerApp2 = scheduler.getApplicationAttempt(am2.getApplicationAttemptId()); // APP1: 1 AM, 1 allocatedContainer - Assertions.assertEquals(2, schedulerApp1.getLiveContainers().size()); + assertEquals(2, schedulerApp1.getLiveContainers().size()); // APP2: 1 AM,1 reservedContainer - Assertions.assertEquals(1, schedulerApp2.getLiveContainers().size()); - Assertions.assertEquals(1, schedulerApp2.getReservedContainers().size()); + assertEquals(1, schedulerApp2.getLiveContainers().size()); + assertEquals(1, schedulerApp2.getReservedContainers().size()); //before,move app2 which has one reservedContainer LeafQueue srcQueue = (LeafQueue) scheduler.getQueue("a"); LeafQueue desQueue = (LeafQueue) scheduler.getQueue("b"); - Assertions.assertEquals(4, srcQueue.getNumContainers()); - Assertions.assertEquals(10*GB, srcQueue.getUsedResources().getMemorySize()); - Assertions.assertEquals(0, desQueue.getNumContainers()); - Assertions.assertEquals(0, desQueue.getUsedResources().getMemorySize()); + assertEquals(4, srcQueue.getNumContainers()); + assertEquals(10*GB, srcQueue.getUsedResources().getMemorySize()); + assertEquals(0, desQueue.getNumContainers()); + assertEquals(0, desQueue.getUsedResources().getMemorySize()); //app1 ResourceUsage (0 reserved) - Assertions.assertEquals(5*GB, + assertEquals(5*GB, schedulerApp1 .getAppAttemptResourceUsage().getAllUsed().getMemorySize()); - Assertions.assertEquals(0, + assertEquals(0, schedulerApp1.getCurrentReservation().getMemorySize()); //app2 ResourceUsage (4GB reserved) - Assertions.assertEquals(1*GB, + assertEquals(1*GB, schedulerApp2 .getAppAttemptResourceUsage().getAllUsed().getMemorySize()); - Assertions.assertEquals(4*GB, + assertEquals(4*GB, schedulerApp2.getCurrentReservation().getMemorySize()); //move app2 which has one reservedContainer scheduler.moveApplication(app2.getApplicationId(), "b"); @@ -3052,10 +3048,10 @@ public void testReservedContainerLeakWhenMoveApplication() throws Exception { rm1.killApp(app2.getApplicationId()); rm1.killApp(app1.getApplicationId()); //after,moved app2 which has one reservedContainer - Assertions.assertEquals(0, srcQueue.getNumContainers()); - Assertions.assertEquals(0, desQueue.getNumContainers()); - Assertions.assertEquals(0, srcQueue.getUsedResources().getMemorySize()); - Assertions.assertEquals(0, desQueue.getUsedResources().getMemorySize()); + assertEquals(0, srcQueue.getNumContainers()); + assertEquals(0, desQueue.getNumContainers()); + assertEquals(0, srcQueue.getUsedResources().getMemorySize()); + assertEquals(0, desQueue.getUsedResources().getMemorySize()); rm1.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/scheduler/capacity/TestCapacitySchedulerApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerApps.java index f26ec8e8b2155..adf9d4923b1bf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerApps.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerApps.java @@ -87,7 +87,6 @@ import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.Resources; 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; @@ -111,7 +110,11 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.setUpMove; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.setUpMoveAmbiguousQueue; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerTestUtilities.stopResourceManager; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -160,7 +163,7 @@ public void testGetAppsInQueue() throws Exception { assertTrue(appsInRoot.contains(application2.getApplicationAttemptId())); assertEquals(3, appsInRoot.size()); - Assertions.assertNull(scheduler.getAppsInQueue("nonexistentqueue")); + assertNull(scheduler.getAppsInQueue("nonexistentqueue")); } @Test @@ -177,7 +180,7 @@ public void testAddAndRemoveAppFromCapacityScheduler() throws Exception { SchedulerApplication app = TestSchedulerUtils.verifyAppAddedAndRemovedFromScheduler( cs.getSchedulerApplications(), cs, "a1"); - Assertions.assertEquals("a1", app.getQueue().getQueueName()); + assertEquals("a1", app.getQueue().getQueueName()); } @Test @@ -210,7 +213,7 @@ public void testKillAllAppsInQueue() throws Exception { String queue = scheduler.getApplicationAttempt(appsInA1.get(0)).getQueue() .getQueueName(); - Assertions.assertEquals("a1", queue); + assertEquals("a1", queue); List appsInRoot = scheduler.getAppsInQueue("root"); assertTrue(appsInRoot.contains(appAttemptId)); @@ -257,7 +260,7 @@ public void testKillAllAppsInvalidSource() throws Exception { // now kill the app try { scheduler.killAllAppsInQueue("DOES_NOT_EXIST"); - Assertions.fail(); + fail(); } catch (YarnException e) { // expected } @@ -309,8 +312,8 @@ public void testAppReservationWithDominantResourceCalculator() throws Exception rm.getResourceScheduler().getNodeReport(nm1.getNodeId()); // check node report - Assertions.assertEquals(1 * GB, reportNm1.getUsedResource().getMemorySize()); - Assertions.assertEquals(9 * GB, reportNm1.getAvailableResource().getMemorySize()); + assertEquals(1 * GB, reportNm1.getUsedResource().getMemorySize()); + assertEquals(9 * GB, reportNm1.getAvailableResource().getMemorySize()); // add request for containers am1.addRequests(new String[]{"127.0.0.1", "127.0.0.2"}, 1 * GB, 1, 1); @@ -323,8 +326,8 @@ public void testAppReservationWithDominantResourceCalculator() throws Exception ApplicationResourceUsageReport report = rm.getResourceScheduler().getAppResourceUsageReport( attempt1.getAppAttemptId()); - Assertions.assertEquals(0, allocResponse.getAllocatedContainers().size()); - Assertions.assertEquals(0, report.getNumReservedContainers()); + assertEquals(0, allocResponse.getAllocatedContainers().size()); + assertEquals(0, report.getNumReservedContainers()); // container should get allocated on this node nm2.nodeHeartbeat(true); @@ -336,8 +339,8 @@ public void testAppReservationWithDominantResourceCalculator() throws Exception report = rm.getResourceScheduler().getAppResourceUsageReport( attempt1.getAppAttemptId()); - Assertions.assertEquals(1, allocResponse.getAllocatedContainers().size()); - Assertions.assertEquals(0, report.getNumReservedContainers()); + assertEquals(1, allocResponse.getAllocatedContainers().size()); + assertEquals(0, report.getNumReservedContainers()); rm.stop(); } @@ -347,7 +350,7 @@ public void testMoveAppAmbiguousQueue() throws Exception { AbstractYarnScheduler scheduler = (AbstractYarnScheduler) rm.getResourceScheduler(); QueueMetrics metrics = scheduler.getRootQueueMetrics(); - Assertions.assertEquals(0, metrics.getAppsPending()); + assertEquals(0, metrics.getAppsPending()); // submit an app MockRMAppSubmissionData data = MockRMAppSubmissionData.Builder.createWithMemory(GB, rm) @@ -364,7 +367,7 @@ public void testMoveAppAmbiguousQueue() throws Exception { String queue = scheduler.getApplicationAttempt(appsInA.get(0)).getQueue() .getQueueName(); - Assertions.assertEquals("a", queue); + assertEquals("a", queue); // now move the app scheduler.moveApplication(app.getApplicationId(), "a1"); @@ -373,7 +376,7 @@ public void testMoveAppAmbiguousQueue() throws Exception { queue = scheduler.getApplicationAttempt(appsInA1.get(0)).getQueue() .getQueueName(); - Assertions.assertEquals("a1", queue); + assertEquals("a1", queue); appsInA = scheduler.getAppsInQueue("root.a.a"); assertTrue(appsInA.isEmpty()); @@ -387,7 +390,7 @@ public void testMoveAppBasic() throws Exception { AbstractYarnScheduler scheduler = (AbstractYarnScheduler) rm.getResourceScheduler(); QueueMetrics metrics = scheduler.getRootQueueMetrics(); - Assertions.assertEquals(0, metrics.getAppsPending()); + assertEquals(0, metrics.getAppsPending()); // submit an app MockRMAppSubmissionData data = MockRMAppSubmissionData.Builder.createWithMemory(GB, rm) @@ -407,7 +410,7 @@ public void testMoveAppBasic() throws Exception { String queue = scheduler.getApplicationAttempt(appsInA1.get(0)).getQueue() .getQueueName(); - Assertions.assertEquals("a1", queue); + assertEquals("a1", queue); List appsInA = scheduler.getAppsInQueue("a"); assertTrue(appsInA.contains(appAttemptId)); @@ -434,7 +437,7 @@ public void testMoveAppBasic() throws Exception { queue = scheduler.getApplicationAttempt(appsInB1.get(0)).getQueue() .getQueueName(); - Assertions.assertEquals("b1", queue); + assertEquals("b1", queue); appsInB = scheduler.getAppsInQueue("b"); assertTrue(appsInB.contains(appAttemptId)); @@ -562,7 +565,7 @@ private void assertApps(ResourceScheduler scheduler, private void assertOneAppInQueue(AbstractYarnScheduler scheduler, String queueName) { List apps = scheduler.getAppsInQueue(queueName); assertEquals(1, apps.size()); - Assertions.assertEquals(queueName, + assertEquals(queueName, scheduler.getApplicationAttempt(apps.get(0)).getQueue().getQueueName()); } @@ -782,7 +785,7 @@ public void testMoveAppSuccess() throws Exception { @Test public void testMoveAppViolateQueueState() throws Exception { - assertThrows(YarnException.class, ()->{ + assertThrows(YarnException.class, () -> { resourceManager = new ResourceManager() { @Override protected RMNodeLabelsManager createNodeLabelManager() { @@ -792,24 +795,24 @@ protected RMNodeLabelsManager createNodeLabelManager() { } }; CapacitySchedulerConfiguration csConf = - new CapacitySchedulerConfiguration(); + new CapacitySchedulerConfiguration(); setupQueueConfiguration(csConf); StringBuilder qState = new StringBuilder(); qState.append(CapacitySchedulerConfiguration.PREFIX).append(B) - .append(CapacitySchedulerConfiguration.DOT) - .append(CapacitySchedulerConfiguration.STATE); + .append(CapacitySchedulerConfiguration.DOT) + .append(CapacitySchedulerConfiguration.STATE); csConf.set(qState.toString(), QueueState.STOPPED.name()); YarnConfiguration conf = new YarnConfiguration(csConf); conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class, - ResourceScheduler.class); + ResourceScheduler.class); resourceManager.init(conf); resourceManager.getRMContext().getContainerTokenSecretManager() - .rollMasterKey(); + .rollMasterKey(); resourceManager.getRMContext().getNMTokenSecretManager().rollMasterKey(); ((AsyncDispatcher) resourceManager.getRMContext().getDispatcher()).start(); mockContext = mock(RMContext.class); when(mockContext.getConfigurationProvider()).thenReturn( - new LocalConfigurationProvider()); + new LocalConfigurationProvider()); ResourceScheduler scheduler = resourceManager.getResourceScheduler(); @@ -818,8 +821,8 @@ protected RMNodeLabelsManager createNodeLabelManager() { // Register node1 String host0 = "host_0"; NodeManager nm0 = - registerNode(resourceManager, host0, 1234, 2345, NetworkTopology.DEFAULT_RACK, - Resources.createResource(6 * GB, 1), mockNodeStatus); + registerNode(resourceManager, host0, 1234, 2345, NetworkTopology.DEFAULT_RACK, + Resources.createResource(6 * GB, 1), mockNodeStatus); // ResourceRequest priorities Priority priority0 = Priority.newInstance(0); @@ -827,7 +830,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { // Submit application_0 Application application0 = - new Application("user_0", "a1", resourceManager); + new Application("user_0", "a1", resourceManager); application0.submit(); // app + app attempt event sent to scheduler application0.addNodeManager(host0, 1234, nm0); @@ -839,7 +842,7 @@ protected RMNodeLabelsManager createNodeLabelManager() { application0.addResourceRequestSpec(priority0, capability01); Task task00 = - new Task(application0, priority1, new String[]{host0}); + new Task(application0, priority1, new String[]{host0}); application0.addTask(task00); // Send resource requests to the scheduler @@ -1065,10 +1068,10 @@ public void testMaxParallelAppsPendingQueueMetrics() throws Exception { RMAppAttemptState.FINISHED, true)); } - Assertions.assertEquals(0 -, cs.getRootQueueMetrics().getAppsPending(), "No pending app should remain for root queue"); - Assertions.assertEquals(0 -, cs.getRootQueueMetrics().getAppsRunning(), "No running application should remain for root queue"); + assertEquals(0, cs.getRootQueueMetrics().getAppsPending(), + "No pending app should remain for root queue"); + assertEquals(0, cs.getRootQueueMetrics().getAppsRunning(), + "No running application should remain for root queue"); rm.stop(); } @@ -1106,7 +1109,7 @@ public void testMoveAllAppsInvalidDestination() throws Exception { // now move the app try { scheduler.moveAllApps("a1", "DOES_NOT_EXIST"); - Assertions.fail(); + fail(); } catch (YarnException e) { // expected } @@ -1150,7 +1153,7 @@ public void testMoveAllAppsInvalidSource() throws Exception { // now move the app try { scheduler.moveAllApps("DOES_NOT_EXIST", "b1"); - Assertions.fail(); + fail(); } catch (YarnException e) { // expected } @@ -1365,11 +1368,11 @@ public void testMoveAttemptNotAdded() throws Exception { CSQueue queueA = cs.getQueue("a"); CSQueue queueA1 = cs.getQueue("a1"); CSQueue queueB1 = cs.getQueue("b1"); - Assertions.assertEquals(1, rootQ.getNumApplications()); - Assertions.assertEquals(0, queueA.getNumApplications()); - Assertions.assertEquals(1, queueB.getNumApplications()); - Assertions.assertEquals(0, queueA1.getNumApplications()); - Assertions.assertEquals(1, queueB1.getNumApplications()); + assertEquals(1, rootQ.getNumApplications()); + assertEquals(0, queueA.getNumApplications()); + assertEquals(1, queueB.getNumApplications()); + assertEquals(0, queueA1.getNumApplications()); + assertEquals(1, queueB1.getNumApplications()); rm.close(); } @@ -1423,9 +1426,9 @@ public void testRemoveAttemptMoveAdded() throws Exception { // Move application to queue b1 sch.moveApplication(appAttemptId.getApplicationId(), "b1"); // Check queue metrics after move - Assertions.assertEquals(0, queueA1.getNumApplications()); - Assertions.assertEquals(1, queueB.getNumApplications()); - Assertions.assertEquals(0, queueB1.getNumApplications()); + assertEquals(0, queueA1.getNumApplications()); + assertEquals(1, queueB.getNumApplications()); + assertEquals(0, queueB1.getNumApplications()); // Release attempt add event ApplicationAttemptId appAttemptId2 = @@ -1435,27 +1438,27 @@ public void testRemoveAttemptMoveAdded() throws Exception { sch.handle(addAttemptEvent2); // Check metrics after attempt added - Assertions.assertEquals(0, queueA1.getNumApplications()); - Assertions.assertEquals(1, queueB.getNumApplications()); - Assertions.assertEquals(1, queueB1.getNumApplications()); + assertEquals(0, queueA1.getNumApplications()); + assertEquals(1, queueB.getNumApplications()); + assertEquals(1, queueB1.getNumApplications()); QueueMetrics queueB1M = queueB1.getMetrics(); QueueMetrics queueBM = queueB.getMetrics(); // Verify allocation MB of current state - Assertions.assertEquals(0, queueA1M.getAllocatedMB()); - Assertions.assertEquals(0, queueA1M.getAllocatedVirtualCores()); - Assertions.assertEquals(1024, queueB1M.getAllocatedMB()); - Assertions.assertEquals(1, queueB1M.getAllocatedVirtualCores()); + assertEquals(0, queueA1M.getAllocatedMB()); + assertEquals(0, queueA1M.getAllocatedVirtualCores()); + assertEquals(1024, queueB1M.getAllocatedMB()); + assertEquals(1, queueB1M.getAllocatedVirtualCores()); // remove attempt sch.handle(new AppAttemptRemovedSchedulerEvent(appAttemptId2, RMAppAttemptState.FINISHED, false)); - Assertions.assertEquals(0, queueA1M.getAllocatedMB()); - Assertions.assertEquals(0, queueA1M.getAllocatedVirtualCores()); - Assertions.assertEquals(0, queueB1M.getAllocatedMB()); - Assertions.assertEquals(0, queueB1M.getAllocatedVirtualCores()); + assertEquals(0, queueA1M.getAllocatedMB()); + assertEquals(0, queueA1M.getAllocatedVirtualCores()); + assertEquals(0, queueB1M.getAllocatedMB()); + assertEquals(0, queueB1M.getAllocatedVirtualCores()); verifyQueueMetrics(queueB1M); verifyQueueMetrics(queueBM); @@ -1477,16 +1480,16 @@ public void testAppSubmission() throws Exception { rm.start(); RMApp noParentQueueApp = submitAppAndWaitForState(rm, "q", RMAppState.FAILED); - Assertions.assertEquals(RMAppState.FAILED, noParentQueueApp.getState()); + assertEquals(RMAppState.FAILED, noParentQueueApp.getState()); RMApp ambiguousQueueApp = submitAppAndWaitForState(rm, "b", RMAppState.FAILED); - Assertions.assertEquals(RMAppState.FAILED, ambiguousQueueApp.getState()); + assertEquals(RMAppState.FAILED, ambiguousQueueApp.getState()); RMApp emptyPartQueueApp = submitAppAndWaitForState(rm, "root..a1", RMAppState.FAILED); - Assertions.assertEquals(RMAppState.FAILED, emptyPartQueueApp.getState()); + assertEquals(RMAppState.FAILED, emptyPartQueueApp.getState()); RMApp failedAutoQueue = submitAppAndWaitForState(rm, "root.a.b.c.d", RMAppState.FAILED); - Assertions.assertEquals(RMAppState.FAILED, failedAutoQueue.getState()); + assertEquals(RMAppState.FAILED, failedAutoQueue.getState()); } private RMApp submitAppAndWaitForState(MockRM rm, String b, RMAppState state) throws Exception { @@ -1533,13 +1536,13 @@ private CapacitySchedulerQueueInfo getQueueInfo(String name, } private void verifyQueueMetrics(QueueMetrics queue) { - Assertions.assertEquals(0, queue.getPendingMB()); - Assertions.assertEquals(0, queue.getActiveUsers()); - Assertions.assertEquals(0, queue.getActiveApps()); - Assertions.assertEquals(0, queue.getAppsPending()); - Assertions.assertEquals(0, queue.getAppsRunning()); - Assertions.assertEquals(0, queue.getAllocatedMB()); - Assertions.assertEquals(0, queue.getAllocatedVirtualCores()); + assertEquals(0, queue.getPendingMB()); + assertEquals(0, queue.getActiveUsers()); + assertEquals(0, queue.getActiveApps()); + assertEquals(0, queue.getAppsPending()); + assertEquals(0, queue.getAppsRunning()); + assertEquals(0, queue.getAllocatedMB()); + assertEquals(0, queue.getAllocatedVirtualCores()); } private Configuration getCapacityConfiguration(Configuration config) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java index cecc3ae9ef0ec..9b74370d9f939 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java @@ -18,6 +18,17 @@ package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.anyBoolean; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.spy; + import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList; import org.apache.hadoop.conf.Configuration; @@ -65,12 +76,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.SimpleCandidateNodeSet; import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey; import org.apache.hadoop.yarn.util.resource.Resources; -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.junit.contrib.java.lang.system.internal.NoExitSecurityManager; -import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -162,7 +171,7 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler(); for (CapacityScheduler.AsyncScheduleThread thread : cs.getAsyncSchedulerThreads()) { - Assertions.assertTrue(thread.getName() + assertTrue(thread.getName() .startsWith("AsyncCapacitySchedulerThread")); } } @@ -234,7 +243,7 @@ public RMNodeLabelsManager createNodeLabelManager() { waitTime -= 50; } - Assertions.assertEquals( + assertEquals( rm.getResourceScheduler().getRootQueueMetrics().getAllocatedMB(), totalAsked); @@ -242,7 +251,7 @@ public RMNodeLabelsManager createNodeLabelManager() { // required waitTime = 2000; // ms while (waitTime > 0) { - Assertions.assertEquals( + assertEquals( rm.getResourceScheduler().getRootQueueMetrics().getAllocatedMB(), totalAsked); waitTime -= 50; @@ -277,7 +286,7 @@ public void testCommitProposalForFailedAppAttempt() .nodeCount() < 2) { Thread.sleep(10); } - Assertions.assertEquals(2, + assertEquals(2, ((AbstractYarnScheduler) rm.getRMContext().getScheduler()) .getNodeTracker().nodeCount()); CapacityScheduler scheduler = @@ -310,8 +319,8 @@ public void testCommitProposalForFailedAppAttempt() // nm1 runs 1 container(app1-container_01/AM) // nm2 runs 1 container(app1-container_02) - Assertions.assertEquals(1, sn1.getNumContainers()); - Assertions.assertEquals(1, sn2.getNumContainers()); + assertEquals(1, sn1.getNumContainers()); + assertEquals(1, sn2.getNumContainers()); // kill app attempt1 scheduler.handle( @@ -352,8 +361,8 @@ public void testCommitProposalForFailedAppAttempt() ResourceCommitRequest request = new ResourceCommitRequest(null, reservedProposals, null); scheduler.tryCommit(scheduler.getClusterResource(), request, true); - Assertions.assertNull( - sn2.getReservedContainer(), "Outdated proposal should not be accepted!"); + assertNull(sn2.getReservedContainer(), + "Outdated proposal should not be accepted!"); rm.stop(); } @@ -381,7 +390,7 @@ public void testCommitOutdatedReservedProposal() throws Exception { waitTime -= 10; Thread.sleep(10); } - Assertions.assertEquals(2, + assertEquals(2, ((AbstractYarnScheduler) rm.getRMContext().getScheduler()) .getNodeTracker().nodeCount()); @@ -423,8 +432,8 @@ public void testCommitOutdatedReservedProposal() throws Exception { // nm1 runs 3 containers(app1-container_01/AM, app1-container_02, // app2-container_01/AM) // nm2 runs 1 container(app1-container_03) - Assertions.assertEquals(3, sn1.getNumContainers()); - Assertions.assertEquals(1, sn2.getNumContainers()); + assertEquals(3, sn1.getNumContainers()); + assertEquals(1, sn2.getNumContainers()); // reserve 1 container(app1-container_04) for app1 on nm1 ResourceRequest rr2 = ResourceRequest @@ -438,15 +447,15 @@ public void testCommitOutdatedReservedProposal() throws Exception { waitTime -= 10; Thread.sleep(10); } - Assertions.assertNotNull(sn1.getReservedContainer()); + assertNotNull(sn1.getReservedContainer()); final CapacityScheduler cs = (CapacityScheduler) scheduler; - final CapacityScheduler spyCs = Mockito.spy(cs); + final CapacityScheduler spyCs = spy(cs); final AtomicBoolean isFirstReserve = new AtomicBoolean(true); final AtomicBoolean isChecked = new AtomicBoolean(false); // handle CapacityScheduler#tryCommit, // reproduce the process that can raise IllegalStateException before - Mockito.doAnswer(new Answer() { + doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) throws Exception { ResourceCommitRequest request = (ResourceCommitRequest) invocation.getArguments()[1]; @@ -460,7 +469,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { ContainerState.COMPLETE, "", ContainerExitStatus.KILLED_BY_RESOURCEMANAGER), RMContainerEventType.KILL); - Assertions.assertEquals(0, sn2.getCopiedListOfRunningContainers().size()); + assertEquals(0, sn2.getCopiedListOfRunningContainers().size()); // unreserve app1-container_04 on nm1 // and allocate app1-container_05 on nm2 cs.handle(new NodeUpdateSchedulerEvent(sn2.getRMNode())); @@ -470,8 +479,8 @@ public Object answer(InvocationOnMock invocation) throws Exception { waitTime -= 10; Thread.sleep(10); } - Assertions.assertEquals(1, sn2.getCopiedListOfRunningContainers().size()); - Assertions.assertNull(sn1.getReservedContainer()); + assertEquals(1, sn2.getCopiedListOfRunningContainers().size()); + assertNull(sn1.getReservedContainer()); // reserve app2-container_02 on nm1 ResourceRequest rr3 = ResourceRequest @@ -484,7 +493,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { waitTime -= 10; Thread.sleep(10); } - Assertions.assertNotNull(sn1.getReservedContainer()); + assertNotNull(sn1.getReservedContainer()); // call real apply try { @@ -492,7 +501,7 @@ public Object answer(InvocationOnMock invocation) throws Exception { (ResourceCommitRequest) invocation.getArguments()[1], true); } catch (Exception e) { e.printStackTrace(); - Assertions.fail(); + fail(); } isChecked.set(true); } else { @@ -501,8 +510,8 @@ public Object answer(InvocationOnMock invocation) throws Exception { } return null; } - }).when(spyCs).tryCommit(Mockito.any(Resource.class), - Mockito.any(ResourceCommitRequest.class), Mockito.anyBoolean()); + }).when(spyCs).tryCommit(any(Resource.class), + any(ResourceCommitRequest.class), anyBoolean()); spyCs.handle(new NodeUpdateSchedulerEvent(sn1.getRMNode())); @@ -538,7 +547,7 @@ public void testNodeResourceOverAllocated() .nodeCount() < 2) { Thread.sleep(10); } - Assertions.assertEquals(2, + assertEquals(2, ((AbstractYarnScheduler) rm.getRMContext().getScheduler()) .getNodeTracker().nodeCount()); CapacityScheduler scheduler = @@ -593,8 +602,8 @@ public void testNodeResourceOverAllocated() scheduler.tryCommit(scheduler.getClusterResource(), request, true); } // make sure node resource can't be over-allocated! - Assertions.assertTrue( - sn1.getUnallocatedResource().getMemorySize() > 0, "Node resource is Over-allocated!"); + assertTrue(sn1.getUnallocatedResource().getMemorySize() > 0, + "Node resource is Over-allocated!"); rm.stop(); } @@ -675,9 +684,9 @@ public RMNodeLabelsManager createNodeLabelManager() { // Make sure that NM5-9 don't have non-AM containers. for (int i = 0; i < 9; i++) { if (i < 5) { - Assertions.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) > 0); + assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) > 0); } else { - Assertions.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) == 0); + assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) == 0); } } @@ -750,12 +759,12 @@ public RMNodeLabelsManager createNodeLabelManager() { new RMNodeEvent(rmNode.getNodeID(), RMNodeEventType.GRACEFUL_DECOMMISSION)); rm.drainEvents(); - Assertions.assertEquals(NodeState.DECOMMISSIONING, rmNode.getState()); + assertEquals(NodeState.DECOMMISSIONING, rmNode.getState()); boolean shouldSkip = cs.shouldSkipNodeSchedule(cs.getNode(nms.get(i).getNodeId()), cs, true); // make sure should skip - Assertions.assertTrue(shouldSkip); + assertTrue(shouldSkip); } for (int i = 5; i < 9; i++) { @@ -763,7 +772,7 @@ public RMNodeLabelsManager createNodeLabelManager() { cs.shouldSkipNodeSchedule(cs.getNode(nms.get(i).getNodeId()), cs, true); // make sure should not skip - Assertions.assertFalse(shouldSkip); + assertFalse(shouldSkip); } pauseNMHeartbeat(); @@ -782,9 +791,9 @@ public RMNodeLabelsManager createNodeLabelManager() { //Make sure that NM 0-5 don't have non-AM containers. for (int i = 0; i < 9; i++) { if (i < 5) { - Assertions.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) == 0); + assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) == 0); } else { - Assertions.assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) > 0); + assertTrue(checkNumNonAMContainersOnNode(cs, nms.get(i)) > 0); } } rm.close(); @@ -847,7 +856,7 @@ public void testCommitDuplicatedAllocateFromReservedProposals() .nodeCount() < 2) { Thread.sleep(10); } - Assertions.assertEquals(2, + assertEquals(2, ((AbstractYarnScheduler) rm.getRMContext().getScheduler()) .getNodeTracker().nodeCount()); CapacityScheduler cs = @@ -877,8 +886,8 @@ public void testCommitDuplicatedAllocateFromReservedProposals() // nm1 runs 2 container(container_01/AM, container_02) allocateAndLaunchContainers(am, nm1, rm, 1, Resources.createResource(6 * GB), 0, 2); - Assertions.assertEquals(2, sn1.getNumContainers()); - Assertions.assertEquals(1 * GB, sn1.getUnallocatedResource().getMemorySize()); + assertEquals(2, sn1.getNumContainers()); + assertEquals(1 * GB, sn1.getUnallocatedResource().getMemorySize()); // app asks 5 * 2G container // nm1 reserves 1 * 2G containers @@ -886,7 +895,7 @@ public void testCommitDuplicatedAllocateFromReservedProposals() .newInstance(Priority.newInstance(0), "*", Resources.createResource(2 * GB), 5)), null); cs.handle(new NodeUpdateSchedulerEvent(sn1.getRMNode())); - Assertions.assertEquals(1, schedulerApp.getReservedContainers().size()); + assertEquals(1, schedulerApp.getReservedContainers().size()); // rm kills 1 * 6G container_02 for (RMContainer rmContainer : sn1.getCopiedListOfRunningContainers()) { @@ -898,13 +907,13 @@ public void testCommitDuplicatedAllocateFromReservedProposals() RMContainerEventType.KILL); } } - Assertions.assertEquals(7 * GB, sn1.getUnallocatedResource().getMemorySize()); + assertEquals(7 * GB, sn1.getUnallocatedResource().getMemorySize()); - final CapacityScheduler spyCs = Mockito.spy(cs); + final CapacityScheduler spyCs = spy(cs); // handle CapacityScheduler#tryCommit, submit duplicated proposals // that do allocation for reserved container for three times, // to simulate that case in YARN-8127 - Mockito.doAnswer(new Answer() { + doAnswer(new Answer() { public Boolean answer(InvocationOnMock invocation) throws Exception { ResourceCommitRequest request = (ResourceCommitRequest) invocation.getArguments()[1]; @@ -915,14 +924,14 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { (ResourceCommitRequest) invocation.getArguments()[1], (Boolean) invocation.getArguments()[2]); } - Assertions.assertEquals(2, sn1.getCopiedListOfRunningContainers().size()); - Assertions.assertEquals(5 * GB, + assertEquals(2, sn1.getCopiedListOfRunningContainers().size()); + assertEquals(5 * GB, sn1.getUnallocatedResource().getMemorySize()); } return true; } - }).when(spyCs).tryCommit(Mockito.any(Resource.class), - Mockito.any(ResourceCommitRequest.class), Mockito.anyBoolean()); + }).when(spyCs).tryCommit(any(Resource.class), + any(ResourceCommitRequest.class), anyBoolean()); spyCs.handle(new NodeUpdateSchedulerEvent(sn1.getRMNode())); @@ -977,8 +986,8 @@ public void testReleaseOutdatedReservedContainer() throws Exception { cs.getApplicationAttempt(am1.getApplicationAttemptId()); cs.handle(new NodeUpdateSchedulerEvent(rmNode1)); - Assertions.assertEquals(1, schedulerApp1.getReservedContainers().size()); - Assertions.assertEquals(9 * GB, + assertEquals(1, schedulerApp1.getReservedContainers().size()); + assertEquals(9 * GB, defaultQueue.getQueueResourceUsage().getUsed().getMemorySize()); RMContainer reservedContainer = @@ -988,13 +997,13 @@ public void testReleaseOutdatedReservedContainer() throws Exception { sn2, sn1, cs.getRMContext(), reservedContainer); boolean tryCommitResult = cs.tryCommit(cs.getClusterResource(), allocateFromSameReservedContainerProposal1, true); - Assertions.assertTrue(tryCommitResult); + assertTrue(tryCommitResult); ResourceCommitRequest allocateFromSameReservedContainerProposal2 = createAllocateFromReservedProposal(4, allocateResource, schedulerApp1, sn3, sn1, cs.getRMContext(), reservedContainer); tryCommitResult = cs.tryCommit(cs.getClusterResource(), allocateFromSameReservedContainerProposal2, true); - Assertions.assertFalse(tryCommitResult, "This proposal should be rejected because " + assertFalse(tryCommitResult, "This proposal should be rejected because " + "it try to release an outdated reserved container"); rm1.close(); @@ -1059,17 +1068,17 @@ public void testCommitProposalsForUnusableNode() throws Exception { Resources.createResource(8 * GB), 1)), null); List reservedProposalParts = new ArrayList<>(); - final CapacityScheduler spyCs = Mockito.spy(cs); + final CapacityScheduler spyCs = spy(cs); // handle CapacityScheduler#tryCommit - Mockito.doAnswer(new Answer() { + doAnswer(new Answer() { public Boolean answer(InvocationOnMock invocation) throws Exception { for (Object argument : invocation.getArguments()) { reservedProposalParts.add(argument); } return false; } - }).when(spyCs).tryCommit(Mockito.any(Resource.class), - Mockito.any(ResourceCommitRequest.class), Mockito.anyBoolean()); + }).when(spyCs).tryCommit(any(Resource.class), + any(ResourceCommitRequest.class), anyBoolean()); spyCs.handle(new NodeUpdateSchedulerEvent(sn1.getRMNode())); @@ -1078,15 +1087,15 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { cs.getRMContext().getDispatcher().getEventHandler().handle( new RMNodeEvent(nm1.getNodeId(), RMNodeEventType.DECOMMISSION)); rm.drainEvents(); - Assertions.assertEquals(NodeState.DECOMMISSIONED, rmNode1.getState()); - Assertions.assertNull(cs.getNode(nm1.getNodeId())); + assertEquals(NodeState.DECOMMISSIONED, rmNode1.getState()); + assertNull(cs.getNode(nm1.getNodeId())); // try commit after nm1 decommissioned boolean isSuccess = cs.tryCommit((Resource) reservedProposalParts.get(0), (ResourceCommitRequest) reservedProposalParts.get(1), (Boolean) reservedProposalParts.get(2)); - Assertions.assertFalse(isSuccess); + assertFalse(isSuccess); rm.stop(); } @@ -1195,10 +1204,10 @@ public void testReturnNullWhenGetSchedulerContainer() throws Exception { ContainerId.newContainerId(am1.getApplicationAttemptId(), 1)); // spy CapacityScheduler - final CapacityScheduler spyCs = Mockito.spy(cs); + final CapacityScheduler spyCs = spy(cs); // hook CapacityScheduler#submitResourceCommitRequest List assignmentSnapshots = new ArrayList<>(); - Mockito.doAnswer(new Answer() { + doAnswer(new Answer() { public Boolean answer(InvocationOnMock invocation) throws Exception { CSAssignment assignment = (CSAssignment) invocation.getArguments()[1]; if (cs.getNode(nm1.getNodeId()) != null) { @@ -1206,8 +1215,8 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { cs.getRMContext().getDispatcher().getEventHandler().handle( new RMNodeEvent(nm1.getNodeId(), RMNodeEventType.DECOMMISSION)); rm.drainEvents(); - Assertions.assertEquals(NodeState.DECOMMISSIONED, rmNode1.getState()); - Assertions.assertNull(cs.getNode(nm1.getNodeId())); + assertEquals(NodeState.DECOMMISSIONED, rmNode1.getState()); + assertNull(cs.getNode(nm1.getNodeId())); assignmentSnapshots.add(assignment); } else { // add am container on nm1 to containersToKill @@ -1219,15 +1228,15 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { assignment); return false; } - }).when(spyCs).submitResourceCommitRequest(Mockito.any(Resource.class), - Mockito.any(CSAssignment.class)); + }).when(spyCs).submitResourceCommitRequest(any(Resource.class), + any(CSAssignment.class)); // allocation on nm1, test return null when get scheduler container CandidateNodeSet candidateNodeSet = new SimpleCandidateNodeSet(sn1); spyCs.allocateContainersToNode(candidateNodeSet, false); // make sure unconfirmed resource is decreased correctly - Assertions.assertTrue(spyCs.getApplicationAttempt(am1.getApplicationAttemptId()) + assertTrue(spyCs.getApplicationAttempt(am1.getApplicationAttemptId()) .hasPendingResourceRequest(RMNodeLabelsManager.NO_LABEL, SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY)); @@ -1237,7 +1246,7 @@ public Boolean answer(InvocationOnMock invocation) throws Exception { new SimpleCandidateNodeSet(sn2); spyCs.allocateContainersToNode(candidateNodeSet, false); // make sure unconfirmed resource is decreased correctly - Assertions.assertTrue(spyCs.getApplicationAttempt(am1.getApplicationAttemptId()) + assertTrue(spyCs.getApplicationAttempt(am1.getApplicationAttemptId()) .hasPendingResourceRequest(RMNodeLabelsManager.NO_LABEL, SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY)); @@ -1280,7 +1289,7 @@ private void allocateAndLaunchContainers(MockAM am, MockNM nm, MockRM rm, ContainerId lastContainerId = ContainerId .newContainerId(am.getApplicationAttemptId(), startContainerId + nContainer - 1); - Assertions.assertTrue( + assertTrue( rm.waitForState(nm, lastContainerId, RMContainerState.ALLOCATED)); // Acquire them, and NM report RUNNING am.allocate(null, null); @@ -1295,7 +1304,7 @@ private void allocateAndLaunchContainers(MockAM am, MockNM nm, MockRM rm, rmContainer.handle( new RMContainerEvent(containerId, RMContainerEventType.LAUNCHED)); } else { - Assertions.fail("Cannot find RMContainer"); + fail("Cannot find RMContainer"); } rm.waitForState(nm, ContainerId.newContainerId(am.getApplicationAttemptId(), cId), diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueueBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueueBase.java index f2ec1ed0b3224..ae144b43aa483 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueueBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoCreatedQueueBase.java @@ -73,7 +73,6 @@ import org.apache.hadoop.yarn.util.YarnVersionInfo; import org.apache.hadoop.yarn.util.resource.Resources; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import java.io.IOException; @@ -696,7 +695,7 @@ protected RMApp submitApp(String user, String queue, String nodeLabel) .withAmLabel(nodeLabel) .build(); RMApp app = MockRMAppSubmitter.submit(mockRM, data); - Assertions.assertEquals(app.getAmNodeLabelExpression(), nodeLabel); + assertEquals(app.getAmNodeLabelExpression(), nodeLabel); // check preconditions List appsInC = cs.getAppsInQueue(PARENT_QUEUE); assertEquals(1, appsInC.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/scheduler/capacity/TestCapacitySchedulerAutoQueueCreation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoQueueCreation.java index 738d638acf51d..1fbfa30b57204 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoQueueCreation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAutoQueueCreation.java @@ -73,7 +73,6 @@ .RMContainerTokenSecretManager; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.slf4j.Logger; @@ -661,18 +660,17 @@ public void testAutoQueueCreationWithWeightModeAndMaxAppLifetimeFirstSubmittedAp .build(); RMApp app1 = MockRMAppSubmitter.submit(newMockRM, app); - Assertions.assertEquals(newCS.getMaximumApplicationLifetime("root.test.user"), 20L); + assertEquals(newCS.getMaximumApplicationLifetime("root.test.user"), 20L); try { newMockRM.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); - Assertions.assertEquals(RMAppState.KILLED, app1.getState()); - Assertions.assertTrue( - totalTimeRun > (defaultRootLifetime * 1000), "Application killed before default lifetime value"); - Assertions.assertTrue( - - totalTimeRun < (maxRootLifetime * 1000), "Application killed after max lifetime value " + totalTimeRun); + assertEquals(RMAppState.KILLED, app1.getState()); + assertTrue(totalTimeRun > (defaultRootLifetime * 1000), + "Application killed before default lifetime value"); + assertTrue(totalTimeRun < (maxRootLifetime * 1000), + "Application killed after max lifetime value " + totalTimeRun); } finally { ((CapacityScheduler) newMockRM.getResourceScheduler()).stop(); newMockRM.stop(); @@ -919,28 +917,23 @@ public void testClusterResourceUpdationOnAutoCreatedLeafQueues() throws Resource MIN_RES = Resources.createResource(14438, 6); - Assertions.assertEquals( - Resources.none(), user3LeafQueue.getQueueResourceQuotas() - .getEffectiveMinResource(), "Effective Min resource for USER3 is not correct"); - Assertions.assertEquals( - MAX_RES, user3LeafQueue - .getQueueResourceQuotas() - .getEffectiveMaxResource(), "Effective Max resource for USER3 is not correct"); + assertEquals(Resources.none(), user3LeafQueue.getQueueResourceQuotas() + .getEffectiveMinResource(), "Effective Min resource for USER3 is not correct"); + assertEquals(MAX_RES, user3LeafQueue + .getQueueResourceQuotas() + .getEffectiveMaxResource(), "Effective Max resource for USER3 is not correct"); CSQueue user1LeafQueue = newCS.getQueue(USER1); CSQueue user2LeafQueue = newCS.getQueue(USER2); - Assertions.assertEquals( - MIN_RES, user1LeafQueue.getQueueResourceQuotas() - .getEffectiveMinResource(), "Effective Min resource for USER2 is not correct"); - Assertions.assertEquals( - MAX_RES, user1LeafQueue.getQueueResourceQuotas().getEffectiveMaxResource(), "Effective Max resource for USER2 is not correct"); - - Assertions.assertEquals( - MIN_RES, user2LeafQueue.getQueueResourceQuotas() - .getEffectiveMinResource(), "Effective Min resource for USER1 is not correct"); - Assertions.assertEquals( - MAX_RES, user2LeafQueue.getQueueResourceQuotas() - .getEffectiveMaxResource(), "Effective Max resource for USER1 is not correct"); + assertEquals(MIN_RES, user1LeafQueue.getQueueResourceQuotas() + .getEffectiveMinResource(), "Effective Min resource for USER2 is not correct"); + assertEquals(MAX_RES, user1LeafQueue.getQueueResourceQuotas().getEffectiveMaxResource(), + "Effective Max resource for USER2 is not correct"); + + assertEquals(MIN_RES, user2LeafQueue.getQueueResourceQuotas() + .getEffectiveMinResource(), "Effective Min resource for USER1 is not correct"); + assertEquals(MAX_RES, user2LeafQueue.getQueueResourceQuotas() + .getEffectiveMaxResource(), "Effective Max resource for USER1 is not correct"); // unregister one NM. newMockRM.unRegisterNode(nm3); @@ -948,12 +941,11 @@ public void testClusterResourceUpdationOnAutoCreatedLeafQueues() throws Resource MAX_RES_UPDATED = Resources.createResource(128000, 20); // After loosing one NM, resources will reduce - Assertions.assertEquals( - MIN_RES_UPDATED, user1LeafQueue.getQueueResourceQuotas().getEffectiveMinResource - (), "Effective Min resource for USER2 is not correct"); - Assertions.assertEquals( - MAX_RES_UPDATED, user2LeafQueue.getQueueResourceQuotas() - .getEffectiveMaxResource(), "Effective Max resource for USER2 is not correct"); + assertEquals(MIN_RES_UPDATED, + user1LeafQueue.getQueueResourceQuotas().getEffectiveMinResource + (), "Effective Min resource for USER2 is not correct"); + assertEquals(MAX_RES_UPDATED, user2LeafQueue.getQueueResourceQuotas() + .getEffectiveMaxResource(), "Effective Max resource for USER2 is not correct"); } finally { cleanupQueue(USER1); @@ -1107,8 +1099,7 @@ public RMNodeLabelsManager createNodeLabelManager() { CapacityScheduler cs = (CapacityScheduler) mockRM.getResourceScheduler(); CSQueue queue = cs.getQueue("root.a.testuser"); assertNotNull(queue, "Leaf queue has not been auto-created"); - assertEquals(1 -, queue.getNumApplications(), "Number of running applications"); + assertEquals(1, queue.getNumApplications(), "Number of running applications"); } finally { if (mockRM != null) { mockRM.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/scheduler/capacity/TestCapacitySchedulerConfigValidator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfigValidator.java index b9ccb808e2a90..59499a1ab5369 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfigValidator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfigValidator.java @@ -40,17 +40,23 @@ import org.apache.hadoop.yarn.util.YarnVersionInfo; import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import java.io.IOException; import java.util.HashMap; import java.util.Map; import static org.apache.hadoop.yarn.api.records.ResourceInformation.GPU_URI; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestCapacitySchedulerConfigValidator { public static final int NODE_MEMORY = 16; @@ -120,14 +126,14 @@ public static void setupResources(boolean useGpu) { */ @Test public void testValidateMemoryAllocationInvalidMinMem() { - assertThrows(YarnRuntimeException.class, ()->{ + assertThrows(YarnRuntimeException.class, () -> { Map configs = new HashMap(); configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, "0"); Configuration config = CapacitySchedulerConfigGeneratorForTest - .createConfiguration(configs); + .createConfiguration(configs); CapacitySchedulerConfigValidator.validateMemoryAllocation(config); fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB + - " should be > 0"); + " should be > 0"); }); } @@ -137,16 +143,15 @@ public void testValidateMemoryAllocationInvalidMinMem() { */ @Test public void testValidateMemoryAllocationHIgherMinThanMaxMem() { - assertThrows(YarnRuntimeException.class, ()->{ + assertThrows(YarnRuntimeException.class, () -> { Map configs = new HashMap(); configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB, "8192"); configs.put(YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, "1024"); Configuration config = CapacitySchedulerConfigGeneratorForTest - .createConfiguration(configs); + .createConfiguration(configs); CapacitySchedulerConfigValidator.validateMemoryAllocation(config); fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB + " should be > " - + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB); - + + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB); }); } @@ -168,14 +173,14 @@ public void testValidateMemoryAllocation() { */ @Test public void testValidateVCoresInvalidMinVCore() { - assertThrows(YarnRuntimeException.class, ()->{ + assertThrows(YarnRuntimeException.class, () -> { Map configs = new HashMap(); configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES, "0"); Configuration config = CapacitySchedulerConfigGeneratorForTest - .createConfiguration(configs); + .createConfiguration(configs); CapacitySchedulerConfigValidator.validateVCores(config); fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES - + " should be > 0"); + + " should be > 0"); }); } @@ -185,16 +190,16 @@ public void testValidateVCoresInvalidMinVCore() { */ @Test public void testValidateVCoresHigherMinThanMaxVCore() { - assertThrows(YarnRuntimeException.class, ()->{ + assertThrows(YarnRuntimeException.class, () -> { Map configs = new HashMap(); configs.put(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES, "4"); configs.put(YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, "1"); Configuration config = CapacitySchedulerConfigGeneratorForTest - .createConfiguration(configs); + .createConfiguration(configs); CapacitySchedulerConfigValidator.validateVCores(config); fail(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES + - " should be > " - + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB); + " should be > " + + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB); }); } @@ -224,8 +229,7 @@ public void testValidateCSConfigInvalidCapacity() { .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("Invalid capacity"); } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() - .startsWith("Illegal capacity")); + assertTrue(e.getCause().getMessage().startsWith("Illegal capacity")); } } @@ -244,7 +248,7 @@ public void testValidateCSConfigDefaultRCAbsoluteModeParentMaxMemoryExceeded() .validateCSConfiguration(oldConfiguration, newConfiguration, rmContext); fail("Parent maximum capacity exceeded"); } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .startsWith("Max resource configuration")); } finally { mockRM.stop(); @@ -285,7 +289,7 @@ public void testValidateCSConfigDominantRCAbsoluteModeParentMaxMemoryExceeded() .validateCSConfiguration(oldConfiguration, newConfiguration, rmContext); fail("Parent maximum capacity exceeded"); } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .startsWith("Max resource configuration")); } finally { mockRM.stop(); @@ -306,7 +310,7 @@ public void testValidateCSConfigDominantRCAbsoluteModeParentMaxVcoreExceeded() t .validateCSConfiguration(oldConfiguration, newConfiguration, rmContext); fail("Parent maximum capacity exceeded"); } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .startsWith("Max resource configuration")); } finally { mockRM.stop(); @@ -327,7 +331,7 @@ public void testValidateCSConfigDominantRCAbsoluteModeParentMaxGPUExceeded() thr .validateCSConfiguration(oldConfiguration, newConfiguration, rmContext); fail("Parent maximum capacity exceeded"); } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .startsWith("Max resource configuration")); } finally { mockRM.stop(); @@ -344,7 +348,7 @@ public void testValidateCSConfigStopALeafQueue() throws IOException { RMContext rmContext = prepareRMContext(); boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assertions.assertTrue(isValidConfig); + assertTrue(isValidConfig); } /** @@ -363,7 +367,7 @@ public void testValidateCSConfigStopANonLeafQueueInvalid() { .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("There are child queues in running state"); } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .contains("The parent queue:root cannot be STOPPED")); } } @@ -382,7 +386,7 @@ public void testValidateCSConfigStopANonLeafQueue() throws IOException { RMContext rmContext = prepareRMContext(); Boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assertions.assertTrue(isValidConfig); + assertTrue(isValidConfig); } @@ -410,7 +414,7 @@ public void testValidateCSConfigAddALeafQueueInvalid() { fail("Invalid capacity for children of queue root"); } } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .startsWith("Illegal capacity")); } } @@ -436,7 +440,7 @@ public void testValidateCSConfigAddALeafQueueValid() throws IOException { RMContext rmContext = prepareRMContext(); Boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assertions.assertTrue(isValidConfig); + assertTrue(isValidConfig); } @Test @@ -459,33 +463,33 @@ public void testValidateDoesNotModifyTheDefaultMetricsSystem() throws Exception QueueMetrics origQM1 = cache.get("root.test1"); QueueMetrics origQM2 = cache.get("root.test2"); - Assertions.assertNotNull(origQM1, "Original queues should be found in the cache"); - Assertions.assertNotNull(origQM2, "Original queues should be found in the cache"); + assertNotNull(origQM1, "Original queues should be found in the cache"); + assertNotNull(origQM2, "Original queues should be found in the cache"); QueueMetrics origPQM1 = cache.get("default.root.test1"); QueueMetrics origPQM2 = cache.get("default.root.test2"); - Assertions.assertNotNull( - origPQM1, "Original queues should be found in the cache (PartitionQueueMetrics)"); - Assertions.assertNotNull( - origPQM2, "Original queues should be found in the cache (PartitionQueueMetrics)"); + assertNotNull(origPQM1, + "Original queues should be found in the cache (PartitionQueueMetrics)"); + assertNotNull(origPQM2, + "Original queues should be found in the cache (PartitionQueueMetrics)"); MetricsSource origMS1 = ms.getSource("QueueMetrics,q0=root,q1=test1"); MetricsSource origMS2 = ms.getSource("QueueMetrics,q0=root,q1=test2"); - Assertions.assertNotNull( - origMS1, "Original queues should be found in the Metrics System"); - Assertions.assertNotNull( - origMS2, "Original queues should be found in the Metrics System"); + assertNotNull(origMS1, + "Original queues should be found in the Metrics System"); + assertNotNull(origMS2, + "Original queues should be found in the Metrics System"); MetricsSource origPMS1 = ms .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test1"); MetricsSource origPMS2 = ms .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test2"); - Assertions.assertNotNull( - origPMS1, "Original queues should be found in Metrics System (PartitionQueueMetrics)"); - Assertions.assertNotNull( - origPMS2, "Original queues should be found in Metrics System (PartitionQueueMetrics)"); + assertNotNull(origPMS1, + "Original queues should be found in Metrics System (PartitionQueueMetrics)"); + assertNotNull(origPMS2, + "Original queues should be found in Metrics System (PartitionQueueMetrics)"); Configuration newConfig = new Configuration(oldConfig); newConfig @@ -499,32 +503,30 @@ public void testValidateDoesNotModifyTheDefaultMetricsSystem() throws Exception boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assertions.assertTrue(isValidConfig); - - Assertions.assertFalse( - cache.containsKey("root.test3"), "Validated new queue should not be in the cache"); - Assertions.assertFalse( - cache.containsKey("default.root.test3"), "Validated new queue should not be in the cache (PartitionQueueMetrics)"); - Assertions.assertNull( - ms.getSource("QueueMetrics,q0=root,q1=test3"), "Validated new queue should not be in the Metrics System"); - Assertions.assertNull( - - ms - .getSource("PartitionQueueMetrics,partition=,q0=root,q1=test3"), "Validated new queue should not be in Metrics System (PartitionQueueMetrics)"); + assertTrue(isValidConfig); + + assertFalse(cache.containsKey("root.test3"), + "Validated new queue should not be in the cache"); + assertFalse(cache.containsKey("default.root.test3"), + "Validated new queue should not be in the cache (PartitionQueueMetrics)"); + assertNull(ms.getSource("QueueMetrics,q0=root,q1=test3"), + "Validated new queue should not be in the Metrics System"); + assertNull(ms.getSource("PartitionQueueMetrics,partition=,q0=root,q1=test3"), + "Validated new queue should not be in Metrics System (PartitionQueueMetrics)"); // Config validation should not change the existing // objects in the cache and the metrics system - Assertions.assertEquals(origQM1, cache.get("root.test1")); - Assertions.assertEquals(origQM2, cache.get("root.test2")); - Assertions.assertEquals(origPQM1, cache.get("default.root.test1")); - Assertions.assertEquals(origPQM1, cache.get("default.root.test1")); - Assertions.assertEquals(origMS1, + assertEquals(origQM1, cache.get("root.test1")); + assertEquals(origQM2, cache.get("root.test2")); + assertEquals(origPQM1, cache.get("default.root.test1")); + assertEquals(origPQM1, cache.get("default.root.test1")); + assertEquals(origMS1, ms.getSource("QueueMetrics,q0=root,q1=test1")); - Assertions.assertEquals(origMS2, + assertEquals(origMS2, ms.getSource("QueueMetrics,q0=root,q1=test2")); - Assertions.assertEquals(origPMS1, + assertEquals(origPMS1, ms.getSource("PartitionQueueMetrics,partition=,q0=root,q1=test1")); - Assertions.assertEquals(origPMS2, + assertEquals(origPMS2, ms.getSource("PartitionQueueMetrics,partition=,q0=root,q1=test2")); } finally { mockRM.stop(); @@ -551,9 +553,9 @@ public void testValidateCSConfigInvalidQueueDeletion() { .validateCSConfiguration(oldConfig, newConfig, rmContext); fail("Invalid capacity for children of queue root"); } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .contains("root.test2 cannot be deleted")); - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .contains("the queue is not yet in stopped state")); } } @@ -580,7 +582,7 @@ public void testValidateCSConfigInvalidQueueDeletion2() { fail("Invalid capacity for children of queue root"); } } catch (IOException e) { - Assertions.assertTrue(e.getCause().getMessage() + assertTrue(e.getCause().getMessage() .contains("Illegal capacity")); } } @@ -603,7 +605,7 @@ public void testValidateCSConfigValidQueueDeletion() throws IOException { RMContext rmContext = prepareRMContext(); boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assertions.assertTrue(isValidConfig); + assertTrue(isValidConfig); } @@ -621,30 +623,26 @@ public void testAddQueueToALeafQueue() throws IOException { RMContext rmContext = prepareRMContext(); boolean isValidConfig = CapacitySchedulerConfigValidator .validateCSConfiguration(oldConfig, newConfig, rmContext); - Assertions.assertTrue(isValidConfig); + assertTrue(isValidConfig); } public static RMContext prepareRMContext() { setupResources(false); - RMContext rmContext = Mockito.mock(RMContext.class); - CapacityScheduler mockCs = Mockito.mock(CapacityScheduler.class); - Mockito.when(rmContext.getScheduler()).thenReturn(mockCs); - LocalConfigurationProvider configProvider = Mockito - .mock(LocalConfigurationProvider.class); - Mockito.when(rmContext.getConfigurationProvider()) + RMContext rmContext = mock(RMContext.class); + CapacityScheduler mockCs = mock(CapacityScheduler.class); + when(rmContext.getScheduler()).thenReturn(mockCs); + LocalConfigurationProvider configProvider = mock(LocalConfigurationProvider.class); + when(rmContext.getConfigurationProvider()) .thenReturn(configProvider); - RMNodeLabelsManager nodeLabelsManager = Mockito - .mock(RMNodeLabelsManager.class); - Mockito.when(rmContext.getNodeLabelManager()).thenReturn(nodeLabelsManager); - LightWeightResource partitionResource = Mockito - .mock(LightWeightResource.class); - Mockito.when(nodeLabelsManager - .getResourceByLabel(Mockito.any(), Mockito.any())) - .thenReturn(partitionResource); - PlacementManager queuePlacementManager = Mockito - .mock(PlacementManager.class); - Mockito.when(rmContext.getQueuePlacementManager()) - .thenReturn(queuePlacementManager); + RMNodeLabelsManager nodeLabelsManager = mock(RMNodeLabelsManager.class); + when(rmContext.getNodeLabelManager()).thenReturn(nodeLabelsManager); + LightWeightResource partitionResource = mock(LightWeightResource.class); + when(nodeLabelsManager + .getResourceByLabel(any(), any())) + .thenReturn(partitionResource); + PlacementManager queuePlacementManager = mock(PlacementManager.class); + when(rmContext.getQueuePlacementManager()) + .thenReturn(queuePlacementManager); return rmContext; }