From ce5ce6d09a47bdf88ebd3d09119f140b2f693183 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sat, 8 Mar 2025 14:54:43 +0800 Subject: [PATCH 1/5] YARN-11262. Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcemanager Part2. --- .../TestAppNameMappingPlacementRule.java | 10 +- .../TestFairQueuePlacementUtils.java | 108 +++--- .../placement/TestPlacementFactory.java | 22 +- .../placement/TestPlacementManager.java | 22 +- .../placement/TestPlacementRuleFS.java | 52 +-- .../TestUserGroupMappingPlacementRule.java | 16 +- .../TestCSMappingPlacementRule.java | 60 +-- .../csmappingrule/TestMappingRule.java | 6 +- .../csmappingrule/TestMappingRuleActions.java | 4 +- .../TestMappingRuleMatchers.java | 60 +-- .../TestMappingRuleValidationContextImpl.java | 4 +- .../csmappingrule/TestVariableContext.java | 64 ++-- .../preprocessor/TestContextProcessor.java | 2 +- .../preprocessor/TestNodeLabelProcessor.java | 2 +- .../preprocessor/TestQueueProcessor.java | 2 +- .../preprocessor/TestTagAddProcessor.java | 2 +- .../recovery/RMStateStoreTestBase.java | 138 +++---- .../TestCheckRemoveZKNodeRMStateStore.java | 40 +- .../recovery/TestFSRMStateStore.java | 41 ++- .../recovery/TestLeveldbRMStateStore.java | 47 ++- .../recovery/TestMemoryRMStateStore.java | 12 +- .../resourcemanager/recovery/TestProtos.java | 8 +- .../recovery/TestRMStateStoreUtils.java | 8 +- .../recovery/TestZKRMStateStore.java | 347 +++++++++--------- .../recovery/TestZKRMStateStorePerf.java | 10 +- ...TestZKRMStateStoreZKClientConnections.java | 28 +- .../reservation/BaseSharingPolicyTest.java | 10 +- .../ReservationSystemTestUtil.java | 16 +- .../TestCapacityOverTimePolicy.java | 2 +- .../TestCapacitySchedulerPlanFollower.java | 26 +- .../TestFairSchedulerPlanFollower.java | 22 +- .../reservation/TestInMemoryPlan.java | 199 +++++----- .../TestInMemoryReservationAllocation.java | 44 +-- .../reservation/TestNoOverCommitPolicy.java | 2 +- ...stPeriodicRLESparseResourceAllocation.java | 70 ++-- .../TestRLESparseResourceAllocation.java | 122 +++--- .../TestReservationInputValidator.java | 226 ++++++------ .../TestReservationSystemUtil.java | 18 +- .../TestSchedulerPlanFollowerBase.java | 42 +-- .../planning/TestAlignedPlanner.java | 180 ++++----- .../planning/TestGreedyReservationAgent.java | 174 ++++----- .../planning/TestReservationAgents.java | 6 +- .../planning/TestSimpleCapacityReplanner.java | 50 +-- .../resource/TestResourceProfiles.java | 48 +-- .../resourcetracker/TestNMExpiry.java | 12 +- .../TestRMNMRPCResponseId.java | 22 +- .../rmapp/TestApplicationLifetimeMonitor.java | 145 ++++---- .../rmapp/TestNodesListManager.java | 46 +-- .../rmapp/TestRMAppTransitions.java | 182 ++++----- .../attempt/TestAMLivelinessMonitor.java | 12 +- .../TestRMAppAttemptImplDiagnostics.java | 12 +- .../attempt/TestRMAppAttemptTransitions.java | 176 +++++---- .../rmcontainer/TestRMContainerImpl.java | 44 ++- 53 files changed, 1553 insertions(+), 1470 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/placement/TestAppNameMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestAppNameMappingPlacementRule.java index 3665dd037ec04..06f493408b7ff 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestAppNameMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestAppNameMappingPlacementRule.java @@ -30,9 +30,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping; import org.apache.hadoop.yarn.util.Records; -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.io.IOException; import java.util.Collections; @@ -55,7 +55,7 @@ public class TestAppNameMappingPlacementRule { private YarnConfiguration conf = new YarnConfiguration(); - @Before + @BeforeEach public void setup() { conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); @@ -108,7 +108,7 @@ private void verifyQueueMapping(QueueMapping queueMapping, asc.setApplicationName(appName); ApplicationPlacementContext ctx = engine.getPlacementForApp(asc, user); - Assert.assertEquals(expectedQueue, + Assertions.assertEquals(expectedQueue, ctx != null ? ctx.getQueue() : inputQueue); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java index 506746add80f3..7ffc4f82f6043 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.placement; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT; import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT_REPLACEMENT; @@ -26,11 +26,11 @@ import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.assureRoot; import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.cleanName; import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.isValidQueueName; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests of the utility methods from {@link FairQueuePlacementUtils}. @@ -50,27 +50,27 @@ public void testCleanName() { final String unTrimmed = " .invalid. "; // not really a valid queue String cleaned = cleanName(clean); - assertEquals("Name was changed and it should not", clean, cleaned); + assertEquals(clean, cleaned, "Name was changed and it should not"); cleaned = cleanName(dotted); - assertFalse("Cleaned name contains dots and it should not", - cleaned.contains(DOT)); + assertFalse( + cleaned.contains(DOT), "Cleaned name contains dots and it should not"); cleaned = cleanName(multiDot); - assertFalse("Cleaned name contains dots and it should not", - cleaned.contains(DOT)); - assertNotEquals("Multi dot failed: wrong replacements found", - cleaned.indexOf(DOT_REPLACEMENT), - cleaned.lastIndexOf(DOT_REPLACEMENT)); + assertFalse( + cleaned.contains(DOT), "Cleaned name contains dots and it should not"); + assertNotEquals( + cleaned.indexOf(DOT_REPLACEMENT) +, cleaned.lastIndexOf(DOT_REPLACEMENT), "Multi dot failed: wrong replacements found"); cleaned = cleanName(seqDot); - assertFalse("Cleaned name contains dots and it should not", - cleaned.contains(DOT)); - assertNotEquals("Sequential dot failed: wrong replacements found", - cleaned.indexOf(DOT_REPLACEMENT), - cleaned.lastIndexOf(DOT_REPLACEMENT)); + assertFalse( + cleaned.contains(DOT), "Cleaned name contains dots and it should not"); + assertNotEquals( + cleaned.indexOf(DOT_REPLACEMENT) +, cleaned.lastIndexOf(DOT_REPLACEMENT), "Sequential dot failed: wrong replacements found"); cleaned = cleanName(unTrimmed); - assertTrue("Trimming start failed: space not removed or dot not replaced", - cleaned.startsWith(DOT_REPLACEMENT)); - assertTrue("Trimming end failed: space not removed or dot not replaced", - cleaned.endsWith(DOT_REPLACEMENT)); + assertTrue( + cleaned.startsWith(DOT_REPLACEMENT), "Trimming start failed: space not removed or dot not replaced"); + assertTrue( + cleaned.endsWith(DOT_REPLACEMENT), "Trimming end failed: space not removed or dot not replaced"); } @Test @@ -82,21 +82,21 @@ public void testAssureRoot() { final String alreadyRoot = "root.base"; String rooted = assureRoot(queueName); - assertTrue("Queue should have root prefix (base)", - rooted.startsWith(ROOT_QUEUE + DOT)); + assertTrue( + rooted.startsWith(ROOT_QUEUE + DOT), "Queue should have root prefix (base)"); rooted = assureRoot(rootOnly); - assertEquals("'root' queue should not have root prefix (root)", - rootOnly, rooted); + assertEquals( + rootOnly, rooted, "'root' queue should not have root prefix (root)"); rooted = assureRoot(rootNoDot); - assertTrue("Queue should have root prefix (rootbase)", - rooted.startsWith(ROOT_QUEUE + DOT)); - assertEquals("'root' queue base was replaced and not prefixed", 5, - rooted.lastIndexOf(ROOT_QUEUE)); + assertTrue( + rooted.startsWith(ROOT_QUEUE + DOT), "Queue should have root prefix (rootbase)"); + assertEquals(5 +, rooted.lastIndexOf(ROOT_QUEUE), "'root' queue base was replaced and not prefixed"); rooted = assureRoot(alreadyRoot); - assertEquals("Root prefixed queue changed and it should not (root.base)", - rooted, alreadyRoot); - assertNull("Null queue did not return null queue", - assureRoot(null)); + assertEquals( + rooted, alreadyRoot, "Root prefixed queue changed and it should not (root.base)"); + assertNull( + assureRoot(null), "Null queue did not return null queue"); assertEquals("Empty queue did not return empty name", "", assureRoot("")); } @@ -113,25 +113,25 @@ public void testIsValidQueueName() { final String endSpace = "invalid "; final String unicodeSpace = "\u00A0invalid"; - assertFalse("'null' queue was not marked as invalid", - isValidQueueName(null)); - assertTrue("empty queue was not tagged valid", isValidQueueName("")); - assertTrue("Simple queue name was not tagged valid (valid)", - isValidQueueName(valid)); - assertTrue("Root only queue was not tagged valid (root)", - isValidQueueName(rootOnly)); - assertTrue("Root prefixed queue was not tagged valid (root.valid)", - isValidQueueName(validRooted)); - assertFalse("Queue starting with dot was not tagged invalid (.invalid)", - isValidQueueName(startDot)); - assertFalse("Queue ending with dot was not tagged invalid (invalid.)", - isValidQueueName(endDot)); - assertFalse("Queue starting with space was not tagged invalid ( invalid)", - isValidQueueName(startSpace)); - assertFalse("Queue ending with space was not tagged invalid (invalid )", - isValidQueueName(endSpace)); + assertFalse( + isValidQueueName(null), "'null' queue was not marked as invalid"); + assertTrue(isValidQueueName(""), "empty queue was not tagged valid"); + assertTrue( + isValidQueueName(valid), "Simple queue name was not tagged valid (valid)"); + assertTrue( + isValidQueueName(rootOnly), "Root only queue was not tagged valid (root)"); + assertTrue( + isValidQueueName(validRooted), "Root prefixed queue was not tagged valid (root.valid)"); + assertFalse( + isValidQueueName(startDot), "Queue starting with dot was not tagged invalid (.invalid)"); + assertFalse( + isValidQueueName(endDot), "Queue ending with dot was not tagged invalid (invalid.)"); + assertFalse( + isValidQueueName(startSpace), "Queue starting with space was not tagged invalid ( invalid)"); + assertFalse( + isValidQueueName(endSpace), "Queue ending with space was not tagged invalid (invalid )"); // just one for sanity check extensive tests are in the scheduler utils - assertFalse("Queue with unicode space was not tagged as invalid (unicode)", - isValidQueueName(unicodeSpace)); + assertFalse( + isValidQueueName(unicodeSpace), "Queue with unicode space was not tagged as invalid (unicode)"); } } \ 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/placement/TestPlacementFactory.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementFactory.java index f4d1733008924..ba6cf5e89b0d8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementFactory.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementFactory.java @@ -18,11 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.placement; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * Test for the {@link PlacementFactory}. @@ -34,10 +32,12 @@ public class TestPlacementFactory { * * @throws ClassNotFoundException */ - @Test(expected = ClassNotFoundException.class) + @Test public void testGetNonExistRuleText() throws ClassNotFoundException { - final String nonExist = "my.placement.Rule"; - PlacementFactory.getPlacementRule(nonExist, null); + assertThrows(ClassNotFoundException.class, ()->{ + final String nonExist = "my.placement.Rule"; + PlacementFactory.getPlacementRule(nonExist, null); + }); } /** @@ -53,8 +53,8 @@ public void testGetExistRuleText() { } catch (ClassNotFoundException cnfe) { fail("Class should have been found"); } - assertNotNull("Rule object is null", rule); - assertEquals("Names not equal", rule.getName(), exists); + assertNotNull(rule, "Rule object is null"); + assertEquals(rule.getName(), exists, "Names not equal"); } /** @@ -65,11 +65,11 @@ public void testGetExistRuleText() { public void testGetRuleClass() { PlacementRule rule = PlacementFactory.getPlacementRule( DefaultPlacementRule.class, null); - assertNotNull("Rule object is null", rule); + assertNotNull(rule, "Rule object is null"); // Should take anything as the second object: ignores unknown types in the // default implementation. rule = PlacementFactory.getPlacementRule( DefaultPlacementRule.class, ""); - assertNotNull("Rule object is null", rule); + assertNotNull(rule, "Rule object is 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/placement/TestPlacementManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementManager.java index e27c4ec532171..ca4d96e647855 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementManager.java @@ -28,10 +28,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; import org.apache.hadoop.yarn.util.Records; -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.util.ArrayList; import java.util.List; @@ -56,7 +56,7 @@ private String getQueueMapping(String parentQueue, String leafQueue) { return parentQueue + DOT + leafQueue; } - @Before + @BeforeEach public void setup() { conf = new CapacitySchedulerConfiguration(); setupQueueConfiguration(conf); @@ -96,8 +96,8 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception { asc.setQueue(YarnConfiguration.DEFAULT_QUEUE_NAME); asc.setApplicationName(APP_NAME); - Assert.assertNull("Placement should be null", - pm.placeApplication(asc, USER2)); + Assertions.assertNull( + pm.placeApplication(asc, USER2), "Placement should be null"); QueueMapping queueMappingEntity = QueueMapping.QueueMappingBuilder.create() .type(MappingType.APPLICATION) .source(APP_NAME) @@ -112,7 +112,7 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception { queuePlacementRules.add(anRule); pm.updateRules(queuePlacementRules); ApplicationPlacementContext pc = pm.placeApplication(asc, USER2); - Assert.assertNotNull(pc); + Assertions.assertNotNull(pc); } @Test @@ -135,13 +135,13 @@ public void testPlacementRuleUpdationOrder() throws Exception { // As we are setting placement rule, It shouldn't update default // placement rule ie user-group. Number of placement rules should be 1. - Assert.assertEquals(1, pm.getPlacementRules().size()); + Assertions.assertEquals(1, pm.getPlacementRules().size()); // Verifying if placement rule set is same as the one we configured - Assert.assertEquals(ugRule.getName(), + Assertions.assertEquals(ugRule.getName(), pm.getPlacementRules().get(0).getName()); } - @After + @AfterEach public void tearDown() { if (null != mockRM) { 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/placement/TestPlacementRuleFS.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java index 1c7e5fa513175..f7c543d4882b9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java @@ -23,9 +23,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.QueueManager; -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.w3c.dom.Document; import org.w3c.dom.Element; @@ -37,10 +37,10 @@ import java.util.List; import static org.apache.hadoop.yarn.server.resourcemanager.placement.PlacementFactory.getPlacementRule; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -75,7 +75,7 @@ public class TestPlacementRuleFS { private QueueManager queueManager; - @Before + @BeforeEach public void initTest() { scheduler = mock(FairScheduler.class); // needed for all rules that rely on group info @@ -85,7 +85,7 @@ public void initTest() { when(scheduler.getQueueManager()).thenReturn(queueManager); } - @After + @AfterEach public void cleanTest() { queueManager = null; scheduler = null; @@ -126,26 +126,26 @@ public void testRuleInitOnly() { private void ruleCreateNoConfig(Class ruleClass) { PlacementRule rule = getPlacementRule(ruleClass, null); String name = ruleClass.getName(); - assertNotNull("Rule object should not be null for " + name, rule); + assertNotNull(rule, "Rule object should not be null for " + name); } private void ruleCreateWrongObject( Class ruleClass) { PlacementRule rule = getPlacementRule(ruleClass, "a string object"); String name = ruleClass.getName(); - assertNotNull("Rule object should not be null for " + name, rule); + assertNotNull(rule, "Rule object should not be null for " + name); } private void ruleCreateBoolean(Class ruleClass) { PlacementRule rule = getPlacementRule(ruleClass, true); String name = ruleClass.getName(); - assertNotNull("Rule object should not be null for " + name, rule); - assertTrue("Create flag was not set to true on " + name, - getCreateFlag(rule)); + assertNotNull(rule, "Rule object should not be null for " + name); + assertTrue( + getCreateFlag(rule), "Create flag was not set to true on " + name); rule = getPlacementRule(ruleClass, false); - assertNotNull("Rule object should not be null for " + name, rule); - assertFalse("Create flag was not set to false on " + name, - getCreateFlag(rule)); + assertNotNull(rule, "Rule object should not be null for " + name); + assertFalse( + getCreateFlag(rule), "Create flag was not set to false on " + name); } private void ruleCreateElement(Class ruleClass) { @@ -153,21 +153,21 @@ private void ruleCreateElement(Class ruleClass) { Element conf = createConf(str); PlacementRule rule = getPlacementRule(ruleClass, conf); String name = ruleClass.getName(); - assertNotNull("Rule object should not be null for " + name, rule); - assertTrue("Create flag was not set to true on " + name, - getCreateFlag(rule)); + assertNotNull(rule, "Rule object should not be null for " + name); + assertTrue( + getCreateFlag(rule), "Create flag was not set to true on " + name); str = ""; conf = createConf(str); rule = getPlacementRule(ruleClass, conf); - assertNotNull("Rule object should not be null for " + name, rule); - assertFalse("Create flag was not set to false on " + name, - getCreateFlag(rule)); + assertNotNull(rule, "Rule object should not be null for " + name); + assertFalse( + getCreateFlag(rule), "Create flag was not set to false on " + name); } private void ruleInit(Class ruleClass) { PlacementRule rule = getPlacementRule(ruleClass, null); String name = ruleClass.getName(); - assertNotNull("Rule object should not be null for " + name, rule); + assertNotNull(rule, "Rule object should not be null for " + name); try { rule.initialize(scheduler); } catch (IOException ioe) { @@ -183,8 +183,8 @@ private void ruleInit(Class ruleClass) { } catch (IOException ioe) { exceptionThrown = true; } - assertTrue("Initialize with parent rule should have thrown exception " + - name, exceptionThrown); + assertTrue(exceptionThrown, "Initialize with parent rule should have thrown exception " + + name); } private Element createConf(String str) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestUserGroupMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestUserGroupMappingPlacementRule.java index 84a3e6c34aa3c..8a1747a3296d7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestUserGroupMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestUserGroupMappingPlacementRule.java @@ -42,14 +42,14 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.PrimaryGroupMapping; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping; import org.apache.hadoop.yarn.util.Records; -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 TestUserGroupMappingPlacementRule { private final YarnConfiguration conf = new YarnConfiguration(); - @Before + @BeforeEach public void setup() { conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING, SimpleGroupsMapping.class, GroupMappingServiceProvider.class); @@ -94,11 +94,11 @@ private void verifyQueueMapping(QueueMappingTestData queueMappingTestData) ApplicationSubmissionContext.class); asc.setQueue(inputQueue); ApplicationPlacementContext ctx = engine.getPlacementForApp(asc, inputUser); - Assert.assertEquals("Queue", expectedQueue, - ctx != null ? ctx.getQueue() : inputQueue); + Assertions.assertEquals(expectedQueue +, ctx != null ? ctx.getQueue() : inputQueue, "Queue"); if (ctx != null && expectedParentQueue != null) { - Assert.assertEquals("Parent Queue", expectedParentQueue, - ctx.getParentQueue()); + Assertions.assertEquals(expectedParentQueue +, ctx.getParentQueue(), "Parent 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/placement/csmappingrule/TestCSMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java index 41ce2b56eab20..80c03b6b739af 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java @@ -34,7 +34,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; import org.apache.hadoop.yarn.util.Records; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,12 +48,8 @@ import java.util.Map; import java.util.Set; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertNull; -import static junit.framework.TestCase.assertTrue; -import static junit.framework.TestCase.fail; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_GROUP_MAPPING; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -185,7 +181,7 @@ private void assertPlace(String message, CSMappingPlacementRule engine, ApplicationSubmissionContext asc, String user, String expectedQueue) { try { ApplicationPlacementContext apc = engine.getPlacementForApp(asc, user); - assertNotNull(message, apc); + assertNotNull(apc, message); String queue = apc.getParentQueue() == null ? "" : (apc.getParentQueue() + DOT); queue += apc.getQueue(); @@ -199,7 +195,7 @@ private void assertPlace(String message, CSMappingPlacementRule engine, private void assertNullResult(String message, CSMappingPlacementRule engine, ApplicationSubmissionContext asc, String user) { try { - assertNull(message, engine.getPlacementForApp(asc, user)); + assertNull(engine.getPlacementForApp(asc, user), message); } catch (YarnException e) { LOG.error(message, e); fail(message); @@ -628,15 +624,15 @@ public void testSecondaryGroupWithParent() throws IOException { void assertConfigTestResult(List rules) { - assertEquals("We only specified one rule", 1, rules.size()); + assertEquals(1, rules.size(), "We only specified one rule"); MappingRule rule = rules.get(0); String ruleStr = rule.toString(); - assertTrue("Rule's matcher variable should be %user", - ruleStr.contains("variable='%user'")); - assertTrue("Rule's match value should be bob", - ruleStr.contains("value='bob'")); - assertTrue("Rule's action should be place to queue", ruleStr.contains( - "action=PlaceToQueueAction{queueName='%primary_group'")); + assertTrue( + ruleStr.contains("variable='%user'"), "Rule's matcher variable should be %user"); + assertTrue( + ruleStr.contains("value='bob'"), "Rule's match value should be bob"); + assertTrue(ruleStr.contains( + "action=PlaceToQueueAction{queueName='%primary_group'"), "Rule's action should be place to queue"); } @Test @@ -677,27 +673,31 @@ public void testEmptyJSONConfiguration() throws IOException { conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_JSON, ""); List rules = conf.getMappingRules(); - assertEquals("We expect no rules", 0, rules.size()); + assertEquals(0, rules.size(), "We expect no rules"); } - @Test(expected = IOException.class) + @Test public void testInvalidJSONConfiguration() throws IOException { - CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration(); - conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT, - CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT_JSON); - conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_JSON, - "I'm a bad JSON, since I'm not a JSON."); - List rules = conf.getMappingRules(); + assertThrows(IOException.class, ()->{ + CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration(); + conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT, + CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT_JSON); + conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_JSON, + "I'm a bad JSON, since I'm not a JSON."); + List rules = conf.getMappingRules(); + }); } - @Test(expected = IOException.class) + @Test public void testMissingJSONFileConfiguration() throws IOException { - CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration(); - conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT, - CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT_JSON); - conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_JSON_FILE, - "/dev/null/nofile"); - List rules = conf.getMappingRules(); + assertThrows(IOException.class, ()->{ + CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration(); + conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT, + CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT_JSON); + conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_JSON_FILE, + "/dev/null/nofile"); + List rules = conf.getMappingRules(); + }); } @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/placement/csmappingrule/TestMappingRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRule.java index 5421f47641962..29966fdb7ec4a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRule.java @@ -18,13 +18,13 @@ package org.apache.hadoop.yarn.server.resourcemanager.placement.csmappingrule; -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 org.apache.hadoop.util.Sets; import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.yarn.server.resourcemanager.placement.VariableContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestMappingRule { VariableContext setupVariables( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleActions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleActions.java index 9224e673325dc..909e46b0cb6b9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleActions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleActions.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.placement.csmappingrule; import org.apache.hadoop.yarn.server.resourcemanager.placement.VariableContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class TestMappingRuleActions { void assertRejectResult(MappingRuleResult 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/placement/csmappingrule/TestMappingRuleMatchers.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java index d245051600b22..3e9e69e44acc0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java @@ -18,15 +18,17 @@ package org.apache.hadoop.yarn.server.resourcemanager.placement.csmappingrule; -import junit.framework.TestCase; +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 org.apache.hadoop.util.Sets; import org.apache.hadoop.yarn.server.resourcemanager.placement.VariableContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -public class TestMappingRuleMatchers extends TestCase { +public class TestMappingRuleMatchers { @Test public void testCatchAll() { @@ -64,12 +66,12 @@ public void testVariableMatcher() { new MappingRuleMatchers.VariableMatcher("%custom", "Matching string")); matchers.forEach((matcherName, matcher) -> { - assertTrue(matcherName + " with matchingContext should match", - matcher.match(matchingContext)); - assertFalse(matcherName + " with mismatchingContext shouldn't match", - matcher.match(mismatchingContext)); - assertFalse(matcherName + " with emptyContext shouldn't match", - matcher.match(emptyContext)); + assertTrue( + matcher.match(matchingContext), matcherName + " with matchingContext should match"); + assertFalse( + matcher.match(mismatchingContext), matcherName + " with mismatchingContext shouldn't match"); + assertFalse( + matcher.match(emptyContext), matcherName + " with emptyContext shouldn't match"); }); } @@ -106,31 +108,31 @@ public void testVariableMatcherSubstitutions() { MappingRuleMatcher userStatic = new MappingRuleMatchers.VariableMatcher("%user", "bob"); - assertTrue("%custom should match %user in matching context", - customUser.match(matchingContext)); - assertTrue("%user should match %custom in matching context", - userCustom.match(matchingContext)); - assertTrue("%user (bob) should match %cus%tom (b + ob) in matching context", - userCusTom.match(matchingContext)); - assertTrue("%user should match %user in any context", - userUser.match(matchingContext)); - assertTrue("%user (bob) should match bob in in matching context", - userStatic.match(matchingContext)); + assertTrue( + customUser.match(matchingContext), "%custom should match %user in matching context"); + assertTrue( + userCustom.match(matchingContext), "%user should match %custom in matching context"); + assertTrue( + userCusTom.match(matchingContext), "%user (bob) should match %cus%tom (b + ob) in matching context"); + assertTrue( + userUser.match(matchingContext), "%user should match %user in any context"); + assertTrue( + userStatic.match(matchingContext), "%user (bob) should match bob in in matching context"); assertFalse( - "%custom (bob) should NOT match %user (dave) in mismatching context", - customUser.match(mismatchingContext)); + + customUser.match(mismatchingContext), "%custom (bob) should NOT match %user (dave) in mismatching context"); assertFalse( - "%user (dave) should NOT match %custom (bob) in mismatching context", - userCustom.match(mismatchingContext)); + + userCustom.match(mismatchingContext), "%user (dave) should NOT match %custom (bob) in mismatching context"); assertFalse( - "%user (dave) should NOT match %cus%tom (b+ob) in mismatching context", - userCusTom.match(mismatchingContext)); - assertTrue("%user should match %user in any context", - userUser.match(mismatchingContext)); + + userCusTom.match(mismatchingContext), "%user (dave) should NOT match %cus%tom (b+ob) in mismatching context"); + assertTrue( + userUser.match(mismatchingContext), "%user should match %user in any context"); assertFalse( - "%user (dave) should NOT match match bob in in matching context", - userStatic.match(mismatchingContext)); + + userStatic.match(mismatchingContext), "%user (dave) should NOT match match bob in in matching context"); } @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/placement/csmappingrule/TestMappingRuleValidationContextImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleValidationContextImpl.java index a015e315c35a9..d6a59ac7615f1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleValidationContextImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleValidationContextImpl.java @@ -21,9 +21,9 @@ import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.server.resourcemanager.placement.MockQueueHierarchyBuilder; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; -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.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestVariableContext.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestVariableContext.java index 30d265b9e8c85..6f7b5aa7e1d81 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestVariableContext.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestVariableContext.java @@ -20,13 +20,13 @@ import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; import org.apache.hadoop.yarn.server.resourcemanager.placement.VariableContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class TestVariableContext { @@ -49,32 +49,38 @@ public void testAddAndGet() { assertEquals("", variables.get("%empty")); } - @Test(expected = IllegalStateException.class) + @Test public void testImmutablesCanOnlySetOnceFromSet() { - VariableContext variables = new VariableContext(); - ImmutableSet immutables = - ImmutableSet.of("%user", "%primary_group", "%secondary_group"); - - variables.setImmutables(immutables); - variables.setImmutables(immutables); + assertThrows(IllegalStateException.class, ()->{ + VariableContext variables = new VariableContext(); + ImmutableSet immutables = + ImmutableSet.of("%user", "%primary_group", "%secondary_group"); + + variables.setImmutables(immutables); + variables.setImmutables(immutables); + }); } - @Test(expected = IllegalStateException.class) + @Test public void testImmutablesCanOnlySetOnceFromArray() { - VariableContext variables = new VariableContext(); + assertThrows(IllegalStateException.class, ()->{ + VariableContext variables = new VariableContext(); - variables.setImmutables("%user", "%primary_group", "%secondary_group"); - variables.setImmutables("%user", "%primary_group", "%secondary_group"); + variables.setImmutables("%user", "%primary_group", "%secondary_group"); + variables.setImmutables("%user", "%primary_group", "%secondary_group"); + }); } - @Test(expected = IllegalStateException.class) + @Test public void testImmutablesCanOnlySetOnceFromSetAndArray() { - VariableContext variables = new VariableContext(); - ImmutableSet immutables = - ImmutableSet.of("%user", "%primary_group", "%secondary_group"); - - variables.setImmutables(immutables); - variables.setImmutables("%user", "%primary_group", "%secondary_group"); + assertThrows(IllegalStateException.class, ()->{ + VariableContext variables = new VariableContext(); + ImmutableSet immutables = + ImmutableSet.of("%user", "%primary_group", "%secondary_group"); + + variables.setImmutables(immutables); + variables.setImmutables("%user", "%primary_group", "%secondary_group"); + }); } @Test @@ -87,15 +93,17 @@ public void testImmutableVariableCanBeSetOnce() { variables.put("%user", "bob"); } - @Test(expected = IllegalStateException.class) + @Test public void testImmutableVariableProtection() { - VariableContext variables = new VariableContext(); - ImmutableSet immutables = - ImmutableSet.of("%user", "%primary_group", "%secondary_group"); - - variables.setImmutables(immutables); - variables.put("%user", "bob"); - variables.put("%user", "bob"); + assertThrows(IllegalStateException.class, ()->{ + VariableContext variables = new VariableContext(); + ImmutableSet immutables = + ImmutableSet.of("%user", "%primary_group", "%secondary_group"); + + variables.setImmutables(immutables); + variables.put("%user", "bob"); + variables.put("%user", "bob"); + }); } @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/preprocessor/TestContextProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestContextProcessor.java index 039e794eddb47..d4b75e6f57cd1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestContextProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestContextProcessor.java @@ -24,7 +24,7 @@ import java.util.Set; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.*; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestNodeLabelProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestNodeLabelProcessor.java index bb55b72ce5b47..3c466bb2b294a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestNodeLabelProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestNodeLabelProcessor.java @@ -21,7 +21,7 @@ import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.*; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestQueueProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestQueueProcessor.java index fc032bb1497b2..4330eaa75a65f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestQueueProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestQueueProcessor.java @@ -20,7 +20,7 @@ import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.*; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestTagAddProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestTagAddProcessor.java index abe0674045026..b39dff88e6e55 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestTagAddProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestTagAddProcessor.java @@ -22,7 +22,7 @@ import java.util.Set; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.*; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java index 1773c7aaa88e7..40720f3cc7c54 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java @@ -18,12 +18,12 @@ package org.apache.hadoop.yarn.server.resourcemanager.recovery; -import static org.junit.Assert.assertArrayEquals; -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.assertArrayEquals; +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.spy; import static org.mockito.Mockito.when; @@ -86,7 +86,7 @@ import org.apache.hadoop.yarn.server.webproxy.ProxyCA; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; public class RMStateStoreTestBase { @@ -484,13 +484,13 @@ public void testRMDTSecretManagerStateStore( RMDTSecretManagerState secretManagerState = store.loadState().getRMDTSecretManagerState(); - Assert.assertEquals(token1, secretManagerState.getTokenState()); - Assert.assertEquals(keySet, secretManagerState.getMasterKeyState()); - Assert.assertEquals(sequenceNumber, + Assertions.assertEquals(token1, secretManagerState.getTokenState()); + Assertions.assertEquals(keySet, secretManagerState.getMasterKeyState()); + Assertions.assertEquals(sequenceNumber, secretManagerState.getDTSequenceNumber()); RMDelegationTokenIdentifier tokenAfterStore = secretManagerState.getTokenState().keySet().iterator().next(); - Assert.assertTrue(Arrays.equals(tokenBeforeStore, + Assertions.assertTrue(Arrays.equals(tokenBeforeStore, tokenAfterStore.getBytes())); // update RM delegation token; @@ -500,9 +500,9 @@ public void testRMDTSecretManagerStateStore( RMDTSecretManagerState updateSecretManagerState = store.loadState().getRMDTSecretManagerState(); - Assert.assertEquals(token1, updateSecretManagerState.getTokenState()); - Assert.assertEquals(keySet, updateSecretManagerState.getMasterKeyState()); - Assert.assertEquals(sequenceNumber, + Assertions.assertEquals(token1, updateSecretManagerState.getTokenState()); + Assertions.assertEquals(keySet, updateSecretManagerState.getMasterKeyState()); + Assertions.assertEquals(sequenceNumber, updateSecretManagerState.getDTSequenceNumber()); // check to delete delegationKey @@ -510,9 +510,9 @@ public void testRMDTSecretManagerStateStore( keySet.clear(); RMDTSecretManagerState noKeySecretManagerState = store.loadState().getRMDTSecretManagerState(); - Assert.assertEquals(token1, noKeySecretManagerState.getTokenState()); - Assert.assertEquals(keySet, noKeySecretManagerState.getMasterKeyState()); - Assert.assertEquals(sequenceNumber, + Assertions.assertEquals(token1, noKeySecretManagerState.getTokenState()); + Assertions.assertEquals(keySet, noKeySecretManagerState.getMasterKeyState()); + Assertions.assertEquals(sequenceNumber, noKeySecretManagerState.getDTSequenceNumber()); // check to delete delegationToken @@ -520,11 +520,11 @@ public void testRMDTSecretManagerStateStore( RMDTSecretManagerState noKeyAndTokenSecretManagerState = store.loadState().getRMDTSecretManagerState(); token1.clear(); - Assert.assertEquals(token1, + Assertions.assertEquals(token1, noKeyAndTokenSecretManagerState.getTokenState()); - Assert.assertEquals(keySet, + Assertions.assertEquals(keySet, noKeyAndTokenSecretManagerState.getMasterKeyState()); - Assert.assertEquals(sequenceNumber, + Assertions.assertEquals(sequenceNumber, noKeySecretManagerState.getDTSequenceNumber()); store.close(); @@ -547,17 +547,17 @@ public void testCheckVersion(RMStateStoreHelper stateStoreHelper) // default version Version defaultVersion = stateStoreHelper.getCurrentVersion(); store.checkVersion(); - Assert.assertEquals(defaultVersion, store.loadVersion()); + Assertions.assertEquals(defaultVersion, store.loadVersion()); // compatible version Version compatibleVersion = Version.newInstance(defaultVersion.getMajorVersion(), defaultVersion.getMinorVersion() + 2); stateStoreHelper.writeVersion(compatibleVersion); - Assert.assertEquals(compatibleVersion, store.loadVersion()); + Assertions.assertEquals(compatibleVersion, store.loadVersion()); store.checkVersion(); // overwrite the compatible version - Assert.assertEquals(defaultVersion, store.loadVersion()); + Assertions.assertEquals(defaultVersion, store.loadVersion()); // incompatible version Version incompatibleVersion = @@ -566,9 +566,9 @@ public void testCheckVersion(RMStateStoreHelper stateStoreHelper) stateStoreHelper.writeVersion(incompatibleVersion); try { store.checkVersion(); - Assert.fail("Invalid version, should fail."); + Assertions.fail("Invalid version, should fail."); } catch (Throwable t) { - Assert.assertTrue(t instanceof RMStateVersionIncompatibleException); + Assertions.assertTrue(t instanceof RMStateVersionIncompatibleException); } } @@ -578,13 +578,13 @@ public void testEpoch(RMStateStoreHelper stateStoreHelper) store.setRMDispatcher(new TestDispatcher()); long firstTimeEpoch = store.getAndIncrementEpoch(); - Assert.assertEquals(epoch, firstTimeEpoch); + Assertions.assertEquals(epoch, firstTimeEpoch); long secondTimeEpoch = store.getAndIncrementEpoch(); - Assert.assertEquals(epoch + 1, secondTimeEpoch); + Assertions.assertEquals(epoch + 1, secondTimeEpoch); long thirdTimeEpoch = store.getAndIncrementEpoch(); - Assert.assertEquals(epoch + 2, thirdTimeEpoch); + Assertions.assertEquals(epoch + 2, thirdTimeEpoch); for (int i = 0; i < epochRange; ++i) { store.getAndIncrementEpoch(); @@ -592,7 +592,7 @@ public void testEpoch(RMStateStoreHelper stateStoreHelper) long wrappedEpoch = store.getAndIncrementEpoch(); // Epoch should have wrapped around and then incremented once for a total // of + 3 - Assert.assertEquals(epoch + 3, wrappedEpoch); + Assertions.assertEquals(epoch + 3, wrappedEpoch); } public void testAppDeletion(RMStateStoreHelper stateStoreHelper) @@ -625,7 +625,7 @@ private ArrayList createAndStoreApps( appList.add(app); } - Assert.assertEquals(numApps, appList.size()); + Assertions.assertEquals(numApps, appList.size()); for (RMApp app : appList) { // wait for app to be stored. while (true) { @@ -646,7 +646,7 @@ public void testDeleteStore(RMStateStoreHelper stateStoreHelper) store.deleteStore(); // verify apps deleted for (RMApp app : appList) { - Assert.assertFalse(stateStoreHelper.appExists(app)); + Assertions.assertFalse(stateStoreHelper.appExists(app)); } } @@ -659,10 +659,10 @@ public void testRemoveApplication(RMStateStoreHelper stateStoreHelper) RMApp rmApp1 = appList.get(0); store.removeApplication(rmApp1.getApplicationId()); - Assert.assertFalse(stateStoreHelper.appExists(rmApp1)); + Assertions.assertFalse(stateStoreHelper.appExists(rmApp1)); RMApp rmApp2 = appList.get(1); - Assert.assertTrue(stateStoreHelper.appExists(rmApp2)); + Assertions.assertTrue(stateStoreHelper.appExists(rmApp2)); } public void testRemoveAttempt(RMStateStoreHelper stateStoreHelper) @@ -685,8 +685,8 @@ public void testRemoveAttempt(RMStateStoreHelper stateStoreHelper) ContainerId.newContainerId(attemptId2, 1).toString(), null, null, dispatcher); store.removeApplicationAttemptInternal(attemptId1); - Assert.assertFalse(stateStoreHelper.attemptExists(attempt1)); - Assert.assertTrue(stateStoreHelper.attemptExists(attempt2)); + Assertions.assertFalse(stateStoreHelper.attemptExists(attempt1)); + Assertions.assertTrue(stateStoreHelper.attemptExists(attempt2)); // let things settle down Thread.sleep(1000); @@ -742,10 +742,10 @@ public void testAMRMTokenSecretManagerStateStore( when(rmContext.getStateStore()).thenReturn(store); store.setRMDispatcher(dispatcher); RMState state = store.loadState(); - Assert.assertNotNull(state.getAMRMTokenSecretManagerState()); - Assert.assertEquals(firstMasterKeyData.getMasterKey(), state + Assertions.assertNotNull(state.getAMRMTokenSecretManagerState()); + Assertions.assertEquals(firstMasterKeyData.getMasterKey(), state .getAMRMTokenSecretManagerState().getCurrentMasterKey()); - Assert.assertNull(state + Assertions.assertNull(state .getAMRMTokenSecretManagerState().getNextMasterKey()); //create and save the second masterkey @@ -762,18 +762,18 @@ public void testAMRMTokenSecretManagerStateStore( when(rmContext.getStateStore()).thenReturn(store); store.setRMDispatcher(dispatcher); RMState state_2 = store.loadState(); - Assert.assertNotNull(state_2.getAMRMTokenSecretManagerState()); - Assert.assertEquals(firstMasterKeyData.getMasterKey(), state_2 + Assertions.assertNotNull(state_2.getAMRMTokenSecretManagerState()); + Assertions.assertEquals(firstMasterKeyData.getMasterKey(), state_2 .getAMRMTokenSecretManagerState().getCurrentMasterKey()); - Assert.assertEquals(secondMasterKeyData.getMasterKey(), state_2 + Assertions.assertEquals(secondMasterKeyData.getMasterKey(), state_2 .getAMRMTokenSecretManagerState().getNextMasterKey()); // re-create the masterKeyData based on the recovered masterkey // should have the same secretKey appTokenMgr.recover(state_2); - Assert.assertEquals(appTokenMgr.getCurrnetMasterKeyData().getSecretKey(), + Assertions.assertEquals(appTokenMgr.getCurrnetMasterKeyData().getSecretKey(), firstMasterKeyData.getSecretKey()); - Assert.assertEquals(appTokenMgr.getNextMasterKeyData().getSecretKey(), + Assertions.assertEquals(appTokenMgr.getNextMasterKeyData().getSecretKey(), secondMasterKeyData.getSecretKey()); store.close(); @@ -814,7 +814,7 @@ public void testReservationStateStore( RMState state = store.loadState(); Map> reservationState = state.getReservationState(); - Assert.assertNotNull(reservationState); + Assertions.assertNotNull(reservationState); // 2. Store single reservation and verify String reservationIdName = r1.toString(); @@ -868,13 +868,13 @@ public void testReservationStateStore( store.setRMDispatcher(dispatcher); state = store.loadState(); reservationState = state.getReservationState(); - Assert.assertNotNull(reservationState); + Assertions.assertNotNull(reservationState); reservations = reservationState.get(planName); - Assert.assertNotNull(reservations); + Assertions.assertNotNull(reservations); ReservationAllocationStateProto storedReservationAllocation = reservations.get(r1); - Assert.assertNull("Removed reservation should not be available in store", - storedReservationAllocation); + Assertions.assertNull( + storedReservationAllocation, "Removed reservation should not be available in store"); storedReservationAllocation = reservations.get(r2); assertAllocationStateEqual( @@ -890,9 +890,9 @@ public void testReservationStateStore( store.setRMDispatcher(dispatcher); state = store.loadState(); reservationState = state.getReservationState(); - Assert.assertNotNull(reservationState); + Assertions.assertNotNull(reservationState); reservations = reservationState.get(planName); - Assert.assertNull(reservations); + Assertions.assertNull(reservations); } public void testProxyCA( @@ -908,22 +908,22 @@ public void testProxyCA( RMStateStore.ProxyCAState proxyCAState = store.loadState().getProxyCAState(); - Assert.assertEquals(originalProxyCA.getCaCert(), proxyCAState.getCaCert()); - Assert.assertEquals(originalProxyCA.getCaKeyPair().getPrivate(), + Assertions.assertEquals(originalProxyCA.getCaCert(), proxyCAState.getCaCert()); + Assertions.assertEquals(originalProxyCA.getCaKeyPair().getPrivate(), proxyCAState.getCaPrivateKey()); // Try replacing with a different ProxyCA ProxyCA newProxyCA = new ProxyCA(); newProxyCA.init(); - Assert.assertNotEquals(originalProxyCA.getCaCert(), newProxyCA.getCaCert()); - Assert.assertNotEquals(originalProxyCA.getCaKeyPair().getPrivate(), + Assertions.assertNotEquals(originalProxyCA.getCaCert(), newProxyCA.getCaCert()); + Assertions.assertNotEquals(originalProxyCA.getCaKeyPair().getPrivate(), newProxyCA.getCaKeyPair().getPrivate()); store.storeProxyCACert(newProxyCA.getCaCert(), newProxyCA.getCaKeyPair().getPrivate()); proxyCAState = store.loadState().getProxyCAState(); - Assert.assertEquals(newProxyCA.getCaCert(), proxyCAState.getCaCert()); - Assert.assertEquals(newProxyCA.getCaKeyPair().getPrivate(), + Assertions.assertEquals(newProxyCA.getCaCert(), proxyCAState.getCaCert()); + Assertions.assertEquals(newProxyCA.getCaKeyPair().getPrivate(), proxyCAState.getCaPrivateKey()); } @@ -938,13 +938,13 @@ private void validateStoredReservation( RMState state = store.loadState(); Map> reservationState = state.getReservationState(); - Assert.assertNotNull(reservationState); + Assertions.assertNotNull(reservationState); Map reservations = reservationState.get(planName); - Assert.assertNotNull(reservations); + Assertions.assertNotNull(reservations); ReservationAllocationStateProto storedReservationAllocation = reservations.get(r1); - Assert.assertNotNull(storedReservationAllocation); + Assertions.assertNotNull(storedReservationAllocation); assertAllocationStateEqual( allocationStateProto, storedReservationAllocation); @@ -955,12 +955,12 @@ void assertAllocationStateEqual( ReservationAllocationStateProto expected, ReservationAllocationStateProto actual) { - Assert.assertEquals( + Assertions.assertEquals( expected.getAcceptanceTime(), actual.getAcceptanceTime()); - Assert.assertEquals(expected.getStartTime(), actual.getStartTime()); - Assert.assertEquals(expected.getEndTime(), actual.getEndTime()); - Assert.assertEquals(expected.getContainsGangs(), actual.getContainsGangs()); - Assert.assertEquals(expected.getUser(), actual.getUser()); + Assertions.assertEquals(expected.getStartTime(), actual.getStartTime()); + Assertions.assertEquals(expected.getEndTime(), actual.getEndTime()); + Assertions.assertEquals(expected.getContainsGangs(), actual.getContainsGangs()); + Assertions.assertEquals(expected.getUser(), actual.getUser()); assertEquals( expected.getReservationDefinition(), actual.getReservationDefinition()); assertEquals(expected.getAllocationRequestsList(), @@ -970,12 +970,12 @@ void assertAllocationStateEqual( void assertAllocationStateEqual( ReservationAllocation expected, ReservationAllocationStateProto actual) { - Assert.assertEquals( + Assertions.assertEquals( expected.getAcceptanceTime(), actual.getAcceptanceTime()); - Assert.assertEquals(expected.getStartTime(), actual.getStartTime()); - Assert.assertEquals(expected.getEndTime(), actual.getEndTime()); - Assert.assertEquals(expected.containsGangs(), actual.getContainsGangs()); - Assert.assertEquals(expected.getUser(), actual.getUser()); + Assertions.assertEquals(expected.getStartTime(), actual.getStartTime()); + Assertions.assertEquals(expected.getEndTime(), actual.getEndTime()); + Assertions.assertEquals(expected.containsGangs(), actual.getContainsGangs()); + Assertions.assertEquals(expected.getUser(), actual.getUser()); assertEquals( expected.getReservationDefinition(), ReservationSystemUtil.convertFromProtoFormat( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestCheckRemoveZKNodeRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestCheckRemoveZKNodeRMStateStore.java index e8d38ebf742f6..c4019a899b0fd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestCheckRemoveZKNodeRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestCheckRemoveZKNodeRMStateStore.java @@ -44,16 +44,17 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; import org.apache.zookeeper.KeeperException; -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; import java.io.IOException; import org.mockito.Mockito; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; public class TestCheckRemoveZKNodeRMStateStore extends RMStateStoreTestBase { @@ -78,13 +79,13 @@ public static CuratorFramework setupCuratorFramework( return curatorFramework; } - @Before + @BeforeEach public void setupCurator() throws Exception { curatorTestingServer = setupCuratorServer(); curatorFramework = setupCuratorFramework(curatorTestingServer); } - @After + @AfterEach public void cleanupCuratorServer() throws IOException { curatorFramework.close(); curatorTestingServer.stop(); @@ -125,7 +126,7 @@ class TestZKRMStateStoreInternal extends ZKRMStateStore { dispatcher.disableExitOnDispatchException(); start(); - Assert.assertTrue(znodeWorkingPath.equals(workingZnode)); + Assertions.assertTrue(znodeWorkingPath.equals(workingZnode)); } private String getVersionNode() { @@ -236,7 +237,8 @@ public boolean attemptExists(RMAppAttempt attempt) throws Exception { } } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testSafeDeleteZKNode() throws Exception { TestZKRMStateStoreTester zkTester = new TestZKRMStateStoreTester(); testRemoveAttempt(zkTester); @@ -262,7 +264,7 @@ public void testRemoveAttempt(RMStateStoreHelper stateStoreHelper) throws Except try { store.removeApplicationAttemptInternal(attemptIdRemoved); } catch (KeeperException.NoNodeException nne) { - Assert.fail("NoNodeException should not happen."); + Assertions.fail("NoNodeException should not happen."); } // The verification method safeDelete is called once. @@ -296,7 +298,7 @@ public void testRemoveApplication(RMStateStoreHelper stateStoreHelper) throws Ex // The occurrence of NoNodeException is induced by calling the safeDelete method. store.removeApplicationStateInternal(appStateRemoved); } catch (KeeperException.NoNodeException nne) { - Assert.fail("NoNodeException should not happen."); + Assertions.fail("NoNodeException should not happen."); } store.close(); @@ -312,7 +314,7 @@ public void testRemoveRMDelegationToken(RMStateStoreHelper stateStoreHelper) thr try { store.removeRMDelegationTokenState(tokenIdRemoved); } catch (KeeperException.NoNodeException nne) { - Assert.fail("NoNodeException should not happen."); + Assertions.fail("NoNodeException should not happen."); } // The verification method safeDelete is called once. @@ -332,7 +334,7 @@ public void testRemoveRMDTMasterKeyState(RMStateStoreHelper stateStoreHelper) th try { store.removeRMDTMasterKeyState(keyRemoved); } catch (KeeperException.NoNodeException nne) { - Assert.fail("NoNodeException should not happen."); + Assertions.fail("NoNodeException should not happen."); } // The verification method safeDelete is called once. @@ -353,7 +355,7 @@ public void testRemoveReservationState(RMStateStoreHelper stateStoreHelper) thro try { store.removeReservationState(planName, reservationIdRemoved.toString()); } catch (KeeperException.NoNodeException nne) { - Assert.fail("NoNodeException should not happen."); + Assertions.fail("NoNodeException should not happen."); } // The verification method safeDelete is called once. @@ -376,11 +378,11 @@ public void testTransitionedToStandbyAfterCheckNode(RMStateStoreHelper stateStor // Transition to active. rm.getRMContext().getRMAdminService().transitionToActive(req); - Assert.assertEquals("RM with ZKStore didn't start", - Service.STATE.STARTED, rm.getServiceState()); - Assert.assertEquals("RM should be Active", - HAServiceProtocol.HAServiceState.ACTIVE, - rm.getRMContext().getRMAdminService().getServiceStatus().getState()); + Assertions.assertEquals( + Service.STATE.STARTED, rm.getServiceState(), "RM with ZKStore didn't start"); + Assertions.assertEquals( + HAServiceProtocol.HAServiceState.ACTIVE +, rm.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); // Simulate throw NodeExistsException ZKRMStateStore zKStore = (ZKRMStateStore) rm.getRMContext().getStateStore(); @@ -397,7 +399,7 @@ public void testTransitionedToStandbyAfterCheckNode(RMStateStoreHelper stateStor try { zKStore.removeApplicationAttemptInternal(attemptIdRemoved); } catch (Exception e) { - Assert.assertTrue(e instanceof KeeperException.NodeExistsException); + Assertions.assertTrue(e instanceof KeeperException.NodeExistsException); } 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/recovery/TestFSRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java index 65de39d7ab21c..4d777b0db71ff 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java @@ -19,7 +19,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.recovery; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.security.PrivilegedExceptionAction; @@ -50,8 +50,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; public class TestFSRMStateStore extends RMStateStoreTestBase { @@ -71,11 +72,11 @@ class TestFileSystemRMStore extends FileSystemRMStateStore { TestFileSystemRMStore(Configuration conf) throws Exception { init(conf); - Assert.assertNull(fs); + Assertions.assertNull(fs); assertTrue(workingDirPathURI.equals(fsWorkingPath)); dispatcher.disableExitOnDispatchException(); start(); - Assert.assertNotNull(fs); + Assertions.assertNotNull(fs); } public Path getVersionNode() { @@ -128,11 +129,11 @@ public RMStateStore getRMStateStore() throws Exception { this.store = new TestFileSystemRMStore(conf); assertThat(store.getNumRetries()).isEqualTo(8); assertThat(store.getRetryInterval()).isEqualTo(900L); - Assert.assertTrue(store.fs.getConf() == store.fsConf); + Assertions.assertTrue(store.fs.getConf() == store.fsConf); FileSystem previousFs = store.fs; store.startInternal(); - Assert.assertTrue(store.fs != previousFs); - Assert.assertTrue(store.fs.getConf() == store.fsConf); + Assertions.assertTrue(store.fs != previousFs); + Assertions.assertTrue(store.fs.getConf() == store.fsConf); return store; } @@ -172,7 +173,8 @@ public boolean attemptExists(RMAppAttempt attempt) throws IOException { } } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testFSRMStateStore() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(); MiniDFSCluster cluster = @@ -196,7 +198,7 @@ public void testFSRMStateStore() throws Exception { fsOut.close(); testRMAppStateStore(fsTester); - Assert.assertFalse(fsTester.workingDirPathURI + Assertions.assertFalse(fsTester.workingDirPathURI .getFileSystem(conf).exists(tempAppAttemptFile)); testRMDTSecretManagerStateStore(fsTester); testCheckVersion(fsTester); @@ -213,7 +215,8 @@ public void testFSRMStateStore() throws Exception { } } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testHDFSRMStateStore() throws Exception { final HdfsConfiguration conf = new HdfsConfiguration(); UserGroupInformation yarnAdmin = @@ -293,11 +296,11 @@ private void verifyFilesUnreadablebyHDFS(MiniDFSCluster cluster, try { LOG.warn("\n\n ##Testing path [" + p + "]\n\n"); fs.open(p); - Assert.fail("Super user should not be able to read ["+ UserGroupInformation.getCurrentUser() + "] [" + p.getName() + "]"); + Assertions.fail("Super user should not be able to read ["+ UserGroupInformation.getCurrentUser() + "] [" + p.getName() + "]"); } catch (AccessControlException e) { - Assert.assertTrue(e.getMessage().contains("superuser is not allowed to perform this operation")); + Assertions.assertTrue(e.getMessage().contains("superuser is not allowed to perform this operation")); } catch (Exception e) { - Assert.fail("Should get an AccessControlException here"); + Assertions.fail("Should get an AccessControlException here"); } } if (stat.isDirectory()) { @@ -310,7 +313,8 @@ private void verifyFilesUnreadablebyHDFS(MiniDFSCluster cluster, } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testCheckMajorVersionChange() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(); MiniDFSCluster cluster = @@ -355,7 +359,7 @@ protected synchronized void storeVersion() throws Exception { RMStateStore store = fsTester.getRMStateStore(); Version defaultVersion = fsTester.getCurrentVersion(); store.checkVersion(); - Assert.assertEquals(defaultVersion, store.loadVersion()); + Assertions.assertEquals(defaultVersion, store.loadVersion()); } finally { cluster.shutdown(); } @@ -391,7 +395,8 @@ protected void modifyRMDelegationTokenState() throws Exception { nodeCreatePath.getName() + ".new")); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testFSRMStateStoreClientRetry() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(); MiniDFSCluster cluster = @@ -419,7 +424,7 @@ public void testFSRMStateStoreClientRetry() throws Exception { clientThread.start(); cluster.restartNameNode(); clientThread.join(); - Assert.assertFalse(assertionFailedInThread.get()); + Assertions.assertFalse(assertionFailedInThread.get()); } finally { cluster.shutdown(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestLeveldbRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestLeveldbRMStateStore.java index e93599dd47ec4..57d687b39af8b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestLeveldbRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestLeveldbRMStateStore.java @@ -36,9 +36,10 @@ import org.fusesource.leveldbjni.JniDBFactory; import org.iq80.leveldb.DB; import org.iq80.leveldb.Options; -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 TestLeveldbRMStateStore extends RMStateStoreTestBase { @@ -50,14 +51,14 @@ public class TestLeveldbRMStateStore extends RMStateStoreTestBase { private YarnConfiguration conf; private LeveldbRMStateStore stateStore = null; - @Before + @BeforeEach public void setup() throws IOException { FileUtil.fullyDelete(TEST_DIR); conf = new YarnConfiguration(); conf.set(YarnConfiguration.RM_LEVELDB_STORE_PATH, TEST_DIR.toString()); } - @After + @AfterEach public void cleanup() throws IOException { if (stateStore != null) { stateStore.close(); @@ -65,25 +66,29 @@ public void cleanup() throws IOException { FileUtil.fullyDelete(TEST_DIR); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testApps() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testRMAppStateStore(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testClientTokens() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testRMDTSecretManagerStateStore(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testVersion() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testCheckVersion(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testEpoch() throws Exception { conf.setLong(YarnConfiguration.RM_EPOCH, epoch); conf.setLong(YarnConfiguration.RM_EPOCH_RANGE, getEpochRange()); @@ -91,49 +96,57 @@ public void testEpoch() throws Exception { testEpoch(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAppDeletion() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testAppDeletion(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testDeleteStore() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testDeleteStore(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testRemoveApplication() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testRemoveApplication(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testRemoveAttempt() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testRemoveAttempt(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testAMTokens() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testAMRMTokenSecretManagerStateStore(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testReservation() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testReservationStateStore(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testProxyCA() throws Exception { LeveldbStateStoreTester tester = new LeveldbStateStoreTester(); testProxyCA(tester); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testCompactionCycle() { final DB mockdb = mock(DB.class); conf.setLong(YarnConfiguration.RM_LEVELDB_COMPACTION_INTERVAL_SECS, 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/recovery/TestMemoryRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestMemoryRMStateStore.java index cb278c06e6170..f1e68cbbc4378 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestMemoryRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestMemoryRMStateStore.java @@ -22,9 +22,9 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier; import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; public class TestMemoryRMStateStore { @@ -47,8 +47,8 @@ public synchronized void removeRMDelegationTokenState( RMDelegationTokenIdentifier mockTokenId = mock(RMDelegationTokenIdentifier.class); store.removeRMDelegationToken(mockTokenId); - assertTrue("RMStateStore should have been in fenced state", - store.isFencedState()); + assertTrue( + store.isFencedState(), "RMStateStore should have been in fenced state"); store = new MemoryRMStateStore() { @Override public synchronized void removeRMDelegationToken( @@ -61,7 +61,7 @@ public synchronized void removeRMDelegationToken( store.setResourceManager(mockRM); store.setRMDispatcher(new RMStateStoreTestBase.TestDispatcher()); store.removeRMDelegationToken(mockTokenId); - assertTrue("RMStateStore should have been in fenced state", - store.isFencedState()); + assertTrue( + store.isFencedState(), "RMStateStore should have been in fenced state"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestProtos.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestProtos.java index d42b411a858e3..df1c3e38f9d61 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestProtos.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestProtos.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.recovery; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.List; @@ -27,8 +27,8 @@ import org.apache.hadoop.yarn.api.records.NMToken; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerRecoveryProtos.EpochProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.AllocateResponseProto; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Simple test to verify the protos generated are valid @@ -39,7 +39,7 @@ public class TestProtos { public void testProtoCanBePrinted() throws Exception { EpochProto proto = EpochProto.newBuilder().setEpoch(100).build(); String protoString = proto.toString(); - Assert.assertNotNull(protoString); + Assertions.assertNotNull(protoString); } @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/recovery/TestRMStateStoreUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestRMStateStoreUtils.java index 889f74f9bf632..d8f431f231c9f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestRMStateStoreUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestRMStateStoreUtils.java @@ -23,9 +23,9 @@ import org.apache.hadoop.io.Text; import org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier; import org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestRMStateStoreUtils { @@ -64,8 +64,8 @@ public void testReadRMDelegationTokenIdentifierData(boolean oldFormat) RMDelegationTokenIdentifierData identifierData = RMStateStoreUtils.readRMDelegationTokenIdentifierData(inBuf); - assertEquals("Found unexpected data still in the InputStream", - -1, inBuf.read()); + assertEquals( + -1, inBuf.read(), "Found unexpected data still in the InputStream"); RMDelegationTokenIdentifier identifier = identifierData.getTokenIdentifier(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java index bbf5e2ed351c7..3e337e7462fcd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java @@ -69,9 +69,10 @@ import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.ZooDefs.Perms; import org.apache.zookeeper.data.ACL; -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.apache.hadoop.thirdparty.com.google.common.base.Joiner; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableMap; @@ -80,12 +81,12 @@ import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -125,13 +126,13 @@ public static CuratorFramework setupCuratorFramework( return curatorFramework; } - @Before + @BeforeEach public void setupCurator() throws Exception { curatorTestingServer = setupCuratorServer(); curatorFramework = setupCuratorFramework(curatorTestingServer); } - @After + @AfterEach public void cleanupCuratorServer() throws IOException { curatorFramework.close(); curatorTestingServer.stop(); @@ -280,7 +281,8 @@ public int getDelegationTokenNodeSplitIndex() { } } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testZKRMStateStoreRealZK() throws Exception { TestZKRMStateStoreTester zkTester = new TestZKRMStateStoreTester(); testRMAppStateStore(zkTester); @@ -333,7 +335,8 @@ public void handle(Event event) { ; } - @Test (timeout = 60000) + @Test + @Timeout(value = 60) public void testCheckMajorVersionChange() throws Exception { TestZKRMStateStoreTester zkTester = new TestZKRMStateStoreTester() { Version VERSION_INFO = Version.newInstance(Integer.MAX_VALUE, 0); @@ -376,8 +379,8 @@ protected synchronized void storeVersion() throws Exception { RMStateStore store = zkTester.getRMStateStore(); Version defaultVersion = zkTester.getCurrentVersion(); store.checkVersion(); - assertEquals("Store had wrong version", - defaultVersion, store.loadVersion()); + assertEquals( + defaultVersion, store.loadVersion(), "Store had wrong version"); } public static Configuration createHARMConf(String rmIds, String rmId, @@ -487,22 +490,22 @@ public void testFencing() 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 = createHARMConf("rm1,rm2", "rm2", 5678, false, curatorTestingServer); ResourceManager rm2 = new MockRM(conf2); rm2.start(); 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 == @@ -510,12 +513,12 @@ public void testFencing() 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"); rm1.close(); rm2.close(); } @@ -527,8 +530,8 @@ public void testFencedState() throws Exception { // Move state to FENCED from ACTIVE store.updateFencedState(); - assertEquals("RMStateStore should have been in fenced state", - true, store.isFencedState()); + assertEquals( + true, store.isFencedState(), "RMStateStore should have been in fenced state"); long submitTime = System.currentTimeMillis(); long startTime = submitTime + 1000; @@ -542,8 +545,8 @@ public void testFencedState() throws Exception { when(mockApp.getApplicationSubmissionContext()).thenReturn(context); when(mockApp.getUser()).thenReturn("test"); store.storeNewApplication(mockApp); - assertEquals("RMStateStore should have been in fenced state", - true, store.isFencedState()); + assertEquals( + true, store.isFencedState(), "RMStateStore should have been in fenced state"); // Add a new attempt ClientToAMTokenSecretManagerInRM clientToAMTokenMgr = @@ -566,8 +569,8 @@ public void testFencedState() throws Exception { when(mockRmAppAttemptMetrics.getAggregateAppResourceUsage()) .thenReturn(new AggregateAppResourceUsage(new HashMap<>())); store.storeNewApplicationAttempt(mockAttempt); - assertEquals("RMStateStore should have been in fenced state", - true, store.isFencedState()); + assertEquals( + true, store.isFencedState(), "RMStateStore should have been in fenced state"); long finishTime = submitTime + 1000; // Update attempt @@ -578,20 +581,20 @@ public void testFencedState() throws Exception { "test", FinalApplicationStatus.SUCCEEDED, 100, finishTime, new HashMap<>(), new HashMap<>(), 0); store.updateApplicationAttemptState(newAttemptState); - assertEquals("RMStateStore should have been in fenced state", - true, store.isFencedState()); + assertEquals( + true, store.isFencedState(), "RMStateStore should have been in fenced state"); // Update app ApplicationStateData appState = ApplicationStateData.newInstance(submitTime, startTime, context, "test"); store.updateApplicationState(appState); - assertEquals("RMStateStore should have been in fenced state", - true, store.isFencedState()); + assertEquals( + true, store.isFencedState(), "RMStateStore should have been in fenced state"); // Remove app store.removeApplication(mockApp); - assertEquals("RMStateStore should have been in fenced state", - true, store.isFencedState()); + assertEquals( + true, store.isFencedState(), "RMStateStore should have been in fenced state"); // store RM delegation token; RMDelegationTokenIdentifier dtId1 = @@ -599,43 +602,43 @@ public void testFencedState() throws Exception { new Text("renewer1"), new Text("realuser1")); Long renewDate1 = new Long(System.currentTimeMillis()); dtId1.setSequenceNumber(1111); - assertFalse("Token " + dtId1 - + " should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(dtId1, 0)); + assertFalse( + zkTester.delegationTokenExists(dtId1, 0), "Token " + dtId1 + + " should not exist but was found in ZooKeeper"); store.storeRMDelegationToken(dtId1, renewDate1); - assertFalse("Token " + dtId1 - + " should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(dtId1, 0)); - assertEquals("RMStateStore should have been in fenced state", true, - store.isFencedState()); + assertFalse( + zkTester.delegationTokenExists(dtId1, 0), "Token " + dtId1 + + " should not exist but was found in ZooKeeper"); + assertEquals(true +, store.isFencedState(), "RMStateStore should have been in fenced state"); store.updateRMDelegationToken(dtId1, renewDate1); - assertFalse("Token " + dtId1 - + " should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(dtId1, 0)); - assertEquals("RMStateStore should have been in fenced state", true, - store.isFencedState()); + assertFalse( + zkTester.delegationTokenExists(dtId1, 0), "Token " + dtId1 + + " should not exist but was found in ZooKeeper"); + assertEquals(true +, store.isFencedState(), "RMStateStore should have been in fenced state"); // remove delegation key; store.removeRMDelegationToken(dtId1); - assertEquals("RMStateStore should have been in fenced state", true, - store.isFencedState()); + assertEquals(true +, store.isFencedState(), "RMStateStore should have been in fenced state"); // store delegation master key; DelegationKey key = new DelegationKey(1234, 4321, "keyBytes".getBytes()); store.storeRMDTMasterKey(key); - assertEquals("RMStateStore should have been in fenced state", true, - store.isFencedState()); + assertEquals(true +, store.isFencedState(), "RMStateStore should have been in fenced state"); // remove delegation master key; store.removeRMDTMasterKey(key); - assertEquals("RMStateStore should have been in fenced state", true, - store.isFencedState()); + assertEquals(true +, store.isFencedState(), "RMStateStore should have been in fenced state"); // store or update AMRMToken; store.storeOrUpdateAMRMTokenSecretManager(null, false); - assertEquals("RMStateStore should have been in fenced state", true, - store.isFencedState()); + assertEquals(true +, store.isFencedState(), "RMStateStore should have been in fenced state"); store.close(); } @@ -707,19 +710,19 @@ private static void verifyLoadedApp(ApplicationStateData appState, ApplicationId appId, String user, long submitTime, long startTime, RMAppState state, long finishTime, String diagnostics) { // Check if app is loaded correctly - assertNotNull("App " + appId + " should have been loaded.", appState); - assertEquals("App submit time in app state", submitTime, - appState.getSubmitTime()); - assertEquals("App start time in app state", startTime, - appState.getStartTime()); - assertEquals("App ID in app state", appId, - appState.getApplicationSubmissionContext().getApplicationId()); - assertEquals("App state", state, appState.getState()); - assertEquals("Finish time in app state", finishTime, - appState.getFinishTime()); - assertEquals("User in app state", user, appState.getUser()); - assertEquals("Diagnostics in app state", diagnostics, - appState.getDiagnostics()); + assertNotNull(appState, "App " + appId + " should have been loaded."); + assertEquals(submitTime +, appState.getSubmitTime(), "App submit time in app state"); + assertEquals(startTime +, appState.getStartTime(), "App start time in app state"); + assertEquals(appId +, appState.getApplicationSubmissionContext().getApplicationId(), "App ID in app state"); + assertEquals(state, appState.getState(), "App state"); + assertEquals(finishTime +, appState.getFinishTime(), "Finish time in app state"); + assertEquals(user, appState.getUser(), "User in app state"); + assertEquals(diagnostics +, appState.getDiagnostics(), "Diagnostics in app state"); } private static void verifyLoadedApp(RMState rmState, @@ -737,14 +740,14 @@ private static void verifyLoadedApp(RMState rmState, Map rmAppState = rmState.getApplicationState(); ApplicationStateData appState = rmAppState.get(appId); - assertNotNull(appId + " is not there in loaded apps", appState); + assertNotNull(appState, appId + " is not there in loaded apps"); verifyLoadedApp(appState, appId, "test", submitTime, startTime, isFinished ? RMAppState.FINISHED : null, finishTime, isFinished ? "appDiagnostics" : ""); // Check attempt state. if (attempts != null) { - assertEquals("Attempts loaded for app " + appId, attempts.size(), - appState.attempts.size()); + assertEquals(attempts.size() +, appState.attempts.size(), "Attempts loaded for app " + appId); if (finalStatuses != null && amExitStatuses != null) { for (int i = 0; i < attempts.size(); i++) { if (finalStatuses.get(i) != null) { @@ -758,7 +761,7 @@ private static void verifyLoadedApp(RMState rmState, } } else { assertEquals( - "Attempts loaded for app " + appId, 0, appState.attempts.size()); + 0, appState.attempts.size(), "Attempts loaded for app " + appId); } } @@ -779,27 +782,27 @@ private static void verifyLoadedAttempt(ApplicationStateData appState, ApplicationAttemptStateData attemptState = appState.getAttempt(attemptId); // Check if attempt is loaded correctly assertNotNull( - "Attempt " + attemptId + " should have been loaded.", attemptState); - assertEquals("Attempt Id in attempt state", - attemptId, attemptState.getAttemptId()); - assertEquals("Master Container Id in attempt state", - masterContainerId, attemptState.getMasterContainer().getId()); + attemptState, "Attempt " + attemptId + " should have been loaded."); + assertEquals( + attemptId, attemptState.getAttemptId(), "Attempt Id in attempt state"); + assertEquals( + masterContainerId, attemptState.getMasterContainer().getId(), "Master Container Id in attempt state"); if (null != clientTokenKey) { - assertArrayEquals("Client token key in attempt state", - clientTokenKey.getEncoded(), attemptState.getAppAttemptTokens(). - getSecretKey(RMStateStore.AM_CLIENT_TOKEN_MASTER_KEY_NAME)); + assertArrayEquals( + clientTokenKey.getEncoded(), attemptState.getAppAttemptTokens(). + getSecretKey(RMStateStore.AM_CLIENT_TOKEN_MASTER_KEY_NAME), "Client token key in attempt state"); } - assertEquals("Attempt state", state, attemptState.getState()); - assertEquals("Finish time in attempt state", finishTime, - attemptState.getFinishTime()); - assertEquals("Diagnostics in attempt state", diagnostics, - attemptState.getDiagnostics()); - assertEquals("AM Container exit status in attempt state", amExitStatus, - attemptState.getAMContainerExitStatus()); - assertEquals("Final app status in attempt state", finalStatus, - attemptState.getFinalApplicationStatus()); - assertEquals("Tracking URL in attempt state", trackingURL, - attemptState.getFinalTrackingUrl()); + assertEquals(state, attemptState.getState(), "Attempt state"); + assertEquals(finishTime +, attemptState.getFinishTime(), "Finish time in attempt state"); + assertEquals(diagnostics +, attemptState.getDiagnostics(), "Diagnostics in attempt state"); + assertEquals(amExitStatus +, attemptState.getAMContainerExitStatus(), "AM Container exit status in attempt state"); + assertEquals(finalStatus +, attemptState.getFinalApplicationStatus(), "Final app status in attempt state"); + assertEquals(trackingURL +, attemptState.getFinalTrackingUrl(), "Tracking URL in attempt state"); } private static ApplicationStateData createAppState( @@ -931,8 +934,8 @@ private static void verifyAppPathPath(RMStateStore store, ApplicationId appId, ZKRMStateStore.ROOT_ZNODE_NAME, ZKRMStateStore.RM_APP_ROOT, ZKRMStateStore.RM_APP_ROOT_HIERARCHIES, String.valueOf(splitIndex), appParent, appPath); - assertTrue("Application with id " + appIdStr + " does not exist as per " + - "split in state store.", ((ZKRMStateStore)store).exists(path)); + assertTrue(((ZKRMStateStore)store).exists(path), "Application with id " + appIdStr + " does not exist as per " + + "split in state store."); } private static void verifyAppInHierarchicalPath(RMStateStore store, @@ -946,8 +949,8 @@ private static void verifyAppInHierarchicalPath(RMStateStore store, } else { path = createPath(path, appId); } - assertTrue(appId + " should exist in path " + path, - ((ZKRMStateStore)store).exists(createPath(path))); + assertTrue( + ((ZKRMStateStore)store).exists(createPath(path)), appId + " should exist in path " + path); } private static void assertHierarchicalPaths(RMStateStore store, @@ -959,9 +962,9 @@ private static void assertHierarchicalPaths(RMStateStore store, path = createPath(path, ZKRMStateStore.RM_APP_ROOT_HIERARCHIES, String.valueOf(entry.getKey())); } - assertEquals("Number of childrens for path " + path, - (int) entry.getValue(), - ((ZKRMStateStore)store).getChildren(path).size()); + assertEquals( + (int) entry.getValue() +, ((ZKRMStateStore)store).getChildren(path).size(), "Number of childrens for path " + path); } } @@ -1056,7 +1059,7 @@ public void testAppNodeSplit() throws Exception { FinalApplicationStatus.SUCCEEDED)); // assert store is in expected state after everything is cleaned - assertTrue("Store is not in expected state", zkTester.isFinalStateValid()); + assertTrue(zkTester.isFinalStateValid(), "Store is not in expected state"); store.close(); } @@ -1128,8 +1131,8 @@ public void testAppNodeSplitChangeAcrossRestarts() throws Exception { store = zkTester.getRMStateStore(createConfForAppNodeSplit(0)); store.setRMDispatcher(dispatcher); state = store.loadState(); - assertEquals("Number of Apps loaded should be 4.", 4, - state.getApplicationState().size()); + assertEquals(4 +, state.getApplicationState().size(), "Number of Apps loaded should be 4."); verifyLoadedApp(state, appId1, submitTime, startTime, 1234, true, Lists.newArrayList(attemptId1, attemptId2), Lists.newArrayList(-1000, 100), Lists.newArrayList(null, FinalApplicationStatus.SUCCEEDED)); @@ -1144,8 +1147,8 @@ public void testAppNodeSplitChangeAcrossRestarts() throws Exception { store = zkTester.getRMStateStore(createConfForAppNodeSplit(3)); store.setRMDispatcher(dispatcher); state = store.loadState(); - assertEquals("Number of apps loaded should be 5.", 5, - state.getApplicationState().size()); + assertEquals(5 +, state.getApplicationState().size(), "Number of apps loaded should be 5."); verifyLoadedApp(state, dummyAppId, submitTime, startTime, 1234, true, Lists.newArrayList(dummyAttemptId), Lists.newArrayList(111), Lists.newArrayList(FinalApplicationStatus.SUCCEEDED)); @@ -1192,8 +1195,8 @@ public void testAppNodeSplitChangeAcrossRestarts() throws Exception { store = zkTester.getRMStateStore(createConfForAppNodeSplit(3)); store.setRMDispatcher(dispatcher); state = store.loadState(); - assertEquals("Number of apps loaded should be 0.", 0, - state.getApplicationState().size()); + assertEquals(0 +, state.getApplicationState().size(), "Number of apps loaded should be 0."); // Close the state store. store.close(); } @@ -1213,16 +1216,16 @@ private void verifyDelegationTokensStateStore( int sequenceNumber) throws Exception { RMStateStore.RMDTSecretManagerState secretManagerState = zkTester.store.loadState().getRMDTSecretManagerState(); - assertEquals("Unexpected token state", - tokensWithRenewal, secretManagerState.getTokenState()); - assertEquals("Unexpected sequence number", sequenceNumber, - secretManagerState.getDTSequenceNumber()); + assertEquals( + tokensWithRenewal, secretManagerState.getTokenState(), "Unexpected token state"); + assertEquals(sequenceNumber +, secretManagerState.getDTSequenceNumber(), "Unexpected sequence number"); for (Map.Entry tokenEntry : tokensWithIndex.entrySet()) { - assertTrue("Expected to find token " + tokenEntry.getKey() - + " in zookeeper but did not", - zkTester.delegationTokenExists(tokenEntry.getKey(), - tokenEntry.getValue())); + assertTrue( + zkTester.delegationTokenExists(tokenEntry.getKey(), + tokenEntry.getValue()), "Expected to find token " + tokenEntry.getKey() + + " in zookeeper but did not"); } } @@ -1233,12 +1236,12 @@ private void verifyDelegationTokenInStateStore( zkTester.store.loadState().getRMDTSecretManagerState(); Map tokenState = secretManagerState.getTokenState(); - assertTrue("token state does not contain " + token, - tokenState.containsKey(token)); - assertTrue("token state does not contain a token with renewal " + renewDate, - tokenState.containsValue(renewDate)); - assertTrue("Token " + token + "should exist but was not found in ZooKeeper", - zkTester.delegationTokenExists(token, index)); + assertTrue( + tokenState.containsKey(token), "token state does not contain " + token); + assertTrue( + tokenState.containsValue(renewDate), "token state does not contain a token with renewal " + renewDate); + assertTrue( + zkTester.delegationTokenExists(token, index), "Token " + token + "should exist but was not found in ZooKeeper"); } private RMDelegationTokenIdentifier storeUpdateAndVerifyDelegationToken( @@ -1250,8 +1253,8 @@ private RMDelegationTokenIdentifier storeUpdateAndVerifyDelegationToken( RMDelegationTokenIdentifier token = new RMDelegationTokenIdentifier(new Text("owner"), new Text("renewer"), new Text("realuser")); - assertFalse("Token should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(token, split)); + assertFalse( + zkTester.delegationTokenExists(token, split), "Token should not exist but was found in ZooKeeper"); token.setSequenceNumber(sequenceNumber); Long renewDate = System.currentTimeMillis(); zkTester.store.storeRMDelegationToken(token, renewDate); @@ -1281,28 +1284,28 @@ public void testDelegationTokenSplitIndexConfig() throws Exception { // Valid values TestZKRMStateStoreTester zkTester = new TestZKRMStateStoreTester(); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(0)).close(); - assertEquals("Incorrect split index", - 0, zkTester.getDelegationTokenNodeSplitIndex()); + assertEquals( + 0, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(1)).close(); - assertEquals("Incorrect split index", - 1, zkTester.getDelegationTokenNodeSplitIndex()); + assertEquals( + 1, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(2)).close(); - assertEquals("Incorrect split index", - 2, zkTester.getDelegationTokenNodeSplitIndex()); + assertEquals( + 2, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(3)).close(); - assertEquals("Incorrect split index", - 3, zkTester.getDelegationTokenNodeSplitIndex()); + assertEquals( + 3, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(4)).close(); - assertEquals("Incorrect split index", - 4, zkTester.getDelegationTokenNodeSplitIndex()); + assertEquals( + 4, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); // Invalid values --> override to 0 zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(-1)).close(); - assertEquals("Incorrect split index", - 0, zkTester.getDelegationTokenNodeSplitIndex()); + assertEquals( + 0, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(5)).close(); - assertEquals("Incorrect split index", - 0, zkTester.getDelegationTokenNodeSplitIndex()); + assertEquals( + 0, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); } @Test @@ -1348,12 +1351,12 @@ public void testDelegationTokenNode(int split) throws Exception { store.loadState().getRMDTSecretManagerState(); tokensWithRenewal.clear(); tokensWithIndex.clear(); - assertEquals("Unexpected token state", - tokensWithRenewal, state.getTokenState()); - assertEquals("Unexpected sequence number", - sequenceNumber, state.getDTSequenceNumber()); - assertFalse("Token should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(token, split)); + assertEquals( + tokensWithRenewal, state.getTokenState(), "Unexpected token state"); + assertEquals( + sequenceNumber, state.getDTSequenceNumber(), "Unexpected sequence number"); + assertFalse( + zkTester.delegationTokenExists(token, split), "Token should not exist but was found in ZooKeeper"); store.close(); } @@ -1375,8 +1378,8 @@ public void testDelegationTokenNodeWithSplitMultiple() throws Exception { new Text("renewer" + i), new Text("realuser" + i)); sequenceNumber = i; token.setSequenceNumber(sequenceNumber); - assertFalse("Token should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(token, 1)); + assertFalse( + zkTester.delegationTokenExists(token, 1), "Token should not exist but was found in ZooKeeper"); Long renewDate = System.currentTimeMillis(); store.storeRMDelegationToken(token, renewDate); modifyRMDelegationTokenState(); @@ -1419,9 +1422,9 @@ public void testDelegationTokenNodeWithSplitMultiple() throws Exception { verifyDelegationTokensStateStore(zkTester, tokensWithRenewal, tokensWithIndex, sequenceNumber); for (RMDelegationTokenIdentifier token : tokensToDelete) { - assertFalse("Token " + token - + " should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(token, 1)); + assertFalse( + zkTester.delegationTokenExists(token, 1), "Token " + token + + " should not exist but was found in ZooKeeper"); } store.close(); } @@ -1495,15 +1498,15 @@ public void testDelegationTokenNodeWithSplitChangeAcrossRestarts() tokensWithIndex.clear(); verifyDelegationTokensStateStore( zkTester, tokensWithRenewal, tokensWithIndex, sequenceNumber); - assertFalse("Token " + token1 - + " should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(token1, 1)); - assertFalse("Token " + token1 - + " should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(token2, 2)); - assertFalse("Token " + token1 - + " should not exist but was found in ZooKeeper", - zkTester.delegationTokenExists(token0, 0)); + assertFalse( + zkTester.delegationTokenExists(token1, 1), "Token " + token1 + + " should not exist but was found in ZooKeeper"); + assertFalse( + zkTester.delegationTokenExists(token2, 2), "Token " + token1 + + " should not exist but was found in ZooKeeper"); + assertFalse( + zkTester.delegationTokenExists(token0, 0), "Token " + token1 + + " should not exist but was found in ZooKeeper"); // Store a token with index 3 sequenceNumber++; storeUpdateAndVerifyDelegationToken(zkTester, tokensWithRenewal, @@ -1550,10 +1553,10 @@ public void testAppSubmissionContextIsPrunedInFinalApplicationState() ctx = rmState.getApplicationState().get(appId) .getApplicationSubmissionContext(); - assertEquals("ApplicationSchedulingPropertiesMap should not have been " + assertEquals( + schedulingPropertiesMap, ctx.getApplicationSchedulingPropertiesMap(), "ApplicationSchedulingPropertiesMap should not have been " + "pruned from the application submission context before the " - + "FINISHED state", - schedulingPropertiesMap, ctx.getApplicationSchedulingPropertiesMap()); + + "FINISHED state"); appState.setState(RMAppState.FINISHED); store.handleStoreEvent(new RMStateUpdateAppEvent(appState, false, null)); @@ -1566,9 +1569,9 @@ public void testAppSubmissionContextIsPrunedInFinalApplicationState() assertEquals("a_queue", ctx.getQueue()); assertNotNull(ctx.getAMContainerSpec()); assertEquals(17L, ctx.getResource().getMemorySize()); - assertEquals("ApplicationSchedulingPropertiesMap should have been pruned" - + " from the application submission context when in FINISHED STATE", - Collections.emptyMap(), ctx.getApplicationSchedulingPropertiesMap()); + assertEquals( + Collections.emptyMap(), ctx.getApplicationSchedulingPropertiesMap(), "ApplicationSchedulingPropertiesMap should have been pruned" + + " from the application submission context when in FINISHED STATE"); store.close(); } @@ -1589,8 +1592,8 @@ public void testMetricsInited() throws Exception { Thread.sleep(110); opDurations.getMetrics(collector, true); - assertEquals("Incorrect number of perf metrics", 1, - collector.getRecords().size()); + assertEquals(1 +, collector.getRecords().size(), "Incorrect number of perf metrics"); MetricsRecord record = collector.getRecords().get(0); MetricsRecords.assertTag(record, ZKRMStateStoreOpDurations.RECORD_INFO.name(), diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStorePerf.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStorePerf.java index 3cb428c5c5960..c0ac6bcc2b4a1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStorePerf.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStorePerf.java @@ -45,9 +45,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.security.AMRMTokenSecretManager; import org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM; -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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -78,12 +78,12 @@ public class TestZKRMStateStorePerf extends RMStateStoreTestBase private ClientToAMTokenSecretManagerInRM clientToAMTokenMgr; private TestingServer curatorTestingServer; - @Before + @BeforeEach public void setUpZKServer() throws Exception { curatorTestingServer = new TestingServer(); } - @After + @AfterEach public void tearDown() throws Exception { if (store != null) { store.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/recovery/TestZKRMStateStoreZKClientConnections.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStoreZKClientConnections.java index dce2bed5522e7..f405ac622c1b6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStoreZKClientConnections.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStoreZKClientConnections.java @@ -29,16 +29,17 @@ import org.apache.hadoop.util.ZKUtil; import org.apache.zookeeper.server.auth.DigestAuthenticationProvider; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicBoolean; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestZKRMStateStoreZKClientConnections { private static final Logger LOG = @@ -60,13 +61,13 @@ public class TestZKRMStateStoreZKClientConnections { private TestingServer testingServer; - @Before + @BeforeEach public void setupZKServer() throws Exception { testingServer = new TestingServer(); testingServer.start(); } - @After + @AfterEach public void cleanupZKServer() throws Exception { testingServer.stop(); } @@ -96,7 +97,8 @@ public RMStateStore getRMStateStore(Configuration conf) throws Exception { } } - @Test (timeout = 20000) + @Test + @Timeout(value = 20) public void testZKClientRetry() throws Exception { TestZKClient zkClientTester = new TestZKClient(); final String path = "/test"; @@ -124,10 +126,11 @@ public void run() { Thread.sleep(2000); testingServer.start(); clientThread.join(); - Assert.assertFalse(assertionFailedInThread.get()); + Assertions.assertFalse(assertionFailedInThread.get()); } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testSetZKAcl() { TestZKClient zkClientTester = new TestZKClient(); YarnConfiguration conf = new YarnConfiguration(); @@ -140,7 +143,8 @@ public void testSetZKAcl() { } } - @Test(timeout = 20000) + @Test + @Timeout(value = 20) public void testInvalidZKAclConfiguration() { TestZKClient zkClientTester = new TestZKClient(); YarnConfiguration conf = new YarnConfiguration(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java index b9ce54e6a5cbe..42242c62ddf4c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java @@ -17,8 +17,8 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import java.io.IOException; @@ -33,7 +33,7 @@ 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.jupiter.api.BeforeEach; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -75,7 +75,7 @@ public abstract class BaseSharingPolicyTest { protected ReservationSchedulerConfiguration conf; - @Before + @BeforeEach public void setup() { // 1 sec step step = 1000L; @@ -138,7 +138,7 @@ public void runTest() throws IOException, PlanningException { "dedicated", rstart, rend, reservationIntervalResourceMap, res, minAlloc); - assertTrue(plan.toString(), plan.addReservation(resAlloc, false)); + assertTrue(plan.addReservation(resAlloc, false), plan.toString()); } // fail if error was expected if (expectedError != 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/reservation/ReservationSystemTestUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java index 7e172aee35308..0813e9b00f734 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java @@ -65,7 +65,7 @@ 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.DefaultResourceCalculator; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -112,13 +112,13 @@ public static ReservationSchedulerConfiguration createConf( public static void validateReservationQueue( AbstractReservationSystem reservationSystem, String planQName) { Plan plan = reservationSystem.getPlan(planQName); - Assert.assertNotNull(plan); - Assert.assertTrue(plan instanceof InMemoryPlan); - Assert.assertEquals(planQName, plan.getQueueName()); - Assert.assertEquals(8192, plan.getTotalCapacity().getMemorySize()); - Assert.assertTrue( + Assertions.assertNotNull(plan); + Assertions.assertTrue(plan instanceof InMemoryPlan); + Assertions.assertEquals(planQName, plan.getQueueName()); + Assertions.assertEquals(8192, plan.getTotalCapacity().getMemorySize()); + Assertions.assertTrue( plan.getReservationAgent() instanceof AlignedPlannerWithGreedy); - Assert + Assertions .assertTrue(plan.getSharingPolicy() instanceof CapacityOverTimePolicy); } @@ -256,7 +256,7 @@ public CapacityScheduler mockCapacityScheduler(int numContainers) try { cs.serviceInit(conf); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } initializeRMContext(numContainers, cs, mockRmContext); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacityOverTimePolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacityOverTimePolicy.java index a988211d78f14..0ee05434e97ea 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacityOverTimePolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacityOverTimePolicy.java @@ -25,7 +25,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException; import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningQuotaException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java index 20aa5511f8222..5149e4111ed7b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.reservation; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -50,11 +50,11 @@ import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.rules.TestName; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -70,7 +70,7 @@ public class TestCapacitySchedulerPlanFollower extends @Rule public TestName name = new TestName(); - @Before + @BeforeEach public void setUp() throws Exception { CapacityScheduler spyCs = new CapacityScheduler(); cs = spy(spyCs); @@ -161,8 +161,8 @@ protected void verifyCapacity(Queue defQ) { @Override protected void checkDefaultQueueBeforePlanFollowerRun(){ Queue defQ = getDefaultQueue(); - Assert.assertEquals(0, getNumberOfApplications(defQ)); - Assert.assertNotNull(defQ); + Assertions.assertEquals(0, getNumberOfApplications(defQ)); + Assertions.assertNotNull(defQ); } @Override @@ -196,8 +196,8 @@ protected void assertReservationQueueExists(ReservationId r2, double expectedCapacity, double expectedMaxCapacity) { CSQueue q = cs.getQueue(r2.toString()); assertNotNull(q); - Assert.assertEquals(expectedCapacity, q.getCapacity(), 0.01); - Assert.assertEquals(expectedMaxCapacity, q.getMaximumCapacity(), 1.0); + Assertions.assertEquals(expectedCapacity, q.getCapacity(), 0.01); + Assertions.assertEquals(expectedMaxCapacity, q.getMaximumCapacity(), 1.0); } @Override @@ -211,7 +211,7 @@ public static ApplicationACLsManager mockAppACLsManager() { return new ApplicationACLsManager(conf); } - @After + @AfterEach public void tearDown() throws Exception { if (scheduler != 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/reservation/TestFairSchedulerPlanFollower.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java index 77bea57469b8b..d74c3426e7b25 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.reservation; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -50,11 +50,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerTestBase; import org.apache.hadoop.yarn.server.security.ApplicationACLsManager; import org.apache.hadoop.yarn.util.Clock; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.rules.TestName; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -81,7 +81,7 @@ protected Configuration createConfiguration() { return conf; } - @Before + @BeforeEach public void setUp() throws Exception { conf = createConfiguration(); ReservationSystemTestUtil.setupFSAllocationFile(ALLOC_FILE); @@ -132,7 +132,7 @@ public void testWithKillOnExpiry() throws PlanningException, @Override protected void checkDefaultQueueBeforePlanFollowerRun() { - Assert.assertNull(getDefaultQueue()); + Assertions.assertNull(getDefaultQueue()); } @Override protected void verifyCapacity(Queue defQ) { @@ -172,7 +172,7 @@ protected void assertReservationQueueExists(ReservationId r, false); assertNotNull(q); // For now we are setting both to same weight - Assert.assertEquals(expectedCapacity, q.getWeight(), 0.01); + Assertions.assertEquals(expectedCapacity, q.getWeight(), 0.01); } @Override @@ -192,7 +192,7 @@ public static ApplicationACLsManager mockAppACLsManager() { return new ApplicationACLsManager(conf); } - @After + @AfterEach public void tearDown() throws Exception { if (scheduler != null) { fs.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/reservation/TestInMemoryPlan.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryPlan.java index c687eeab74931..c11249ea9aeec 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryPlan.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryPlan.java @@ -17,7 +17,8 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -46,10 +47,10 @@ import org.apache.hadoop.yarn.util.UTCClock; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Testing the class {@link InMemoryPlan}. @@ -72,7 +73,7 @@ public class TestInMemoryPlan { private RMContext context; private long maxPeriodicity; - @Before + @BeforeEach public void setUp() throws PlanningException { resCalc = new DefaultResourceCalculator(); minAlloc = Resource.newInstance(1024, 1); @@ -89,7 +90,7 @@ public void setUp() throws PlanningException { context = ReservationSystemTestUtil.createMockRMContext(); } - @After + @AfterEach public void tearDown() { resCalc = null; minAlloc = null; @@ -112,26 +113,28 @@ public void testAddReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc, start, 0); } - @Test(expected = PlanningException.class) + @Test public void testOutOfRange() throws PlanningException { - maxPeriodicity = 100; - Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, - resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, - context, new UTCClock()); - - // we expect the plan to complaint as the range 330-150 > 50 - RLESparseResourceAllocation availableBefore = - plan.getAvailableResourceOverTime(user, null, 150, 330, 50); + assertThrows(PlanningException.class, ()->{ + maxPeriodicity = 100; + Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, + resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, + context, new UTCClock()); + + // we expect the plan to complaint as the range 330-150 > 50 + RLESparseResourceAllocation availableBefore = + plan.getAvailableResourceOverTime(user, null, 150, 330, 50); + }); } @Test @@ -151,11 +154,11 @@ public void testAddPeriodicReservation() throws PlanningException { reservationID, start, alloc, String.valueOf(period)); // use periodicity of 1hr rAllocation.setPeriodicity(period); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc, start, period); @@ -192,10 +195,10 @@ private void checkAllocation(Plan plan, int[] alloc, int start, long y = 0; Resource res = Resource.newInstance(1024 * (alloc[i]), (alloc[i])); while (y <= end * 2) { - assertEquals("At time: " + start + i + y, res, - plan.getTotalCommittedResources(start + i + y)); - assertEquals(" At time: " + (start + i + y), res, - userCons.getCapacityAtTime(start + i + y)); + assertEquals(res +, plan.getTotalCommittedResources(start + i + y), "At time: " + start + i + y); + assertEquals(res +, userCons.getCapacityAtTime(start + i + y), " At time: " + (start + i + y)); y = y + periodicity; } } @@ -212,11 +215,11 @@ public void testAddEmptyReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } @@ -231,11 +234,11 @@ public void testAddReservationAlreadyExists() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc, start, 0); @@ -243,11 +246,11 @@ public void testAddReservationAlreadyExists() { // Try to add it again try { plan.addReservation(rAllocation, false); - Assert.fail("Add should fail as it already exists"); + Assertions.fail("Add should fail as it already exists"); } catch (IllegalArgumentException e) { - Assert.assertTrue(e.getMessage().endsWith("already exists")); + Assertions.assertTrue(e.getMessage().endsWith("already exists")); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); } @@ -263,11 +266,11 @@ public void testUpdateReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); @@ -288,7 +291,7 @@ public void testUpdateReservation() { try { plan.updateReservation(rAllocation); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); @@ -319,11 +322,11 @@ public void testUpdatePeriodicReservation() { rAllocation.getReservationDefinition() .setRecurrenceExpression(String.valueOf(period)); rAllocation.setPeriodicity(period); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } System.out.println(plan.toString()); doAssertions(plan, rAllocation); @@ -340,7 +343,7 @@ public void testUpdatePeriodicReservation() { try { plan.updateReservation(rAllocation); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, updatedAlloc, start, period); @@ -357,16 +360,16 @@ public void testUpdateNonExistingReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.updateReservation(rAllocation); - Assert.fail("Update should fail as it does not exist in the plan"); + Assertions.fail("Update should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { - Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan")); + Assertions.assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); } @Test @@ -380,11 +383,11 @@ public void testDeleteReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc, true); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); @@ -404,9 +407,9 @@ public void testDeleteReservation() { try { plan.deleteReservation(reservationID); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); userCons = plan.getConsumptionForUserOverTime(user, start, start + alloc.length); for (int i = 0; i < alloc.length; i++) { @@ -433,11 +436,11 @@ public void testDeletePeriodicReservation() { rAllocation.getReservationDefinition() .setRecurrenceExpression(String.valueOf(period)); rAllocation.setPeriodicity(period); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } System.out.println(plan.toString()); doAssertions(plan, rAllocation); @@ -447,9 +450,9 @@ public void testDeletePeriodicReservation() { try { plan.deleteReservation(reservationID); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); System.out.print(plan); checkAllocation(plan, new int[] { 0, 0 }, start, period); } @@ -461,16 +464,16 @@ public void testDeleteNonExistingReservation() { ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to delete a reservation without adding - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.deleteReservation(reservationID); - Assert.fail("Delete should fail as it does not exist in the plan"); + Assertions.fail("Delete should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { - Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan")); + Assertions.assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); } @Test @@ -486,11 +489,11 @@ public void testArchiveCompletedReservations() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID1, start, alloc1); - Assert.assertNull(plan.getReservationById(reservationID1)); + Assertions.assertNull(plan.getReservationById(reservationID1)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc1, start, 0); @@ -501,13 +504,13 @@ public void testArchiveCompletedReservations() { int[] alloc2 = { 0, 5, 10, 5, 0 }; rAllocation = createReservationAllocation(reservationID2, start, alloc2, true); - Assert.assertNull(plan.getReservationById(reservationID2)); + Assertions.assertNull(plan.getReservationById(reservationID2)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan.getReservationById(reservationID2)); + Assertions.assertNotNull(plan.getReservationById(reservationID2)); RLESparseResourceAllocation userCons = plan.getConsumptionForUserOverTime(user, start, start + alloc2.length); @@ -531,10 +534,10 @@ public void testArchiveCompletedReservations() { // archival window plan.archiveCompletedReservations(clock.getTime()); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan.getReservationById(reservationID1)); - Assert.assertNull(plan.getReservationById(reservationID2)); + Assertions.assertNotNull(plan.getReservationById(reservationID1)); + Assertions.assertNull(plan.getReservationById(reservationID2)); checkAllocation(plan, alloc1, start, 0); when(clock.getTime()).thenReturn(107L); @@ -543,13 +546,13 @@ public void testArchiveCompletedReservations() { // window plan.archiveCompletedReservations(clock.getTime()); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } userCons = plan.getConsumptionForUserOverTime(user, start, start + alloc1.length); - Assert.assertNull(plan.getReservationById(reservationID1)); + Assertions.assertNull(plan.getReservationById(reservationID1)); for (int i = 0; i < alloc1.length; i++) { assertEquals(Resource.newInstance(0, 0), plan.getTotalCommittedResources(start + i)); @@ -568,26 +571,26 @@ public void testGetReservationsById() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // Verify that get by reservation id works. Set rAllocations = plan.getReservations(reservationID, null, ""); - Assert.assertTrue(rAllocations.size() == 1); - Assert.assertTrue(rAllocation + Assertions.assertTrue(rAllocations.size() == 1); + Assertions.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by reservation id works even when time range // and user is invalid. ReservationInterval interval = new ReservationInterval(0, 0); rAllocations = plan.getReservations(reservationID, interval, "invalid"); - Assert.assertTrue(rAllocations.size() == 1); - Assert.assertTrue(rAllocation + Assertions.assertTrue(rAllocations.size() == 1); + Assertions.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); } @@ -601,11 +604,11 @@ public void testGetReservationsByInvalidId() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // If reservationId is null, then nothing is returned. @@ -613,7 +616,7 @@ public void testGetReservationsByInvalidId() { ReservationSystemTestUtil.getNewReservationId(); Set rAllocations = plan.getReservations(invalidReservationID, null, ""); - Assert.assertTrue(rAllocations.size() == 0); + Assertions.assertTrue(rAllocations.size() == 0); } @Test @@ -626,11 +629,11 @@ public void testGetReservationsByTimeInterval() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // Verify that get by time interval works if the selection interval @@ -639,8 +642,8 @@ public void testGetReservationsByTimeInterval() { rAllocation.getStartTime(), rAllocation.getEndTime()); Set rAllocations = plan.getReservations(null, interval, ""); - Assert.assertTrue(rAllocations.size() == 1); - Assert.assertTrue(rAllocation + Assertions.assertTrue(rAllocations.size() == 1); + Assertions.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by time interval works if the selection interval @@ -650,8 +653,8 @@ public void testGetReservationsByTimeInterval() { rAllocation.getStartTime() + duration * (long) 0.3, rAllocation.getEndTime() - duration * (long) 0.3); rAllocations = plan.getReservations(null, interval, ""); - Assert.assertTrue(rAllocations.size() == 1); - Assert.assertTrue(rAllocation + Assertions.assertTrue(rAllocations.size() == 1); + Assertions.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by time interval selects 1 allocation if the end @@ -659,8 +662,8 @@ public void testGetReservationsByTimeInterval() { // allocation. interval = new ReservationInterval(0, rAllocation.getStartTime()); rAllocations = plan.getReservations(null, interval, ""); - Assert.assertTrue(rAllocations.size() == 1); - Assert.assertTrue(rAllocation + Assertions.assertTrue(rAllocations.size() == 1); + Assertions.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by time interval selects no reservations if the start @@ -668,13 +671,13 @@ public void testGetReservationsByTimeInterval() { interval = new ReservationInterval(rAllocation.getEndTime(), Long.MAX_VALUE); rAllocations = plan.getReservations(null, interval, ""); - Assert.assertTrue(rAllocations.size() == 0); + Assertions.assertTrue(rAllocations.size() == 0); // Verify that get by time interval selects no reservations if the // selection interval and allocation interval do not overlap. interval = new ReservationInterval(0, rAllocation.getStartTime() / 2); rAllocations = plan.getReservations(null, interval, ""); - Assert.assertTrue(rAllocations.size() == 0); + Assertions.assertTrue(rAllocations.size() == 0); } @Test @@ -687,17 +690,17 @@ public void testGetReservationsAtTime() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } Set rAllocations = plan.getReservationsAtTime(rAllocation.getStartTime()); - Assert.assertTrue(rAllocations.size() == 1); - Assert.assertTrue(rAllocation + Assertions.assertTrue(rAllocations.size() == 1); + Assertions.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); } @@ -894,19 +897,19 @@ public void testGetReservationsWithNoInput() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assert.assertNull(plan.getReservationById(reservationID)); + Assertions.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } // Verify that getReservations defaults to getting all reservations if no // reservationID, time interval, and user is provided, Set rAllocations = plan.getReservations(null, null, ""); - Assert.assertTrue(rAllocations.size() == 1); - Assert.assertTrue(rAllocation + Assertions.assertTrue(rAllocations.size() == 1); + Assertions.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); } @@ -919,7 +922,7 @@ public void testGetReservationsWithNoReservation() { ReservationInterval interval = new ReservationInterval(0, Long.MAX_VALUE); Set rAllocations = plan.getReservations(null, interval, ""); - Assert.assertTrue(rAllocations.size() == 0); + Assertions.assertTrue(rAllocations.size() == 0); } private void testPositiveGetRecurringReservationsHelper(long reservationStart, @@ -971,20 +974,20 @@ private ReservationId submitReservation(Plan plan, rAllocation.setPeriodicity(period); - Assert.assertNull(plan.getReservationById(reservation)); + Assertions.assertNull(plan.getReservationById(reservation)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } return reservation; } private void doAssertions(Plan plan, ReservationAllocation rAllocation) { ReservationId reservationID = rAllocation.getReservationId(); - Assert.assertNotNull(plan.getReservationById(reservationID)); + Assertions.assertNotNull(plan.getReservationById(reservationID)); assertEquals(rAllocation, plan.getReservationById(reservationID)); - Assert.assertTrue(((InMemoryPlan) plan).getAllReservations().size() == 1); + Assertions.assertTrue(((InMemoryPlan) plan).getAllReservations().size() == 1); if (rAllocation.getPeriodicity() <= 0) { assertEquals(rAllocation.getEndTime(), plan.getLastEndTime()); } @@ -993,7 +996,7 @@ private void doAssertions(Plan plan, ReservationAllocation rAllocation) { assertEquals(maxAlloc, plan.getMaximumAllocation()); assertEquals(resCalc, plan.getResourceCalculator()); assertEquals(planName, plan.getQueueName()); - Assert.assertTrue(plan.getMoveOnExpiry()); + Assertions.assertTrue(plan.getMoveOnExpiry()); } private ReservationDefinition createSimpleReservationDefinition(long arrival, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryReservationAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryReservationAllocation.java index 9fd51134ca300..d3e4b62ba74bf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryReservationAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryReservationAllocation.java @@ -27,10 +27,10 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -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; public class TestInMemoryReservationAllocation { @@ -41,13 +41,13 @@ public class TestInMemoryReservationAllocation { private Random rand = new Random(); - @Before + @BeforeEach public void setUp() { resCalc = new DefaultResourceCalculator(); minAlloc = Resource.newInstance(1, 1); } - @After + @AfterEach public void tearDown() { user = null; planName = null; @@ -71,9 +71,9 @@ public void testBlocks() { new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); - Assert.assertFalse(rAllocation.containsGangs()); + Assertions.assertFalse(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), + Assertions.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rAllocation.getResourcesAtTime(start + i)); } } @@ -94,9 +94,9 @@ public void testSteps() { new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); - Assert.assertFalse(rAllocation.containsGangs()); + Assertions.assertFalse(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals( + Assertions.assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rAllocation.getResourcesAtTime(start + i)); } @@ -118,9 +118,9 @@ public void testSkyline() { new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); - Assert.assertFalse(rAllocation.containsGangs()); + Assertions.assertFalse(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals( + Assertions.assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rAllocation.getResourcesAtTime(start + i)); } @@ -143,7 +143,7 @@ public void testZeroAlloaction() { start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, (int) start, alloc); - Assert.assertFalse(rAllocation.containsGangs()); + Assertions.assertFalse(rAllocation.containsGangs()); } @Test @@ -164,9 +164,9 @@ public void testGangAlloaction() { start, start + alloc.length + 1, allocations, resCalc, minAlloc, isGang); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); - Assert.assertTrue(rAllocation.containsGangs()); + Assertions.assertTrue(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), + Assertions.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rAllocation.getResourcesAtTime(start + i)); } } @@ -175,13 +175,13 @@ private void doAssertions(ReservationAllocation rAllocation, ReservationId reservationID, ReservationDefinition rDef, Map allocations, int start, int[] alloc) { - Assert.assertEquals(reservationID, rAllocation.getReservationId()); - Assert.assertEquals(rDef, rAllocation.getReservationDefinition()); - Assert.assertEquals(allocations, rAllocation.getAllocationRequests()); - Assert.assertEquals(user, rAllocation.getUser()); - Assert.assertEquals(planName, rAllocation.getPlanName()); - Assert.assertEquals(start, rAllocation.getStartTime()); - Assert.assertEquals(start + alloc.length + 1, rAllocation.getEndTime()); + Assertions.assertEquals(reservationID, rAllocation.getReservationId()); + Assertions.assertEquals(rDef, rAllocation.getReservationDefinition()); + Assertions.assertEquals(allocations, rAllocation.getAllocationRequests()); + Assertions.assertEquals(user, rAllocation.getUser()); + Assertions.assertEquals(planName, rAllocation.getPlanName()); + Assertions.assertEquals(start, rAllocation.getStartTime()); + Assertions.assertEquals(start + alloc.length + 1, rAllocation.getEndTime()); } private Map generateAllocation( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestNoOverCommitPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestNoOverCommitPolicy.java index accdf24a02a1c..585c375166925 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestNoOverCommitPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestNoOverCommitPolicy.java @@ -25,7 +25,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException; import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.ResourceOverCommitException; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestPeriodicRLESparseResourceAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestPeriodicRLESparseResourceAllocation.java index 457e2eede1dc5..0f06a25615610 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestPeriodicRLESparseResourceAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestPeriodicRLESparseResourceAllocation.java @@ -20,8 +20,8 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,13 +43,13 @@ public void testPeriodicCapacity() { PeriodicRLESparseResourceAllocation periodicVector = new PeriodicRLESparseResourceAllocation(rleSparseVector, 20L); LOG.info(periodicVector.toString()); - Assert.assertEquals(Resource.newInstance(5, 5), + Assertions.assertEquals(Resource.newInstance(5, 5), periodicVector.getCapacityAtTime(10L)); - Assert.assertEquals(Resource.newInstance(10, 10), + Assertions.assertEquals(Resource.newInstance(10, 10), periodicVector.getCapacityAtTime(20L)); - Assert.assertEquals(Resource.newInstance(7, 7), + Assertions.assertEquals(Resource.newInstance(7, 7), periodicVector.getCapacityAtTime(27L)); - Assert.assertEquals(Resource.newInstance(5, 5), + Assertions.assertEquals(Resource.newInstance(5, 5), periodicVector.getCapacityAtTime(50L)); } @@ -62,15 +62,15 @@ public void testMaxPeriodicCapacity() { PeriodicRLESparseResourceAllocation periodicVector = new PeriodicRLESparseResourceAllocation(rleSparseVector, 8L); LOG.info(periodicVector.toString()); - Assert.assertEquals(periodicVector.getMaximumPeriodicCapacity(0, 1), + Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(0, 1), Resource.newInstance(10, 10)); - Assert.assertEquals(periodicVector.getMaximumPeriodicCapacity(8, 2), + Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(8, 2), Resource.newInstance(7, 7)); - Assert.assertEquals(periodicVector.getMaximumPeriodicCapacity(16, 3), + Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(16, 3), Resource.newInstance(10, 10)); - Assert.assertEquals(periodicVector.getMaximumPeriodicCapacity(17, 4), + Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(17, 4), Resource.newInstance(5, 5)); - Assert.assertEquals(periodicVector.getMaximumPeriodicCapacity(32, 5), + Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(32, 5), Resource.newInstance(4, 4)); } @@ -93,23 +93,23 @@ public void testMixPeriodicAndNonPeriodic() throws PlanningException { Resource.newInstance(100 * 1024, 100), periodic, nonPeriodic, RLESparseResourceAllocation.RLEOperator.add, 2, 25); - Assert.assertEquals(Resource.newInstance(5, 5), + Assertions.assertEquals(Resource.newInstance(5, 5), merged.getCapacityAtTime(2L)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(3L)); - Assert.assertEquals(Resource.newInstance(2, 2), + Assertions.assertEquals(Resource.newInstance(2, 2), merged.getCapacityAtTime(11L)); - Assert.assertEquals(Resource.newInstance(15, 15), + Assertions.assertEquals(Resource.newInstance(15, 15), merged.getCapacityAtTime(12L)); - Assert.assertEquals(Resource.newInstance(10, 10), + Assertions.assertEquals(Resource.newInstance(10, 10), merged.getCapacityAtTime(13L)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(14L)); - Assert.assertEquals(Resource.newInstance(2, 2), + Assertions.assertEquals(Resource.newInstance(2, 2), merged.getCapacityAtTime(21L)); - Assert.assertEquals(Resource.newInstance(5, 5), + Assertions.assertEquals(Resource.newInstance(5, 5), merged.getCapacityAtTime(22L)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(23L)); } @@ -123,15 +123,15 @@ public void testSetCapacityInInterval() { new PeriodicRLESparseResourceAllocation(rleSparseVector, 10L); ReservationInterval interval = new ReservationInterval(5L, 10L); periodicVector.addInterval(interval, Resource.newInstance(8, 8)); - Assert.assertEquals(Resource.newInstance(8, 8), + Assertions.assertEquals(Resource.newInstance(8, 8), periodicVector.getCapacityAtTime(5L)); - Assert.assertEquals(Resource.newInstance(8, 8), + Assertions.assertEquals(Resource.newInstance(8, 8), periodicVector.getCapacityAtTime(9L)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), periodicVector.getCapacityAtTime(10L)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), periodicVector.getCapacityAtTime(0L)); - // Assert.assertFalse(periodicVector.addInterval( + // Assertions.assertFalse(periodicVector.addInterval( // new ReservationInterval(7L, 12L), Resource.newInstance(8, 8))); } @@ -143,29 +143,29 @@ public void testRemoveInterval() { PeriodicRLESparseResourceAllocation periodicVector = new PeriodicRLESparseResourceAllocation(rleSparseVector, 10L); ReservationInterval interval = new ReservationInterval(3L, 7L); - Assert.assertTrue( + Assertions.assertTrue( periodicVector.removeInterval(interval, Resource.newInstance(3, 3))); - Assert.assertEquals(Resource.newInstance(2, 2), + Assertions.assertEquals(Resource.newInstance(2, 2), periodicVector.getCapacityAtTime(1L)); - Assert.assertEquals(Resource.newInstance(2, 2), + Assertions.assertEquals(Resource.newInstance(2, 2), periodicVector.getCapacityAtTime(2L)); - Assert.assertEquals(Resource.newInstance(2, 2), + Assertions.assertEquals(Resource.newInstance(2, 2), periodicVector.getCapacityAtTime(3L)); - Assert.assertEquals(Resource.newInstance(2, 2), + Assertions.assertEquals(Resource.newInstance(2, 2), periodicVector.getCapacityAtTime(4L)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), periodicVector.getCapacityAtTime(5L)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), periodicVector.getCapacityAtTime(6L)); - Assert.assertEquals(Resource.newInstance(4, 4), + Assertions.assertEquals(Resource.newInstance(4, 4), periodicVector.getCapacityAtTime(7L)); // invalid interval - Assert.assertFalse(periodicVector.removeInterval( + Assertions.assertFalse(periodicVector.removeInterval( new ReservationInterval(7L, 12L), Resource.newInstance(1, 1))); // invalid capacity - Assert.assertFalse(periodicVector.removeInterval( + Assertions.assertFalse(periodicVector.removeInterval( new ReservationInterval(2L, 4L), Resource.newInstance(8, 8))); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java index 0027cebcfc676..b810d27014449 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java @@ -17,9 +17,9 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import java.util.HashMap; import java.util.Map; @@ -34,9 +34,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -322,26 +322,26 @@ public void testBlocks() { rleSparseVector.addInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); - Assert.assertFalse(rleSparseVector.isEmpty()); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertFalse(rleSparseVector.isEmpty()); + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), + Assertions.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rleSparseVector.getCapacityAtTime(start + i)); } - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i)); } - Assert.assertTrue(rleSparseVector.isEmpty()); + Assertions.assertTrue(rleSparseVector.isEmpty()); } @Test @@ -374,28 +374,28 @@ public void testPartialRemoval() { // Current bug prevents this to pass. The RLESparseResourceAllocation // does not handle removal of "partial" // allocations correctly. - Assert.assertEquals(102400, + Assertions.assertEquals(102400, rleSparseVector.getCapacityAtTime(10).getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, rleSparseVector.getCapacityAtTime(13).getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, rleSparseVector.getCapacityAtTime(19).getMemorySize()); - Assert.assertEquals(102400, + Assertions.assertEquals(102400, rleSparseVector.getCapacityAtTime(21).getMemorySize()); - Assert.assertEquals(2 * 102400, + Assertions.assertEquals(2 * 102400, rleSparseVector.getCapacityAtTime(26).getMemorySize()); ReservationInterval riRemove2 = new ReservationInterval(9, 13); rleSparseVector.removeInterval(riRemove2, rr); LOG.info(rleSparseVector.toString()); - Assert.assertEquals(0, + Assertions.assertEquals(0, rleSparseVector.getCapacityAtTime(11).getMemorySize()); - Assert.assertEquals(-102400, + Assertions.assertEquals(-102400, rleSparseVector.getCapacityAtTime(9).getMemorySize()); - Assert.assertEquals(0, + Assertions.assertEquals(0, rleSparseVector.getCapacityAtTime(13).getMemorySize()); - Assert.assertEquals(102400, + Assertions.assertEquals(102400, rleSparseVector.getCapacityAtTime(20).getMemorySize()); } @@ -414,27 +414,27 @@ public void testSteps() { rleSparseVector.addInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); - Assert.assertFalse(rleSparseVector.isEmpty()); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertFalse(rleSparseVector.isEmpty()); + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals( + Assertions.assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rleSparseVector.getCapacityAtTime(start + i)); } - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i)); } - Assert.assertTrue(rleSparseVector.isEmpty()); + Assertions.assertTrue(rleSparseVector.isEmpty()); } @Test @@ -451,27 +451,27 @@ public void testSkyline() { rleSparseVector.addInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); - Assert.assertFalse(rleSparseVector.isEmpty()); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertFalse(rleSparseVector.isEmpty()); + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals( + Assertions.assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rleSparseVector.getCapacityAtTime(start + i)); } - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); for (int i = 0; i < alloc.length; i++) { - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i)); } - Assert.assertTrue(rleSparseVector.isEmpty()); + Assertions.assertTrue(rleSparseVector.isEmpty()); } @Test @@ -482,9 +482,9 @@ public void testZeroAllocation() { rleSparseVector.addInterval(new ReservationInterval(0, Long.MAX_VALUE), Resource.newInstance(0, 0)); LOG.info(rleSparseVector.toString()); - Assert.assertEquals(Resource.newInstance(0, 0), + Assertions.assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(new Random().nextLong())); - Assert.assertTrue(rleSparseVector.isEmpty()); + Assertions.assertTrue(rleSparseVector.isEmpty()); } @Test @@ -496,7 +496,7 @@ public void testToIntervalMap() { // Check empty mapAllocations = rleSparseVector.toIntervalMap(); - Assert.assertTrue(mapAllocations.isEmpty()); + Assertions.assertTrue(mapAllocations.isEmpty()); // Check full int[] alloc = { 0, 5, 10, 10, 5, 0, 5, 0 }; @@ -507,28 +507,28 @@ public void testToIntervalMap() { rleSparseVector.addInterval(ip.getKey(), ip.getValue()); } mapAllocations = rleSparseVector.toIntervalMap(); - Assert.assertTrue(mapAllocations.size() == 5); + Assertions.assertTrue(mapAllocations.size() == 5); for (Entry entry : mapAllocations .entrySet()) { ReservationInterval interval = entry.getKey(); Resource resource = entry.getValue(); if (interval.getStartTime() == 101L) { - Assert.assertTrue(interval.getEndTime() == 102L); - Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); + Assertions.assertTrue(interval.getEndTime() == 102L); + Assertions.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); } else if (interval.getStartTime() == 102L) { - Assert.assertTrue(interval.getEndTime() == 104L); - Assert.assertEquals(resource, Resource.newInstance(10 * 1024, 10)); + Assertions.assertTrue(interval.getEndTime() == 104L); + Assertions.assertEquals(resource, Resource.newInstance(10 * 1024, 10)); } else if (interval.getStartTime() == 104L) { - Assert.assertTrue(interval.getEndTime() == 105L); - Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); + Assertions.assertTrue(interval.getEndTime() == 105L); + Assertions.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); } else if (interval.getStartTime() == 105L) { - Assert.assertTrue(interval.getEndTime() == 106L); - Assert.assertEquals(resource, Resource.newInstance(0 * 1024, 0)); + Assertions.assertTrue(interval.getEndTime() == 106L); + Assertions.assertEquals(resource, Resource.newInstance(0 * 1024, 0)); } else if (interval.getStartTime() == 106L) { - Assert.assertTrue(interval.getEndTime() == 107L); - Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); + Assertions.assertTrue(interval.getEndTime() == 107L); + Assertions.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); } else { - Assert.fail(); + Assertions.fail(); } } } @@ -540,21 +540,21 @@ public void testMaxPeriodicCapacity() { RLESparseResourceAllocation rleSparseVector = ReservationSystemTestUtil .generateRLESparseResourceAllocation(alloc, timeSteps); LOG.info(rleSparseVector.toString()); - Assert.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 1), + Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 1), Resource.newInstance(10, 10)); - Assert.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 2), + Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 2), Resource.newInstance(7, 7)); - Assert.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 3), + Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 3), Resource.newInstance(10, 10)); - Assert.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 4), + Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 4), Resource.newInstance(3, 3)); - Assert.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 5), + Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 5), Resource.newInstance(4, 4)); - Assert.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 5), + Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 5), Resource.newInstance(4, 4)); - Assert.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(7, 5), + Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(7, 5), Resource.newInstance(8, 8)); - Assert.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(10, 3), + Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(10, 3), Resource.newInstance(0, 0)); } @@ -565,11 +565,11 @@ public void testGetMinimumCapacityInInterval() { RLESparseResourceAllocation rleSparseVector = ReservationSystemTestUtil .generateRLESparseResourceAllocation(alloc, timeSteps); LOG.info(rleSparseVector.toString()); - Assert.assertEquals(rleSparseVector.getMinimumCapacityInInterval( + Assertions.assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(1L, 3L)), Resource.newInstance(5, 5)); - Assert.assertEquals(rleSparseVector.getMinimumCapacityInInterval( + Assertions.assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(2L, 5L)), Resource.newInstance(3, 3)); - Assert.assertEquals(rleSparseVector.getMinimumCapacityInInterval( + Assertions.assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(1L, 7L)), Resource.newInstance(0, 0)); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java index fd1da210ae591..75e3510e63e29 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java @@ -49,10 +49,10 @@ import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -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; public class TestReservationInputValidator { @@ -68,7 +68,7 @@ public class TestReservationInputValidator { private ReservationInputValidator rrValidator; - @Before + @BeforeEach public void setUp() { clock = mock(Clock.class); plan = mock(Plan.class); @@ -87,7 +87,7 @@ public void setUp() { when(rSystem.getPlan(PLAN_NAME)).thenReturn(plan); } - @After + @AfterEach public void tearDown() { rrValidator = null; clock = null; @@ -104,9 +104,9 @@ public void testSubmitReservationNormal() { rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); } catch (YarnException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan); + Assertions.assertNotNull(plan); } @Test @@ -118,11 +118,11 @@ public void testSubmitReservationDoesNotExist() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertEquals("The queue is not specified. Please try again with a " + Assertions.assertEquals("The queue is not specified. Please try again with a " + "valid reservable queue.", message); LOG.info(message); } @@ -138,11 +138,11 @@ public void testSubmitReservationInvalidPlan() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message .endsWith(" is not managed by reservation system. Please try again with a valid reservable queue.")); LOG.info(message); @@ -159,11 +159,11 @@ public void testSubmitReservationNoDefinition() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertEquals("Missing reservation definition. Please try again by " + Assertions.assertEquals("Missing reservation definition. Please try again by " + "specifying a reservation definition.", message); LOG.info(message); } @@ -178,11 +178,11 @@ public void testSubmitReservationInvalidDeadline() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("The specified deadline: 0 is the past")); LOG.info(message); } @@ -197,11 +197,11 @@ public void testSubmitReservationInvalidRR() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } @@ -216,11 +216,11 @@ public void testSubmitReservationEmptyRR() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } @@ -235,12 +235,12 @@ public void testSubmitReservationInvalidDuration() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message.startsWith("The time difference")); - Assert + Assertions.assertTrue(message.startsWith("The time difference")); + Assertions .assertTrue(message .contains("must be greater or equal to the minimum resource duration")); LOG.info(message); @@ -258,13 +258,13 @@ public void testSubmitReservationExceedsGangSize() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message.startsWith( + Assertions.assertTrue(message.startsWith( "The size of the largest gang in the reservation definition")); - Assert.assertTrue(message.contains( + Assertions.assertTrue(message.contains( "exceed the capacity available ")); LOG.info(message); } @@ -280,9 +280,9 @@ public void testSubmitReservationValidRecurrenceExpression() { rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); } catch (YarnException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan); + Assertions.assertNotNull(plan); } @Test @@ -294,11 +294,11 @@ public void testSubmitReservationNegativeRecurrenceExpression() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("Negative Period : ")); LOG.info(message); } @@ -315,11 +315,11 @@ public void testSubmitReservationMaxPeriodIndivisibleByRecurrenceExp() { try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message.startsWith("The maximum periodicity:")); + Assertions.assertTrue(message.startsWith("The maximum periodicity:")); LOG.info(message); } } @@ -334,11 +334,11 @@ public void testSubmitReservationInvalidRecurrenceExpression() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("Invalid period ")); LOG.info(message); } @@ -351,11 +351,11 @@ public void testSubmitReservationInvalidRecurrenceExpression() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("Duration of the requested reservation:")); LOG.info(message); } @@ -369,9 +369,9 @@ public void testUpdateReservationNormal() { try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); } catch (YarnException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan); + Assertions.assertNotNull(plan); } @Test @@ -380,11 +380,11 @@ public void testUpdateReservationNoID() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); LOG.info(message); @@ -400,11 +400,11 @@ public void testUpdateReservationDoesnotExist() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message.equals(MessageFormat .format( "The specified reservation with ID: {0} is unknown. Please try again with a valid reservation.", @@ -421,11 +421,11 @@ public void testUpdateReservationInvalidPlan() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message .endsWith(" is not associated with any valid plan. Please try again with a valid reservation.")); LOG.info(message); @@ -439,11 +439,11 @@ public void testUpdateReservationNoDefinition() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message .startsWith("Missing reservation definition. Please try again by specifying a reservation definition.")); LOG.info(message); @@ -457,11 +457,11 @@ public void testUpdateReservationInvalidDeadline() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("The specified deadline: 0 is the past")); LOG.info(message); } @@ -474,11 +474,11 @@ public void testUpdateReservationInvalidRR() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } @@ -491,11 +491,11 @@ public void testUpdateReservationEmptyRR() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } @@ -508,11 +508,11 @@ public void testUpdateReservationInvalidDuration() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message .contains("must be greater or equal to the minimum resource duration")); LOG.info(message); @@ -528,13 +528,13 @@ public void testUpdateReservationExceedsGangSize() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message.startsWith( + Assertions.assertTrue(message.startsWith( "The size of the largest gang in the reservation definition")); - Assert.assertTrue(message.contains( + Assertions.assertTrue(message.contains( "exceed the capacity available ")); LOG.info(message); } @@ -549,9 +549,9 @@ public void testUpdateReservationValidRecurrenceExpression() { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); } catch (YarnException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan); + Assertions.assertNotNull(plan); } @Test @@ -562,11 +562,11 @@ public void testUpdateReservationNegativeRecurrenceExpression() { try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("Negative Period : ")); LOG.info(message); } @@ -581,11 +581,11 @@ public void testUpdateReservationInvalidRecurrenceExpression() { try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("Invalid period ")); LOG.info(message); } @@ -597,11 +597,11 @@ public void testUpdateReservationInvalidRecurrenceExpression() { try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message + Assertions.assertTrue(message .startsWith("Duration of the requested reservation:")); LOG.info(message); } @@ -619,9 +619,9 @@ public void testDeleteReservationNormal() { try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); } catch (YarnException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan); + Assertions.assertNotNull(plan); } @Test @@ -630,11 +630,11 @@ public void testDeleteReservationNoID() { Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); LOG.info(message); @@ -650,11 +650,11 @@ public void testDeleteReservationDoesnotExist() { Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message.equals(MessageFormat .format( "The specified reservation with ID: {0} is unknown. Please try again with a valid reservation.", @@ -673,11 +673,11 @@ public void testDeleteReservationInvalidPlan() { Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert + Assertions .assertTrue(message .endsWith(" is not associated with any valid plan. Please try again with a valid reservation.")); LOG.info(message); @@ -696,9 +696,9 @@ public void testListReservationsNormal() { try { plan = rrValidator.validateReservationListRequest(rSystem, request); } catch (YarnException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan); + Assertions.assertNotNull(plan); } @Test @@ -715,9 +715,9 @@ public void testListReservationsInvalidTimeIntervalDefaults() { try { plan = rrValidator.validateReservationListRequest(rSystem, request); } catch (YarnException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } - Assert.assertNotNull(plan); + Assertions.assertNotNull(plan); } @Test @@ -731,11 +731,11 @@ public void testListReservationsInvalidTimeInterval() { Plan plan = null; try { plan = rrValidator.validateReservationListRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message.equals("The specified end time must be " + + Assertions.assertTrue(message.equals("The specified end time must be " + "greater than the specified start time.")); LOG.info(message); } @@ -748,11 +748,11 @@ public void testListReservationsEmptyQueue() { Plan plan = null; try { plan = rrValidator.validateReservationListRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message.equals( + Assertions.assertTrue(message.equals( "The queue is not specified. Please try again with a valid " + "reservable queue.")); LOG.info(message); @@ -768,11 +768,11 @@ public void testListReservationsNullPlan() { Plan plan = null; try { plan = rrValidator.validateReservationListRequest(rSystem, request); - Assert.fail(); + Assertions.fail(); } catch (YarnException e) { - Assert.assertNull(plan); + Assertions.assertNull(plan); String message = e.getMessage(); - Assert.assertTrue(message.equals( + Assertions.assertTrue(message.equals( "The specified queue: " + ReservationSystemTestUtil.reservationQ + " is not managed by reservation system." + " Please try again with a valid reservable 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/reservation/TestReservationSystemUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java index a092e0d527a30..0043d2c8ac833 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java @@ -26,8 +26,8 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.Date; @@ -53,7 +53,7 @@ public void testConvertAllocationsToReservationInfo() { assertThat(infoList).hasSize(1); assertThat(infoList.get(0).getReservationId().toString()).isEqualTo( id.toString()); - Assert.assertFalse(infoList.get(0).getResourceAllocationRequests() + Assertions.assertFalse(infoList.get(0).getResourceAllocationRequests() .isEmpty()); } @@ -71,10 +71,10 @@ public void testConvertAllocationsToReservationInfoNoAllocations() { .convertAllocationsToReservationInfo( Collections.singleton(allocation), false); - Assert.assertEquals(infoList.size(), 1); - Assert.assertEquals(infoList.get(0).getReservationId().toString(), + Assertions.assertEquals(infoList.size(), 1); + Assertions.assertEquals(infoList.get(0).getReservationId().toString(), id.toString()); - Assert.assertTrue(infoList.get(0).getResourceAllocationRequests() + Assertions.assertTrue(infoList.get(0).getResourceAllocationRequests() .isEmpty()); } @@ -92,10 +92,10 @@ public void testConvertAllocationsToReservationInfoEmptyAllocations() { .convertAllocationsToReservationInfo( Collections.singleton(allocation), false); - Assert.assertEquals(infoList.size(), 1); - Assert.assertEquals(infoList.get(0).getReservationId().toString(), + Assertions.assertEquals(infoList.size(), 1); + Assertions.assertEquals(infoList.get(0).getReservationId().toString(), id.toString()); - Assert.assertTrue(infoList.get(0).getResourceAllocationRequests() + Assertions.assertTrue(infoList.get(0).getResourceAllocationRequests() .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/reservation/TestSchedulerPlanFollowerBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestSchedulerPlanFollowerBase.java index f61d427f07dce..5f737cf471d55 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestSchedulerPlanFollowerBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestSchedulerPlanFollowerBase.java @@ -18,9 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import org.apache.hadoop.security.AccessControlException; @@ -43,7 +43,7 @@ import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; public abstract class TestSchedulerPlanFollowerBase { final static int GB = 1024; @@ -73,23 +73,23 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( 0, 0 + f1.length + 1, f1.length); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r1, rDef, "u3", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r1, rDef, "u3", "dedicated", 0, 0 + f1.length, ReservationSystemTestUtil - .generateAllocation(0L, 1L, f1), res, minAlloc), false)); + .generateAllocation(0L, 1L, f1), res, minAlloc), false), plan.toString()); ReservationId r2 = ReservationId.newInstance(ts, 2); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r2, rDef, "u3", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r2, rDef, "u3", "dedicated", 3, 3 + f1.length, ReservationSystemTestUtil - .generateAllocation(3L, 1L, f1), res, minAlloc), false)); + .generateAllocation(3L, 1L, f1), res, minAlloc), false), plan.toString()); ReservationId r3 = ReservationId.newInstance(ts, 3); int[] f2 = { 0, 10, 20, 10, 0 }; - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r3, rDef, "u4", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r3, rDef, "u4", "dedicated", 10, 10 + f2.length, ReservationSystemTestUtil - .generateAllocation(10L, 1L, f2), res, minAlloc), false)); + .generateAllocation(10L, 1L, f2), res, minAlloc), false), plan.toString()); // default reseration queue should exist before run of PlanFollower AND have @@ -124,10 +124,10 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, // initial default reservation queue should have no apps after first run Queue defQ = getDefaultQueue(); - Assert.assertEquals(0, getNumberOfApplications(defQ)); + Assertions.assertEquals(0, getNumberOfApplications(defQ)); assertReservationQueueExists(r1, 0.1, 0.1); - Assert.assertEquals(1, getNumberOfApplications(q)); + Assertions.assertEquals(1, getNumberOfApplications(q)); assertReservationQueueDoesNotExist(r2); assertReservationQueueDoesNotExist(r3); @@ -135,9 +135,9 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, when(mClock.getTime()).thenReturn(3L); planFollower.run(); - Assert.assertEquals(0, getNumberOfApplications(defQ)); + Assertions.assertEquals(0, getNumberOfApplications(defQ)); assertReservationQueueExists(r1, 0.1, 0.1); - Assert.assertEquals(1, getNumberOfApplications(q)); + Assertions.assertEquals(1, getNumberOfApplications(q)); assertReservationQueueExists(r2, 0.1, 0.1); assertReservationQueueDoesNotExist(r3); @@ -147,11 +147,11 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, q = getReservationQueue(r1.toString()); if (isMove) { // app should have been moved to default reservation queue - Assert.assertEquals(1, getNumberOfApplications(defQ)); + Assertions.assertEquals(1, getNumberOfApplications(defQ)); assertNull(q); } else { // app should be killed - Assert.assertEquals(0, getNumberOfApplications(defQ)); + Assertions.assertEquals(0, getNumberOfApplications(defQ)); assertNotNull(q); AppAttemptRemovedSchedulerEvent appAttemptRemovedEvent = new AppAttemptRemovedSchedulerEvent(appAttemptId_0, @@ -166,10 +166,10 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, if (isMove) { // app should have been moved to default reservation queue - Assert.assertEquals(1, getNumberOfApplications(defQ)); + Assertions.assertEquals(1, getNumberOfApplications(defQ)); } else { // app should be killed - Assert.assertEquals(0, getNumberOfApplications(defQ)); + Assertions.assertEquals(0, getNumberOfApplications(defQ)); } assertReservationQueueDoesNotExist(r1); assertReservationQueueDoesNotExist(r2); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java index e26f9458682f6..014f199df8e48 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java @@ -20,9 +20,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import java.util.ArrayList; @@ -56,8 +56,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.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.slf4j.Logger; @@ -126,16 +126,16 @@ public void testSingleReservationAccept() throws PlanningException { agentRight.createReservation(reservationID, "u1", plan, rr1); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == numJobsInScenario + 1); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == numJobsInScenario + 1, "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue(alloc1.toString(), - check(alloc1, 10 * step, 20 * step, 10, 2048, 2)); + assertTrue( + check(alloc1, 10 * step, 20 * step, 10, 2048, 2), alloc1.toString()); System.out.println("--------AFTER AGENT----------"); System.out.println(plan.toString()); @@ -177,8 +177,8 @@ public void testOrderNoGapImpossible() throws PlanningException { } // CHECK: allocation was not accepted - assertTrue("Agent-based allocation should have failed", plan - .getAllReservations().size() == numJobsInScenario); + assertTrue(plan + .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); } @@ -217,8 +217,8 @@ public void testOrderNoGapImpossible2() throws PlanningException { } // CHECK: allocation was not accepted - assertTrue("Agent-based allocation should have failed", plan - .getAllReservations().size() == numJobsInScenario); + assertTrue(plan + .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); } @@ -257,8 +257,8 @@ public void testOrderImpossible() throws PlanningException { } // CHECK: allocation was not accepted - assertTrue("Agent-based allocation should have failed", plan - .getAllReservations().size() == numJobsInScenario); + assertTrue(plan + .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); } @@ -297,8 +297,8 @@ public void testAnyImpossible() throws PlanningException { } // CHECK: allocation was not accepted - assertTrue("Agent-based allocation should have failed", plan - .getAllReservations().size() == numJobsInScenario); + assertTrue(plan + .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); } @@ -332,16 +332,16 @@ public void testAnyAccept() throws PlanningException { agentRight.createReservation(reservationID, "u1", plan, rr1); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == numJobsInScenario + 1); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == numJobsInScenario + 1, "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue(alloc1.toString(), - check(alloc1, 14 * step, 15 * step, 20, 1024, 1)); + assertTrue( + check(alloc1, 14 * step, 15 * step, 20, 1024, 1), alloc1.toString()); } @@ -375,18 +375,18 @@ public void testAllAccept() throws PlanningException { agentRight.createReservation(reservationID, "u1", plan, rr1); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == numJobsInScenario + 1); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == numJobsInScenario + 1, "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue(alloc1.toString(), - check(alloc1, 10 * step, 11 * step, 20, 1024, 1)); - assertTrue(alloc1.toString(), - check(alloc1, 14 * step, 15 * step, 20, 1024, 1)); + assertTrue( + check(alloc1, 10 * step, 11 * step, 20, 1024, 1), alloc1.toString()); + assertTrue( + check(alloc1, 14 * step, 15 * step, 20, 1024, 1), alloc1.toString()); } @@ -425,8 +425,8 @@ public void testAllImpossible() throws PlanningException { } // CHECK: allocation was not accepted - assertTrue("Agent-based allocation should have failed", plan - .getAllReservations().size() == numJobsInScenario); + assertTrue(plan + .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); } @@ -470,16 +470,16 @@ public void testUpdate() throws PlanningException { agentRight.updateReservation(flexReservationID, "uFlex", plan, rrFlex); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", flexReservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 1); + assertTrue(flexReservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 1, "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(flexReservationID); // Verify allocation - assertTrue(alloc1.toString(), - check(alloc1, 10 * step, 14 * step, 50, 1024, 1)); + assertTrue( + check(alloc1, 10 * step, 14 * step, 50, 1024, 1), alloc1.toString()); } @@ -509,8 +509,8 @@ public void testImpossibleDuration() throws PlanningException { } // CHECK: allocation was not accepted - assertTrue("Agent-based allocation should have failed", plan - .getAllReservations().size() == 0); + assertTrue(plan + .getAllReservations().size() == 0, "Agent-based allocation should have failed"); } @@ -537,20 +537,20 @@ public void testLoadedDurationIntervals() throws PlanningException { agentRight.createReservation(reservationID, "u1", plan, rr1); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == numJobsInScenario + 1); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == numJobsInScenario + 1, "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue(alloc1.toString(), - check(alloc1, 10 * step, 11 * step, 20, 1024, 1)); - assertTrue(alloc1.toString(), - check(alloc1, 11 * step, 12 * step, 20, 1024, 1)); - assertTrue(alloc1.toString(), - check(alloc1, 12 * step, 13 * step, 40, 1024, 1)); + assertTrue( + check(alloc1, 10 * step, 11 * step, 20, 1024, 1), alloc1.toString()); + assertTrue( + check(alloc1, 11 * step, 12 * step, 20, 1024, 1), alloc1.toString()); + assertTrue( + check(alloc1, 12 * step, 13 * step, 40, 1024, 1), alloc1.toString()); } @Test @@ -608,10 +608,10 @@ public void testCostFunction() throws PlanningException { // Get reservation ReservationAllocation alloc3 = plan.getReservationById(reservationID3); - assertTrue(alloc3.toString(), - check(alloc3, 10 * step, 11 * step, 0, 1024, 1)); - assertTrue(alloc3.toString(), - check(alloc3, 11 * step, 12 * step, 1, 1024, 1)); + assertTrue( + check(alloc3, 10 * step, 11 * step, 0, 1024, 1), alloc3.toString()); + assertTrue( + check(alloc3, 11 * step, 12 * step, 1, 1024, 1), alloc3.toString()); } @@ -734,8 +734,8 @@ public void testFromCluster() throws PlanningException { } // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == list.size()); + assertTrue(plan.getAllReservations() + .size() == list.size(), "Agent-based allocation failed"); } @@ -767,16 +767,16 @@ public void testSingleReservationAcceptAllocateLeft() agentLeft.createReservation(reservationID, "u1", plan, rr1); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 1); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 1, "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue(alloc1.toString(), - check(alloc1, 10 * step, 30 * step, 20, 1024, 1)); + assertTrue( + check(alloc1, 10 * step, 30 * step, 20, 1024, 1), alloc1.toString()); } @@ -820,16 +820,16 @@ public void testLeftSucceedsRightFails() throws PlanningException { agentLeft.createReservation(reservationID1, "u1", plan, rr1); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", reservationID1 != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == numJobsInScenario + 1); + assertTrue(reservationID1 != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == numJobsInScenario + 1, "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(reservationID1); // Verify allocation - assertTrue(alloc1.toString(), - check(alloc1, 7 * step, 11 * step, 20, 1024, 1)); + assertTrue( + check(alloc1, 7 * step, 11 * step, 20, 1024, 1), alloc1.toString()); // Add second reservation ReservationId reservationID2 = @@ -837,16 +837,16 @@ public void testLeftSucceedsRightFails() throws PlanningException { agentLeft.createReservation(reservationID2, "u2", plan, rr2); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", reservationID2 != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == numJobsInScenario + 2); + assertTrue(reservationID2 != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == numJobsInScenario + 2, "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc2 = plan.getReservationById(reservationID2); // Verify allocation - assertTrue(alloc2.toString(), - check(alloc2, 14 * step, 16 * step, 100, 1024, 1)); + assertTrue( + check(alloc2, 14 * step, 16 * step, 100, 1024, 1), alloc2.toString()); agentLeft.deleteReservation(reservationID1, "u1", plan); agentLeft.deleteReservation(reservationID2, "u2", plan); @@ -859,9 +859,9 @@ public void testLeftSucceedsRightFails() throws PlanningException { agentRight.createReservation(reservationID3, "u1", plan, rr1); // CHECK: allocation was accepted - assertTrue("Agent-based allocation failed", reservationID3 != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == numJobsInScenario + 1); + assertTrue(reservationID3 != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == numJobsInScenario + 1, "Agent-based allocation failed"); // Add 2nd reservation try { @@ -899,45 +899,45 @@ public void testValidateOrderNoGap() { curAlloc.clear(); curAlloc.put(new ReservationInterval(9 * step, 10 * step), Resource.newInstance(1024, 1)); - assertTrue("validateOrderNoFap() should have succeeded", - IterativePlanner.validateOrderNoGap(allocation, curAlloc, false)); + assertTrue( + IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), "validateOrderNoFap() should have succeeded"); // 2. allocateLeft = false, fail when curAlloc has a gap curAlloc.put(new ReservationInterval(7 * step, 8 * step), Resource.newInstance(1024, 1)); - assertFalse("validateOrderNoGap() failed to identify a gap in curAlloc", - IterativePlanner.validateOrderNoGap(allocation, curAlloc, false)); + assertFalse( + IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), "validateOrderNoGap() failed to identify a gap in curAlloc"); // 3. allocateLeft = false, fail when there is a gap between curAlloc and // allocations curAlloc.clear(); curAlloc.put(new ReservationInterval(8 * step, 9 * step), Resource.newInstance(1024, 1)); - assertFalse("validateOrderNoGap() failed to identify a gap between " - + "allocations and curAlloc", - IterativePlanner.validateOrderNoGap(allocation, curAlloc, false)); + assertFalse( + IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), "validateOrderNoGap() failed to identify a gap between " + + "allocations and curAlloc"); // 4. allocateLeft = true, succeed when there is no gap curAlloc.clear(); curAlloc.put(new ReservationInterval(13 * step, 14 * step), Resource.newInstance(1024, 1)); - assertTrue("validateOrderNoFap() should have succeeded", - IterativePlanner.validateOrderNoGap(allocation, curAlloc, true)); + assertTrue( + IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), "validateOrderNoFap() should have succeeded"); // 5. allocateLeft = true, fail when there is a gap between curAlloc and // allocations curAlloc.put(new ReservationInterval(15 * step, 16 * step), Resource.newInstance(1024, 1)); - assertFalse("validateOrderNoGap() failed to identify a gap in curAlloc", - IterativePlanner.validateOrderNoGap(allocation, curAlloc, true)); + assertFalse( + IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), "validateOrderNoGap() failed to identify a gap in curAlloc"); // 6. allocateLeft = true, fail when curAlloc has a gap curAlloc.clear(); curAlloc.put(new ReservationInterval(14 * step, 15 * step), Resource.newInstance(1024, 1)); - assertFalse("validateOrderNoGap() failed to identify a gap between " - + "allocations and curAlloc", - IterativePlanner.validateOrderNoGap(allocation, curAlloc, true)); + assertFalse( + IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), "validateOrderNoGap() failed to identify a gap between " + + "allocations and curAlloc"); } @@ -1067,7 +1067,7 @@ public void testGetDurationInterval() throws PlanningException { } - @Before + @BeforeEach public void setup() throws Exception { // Initialize random seed @@ -1165,12 +1165,12 @@ private void addFixedAllocation(long start, long step, int[] f) ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( start, start + f.length * step, f.length * step); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation( + assertTrue( + plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "user_fixed", "dedicated", start, start + f.length * step, ReservationSystemTestUtil.generateAllocation(start, step, f), res, - minAlloc), false)); + minAlloc), false), plan.toString()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java index 7c7b0a5fced27..a01e0e38d38b2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java @@ -17,11 +17,11 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning; -import static org.junit.Assert.assertFalse; -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.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.Mockito.mock; import java.io.IOException; @@ -55,8 +55,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.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.slf4j.Logger; @@ -97,7 +97,7 @@ public static Collection data() { }); } - @Before + @BeforeEach public void setup() throws Exception { long seed = rand.nextLong(); @@ -154,9 +154,9 @@ public void testSimple() throws PlanningException { .getNewReservationId(); agent.createReservation(reservationID, "u1", plan, rr); - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 3); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 3, "Agent-based allocation failed"); ReservationAllocation cs = plan.getReservationById(reservationID); @@ -168,16 +168,16 @@ public void testSimple() throws PlanningException { if(allocateLeft){ for (long i = 5 * step; i < 15 * step; i++) { assertTrue( - "Agent-based allocation unexpected", - Resources.equals(cs.getResourcesAtTime(i), - Resource.newInstance(2048 * 10, 2 * 10))); + + Resources.equals(cs.getResourcesAtTime(i), + Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected"); } } else { for (long i = 10 * step; i < 20 * step; i++) { assertTrue( - "Agent-based allocation unexpected", - Resources.equals(cs.getResourcesAtTime(i), - Resource.newInstance(2048 * 10, 2 * 10))); + + Resources.equals(cs.getResourcesAtTime(i), + Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected"); } } } @@ -239,9 +239,9 @@ public void testSharingPolicyFeedback() throws PlanningException { // expected } - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 4); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 4, "Agent-based allocation failed"); ReservationAllocation cs = plan.getReservationById(reservationID); ReservationAllocation cs2 = plan.getReservationById(reservationID2); @@ -259,29 +259,29 @@ public void testSharingPolicyFeedback() throws PlanningException { if (allocateLeft) { for (long i = 5 * step; i < 15 * step; i++) { assertTrue( - "Agent-based allocation unexpected", - Resources.equals(cs.getResourcesAtTime(i), - Resource.newInstance(2048 * 20, 2 * 20))); + + Resources.equals(cs.getResourcesAtTime(i), + Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); } for (long i = 15 * step; i < 25 * step; i++) { // RR2 is pushed out by the presence of RR assertTrue( - "Agent-based allocation unexpected", - Resources.equals(cs2.getResourcesAtTime(i), - Resource.newInstance(2048 * 20, 2 * 20))); + + Resources.equals(cs2.getResourcesAtTime(i), + Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); } } else { for (long i = 90 * step; i < 100 * step; i++) { assertTrue( - "Agent-based allocation unexpected", - Resources.equals(cs.getResourcesAtTime(i), - Resource.newInstance(2048 * 20, 2 * 20))); + + Resources.equals(cs.getResourcesAtTime(i), + Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); } for (long i = 80 * step; i < 90 * step; i++) { assertTrue( - "Agent-based allocation unexpected", - Resources.equals(cs2.getResourcesAtTime(i), - Resource.newInstance(2048 * 20, 2 * 20))); + + Resources.equals(cs2.getResourcesAtTime(i), + Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); } } } @@ -297,12 +297,12 @@ public void testOrder() throws PlanningException { ReservationSystemTestUtil.createSimpleReservationDefinition(30 * step, 30 * step + f.length * step, f.length * step, 1, recurrenceExpression); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation( + assertTrue( + plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", "dedicated", 30 * step, 30 * step + f.length * step, ReservationSystemTestUtil.generateAllocation(30 * step, step, f), - res, minAlloc), false)); + res, minAlloc), false), plan.toString()); // create a chain of 4 RR, mixing gang and non-gang ReservationDefinition rr = new ReservationDefinitionPBImpl(); @@ -329,23 +329,23 @@ public void testOrder() throws PlanningException { agent.createReservation(reservationID, "u1", plan, rr); // validate - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 4); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 4, "Agent-based allocation failed"); ReservationAllocation cs = plan.getReservationById(reservationID); if (allocateLeft) { - assertTrue(cs.toString(), check(cs, 0 * step, 10 * step, 20, 1024, 1)); - assertTrue(cs.toString(), check(cs, 10 * step, 30 * step, 10, 1024, 1)); - assertTrue(cs.toString(), check(cs, 32 * step, 42 * step, 20, 1024, 1)); - assertTrue(cs.toString(), check(cs, 42 * step, 62 * step, 10, 1024, 1)); + assertTrue(check(cs, 0 * step, 10 * step, 20, 1024, 1), cs.toString()); + assertTrue(check(cs, 10 * step, 30 * step, 10, 1024, 1), cs.toString()); + assertTrue(check(cs, 32 * step, 42 * step, 20, 1024, 1), cs.toString()); + assertTrue(check(cs, 42 * step, 62 * step, 10, 1024, 1), cs.toString()); } else { - assertTrue(cs.toString(), check(cs, 0 * step, 10 * step, 20, 1024, 1)); - assertTrue(cs.toString(), check(cs, 10 * step, 30 * step, 10, 1024, 1)); - assertTrue(cs.toString(), check(cs, 40 * step, 50 * step, 20, 1024, 1)); - assertTrue(cs.toString(), check(cs, 50 * step, 70 * step, 10, 1024, 1)); + assertTrue(check(cs, 0 * step, 10 * step, 20, 1024, 1), cs.toString()); + assertTrue(check(cs, 10 * step, 30 * step, 10, 1024, 1), cs.toString()); + assertTrue(check(cs, 40 * step, 50 * step, 20, 1024, 1), cs.toString()); + assertTrue(check(cs, 50 * step, 70 * step, 10, 1024, 1), cs.toString()); } System.out.println("--------AFTER ORDER ALLOCATION (queue: " + reservationID + ")----------"); @@ -363,12 +363,12 @@ public void testOrderNoGapImpossible() throws PlanningException { .createSimpleReservationDefinition(30, 30 * step + f.length * step, f.length * step, 1, recurrenceExpression); assertTrue( - plan.toString(), - plan.addReservation(new InMemoryReservationAllocation( + + plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", "dedicated", 30 * step, 30 * step + f.length * step, ReservationSystemTestUtil.generateAllocation(30 * step, step, f), - res, minAlloc), false)); + res, minAlloc), false), plan.toString()); // create a chain of 4 RR, mixing gang and non-gang ReservationDefinition rr = new ReservationDefinitionPBImpl(); @@ -401,9 +401,9 @@ public void testOrderNoGapImpossible() throws PlanningException { } // validate - assertFalse("Agent-based allocation should have failed", result); - assertTrue("Agent-based allocation should have failed", plan - .getAllReservations().size() == 3); + assertFalse(result, "Agent-based allocation should have failed"); + assertTrue(plan + .getAllReservations().size() == 3, "Agent-based allocation should have failed"); System.out .println("--------AFTER ORDER_NO_GAP IMPOSSIBLE ALLOCATION (queue: " @@ -447,16 +447,16 @@ public void testOrderNoGap() throws PlanningException { System.out.println(plan.toCumulativeString()); // validate - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 3); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 3, "Agent-based allocation failed"); ReservationAllocation cs = plan.getReservationById(reservationID); - assertTrue(cs.toString(), check(cs, 0 * step, 10 * step, 20, 1024, 1)); - assertTrue(cs.toString(), check(cs, 10 * step, 30 * step, 10, 1024, 1)); - assertTrue(cs.toString(), check(cs, 30 * step, 40 * step, 20, 1024, 1)); - assertTrue(cs.toString(), check(cs, 40 * step, 60 * step, 10, 1024, 1)); + assertTrue(check(cs, 0 * step, 10 * step, 20, 1024, 1), cs.toString()); + assertTrue(check(cs, 10 * step, 30 * step, 10, 1024, 1), cs.toString()); + assertTrue(check(cs, 30 * step, 40 * step, 20, 1024, 1), cs.toString()); + assertTrue(check(cs, 40 * step, 60 * step, 10, 1024, 1), cs.toString()); } @@ -485,13 +485,13 @@ public void testSingleSliding() throws PlanningException { agent.createReservation(reservationID, "u1", plan, rr); // validate results, we expect the second one to be accepted - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 3); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 3, "Agent-based allocation failed"); ReservationAllocation cs = plan.getReservationById(reservationID); - assertTrue(cs.toString(), check(cs, 100 * step, 120 * step, 100, 1024, 1)); + assertTrue(check(cs, 100 * step, 120 * step, 100, 1024, 1), cs.toString()); System.out.println("--------AFTER packed ALLOCATION (queue: " + reservationID + ")----------"); @@ -533,16 +533,16 @@ public void testAny() throws PlanningException { boolean res = agent.createReservation(reservationID, "u1", plan, rr); // validate results, we expect the second one to be accepted - assertTrue("Agent-based allocation failed", res); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 3); + assertTrue(res, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 3, "Agent-based allocation failed"); ReservationAllocation cs = plan.getReservationById(reservationID); if (allocateLeft) { - assertTrue(cs.toString(), check(cs, 100 * step, 110 * step, 5, 1024, 1)); + assertTrue(check(cs, 100 * step, 110 * step, 5, 1024, 1), cs.toString()); } else { - assertTrue(cs.toString(), check(cs, 110 * step, 120 * step, 20, 1024, 1)); + assertTrue(check(cs, 110 * step, 120 * step, 20, 1024, 1), cs.toString()); } System.out.println("--------AFTER ANY ALLOCATION (queue: " + reservationID @@ -587,9 +587,9 @@ public void testAnyImpossible() throws PlanningException { // expected } // validate results, we expect the second one to be accepted - assertFalse("Agent-based allocation should have failed", result); - assertTrue("Agent-based allocation should have failed", plan - .getAllReservations().size() == 2); + assertFalse(result, "Agent-based allocation should have failed"); + assertTrue(plan + .getAllReservations().size() == 2, "Agent-based allocation should have failed"); System.out.println("--------AFTER ANY IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------"); @@ -625,18 +625,18 @@ public void testAll() throws PlanningException { agent.createReservation(reservationID, "u1", plan, rr); // validate results, we expect the second one to be accepted - assertTrue("Agent-based allocation failed", reservationID != null); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 3); + assertTrue(reservationID != null, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 3, "Agent-based allocation failed"); ReservationAllocation cs = plan.getReservationById(reservationID); if (allocateLeft) { - assertTrue(cs.toString(), check(cs, 100 * step, 110 * step, 25, 1024, 1)); - assertTrue(cs.toString(), check(cs, 110 * step, 120 * step, 20, 1024, 1)); + assertTrue(check(cs, 100 * step, 110 * step, 25, 1024, 1), cs.toString()); + assertTrue(check(cs, 110 * step, 120 * step, 20, 1024, 1), cs.toString()); } else { - assertTrue(cs.toString(), check(cs, 100 * step, 110 * step, 20, 1024, 1)); - assertTrue(cs.toString(), check(cs, 110 * step, 120 * step, 25, 1024, 1)); + assertTrue(check(cs, 100 * step, 110 * step, 20, 1024, 1), cs.toString()); + assertTrue(check(cs, 110 * step, 120 * step, 25, 1024, 1), cs.toString()); } System.out.println("--------AFTER ALL ALLOCATION (queue: " + reservationID @@ -680,9 +680,9 @@ public void testAllImpossible() throws PlanningException { } // validate results, we expect the second one to be accepted - assertFalse("Agent-based allocation failed", result); - assertTrue("Agent-based allocation failed", plan.getAllReservations() - .size() == 2); + assertFalse(result, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations() + .size() == 2, "Agent-based allocation failed"); System.out.println("--------AFTER ALL IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------"); @@ -700,20 +700,20 @@ private void prepareBasicPlan() throws PlanningException { ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( 0, 0 + f.length * step, f.length * step); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation( + assertTrue( + plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", "dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil - .generateAllocation(0, step, f), res, minAlloc), false)); + .generateAllocation(0, step, f), res, minAlloc), false), plan.toString()); int[] f2 = { 5, 5, 5, 5, 5, 5, 5 }; Map alloc = ReservationSystemTestUtil.generateAllocation(5000, step, f2); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation( + assertTrue( + plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", "dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc), - false)); + false), plan.toString()); System.out.println("--------BEFORE AGENT----------"); System.out.println(plan.toString()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestReservationAgents.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestReservationAgents.java index 386fa68260892..b0c832dc4d698 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestReservationAgents.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestReservationAgents.java @@ -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; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.slf4j.Logger; @@ -105,7 +105,7 @@ public static Collection data() { {AlignedPlannerWithGreedy.class, false, "86400000", 100 } }); } - @Before + @BeforeEach public void setup() throws Exception { long seed = rand.nextLong(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java index 1209c7e757ce9..c9e7f6373eff3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java @@ -17,9 +17,9 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation.planning; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -48,7 +48,7 @@ import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestSimpleCapacityReplanner { @@ -93,47 +93,47 @@ public void testReplanningPlanCapacityLoss() throws PlanningException { ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( 0, 0 + f5.length, f5.length); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r1, rDef, "u3", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r1, rDef, "u3", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false)); + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(1L); ReservationId r2 = ReservationId.newInstance(ts, 2); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r2, rDef, "u4", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r2, rDef, "u4", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false)); + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(2L); ReservationId r3 = ReservationId.newInstance(ts, 3); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r3, rDef, "u5", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r3, rDef, "u5", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false)); + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(3L); ReservationId r4 = ReservationId.newInstance(ts, 4); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r4, rDef, "u6", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r4, rDef, "u6", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false)); + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(4L); ReservationId r5 = ReservationId.newInstance(ts, 5); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r5, rDef, "u7", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r5, rDef, "u7", "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false)); + minAlloc), false), plan.toString()); int[] f6 = { 50, 50, 50, 50, 50 }; ReservationId r6 = ReservationId.newInstance(ts, 6); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r6, rDef, "u3", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r6, rDef, "u3", "dedicated", 10, 10 + f6.length, generateAllocation(10, f6), res, - minAlloc), false)); + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(6L); ReservationId r7 = ReservationId.newInstance(ts, 7); - assertTrue(plan.toString(), - plan.addReservation(new InMemoryReservationAllocation(r7, rDef, "u4", + assertTrue( + plan.addReservation(new InMemoryReservationAllocation(r7, rDef, "u4", "dedicated", 10, 10 + f6.length, generateAllocation(10, f6), res, - minAlloc), false)); + minAlloc), false), plan.toString()); // remove some of the resources (requires replanning) plan.setTotalCapacity(Resource.newInstance(70 * 1024, 70)); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java index e1fdf0a25e459..1da0cbede925b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java @@ -29,8 +29,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRMAppSubmitter; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.io.IOException; import java.util.HashMap; @@ -51,7 +52,7 @@ public void testProfilesEnabled() throws Exception { manager.init(conf); try { manager.getResourceProfiles(); - Assert + Assertions .fail("Exception should be thrown as resource profile is not enabled" + " and getResourceProfiles is invoked."); } catch (YarnException ie) { @@ -59,7 +60,7 @@ public void testProfilesEnabled() throws Exception { conf.setBoolean(YarnConfiguration.RM_RESOURCE_PROFILES_ENABLED, true); try { manager.init(conf); - Assert.fail( + Assertions.fail( "Exception should be thrown due to missing resource profiles file"); } catch (IOException ie) { } @@ -85,10 +86,10 @@ public void testLoadProfiles() throws Exception { for (Map.Entry entry : expected.entrySet()) { String profile = entry.getKey(); Resource res = entry.getValue(); - Assert.assertTrue("Mandatory profile '" + profile + "' missing", - profiles.containsKey(profile)); - Assert.assertEquals("Profile " + profile + "' resources don't match", res, - manager.getProfile(profile)); + Assertions.assertTrue( + profiles.containsKey(profile), "Mandatory profile '" + profile + "' missing"); + Assertions.assertEquals(res +, manager.getProfile(profile), "Profile " + profile + "' resources don't match"); } } @@ -105,7 +106,7 @@ public void testLoadIllegalProfiles() throws Exception { conf.set(YarnConfiguration.RM_RESOURCE_PROFILES_SOURCE_FILE, file); try { manager.init(conf); - Assert.fail("Bad profile '" + file + "' is not valid"); + Assertions.fail("Bad profile '" + file + "' is not valid"); } catch (IOException ie) { } } @@ -130,8 +131,8 @@ public void testGetProfile() throws Exception { for (Map.Entry entry : expected.entrySet()) { String profile = entry.getKey(); Resource res = entry.getValue(); - Assert.assertEquals("Profile " + profile + "' resources don't match", res, - manager.getProfile(profile)); + Assertions.assertEquals(res +, manager.getProfile(profile), "Profile " + profile + "' resources don't match"); } } @@ -148,16 +149,17 @@ public void testGetMandatoryProfiles() throws Exception { expected.put("default", Resource.newInstance(2048, 2)); expected.put("maximum", Resource.newInstance(8192, 4)); - Assert.assertEquals("Profile 'minimum' resources don't match", - expected.get("minimum"), manager.getMinimumProfile()); - Assert.assertEquals("Profile 'default' resources don't match", - expected.get("default"), manager.getDefaultProfile()); - Assert.assertEquals("Profile 'maximum' resources don't match", - expected.get("maximum"), manager.getMaximumProfile()); + Assertions.assertEquals( + expected.get("minimum"), manager.getMinimumProfile(), "Profile 'minimum' resources don't match"); + Assertions.assertEquals( + expected.get("default"), manager.getDefaultProfile(), "Profile 'default' resources don't match"); + Assertions.assertEquals( + expected.get("maximum"), manager.getMaximumProfile(), "Profile 'maximum' resources don't match"); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testResourceProfilesInAMResponse() throws Exception { Configuration conf = new Configuration(); MockRM rm = new MockRM(conf); @@ -168,7 +170,7 @@ public void testResourceProfilesInAMResponse() throws Exception { RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); RegisterApplicationMasterResponse resp = am1.registerAppAttempt(); - Assert.assertEquals(0, resp.getResourceProfiles().size()); + Assertions.assertEquals(0, resp.getResourceProfiles().size()); rm.stop(); conf.setBoolean(YarnConfiguration.RM_RESOURCE_PROFILES_ENABLED, true); conf.set(YarnConfiguration.RM_RESOURCE_PROFILES_SOURCE_FILE, @@ -181,12 +183,12 @@ public void testResourceProfilesInAMResponse() throws Exception { attempt1 = app1.getCurrentAppAttempt(); am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); resp = am1.registerAppAttempt(); - Assert.assertEquals(3, resp.getResourceProfiles().size()); - Assert.assertEquals(Resource.newInstance(1024, 1), + Assertions.assertEquals(3, resp.getResourceProfiles().size()); + Assertions.assertEquals(Resource.newInstance(1024, 1), resp.getResourceProfiles().get("minimum")); - Assert.assertEquals(Resource.newInstance(2048, 2), + Assertions.assertEquals(Resource.newInstance(2048, 2), resp.getResourceProfiles().get("default")); - Assert.assertEquals(Resource.newInstance(8192, 4), + Assertions.assertEquals(Resource.newInstance(8192, 4), resp.getResourceProfiles().get("maximum")); 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/resourcetracker/TestNMExpiry.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java index 328f3b46a4739..796a5f520e465 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java @@ -21,7 +21,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus; import org.apache.hadoop.yarn.server.api.records.NodeStatus; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,8 +48,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager; import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM; 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; public class TestNMExpiry { private static final Logger LOG = @@ -70,7 +70,7 @@ public void serviceInit(Configuration conf) throws Exception { } } - @Before + @BeforeEach public void setUp() { Configuration conf = new Configuration(); // Dispatcher that processes events inline @@ -164,7 +164,7 @@ public void testNMExpiry() throws Exception { wait(100); } } - Assert.assertEquals(2, ClusterMetrics.getMetrics().getNumLostNMs()); + Assertions.assertEquals(2, ClusterMetrics.getMetrics().getNumLostNMs()); request3 = recordFactory .newRecordInstance(RegisterNodeManagerRequest.class); @@ -178,7 +178,7 @@ public void testNMExpiry() throws Exception { /* test to see if hostanme 3 does not expire */ stopT = false; new ThirdNodeHeartBeatThread().start(); - Assert.assertEquals(2,ClusterMetrics.getMetrics().getNumLostNMs()); + Assertions.assertEquals(2,ClusterMetrics.getMetrics().getNumLostNMs()); stopT = true; } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java index 6e36c533a4bfe..33c0a93a22ca1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java @@ -46,10 +46,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager; import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM; 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; @SuppressWarnings("rawtypes") public class TestRMNMRPCResponseId { @@ -57,7 +57,7 @@ public class TestRMNMRPCResponseId { ResourceTrackerService resourceTrackerService; private NodeId nodeId; - @Before + @BeforeEach public void setUp() { Configuration conf = new Configuration(); // Dispatcher that processes events inline @@ -86,7 +86,7 @@ nodesListManager, new NMLivelinessMonitor(dispatcher), resourceTrackerService.init(conf); } - @After + @AfterEach public void tearDown() { /* do nothing */ } @@ -121,20 +121,20 @@ public void testRPCResponseId() throws IOException, YarnException { nodeStatus.setResponseId(0); NodeHeartbeatResponse response = resourceTrackerService.nodeHeartbeat( nodeHeartBeatRequest); - Assert.assertTrue(response.getResponseId() == 1); + Assertions.assertTrue(response.getResponseId() == 1); nodeStatus.setResponseId(response.getResponseId()); response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest); - Assert.assertTrue(response.getResponseId() == 2); + Assertions.assertTrue(response.getResponseId() == 2); /* try calling with less response id */ response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest); - Assert.assertTrue(response.getResponseId() == 2); + Assertions.assertTrue(response.getResponseId() == 2); nodeStatus.setResponseId(0); response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest); - Assert.assertTrue(NodeAction.RESYNC.equals(response.getNodeAction())); - Assert.assertEquals("Too far behind rm response id:2 nm response id:0", + Assertions.assertTrue(NodeAction.RESYNC.equals(response.getNodeAction())); + Assertions.assertEquals("Too far behind rm response id:2 nm response id:0", response.getDiagnosticsMessage()); } } \ 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/rmapp/TestApplicationLifetimeMonitor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java index 569919c01c4fa..b635fe94a4a6b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java @@ -18,8 +18,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.rmapp; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.ArrayList; @@ -64,9 +64,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; import org.apache.hadoop.yarn.util.Times; import org.slf4j.event.Level; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -97,7 +98,7 @@ public TestApplicationLifetimeMonitor(Class schedulerParameter) { scheduler = schedulerParameter; } - @Before + @BeforeEach public void setup() throws IOException { if (scheduler.equals(CapacityScheduler.class)) { // Since there is limited lifetime monitoring support in fair scheduler @@ -118,7 +119,8 @@ public void setup() throws IOException { 3000L); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testApplicationLifetimeMonitor() throws Exception { MockRM rm = null; @@ -167,8 +169,8 @@ public void testApplicationLifetimeMonitor() rm.sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId()); am1.registerAppAttempt(); rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); - Assert.assertTrue("Application killed before lifetime value", - (System.currentTimeMillis() - app1.getSubmitTime()) > 10000); + Assertions.assertTrue( + (System.currentTimeMillis() - app1.getSubmitTime()) > 10000, "Application killed before lifetime value"); Map updateTimeout = new HashMap(); @@ -196,8 +198,8 @@ public void testApplicationLifetimeMonitor() long afterUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME); - Assert.assertTrue("Application lifetime value not updated", - afterUpdate > beforeUpdate); + Assertions.assertTrue( + afterUpdate > beforeUpdate, "Application lifetime value not updated"); // verify for application report. RecordFactory recordFactory = @@ -208,17 +210,17 @@ public void testApplicationLifetimeMonitor() Map appTimeouts = rm .getRMContext().getClientRMService().getApplicationReport(appRequest) .getApplicationReport().getApplicationTimeouts(); - Assert.assertTrue("Application Timeout are empty.", - !appTimeouts.isEmpty()); + Assertions.assertTrue( + !appTimeouts.isEmpty(), "Application Timeout are empty."); ApplicationTimeout timeout = appTimeouts.get(ApplicationTimeoutType.LIFETIME); - Assert.assertTrue("Application remaining time is incorrect", - timeout.getRemainingTime() > 0); + Assertions.assertTrue( + timeout.getRemainingTime() > 0, "Application remaining time is incorrect"); rm.waitForState(app2.getApplicationId(), RMAppState.KILLED); // verify for app killed with updated lifetime - Assert.assertTrue("Application killed before lifetime value", - app2.getFinishTime() > afterUpdate); + Assertions.assertTrue( + app2.getFinishTime() > afterUpdate, "Application killed before lifetime value"); if (scheduler.equals(CapacityScheduler.class)) { // Supported only on capacity scheduler @@ -228,18 +230,19 @@ public void testApplicationLifetimeMonitor() // so killed after queue max lifetime. rm.waitForState(app4.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app4.getFinishTime() - app4.getSubmitTime(); - Assert.assertTrue("Application killed before lifetime value", - totalTimeRun > (maxLifetime * 1000)); - Assert.assertTrue( - "Application killed before lifetime value " + totalTimeRun, - totalTimeRun < ((maxLifetime + 10L) * 1000)); + Assertions.assertTrue( + totalTimeRun > (maxLifetime * 1000), "Application killed before lifetime value"); + Assertions.assertTrue( + + totalTimeRun < ((maxLifetime + 10L) * 1000), "Application killed before lifetime value " + totalTimeRun); } } finally { stopRM(rm); } } - @Test(timeout = 180000) + @Test + @Timeout(value = 180) public void testApplicationLifetimeOnRMRestart() throws Exception { conf.setBoolean(YarnConfiguration.RECOVERY_ENABLED, true); conf.setBoolean(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, @@ -310,12 +313,13 @@ public void testApplicationLifetimeOnRMRestart() throws Exception { // wait for app life time and application to be in killed state. rm2.waitForState(recoveredApp1.getApplicationId(), RMAppState.KILLED); - Assert.assertTrue("Application killed before lifetime value", - recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime() - + appLifetime * 1000)); + Assertions.assertTrue( + recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime() + + appLifetime * 1000), "Application killed before lifetime value"); } - @Test(timeout = 60000) + @Test + @Timeout(value = 60) public void testUpdateApplicationTimeoutForStateStoreUpdateFail() throws Exception { MockRM rm1 = null; @@ -375,8 +379,8 @@ public synchronized void updateApplicationStateInternal( fail("Update application should fail."); } catch (YarnException e) { // expected - assertTrue("State-store exception does not containe appId", - e.getMessage().contains(app1.getApplicationId().toString())); + assertTrue( + e.getMessage().contains(app1.getApplicationId().toString()), "State-store exception does not containe appId"); } applicationTimeouts = app1.getApplicationTimeouts(); @@ -384,18 +388,19 @@ public synchronized void updateApplicationStateInternal( long afterUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME); - Assert.assertEquals("Application timeout is updated", beforeUpdate, - afterUpdate); + Assertions.assertEquals(beforeUpdate +, afterUpdate, "Application timeout is updated"); rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED); // verify for app killed with updated lifetime - Assert.assertTrue("Application killed before lifetime value", - app1.getFinishTime() > afterUpdate); + Assertions.assertTrue( + app1.getFinishTime() > afterUpdate, "Application killed before lifetime value"); } finally { stopRM(rm1); } } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testInheritAppLifetimeFromParentQueue() throws Exception { YarnConfiguration yarnConf = conf; long maxRootLifetime = 20L; @@ -436,28 +441,29 @@ public void testInheritAppLifetimeFromParentQueue() throws Exception { rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // Child queue should have inherited parent max and default lifetimes. - Assert.assertEquals("Child queue max lifetime should have overridden" - + " parent value", - maxRootLifetime, - csched.getQueue(CQ1).getMaximumApplicationLifetime()); - Assert.assertEquals("Child queue default lifetime should have" - + " overridden parent value", - defaultRootLifetime, - csched.getQueue(CQ1).getDefaultApplicationLifetime()); + Assertions.assertEquals( + maxRootLifetime +, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden" + + " parent value"); + Assertions.assertEquals( + defaultRootLifetime +, csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have" + + " overridden parent value"); // app1 (run in the 'child1' queue) should have run longer than the // default lifetime but less than the max lifetime. - Assert.assertTrue("Application killed before default lifetime value", - totalTimeRun > (defaultRootLifetime * 1000)); - Assert.assertTrue( - "Application killed after max lifetime value " + totalTimeRun, - totalTimeRun < (maxRootLifetime * 1000)); + Assertions.assertTrue( + totalTimeRun > (defaultRootLifetime * 1000), "Application killed before default lifetime value"); + Assertions.assertTrue( + + totalTimeRun < (maxRootLifetime * 1000), "Application killed after max lifetime value " + totalTimeRun); } } finally { stopRM(rm); } } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testOverrideParentQueueMaxAppLifetime() throws Exception { YarnConfiguration yarnConf = conf; long maxRootLifetime = 20L; @@ -501,22 +507,23 @@ public void testOverrideParentQueueMaxAppLifetime() throws Exception { rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // Child queue's max lifetime can override parent's and be larger. - Assert.assertTrue("Application killed before default lifetime value", - (maxRootLifetime < maxChildLifetime) - && (totalTimeRun > (maxChildLifetime * 1000))); - Assert.assertEquals("Root queue max lifetime property set incorrectly", - maxRootLifetime, - csched.getRootQueue().getMaximumApplicationLifetime()); - Assert.assertEquals("Child queue max lifetime should have overridden" - + " parent value", maxChildLifetime, - csched.getQueue(CQ1).getMaximumApplicationLifetime()); + Assertions.assertTrue( + (maxRootLifetime < maxChildLifetime) + && (totalTimeRun > (maxChildLifetime * 1000)), "Application killed before default lifetime value"); + Assertions.assertEquals( + maxRootLifetime +, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly"); + Assertions.assertEquals(maxChildLifetime +, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden" + + " parent value"); } } finally { stopRM(rm); } } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testOverrideParentQueueDefaultAppLifetime() throws Exception { YarnConfiguration yarnConf = conf; long maxRootLifetime = -1L; @@ -560,19 +567,19 @@ public void testOverrideParentQueueDefaultAppLifetime() throws Exception { long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // app1 (run in 'child1' queue) should have overridden the parent's // default lifetime. - Assert.assertTrue("Application killed before default lifetime value", - totalTimeRun > (defaultChildLifetime * 1000)); + Assertions.assertTrue( + totalTimeRun > (defaultChildLifetime * 1000), "Application killed before default lifetime value"); // Root and child queue's max lifetime should be -1. - Assert.assertEquals("Root queue max lifetime property set incorrectly", - maxRootLifetime, - csched.getRootQueue().getMaximumApplicationLifetime()); - Assert.assertEquals("Child queue max lifetime property set incorrectly", - maxChildLifetime, - csched.getQueue(CQ1).getMaximumApplicationLifetime()); + Assertions.assertEquals( + maxRootLifetime +, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly"); + Assertions.assertEquals( + maxChildLifetime +, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime property set incorrectly"); // 'child1' queue's default lifetime should have overridden parent's. - Assert.assertEquals("Child queue default lifetime should have" - + " overridden parent value", defaultChildLifetime, - csched.getQueue(CQ1).getDefaultApplicationLifetime()); + Assertions.assertEquals(defaultChildLifetime +, csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have" + + " overridden parent value"); } } finally { stopRM(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/rmapp/TestNodesListManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java index 35148e9a450a4..35f0145dcaf5f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java @@ -44,15 +44,17 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.util.ControlledClock; import org.slf4j.event.Level; -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.mockito.ArgumentMatcher; public class TestNodesListManager { private boolean isRMAppEvent; private boolean isNodesListEvent; - @Test(timeout = 300000) + @Test + @Timeout(value = 300) public void testNodeUsableEvent() throws Exception { GenericTestUtils.setRootLogLevel(Level.DEBUG); final Dispatcher dispatcher = getDispatcher(); @@ -87,10 +89,10 @@ protected Dispatcher createDispatcher() { // Should not have RMAppNodeUpdateEvent to AsyncDispatcher. dispatcher.getEventHandler().handle(new NodesListManagerEvent( NodesListManagerEventType.NODE_USABLE, rmnode)); - Assert.assertFalse("Got unexpected RM app event", - getIsRMAppEvent()); - Assert.assertTrue("Received no NodesListManagerEvent", - getIsNodesListEvent()); + Assertions.assertFalse( + getIsRMAppEvent(), "Got unexpected RM app event"); + Assertions.assertTrue( + getIsNodesListEvent(), "Received no NodesListManagerEvent"); } @Test @@ -104,28 +106,28 @@ public void testCachedResolver() throws Exception { resolver.init(new YarnConfiguration()); resolver.start(); resolver.addToCache("testCachedResolverHost1", "1.1.1.1"); - Assert.assertEquals("1.1.1.1", + Assertions.assertEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); resolver.addToCache("testCachedResolverHost2", "1.1.1.2"); - Assert.assertEquals("1.1.1.1", + Assertions.assertEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assert.assertEquals("1.1.1.2", + Assertions.assertEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); // test removeFromCache resolver.removeFromCache("testCachedResolverHost1"); - Assert.assertNotEquals("1.1.1.1", + Assertions.assertNotEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assert.assertEquals("1.1.1.2", + Assertions.assertEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); // test expiry clock.tickMsec(CACHE_EXPIRY_INTERVAL_SECS * 1000 + 1); resolver.getExpireChecker().run(); - Assert.assertNotEquals("1.1.1.1", + Assertions.assertNotEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assert.assertNotEquals("1.1.1.2", + Assertions.assertNotEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); } @@ -140,8 +142,8 @@ public void testDefaultResolver() throws Exception { NodesListManager nodesListManager = rm.getNodesListManager(); NodesListManager.Resolver resolver = nodesListManager.getResolver(); - Assert.assertTrue("default resolver should be DirectResolver", - resolver instanceof NodesListManager.DirectResolver); + Assertions.assertTrue( + resolver instanceof NodesListManager.DirectResolver, "default resolver should be DirectResolver"); } @Test @@ -162,9 +164,9 @@ public void testCachedResolverWithEvent() throws Exception { resolver.addToCache("testCachedResolverHost1", "1.1.1.1"); resolver.addToCache("testCachedResolverHost2", "1.1.1.2"); - Assert.assertEquals("1.1.1.1", + Assertions.assertEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assert.assertEquals("1.1.1.2", + Assertions.assertEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); RMNode rmnode1 = MockNodes.newNodeInfo(1, Resource.newInstance(28000, 8), @@ -175,17 +177,17 @@ public void testCachedResolverWithEvent() throws Exception { nodesListManager.handle( new NodesListManagerEvent(NodesListManagerEventType.NODE_USABLE, rmnode1)); - Assert.assertNotEquals("1.1.1.1", + Assertions.assertNotEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assert.assertEquals("1.1.1.2", + Assertions.assertEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); nodesListManager.handle( new NodesListManagerEvent(NodesListManagerEventType.NODE_USABLE, rmnode2)); - Assert.assertNotEquals("1.1.1.1", + Assertions.assertNotEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assert.assertNotEquals("1.1.1.2", + Assertions.assertNotEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java index 536ad2b7896a1..8a89aade79465 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -88,9 +88,10 @@ import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.Records; -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.mockito.ArgumentCaptor; @@ -110,9 +111,9 @@ import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; @@ -227,7 +228,7 @@ public TestRMAppTransitions(boolean isSecurityEnabled) { this.isSecurityEnabled = isSecurityEnabled; } - @Before + @BeforeEach public void setUp() throws Exception { conf = new YarnConfiguration(); AuthenticationMethod authMethod = AuthenticationMethod.SIMPLE; @@ -429,52 +430,52 @@ protected RMApp createNewTestApp(ApplicationSubmissionContext // Test expected newly created app state private static void testAppStartState(ApplicationId applicationId, String user, String name, String queue, RMApp application) { - Assert.assertTrue("application start time is not greater than 0", - application.getStartTime() > 0); - Assert.assertTrue("application start time is before currentTime", - application.getStartTime() <= System.currentTimeMillis()); - Assert.assertEquals("application user is not correct", - user, application.getUser()); - Assert.assertEquals("application id is not correct", - applicationId, application.getApplicationId()); - Assert.assertEquals("application progress is not correct", - (float)0.0, application.getProgress(), (float)0.0); - Assert.assertEquals("application queue is not correct", - queue, application.getQueue()); - Assert.assertEquals("application name is not correct", - name, application.getName()); - Assert.assertEquals("application finish time is not 0 and should be", - 0, application.getFinishTime()); - Assert.assertNull("application tracking url is not correct", - application.getTrackingUrl()); + Assertions.assertTrue( + application.getStartTime() > 0, "application start time is not greater than 0"); + Assertions.assertTrue( + application.getStartTime() <= System.currentTimeMillis(), "application start time is before currentTime"); + Assertions.assertEquals( + user, application.getUser(), "application user is not correct"); + Assertions.assertEquals( + applicationId, application.getApplicationId(), "application id is not correct"); + Assertions.assertEquals( + (float)0.0, application.getProgress(), (float)0.0, "application progress is not correct"); + Assertions.assertEquals( + queue, application.getQueue(), "application queue is not correct"); + Assertions.assertEquals( + name, application.getName(), "application name is not correct"); + Assertions.assertEquals( + 0, application.getFinishTime(), "application finish time is not 0 and should be"); + Assertions.assertNull( + application.getTrackingUrl(), "application tracking url is not correct"); StringBuilder diag = application.getDiagnostics(); - Assert.assertEquals("application diagnostics is not correct", - 0, diag.length()); + Assertions.assertEquals( + 0, diag.length(), "application diagnostics is not correct"); } // test to make sure times are set when app finishes private void assertStartTimeSet(RMApp application) { - Assert.assertTrue("application start time is before test case start time", - application.getStartTime() >= testCaseStartTime); - Assert.assertTrue("application start time is before currentTime", - application.getStartTime() <= System.currentTimeMillis()); + Assertions.assertTrue( + application.getStartTime() >= testCaseStartTime, "application start time is before test case start time"); + Assertions.assertTrue( + application.getStartTime() <= System.currentTimeMillis(), "application start time is before currentTime"); } private static void assertAppState(RMAppState state, RMApp application) { - Assert.assertEquals("application state should have been " + state, - state, application.getState()); + Assertions.assertEquals( + state, application.getState(), "application state should have been " + state); } private static void assertFinalAppStatus(FinalApplicationStatus status, RMApp application) { - Assert.assertEquals("Final application status should have been " + status, - status, application.getFinalApplicationStatus()); + Assertions.assertEquals( + status, application.getFinalApplicationStatus(), "Final application status should have been " + status); } // test to make sure times are set when app finishes private void assertTimesAtFinish(RMApp application) { assertStartTimeSet(application); - Assert.assertTrue("application finish time is not >= start time", - (application.getFinishTime() >= application.getStartTime())); + Assertions.assertTrue( + (application.getFinishTime() >= application.getStartTime()), "application finish time is not >= start time"); } private void assertAppFinalStateSaved(RMApp application){ @@ -503,7 +504,7 @@ private void assertKilled(RMApp application) { assertAppState(RMAppState.KILLED, application); assertFinalAppStatus(FinalApplicationStatus.KILLED, application); StringBuilder diag = application.getDiagnostics(); - Assert.assertEquals("application diagnostics is not correct", + Assertions.assertEquals("application diagnostics is not correct", "Application killed by user.", diag.toString()); } @@ -512,8 +513,8 @@ private void assertFailed(RMApp application, String regex) { assertAppState(RMAppState.FAILED, application); assertFinalAppStatus(FinalApplicationStatus.FAILED, application); StringBuilder diag = application.getDiagnostics(); - Assert.assertTrue("application diagnostics is not correct", - diag.toString().matches(regex)); + Assertions.assertTrue( + diag.toString().matches(regex), "application diagnostics is not correct"); } private void sendAppUpdateSavedEvent(RMApp application) { @@ -629,7 +630,7 @@ protected RMApp testCreateAppFinishing( // unmanaged AMs don't use the FINISHING state assert submissionContext == null || !submissionContext.getUnmanagedAM(); RMApp application = testCreateAppFinalSaving(submissionContext); - Assert.assertNotNull("app shouldn't be null", application); + Assertions.assertNotNull(application, "app shouldn't be null"); // FINAL_SAVING => FINISHING event RMAppEventType.APP_UPDATED RMAppEvent appUpdated = new RMAppEvent(application.getApplicationId(), RMAppEventType.APP_UPDATE_SAVED); @@ -671,8 +672,8 @@ protected RMApp testCreateAppFinished( assertTimesAtFinish(application); // finished without a proper unregister implies failed assertFinalAppStatus(FinalApplicationStatus.FAILED, application); - Assert.assertTrue("Finished app missing diagnostics", - application.getDiagnostics().indexOf(diagnostics) != -1); + Assertions.assertTrue( + application.getDiagnostics().indexOf(diagnostics) != -1, "Finished app missing diagnostics"); return application; } @@ -685,8 +686,8 @@ public void testUnmanagedApp() throws Exception { LOG.info("--- START: testUnmanagedAppSuccessPath ---"); final String diagMsg = "some diagnostics"; RMApp application = testCreateAppFinished(subContext, diagMsg); - Assert.assertTrue("Finished app missing diagnostics", - application.getDiagnostics().indexOf(diagMsg) != -1); + Assertions.assertTrue( + application.getDiagnostics().indexOf(diagMsg) != -1, "Finished app missing diagnostics"); // reset the counter of Mockito.verify reset(writer); @@ -700,7 +701,7 @@ public void testUnmanagedApp() throws Exception { application.handle(event); rmDispatcher.await(); RMAppAttempt appAttempt = application.getCurrentAppAttempt(); - Assert.assertEquals(1, appAttempt.getAppAttemptId().getAttemptId()); + Assertions.assertEquals(1, appAttempt.getAppAttemptId().getAttemptId()); sendAppUpdateSavedEvent(application); assertFailed(application, ".*Unmanaged application.*Failing the application.*"); @@ -713,12 +714,13 @@ public void testAppSuccessPath() throws Exception { LOG.info("--- START: testAppSuccessPath ---"); final String diagMsg = "some diagnostics"; RMApp application = testCreateAppFinished(null, diagMsg); - Assert.assertTrue("Finished application missing diagnostics", - application.getDiagnostics().indexOf(diagMsg) != -1); + Assertions.assertTrue( + application.getDiagnostics().indexOf(diagMsg) != -1, "Finished application missing diagnostics"); verifyRMAppFieldsForFinalTransitions(application); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppRecoverPath() throws IOException { LOG.info("--- START: testAppRecoverPath ---"); ApplicationSubmissionContext sub = @@ -727,7 +729,8 @@ public void testAppRecoverPath() throws IOException { testCreateAppSubmittedRecovery(sub); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppNewKill() throws IOException { LOG.info("--- START: testAppNewKill ---"); @@ -767,7 +770,8 @@ public void testAppNewReject() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppNewRejectAddToStore() throws IOException { LOG.info("--- START: testAppNewRejectAddToStore ---"); @@ -786,7 +790,8 @@ public void testAppNewRejectAddToStore() throws IOException { rmContext.getStateStore().removeApplication(application); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppNewSavingKill() throws IOException { LOG.info("--- START: testAppNewSavingKill ---"); @@ -808,7 +813,8 @@ public void testAppNewSavingKill() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppNewSavingReject() throws IOException { LOG.info("--- START: testAppNewSavingReject ---"); @@ -826,7 +832,8 @@ public void testAppNewSavingReject() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppNewSavingSaveReject() throws IOException { LOG.info("--- START: testAppNewSavingSaveReject ---"); RMApp application = testCreateAppNewSaving(null); @@ -843,7 +850,8 @@ public void testAppNewSavingSaveReject() throws IOException { assertTimesAtFinish(application); } - @Test (timeout = 30000) + @Test + @Timeout(value = 30) public void testAppSubmittedRejected() throws IOException { LOG.info("--- START: testAppSubmittedRejected ---"); @@ -890,7 +898,7 @@ public void testAppAcceptedFailed() throws IOException { RMApp application = testCreateAppAccepted(null); // ACCEPTED => ACCEPTED event RMAppEventType.RMAppEventType.ATTEMPT_FAILED - Assert.assertTrue(maxAppAttempts > 1); + Assertions.assertTrue(maxAppAttempts > 1); for (int i=1; i < maxAppAttempts; i++) { RMAppEvent event = new RMAppFailedAttemptEvent(application.getApplicationId(), @@ -1029,10 +1037,10 @@ public void testAppRunningFailed() throws IOException { RMApp application = testCreateAppRunning(null); RMAppAttempt appAttempt = application.getCurrentAppAttempt(); int expectedAttemptId = 1; - Assert.assertEquals(expectedAttemptId, + Assertions.assertEquals(expectedAttemptId, appAttempt.getAppAttemptId().getAttemptId()); // RUNNING => FAILED/RESTARTING event RMAppEventType.ATTEMPT_FAILED - Assert.assertTrue(maxAppAttempts > 1); + Assertions.assertTrue(maxAppAttempts > 1); for (int i=1; i applicationState = @@ -1292,20 +1304,20 @@ public void testRecoverApplication(ApplicationStateData appState, Collections.singletonList(BuilderUtils.newResourceRequest( RMAppAttemptImpl.AM_CONTAINER_PRIORITY, ResourceRequest.ANY, submissionContext.getResource(), 1))); - Assert.assertEquals(RMAppState.NEW, application.getState()); + Assertions.assertEquals(RMAppState.NEW, application.getState()); RMAppEvent recoverEvent = new RMAppRecoverEvent(application.getApplicationId(), rmState); // Trigger RECOVER event. application.handle(recoverEvent); // Application final status looked from recoveredFinalStatus - Assert.assertTrue("Application is not in recoveredFinalStatus.", - RMAppImpl.isAppInFinalState(application)); + Assertions.assertTrue( + RMAppImpl.isAppInFinalState(application), "Application is not in recoveredFinalStatus."); rmDispatcher.await(); RMAppState finalState = appState.getState(); - Assert.assertEquals("Application is not in finalState.", finalState, - application.getState()); + Assertions.assertEquals(finalState +, application.getState(), "Application is not in finalState."); verifyRMAppFieldsForFinalTransitions(application); } @@ -1325,21 +1337,21 @@ public void testGetAppReport() throws IOException { RMApp app = createNewTestApp(null); assertAppState(RMAppState.NEW, app); ApplicationReport report = app.createAndGetApplicationReport(null, true); - Assert.assertNotNull(report.getApplicationResourceUsageReport()); + Assertions.assertNotNull(report.getApplicationResourceUsageReport()); assertThat(report.getApplicationResourceUsageReport()). isEqualTo(RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT); report = app.createAndGetApplicationReport("clientuser", true); - Assert.assertNotNull(report.getApplicationResourceUsageReport()); - Assert.assertTrue("bad proxy url for app", - report.getTrackingUrl().endsWith("/proxy/" + app.getApplicationId() - + "/")); + Assertions.assertNotNull(report.getApplicationResourceUsageReport()); + Assertions.assertTrue( + report.getTrackingUrl().endsWith("/proxy/" + app.getApplicationId() + + "/"), "bad proxy url for app"); } private void verifyAppBeforeFinishEvent(RMApp app) { assertEquals(0L, ((RMAppImpl) app).getLogAggregationStartTime()); //RMAppEventType.APP_UPDATE_SAVED sets the finish time - assertTrue("App manager events should not be received!", - appManagerDispatcher.events.isEmpty()); + assertTrue( + appManagerDispatcher.events.isEmpty(), "App manager events should not be received!"); } private void verifyAppAfterFinishEvent(RMApp app) { @@ -1363,22 +1375,22 @@ private void verifyApplicationFinished(RMAppState state) { ArgumentCaptor finalState = ArgumentCaptor.forClass(RMAppState.class); verify(writer).applicationFinished(any(RMApp.class), finalState.capture()); - Assert.assertEquals(state, finalState.getValue()); + Assertions.assertEquals(state, finalState.getValue()); finalState = ArgumentCaptor.forClass(RMAppState.class); verify(publisher).appFinished(any(RMApp.class), finalState.capture(), anyLong()); - Assert.assertEquals(state, finalState.getValue()); + Assertions.assertEquals(state, finalState.getValue()); } private void verifyAppRemovedSchedulerEvent(RMApp app, RMAppState finalState) { SchedulerEvent lastEvent = schedulerDispatcher.lastSchedulerEvent; - Assert.assertEquals(SchedulerEventType.APP_REMOVED, lastEvent.getType()); + Assertions.assertEquals(SchedulerEventType.APP_REMOVED, lastEvent.getType()); if (lastEvent instanceof AppRemovedSchedulerEvent) { AppRemovedSchedulerEvent appRemovedEvent = (AppRemovedSchedulerEvent) lastEvent; - Assert.assertEquals(finalState, appRemovedEvent.getFinalState()); - Assert.assertEquals(app.getApplicationId().getId(), + Assertions.assertEquals(finalState, appRemovedEvent.getFinalState()); + Assertions.assertEquals(app.getApplicationId().getId(), appRemovedEvent.getApplicationID().getId()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestAMLivelinessMonitor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestAMLivelinessMonitor.java index 33253ecb3bffc..f23ae4a51bdee 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestAMLivelinessMonitor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestAMLivelinessMonitor.java @@ -26,14 +26,16 @@ import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore; import org.apache.hadoop.yarn.util.ControlledClock; -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 static org.mockito.Mockito.mock; public class TestAMLivelinessMonitor { - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testResetTimer() throws Exception { YarnConfiguration conf = new YarnConfiguration(); UserGroupInformation.setConfiguration(conf); @@ -58,7 +60,7 @@ public synchronized RMState loadState() throws Exception { dispatcher, clock) { @Override protected void expire(ApplicationAttemptId id) { - Assert.assertEquals(id, attemptId); + Assertions.assertEquals(id, attemptId); expired[0] = true; } }; @@ -75,7 +77,7 @@ protected AMLivelinessMonitor createAMLivelinessMonitor() { Thread.sleep(100); } // expired[0] would be set to true without resetTimer - Assert.assertFalse(expired[0]); + Assertions.assertFalse(expired[0]); 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/rmapp/attempt/TestRMAppAttemptImplDiagnostics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptImplDiagnostics.java index 6c1b08269f508..852375722e51b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptImplDiagnostics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptImplDiagnostics.java @@ -28,10 +28,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.RMContext; import org.apache.hadoop.yarn.util.BoundedAppender; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.rules.ExpectedException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -72,8 +72,8 @@ public void whenAppendedWithinLimitMessagesArePreserved() { final String withinLimit = RandomStringUtils.random(1024); appAttempt.appendDiagnostics(withinLimit); - assertEquals("messages within limit should be preserved", withinLimit, - appAttempt.getDiagnostics()); + assertEquals(withinLimit +, appAttempt.getDiagnostics(), "messages within limit should be preserved"); } @Test @@ -90,8 +90,8 @@ public void whenAppendedBeyondLimitMessagesAreTruncated() { BoundedAppender.TRUNCATED_MESSAGES_TEMPLATE, 1024, 1025, beyondLimit.substring(1)); - assertEquals("messages beyond limit should be truncated", truncated, - appAttempt.getDiagnostics()); + assertEquals(truncated +, appAttempt.getDiagnostics(), "messages beyond limit should be truncated"); } private RMAppAttemptImpl createRMAppAttemptImpl( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java index 9e8f2f5edbdcd..0bdcd50ead00f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java @@ -18,11 +18,11 @@ package org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt; import static org.apache.hadoop.yarn.util.StringHelper.pjoin; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.Assume.assumeTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; @@ -113,10 +113,11 @@ import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.webapp.util.WebAppUtils; -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.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.mockito.ArgumentCaptor; @@ -236,7 +237,7 @@ public TestRMAppAttemptTransitions(Boolean isSecurityEnabled) { } @SuppressWarnings("deprecation") - @Before + @BeforeEach public void setUp() throws Exception { AuthenticationMethod authMethod = AuthenticationMethod.SIMPLE; if (isSecurityEnabled) { @@ -331,8 +332,8 @@ masterService, submissionContext, new Configuration(), protected void onInvalidTranstion( RMAppAttemptEventType rmAppAttemptEventType, RMAppAttemptState state) { - Assert.assertTrue("RMAppAttemptImpl can't handle " - + rmAppAttemptEventType + " at state " + state, false); + Assertions.assertTrue(false, "RMAppAttemptImpl can't handle " + + rmAppAttemptEventType + " at state " + state); } }; @@ -343,7 +344,7 @@ protected void onInvalidTranstion( testAppAttemptNewState(); } - @After + @AfterEach public void tearDown() throws Exception { ((AsyncDispatcher)this.spyRMContext.getDispatcher()).stop(); } @@ -351,7 +352,7 @@ public void tearDown() throws Exception { private String getProxyUrl(RMAppAttempt appAttempt) { String url = rmContext.getAppProxyUrl(conf, appAttempt.getAppAttemptId().getApplicationId()); - Assert.assertNotEquals("N/A", url); + Assertions.assertNotEquals("N/A", url); return url; } @@ -588,7 +589,7 @@ private void testAppAttemptFinishedState(Container container, verifyAttemptFinalStateSaved(); assertEquals(finishedContainerCount, applicationAttempt .getJustFinishedContainers().size()); - Assert.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) + Assertions.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) .size()); assertEquals(container, applicationAttempt.getMasterContainer()); assertEquals(finalStatus, applicationAttempt.getFinalApplicationStatus()); @@ -773,8 +774,8 @@ public void testUsageReport() { // expect usage stats to come from the scheduler report ApplicationResourceUsageReport report = applicationAttempt.getApplicationResourceUsageReport(); - Assert.assertEquals(123456L, report.getMemorySeconds()); - Assert.assertEquals(55544L, report.getVcoreSeconds()); + Assertions.assertEquals(123456L, report.getMemorySeconds()); + Assertions.assertEquals(55544L, report.getVcoreSeconds()); // finish app attempt and remove it from scheduler when(appResUsgRpt.getMemorySeconds()).thenReturn(223456L); @@ -789,8 +790,8 @@ public void testUsageReport() { when(scheduler.getSchedulerAppInfo(eq(attemptId))).thenReturn(null); report = applicationAttempt.getApplicationResourceUsageReport(); - Assert.assertEquals(223456, report.getMemorySeconds()); - Assert.assertEquals(75544, report.getVcoreSeconds()); + Assertions.assertEquals(223456, report.getMemorySeconds()); + Assertions.assertEquals(75544, report.getVcoreSeconds()); } @Test @@ -925,7 +926,8 @@ public void testAllocatedToFailed() { testAppAttemptFailedState(amContainer, diagnostics); } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testAllocatedToRunning() { Container amContainer = allocateApplicationAttempt(); // Register attempt event arrives before launched attempt event @@ -933,7 +935,8 @@ public void testAllocatedToRunning() { launchApplicationAttempt(amContainer, RMAppAttemptState.RUNNING); } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testCreateAppAttemptReport() { RMAppAttemptState[] attemptStates = RMAppAttemptState.values(); applicationAttempt.handle(new RMAppAttemptEvent( @@ -946,7 +949,8 @@ public void testCreateAppAttemptReport() { } } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testLaunchedAtFinalSaving() { Container amContainer = allocateApplicationAttempt(); @@ -978,7 +982,8 @@ public void testLaunchedAtFinalSaving() { applicationAttempt.getAppAttemptState()); } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testAttemptAddedAtFinalSaving() { submitApplicationAttempt(); @@ -995,7 +1000,8 @@ public void testAttemptAddedAtFinalSaving() { applicationAttempt.getAppAttemptState()); } - @Test(timeout = 10000) + @Test + @Timeout(value = 10) public void testAttemptRegisteredAtFailed() { Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); @@ -1152,7 +1158,8 @@ public void testRunningToKilled() { verifyApplicationAttemptFinished(RMAppAttemptState.KILLED); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testLaunchedExpire() { Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); @@ -1163,8 +1170,8 @@ public void testLaunchedExpire() { sendAttemptUpdateSavedEvent(applicationAttempt); assertEquals(RMAppAttemptState.FAILED, applicationAttempt.getAppAttemptState()); - assertTrue("expire diagnostics missing", - applicationAttempt.getDiagnostics().contains("timed out")); + assertTrue( + applicationAttempt.getDiagnostics().contains("timed out"), "expire diagnostics missing"); String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app", applicationAttempt.getAppAttemptId().getApplicationId()); assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl()); @@ -1174,7 +1181,8 @@ public void testLaunchedExpire() { } @SuppressWarnings("unchecked") - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testLaunchedFailWhileAHSEnabled() { Configuration myConf = new Configuration(conf); myConf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED, true); @@ -1246,7 +1254,8 @@ public void testLaunchedFailWhileAHSEnabled() { assertEquals(rmAppPageUrl, myApplicationAttempt.getTrackingUrl()); } - @Test(timeout=20000) + @Test + @Timeout(value = 20) public void testRunningExpire() { Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); @@ -1258,8 +1267,8 @@ public void testRunningExpire() { sendAttemptUpdateSavedEvent(applicationAttempt); assertEquals(RMAppAttemptState.FAILED, applicationAttempt.getAppAttemptState()); - assertTrue("expire diagnostics missing", - applicationAttempt.getDiagnostics().contains("timed out")); + assertTrue( + applicationAttempt.getDiagnostics().contains("timed out"), "expire diagnostics missing"); String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app", applicationAttempt.getAppAttemptId().getApplicationId()); assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl()); @@ -1497,37 +1506,37 @@ public void testFinishedContainer() { ArgumentCaptor.forClass(RMNodeFinishedContainersPulledByAMEvent.class); // Verify justFinishedContainers - Assert.assertEquals(1, applicationAttempt.getJustFinishedContainers() + Assertions.assertEquals(1, applicationAttempt.getJustFinishedContainers() .size()); - Assert.assertEquals(container1.getId(), applicationAttempt + Assertions.assertEquals(container1.getId(), applicationAttempt .getJustFinishedContainers().get(0).getContainerId()); - Assert.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) + Assertions.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) .size()); // Verify finishedContainersSentToAM gets container after pull List containerStatuses = applicationAttempt .pullJustFinishedContainers(); - Assert.assertEquals(1, containerStatuses.size()); + Assertions.assertEquals(1, containerStatuses.size()); Mockito.verify(rmnodeEventHandler, never()).handle(Mockito .any(RMNodeEvent.class)); - Assert.assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); - Assert.assertEquals(1, getFinishedContainersSentToAM(applicationAttempt) + Assertions.assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); + Assertions.assertEquals(1, getFinishedContainersSentToAM(applicationAttempt) .size()); // Verify container is acked to NM via the RMNodeEvent after second pull containerStatuses = applicationAttempt.pullJustFinishedContainers(); - Assert.assertEquals(0, containerStatuses.size()); + Assertions.assertEquals(0, containerStatuses.size()); Mockito.verify(rmnodeEventHandler).handle(captor.capture()); - Assert.assertEquals(container1.getId(), captor.getValue().getContainers() + Assertions.assertEquals(container1.getId(), captor.getValue().getContainers() .get(0)); - Assert.assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); - Assert.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) + Assertions.assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); + Assertions.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) .size()); // verify if no containers to acknowledge to NM then event should not be // triggered. Number of times event invoked is 1 i.e on second pull containerStatuses = applicationAttempt.pullJustFinishedContainers(); - Assert.assertEquals(0, containerStatuses.size()); + Assertions.assertEquals(0, containerStatuses.size()); Mockito.verify(rmnodeEventHandler, times(1)) .handle(Mockito.any(RMNodeEvent.class)); } @@ -1561,11 +1570,11 @@ public void testFinishedContainerNotBeingPulledByAMHeartbeat() { // Verify justFinishedContainers ArgumentCaptor captor = ArgumentCaptor.forClass(RMNodeFinishedContainersPulledByAMEvent.class); - Assert.assertEquals(1, applicationAttempt.getJustFinishedContainers() + Assertions.assertEquals(1, applicationAttempt.getJustFinishedContainers() .size()); - Assert.assertEquals(container1.getId(), applicationAttempt + Assertions.assertEquals(container1.getId(), applicationAttempt .getJustFinishedContainers().get(0).getContainerId()); - Assert.assertTrue( + Assertions.assertTrue( getFinishedContainersSentToAM(applicationAttempt).isEmpty()); // finish AM container to emulate AM exit event @@ -1580,15 +1589,15 @@ public void testFinishedContainerNotBeingPulledByAMHeartbeat() { List containerPulledEvents = captor.getAllValues(); // Verify AM container is acked to NM via the RMNodeEvent immediately - Assert.assertEquals(amContainer.getId(), + Assertions.assertEquals(amContainer.getId(), containerPulledEvents.get(0).getContainers().get(0)); // Verify the non-AM container is acked to NM via the RMNodeEvent - Assert.assertEquals(container1.getId(), + Assertions.assertEquals(container1.getId(), containerPulledEvents.get(1).getContainers().get(0)); - Assert.assertTrue("No container shall be added to justFinishedContainers" + - " as soon as AM container exits", - applicationAttempt.getJustFinishedContainers().isEmpty()); - Assert.assertTrue( + Assertions.assertTrue( + applicationAttempt.getJustFinishedContainers().isEmpty(), "No container shall be added to justFinishedContainers" + + " as soon as AM container exits"); + Assertions.assertTrue( getFinishedContainersSentToAM(applicationAttempt).isEmpty()); } @@ -1617,7 +1626,7 @@ public void testFinishedContainerAfterAMExit() { ArgumentCaptor captor = ArgumentCaptor.forClass(RMNodeFinishedContainersPulledByAMEvent.class); Mockito.verify(rmnodeEventHandler).handle(captor.capture()); - Assert.assertEquals(amContainer.getId(), + Assertions.assertEquals(amContainer.getId(), captor.getValue().getContainers().get(0)); // Complete a non-AM container @@ -1636,12 +1645,12 @@ public void testFinishedContainerAfterAMExit() { captor = ArgumentCaptor.forClass( RMNodeFinishedContainersPulledByAMEvent.class); Mockito.verify(rmnodeEventHandler, times(2)).handle(captor.capture()); - Assert.assertEquals(container1.getId(), + Assertions.assertEquals(container1.getId(), captor.getAllValues().get(1).getContainers().get(0)); - Assert.assertTrue("No container shall be added to justFinishedContainers" + - " after AM container exited", - applicationAttempt.getJustFinishedContainers().isEmpty()); - Assert.assertTrue( + Assertions.assertTrue( + applicationAttempt.getJustFinishedContainers().isEmpty(), "No container shall be added to justFinishedContainers" + + " after AM container exited"); + Assertions.assertTrue( getFinishedContainersSentToAM(applicationAttempt).isEmpty()); } @@ -1666,14 +1675,14 @@ public void testGetClientToken() throws Exception { // before attempt is launched, can not get ClientToken Token token = applicationAttempt.createClientToken(null); - Assert.assertNull(token); + Assertions.assertNull(token); launchApplicationAttempt(amContainer); // after attempt is launched , can get ClientToken token = applicationAttempt.createClientToken(null); - Assert.assertNull(token); + Assertions.assertNull(token); token = applicationAttempt.createClientToken("clientuser"); - Assert.assertNotNull(token); + Assertions.assertNotNull(token); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt .getAppAttemptId(), RMAppAttemptEventType.KILL)); @@ -1682,9 +1691,9 @@ public void testGetClientToken() throws Exception { sendAttemptUpdateSavedEvent(applicationAttempt); // after attempt is killed, can not get Client Token token = applicationAttempt.createClientToken(null); - Assert.assertNull(token); + Assertions.assertNull(token); token = applicationAttempt.createClientToken("clientuser"); - Assert.assertNull(token); + Assertions.assertNull(token); } // this is to test master key is saved in the secret manager only after @@ -1696,10 +1705,10 @@ public void testApplicationAttemptMasterKey() throws Exception { boolean isMasterKeyExisted = clientToAMTokenManager.hasMasterKey(appid); if (isSecurityEnabled) { - Assert.assertTrue(isMasterKeyExisted); - Assert.assertNotNull(clientToAMTokenManager.getMasterKey(appid)); + Assertions.assertTrue(isMasterKeyExisted); + Assertions.assertNotNull(clientToAMTokenManager.getMasterKey(appid)); } else { - Assert.assertFalse(isMasterKeyExisted); + Assertions.assertFalse(isMasterKeyExisted); } launchApplicationAttempt(amContainer); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt @@ -1709,7 +1718,7 @@ public void testApplicationAttemptMasterKey() throws Exception { sendAttemptUpdateSavedEvent(applicationAttempt); // after attempt is killed, can not get MasterKey isMasterKeyExisted = clientToAMTokenManager.hasMasterKey(appid); - Assert.assertFalse(isMasterKeyExisted); + Assertions.assertFalse(isMasterKeyExisted); } @Test @@ -1862,7 +1871,8 @@ public Allocation answer(InvocationOnMock invocation) (RMAppAttemptImpl) applicationAttempt, null); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testNewToFailed() { applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt .getAppAttemptId(), RMAppAttemptEventType.FAIL, FAILED_DIAGNOSTICS)); @@ -1872,7 +1882,8 @@ public void testNewToFailed() { verifyTokenCount(applicationAttempt.getAppAttemptId(), 1); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testSubmittedToFailed() { submitApplicationAttempt(); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt @@ -1882,7 +1893,8 @@ public void testSubmittedToFailed() { testAppAttemptFailedState(null, FAILED_DIAGNOSTICS); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testScheduledToFailed() { scheduleApplicationAttempt(); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt @@ -1892,7 +1904,8 @@ public void testScheduledToFailed() { testAppAttemptFailedState(null, FAILED_DIAGNOSTICS); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testAllocatedToFailedUserTriggeredFailEvent() { Container amContainer = allocateApplicationAttempt(); assertEquals(YarnApplicationAttemptState.ALLOCATED, @@ -1902,7 +1915,8 @@ public void testAllocatedToFailedUserTriggeredFailEvent() { testAppAttemptFailedState(amContainer, FAILED_DIAGNOSTICS); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testRunningToFailedUserTriggeredFailEvent() { Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); @@ -1936,15 +1950,15 @@ public void testRunningToFailedUserTriggeredFailEvent() { private void verifyAMCrashAtAllocatedDiagnosticInfo(String diagnostics, int exitCode, boolean shouldCheckURL) { - assertTrue("Diagnostic information does not point the logs to the users", - diagnostics.contains("logs")); - assertTrue("Diagnostic information does not contain application attempt id", - diagnostics.contains(applicationAttempt.getAppAttemptId().toString())); - assertTrue("Diagnostic information does not contain application exit code", - diagnostics.contains("exitCode: " + exitCode)); + assertTrue( + diagnostics.contains("logs"), "Diagnostic information does not point the logs to the users"); + assertTrue( + diagnostics.contains(applicationAttempt.getAppAttemptId().toString()), "Diagnostic information does not contain application attempt id"); + assertTrue( + diagnostics.contains("exitCode: " + exitCode), "Diagnostic information does not contain application exit code"); if (shouldCheckURL) { - assertTrue("Diagnostic information does not contain application proxy URL", - diagnostics.contains(applicationAttempt.getTrackingUrl())); + assertTrue( + diagnostics.contains(applicationAttempt.getTrackingUrl()), "Diagnostic information does not contain application proxy URL"); } } @@ -1981,12 +1995,12 @@ private void verifyApplicationAttemptFinished(RMAppAttemptState state) { ArgumentCaptor.forClass(RMAppAttemptState.class); verify(writer).applicationAttemptFinished( any(RMAppAttempt.class), finalState.capture()); - Assert.assertEquals(state, finalState.getValue()); + Assertions.assertEquals(state, finalState.getValue()); finalState = ArgumentCaptor.forClass(RMAppAttemptState.class); verify(publisher).appAttemptFinished(any(RMAppAttempt.class), finalState.capture(), any(RMApp.class), anyLong()); - Assert.assertEquals(state, finalState.getValue()); + Assertions.assertEquals(state, finalState.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/rmcontainer/TestRMContainerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java index c16116f22c376..b0508d27e5a79 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java @@ -18,7 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.rmcontainer; -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.anyLong; import static org.mockito.Mockito.mock; @@ -74,8 +74,9 @@ import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -298,7 +299,7 @@ public void testExistenceOfResourceRequestInRMContainer() throws Exception { // Verify whether list of ResourceRequest is present in RMContainer // while moving to ALLOCATED state - Assert.assertNotNull( + Assertions.assertNotNull( scheduler.getRMContainer(containerId2).getContainerRequest()); // Allocate container @@ -308,11 +309,12 @@ public void testExistenceOfResourceRequestInRMContainer() throws Exception { // After RMContainer moving to ACQUIRED state, list of ResourceRequest will // be empty - Assert.assertNull( + Assertions.assertNull( scheduler.getRMContainer(containerId2).getContainerRequest()); } - @Test (timeout = 180000) + @Test + @Timeout(value = 180) public void testStoreAllContainerMetrics() throws Exception { Configuration conf = new Configuration(); conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -352,7 +354,8 @@ public void testStoreAllContainerMetrics() throws Exception { verify(publisher, times(2)).containerFinished(any(RMContainer.class), anyLong()); } - @Test (timeout = 180000) + @Test + @Timeout(value = 180) public void testStoreOnlyAMContainerMetrics() throws Exception { Configuration conf = new Configuration(); conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); @@ -446,7 +449,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() SchedulerRequestKey.extractFrom(container), appAttemptId, nodeId, "user", rmContext); - Assert.assertEquals(0, + Assertions.assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags( TestUtils.getMockApplicationId(1), null), @@ -456,7 +459,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.START)); schedulerNode.allocateContainer(rmContainer); - Assert.assertEquals(1, + Assertions.assertEquals(1, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -466,7 +469,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.KILL)); schedulerNode.releaseContainer(container.getId(), true); - Assert.assertEquals(0, + Assertions.assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -476,7 +479,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() SchedulerRequestKey.extractFrom(container), appAttemptId, nodeId, "user", rmContext); - Assert.assertEquals(0, + Assertions.assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -486,7 +489,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.START)); schedulerNode.allocateContainer(rmContainer); - Assert.assertEquals(1, + Assertions.assertEquals(1, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -499,7 +502,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.FINISHED)); schedulerNode.releaseContainer(container.getId(), true); - Assert.assertEquals(0, + Assertions.assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -510,7 +513,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() nodeId, "user", rmContext); rmContainer.setAllocationTags(ImmutableSet.of("mapper")); - Assert.assertEquals(0, + Assertions.assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -519,7 +522,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.START)); schedulerNode.allocateContainer(rmContainer); - Assert.assertEquals(1, + Assertions.assertEquals(1, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -535,7 +538,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.FINISHED)); schedulerNode.releaseContainer(container.getId(), true); - Assert.assertEquals(0, + Assertions.assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -546,7 +549,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() "user", rmContext); rmContainer.setAllocationTags(ImmutableSet.of("mapper")); - Assert.assertEquals(0, + Assertions.assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -559,13 +562,14 @@ public void testContainerTransitionNotifyAllocationTagsManager() rmContainer .handle(new RMContainerRecoverEvent(containerId, containerStatus)); - Assert.assertEquals(1, + Assertions.assertEquals(1, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); } - @Test(timeout = 30000) + @Test + @Timeout(value = 30) public void testContainerAcquiredAtKilled() { DrainDispatcher drainDispatcher = new DrainDispatcher(); EventHandler appAttemptEventHandler = mock( @@ -616,7 +620,7 @@ public void testContainerAcquiredAtKilled() { @Override protected void onInvalidStateTransition( RMContainerEventType rmContainerEventType, RMContainerState state) { - Assert.fail("RMContainerImpl: can't handle " + rmContainerEventType + Assertions.fail("RMContainerImpl: can't handle " + rmContainerEventType + " at state " + state); } }; From 7038f268ac377cfe36877107f12fa91c7c028ce0 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sat, 8 Mar 2025 20:24:20 +0800 Subject: [PATCH 2/5] YARN-11262. Fix Junit Test Error & CheckStyle Issue. --- .../TestAppNameMappingPlacementRule.java | 4 +- .../TestFairQueuePlacementUtils.java | 94 +++--- .../placement/TestPlacementFactory.java | 5 +- .../placement/TestPlacementManager.java | 13 +- .../placement/TestPlacementRuleFS.java | 4 +- .../TestUserGroupMappingPlacementRule.java | 10 +- .../TestCSMappingPlacementRule.java | 19 +- .../csmappingrule/TestMappingRuleActions.java | 5 +- .../TestMappingRuleMatchers.java | 58 ++-- .../TestMappingRuleValidationContextImpl.java | 5 +- .../csmappingrule/TestVariableContext.java | 22 +- .../preprocessor/TestContextProcessor.java | 4 +- .../preprocessor/TestQueueProcessor.java | 5 +- .../preprocessor/TestTagAddProcessor.java | 6 +- .../recovery/RMStateStoreTestBase.java | 125 +++---- .../TestCheckRemoveZKNodeRMStateStore.java | 75 +++-- .../recovery/TestFSRMStateStore.java | 28 +- .../recovery/TestMemoryRMStateStore.java | 8 +- .../resourcemanager/recovery/TestProtos.java | 6 +- .../recovery/TestRMStateStoreUtils.java | 4 +- .../recovery/TestZKRMStateStore.java | 285 ++++++++-------- ...TestZKRMStateStoreZKClientConnections.java | 4 +- .../reservation/BaseSharingPolicyTest.java | 8 - .../ReservationSystemTestUtil.java | 21 +- .../TestCapacityOverTimePolicy.java | 28 +- .../TestCapacitySchedulerPlanFollower.java | 18 +- .../TestFairSchedulerPlanFollower.java | 14 +- .../reservation/TestInMemoryPlan.java | 177 +++++----- .../TestInMemoryReservationAllocation.java | 37 ++- .../reservation/TestNoOverCommitPolicy.java | 28 +- ...stPeriodicRLESparseResourceAllocation.java | 71 ++-- .../TestRLESparseResourceAllocation.java | 119 +++---- .../TestReservationInputValidator.java | 257 +++++++-------- .../TestReservationSystemUtil.java | 18 +- .../TestSchedulerPlanFollowerBase.java | 42 +-- .../planning/TestAlignedPlanner.java | 132 ++++---- .../planning/TestGreedyReservationAgent.java | 102 ++++-- .../planning/TestReservationAgents.java | 31 +- .../planning/TestSimpleCapacityReplanner.java | 48 +-- .../resource/TestResourceProfiles.java | 37 ++- .../resourcetracker/TestNMExpiry.java | 6 +- .../TestRMNMRPCResponseId.java | 14 +- .../rmapp/TestApplicationLifetimeMonitor.java | 94 +++--- .../rmapp/TestRMAppTransitions.java | 310 ++++++++++-------- 44 files changed, 1290 insertions(+), 1111 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/placement/TestAppNameMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestAppNameMappingPlacementRule.java index 06f493408b7ff..4cdbf150cb9a9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestAppNameMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestAppNameMappingPlacementRule.java @@ -30,7 +30,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping; import org.apache.hadoop.yarn.util.Records; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,6 +37,7 @@ import java.util.Collections; import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -108,7 +108,7 @@ private void verifyQueueMapping(QueueMapping queueMapping, asc.setApplicationName(appName); ApplicationPlacementContext ctx = engine.getPlacementForApp(asc, user); - Assertions.assertEquals(expectedQueue, + assertEquals(expectedQueue, ctx != null ? ctx.getQueue() : inputQueue); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java index 7ffc4f82f6043..8b94bd7a13356 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java @@ -52,25 +52,25 @@ public void testCleanName() { String cleaned = cleanName(clean); assertEquals(clean, cleaned, "Name was changed and it should not"); cleaned = cleanName(dotted); - assertFalse( - cleaned.contains(DOT), "Cleaned name contains dots and it should not"); + assertFalse(cleaned.contains(DOT), + "Cleaned name contains dots and it should not"); cleaned = cleanName(multiDot); - assertFalse( - cleaned.contains(DOT), "Cleaned name contains dots and it should not"); - assertNotEquals( - cleaned.indexOf(DOT_REPLACEMENT) -, cleaned.lastIndexOf(DOT_REPLACEMENT), "Multi dot failed: wrong replacements found"); + assertFalse(cleaned.contains(DOT), + "Cleaned name contains dots and it should not"); + assertNotEquals(cleaned.indexOf(DOT_REPLACEMENT), + cleaned.lastIndexOf(DOT_REPLACEMENT), + "Multi dot failed: wrong replacements found"); cleaned = cleanName(seqDot); - assertFalse( - cleaned.contains(DOT), "Cleaned name contains dots and it should not"); - assertNotEquals( - cleaned.indexOf(DOT_REPLACEMENT) -, cleaned.lastIndexOf(DOT_REPLACEMENT), "Sequential dot failed: wrong replacements found"); + assertFalse(cleaned.contains(DOT), + "Cleaned name contains dots and it should not"); + assertNotEquals(cleaned.indexOf(DOT_REPLACEMENT), + cleaned.lastIndexOf(DOT_REPLACEMENT), + "Sequential dot failed: wrong replacements found"); cleaned = cleanName(unTrimmed); - assertTrue( - cleaned.startsWith(DOT_REPLACEMENT), "Trimming start failed: space not removed or dot not replaced"); - assertTrue( - cleaned.endsWith(DOT_REPLACEMENT), "Trimming end failed: space not removed or dot not replaced"); + assertTrue(cleaned.startsWith(DOT_REPLACEMENT), + "Trimming start failed: space not removed or dot not replaced"); + assertTrue(cleaned.endsWith(DOT_REPLACEMENT), + "Trimming end failed: space not removed or dot not replaced"); } @Test @@ -82,23 +82,22 @@ public void testAssureRoot() { final String alreadyRoot = "root.base"; String rooted = assureRoot(queueName); - assertTrue( - rooted.startsWith(ROOT_QUEUE + DOT), "Queue should have root prefix (base)"); + assertTrue(rooted.startsWith(ROOT_QUEUE + DOT), + "Queue should have root prefix (base)"); rooted = assureRoot(rootOnly); - assertEquals( - rootOnly, rooted, "'root' queue should not have root prefix (root)"); + assertEquals(rootOnly, rooted, + "'root' queue should not have root prefix (root)"); rooted = assureRoot(rootNoDot); - assertTrue( - rooted.startsWith(ROOT_QUEUE + DOT), "Queue should have root prefix (rootbase)"); - assertEquals(5 -, rooted.lastIndexOf(ROOT_QUEUE), "'root' queue base was replaced and not prefixed"); + assertTrue(rooted.startsWith(ROOT_QUEUE + DOT), + "Queue should have root prefix (rootbase)"); + assertEquals(5, rooted.lastIndexOf(ROOT_QUEUE), + "'root' queue base was replaced and not prefixed"); rooted = assureRoot(alreadyRoot); - assertEquals( - rooted, alreadyRoot, "Root prefixed queue changed and it should not (root.base)"); - assertNull( - assureRoot(null), "Null queue did not return null queue"); - assertEquals("Empty queue did not return empty name", "", - assureRoot("")); + assertEquals(rooted, alreadyRoot, + "Root prefixed queue changed and it should not (root.base)"); + assertNull(assureRoot(null), "Null queue did not return null queue"); + assertEquals("", assureRoot(""), + "Empty queue did not return empty name"); } @Test @@ -113,25 +112,24 @@ public void testIsValidQueueName() { final String endSpace = "invalid "; final String unicodeSpace = "\u00A0invalid"; - assertFalse( - isValidQueueName(null), "'null' queue was not marked as invalid"); + assertFalse(isValidQueueName(null), "'null' queue was not marked as invalid"); assertTrue(isValidQueueName(""), "empty queue was not tagged valid"); - assertTrue( - isValidQueueName(valid), "Simple queue name was not tagged valid (valid)"); - assertTrue( - isValidQueueName(rootOnly), "Root only queue was not tagged valid (root)"); - assertTrue( - isValidQueueName(validRooted), "Root prefixed queue was not tagged valid (root.valid)"); - assertFalse( - isValidQueueName(startDot), "Queue starting with dot was not tagged invalid (.invalid)"); - assertFalse( - isValidQueueName(endDot), "Queue ending with dot was not tagged invalid (invalid.)"); - assertFalse( - isValidQueueName(startSpace), "Queue starting with space was not tagged invalid ( invalid)"); - assertFalse( - isValidQueueName(endSpace), "Queue ending with space was not tagged invalid (invalid )"); + assertTrue(isValidQueueName(valid), + "Simple queue name was not tagged valid (valid)"); + assertTrue(isValidQueueName(rootOnly), + "Root only queue was not tagged valid (root)"); + assertTrue(isValidQueueName(validRooted), + "Root prefixed queue was not tagged valid (root.valid)"); + assertFalse(isValidQueueName(startDot), + "Queue starting with dot was not tagged invalid (.invalid)"); + assertFalse(isValidQueueName(endDot), + "Queue ending with dot was not tagged invalid (invalid.)"); + assertFalse(isValidQueueName(startSpace), + "Queue starting with space was not tagged invalid ( invalid)"); + assertFalse(isValidQueueName(endSpace), + "Queue ending with space was not tagged invalid (invalid )"); // just one for sanity check extensive tests are in the scheduler utils - assertFalse( - isValidQueueName(unicodeSpace), "Queue with unicode space was not tagged as invalid (unicode)"); + assertFalse(isValidQueueName(unicodeSpace), + "Queue with unicode space was not tagged as invalid (unicode)"); } } \ 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/placement/TestPlacementFactory.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementFactory.java index ba6cf5e89b0d8..90fa481d2c465 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementFactory.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementFactory.java @@ -20,7 +20,10 @@ import org.junit.jupiter.api.Test; -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.fail; /** * Test for the {@link PlacementFactory}. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementManager.java index ca4d96e647855..4f286edf24f06 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementManager.java @@ -29,7 +29,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; import org.apache.hadoop.yarn.util.Records; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,6 +37,9 @@ import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT; import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.setupQueueConfiguration; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class TestPlacementManager { @@ -96,8 +98,7 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception { asc.setQueue(YarnConfiguration.DEFAULT_QUEUE_NAME); asc.setApplicationName(APP_NAME); - Assertions.assertNull( - pm.placeApplication(asc, USER2), "Placement should be null"); + assertNull(pm.placeApplication(asc, USER2), "Placement should be null"); QueueMapping queueMappingEntity = QueueMapping.QueueMappingBuilder.create() .type(MappingType.APPLICATION) .source(APP_NAME) @@ -112,7 +113,7 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception { queuePlacementRules.add(anRule); pm.updateRules(queuePlacementRules); ApplicationPlacementContext pc = pm.placeApplication(asc, USER2); - Assertions.assertNotNull(pc); + assertNotNull(pc); } @Test @@ -135,9 +136,9 @@ public void testPlacementRuleUpdationOrder() throws Exception { // As we are setting placement rule, It shouldn't update default // placement rule ie user-group. Number of placement rules should be 1. - Assertions.assertEquals(1, pm.getPlacementRules().size()); + assertEquals(1, pm.getPlacementRules().size()); // Verifying if placement rule set is same as the one we configured - Assertions.assertEquals(ugRule.getName(), + assertEquals(ugRule.getName(), pm.getPlacementRules().get(0).getName()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java index f7c543d4882b9..85d8a4fbcbfeb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java @@ -183,8 +183,8 @@ private void ruleInit(Class ruleClass) { } catch (IOException ioe) { exceptionThrown = true; } - assertTrue(exceptionThrown, "Initialize with parent rule should have thrown exception " + - name); + assertTrue(exceptionThrown, + "Initialize with parent rule should have thrown exception " + name); } private Element createConf(String str) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestUserGroupMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestUserGroupMappingPlacementRule.java index 8a1747a3296d7..6998134d83efa 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestUserGroupMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestUserGroupMappingPlacementRule.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.placement; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.isNull; @@ -42,7 +43,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.PrimaryGroupMapping; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping; import org.apache.hadoop.yarn.util.Records; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -94,11 +94,11 @@ private void verifyQueueMapping(QueueMappingTestData queueMappingTestData) ApplicationSubmissionContext.class); asc.setQueue(inputQueue); ApplicationPlacementContext ctx = engine.getPlacementForApp(asc, inputUser); - Assertions.assertEquals(expectedQueue -, ctx != null ? ctx.getQueue() : inputQueue, "Queue"); + assertEquals(expectedQueue, + ctx != null ? ctx.getQueue() : inputQueue, "Queue"); if (ctx != null && expectedParentQueue != null) { - Assertions.assertEquals(expectedParentQueue -, ctx.getParentQueue(), "Parent Queue"); + assertEquals(expectedParentQueue, + ctx.getParentQueue(), "Parent 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/placement/csmappingrule/TestCSMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java index 80c03b6b739af..7b8b2b5a2d539 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java @@ -33,9 +33,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; import org.apache.hadoop.yarn.util.Records; -import org.junit.Rule; import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,13 +42,19 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_GROUP_MAPPING; -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.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.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -59,8 +64,8 @@ public class TestCSMappingPlacementRule { private static final Logger LOG = LoggerFactory .getLogger(TestCSMappingPlacementRule.class); - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + static Path folder; private Map> userGroups = ImmutableMap.>builder() @@ -185,7 +190,7 @@ private void assertPlace(String message, CSMappingPlacementRule engine, String queue = apc.getParentQueue() == null ? "" : (apc.getParentQueue() + DOT); queue += apc.getQueue(); - assertEquals(message, expectedQueue, queue); + assertEquals(expectedQueue, queue, message); } catch (YarnException e) { LOG.error(message, e); fail(message); @@ -706,7 +711,7 @@ public void testJSONFileConfiguration() throws IOException { conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT, CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT_JSON); - File jsonFile = folder.newFile("testJSONFileConfiguration.json"); + File jsonFile = folder.resolve("testJSONFileConfiguration.json").toFile(); BufferedWriter writer = new BufferedWriter(new FileWriter(jsonFile)); try { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleActions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleActions.java index 909e46b0cb6b9..ed7d7b1019ebe 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleActions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleActions.java @@ -20,7 +20,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.placement.VariableContext; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestMappingRuleActions { void assertRejectResult(MappingRuleResult 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/placement/csmappingrule/TestMappingRuleMatchers.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java index 3e9e69e44acc0..654cf3af9a243 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java @@ -66,12 +66,12 @@ public void testVariableMatcher() { new MappingRuleMatchers.VariableMatcher("%custom", "Matching string")); matchers.forEach((matcherName, matcher) -> { - assertTrue( - matcher.match(matchingContext), matcherName + " with matchingContext should match"); - assertFalse( - matcher.match(mismatchingContext), matcherName + " with mismatchingContext shouldn't match"); - assertFalse( - matcher.match(emptyContext), matcherName + " with emptyContext shouldn't match"); + assertTrue(matcher.match(matchingContext), + matcherName + " with matchingContext should match"); + assertFalse(matcher.match(mismatchingContext), + matcherName + " with mismatchingContext shouldn't match"); + assertFalse(matcher.match(emptyContext), + matcherName + " with emptyContext shouldn't match"); }); } @@ -108,31 +108,27 @@ public void testVariableMatcherSubstitutions() { MappingRuleMatcher userStatic = new MappingRuleMatchers.VariableMatcher("%user", "bob"); - assertTrue( - customUser.match(matchingContext), "%custom should match %user in matching context"); - assertTrue( - userCustom.match(matchingContext), "%user should match %custom in matching context"); - assertTrue( - userCusTom.match(matchingContext), "%user (bob) should match %cus%tom (b + ob) in matching context"); - assertTrue( - userUser.match(matchingContext), "%user should match %user in any context"); - assertTrue( - userStatic.match(matchingContext), "%user (bob) should match bob in in matching context"); - - assertFalse( - - customUser.match(mismatchingContext), "%custom (bob) should NOT match %user (dave) in mismatching context"); - assertFalse( - - userCustom.match(mismatchingContext), "%user (dave) should NOT match %custom (bob) in mismatching context"); - assertFalse( - - userCusTom.match(mismatchingContext), "%user (dave) should NOT match %cus%tom (b+ob) in mismatching context"); - assertTrue( - userUser.match(mismatchingContext), "%user should match %user in any context"); - assertFalse( - - userStatic.match(mismatchingContext), "%user (dave) should NOT match match bob in in matching context"); + assertTrue(customUser.match(matchingContext), + "%custom should match %user in matching context"); + assertTrue(userCustom.match(matchingContext), + "%user should match %custom in matching context"); + assertTrue(userCusTom.match(matchingContext), + "%user (bob) should match %cus%tom (b + ob) in matching context"); + assertTrue(userUser.match(matchingContext), + "%user should match %user in any context"); + assertTrue(userStatic.match(matchingContext), + "%user (bob) should match bob in in matching context"); + + assertFalse(customUser.match(mismatchingContext), + "%custom (bob) should NOT match %user (dave) in mismatching context"); + assertFalse(userCustom.match(mismatchingContext), + "%user (dave) should NOT match %custom (bob) in mismatching context"); + assertFalse(userCusTom.match(mismatchingContext), + "%user (dave) should NOT match %cus%tom (b+ob) in mismatching context"); + assertTrue(userUser.match(mismatchingContext), + "%user should match %user in any context"); + assertFalse(userStatic.match(mismatchingContext), + "%user (dave) should NOT match match bob in in matching context"); } @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/placement/csmappingrule/TestMappingRuleValidationContextImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleValidationContextImpl.java index d6a59ac7615f1..6e2ad9f736147 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleValidationContextImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleValidationContextImpl.java @@ -23,7 +23,10 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; import org.junit.jupiter.api.Test; -import static 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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestVariableContext.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestVariableContext.java index 6f7b5aa7e1d81..080908adac272 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestVariableContext.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestVariableContext.java @@ -26,7 +26,13 @@ import java.util.HashSet; import java.util.Set; -import static 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 static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestVariableContext { @@ -51,10 +57,10 @@ public void testAddAndGet() { @Test public void testImmutablesCanOnlySetOnceFromSet() { - assertThrows(IllegalStateException.class, ()->{ + assertThrows(IllegalStateException.class, () -> { VariableContext variables = new VariableContext(); ImmutableSet immutables = - ImmutableSet.of("%user", "%primary_group", "%secondary_group"); + ImmutableSet.of("%user", "%primary_group", "%secondary_group"); variables.setImmutables(immutables); variables.setImmutables(immutables); @@ -63,7 +69,7 @@ public void testImmutablesCanOnlySetOnceFromSet() { @Test public void testImmutablesCanOnlySetOnceFromArray() { - assertThrows(IllegalStateException.class, ()->{ + assertThrows(IllegalStateException.class, () -> { VariableContext variables = new VariableContext(); variables.setImmutables("%user", "%primary_group", "%secondary_group"); @@ -73,10 +79,10 @@ public void testImmutablesCanOnlySetOnceFromArray() { @Test public void testImmutablesCanOnlySetOnceFromSetAndArray() { - assertThrows(IllegalStateException.class, ()->{ + assertThrows(IllegalStateException.class, () -> { VariableContext variables = new VariableContext(); ImmutableSet immutables = - ImmutableSet.of("%user", "%primary_group", "%secondary_group"); + ImmutableSet.of("%user", "%primary_group", "%secondary_group"); variables.setImmutables(immutables); variables.setImmutables("%user", "%primary_group", "%secondary_group"); @@ -95,10 +101,10 @@ public void testImmutableVariableCanBeSetOnce() { @Test public void testImmutableVariableProtection() { - assertThrows(IllegalStateException.class, ()->{ + assertThrows(IllegalStateException.class, () -> { VariableContext variables = new VariableContext(); ImmutableSet immutables = - ImmutableSet.of("%user", "%primary_group", "%secondary_group"); + ImmutableSet.of("%user", "%primary_group", "%secondary_group"); variables.setImmutables(immutables); variables.put("%user", "bob"); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestContextProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestContextProcessor.java index d4b75e6f57cd1..708c2899039d2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestContextProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestContextProcessor.java @@ -26,7 +26,9 @@ import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; import org.junit.jupiter.api.Test; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestQueueProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestQueueProcessor.java index 4330eaa75a65f..421d5c6fc25de 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestQueueProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestQueueProcessor.java @@ -22,7 +22,10 @@ import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; import org.junit.jupiter.api.Test; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestTagAddProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestTagAddProcessor.java index b39dff88e6e55..6d5880c088189 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestTagAddProcessor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/preprocessor/TestTagAddProcessor.java @@ -23,7 +23,11 @@ import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; import org.junit.jupiter.api.Test; -import static org.mockito.Mockito.*; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java index 40720f3cc7c54..73a92da17b859 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java @@ -20,7 +20,9 @@ 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.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -86,7 +88,6 @@ import org.apache.hadoop.yarn.server.webproxy.ProxyCA; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.jupiter.api.Assertions; public class RMStateStoreTestBase { @@ -484,13 +485,13 @@ public void testRMDTSecretManagerStateStore( RMDTSecretManagerState secretManagerState = store.loadState().getRMDTSecretManagerState(); - Assertions.assertEquals(token1, secretManagerState.getTokenState()); - Assertions.assertEquals(keySet, secretManagerState.getMasterKeyState()); - Assertions.assertEquals(sequenceNumber, + assertEquals(token1, secretManagerState.getTokenState()); + assertEquals(keySet, secretManagerState.getMasterKeyState()); + assertEquals(sequenceNumber, secretManagerState.getDTSequenceNumber()); RMDelegationTokenIdentifier tokenAfterStore = secretManagerState.getTokenState().keySet().iterator().next(); - Assertions.assertTrue(Arrays.equals(tokenBeforeStore, + assertTrue(Arrays.equals(tokenBeforeStore, tokenAfterStore.getBytes())); // update RM delegation token; @@ -500,9 +501,9 @@ public void testRMDTSecretManagerStateStore( RMDTSecretManagerState updateSecretManagerState = store.loadState().getRMDTSecretManagerState(); - Assertions.assertEquals(token1, updateSecretManagerState.getTokenState()); - Assertions.assertEquals(keySet, updateSecretManagerState.getMasterKeyState()); - Assertions.assertEquals(sequenceNumber, + assertEquals(token1, updateSecretManagerState.getTokenState()); + assertEquals(keySet, updateSecretManagerState.getMasterKeyState()); + assertEquals(sequenceNumber, updateSecretManagerState.getDTSequenceNumber()); // check to delete delegationKey @@ -510,9 +511,9 @@ public void testRMDTSecretManagerStateStore( keySet.clear(); RMDTSecretManagerState noKeySecretManagerState = store.loadState().getRMDTSecretManagerState(); - Assertions.assertEquals(token1, noKeySecretManagerState.getTokenState()); - Assertions.assertEquals(keySet, noKeySecretManagerState.getMasterKeyState()); - Assertions.assertEquals(sequenceNumber, + assertEquals(token1, noKeySecretManagerState.getTokenState()); + assertEquals(keySet, noKeySecretManagerState.getMasterKeyState()); + assertEquals(sequenceNumber, noKeySecretManagerState.getDTSequenceNumber()); // check to delete delegationToken @@ -520,11 +521,11 @@ public void testRMDTSecretManagerStateStore( RMDTSecretManagerState noKeyAndTokenSecretManagerState = store.loadState().getRMDTSecretManagerState(); token1.clear(); - Assertions.assertEquals(token1, + assertEquals(token1, noKeyAndTokenSecretManagerState.getTokenState()); - Assertions.assertEquals(keySet, + assertEquals(keySet, noKeyAndTokenSecretManagerState.getMasterKeyState()); - Assertions.assertEquals(sequenceNumber, + assertEquals(sequenceNumber, noKeySecretManagerState.getDTSequenceNumber()); store.close(); @@ -547,17 +548,17 @@ public void testCheckVersion(RMStateStoreHelper stateStoreHelper) // default version Version defaultVersion = stateStoreHelper.getCurrentVersion(); store.checkVersion(); - Assertions.assertEquals(defaultVersion, store.loadVersion()); + assertEquals(defaultVersion, store.loadVersion()); // compatible version Version compatibleVersion = Version.newInstance(defaultVersion.getMajorVersion(), defaultVersion.getMinorVersion() + 2); stateStoreHelper.writeVersion(compatibleVersion); - Assertions.assertEquals(compatibleVersion, store.loadVersion()); + assertEquals(compatibleVersion, store.loadVersion()); store.checkVersion(); // overwrite the compatible version - Assertions.assertEquals(defaultVersion, store.loadVersion()); + assertEquals(defaultVersion, store.loadVersion()); // incompatible version Version incompatibleVersion = @@ -566,9 +567,9 @@ public void testCheckVersion(RMStateStoreHelper stateStoreHelper) stateStoreHelper.writeVersion(incompatibleVersion); try { store.checkVersion(); - Assertions.fail("Invalid version, should fail."); + fail("Invalid version, should fail."); } catch (Throwable t) { - Assertions.assertTrue(t instanceof RMStateVersionIncompatibleException); + assertTrue(t instanceof RMStateVersionIncompatibleException); } } @@ -578,13 +579,13 @@ public void testEpoch(RMStateStoreHelper stateStoreHelper) store.setRMDispatcher(new TestDispatcher()); long firstTimeEpoch = store.getAndIncrementEpoch(); - Assertions.assertEquals(epoch, firstTimeEpoch); + assertEquals(epoch, firstTimeEpoch); long secondTimeEpoch = store.getAndIncrementEpoch(); - Assertions.assertEquals(epoch + 1, secondTimeEpoch); + assertEquals(epoch + 1, secondTimeEpoch); long thirdTimeEpoch = store.getAndIncrementEpoch(); - Assertions.assertEquals(epoch + 2, thirdTimeEpoch); + assertEquals(epoch + 2, thirdTimeEpoch); for (int i = 0; i < epochRange; ++i) { store.getAndIncrementEpoch(); @@ -592,7 +593,7 @@ public void testEpoch(RMStateStoreHelper stateStoreHelper) long wrappedEpoch = store.getAndIncrementEpoch(); // Epoch should have wrapped around and then incremented once for a total // of + 3 - Assertions.assertEquals(epoch + 3, wrappedEpoch); + assertEquals(epoch + 3, wrappedEpoch); } public void testAppDeletion(RMStateStoreHelper stateStoreHelper) @@ -625,7 +626,7 @@ private ArrayList createAndStoreApps( appList.add(app); } - Assertions.assertEquals(numApps, appList.size()); + assertEquals(numApps, appList.size()); for (RMApp app : appList) { // wait for app to be stored. while (true) { @@ -646,7 +647,7 @@ public void testDeleteStore(RMStateStoreHelper stateStoreHelper) store.deleteStore(); // verify apps deleted for (RMApp app : appList) { - Assertions.assertFalse(stateStoreHelper.appExists(app)); + assertFalse(stateStoreHelper.appExists(app)); } } @@ -659,10 +660,10 @@ public void testRemoveApplication(RMStateStoreHelper stateStoreHelper) RMApp rmApp1 = appList.get(0); store.removeApplication(rmApp1.getApplicationId()); - Assertions.assertFalse(stateStoreHelper.appExists(rmApp1)); + assertFalse(stateStoreHelper.appExists(rmApp1)); RMApp rmApp2 = appList.get(1); - Assertions.assertTrue(stateStoreHelper.appExists(rmApp2)); + assertTrue(stateStoreHelper.appExists(rmApp2)); } public void testRemoveAttempt(RMStateStoreHelper stateStoreHelper) @@ -685,8 +686,8 @@ public void testRemoveAttempt(RMStateStoreHelper stateStoreHelper) ContainerId.newContainerId(attemptId2, 1).toString(), null, null, dispatcher); store.removeApplicationAttemptInternal(attemptId1); - Assertions.assertFalse(stateStoreHelper.attemptExists(attempt1)); - Assertions.assertTrue(stateStoreHelper.attemptExists(attempt2)); + assertFalse(stateStoreHelper.attemptExists(attempt1)); + assertTrue(stateStoreHelper.attemptExists(attempt2)); // let things settle down Thread.sleep(1000); @@ -742,10 +743,10 @@ public void testAMRMTokenSecretManagerStateStore( when(rmContext.getStateStore()).thenReturn(store); store.setRMDispatcher(dispatcher); RMState state = store.loadState(); - Assertions.assertNotNull(state.getAMRMTokenSecretManagerState()); - Assertions.assertEquals(firstMasterKeyData.getMasterKey(), state + assertNotNull(state.getAMRMTokenSecretManagerState()); + assertEquals(firstMasterKeyData.getMasterKey(), state .getAMRMTokenSecretManagerState().getCurrentMasterKey()); - Assertions.assertNull(state + assertNull(state .getAMRMTokenSecretManagerState().getNextMasterKey()); //create and save the second masterkey @@ -762,18 +763,18 @@ public void testAMRMTokenSecretManagerStateStore( when(rmContext.getStateStore()).thenReturn(store); store.setRMDispatcher(dispatcher); RMState state_2 = store.loadState(); - Assertions.assertNotNull(state_2.getAMRMTokenSecretManagerState()); - Assertions.assertEquals(firstMasterKeyData.getMasterKey(), state_2 + assertNotNull(state_2.getAMRMTokenSecretManagerState()); + assertEquals(firstMasterKeyData.getMasterKey(), state_2 .getAMRMTokenSecretManagerState().getCurrentMasterKey()); - Assertions.assertEquals(secondMasterKeyData.getMasterKey(), state_2 + assertEquals(secondMasterKeyData.getMasterKey(), state_2 .getAMRMTokenSecretManagerState().getNextMasterKey()); // re-create the masterKeyData based on the recovered masterkey // should have the same secretKey appTokenMgr.recover(state_2); - Assertions.assertEquals(appTokenMgr.getCurrnetMasterKeyData().getSecretKey(), + assertEquals(appTokenMgr.getCurrnetMasterKeyData().getSecretKey(), firstMasterKeyData.getSecretKey()); - Assertions.assertEquals(appTokenMgr.getNextMasterKeyData().getSecretKey(), + assertEquals(appTokenMgr.getNextMasterKeyData().getSecretKey(), secondMasterKeyData.getSecretKey()); store.close(); @@ -814,7 +815,7 @@ public void testReservationStateStore( RMState state = store.loadState(); Map> reservationState = state.getReservationState(); - Assertions.assertNotNull(reservationState); + assertNotNull(reservationState); // 2. Store single reservation and verify String reservationIdName = r1.toString(); @@ -868,12 +869,12 @@ public void testReservationStateStore( store.setRMDispatcher(dispatcher); state = store.loadState(); reservationState = state.getReservationState(); - Assertions.assertNotNull(reservationState); + assertNotNull(reservationState); reservations = reservationState.get(planName); - Assertions.assertNotNull(reservations); + assertNotNull(reservations); ReservationAllocationStateProto storedReservationAllocation = reservations.get(r1); - Assertions.assertNull( + assertNull( storedReservationAllocation, "Removed reservation should not be available in store"); storedReservationAllocation = reservations.get(r2); @@ -890,9 +891,9 @@ public void testReservationStateStore( store.setRMDispatcher(dispatcher); state = store.loadState(); reservationState = state.getReservationState(); - Assertions.assertNotNull(reservationState); + assertNotNull(reservationState); reservations = reservationState.get(planName); - Assertions.assertNull(reservations); + assertNull(reservations); } public void testProxyCA( @@ -908,22 +909,22 @@ public void testProxyCA( RMStateStore.ProxyCAState proxyCAState = store.loadState().getProxyCAState(); - Assertions.assertEquals(originalProxyCA.getCaCert(), proxyCAState.getCaCert()); - Assertions.assertEquals(originalProxyCA.getCaKeyPair().getPrivate(), + assertEquals(originalProxyCA.getCaCert(), proxyCAState.getCaCert()); + assertEquals(originalProxyCA.getCaKeyPair().getPrivate(), proxyCAState.getCaPrivateKey()); // Try replacing with a different ProxyCA ProxyCA newProxyCA = new ProxyCA(); newProxyCA.init(); - Assertions.assertNotEquals(originalProxyCA.getCaCert(), newProxyCA.getCaCert()); - Assertions.assertNotEquals(originalProxyCA.getCaKeyPair().getPrivate(), + assertNotEquals(originalProxyCA.getCaCert(), newProxyCA.getCaCert()); + assertNotEquals(originalProxyCA.getCaKeyPair().getPrivate(), newProxyCA.getCaKeyPair().getPrivate()); store.storeProxyCACert(newProxyCA.getCaCert(), newProxyCA.getCaKeyPair().getPrivate()); proxyCAState = store.loadState().getProxyCAState(); - Assertions.assertEquals(newProxyCA.getCaCert(), proxyCAState.getCaCert()); - Assertions.assertEquals(newProxyCA.getCaKeyPair().getPrivate(), + assertEquals(newProxyCA.getCaCert(), proxyCAState.getCaCert()); + assertEquals(newProxyCA.getCaKeyPair().getPrivate(), proxyCAState.getCaPrivateKey()); } @@ -938,13 +939,13 @@ private void validateStoredReservation( RMState state = store.loadState(); Map> reservationState = state.getReservationState(); - Assertions.assertNotNull(reservationState); + assertNotNull(reservationState); Map reservations = reservationState.get(planName); - Assertions.assertNotNull(reservations); + assertNotNull(reservations); ReservationAllocationStateProto storedReservationAllocation = reservations.get(r1); - Assertions.assertNotNull(storedReservationAllocation); + assertNotNull(storedReservationAllocation); assertAllocationStateEqual( allocationStateProto, storedReservationAllocation); @@ -955,12 +956,12 @@ void assertAllocationStateEqual( ReservationAllocationStateProto expected, ReservationAllocationStateProto actual) { - Assertions.assertEquals( + assertEquals( expected.getAcceptanceTime(), actual.getAcceptanceTime()); - Assertions.assertEquals(expected.getStartTime(), actual.getStartTime()); - Assertions.assertEquals(expected.getEndTime(), actual.getEndTime()); - Assertions.assertEquals(expected.getContainsGangs(), actual.getContainsGangs()); - Assertions.assertEquals(expected.getUser(), actual.getUser()); + assertEquals(expected.getStartTime(), actual.getStartTime()); + assertEquals(expected.getEndTime(), actual.getEndTime()); + assertEquals(expected.getContainsGangs(), actual.getContainsGangs()); + assertEquals(expected.getUser(), actual.getUser()); assertEquals( expected.getReservationDefinition(), actual.getReservationDefinition()); assertEquals(expected.getAllocationRequestsList(), @@ -970,12 +971,12 @@ void assertAllocationStateEqual( void assertAllocationStateEqual( ReservationAllocation expected, ReservationAllocationStateProto actual) { - Assertions.assertEquals( + assertEquals( expected.getAcceptanceTime(), actual.getAcceptanceTime()); - Assertions.assertEquals(expected.getStartTime(), actual.getStartTime()); - Assertions.assertEquals(expected.getEndTime(), actual.getEndTime()); - Assertions.assertEquals(expected.containsGangs(), actual.getContainsGangs()); - Assertions.assertEquals(expected.getUser(), actual.getUser()); + assertEquals(expected.getStartTime(), actual.getStartTime()); + assertEquals(expected.getEndTime(), actual.getEndTime()); + assertEquals(expected.containsGangs(), actual.getContainsGangs()); + assertEquals(expected.getUser(), actual.getUser()); assertEquals( expected.getReservationDefinition(), ReservationSystemUtil.convertFromProtoFormat( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestCheckRemoveZKNodeRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestCheckRemoveZKNodeRMStateStore.java index c4019a899b0fd..a547e673a0825 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestCheckRemoveZKNodeRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestCheckRemoveZKNodeRMStateStore.java @@ -53,8 +53,17 @@ import java.io.IOException; -import org.mockito.Mockito; -import org.junit.jupiter.api.Assertions; +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.anyList; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class TestCheckRemoveZKNodeRMStateStore extends RMStateStoreTestBase { @@ -102,31 +111,31 @@ class TestZKRMStateStoreInternal extends ZKRMStateStore { private ZKCuratorManager zkCuratorManager; TestZKRMStateStoreInternal(Configuration conf, String workingZnode) throws Exception { - resourceManager = Mockito.mock(ResourceManager.class); - zkCuratorManager = Mockito.mock(ZKCuratorManager.class, Mockito.RETURNS_DEEP_STUBS); + resourceManager = mock(ResourceManager.class); + zkCuratorManager = mock(ZKCuratorManager.class, RETURNS_DEEP_STUBS); - Mockito.when(resourceManager.getZKManager()).thenReturn(zkCuratorManager); - Mockito.when(resourceManager.createAndStartZKManager(conf)).thenReturn(zkCuratorManager); - Mockito.when(zkCuratorManager.exists(getAppNode("application_1708333280_0001"))) + when(resourceManager.getZKManager()).thenReturn(zkCuratorManager); + when(resourceManager.createAndStartZKManager(conf)).thenReturn(zkCuratorManager); + when(zkCuratorManager.exists(getAppNode("application_1708333280_0001"))) .thenReturn(true); - Mockito.when(zkCuratorManager.exists(getAppNode("application_1708334188_0001"))) + when(zkCuratorManager.exists(getAppNode("application_1708334188_0001"))) .thenReturn(true).thenReturn(false); - Mockito.when(zkCuratorManager.exists(getDelegationTokenNode(0, 0))) + when(zkCuratorManager.exists(getDelegationTokenNode(0, 0))) .thenReturn(true).thenReturn(false); - Mockito.when(zkCuratorManager.exists(getAppNode("application_1709705779_0001"))) + when(zkCuratorManager.exists(getAppNode("application_1709705779_0001"))) .thenReturn(true); - Mockito.when(zkCuratorManager.exists(getAttemptNode("application_1709705779_0001", + when(zkCuratorManager.exists(getAttemptNode("application_1709705779_0001", "appattempt_1709705779_0001_000001"))) .thenReturn(true); - Mockito.doThrow(new KeeperException.NoNodeException()).when(zkCuratorManager) - .safeDelete(Mockito.anyString(), Mockito.anyList(), Mockito.anyString()); + doThrow(new KeeperException.NoNodeException()).when(zkCuratorManager) + .safeDelete(anyString(), anyList(), anyString()); setResourceManager(resourceManager); init(conf); dispatcher.disableExitOnDispatchException(); start(); - Assertions.assertTrue(znodeWorkingPath.equals(workingZnode)); + assertTrue(znodeWorkingPath.equals(workingZnode)); } private String getVersionNode() { @@ -264,12 +273,12 @@ public void testRemoveAttempt(RMStateStoreHelper stateStoreHelper) throws Except try { store.removeApplicationAttemptInternal(attemptIdRemoved); } catch (KeeperException.NoNodeException nne) { - Assertions.fail("NoNodeException should not happen."); + fail("NoNodeException should not happen."); } // The verification method safeDelete is called once. - Mockito.verify(store.resourceManager.getZKManager(), Mockito.times(1)) - .safeDelete(Mockito.anyString(), Mockito.anyList(), Mockito.anyString()); + verify(store.resourceManager.getZKManager(), times(1)) + .safeDelete(anyString(), anyList(), anyString()); store.close(); } @@ -298,7 +307,7 @@ public void testRemoveApplication(RMStateStoreHelper stateStoreHelper) throws Ex // The occurrence of NoNodeException is induced by calling the safeDelete method. store.removeApplicationStateInternal(appStateRemoved); } catch (KeeperException.NoNodeException nne) { - Assertions.fail("NoNodeException should not happen."); + fail("NoNodeException should not happen."); } store.close(); @@ -314,12 +323,12 @@ public void testRemoveRMDelegationToken(RMStateStoreHelper stateStoreHelper) thr try { store.removeRMDelegationTokenState(tokenIdRemoved); } catch (KeeperException.NoNodeException nne) { - Assertions.fail("NoNodeException should not happen."); + fail("NoNodeException should not happen."); } // The verification method safeDelete is called once. - Mockito.verify(store.resourceManager.getZKManager(), Mockito.times(1)) - .safeDelete(Mockito.anyString(), Mockito.anyList(), Mockito.anyString()); + verify(store.resourceManager.getZKManager(), times(1)) + .safeDelete(anyString(), anyList(), anyString()); store.close(); } @@ -334,12 +343,12 @@ public void testRemoveRMDTMasterKeyState(RMStateStoreHelper stateStoreHelper) th try { store.removeRMDTMasterKeyState(keyRemoved); } catch (KeeperException.NoNodeException nne) { - Assertions.fail("NoNodeException should not happen."); + fail("NoNodeException should not happen."); } // The verification method safeDelete is called once. - Mockito.verify(store.resourceManager.getZKManager(), Mockito.times(1)) - .safeDelete(Mockito.anyString(), Mockito.anyList(), Mockito.anyString()); + verify(store.resourceManager.getZKManager(), times(1)) + .safeDelete(anyString(), anyList(), anyString()); store.close(); } @@ -355,12 +364,12 @@ public void testRemoveReservationState(RMStateStoreHelper stateStoreHelper) thro try { store.removeReservationState(planName, reservationIdRemoved.toString()); } catch (KeeperException.NoNodeException nne) { - Assertions.fail("NoNodeException should not happen."); + fail("NoNodeException should not happen."); } // The verification method safeDelete is called once. - Mockito.verify(store.resourceManager.getZKManager(), Mockito.times(1)) - .safeDelete(Mockito.anyString(), Mockito.anyList(), Mockito.anyString()); + verify(store.resourceManager.getZKManager(), times(1)) + .safeDelete(anyString(), anyList(), anyString()); store.close(); } @@ -378,11 +387,11 @@ public void testTransitionedToStandbyAfterCheckNode(RMStateStoreHelper stateStor // Transition to active. rm.getRMContext().getRMAdminService().transitionToActive(req); - Assertions.assertEquals( - Service.STATE.STARTED, rm.getServiceState(), "RM with ZKStore didn't start"); - Assertions.assertEquals( - HAServiceProtocol.HAServiceState.ACTIVE -, rm.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); + assertEquals(Service.STATE.STARTED, rm.getServiceState(), + "RM with ZKStore didn't start"); + assertEquals(HAServiceProtocol.HAServiceState.ACTIVE, + rm.getRMContext().getRMAdminService().getServiceStatus().getState(), + "RM should be Active"); // Simulate throw NodeExistsException ZKRMStateStore zKStore = (ZKRMStateStore) rm.getRMContext().getStateStore(); @@ -399,7 +408,7 @@ public void testTransitionedToStandbyAfterCheckNode(RMStateStoreHelper stateStor try { zKStore.removeApplicationAttemptInternal(attemptIdRemoved); } catch (Exception e) { - Assertions.assertTrue(e instanceof KeeperException.NodeExistsException); + assertTrue(e instanceof KeeperException.NodeExistsException); } 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/recovery/TestFSRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java index 4d777b0db71ff..83f76d043663e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java @@ -19,7 +19,12 @@ package org.apache.hadoop.yarn.server.resourcemanager.recovery; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.security.PrivilegedExceptionAction; @@ -50,7 +55,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -72,11 +76,11 @@ class TestFileSystemRMStore extends FileSystemRMStateStore { TestFileSystemRMStore(Configuration conf) throws Exception { init(conf); - Assertions.assertNull(fs); + assertNull(fs); assertTrue(workingDirPathURI.equals(fsWorkingPath)); dispatcher.disableExitOnDispatchException(); start(); - Assertions.assertNotNull(fs); + assertNotNull(fs); } public Path getVersionNode() { @@ -129,11 +133,11 @@ public RMStateStore getRMStateStore() throws Exception { this.store = new TestFileSystemRMStore(conf); assertThat(store.getNumRetries()).isEqualTo(8); assertThat(store.getRetryInterval()).isEqualTo(900L); - Assertions.assertTrue(store.fs.getConf() == store.fsConf); + assertTrue(store.fs.getConf() == store.fsConf); FileSystem previousFs = store.fs; store.startInternal(); - Assertions.assertTrue(store.fs != previousFs); - Assertions.assertTrue(store.fs.getConf() == store.fsConf); + assertTrue(store.fs != previousFs); + assertTrue(store.fs.getConf() == store.fsConf); return store; } @@ -198,7 +202,7 @@ public void testFSRMStateStore() throws Exception { fsOut.close(); testRMAppStateStore(fsTester); - Assertions.assertFalse(fsTester.workingDirPathURI + assertFalse(fsTester.workingDirPathURI .getFileSystem(conf).exists(tempAppAttemptFile)); testRMDTSecretManagerStateStore(fsTester); testCheckVersion(fsTester); @@ -296,11 +300,11 @@ private void verifyFilesUnreadablebyHDFS(MiniDFSCluster cluster, try { LOG.warn("\n\n ##Testing path [" + p + "]\n\n"); fs.open(p); - Assertions.fail("Super user should not be able to read ["+ UserGroupInformation.getCurrentUser() + "] [" + p.getName() + "]"); + fail("Super user should not be able to read ["+ UserGroupInformation.getCurrentUser() + "] [" + p.getName() + "]"); } catch (AccessControlException e) { - Assertions.assertTrue(e.getMessage().contains("superuser is not allowed to perform this operation")); + assertTrue(e.getMessage().contains("superuser is not allowed to perform this operation")); } catch (Exception e) { - Assertions.fail("Should get an AccessControlException here"); + fail("Should get an AccessControlException here"); } } if (stat.isDirectory()) { @@ -359,7 +363,7 @@ protected synchronized void storeVersion() throws Exception { RMStateStore store = fsTester.getRMStateStore(); Version defaultVersion = fsTester.getCurrentVersion(); store.checkVersion(); - Assertions.assertEquals(defaultVersion, store.loadVersion()); + assertEquals(defaultVersion, store.loadVersion()); } finally { cluster.shutdown(); } @@ -424,7 +428,7 @@ public void testFSRMStateStoreClientRetry() throws Exception { clientThread.start(); cluster.restartNameNode(); clientThread.join(); - Assertions.assertFalse(assertionFailedInThread.get()); + assertFalse(assertionFailedInThread.get()); } finally { cluster.shutdown(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestMemoryRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestMemoryRMStateStore.java index f1e68cbbc4378..6563e8de4f449 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestMemoryRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestMemoryRMStateStore.java @@ -47,8 +47,8 @@ public synchronized void removeRMDelegationTokenState( RMDelegationTokenIdentifier mockTokenId = mock(RMDelegationTokenIdentifier.class); store.removeRMDelegationToken(mockTokenId); - assertTrue( - store.isFencedState(), "RMStateStore should have been in fenced state"); + assertTrue(store.isFencedState(), + "RMStateStore should have been in fenced state"); store = new MemoryRMStateStore() { @Override public synchronized void removeRMDelegationToken( @@ -61,7 +61,7 @@ public synchronized void removeRMDelegationToken( store.setResourceManager(mockRM); store.setRMDispatcher(new RMStateStoreTestBase.TestDispatcher()); store.removeRMDelegationToken(mockTokenId); - assertTrue( - store.isFencedState(), "RMStateStore should have been in fenced state"); + assertTrue(store.isFencedState(), + "RMStateStore should have been in fenced state"); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestProtos.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestProtos.java index df1c3e38f9d61..f4858f4398902 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestProtos.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestProtos.java @@ -18,7 +18,8 @@ package org.apache.hadoop.yarn.server.resourcemanager.recovery; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.List; @@ -27,7 +28,6 @@ import org.apache.hadoop.yarn.api.records.NMToken; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerRecoveryProtos.EpochProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.AllocateResponseProto; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** @@ -39,7 +39,7 @@ public class TestProtos { public void testProtoCanBePrinted() throws Exception { EpochProto proto = EpochProto.newBuilder().setEpoch(100).build(); String protoString = proto.toString(); - Assertions.assertNotNull(protoString); + assertNotNull(protoString); } @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/recovery/TestRMStateStoreUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestRMStateStoreUtils.java index d8f431f231c9f..6cfa834f87928 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestRMStateStoreUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestRMStateStoreUtils.java @@ -64,8 +64,8 @@ public void testReadRMDelegationTokenIdentifierData(boolean oldFormat) RMDelegationTokenIdentifierData identifierData = RMStateStoreUtils.readRMDelegationTokenIdentifierData(inBuf); - assertEquals( - -1, inBuf.read(), "Found unexpected data still in the InputStream"); + assertEquals(-1, inBuf.read(), + "Found unexpected data still in the InputStream"); RMDelegationTokenIdentifier identifier = identifierData.getTokenIdentifier(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java index 3e337e7462fcd..630e8a47f0226 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java @@ -490,22 +490,22 @@ public void testFencing() throws Exception { ResourceManager rm1 = new MockRM(conf1); rm1.start(); rm1.getRMContext().getRMAdminService().transitionToActive(req); - 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"); + 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 = createHARMConf("rm1,rm2", "rm2", 5678, false, curatorTestingServer); ResourceManager rm2 = new MockRM(conf2); rm2.start(); rm2.getRMContext().getRMAdminService().transitionToActive(req); - 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"); + 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 == @@ -513,12 +513,12 @@ public void testFencing() throws Exception { Thread.sleep(100); } } - 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(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"); rm1.close(); rm2.close(); } @@ -530,8 +530,8 @@ public void testFencedState() throws Exception { // Move state to FENCED from ACTIVE store.updateFencedState(); - assertEquals( - true, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); long submitTime = System.currentTimeMillis(); long startTime = submitTime + 1000; @@ -545,8 +545,8 @@ public void testFencedState() throws Exception { when(mockApp.getApplicationSubmissionContext()).thenReturn(context); when(mockApp.getUser()).thenReturn("test"); store.storeNewApplication(mockApp); - assertEquals( - true, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); // Add a new attempt ClientToAMTokenSecretManagerInRM clientToAMTokenMgr = @@ -569,8 +569,8 @@ public void testFencedState() throws Exception { when(mockRmAppAttemptMetrics.getAggregateAppResourceUsage()) .thenReturn(new AggregateAppResourceUsage(new HashMap<>())); store.storeNewApplicationAttempt(mockAttempt); - assertEquals( - true, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); long finishTime = submitTime + 1000; // Update attempt @@ -581,20 +581,20 @@ public void testFencedState() throws Exception { "test", FinalApplicationStatus.SUCCEEDED, 100, finishTime, new HashMap<>(), new HashMap<>(), 0); store.updateApplicationAttemptState(newAttemptState); - assertEquals( - true, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); // Update app ApplicationStateData appState = ApplicationStateData.newInstance(submitTime, startTime, context, "test"); store.updateApplicationState(appState); - assertEquals( - true, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); // Remove app store.removeApplication(mockApp); - assertEquals( - true, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); // store RM delegation token; RMDelegationTokenIdentifier dtId1 = @@ -602,43 +602,40 @@ public void testFencedState() throws Exception { new Text("renewer1"), new Text("realuser1")); Long renewDate1 = new Long(System.currentTimeMillis()); dtId1.setSequenceNumber(1111); - assertFalse( - zkTester.delegationTokenExists(dtId1, 0), "Token " + dtId1 - + " should not exist but was found in ZooKeeper"); + assertFalse(zkTester.delegationTokenExists(dtId1, 0), + "Token " + dtId1 + " should not exist but was found in ZooKeeper"); store.storeRMDelegationToken(dtId1, renewDate1); - assertFalse( - zkTester.delegationTokenExists(dtId1, 0), "Token " + dtId1 - + " should not exist but was found in ZooKeeper"); - assertEquals(true -, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertFalse(zkTester.delegationTokenExists(dtId1, 0), + "Token " + dtId1 + " should not exist but was found in ZooKeeper"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); store.updateRMDelegationToken(dtId1, renewDate1); - assertFalse( - zkTester.delegationTokenExists(dtId1, 0), "Token " + dtId1 + assertFalse(zkTester.delegationTokenExists(dtId1, 0), "Token " + dtId1 + " should not exist but was found in ZooKeeper"); - assertEquals(true -, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); // remove delegation key; store.removeRMDelegationToken(dtId1); - assertEquals(true -, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); // store delegation master key; DelegationKey key = new DelegationKey(1234, 4321, "keyBytes".getBytes()); store.storeRMDTMasterKey(key); - assertEquals(true -, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); // remove delegation master key; store.removeRMDTMasterKey(key); - assertEquals(true -, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); // store or update AMRMToken; store.storeOrUpdateAMRMTokenSecretManager(null, false); - assertEquals(true -, store.isFencedState(), "RMStateStore should have been in fenced state"); + assertEquals(true, store.isFencedState(), + "RMStateStore should have been in fenced state"); store.close(); } @@ -711,18 +708,19 @@ private static void verifyLoadedApp(ApplicationStateData appState, RMAppState state, long finishTime, String diagnostics) { // Check if app is loaded correctly assertNotNull(appState, "App " + appId + " should have been loaded."); - assertEquals(submitTime -, appState.getSubmitTime(), "App submit time in app state"); - assertEquals(startTime -, appState.getStartTime(), "App start time in app state"); - assertEquals(appId -, appState.getApplicationSubmissionContext().getApplicationId(), "App ID in app state"); + assertEquals(submitTime, + appState.getSubmitTime(), "App submit time in app state"); + assertEquals(startTime, + appState.getStartTime(), "App start time in app state"); + assertEquals(appId, + appState.getApplicationSubmissionContext().getApplicationId(), + "App ID in app state"); assertEquals(state, appState.getState(), "App state"); - assertEquals(finishTime -, appState.getFinishTime(), "Finish time in app state"); + assertEquals(finishTime, + appState.getFinishTime(), "Finish time in app state"); assertEquals(user, appState.getUser(), "User in app state"); - assertEquals(diagnostics -, appState.getDiagnostics(), "Diagnostics in app state"); + assertEquals(diagnostics, + appState.getDiagnostics(), "Diagnostics in app state"); } private static void verifyLoadedApp(RMState rmState, @@ -746,8 +744,8 @@ private static void verifyLoadedApp(RMState rmState, isFinished ? "appDiagnostics" : ""); // Check attempt state. if (attempts != null) { - assertEquals(attempts.size() -, appState.attempts.size(), "Attempts loaded for app " + appId); + assertEquals(attempts.size(), + appState.attempts.size(), "Attempts loaded for app " + appId); if (finalStatuses != null && amExitStatuses != null) { for (int i = 0; i < attempts.size(); i++) { if (finalStatuses.get(i) != null) { @@ -781,28 +779,29 @@ private static void verifyLoadedAttempt(ApplicationStateData appState, int amExitStatus, FinalApplicationStatus finalStatus) { ApplicationAttemptStateData attemptState = appState.getAttempt(attemptId); // Check if attempt is loaded correctly - assertNotNull( - attemptState, "Attempt " + attemptId + " should have been loaded."); - assertEquals( - attemptId, attemptState.getAttemptId(), "Attempt Id in attempt state"); - assertEquals( - masterContainerId, attemptState.getMasterContainer().getId(), "Master Container Id in attempt state"); + assertNotNull(attemptState, + "Attempt " + attemptId + " should have been loaded."); + assertEquals(attemptId, attemptState.getAttemptId(), + "Attempt Id in attempt state"); + assertEquals(masterContainerId, attemptState.getMasterContainer().getId(), + "Master Container Id in attempt state"); if (null != clientTokenKey) { - assertArrayEquals( - clientTokenKey.getEncoded(), attemptState.getAppAttemptTokens(). - getSecretKey(RMStateStore.AM_CLIENT_TOKEN_MASTER_KEY_NAME), "Client token key in attempt state"); + assertArrayEquals(clientTokenKey.getEncoded(), + attemptState.getAppAttemptTokens(). + getSecretKey(RMStateStore.AM_CLIENT_TOKEN_MASTER_KEY_NAME), + "Client token key in attempt state"); } assertEquals(state, attemptState.getState(), "Attempt state"); - assertEquals(finishTime -, attemptState.getFinishTime(), "Finish time in attempt state"); - assertEquals(diagnostics -, attemptState.getDiagnostics(), "Diagnostics in attempt state"); - assertEquals(amExitStatus -, attemptState.getAMContainerExitStatus(), "AM Container exit status in attempt state"); - assertEquals(finalStatus -, attemptState.getFinalApplicationStatus(), "Final app status in attempt state"); - assertEquals(trackingURL -, attemptState.getFinalTrackingUrl(), "Tracking URL in attempt state"); + assertEquals(finishTime, attemptState.getFinishTime(), + "Finish time in attempt state"); + assertEquals(diagnostics, attemptState.getDiagnostics(), + "Diagnostics in attempt state"); + assertEquals(amExitStatus, attemptState.getAMContainerExitStatus(), + "AM Container exit status in attempt state"); + assertEquals(finalStatus, attemptState.getFinalApplicationStatus(), + "Final app status in attempt state"); + assertEquals(trackingURL, attemptState.getFinalTrackingUrl(), + "Tracking URL in attempt state"); } private static ApplicationStateData createAppState( @@ -934,7 +933,8 @@ private static void verifyAppPathPath(RMStateStore store, ApplicationId appId, ZKRMStateStore.ROOT_ZNODE_NAME, ZKRMStateStore.RM_APP_ROOT, ZKRMStateStore.RM_APP_ROOT_HIERARCHIES, String.valueOf(splitIndex), appParent, appPath); - assertTrue(((ZKRMStateStore)store).exists(path), "Application with id " + appIdStr + " does not exist as per " + + assertTrue(((ZKRMStateStore)store).exists(path), + "Application with id " + appIdStr + " does not exist as per " + "split in state store."); } @@ -949,8 +949,8 @@ private static void verifyAppInHierarchicalPath(RMStateStore store, } else { path = createPath(path, appId); } - assertTrue( - ((ZKRMStateStore)store).exists(createPath(path)), appId + " should exist in path " + path); + assertTrue(((ZKRMStateStore)store).exists(createPath(path)), + appId + " should exist in path " + path); } private static void assertHierarchicalPaths(RMStateStore store, @@ -962,9 +962,8 @@ private static void assertHierarchicalPaths(RMStateStore store, path = createPath(path, ZKRMStateStore.RM_APP_ROOT_HIERARCHIES, String.valueOf(entry.getKey())); } - assertEquals( - (int) entry.getValue() -, ((ZKRMStateStore)store).getChildren(path).size(), "Number of childrens for path " + path); + assertEquals((int) entry.getValue(), ((ZKRMStateStore)store).getChildren(path).size(), + "Number of childrens for path " + path); } } @@ -1131,8 +1130,8 @@ public void testAppNodeSplitChangeAcrossRestarts() throws Exception { store = zkTester.getRMStateStore(createConfForAppNodeSplit(0)); store.setRMDispatcher(dispatcher); state = store.loadState(); - assertEquals(4 -, state.getApplicationState().size(), "Number of Apps loaded should be 4."); + assertEquals(4, state.getApplicationState().size(), + "Number of Apps loaded should be 4."); verifyLoadedApp(state, appId1, submitTime, startTime, 1234, true, Lists.newArrayList(attemptId1, attemptId2), Lists.newArrayList(-1000, 100), Lists.newArrayList(null, FinalApplicationStatus.SUCCEEDED)); @@ -1147,8 +1146,8 @@ public void testAppNodeSplitChangeAcrossRestarts() throws Exception { store = zkTester.getRMStateStore(createConfForAppNodeSplit(3)); store.setRMDispatcher(dispatcher); state = store.loadState(); - assertEquals(5 -, state.getApplicationState().size(), "Number of apps loaded should be 5."); + assertEquals(5, state.getApplicationState().size(), + "Number of apps loaded should be 5."); verifyLoadedApp(state, dummyAppId, submitTime, startTime, 1234, true, Lists.newArrayList(dummyAttemptId), Lists.newArrayList(111), Lists.newArrayList(FinalApplicationStatus.SUCCEEDED)); @@ -1195,8 +1194,8 @@ public void testAppNodeSplitChangeAcrossRestarts() throws Exception { store = zkTester.getRMStateStore(createConfForAppNodeSplit(3)); store.setRMDispatcher(dispatcher); state = store.loadState(); - assertEquals(0 -, state.getApplicationState().size(), "Number of apps loaded should be 0."); + assertEquals(0, state.getApplicationState().size(), + "Number of apps loaded should be 0."); // Close the state store. store.close(); } @@ -1216,14 +1215,13 @@ private void verifyDelegationTokensStateStore( int sequenceNumber) throws Exception { RMStateStore.RMDTSecretManagerState secretManagerState = zkTester.store.loadState().getRMDTSecretManagerState(); - assertEquals( - tokensWithRenewal, secretManagerState.getTokenState(), "Unexpected token state"); - assertEquals(sequenceNumber -, secretManagerState.getDTSequenceNumber(), "Unexpected sequence number"); + assertEquals(tokensWithRenewal, secretManagerState.getTokenState(), + "Unexpected token state"); + assertEquals(sequenceNumber, secretManagerState.getDTSequenceNumber(), + "Unexpected sequence number"); for (Map.Entry tokenEntry : tokensWithIndex.entrySet()) { - assertTrue( - zkTester.delegationTokenExists(tokenEntry.getKey(), + assertTrue(zkTester.delegationTokenExists(tokenEntry.getKey(), tokenEntry.getValue()), "Expected to find token " + tokenEntry.getKey() + " in zookeeper but did not"); } @@ -1236,12 +1234,12 @@ private void verifyDelegationTokenInStateStore( zkTester.store.loadState().getRMDTSecretManagerState(); Map tokenState = secretManagerState.getTokenState(); - assertTrue( - tokenState.containsKey(token), "token state does not contain " + token); - assertTrue( - tokenState.containsValue(renewDate), "token state does not contain a token with renewal " + renewDate); - assertTrue( - zkTester.delegationTokenExists(token, index), "Token " + token + "should exist but was not found in ZooKeeper"); + assertTrue(tokenState.containsKey(token), + "token state does not contain " + token); + assertTrue(tokenState.containsValue(renewDate), + "token state does not contain a token with renewal " + renewDate); + assertTrue(zkTester.delegationTokenExists(token, index), + "Token " + token + "should exist but was not found in ZooKeeper"); } private RMDelegationTokenIdentifier storeUpdateAndVerifyDelegationToken( @@ -1253,8 +1251,8 @@ private RMDelegationTokenIdentifier storeUpdateAndVerifyDelegationToken( RMDelegationTokenIdentifier token = new RMDelegationTokenIdentifier(new Text("owner"), new Text("renewer"), new Text("realuser")); - assertFalse( - zkTester.delegationTokenExists(token, split), "Token should not exist but was found in ZooKeeper"); + assertFalse(zkTester.delegationTokenExists(token, split), + "Token should not exist but was found in ZooKeeper"); token.setSequenceNumber(sequenceNumber); Long renewDate = System.currentTimeMillis(); zkTester.store.storeRMDelegationToken(token, renewDate); @@ -1284,28 +1282,28 @@ public void testDelegationTokenSplitIndexConfig() throws Exception { // Valid values TestZKRMStateStoreTester zkTester = new TestZKRMStateStoreTester(); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(0)).close(); - assertEquals( - 0, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); + assertEquals(0, zkTester.getDelegationTokenNodeSplitIndex(), + "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(1)).close(); - assertEquals( - 1, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); + assertEquals(1, zkTester.getDelegationTokenNodeSplitIndex(), + "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(2)).close(); - assertEquals( - 2, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); + assertEquals(2, zkTester.getDelegationTokenNodeSplitIndex(), + "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(3)).close(); - assertEquals( - 3, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); + assertEquals(3, zkTester.getDelegationTokenNodeSplitIndex(), + "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(4)).close(); - assertEquals( - 4, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); + assertEquals(4, zkTester.getDelegationTokenNodeSplitIndex(), + "Incorrect split index"); // Invalid values --> override to 0 zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(-1)).close(); - assertEquals( - 0, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); + assertEquals(0, zkTester.getDelegationTokenNodeSplitIndex(), + "Incorrect split index"); zkTester.getRMStateStore(createConfForDelegationTokenNodeSplit(5)).close(); - assertEquals( - 0, zkTester.getDelegationTokenNodeSplitIndex(), "Incorrect split index"); + assertEquals(0, zkTester.getDelegationTokenNodeSplitIndex(), + "Incorrect split index"); } @Test @@ -1351,12 +1349,12 @@ public void testDelegationTokenNode(int split) throws Exception { store.loadState().getRMDTSecretManagerState(); tokensWithRenewal.clear(); tokensWithIndex.clear(); - assertEquals( - tokensWithRenewal, state.getTokenState(), "Unexpected token state"); - assertEquals( - sequenceNumber, state.getDTSequenceNumber(), "Unexpected sequence number"); - assertFalse( - zkTester.delegationTokenExists(token, split), "Token should not exist but was found in ZooKeeper"); + assertEquals(tokensWithRenewal, state.getTokenState(), + "Unexpected token state"); + assertEquals(sequenceNumber, state.getDTSequenceNumber(), + "Unexpected sequence number"); + assertFalse(zkTester.delegationTokenExists(token, split), + "Token should not exist but was found in ZooKeeper"); store.close(); } @@ -1378,8 +1376,8 @@ public void testDelegationTokenNodeWithSplitMultiple() throws Exception { new Text("renewer" + i), new Text("realuser" + i)); sequenceNumber = i; token.setSequenceNumber(sequenceNumber); - assertFalse( - zkTester.delegationTokenExists(token, 1), "Token should not exist but was found in ZooKeeper"); + assertFalse(zkTester.delegationTokenExists(token, 1), + "Token should not exist but was found in ZooKeeper"); Long renewDate = System.currentTimeMillis(); store.storeRMDelegationToken(token, renewDate); modifyRMDelegationTokenState(); @@ -1422,9 +1420,8 @@ public void testDelegationTokenNodeWithSplitMultiple() throws Exception { verifyDelegationTokensStateStore(zkTester, tokensWithRenewal, tokensWithIndex, sequenceNumber); for (RMDelegationTokenIdentifier token : tokensToDelete) { - assertFalse( - zkTester.delegationTokenExists(token, 1), "Token " + token - + " should not exist but was found in ZooKeeper"); + assertFalse(zkTester.delegationTokenExists(token, 1), + "Token " + token + " should not exist but was found in ZooKeeper"); } store.close(); } @@ -1498,15 +1495,12 @@ public void testDelegationTokenNodeWithSplitChangeAcrossRestarts() tokensWithIndex.clear(); verifyDelegationTokensStateStore( zkTester, tokensWithRenewal, tokensWithIndex, sequenceNumber); - assertFalse( - zkTester.delegationTokenExists(token1, 1), "Token " + token1 - + " should not exist but was found in ZooKeeper"); - assertFalse( - zkTester.delegationTokenExists(token2, 2), "Token " + token1 - + " should not exist but was found in ZooKeeper"); - assertFalse( - zkTester.delegationTokenExists(token0, 0), "Token " + token1 - + " should not exist but was found in ZooKeeper"); + assertFalse(zkTester.delegationTokenExists(token1, 1), + "Token " + token1 + " should not exist but was found in ZooKeeper"); + assertFalse(zkTester.delegationTokenExists(token2, 2), "Token " + token1 + + " should not exist but was found in ZooKeeper"); + assertFalse(zkTester.delegationTokenExists(token0, 0), "Token " + token1 + + " should not exist but was found in ZooKeeper"); // Store a token with index 3 sequenceNumber++; storeUpdateAndVerifyDelegationToken(zkTester, tokensWithRenewal, @@ -1553,8 +1547,9 @@ public void testAppSubmissionContextIsPrunedInFinalApplicationState() ctx = rmState.getApplicationState().get(appId) .getApplicationSubmissionContext(); - assertEquals( - schedulingPropertiesMap, ctx.getApplicationSchedulingPropertiesMap(), "ApplicationSchedulingPropertiesMap should not have been " + assertEquals(schedulingPropertiesMap, + ctx.getApplicationSchedulingPropertiesMap(), + "ApplicationSchedulingPropertiesMap should not have been " + "pruned from the application submission context before the " + "FINISHED state"); @@ -1569,8 +1564,8 @@ public void testAppSubmissionContextIsPrunedInFinalApplicationState() assertEquals("a_queue", ctx.getQueue()); assertNotNull(ctx.getAMContainerSpec()); assertEquals(17L, ctx.getResource().getMemorySize()); - assertEquals( - Collections.emptyMap(), ctx.getApplicationSchedulingPropertiesMap(), "ApplicationSchedulingPropertiesMap should have been pruned" + assertEquals(Collections.emptyMap(), ctx.getApplicationSchedulingPropertiesMap(), + "ApplicationSchedulingPropertiesMap should have been pruned" + " from the application submission context when in FINISHED STATE"); store.close(); } @@ -1592,8 +1587,8 @@ public void testMetricsInited() throws Exception { Thread.sleep(110); opDurations.getMetrics(collector, true); - assertEquals(1 -, collector.getRecords().size(), "Incorrect number of perf metrics"); + assertEquals(1, collector.getRecords().size(), + "Incorrect number of perf metrics"); MetricsRecord record = collector.getRecords().get(0); MetricsRecords.assertTag(record, ZKRMStateStoreOpDurations.RECORD_INFO.name(), diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStoreZKClientConnections.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStoreZKClientConnections.java index f405ac622c1b6..d41c8235b5c8c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStoreZKClientConnections.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStoreZKClientConnections.java @@ -30,7 +30,6 @@ import org.apache.zookeeper.server.auth.DigestAuthenticationProvider; 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; @@ -38,6 +37,7 @@ import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicBoolean; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -126,7 +126,7 @@ public void run() { Thread.sleep(2000); testingServer.start(); clientThread.join(); - Assertions.assertFalse(assertionFailedInThread.get()); + assertFalse(assertionFailedInThread.get()); } @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/reservation/BaseSharingPolicyTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java index 42242c62ddf4c..1495dd8c2d3e8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/BaseSharingPolicyTest.java @@ -34,32 +34,24 @@ import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.apache.hadoop.yarn.util.resource.Resources; import org.junit.jupiter.api.BeforeEach; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import net.jcip.annotations.NotThreadSafe; /** * This class is a base test for {@code SharingPolicy} implementors. */ -@RunWith(value = Parameterized.class) @NotThreadSafe @SuppressWarnings("VisibilityModifier") public abstract class BaseSharingPolicyTest { - @Parameterized.Parameter(value = 0) public long duration; - @Parameterized.Parameter(value = 1) public double height; - @Parameterized.Parameter(value = 2) public int numSubmissions; - @Parameterized.Parameter(value = 3) public String recurrenceExpression; - @Parameterized.Parameter(value = 4) public Class expectedError; private long step; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java index 0813e9b00f734..59b476c7bc19b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/ReservationSystemTestUtil.java @@ -17,6 +17,10 @@ *****************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.Mockito.doReturn; @@ -66,7 +70,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.junit.jupiter.api.Assertions; -import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -112,11 +115,11 @@ public static ReservationSchedulerConfiguration createConf( public static void validateReservationQueue( AbstractReservationSystem reservationSystem, String planQName) { Plan plan = reservationSystem.getPlan(planQName); - Assertions.assertNotNull(plan); - Assertions.assertTrue(plan instanceof InMemoryPlan); - Assertions.assertEquals(planQName, plan.getQueueName()); - Assertions.assertEquals(8192, plan.getTotalCapacity().getMemorySize()); - Assertions.assertTrue( + assertNotNull(plan); + assertTrue(plan instanceof InMemoryPlan); + assertEquals(planQName, plan.getQueueName()); + assertEquals(8192, plan.getTotalCapacity().getMemorySize()); + assertTrue( plan.getReservationAgent() instanceof AlignedPlannerWithGreedy); Assertions .assertTrue(plan.getSharingPolicy() instanceof CapacityOverTimePolicy); @@ -247,7 +250,7 @@ public CapacityScheduler mockCapacityScheduler(int numContainers) CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration(); setupQueueConfiguration(conf); - CapacityScheduler cs = Mockito.spy(new CapacityScheduler()); + CapacityScheduler cs = spy(new CapacityScheduler()); cs.setConf(new YarnConfiguration()); RMContext mockRmContext = createRMContext(conf); @@ -256,7 +259,7 @@ public CapacityScheduler mockCapacityScheduler(int numContainers) try { cs.serviceInit(conf); } catch (Exception e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } initializeRMContext(numContainers, cs, mockRmContext); @@ -273,7 +276,7 @@ public static void initializeRMContext(int numContainers, } public static RMContext createRMContext(Configuration conf) { - RMContext mockRmContext = Mockito.spy(new RMContextImpl(null, null, null, + RMContext mockRmContext = spy(new RMContextImpl(null, null, null, null, null, null, new RMContainerTokenSecretManager(conf), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM(), 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/reservation/TestCapacityOverTimePolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacityOverTimePolicy.java index 0ee05434e97ea..afcee0fd716cb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacityOverTimePolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacityOverTimePolicy.java @@ -25,14 +25,12 @@ import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException; import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningQuotaException; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * This class tests the {@code CapacityOvertimePolicy} sharing policy. */ -@RunWith(value = Parameterized.class) @NotThreadSafe @SuppressWarnings("VisibilityModifier") public class TestCapacityOverTimePolicy extends BaseSharingPolicyTest { @@ -43,8 +41,16 @@ public class TestCapacityOverTimePolicy extends BaseSharingPolicyTest { final static String TWOHOURPERIOD = "7200000"; final static String ONEDAYPERIOD = "86400000"; - @Parameterized.Parameters(name = "Duration {0}, height {1}," + - " numSubmission {2}, periodic {3})") + public void initTestCapacityOverTimePolicy(long pDuration, + double pHeight, int pNumSubmissions, String pRecurrenceExpression, Class pExpectedError) { + this.duration = pDuration; + this.height = pHeight; + this.numSubmissions = pNumSubmissions; + this.recurrenceExpression = pRecurrenceExpression; + this.expectedError = pExpectedError; + super.setup(); + } + public static Collection data() { return Arrays.asList(new Object[][] { @@ -131,8 +137,14 @@ public SharingPolicy getInitializedPolicy() { return policy; } - @Test - public void testAllocation() throws IOException, PlanningException { + @ParameterizedTest(name = "Duration {0}, height {1}," + + " numSubmission {2}, periodic {3})") + @MethodSource("data") + public void testAllocation(long pDuration, double pHeight, int pNumSubmissions, + String pRecurrenceExpression, Class pExpectedError) + throws IOException, PlanningException { + initTestCapacityOverTimePolicy(pDuration, pHeight, pNumSubmissions, + pRecurrenceExpression, pExpectedError); runTest(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java index 5149e4111ed7b..de0d0b3f26c52 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.reservation; +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; @@ -31,6 +32,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.AccessControlException; +import org.apache.hadoop.test.TestName; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.server.resourcemanager.RMContext; @@ -51,11 +53,9 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; 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.Rule; import org.junit.jupiter.api.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -67,8 +67,8 @@ public class TestCapacitySchedulerPlanFollower extends private CapacitySchedulerContext csContext; private CapacityScheduler cs; - @Rule - public TestName name = new TestName(); + @RegisterExtension + public TestName methodName = new TestName(); @BeforeEach public void setUp() throws Exception { @@ -161,8 +161,8 @@ protected void verifyCapacity(Queue defQ) { @Override protected void checkDefaultQueueBeforePlanFollowerRun(){ Queue defQ = getDefaultQueue(); - Assertions.assertEquals(0, getNumberOfApplications(defQ)); - Assertions.assertNotNull(defQ); + assertEquals(0, getNumberOfApplications(defQ)); + assertNotNull(defQ); } @Override @@ -196,8 +196,8 @@ protected void assertReservationQueueExists(ReservationId r2, double expectedCapacity, double expectedMaxCapacity) { CSQueue q = cs.getQueue(r2.toString()); assertNotNull(q); - Assertions.assertEquals(expectedCapacity, q.getCapacity(), 0.01); - Assertions.assertEquals(expectedMaxCapacity, q.getMaximumCapacity(), 1.0); + assertEquals(expectedCapacity, q.getCapacity(), 0.01); + assertEquals(expectedMaxCapacity, q.getMaximumCapacity(), 1.0); } @Override diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java index d74c3426e7b25..c3a1edc309f9d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.yarn.server.resourcemanager.reservation; +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; @@ -32,6 +33,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.AccessControlException; +import org.apache.hadoop.test.TestName; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.conf.YarnConfiguration; @@ -51,11 +53,9 @@ import org.apache.hadoop.yarn.server.security.ApplicationACLsManager; import org.apache.hadoop.yarn.util.Clock; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; -import org.junit.Rule; import org.junit.jupiter.api.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -70,8 +70,8 @@ public class TestFairSchedulerPlanFollower extends private Configuration conf; private FairSchedulerTestBase testHelper = new FairSchedulerTestBase(); - @Rule - public TestName name = new TestName(); + @RegisterExtension + public TestName methodName = new TestName(); protected Configuration createConfiguration() { Configuration conf = testHelper.createConfiguration(); @@ -132,7 +132,7 @@ public void testWithKillOnExpiry() throws PlanningException, @Override protected void checkDefaultQueueBeforePlanFollowerRun() { - Assertions.assertNull(getDefaultQueue()); + assertNull(getDefaultQueue()); } @Override protected void verifyCapacity(Queue defQ) { @@ -172,7 +172,7 @@ protected void assertReservationQueueExists(ReservationId r, false); assertNotNull(q); // For now we are setting both to same weight - Assertions.assertEquals(expectedCapacity, q.getWeight(), 0.01); + assertEquals(expectedCapacity, q.getWeight(), 0.01); } @Override diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryPlan.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryPlan.java index c11249ea9aeec..2bc3118737a48 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryPlan.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryPlan.java @@ -18,7 +18,11 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -48,7 +52,6 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -113,11 +116,11 @@ public void testAddReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc, start, 0); @@ -125,15 +128,15 @@ public void testAddReservation() { @Test public void testOutOfRange() throws PlanningException { - assertThrows(PlanningException.class, ()->{ + assertThrows(PlanningException.class, () -> { maxPeriodicity = 100; Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, - resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, - context, new UTCClock()); + resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, + context, new UTCClock()); // we expect the plan to complaint as the range 330-150 > 50 RLESparseResourceAllocation availableBefore = - plan.getAvailableResourceOverTime(user, null, 150, 330, 50); + plan.getAvailableResourceOverTime(user, null, 150, 330, 50); }); } @@ -154,11 +157,11 @@ public void testAddPeriodicReservation() throws PlanningException { reservationID, start, alloc, String.valueOf(period)); // use periodicity of 1hr rAllocation.setPeriodicity(period); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc, start, period); @@ -195,10 +198,10 @@ private void checkAllocation(Plan plan, int[] alloc, int start, long y = 0; Resource res = Resource.newInstance(1024 * (alloc[i]), (alloc[i])); while (y <= end * 2) { - assertEquals(res -, plan.getTotalCommittedResources(start + i + y), "At time: " + start + i + y); - assertEquals(res -, userCons.getCapacityAtTime(start + i + y), " At time: " + (start + i + y)); + assertEquals(res, plan.getTotalCommittedResources(start + i + y), + "At time: " + start + i + y); + assertEquals(res, userCons.getCapacityAtTime(start + i + y), + " At time: " + (start + i + y)); y = y + periodicity; } } @@ -215,11 +218,11 @@ public void testAddEmptyReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } } @@ -234,11 +237,11 @@ public void testAddReservationAlreadyExists() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc, start, 0); @@ -246,11 +249,11 @@ public void testAddReservationAlreadyExists() { // Try to add it again try { plan.addReservation(rAllocation, false); - Assertions.fail("Add should fail as it already exists"); + fail("Add should fail as it already exists"); } catch (IllegalArgumentException e) { - Assertions.assertTrue(e.getMessage().endsWith("already exists")); + assertTrue(e.getMessage().endsWith("already exists")); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); } @@ -266,11 +269,11 @@ public void testUpdateReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); @@ -291,7 +294,7 @@ public void testUpdateReservation() { try { plan.updateReservation(rAllocation); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); @@ -322,11 +325,11 @@ public void testUpdatePeriodicReservation() { rAllocation.getReservationDefinition() .setRecurrenceExpression(String.valueOf(period)); rAllocation.setPeriodicity(period); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } System.out.println(plan.toString()); doAssertions(plan, rAllocation); @@ -343,7 +346,7 @@ public void testUpdatePeriodicReservation() { try { plan.updateReservation(rAllocation); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, updatedAlloc, start, period); @@ -360,16 +363,16 @@ public void testUpdateNonExistingReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.updateReservation(rAllocation); - Assertions.fail("Update should fail as it does not exist in the plan"); + fail("Update should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { - Assertions.assertTrue(e.getMessage().endsWith("does not exist in the plan")); + assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); } @Test @@ -383,11 +386,11 @@ public void testDeleteReservation() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc, true); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); @@ -407,9 +410,9 @@ public void testDeleteReservation() { try { plan.deleteReservation(reservationID); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); userCons = plan.getConsumptionForUserOverTime(user, start, start + alloc.length); for (int i = 0; i < alloc.length; i++) { @@ -436,11 +439,11 @@ public void testDeletePeriodicReservation() { rAllocation.getReservationDefinition() .setRecurrenceExpression(String.valueOf(period)); rAllocation.setPeriodicity(period); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } System.out.println(plan.toString()); doAssertions(plan, rAllocation); @@ -450,9 +453,9 @@ public void testDeletePeriodicReservation() { try { plan.deleteReservation(reservationID); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); System.out.print(plan); checkAllocation(plan, new int[] { 0, 0 }, start, period); } @@ -464,16 +467,16 @@ public void testDeleteNonExistingReservation() { ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to delete a reservation without adding - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.deleteReservation(reservationID); - Assertions.fail("Delete should fail as it does not exist in the plan"); + fail("Delete should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { - Assertions.assertTrue(e.getMessage().endsWith("does not exist in the plan")); + assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); } @Test @@ -489,11 +492,11 @@ public void testArchiveCompletedReservations() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID1, start, alloc1); - Assertions.assertNull(plan.getReservationById(reservationID1)); + assertNull(plan.getReservationById(reservationID1)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } doAssertions(plan, rAllocation); checkAllocation(plan, alloc1, start, 0); @@ -504,13 +507,13 @@ public void testArchiveCompletedReservations() { int[] alloc2 = { 0, 5, 10, 5, 0 }; rAllocation = createReservationAllocation(reservationID2, start, alloc2, true); - Assertions.assertNull(plan.getReservationById(reservationID2)); + assertNull(plan.getReservationById(reservationID2)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan.getReservationById(reservationID2)); + assertNotNull(plan.getReservationById(reservationID2)); RLESparseResourceAllocation userCons = plan.getConsumptionForUserOverTime(user, start, start + alloc2.length); @@ -534,10 +537,10 @@ public void testArchiveCompletedReservations() { // archival window plan.archiveCompletedReservations(clock.getTime()); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan.getReservationById(reservationID1)); - Assertions.assertNull(plan.getReservationById(reservationID2)); + assertNotNull(plan.getReservationById(reservationID1)); + assertNull(plan.getReservationById(reservationID2)); checkAllocation(plan, alloc1, start, 0); when(clock.getTime()).thenReturn(107L); @@ -546,13 +549,13 @@ public void testArchiveCompletedReservations() { // window plan.archiveCompletedReservations(clock.getTime()); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } userCons = plan.getConsumptionForUserOverTime(user, start, start + alloc1.length); - Assertions.assertNull(plan.getReservationById(reservationID1)); + assertNull(plan.getReservationById(reservationID1)); for (int i = 0; i < alloc1.length; i++) { assertEquals(Resource.newInstance(0, 0), plan.getTotalCommittedResources(start + i)); @@ -571,26 +574,26 @@ public void testGetReservationsById() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } // Verify that get by reservation id works. Set rAllocations = plan.getReservations(reservationID, null, ""); - Assertions.assertTrue(rAllocations.size() == 1); - Assertions.assertTrue(rAllocation + assertTrue(rAllocations.size() == 1); + assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by reservation id works even when time range // and user is invalid. ReservationInterval interval = new ReservationInterval(0, 0); rAllocations = plan.getReservations(reservationID, interval, "invalid"); - Assertions.assertTrue(rAllocations.size() == 1); - Assertions.assertTrue(rAllocation + assertTrue(rAllocations.size() == 1); + assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); } @@ -604,11 +607,11 @@ public void testGetReservationsByInvalidId() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } // If reservationId is null, then nothing is returned. @@ -616,7 +619,7 @@ public void testGetReservationsByInvalidId() { ReservationSystemTestUtil.getNewReservationId(); Set rAllocations = plan.getReservations(invalidReservationID, null, ""); - Assertions.assertTrue(rAllocations.size() == 0); + assertTrue(rAllocations.size() == 0); } @Test @@ -629,11 +632,11 @@ public void testGetReservationsByTimeInterval() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } // Verify that get by time interval works if the selection interval @@ -642,8 +645,8 @@ public void testGetReservationsByTimeInterval() { rAllocation.getStartTime(), rAllocation.getEndTime()); Set rAllocations = plan.getReservations(null, interval, ""); - Assertions.assertTrue(rAllocations.size() == 1); - Assertions.assertTrue(rAllocation + assertTrue(rAllocations.size() == 1); + assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by time interval works if the selection interval @@ -653,8 +656,8 @@ public void testGetReservationsByTimeInterval() { rAllocation.getStartTime() + duration * (long) 0.3, rAllocation.getEndTime() - duration * (long) 0.3); rAllocations = plan.getReservations(null, interval, ""); - Assertions.assertTrue(rAllocations.size() == 1); - Assertions.assertTrue(rAllocation + assertTrue(rAllocations.size() == 1); + assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by time interval selects 1 allocation if the end @@ -662,8 +665,8 @@ public void testGetReservationsByTimeInterval() { // allocation. interval = new ReservationInterval(0, rAllocation.getStartTime()); rAllocations = plan.getReservations(null, interval, ""); - Assertions.assertTrue(rAllocations.size() == 1); - Assertions.assertTrue(rAllocation + assertTrue(rAllocations.size() == 1); + assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by time interval selects no reservations if the start @@ -671,13 +674,13 @@ public void testGetReservationsByTimeInterval() { interval = new ReservationInterval(rAllocation.getEndTime(), Long.MAX_VALUE); rAllocations = plan.getReservations(null, interval, ""); - Assertions.assertTrue(rAllocations.size() == 0); + assertTrue(rAllocations.size() == 0); // Verify that get by time interval selects no reservations if the // selection interval and allocation interval do not overlap. interval = new ReservationInterval(0, rAllocation.getStartTime() / 2); rAllocations = plan.getReservations(null, interval, ""); - Assertions.assertTrue(rAllocations.size() == 0); + assertTrue(rAllocations.size() == 0); } @Test @@ -690,17 +693,17 @@ public void testGetReservationsAtTime() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } Set rAllocations = plan.getReservationsAtTime(rAllocation.getStartTime()); - Assertions.assertTrue(rAllocations.size() == 1); - Assertions.assertTrue(rAllocation + assertTrue(rAllocations.size() == 1); + assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); } @@ -897,19 +900,19 @@ public void testGetReservationsWithNoInput() { int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); - Assertions.assertNull(plan.getReservationById(reservationID)); + assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } // Verify that getReservations defaults to getting all reservations if no // reservationID, time interval, and user is provided, Set rAllocations = plan.getReservations(null, null, ""); - Assertions.assertTrue(rAllocations.size() == 1); - Assertions.assertTrue(rAllocation + assertTrue(rAllocations.size() == 1); + assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); } @@ -922,7 +925,7 @@ public void testGetReservationsWithNoReservation() { ReservationInterval interval = new ReservationInterval(0, Long.MAX_VALUE); Set rAllocations = plan.getReservations(null, interval, ""); - Assertions.assertTrue(rAllocations.size() == 0); + assertTrue(rAllocations.size() == 0); } private void testPositiveGetRecurringReservationsHelper(long reservationStart, @@ -974,20 +977,20 @@ private ReservationId submitReservation(Plan plan, rAllocation.setPeriodicity(period); - Assertions.assertNull(plan.getReservationById(reservation)); + assertNull(plan.getReservationById(reservation)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } return reservation; } private void doAssertions(Plan plan, ReservationAllocation rAllocation) { ReservationId reservationID = rAllocation.getReservationId(); - Assertions.assertNotNull(plan.getReservationById(reservationID)); + assertNotNull(plan.getReservationById(reservationID)); assertEquals(rAllocation, plan.getReservationById(reservationID)); - Assertions.assertTrue(((InMemoryPlan) plan).getAllReservations().size() == 1); + assertTrue(((InMemoryPlan) plan).getAllReservations().size() == 1); if (rAllocation.getPeriodicity() <= 0) { assertEquals(rAllocation.getEndTime(), plan.getLastEndTime()); } @@ -996,7 +999,7 @@ private void doAssertions(Plan plan, ReservationAllocation rAllocation) { assertEquals(maxAlloc, plan.getMaximumAllocation()); assertEquals(resCalc, plan.getResourceCalculator()); assertEquals(planName, plan.getQueueName()); - Assertions.assertTrue(plan.getMoveOnExpiry()); + assertTrue(plan.getMoveOnExpiry()); } private ReservationDefinition createSimpleReservationDefinition(long arrival, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryReservationAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryReservationAllocation.java index d3e4b62ba74bf..b43472f450692 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryReservationAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestInMemoryReservationAllocation.java @@ -17,6 +17,10 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; +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 java.util.HashMap; import java.util.Map; import java.util.Random; @@ -28,7 +32,6 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -71,9 +74,9 @@ public void testBlocks() { new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); - Assertions.assertFalse(rAllocation.containsGangs()); + assertFalse(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), + assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rAllocation.getResourcesAtTime(start + i)); } } @@ -94,9 +97,9 @@ public void testSteps() { new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); - Assertions.assertFalse(rAllocation.containsGangs()); + assertFalse(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals( + assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rAllocation.getResourcesAtTime(start + i)); } @@ -118,9 +121,9 @@ public void testSkyline() { new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); - Assertions.assertFalse(rAllocation.containsGangs()); + assertFalse(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals( + assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rAllocation.getResourcesAtTime(start + i)); } @@ -143,7 +146,7 @@ public void testZeroAlloaction() { start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, (int) start, alloc); - Assertions.assertFalse(rAllocation.containsGangs()); + assertFalse(rAllocation.containsGangs()); } @Test @@ -164,9 +167,9 @@ public void testGangAlloaction() { start, start + alloc.length + 1, allocations, resCalc, minAlloc, isGang); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); - Assertions.assertTrue(rAllocation.containsGangs()); + assertTrue(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), + assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rAllocation.getResourcesAtTime(start + i)); } } @@ -175,13 +178,13 @@ private void doAssertions(ReservationAllocation rAllocation, ReservationId reservationID, ReservationDefinition rDef, Map allocations, int start, int[] alloc) { - Assertions.assertEquals(reservationID, rAllocation.getReservationId()); - Assertions.assertEquals(rDef, rAllocation.getReservationDefinition()); - Assertions.assertEquals(allocations, rAllocation.getAllocationRequests()); - Assertions.assertEquals(user, rAllocation.getUser()); - Assertions.assertEquals(planName, rAllocation.getPlanName()); - Assertions.assertEquals(start, rAllocation.getStartTime()); - Assertions.assertEquals(start + alloc.length + 1, rAllocation.getEndTime()); + assertEquals(reservationID, rAllocation.getReservationId()); + assertEquals(rDef, rAllocation.getReservationDefinition()); + assertEquals(allocations, rAllocation.getAllocationRequests()); + assertEquals(user, rAllocation.getUser()); + assertEquals(planName, rAllocation.getPlanName()); + assertEquals(start, rAllocation.getStartTime()); + assertEquals(start + alloc.length + 1, rAllocation.getEndTime()); } private Map generateAllocation( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestNoOverCommitPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestNoOverCommitPolicy.java index 585c375166925..eb7c5522904af 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestNoOverCommitPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestNoOverCommitPolicy.java @@ -25,14 +25,12 @@ import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException; import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.ResourceOverCommitException; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * This clas tests {@code NoOverCommitPolicy} sharing policy. */ -@RunWith(value = Parameterized.class) @NotThreadSafe @SuppressWarnings("VisibilityModifier") public class TestNoOverCommitPolicy extends BaseSharingPolicyTest { @@ -40,8 +38,16 @@ public class TestNoOverCommitPolicy extends BaseSharingPolicyTest { final static long ONEHOUR = 3600 * 1000; final static String TWOHOURPERIOD = "7200000"; - @Parameterized.Parameters(name = "Duration {0}, height {1}," + - " submissions {2}, periodic {3})") + public void initTestNoOverCommitPolicy(long pDuration, + double pHeight, int pNumSubmissions, String pRecurrenceExpression, Class pExpectedError) { + this.duration = pDuration; + this.height = pHeight; + this.numSubmissions = pNumSubmissions; + this.recurrenceExpression = pRecurrenceExpression; + this.expectedError = pExpectedError; + super.setup(); + } + public static Collection data() { return Arrays.asList(new Object[][] { @@ -78,8 +84,14 @@ public SharingPolicy getInitializedPolicy() { return policy; } - @Test - public void testAllocation() throws IOException, PlanningException { + @ParameterizedTest(name = "Duration {0}, height {1}," + + " numSubmission {2}, periodic {3})") + @MethodSource("data") + public void testAllocation(long pDuration, + double pHeight, int pNumSubmissions, String pRecurrenceExpression, Class pExpectedError) + throws IOException, PlanningException { + initTestNoOverCommitPolicy(pDuration, pHeight, pNumSubmissions, + pRecurrenceExpression, pExpectedError); runTest(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestPeriodicRLESparseResourceAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestPeriodicRLESparseResourceAllocation.java index 0f06a25615610..9b484e83f724e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestPeriodicRLESparseResourceAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestPeriodicRLESparseResourceAllocation.java @@ -18,9 +18,12 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation; +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 org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,13 +46,13 @@ public void testPeriodicCapacity() { PeriodicRLESparseResourceAllocation periodicVector = new PeriodicRLESparseResourceAllocation(rleSparseVector, 20L); LOG.info(periodicVector.toString()); - Assertions.assertEquals(Resource.newInstance(5, 5), + assertEquals(Resource.newInstance(5, 5), periodicVector.getCapacityAtTime(10L)); - Assertions.assertEquals(Resource.newInstance(10, 10), + assertEquals(Resource.newInstance(10, 10), periodicVector.getCapacityAtTime(20L)); - Assertions.assertEquals(Resource.newInstance(7, 7), + assertEquals(Resource.newInstance(7, 7), periodicVector.getCapacityAtTime(27L)); - Assertions.assertEquals(Resource.newInstance(5, 5), + assertEquals(Resource.newInstance(5, 5), periodicVector.getCapacityAtTime(50L)); } @@ -62,15 +65,15 @@ public void testMaxPeriodicCapacity() { PeriodicRLESparseResourceAllocation periodicVector = new PeriodicRLESparseResourceAllocation(rleSparseVector, 8L); LOG.info(periodicVector.toString()); - Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(0, 1), + assertEquals(periodicVector.getMaximumPeriodicCapacity(0, 1), Resource.newInstance(10, 10)); - Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(8, 2), + assertEquals(periodicVector.getMaximumPeriodicCapacity(8, 2), Resource.newInstance(7, 7)); - Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(16, 3), + assertEquals(periodicVector.getMaximumPeriodicCapacity(16, 3), Resource.newInstance(10, 10)); - Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(17, 4), + assertEquals(periodicVector.getMaximumPeriodicCapacity(17, 4), Resource.newInstance(5, 5)); - Assertions.assertEquals(periodicVector.getMaximumPeriodicCapacity(32, 5), + assertEquals(periodicVector.getMaximumPeriodicCapacity(32, 5), Resource.newInstance(4, 4)); } @@ -93,23 +96,23 @@ public void testMixPeriodicAndNonPeriodic() throws PlanningException { Resource.newInstance(100 * 1024, 100), periodic, nonPeriodic, RLESparseResourceAllocation.RLEOperator.add, 2, 25); - Assertions.assertEquals(Resource.newInstance(5, 5), + assertEquals(Resource.newInstance(5, 5), merged.getCapacityAtTime(2L)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(3L)); - Assertions.assertEquals(Resource.newInstance(2, 2), + assertEquals(Resource.newInstance(2, 2), merged.getCapacityAtTime(11L)); - Assertions.assertEquals(Resource.newInstance(15, 15), + assertEquals(Resource.newInstance(15, 15), merged.getCapacityAtTime(12L)); - Assertions.assertEquals(Resource.newInstance(10, 10), + assertEquals(Resource.newInstance(10, 10), merged.getCapacityAtTime(13L)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(14L)); - Assertions.assertEquals(Resource.newInstance(2, 2), + assertEquals(Resource.newInstance(2, 2), merged.getCapacityAtTime(21L)); - Assertions.assertEquals(Resource.newInstance(5, 5), + assertEquals(Resource.newInstance(5, 5), merged.getCapacityAtTime(22L)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), merged.getCapacityAtTime(23L)); } @@ -123,15 +126,15 @@ public void testSetCapacityInInterval() { new PeriodicRLESparseResourceAllocation(rleSparseVector, 10L); ReservationInterval interval = new ReservationInterval(5L, 10L); periodicVector.addInterval(interval, Resource.newInstance(8, 8)); - Assertions.assertEquals(Resource.newInstance(8, 8), + assertEquals(Resource.newInstance(8, 8), periodicVector.getCapacityAtTime(5L)); - Assertions.assertEquals(Resource.newInstance(8, 8), + assertEquals(Resource.newInstance(8, 8), periodicVector.getCapacityAtTime(9L)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), periodicVector.getCapacityAtTime(10L)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), periodicVector.getCapacityAtTime(0L)); - // Assertions.assertFalse(periodicVector.addInterval( + // assertFalse(periodicVector.addInterval( // new ReservationInterval(7L, 12L), Resource.newInstance(8, 8))); } @@ -143,29 +146,29 @@ public void testRemoveInterval() { PeriodicRLESparseResourceAllocation periodicVector = new PeriodicRLESparseResourceAllocation(rleSparseVector, 10L); ReservationInterval interval = new ReservationInterval(3L, 7L); - Assertions.assertTrue( + assertTrue( periodicVector.removeInterval(interval, Resource.newInstance(3, 3))); - Assertions.assertEquals(Resource.newInstance(2, 2), + assertEquals(Resource.newInstance(2, 2), periodicVector.getCapacityAtTime(1L)); - Assertions.assertEquals(Resource.newInstance(2, 2), + assertEquals(Resource.newInstance(2, 2), periodicVector.getCapacityAtTime(2L)); - Assertions.assertEquals(Resource.newInstance(2, 2), + assertEquals(Resource.newInstance(2, 2), periodicVector.getCapacityAtTime(3L)); - Assertions.assertEquals(Resource.newInstance(2, 2), + assertEquals(Resource.newInstance(2, 2), periodicVector.getCapacityAtTime(4L)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), periodicVector.getCapacityAtTime(5L)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), periodicVector.getCapacityAtTime(6L)); - Assertions.assertEquals(Resource.newInstance(4, 4), + assertEquals(Resource.newInstance(4, 4), periodicVector.getCapacityAtTime(7L)); // invalid interval - Assertions.assertFalse(periodicVector.removeInterval( + assertFalse(periodicVector.removeInterval( new ReservationInterval(7L, 12L), Resource.newInstance(1, 1))); // invalid capacity - Assertions.assertFalse(periodicVector.removeInterval( + assertFalse(periodicVector.removeInterval( new ReservationInterval(2L, 4L), Resource.newInstance(8, 8))); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java index b810d27014449..e38bebad4a338 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestRLESparseResourceAllocation.java @@ -18,7 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.util.HashMap; @@ -34,8 +36,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.jupiter.api.Assertions; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -251,7 +252,7 @@ public void testMergesubtractTestNonNegative() throws PlanningException { } @Test - @Ignore + @Disabled public void testMergeSpeed() throws PlanningException { for (int j = 0; j < 100; j++) { @@ -322,26 +323,26 @@ public void testBlocks() { rleSparseVector.addInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); - Assertions.assertFalse(rleSparseVector.isEmpty()); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertFalse(rleSparseVector.isEmpty()); + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), + assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rleSparseVector.getCapacityAtTime(start + i)); } - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i)); } - Assertions.assertTrue(rleSparseVector.isEmpty()); + assertTrue(rleSparseVector.isEmpty()); } @Test @@ -374,28 +375,28 @@ public void testPartialRemoval() { // Current bug prevents this to pass. The RLESparseResourceAllocation // does not handle removal of "partial" // allocations correctly. - Assertions.assertEquals(102400, + assertEquals(102400, rleSparseVector.getCapacityAtTime(10).getMemorySize()); - Assertions.assertEquals(0, + assertEquals(0, rleSparseVector.getCapacityAtTime(13).getMemorySize()); - Assertions.assertEquals(0, + assertEquals(0, rleSparseVector.getCapacityAtTime(19).getMemorySize()); - Assertions.assertEquals(102400, + assertEquals(102400, rleSparseVector.getCapacityAtTime(21).getMemorySize()); - Assertions.assertEquals(2 * 102400, + assertEquals(2 * 102400, rleSparseVector.getCapacityAtTime(26).getMemorySize()); ReservationInterval riRemove2 = new ReservationInterval(9, 13); rleSparseVector.removeInterval(riRemove2, rr); LOG.info(rleSparseVector.toString()); - Assertions.assertEquals(0, + assertEquals(0, rleSparseVector.getCapacityAtTime(11).getMemorySize()); - Assertions.assertEquals(-102400, + assertEquals(-102400, rleSparseVector.getCapacityAtTime(9).getMemorySize()); - Assertions.assertEquals(0, + assertEquals(0, rleSparseVector.getCapacityAtTime(13).getMemorySize()); - Assertions.assertEquals(102400, + assertEquals(102400, rleSparseVector.getCapacityAtTime(20).getMemorySize()); } @@ -414,27 +415,27 @@ public void testSteps() { rleSparseVector.addInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); - Assertions.assertFalse(rleSparseVector.isEmpty()); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertFalse(rleSparseVector.isEmpty()); + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals( + assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rleSparseVector.getCapacityAtTime(start + i)); } - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i)); } - Assertions.assertTrue(rleSparseVector.isEmpty()); + assertTrue(rleSparseVector.isEmpty()); } @Test @@ -451,27 +452,27 @@ public void testSkyline() { rleSparseVector.addInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); - Assertions.assertFalse(rleSparseVector.isEmpty()); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertFalse(rleSparseVector.isEmpty()); + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(99)); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 1)); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals( + assertEquals( Resource.newInstance(1024 * (alloc[i] + i), (alloc[i] + i)), rleSparseVector.getCapacityAtTime(start + i)); } - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + alloc.length + 2)); for (Entry ip : inputs) { rleSparseVector.removeInterval(ip.getKey(), ip.getValue()); } LOG.info(rleSparseVector.toString()); for (int i = 0; i < alloc.length; i++) { - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(start + i)); } - Assertions.assertTrue(rleSparseVector.isEmpty()); + assertTrue(rleSparseVector.isEmpty()); } @Test @@ -482,9 +483,9 @@ public void testZeroAllocation() { rleSparseVector.addInterval(new ReservationInterval(0, Long.MAX_VALUE), Resource.newInstance(0, 0)); LOG.info(rleSparseVector.toString()); - Assertions.assertEquals(Resource.newInstance(0, 0), + assertEquals(Resource.newInstance(0, 0), rleSparseVector.getCapacityAtTime(new Random().nextLong())); - Assertions.assertTrue(rleSparseVector.isEmpty()); + assertTrue(rleSparseVector.isEmpty()); } @Test @@ -496,7 +497,7 @@ public void testToIntervalMap() { // Check empty mapAllocations = rleSparseVector.toIntervalMap(); - Assertions.assertTrue(mapAllocations.isEmpty()); + assertTrue(mapAllocations.isEmpty()); // Check full int[] alloc = { 0, 5, 10, 10, 5, 0, 5, 0 }; @@ -507,28 +508,28 @@ public void testToIntervalMap() { rleSparseVector.addInterval(ip.getKey(), ip.getValue()); } mapAllocations = rleSparseVector.toIntervalMap(); - Assertions.assertTrue(mapAllocations.size() == 5); + assertTrue(mapAllocations.size() == 5); for (Entry entry : mapAllocations .entrySet()) { ReservationInterval interval = entry.getKey(); Resource resource = entry.getValue(); if (interval.getStartTime() == 101L) { - Assertions.assertTrue(interval.getEndTime() == 102L); - Assertions.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); + assertTrue(interval.getEndTime() == 102L); + assertEquals(resource, Resource.newInstance(5 * 1024, 5)); } else if (interval.getStartTime() == 102L) { - Assertions.assertTrue(interval.getEndTime() == 104L); - Assertions.assertEquals(resource, Resource.newInstance(10 * 1024, 10)); + assertTrue(interval.getEndTime() == 104L); + assertEquals(resource, Resource.newInstance(10 * 1024, 10)); } else if (interval.getStartTime() == 104L) { - Assertions.assertTrue(interval.getEndTime() == 105L); - Assertions.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); + assertTrue(interval.getEndTime() == 105L); + assertEquals(resource, Resource.newInstance(5 * 1024, 5)); } else if (interval.getStartTime() == 105L) { - Assertions.assertTrue(interval.getEndTime() == 106L); - Assertions.assertEquals(resource, Resource.newInstance(0 * 1024, 0)); + assertTrue(interval.getEndTime() == 106L); + assertEquals(resource, Resource.newInstance(0 * 1024, 0)); } else if (interval.getStartTime() == 106L) { - Assertions.assertTrue(interval.getEndTime() == 107L); - Assertions.assertEquals(resource, Resource.newInstance(5 * 1024, 5)); + assertTrue(interval.getEndTime() == 107L); + assertEquals(resource, Resource.newInstance(5 * 1024, 5)); } else { - Assertions.fail(); + fail(); } } } @@ -540,21 +541,21 @@ public void testMaxPeriodicCapacity() { RLESparseResourceAllocation rleSparseVector = ReservationSystemTestUtil .generateRLESparseResourceAllocation(alloc, timeSteps); LOG.info(rleSparseVector.toString()); - Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 1), + assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 1), Resource.newInstance(10, 10)); - Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 2), + assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 2), Resource.newInstance(7, 7)); - Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 3), + assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 3), Resource.newInstance(10, 10)); - Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 4), + assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 4), Resource.newInstance(3, 3)); - Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 5), + assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 5), Resource.newInstance(4, 4)); - Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 5), + assertEquals(rleSparseVector.getMaximumPeriodicCapacity(0, 5), Resource.newInstance(4, 4)); - Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(7, 5), + assertEquals(rleSparseVector.getMaximumPeriodicCapacity(7, 5), Resource.newInstance(8, 8)); - Assertions.assertEquals(rleSparseVector.getMaximumPeriodicCapacity(10, 3), + assertEquals(rleSparseVector.getMaximumPeriodicCapacity(10, 3), Resource.newInstance(0, 0)); } @@ -565,11 +566,11 @@ public void testGetMinimumCapacityInInterval() { RLESparseResourceAllocation rleSparseVector = ReservationSystemTestUtil .generateRLESparseResourceAllocation(alloc, timeSteps); LOG.info(rleSparseVector.toString()); - Assertions.assertEquals(rleSparseVector.getMinimumCapacityInInterval( + assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(1L, 3L)), Resource.newInstance(5, 5)); - Assertions.assertEquals(rleSparseVector.getMinimumCapacityInInterval( + assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(2L, 5L)), Resource.newInstance(3, 3)); - Assertions.assertEquals(rleSparseVector.getMinimumCapacityInInterval( + assertEquals(rleSparseVector.getMinimumCapacityInInterval( new ReservationInterval(1L, 7L)), Resource.newInstance(0, 0)); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java index 75e3510e63e29..458667c5669b2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java @@ -17,6 +17,11 @@ *******************************************************************************/ package org.apache.hadoop.yarn.server.resourcemanager.reservation; +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.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -50,7 +55,6 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -104,9 +108,9 @@ public void testSubmitReservationNormal() { rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); } catch (YarnException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan); + assertNotNull(plan); } @Test @@ -118,11 +122,11 @@ public void testSubmitReservationDoesNotExist() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertEquals("The queue is not specified. Please try again with a " + assertEquals("The queue is not specified. Please try again with a " + "valid reservable queue.", message); LOG.info(message); } @@ -138,13 +142,12 @@ public void testSubmitReservationInvalidPlan() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message - .endsWith(" is not managed by reservation system. Please try again with a valid reservable queue.")); + assertTrue(message.endsWith(" is not managed by reservation system. " + + "Please try again with a valid reservable queue.")); LOG.info(message); } } @@ -159,11 +162,11 @@ public void testSubmitReservationNoDefinition() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertEquals("Missing reservation definition. Please try again by " + assertEquals("Missing reservation definition. Please try again by " + "specifying a reservation definition.", message); LOG.info(message); } @@ -178,11 +181,11 @@ public void testSubmitReservationInvalidDeadline() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("The specified deadline: 0 is the past")); LOG.info(message); } @@ -197,11 +200,11 @@ public void testSubmitReservationInvalidRR() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } @@ -216,11 +219,11 @@ public void testSubmitReservationEmptyRR() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } @@ -235,14 +238,13 @@ public void testSubmitReservationInvalidDuration() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message.startsWith("The time difference")); - Assertions - .assertTrue(message - .contains("must be greater or equal to the minimum resource duration")); + assertTrue(message.startsWith("The time difference")); + assertTrue(message + .contains("must be greater or equal to the minimum resource duration")); LOG.info(message); } } @@ -258,13 +260,13 @@ public void testSubmitReservationExceedsGangSize() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message.startsWith( + assertTrue(message.startsWith( "The size of the largest gang in the reservation definition")); - Assertions.assertTrue(message.contains( + assertTrue(message.contains( "exceed the capacity available ")); LOG.info(message); } @@ -280,9 +282,9 @@ public void testSubmitReservationValidRecurrenceExpression() { rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); } catch (YarnException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan); + assertNotNull(plan); } @Test @@ -294,11 +296,11 @@ public void testSubmitReservationNegativeRecurrenceExpression() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("Negative Period : ")); LOG.info(message); } @@ -315,11 +317,11 @@ public void testSubmitReservationMaxPeriodIndivisibleByRecurrenceExp() { try { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message.startsWith("The maximum periodicity:")); + assertTrue(message.startsWith("The maximum periodicity:")); LOG.info(message); } } @@ -334,11 +336,11 @@ public void testSubmitReservationInvalidRecurrenceExpression() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("Invalid period ")); LOG.info(message); } @@ -351,11 +353,11 @@ public void testSubmitReservationInvalidRecurrenceExpression() { plan = rrValidator.validateReservationSubmissionRequest(rSystem, request, ReservationSystemTestUtil.getNewReservationId()); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("Duration of the requested reservation:")); LOG.info(message); } @@ -369,9 +371,9 @@ public void testUpdateReservationNormal() { try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); } catch (YarnException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan); + assertNotNull(plan); } @Test @@ -380,13 +382,12 @@ public void testUpdateReservationNoID() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message - .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); + assertTrue(message + .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); LOG.info(message); } } @@ -400,15 +401,13 @@ public void testUpdateReservationDoesnotExist() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message.equals(MessageFormat - .format( - "The specified reservation with ID: {0} is unknown. Please try again with a valid reservation.", - rId))); + assertTrue(message.equals(MessageFormat + .format("The specified reservation with ID: {0} is unknown. " + + "Please try again with a valid reservation.", rId))); LOG.info(message); } } @@ -421,13 +420,13 @@ public void testUpdateReservationInvalidPlan() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message - .endsWith(" is not associated with any valid plan. Please try again with a valid reservation.")); + assertTrue(message + .endsWith(" is not associated with any valid plan. " + + "Please try again with a valid reservation.")); LOG.info(message); } } @@ -439,13 +438,12 @@ public void testUpdateReservationNoDefinition() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message - .startsWith("Missing reservation definition. Please try again by specifying a reservation definition.")); + assertTrue(message.startsWith("Missing reservation definition. " + + "Please try again by specifying a reservation definition.")); LOG.info(message); } } @@ -457,11 +455,11 @@ public void testUpdateReservationInvalidDeadline() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("The specified deadline: 0 is the past")); LOG.info(message); } @@ -474,11 +472,11 @@ public void testUpdateReservationInvalidRR() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } @@ -491,11 +489,11 @@ public void testUpdateReservationEmptyRR() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("No resources have been specified to reserve")); LOG.info(message); } @@ -508,13 +506,12 @@ public void testUpdateReservationInvalidDuration() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message - .contains("must be greater or equal to the minimum resource duration")); + assertTrue(message.contains("must be greater or " + + "equal to the minimum resource duration")); LOG.info(message); } } @@ -528,13 +525,13 @@ public void testUpdateReservationExceedsGangSize() { Plan plan = null; try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message.startsWith( + assertTrue(message.startsWith( "The size of the largest gang in the reservation definition")); - Assertions.assertTrue(message.contains( + assertTrue(message.contains( "exceed the capacity available ")); LOG.info(message); } @@ -549,9 +546,9 @@ public void testUpdateReservationValidRecurrenceExpression() { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); } catch (YarnException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan); + assertNotNull(plan); } @Test @@ -562,11 +559,11 @@ public void testUpdateReservationNegativeRecurrenceExpression() { try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("Negative Period : ")); LOG.info(message); } @@ -581,11 +578,11 @@ public void testUpdateReservationInvalidRecurrenceExpression() { try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("Invalid period ")); LOG.info(message); } @@ -597,11 +594,11 @@ public void testUpdateReservationInvalidRecurrenceExpression() { try { plan = rrValidator.validateReservationUpdateRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message + assertTrue(message .startsWith("Duration of the requested reservation:")); LOG.info(message); } @@ -619,9 +616,9 @@ public void testDeleteReservationNormal() { try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); } catch (YarnException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan); + assertNotNull(plan); } @Test @@ -630,13 +627,12 @@ public void testDeleteReservationNoID() { Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message - .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); + assertTrue(message + .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); LOG.info(message); } } @@ -650,15 +646,13 @@ public void testDeleteReservationDoesnotExist() { Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message.equals(MessageFormat - .format( - "The specified reservation with ID: {0} is unknown. Please try again with a valid reservation.", - rId))); + assertTrue(message.equals(MessageFormat + .format("The specified reservation with ID: {0} is unknown. " + + "Please try again with a valid reservation.", rId))); LOG.info(message); } } @@ -673,13 +667,12 @@ public void testDeleteReservationInvalidPlan() { Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions - .assertTrue(message - .endsWith(" is not associated with any valid plan. Please try again with a valid reservation.")); + assertTrue(message.endsWith(" is not associated with any valid plan. " + + "Please try again with a valid reservation.")); LOG.info(message); } } @@ -696,9 +689,9 @@ public void testListReservationsNormal() { try { plan = rrValidator.validateReservationListRequest(rSystem, request); } catch (YarnException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan); + assertNotNull(plan); } @Test @@ -715,9 +708,9 @@ public void testListReservationsInvalidTimeIntervalDefaults() { try { plan = rrValidator.validateReservationListRequest(rSystem, request); } catch (YarnException e) { - Assertions.fail(e.getMessage()); + fail(e.getMessage()); } - Assertions.assertNotNull(plan); + assertNotNull(plan); } @Test @@ -731,11 +724,11 @@ public void testListReservationsInvalidTimeInterval() { Plan plan = null; try { plan = rrValidator.validateReservationListRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message.equals("The specified end time must be " + + assertTrue(message.equals("The specified end time must be " + "greater than the specified start time.")); LOG.info(message); } @@ -748,11 +741,11 @@ public void testListReservationsEmptyQueue() { Plan plan = null; try { plan = rrValidator.validateReservationListRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message.equals( + assertTrue(message.equals( "The queue is not specified. Please try again with a valid " + "reservable queue.")); LOG.info(message); @@ -768,11 +761,11 @@ public void testListReservationsNullPlan() { Plan plan = null; try { plan = rrValidator.validateReservationListRequest(rSystem, request); - Assertions.fail(); + fail(); } catch (YarnException e) { - Assertions.assertNull(plan); + assertNull(plan); String message = e.getMessage(); - Assertions.assertTrue(message.equals( + assertTrue(message.equals( "The specified queue: " + ReservationSystemTestUtil.reservationQ + " is not managed by reservation system." + " Please try again with a valid reservable 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/reservation/TestReservationSystemUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java index 0043d2c8ac833..cfb67997e8240 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationSystemUtil.java @@ -18,6 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation; import static org.assertj.core.api.Assertions.assertThat; +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 org.apache.hadoop.yarn.api.records.ReservationAllocationState; @@ -26,7 +29,6 @@ import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -53,7 +55,7 @@ public void testConvertAllocationsToReservationInfo() { assertThat(infoList).hasSize(1); assertThat(infoList.get(0).getReservationId().toString()).isEqualTo( id.toString()); - Assertions.assertFalse(infoList.get(0).getResourceAllocationRequests() + assertFalse(infoList.get(0).getResourceAllocationRequests() .isEmpty()); } @@ -71,10 +73,10 @@ public void testConvertAllocationsToReservationInfoNoAllocations() { .convertAllocationsToReservationInfo( Collections.singleton(allocation), false); - Assertions.assertEquals(infoList.size(), 1); - Assertions.assertEquals(infoList.get(0).getReservationId().toString(), + assertEquals(infoList.size(), 1); + assertEquals(infoList.get(0).getReservationId().toString(), id.toString()); - Assertions.assertTrue(infoList.get(0).getResourceAllocationRequests() + assertTrue(infoList.get(0).getResourceAllocationRequests() .isEmpty()); } @@ -92,10 +94,10 @@ public void testConvertAllocationsToReservationInfoEmptyAllocations() { .convertAllocationsToReservationInfo( Collections.singleton(allocation), false); - Assertions.assertEquals(infoList.size(), 1); - Assertions.assertEquals(infoList.get(0).getReservationId().toString(), + assertEquals(infoList.size(), 1); + assertEquals(infoList.get(0).getReservationId().toString(), id.toString()); - Assertions.assertTrue(infoList.get(0).getResourceAllocationRequests() + assertTrue(infoList.get(0).getResourceAllocationRequests() .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/reservation/TestSchedulerPlanFollowerBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestSchedulerPlanFollowerBase.java index 5f737cf471d55..a7f3d3746654a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestSchedulerPlanFollowerBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestSchedulerPlanFollowerBase.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.reservation; +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; @@ -43,7 +44,6 @@ import org.apache.hadoop.yarn.util.Clock; import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator; import org.apache.hadoop.yarn.util.resource.ResourceCalculator; -import org.junit.jupiter.api.Assertions; public abstract class TestSchedulerPlanFollowerBase { final static int GB = 1024; @@ -73,23 +73,23 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( 0, 0 + f1.length + 1, f1.length); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r1, rDef, "u3", - "dedicated", 0, 0 + f1.length, ReservationSystemTestUtil - .generateAllocation(0L, 1L, f1), res, minAlloc), false), plan.toString()); + assertTrue(plan.addReservation(new InMemoryReservationAllocation(r1, rDef, "u3", + "dedicated", 0, 0 + f1.length, ReservationSystemTestUtil + .generateAllocation(0L, 1L, f1), res, minAlloc), false), + plan.toString()); ReservationId r2 = ReservationId.newInstance(ts, 2); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r2, rDef, "u3", - "dedicated", 3, 3 + f1.length, ReservationSystemTestUtil - .generateAllocation(3L, 1L, f1), res, minAlloc), false), plan.toString()); + assertTrue(plan.addReservation(new InMemoryReservationAllocation(r2, rDef, "u3", + "dedicated", 3, 3 + f1.length, ReservationSystemTestUtil + .generateAllocation(3L, 1L, f1), res, minAlloc), false), + plan.toString()); ReservationId r3 = ReservationId.newInstance(ts, 3); int[] f2 = { 0, 10, 20, 10, 0 }; - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r3, rDef, "u4", - "dedicated", 10, 10 + f2.length, ReservationSystemTestUtil - .generateAllocation(10L, 1L, f2), res, minAlloc), false), plan.toString()); + assertTrue(plan.addReservation(new InMemoryReservationAllocation(r3, rDef, "u4", + "dedicated", 10, 10 + f2.length, ReservationSystemTestUtil + .generateAllocation(10L, 1L, f2), res, minAlloc), false), + plan.toString()); // default reseration queue should exist before run of PlanFollower AND have @@ -124,10 +124,10 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, // initial default reservation queue should have no apps after first run Queue defQ = getDefaultQueue(); - Assertions.assertEquals(0, getNumberOfApplications(defQ)); + assertEquals(0, getNumberOfApplications(defQ)); assertReservationQueueExists(r1, 0.1, 0.1); - Assertions.assertEquals(1, getNumberOfApplications(q)); + assertEquals(1, getNumberOfApplications(q)); assertReservationQueueDoesNotExist(r2); assertReservationQueueDoesNotExist(r3); @@ -135,9 +135,9 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, when(mClock.getTime()).thenReturn(3L); planFollower.run(); - Assertions.assertEquals(0, getNumberOfApplications(defQ)); + assertEquals(0, getNumberOfApplications(defQ)); assertReservationQueueExists(r1, 0.1, 0.1); - Assertions.assertEquals(1, getNumberOfApplications(q)); + assertEquals(1, getNumberOfApplications(q)); assertReservationQueueExists(r2, 0.1, 0.1); assertReservationQueueDoesNotExist(r3); @@ -147,11 +147,11 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, q = getReservationQueue(r1.toString()); if (isMove) { // app should have been moved to default reservation queue - Assertions.assertEquals(1, getNumberOfApplications(defQ)); + assertEquals(1, getNumberOfApplications(defQ)); assertNull(q); } else { // app should be killed - Assertions.assertEquals(0, getNumberOfApplications(defQ)); + assertEquals(0, getNumberOfApplications(defQ)); assertNotNull(q); AppAttemptRemovedSchedulerEvent appAttemptRemovedEvent = new AppAttemptRemovedSchedulerEvent(appAttemptId_0, @@ -166,10 +166,10 @@ protected void testPlanFollower(boolean isMove) throws PlanningException, if (isMove) { // app should have been moved to default reservation queue - Assertions.assertEquals(1, getNumberOfApplications(defQ)); + assertEquals(1, getNumberOfApplications(defQ)); } else { // app should be killed - Assertions.assertEquals(0, getNumberOfApplications(defQ)); + assertEquals(0, getNumberOfApplications(defQ)); } assertReservationQueueDoesNotExist(r1); assertReservationQueueDoesNotExist(r2); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java index 014f199df8e48..b2e154be3a74b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java @@ -57,9 +57,8 @@ import org.apache.hadoop.yarn.util.resource.ResourceCalculator; import org.apache.hadoop.yarn.util.resource.Resources; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,12 +66,10 @@ /** * This class tests the {@code AlignedPlannerWithGreedy} agent. */ -@RunWith(value = Parameterized.class) @NotThreadSafe @SuppressWarnings("VisibilityModifier") public class TestAlignedPlanner { - @Parameterized.Parameter(value = 0) public String recurrenceExpression; final static String NONPERIODIC = "0"; @@ -92,8 +89,6 @@ public class TestAlignedPlanner { private Resource clusterCapacity; private long step; - - @Parameterized.Parameters(name = "Testing: periodicity {0})") public static Collection data() { return Arrays.asList(new Object[][]{ {NONPERIODIC}, @@ -102,8 +97,15 @@ public static Collection data() { }); } - @Test - public void testSingleReservationAccept() throws PlanningException { + public void initTestAlignedPlanner(String pRecurrenceExpression) { + this.recurrenceExpression = pRecurrenceExpression; + } + + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testSingleReservationAccept(String pRecurrenceExpression) throws PlanningException { + + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario1(); @@ -142,9 +144,10 @@ public void testSingleReservationAccept() throws PlanningException { } - @Test - public void testOrderNoGapImpossible() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testOrderNoGapImpossible(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario2(); @@ -182,9 +185,10 @@ public void testOrderNoGapImpossible() throws PlanningException { } - @Test - public void testOrderNoGapImpossible2() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testOrderNoGapImpossible2(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario2(); @@ -222,9 +226,10 @@ public void testOrderNoGapImpossible2() throws PlanningException { } - @Test - public void testOrderImpossible() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testOrderImpossible(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario2(); @@ -262,9 +267,10 @@ public void testOrderImpossible() throws PlanningException { } - @Test - public void testAnyImpossible() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testAnyImpossible(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario2(); @@ -302,9 +308,10 @@ public void testAnyImpossible() throws PlanningException { } - @Test - public void testAnyAccept() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testAnyAccept(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario2(); @@ -345,9 +352,10 @@ public void testAnyAccept() throws PlanningException { } - @Test - public void testAllAccept() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testAllAccept(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario2(); @@ -390,9 +398,10 @@ public void testAllAccept() throws PlanningException { } - @Test - public void testAllImpossible() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testAllImpossible(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario2(); @@ -430,9 +439,10 @@ public void testAllImpossible() throws PlanningException { } - @Test - public void testUpdate() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testUpdate(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Create flexible reservation ReservationDefinition rrFlex = createReservationDefinition( @@ -483,9 +493,10 @@ public void testUpdate() throws PlanningException { } - @Test - public void testImpossibleDuration() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testImpossibleDuration(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Create reservation ReservationDefinition rr1 = createReservationDefinition( @@ -514,9 +525,10 @@ public void testImpossibleDuration() throws PlanningException { } - @Test - public void testLoadedDurationIntervals() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testLoadedDurationIntervals(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); int numJobsInScenario = initializeScenario3(); // Create reservation @@ -553,9 +565,10 @@ public void testLoadedDurationIntervals() throws PlanningException { check(alloc1, 12 * step, 13 * step, 40, 1024, 1), alloc1.toString()); } - @Test - public void testCostFunction() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testCostFunction(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Create large memory reservation ReservationDefinition rr7Mem1Core = createReservationDefinition( @@ -615,9 +628,10 @@ public void testCostFunction() throws PlanningException { } - @Test - public void testFromCluster() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testFromCluster(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // int numJobsInScenario = initializeScenario3(); List list = new ArrayList(); @@ -739,10 +753,11 @@ public void testFromCluster() throws PlanningException { } - @Test - public void testSingleReservationAcceptAllocateLeft() + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testSingleReservationAcceptAllocateLeft(String pRecurrenceExpression) throws PlanningException { - + initTestAlignedPlanner(pRecurrenceExpression); // Create reservation ReservationDefinition rr1 = createReservationDefinition( @@ -780,9 +795,10 @@ public void testSingleReservationAcceptAllocateLeft() } - @Test - public void testLeftSucceedsRightFails() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testLeftSucceedsRightFails(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); // Prepare basic plan int numJobsInScenario = initializeScenario2(); @@ -875,9 +891,10 @@ public void testLeftSucceedsRightFails() throws PlanningException { } - @Test - public void testValidateOrderNoGap() { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testValidateOrderNoGap(String pRecurrenceExpression) { + initTestAlignedPlanner(pRecurrenceExpression); // // Initialize allocations // @@ -941,9 +958,10 @@ public void testValidateOrderNoGap() { } - @Test - public void testGetDurationInterval() throws PlanningException { - + @ParameterizedTest(name = "Testing: periodicity {0}") + @MethodSource("data") + public void testGetDurationInterval(String pRecurrenceExpression) throws PlanningException { + initTestAlignedPlanner(pRecurrenceExpression); DurationInterval durationInterval = null; // Create netRLERes: diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java index a01e0e38d38b2..07f5af82cccb6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java @@ -55,22 +55,18 @@ 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.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@RunWith(Parameterized.class) + @SuppressWarnings("VisibilityModifier") public class TestGreedyReservationAgent { - @Parameterized.Parameter(value = 0) public boolean allocateLeft; - @Parameterized.Parameter(value = 1) public String recurrenceExpression; private static final Logger LOG = LoggerFactory @@ -84,8 +80,6 @@ public class TestGreedyReservationAgent { Random rand = new Random(); long step; - @Parameterized.Parameters(name = "Testing: allocateLeft {0}," + - " recurrenceExpression {1})") public static Collection data() { return Arrays.asList(new Object[][] { {true, "0"}, @@ -97,7 +91,13 @@ public static Collection data() { }); } - @BeforeEach + public void initTestGreedyReservationAgent(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + this.allocateLeft = pAllocateLeft; + this.recurrenceExpression = pRecurrenceExpression; + setup(); + } + public void setup() throws Exception { long seed = rand.nextLong(); @@ -134,9 +134,12 @@ public void setup() throws Exception { } @SuppressWarnings("javadoc") - @Test - public void testSimple() throws PlanningException { - + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testSimple(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create a request with a single atomic ask @@ -183,9 +186,12 @@ public void testSimple() throws PlanningException { } @SuppressWarnings("javadoc") - @Test - public void testSharingPolicyFeedback() throws PlanningException { - + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testSharingPolicyFeedback(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // let's constraint the instantaneous allocation and see the @@ -286,8 +292,12 @@ public void testSharingPolicyFeedback() throws PlanningException { } } - @Test - public void testOrder() throws PlanningException { + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testOrder(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create a completely utilized segment around time 30 @@ -354,8 +364,12 @@ public void testOrder() throws PlanningException { } - @Test - public void testOrderNoGapImpossible() throws PlanningException { + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testOrderNoGapImpossible(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create a completely utilized segment at time 30 int[] f = { 100, 100 }; @@ -413,8 +427,12 @@ public void testOrderNoGapImpossible() throws PlanningException { } - @Test - public void testOrderNoGap() throws PlanningException { + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testOrderNoGap(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create a chain of 4 RR, mixing gang and non-gang ReservationDefinition rr = new ReservationDefinitionPBImpl(); @@ -460,8 +478,12 @@ public void testOrderNoGap() throws PlanningException { } - @Test - public void testSingleSliding() throws PlanningException { + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testSingleSliding(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create a single request for which we need subsequent (tight) packing. @@ -500,8 +522,12 @@ public void testSingleSliding() throws PlanningException { } - @Test - public void testAny() throws PlanningException { + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testAny(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create an ANY request, with an impossible step (last in list, first // considered), @@ -552,8 +578,12 @@ public void testAny() throws PlanningException { } - @Test - public void testAnyImpossible() throws PlanningException { + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testAnyImpossible(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create an ANY request, with all impossible alternatives ReservationDefinition rr = new ReservationDefinitionPBImpl(); @@ -598,8 +628,12 @@ public void testAnyImpossible() throws PlanningException { } - @Test - public void testAll() throws PlanningException { + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testAll(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create an ALL request ReservationDefinition rr = new ReservationDefinitionPBImpl(); @@ -646,8 +680,12 @@ public void testAll() throws PlanningException { } - @Test - public void testAllImpossible() throws PlanningException { + @ParameterizedTest(name = "Testing: allocateLeft {0}," + + " recurrenceExpression {1}") + @MethodSource("data") + public void testAllImpossible(boolean pAllocateLeft, + String pRecurrenceExpression) throws Exception { + initTestGreedyReservationAgent(pAllocateLeft, pRecurrenceExpression); prepareBasicPlan(); // create an ALL request, with an impossible combination, it should be // rejected, and allocation remain unchanged diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestReservationAgents.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestReservationAgents.java index b0c832dc4d698..3005ba14e12ce 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestReservationAgents.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestReservationAgents.java @@ -38,10 +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.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,20 +56,15 @@ /** * General purpose ReservationAgent tester. */ -@RunWith(Parameterized.class) @SuppressWarnings("VisibilityModifier") public class TestReservationAgents { - @Parameterized.Parameter(value = 0) public Class agentClass; - @Parameterized.Parameter(value = 1) public boolean allocateLeft; - @Parameterized.Parameter(value = 2) public String recurrenceExpression; - @Parameterized.Parameter(value = 3) public int numOfNodes; private long step; @@ -87,8 +80,15 @@ public class TestReservationAgents { private static final Logger LOG = LoggerFactory.getLogger(TestReservationAgents.class); - @Parameterized.Parameters(name = "Testing: agent {0}, allocateLeft: {1}," + - " recurrenceExpression: {2}, numNodes: {3})") + public void initTestReservationAgents(Class pAgentClass, boolean pAllocateLeft, + String pRecurrenceExpression, int pNumOfNodes) throws Exception { + this.agentClass = pAgentClass; + this.allocateLeft = pAllocateLeft; + this.recurrenceExpression = pRecurrenceExpression; + this.numOfNodes = pNumOfNodes; + setup(); + } + public static Collection data() { return Arrays.asList( new Object[][] {{GreedyReservationAgent.class, true, "0", 100 }, @@ -105,7 +105,6 @@ public static Collection data() { {AlignedPlannerWithGreedy.class, false, "86400000", 100 } }); } - @BeforeEach public void setup() throws Exception { long seed = rand.nextLong(); @@ -141,8 +140,12 @@ public void setup() throws Exception { resCalc, minAlloc, maxAlloc, "dedicated", null, true, context); } - @Test - public void test() throws Exception { + @ParameterizedTest(name = "Testing: agent {0}, allocateLeft: {1}," + + " recurrenceExpression: {2}, numNodes: {3}") + @MethodSource("data") + public void test(Class pAgentClass, boolean pAllocateLeft, + String pRecurrenceExpression, int pNumOfNodes) throws Exception { + initTestReservationAgents(pAgentClass, pAllocateLeft, pRecurrenceExpression, pNumOfNodes); long period = Long.parseLong(recurrenceExpression); for (int i = 0; i < 1000; 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/reservation/planning/TestSimpleCapacityReplanner.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java index c9e7f6373eff3..1a78f609cd12b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java @@ -93,28 +93,28 @@ public void testReplanningPlanCapacityLoss() throws PlanningException { ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( 0, 0 + f5.length, f5.length); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r1, rDef, "u3", - "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false), plan.toString()); + assertTrue(plan.addReservation( + new InMemoryReservationAllocation(r1, rDef, "u3", + "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(1L); ReservationId r2 = ReservationId.newInstance(ts, 2); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r2, rDef, "u4", - "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false), plan.toString()); + assertTrue(plan.addReservation( + new InMemoryReservationAllocation(r2, rDef, "u4", + "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(2L); ReservationId r3 = ReservationId.newInstance(ts, 3); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r3, rDef, "u5", - "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false), plan.toString()); + assertTrue(plan.addReservation( + new InMemoryReservationAllocation(r3, rDef, "u5", + "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(3L); ReservationId r4 = ReservationId.newInstance(ts, 4); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r4, rDef, "u6", - "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false), plan.toString()); + assertTrue(plan.addReservation( + new InMemoryReservationAllocation(r4, rDef, "u6", + "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(4L); ReservationId r5 = ReservationId.newInstance(ts, 5); assertTrue( @@ -124,16 +124,16 @@ public void testReplanningPlanCapacityLoss() throws PlanningException { int[] f6 = { 50, 50, 50, 50, 50 }; ReservationId r6 = ReservationId.newInstance(ts, 6); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r6, rDef, "u3", - "dedicated", 10, 10 + f6.length, generateAllocation(10, f6), res, - minAlloc), false), plan.toString()); + assertTrue(plan.addReservation( + new InMemoryReservationAllocation(r6, rDef, "u3", + "dedicated", 10, 10 + f6.length, generateAllocation(10, f6), res, + minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(6L); ReservationId r7 = ReservationId.newInstance(ts, 7); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r7, rDef, "u4", - "dedicated", 10, 10 + f6.length, generateAllocation(10, f6), res, - minAlloc), false), plan.toString()); + assertTrue(plan.addReservation( + new InMemoryReservationAllocation(r7, rDef, "u4", + "dedicated", 10, 10 + f6.length, generateAllocation(10, f6), res, + minAlloc), false), plan.toString()); // remove some of the resources (requires replanning) plan.setTotalCapacity(Resource.newInstance(70 * 1024, 70)); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java index 1da0cbede925b..798b7f6701da6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java @@ -29,7 +29,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRMAppSubmitter; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -37,6 +36,10 @@ import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + /** * Common test class for resource profile related tests. */ @@ -52,16 +55,14 @@ public void testProfilesEnabled() throws Exception { manager.init(conf); try { manager.getResourceProfiles(); - Assertions - .fail("Exception should be thrown as resource profile is not enabled" - + " and getResourceProfiles is invoked."); + fail("Exception should be thrown as resource profile is not enabled" + + " and getResourceProfiles is invoked."); } catch (YarnException ie) { } conf.setBoolean(YarnConfiguration.RM_RESOURCE_PROFILES_ENABLED, true); try { manager.init(conf); - Assertions.fail( - "Exception should be thrown due to missing resource profiles file"); + fail("Exception should be thrown due to missing resource profiles file"); } catch (IOException ie) { } conf.set(YarnConfiguration.RM_RESOURCE_PROFILES_SOURCE_FILE, @@ -86,9 +87,9 @@ public void testLoadProfiles() throws Exception { for (Map.Entry entry : expected.entrySet()) { String profile = entry.getKey(); Resource res = entry.getValue(); - Assertions.assertTrue( + assertTrue( profiles.containsKey(profile), "Mandatory profile '" + profile + "' missing"); - Assertions.assertEquals(res + assertEquals(res , manager.getProfile(profile), "Profile " + profile + "' resources don't match"); } } @@ -106,7 +107,7 @@ public void testLoadIllegalProfiles() throws Exception { conf.set(YarnConfiguration.RM_RESOURCE_PROFILES_SOURCE_FILE, file); try { manager.init(conf); - Assertions.fail("Bad profile '" + file + "' is not valid"); + fail("Bad profile '" + file + "' is not valid"); } catch (IOException ie) { } } @@ -131,7 +132,7 @@ public void testGetProfile() throws Exception { for (Map.Entry entry : expected.entrySet()) { String profile = entry.getKey(); Resource res = entry.getValue(); - Assertions.assertEquals(res + assertEquals(res , manager.getProfile(profile), "Profile " + profile + "' resources don't match"); } } @@ -149,11 +150,11 @@ public void testGetMandatoryProfiles() throws Exception { expected.put("default", Resource.newInstance(2048, 2)); expected.put("maximum", Resource.newInstance(8192, 4)); - Assertions.assertEquals( + assertEquals( expected.get("minimum"), manager.getMinimumProfile(), "Profile 'minimum' resources don't match"); - Assertions.assertEquals( + assertEquals( expected.get("default"), manager.getDefaultProfile(), "Profile 'default' resources don't match"); - Assertions.assertEquals( + assertEquals( expected.get("maximum"), manager.getMaximumProfile(), "Profile 'maximum' resources don't match"); } @@ -170,7 +171,7 @@ public void testResourceProfilesInAMResponse() throws Exception { RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); RegisterApplicationMasterResponse resp = am1.registerAppAttempt(); - Assertions.assertEquals(0, resp.getResourceProfiles().size()); + assertEquals(0, resp.getResourceProfiles().size()); rm.stop(); conf.setBoolean(YarnConfiguration.RM_RESOURCE_PROFILES_ENABLED, true); conf.set(YarnConfiguration.RM_RESOURCE_PROFILES_SOURCE_FILE, @@ -183,12 +184,12 @@ public void testResourceProfilesInAMResponse() throws Exception { attempt1 = app1.getCurrentAppAttempt(); am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); resp = am1.registerAppAttempt(); - Assertions.assertEquals(3, resp.getResourceProfiles().size()); - Assertions.assertEquals(Resource.newInstance(1024, 1), + assertEquals(3, resp.getResourceProfiles().size()); + assertEquals(Resource.newInstance(1024, 1), resp.getResourceProfiles().get("minimum")); - Assertions.assertEquals(Resource.newInstance(2048, 2), + assertEquals(Resource.newInstance(2048, 2), resp.getResourceProfiles().get("default")); - Assertions.assertEquals(Resource.newInstance(8192, 4), + assertEquals(Resource.newInstance(8192, 4), resp.getResourceProfiles().get("maximum")); 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/resourcetracker/TestNMExpiry.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java index 796a5f520e465..41920a5d7451d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java @@ -19,9 +19,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.resourcetracker; import static org.apache.hadoop.yarn.server.resourcemanager.MockNM.createMockNodeStatus; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.hadoop.yarn.server.api.records.NodeStatus; -import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -164,7 +164,7 @@ public void testNMExpiry() throws Exception { wait(100); } } - Assertions.assertEquals(2, ClusterMetrics.getMetrics().getNumLostNMs()); + assertEquals(2, ClusterMetrics.getMetrics().getNumLostNMs()); request3 = recordFactory .newRecordInstance(RegisterNodeManagerRequest.class); @@ -178,7 +178,7 @@ public void testNMExpiry() throws Exception { /* test to see if hostanme 3 does not expire */ stopT = false; new ThirdNodeHeartBeatThread().start(); - Assertions.assertEquals(2,ClusterMetrics.getMetrics().getNumLostNMs()); + assertEquals(2,ClusterMetrics.getMetrics().getNumLostNMs()); stopT = true; } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java index 33c0a93a22ca1..72380c51369a6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java @@ -18,6 +18,9 @@ package org.apache.hadoop.yarn.server.resourcemanager.resourcetracker; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import org.apache.hadoop.conf.Configuration; @@ -47,7 +50,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM; 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; @@ -121,20 +123,20 @@ public void testRPCResponseId() throws IOException, YarnException { nodeStatus.setResponseId(0); NodeHeartbeatResponse response = resourceTrackerService.nodeHeartbeat( nodeHeartBeatRequest); - Assertions.assertTrue(response.getResponseId() == 1); + assertTrue(response.getResponseId() == 1); nodeStatus.setResponseId(response.getResponseId()); response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest); - Assertions.assertTrue(response.getResponseId() == 2); + assertTrue(response.getResponseId() == 2); /* try calling with less response id */ response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest); - Assertions.assertTrue(response.getResponseId() == 2); + assertTrue(response.getResponseId() == 2); nodeStatus.setResponseId(0); response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest); - Assertions.assertTrue(NodeAction.RESYNC.equals(response.getNodeAction())); - Assertions.assertEquals("Too far behind rm response id:2 nm response id:0", + assertTrue(NodeAction.RESYNC.equals(response.getNodeAction())); + assertEquals("Too far behind rm response id:2 nm response id:0", response.getDiagnosticsMessage()); } } \ 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/rmapp/TestApplicationLifetimeMonitor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java index b635fe94a4a6b..565b4fbc8d7d2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.resourcemanager.rmapp; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -63,18 +64,14 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.QueuePath; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; import org.apache.hadoop.yarn.util.Times; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.event.Level; -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; /** * Test class for application life time monitor feature test. */ -@RunWith(Parameterized.class) public class TestApplicationLifetimeMonitor { private final long maxLifetime = 30L; private static final QueuePath ROOT = new QueuePath(CapacitySchedulerConfiguration.ROOT); @@ -84,7 +81,6 @@ public class TestApplicationLifetimeMonitor { private YarnConfiguration conf; - @Parameterized.Parameters public static Collection data() { Collection params = new ArrayList(); params.add(new Object[]{CapacityScheduler.class}); @@ -94,11 +90,12 @@ public static Collection data() { private Class scheduler; - public TestApplicationLifetimeMonitor(Class schedulerParameter) { + private void initTestApplicationLifetimeMonitor(Class schedulerParameter) + throws IOException { scheduler = schedulerParameter; + setup(); } - @BeforeEach public void setup() throws IOException { if (scheduler.equals(CapacityScheduler.class)) { // Since there is limited lifetime monitoring support in fair scheduler @@ -119,10 +116,12 @@ public void setup() throws IOException { 3000L); } - @Test @Timeout(value = 60) - public void testApplicationLifetimeMonitor() + @ParameterizedTest + @MethodSource("data") + public void testApplicationLifetimeMonitor(Class schedulerParameter) throws Exception { + initTestApplicationLifetimeMonitor(schedulerParameter); MockRM rm = null; try { rm = new MockRM(conf); @@ -169,7 +168,7 @@ public void testApplicationLifetimeMonitor() rm.sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId()); am1.registerAppAttempt(); rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); - Assertions.assertTrue( + assertTrue( (System.currentTimeMillis() - app1.getSubmitTime()) > 10000, "Application killed before lifetime value"); Map updateTimeout = @@ -198,7 +197,7 @@ public void testApplicationLifetimeMonitor() long afterUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME); - Assertions.assertTrue( + assertTrue( afterUpdate > beforeUpdate, "Application lifetime value not updated"); // verify for application report. @@ -210,16 +209,16 @@ public void testApplicationLifetimeMonitor() Map appTimeouts = rm .getRMContext().getClientRMService().getApplicationReport(appRequest) .getApplicationReport().getApplicationTimeouts(); - Assertions.assertTrue( + assertTrue( !appTimeouts.isEmpty(), "Application Timeout are empty."); ApplicationTimeout timeout = appTimeouts.get(ApplicationTimeoutType.LIFETIME); - Assertions.assertTrue( + assertTrue( timeout.getRemainingTime() > 0, "Application remaining time is incorrect"); rm.waitForState(app2.getApplicationId(), RMAppState.KILLED); // verify for app killed with updated lifetime - Assertions.assertTrue( + assertTrue( app2.getFinishTime() > afterUpdate, "Application killed before lifetime value"); if (scheduler.equals(CapacityScheduler.class)) { @@ -230,9 +229,9 @@ public void testApplicationLifetimeMonitor() // so killed after queue max lifetime. rm.waitForState(app4.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app4.getFinishTime() - app4.getSubmitTime(); - Assertions.assertTrue( + assertTrue( totalTimeRun > (maxLifetime * 1000), "Application killed before lifetime value"); - Assertions.assertTrue( + assertTrue( totalTimeRun < ((maxLifetime + 10L) * 1000), "Application killed before lifetime value " + totalTimeRun); } @@ -241,9 +240,11 @@ public void testApplicationLifetimeMonitor() } } - @Test @Timeout(value = 180) - public void testApplicationLifetimeOnRMRestart() throws Exception { + @ParameterizedTest + @MethodSource("data") + public void testApplicationLifetimeOnRMRestart(Class schedulerParameter) throws Exception { + initTestApplicationLifetimeMonitor(schedulerParameter); conf.setBoolean(YarnConfiguration.RECOVERY_ENABLED, true); conf.setBoolean(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, true); @@ -313,15 +314,17 @@ public void testApplicationLifetimeOnRMRestart() throws Exception { // wait for app life time and application to be in killed state. rm2.waitForState(recoveredApp1.getApplicationId(), RMAppState.KILLED); - Assertions.assertTrue( + assertTrue( recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime() + appLifetime * 1000), "Application killed before lifetime value"); } - @Test @Timeout(value = 60) - public void testUpdateApplicationTimeoutForStateStoreUpdateFail() + @ParameterizedTest + @MethodSource("data") + public void testUpdateApplicationTimeoutForStateStoreUpdateFail(Class schedulerParameter) throws Exception { + initTestApplicationLifetimeMonitor(schedulerParameter); MockRM rm1 = null; try { MemoryRMStateStore memStore = new MemoryRMStateStore() { @@ -388,20 +391,22 @@ public synchronized void updateApplicationStateInternal( long afterUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME); - Assertions.assertEquals(beforeUpdate + assertEquals(beforeUpdate , afterUpdate, "Application timeout is updated"); rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED); // verify for app killed with updated lifetime - Assertions.assertTrue( + assertTrue( app1.getFinishTime() > afterUpdate, "Application killed before lifetime value"); } finally { stopRM(rm1); } } - @Test @Timeout(value = 120) - public void testInheritAppLifetimeFromParentQueue() throws Exception { + @ParameterizedTest + @MethodSource("data") + public void testInheritAppLifetimeFromParentQueue(Class schedulerParameter) throws Exception { + initTestApplicationLifetimeMonitor(schedulerParameter); YarnConfiguration yarnConf = conf; long maxRootLifetime = 20L; long defaultRootLifetime = 10L; @@ -441,19 +446,19 @@ public void testInheritAppLifetimeFromParentQueue() throws Exception { rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // Child queue should have inherited parent max and default lifetimes. - Assertions.assertEquals( + assertEquals( maxRootLifetime , csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden" + " parent value"); - Assertions.assertEquals( + assertEquals( defaultRootLifetime , csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have" + " overridden parent value"); // app1 (run in the 'child1' queue) should have run longer than the // default lifetime but less than the max lifetime. - Assertions.assertTrue( + assertTrue( totalTimeRun > (defaultRootLifetime * 1000), "Application killed before default lifetime value"); - Assertions.assertTrue( + assertTrue( totalTimeRun < (maxRootLifetime * 1000), "Application killed after max lifetime value " + totalTimeRun); } @@ -462,9 +467,11 @@ public void testInheritAppLifetimeFromParentQueue() throws Exception { } } - @Test @Timeout(value = 120) - public void testOverrideParentQueueMaxAppLifetime() throws Exception { + @ParameterizedTest + @MethodSource("data") + public void testOverrideParentQueueMaxAppLifetime(Class schedulerParameter) throws Exception { + initTestApplicationLifetimeMonitor(schedulerParameter); YarnConfiguration yarnConf = conf; long maxRootLifetime = 20L; long maxChildLifetime = 40L; @@ -507,13 +514,13 @@ public void testOverrideParentQueueMaxAppLifetime() throws Exception { rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // Child queue's max lifetime can override parent's and be larger. - Assertions.assertTrue( + assertTrue( (maxRootLifetime < maxChildLifetime) && (totalTimeRun > (maxChildLifetime * 1000)), "Application killed before default lifetime value"); - Assertions.assertEquals( + assertEquals( maxRootLifetime , csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly"); - Assertions.assertEquals(maxChildLifetime + assertEquals(maxChildLifetime , csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden" + " parent value"); } @@ -522,9 +529,12 @@ public void testOverrideParentQueueMaxAppLifetime() throws Exception { } } - @Test @Timeout(value = 120) - public void testOverrideParentQueueDefaultAppLifetime() throws Exception { + @ParameterizedTest + @MethodSource("data") + public void testOverrideParentQueueDefaultAppLifetime( + Class schedulerParameter) throws Exception { + initTestApplicationLifetimeMonitor(schedulerParameter); YarnConfiguration yarnConf = conf; long maxRootLifetime = -1L; long maxChildLifetime = -1L; @@ -567,17 +577,17 @@ public void testOverrideParentQueueDefaultAppLifetime() throws Exception { long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // app1 (run in 'child1' queue) should have overridden the parent's // default lifetime. - Assertions.assertTrue( + assertTrue( totalTimeRun > (defaultChildLifetime * 1000), "Application killed before default lifetime value"); // Root and child queue's max lifetime should be -1. - Assertions.assertEquals( + assertEquals( maxRootLifetime , csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly"); - Assertions.assertEquals( + assertEquals( maxChildLifetime , csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime property set incorrectly"); // 'child1' queue's default lifetime should have overridden parent's. - Assertions.assertEquals(defaultChildLifetime + assertEquals(defaultChildLifetime , csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have" + " overridden parent value"); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java index 8a89aade79465..565e00ccd73d1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -88,12 +88,9 @@ import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.Records; -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.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.ArgumentCaptor; import org.slf4j.Logger; @@ -111,9 +108,12 @@ import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.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.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; @@ -125,7 +125,6 @@ import static org.mockito.Mockito.verify; -@RunWith(value = Parameterized.class) public class TestRMAppTransitions { static final Logger LOG = LoggerFactory.getLogger(TestRMAppTransitions.class); @@ -216,7 +215,6 @@ public void handle(SchedulerEvent event) { } } - @Parameterized.Parameters public static Collection getTestParameters() { return Arrays.asList(new Object[][] { { Boolean.FALSE }, @@ -224,11 +222,12 @@ public static Collection getTestParameters() { }); } - public TestRMAppTransitions(boolean isSecurityEnabled) { - this.isSecurityEnabled = isSecurityEnabled; + private void initTestRMAppTransitions(boolean pIsSecurityEnabled) + throws Exception { + this.isSecurityEnabled = pIsSecurityEnabled; + setUp(); } - - @BeforeEach + public void setUp() throws Exception { conf = new YarnConfiguration(); AuthenticationMethod authMethod = AuthenticationMethod.SIMPLE; @@ -430,52 +429,49 @@ protected RMApp createNewTestApp(ApplicationSubmissionContext // Test expected newly created app state private static void testAppStartState(ApplicationId applicationId, String user, String name, String queue, RMApp application) { - Assertions.assertTrue( - application.getStartTime() > 0, "application start time is not greater than 0"); - Assertions.assertTrue( - application.getStartTime() <= System.currentTimeMillis(), "application start time is before currentTime"); - Assertions.assertEquals( - user, application.getUser(), "application user is not correct"); - Assertions.assertEquals( - applicationId, application.getApplicationId(), "application id is not correct"); - Assertions.assertEquals( - (float)0.0, application.getProgress(), (float)0.0, "application progress is not correct"); - Assertions.assertEquals( - queue, application.getQueue(), "application queue is not correct"); - Assertions.assertEquals( - name, application.getName(), "application name is not correct"); - Assertions.assertEquals( - 0, application.getFinishTime(), "application finish time is not 0 and should be"); - Assertions.assertNull( - application.getTrackingUrl(), "application tracking url is not correct"); + assertTrue(application.getStartTime() > 0, + "application start time is not greater than 0"); + assertTrue(application.getStartTime() <= System.currentTimeMillis(), + "application start time is before currentTime"); + assertEquals(user, application.getUser(), "application user is not correct"); + assertEquals(applicationId, application.getApplicationId(), + "application id is not correct"); + assertEquals((float) 0.0, application.getProgress(), + (float) 0.0, "application progress is not correct"); + assertEquals(queue, application.getQueue(), + "application queue is not correct"); + assertEquals(name, application.getName(), "application name is not correct"); + assertEquals(0, application.getFinishTime(), + "application finish time is not 0 and should be"); + assertNull(application.getTrackingUrl(), + "application tracking url is not correct"); StringBuilder diag = application.getDiagnostics(); - Assertions.assertEquals( - 0, diag.length(), "application diagnostics is not correct"); + assertEquals(0, diag.length(), "application diagnostics is not correct"); } // test to make sure times are set when app finishes private void assertStartTimeSet(RMApp application) { - Assertions.assertTrue( - application.getStartTime() >= testCaseStartTime, "application start time is before test case start time"); - Assertions.assertTrue( - application.getStartTime() <= System.currentTimeMillis(), "application start time is before currentTime"); + assertTrue(application.getStartTime() >= testCaseStartTime, + "application start time is before test case start time"); + assertTrue(application.getStartTime() <= System.currentTimeMillis(), + "application start time is before currentTime"); } private static void assertAppState(RMAppState state, RMApp application) { - Assertions.assertEquals( - state, application.getState(), "application state should have been " + state); + assertEquals(state, application.getState(), + "application state should have been " + state); } private static void assertFinalAppStatus(FinalApplicationStatus status, RMApp application) { - Assertions.assertEquals( - status, application.getFinalApplicationStatus(), "Final application status should have been " + status); + assertEquals(status, application.getFinalApplicationStatus(), + "Final application status should have been " + status); } // test to make sure times are set when app finishes private void assertTimesAtFinish(RMApp application) { assertStartTimeSet(application); - Assertions.assertTrue( - (application.getFinishTime() >= application.getStartTime()), "application finish time is not >= start time"); + assertTrue((application.getFinishTime() >= application.getStartTime()), + "application finish time is not >= start time"); } private void assertAppFinalStateSaved(RMApp application){ @@ -504,7 +500,7 @@ private void assertKilled(RMApp application) { assertAppState(RMAppState.KILLED, application); assertFinalAppStatus(FinalApplicationStatus.KILLED, application); StringBuilder diag = application.getDiagnostics(); - Assertions.assertEquals("application diagnostics is not correct", + assertEquals("application diagnostics is not correct", "Application killed by user.", diag.toString()); } @@ -513,8 +509,8 @@ private void assertFailed(RMApp application, String regex) { assertAppState(RMAppState.FAILED, application); assertFinalAppStatus(FinalApplicationStatus.FAILED, application); StringBuilder diag = application.getDiagnostics(); - Assertions.assertTrue( - diag.toString().matches(regex), "application diagnostics is not correct"); + assertTrue(diag.toString().matches(regex), + "application diagnostics is not correct"); } private void sendAppUpdateSavedEvent(RMApp application) { @@ -630,7 +626,7 @@ protected RMApp testCreateAppFinishing( // unmanaged AMs don't use the FINISHING state assert submissionContext == null || !submissionContext.getUnmanagedAM(); RMApp application = testCreateAppFinalSaving(submissionContext); - Assertions.assertNotNull(application, "app shouldn't be null"); + assertNotNull(application, "app shouldn't be null"); // FINAL_SAVING => FINISHING event RMAppEventType.APP_UPDATED RMAppEvent appUpdated = new RMAppEvent(application.getApplicationId(), RMAppEventType.APP_UPDATE_SAVED); @@ -672,13 +668,15 @@ protected RMApp testCreateAppFinished( assertTimesAtFinish(application); // finished without a proper unregister implies failed assertFinalAppStatus(FinalApplicationStatus.FAILED, application); - Assertions.assertTrue( - application.getDiagnostics().indexOf(diagnostics) != -1, "Finished app missing diagnostics"); + assertTrue(application.getDiagnostics().indexOf(diagnostics) != -1, + "Finished app missing diagnostics"); return application; } - @Test - public void testUnmanagedApp() throws Exception { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testUnmanagedApp(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); ApplicationSubmissionContext subContext = new ApplicationSubmissionContextPBImpl(); subContext.setUnmanagedAM(true); @@ -686,8 +684,8 @@ public void testUnmanagedApp() throws Exception { LOG.info("--- START: testUnmanagedAppSuccessPath ---"); final String diagMsg = "some diagnostics"; RMApp application = testCreateAppFinished(subContext, diagMsg); - Assertions.assertTrue( - application.getDiagnostics().indexOf(diagMsg) != -1, "Finished app missing diagnostics"); + assertTrue(application.getDiagnostics().indexOf(diagMsg) != -1, + "Finished app missing diagnostics"); // reset the counter of Mockito.verify reset(writer); @@ -701,27 +699,31 @@ public void testUnmanagedApp() throws Exception { application.handle(event); rmDispatcher.await(); RMAppAttempt appAttempt = application.getCurrentAppAttempt(); - Assertions.assertEquals(1, appAttempt.getAppAttemptId().getAttemptId()); + assertEquals(1, appAttempt.getAppAttemptId().getAttemptId()); sendAppUpdateSavedEvent(application); assertFailed(application, ".*Unmanaged application.*Failing the application.*"); assertAppFinalStateSaved(application); verifyRMAppFieldsForFinalTransitions(application); } - - @Test - public void testAppSuccessPath() throws Exception { + + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppSuccessPath(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppSuccessPath ---"); final String diagMsg = "some diagnostics"; RMApp application = testCreateAppFinished(null, diagMsg); - Assertions.assertTrue( - application.getDiagnostics().indexOf(diagMsg) != -1, "Finished application missing diagnostics"); + assertTrue(application.getDiagnostics().indexOf(diagMsg) != -1, + "Finished application missing diagnostics"); verifyRMAppFieldsForFinalTransitions(application); } - @Test @Timeout(value = 30) - public void testAppRecoverPath() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppRecoverPath(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppRecoverPath ---"); ApplicationSubmissionContext sub = Records.newRecord(ApplicationSubmissionContext.class); @@ -729,9 +731,11 @@ public void testAppRecoverPath() throws IOException { testCreateAppSubmittedRecovery(sub); } - @Test @Timeout(value = 30) - public void testAppNewKill() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppNewKill(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppNewKill ---"); UserGroupInformation fooUser = UserGroupInformation.createUserForTesting( @@ -752,8 +756,10 @@ public void testAppNewKill() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test - public void testAppNewReject() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppNewReject(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppNewReject ---"); RMApp application = createNewTestApp(null); @@ -770,9 +776,11 @@ public void testAppNewReject() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test @Timeout(value = 30) - public void testAppNewRejectAddToStore() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppNewRejectAddToStore(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppNewRejectAddToStore ---"); RMApp application = createNewTestApp(null); @@ -790,9 +798,11 @@ public void testAppNewRejectAddToStore() throws IOException { rmContext.getStateStore().removeApplication(application); } - @Test @Timeout(value = 30) - public void testAppNewSavingKill() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppNewSavingKill(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppNewSavingKill ---"); RMApp application = testCreateAppNewSaving(null); @@ -813,9 +823,11 @@ public void testAppNewSavingKill() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test @Timeout(value = 30) - public void testAppNewSavingReject() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppNewSavingReject(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppNewSavingReject ---"); RMApp application = testCreateAppNewSaving(null); @@ -832,9 +844,11 @@ public void testAppNewSavingReject() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test @Timeout(value = 30) - public void testAppNewSavingSaveReject() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppNewSavingSaveReject(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppNewSavingSaveReject ---"); RMApp application = testCreateAppNewSaving(null); // NEW_SAVING => FAILED event RMAppEventType.APP_SAVE_FAILED @@ -850,9 +864,11 @@ public void testAppNewSavingSaveReject() throws IOException { assertTimesAtFinish(application); } - @Test @Timeout(value = 30) - public void testAppSubmittedRejected() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppSubmittedRejected(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppSubmittedRejected ---"); RMApp application = testCreateAppSubmittedNoRecovery(null); @@ -869,8 +885,11 @@ public void testAppSubmittedRejected() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test - public void testAppSubmittedKill() throws IOException, InterruptedException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppSubmittedKill(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppSubmittedKill---"); RMApp application = testCreateAppSubmittedNoRecovery(null); @@ -892,13 +911,15 @@ public void testAppSubmittedKill() throws IOException, InterruptedException { verifyRMAppFieldsForFinalTransitions(application); } - @Test - public void testAppAcceptedFailed() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppAcceptedFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppAcceptedFailed ---"); RMApp application = testCreateAppAccepted(null); // ACCEPTED => ACCEPTED event RMAppEventType.RMAppEventType.ATTEMPT_FAILED - Assertions.assertTrue(maxAppAttempts > 1); + assertTrue(maxAppAttempts > 1); for (int i=1; i < maxAppAttempts; i++) { RMAppEvent event = new RMAppFailedAttemptEvent(application.getApplicationId(), @@ -927,8 +948,11 @@ public void testAppAcceptedFailed() throws IOException { verifyApplicationFinished(RMAppState.FAILED); } - @Test - public void testAppAcceptedKill() throws IOException, InterruptedException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppAcceptedKill(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppAcceptedKill ---"); RMApp application = testCreateAppAccepted(null); // ACCEPTED => KILLED event RMAppEventType.KILL @@ -956,8 +980,10 @@ public void testAppAcceptedKill() throws IOException, InterruptedException { verifyRMAppFieldsForFinalTransitions(application); } - @Test - public void testAppAcceptedAccepted() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppAcceptedAccepted(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppAcceptedAccepted ---"); RMApp application = testCreateAppAccepted(null); @@ -971,8 +997,10 @@ public void testAppAcceptedAccepted() throws IOException { assertAppStateLaunchTimeSaved(1234L); } - @Test - public void testAcquiredReleased() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAcquiredReleased(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); RMApp application = testCreateAppSubmittedNoRecovery(null); NodeId nodeId = NodeId.newInstance("host", 1234); application.handle( @@ -982,9 +1010,11 @@ public void testAcquiredReleased() throws IOException { assertEquals(0, logAggregationReportsForApp.size()); } - @Test - public void testAppAcceptedAttemptKilled() throws IOException, - InterruptedException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppAcceptedAttemptKilled(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppAcceptedAttemptKilled ---"); RMApp application = testCreateAppAccepted(null); @@ -1005,8 +1035,10 @@ public void testAppAcceptedAttemptKilled() throws IOException, verifyAppRemovedSchedulerEvent(application, RMAppState.KILLED); } - @Test - public void testAppRunningKill() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppRunningKill(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppRunningKill ---"); RMApp application = testCreateAppRunning(null); @@ -1030,17 +1062,19 @@ public void testAppRunningKill() throws IOException { verifyRMAppFieldsForFinalTransitions(application); } - @Test - public void testAppRunningFailed() throws IOException { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAppRunningFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); LOG.info("--- START: testAppRunningFailed ---"); RMApp application = testCreateAppRunning(null); RMAppAttempt appAttempt = application.getCurrentAppAttempt(); int expectedAttemptId = 1; - Assertions.assertEquals(expectedAttemptId, + assertEquals(expectedAttemptId, appAttempt.getAppAttemptId().getAttemptId()); // RUNNING => FAILED/RESTARTING event RMAppEventType.ATTEMPT_FAILED - Assertions.assertTrue(maxAppAttempts > 1); + assertTrue(maxAppAttempts > 1); for (int i=1; i applicationState = state.getApplicationState(); @@ -1304,19 +1352,19 @@ public void testRecoverApplication(ApplicationStateData appState, Collections.singletonList(BuilderUtils.newResourceRequest( RMAppAttemptImpl.AM_CONTAINER_PRIORITY, ResourceRequest.ANY, submissionContext.getResource(), 1))); - Assertions.assertEquals(RMAppState.NEW, application.getState()); + assertEquals(RMAppState.NEW, application.getState()); RMAppEvent recoverEvent = new RMAppRecoverEvent(application.getApplicationId(), rmState); // Trigger RECOVER event. application.handle(recoverEvent); // Application final status looked from recoveredFinalStatus - Assertions.assertTrue( + assertTrue( RMAppImpl.isAppInFinalState(application), "Application is not in recoveredFinalStatus."); rmDispatcher.await(); RMAppState finalState = appState.getState(); - Assertions.assertEquals(finalState + assertEquals(finalState , application.getState(), "Application is not in finalState."); verifyRMAppFieldsForFinalTransitions(application); } @@ -1331,18 +1379,20 @@ public void createRMStateForApplications( null, app.getLaunchTime(), app.getFinishTime(), null); applicationState.put(app.getApplicationId(), appState); } - - @Test - public void testGetAppReport() throws IOException { + + @ParameterizedTest + @MethodSource("getTestParameters") + public void testGetAppReport(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppTransitions(pIsSecurityEnabled); RMApp app = createNewTestApp(null); assertAppState(RMAppState.NEW, app); ApplicationReport report = app.createAndGetApplicationReport(null, true); - Assertions.assertNotNull(report.getApplicationResourceUsageReport()); + assertNotNull(report.getApplicationResourceUsageReport()); assertThat(report.getApplicationResourceUsageReport()). isEqualTo(RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT); report = app.createAndGetApplicationReport("clientuser", true); - Assertions.assertNotNull(report.getApplicationResourceUsageReport()); - Assertions.assertTrue( + assertNotNull(report.getApplicationResourceUsageReport()); + assertTrue( report.getTrackingUrl().endsWith("/proxy/" + app.getApplicationId() + "/"), "bad proxy url for app"); } @@ -1350,8 +1400,8 @@ public void testGetAppReport() throws IOException { private void verifyAppBeforeFinishEvent(RMApp app) { assertEquals(0L, ((RMAppImpl) app).getLogAggregationStartTime()); //RMAppEventType.APP_UPDATE_SAVED sets the finish time - assertTrue( - appManagerDispatcher.events.isEmpty(), "App manager events should not be received!"); + assertTrue(appManagerDispatcher.events.isEmpty(), + "App manager events should not be received!"); } private void verifyAppAfterFinishEvent(RMApp app) { @@ -1375,22 +1425,22 @@ private void verifyApplicationFinished(RMAppState state) { ArgumentCaptor finalState = ArgumentCaptor.forClass(RMAppState.class); verify(writer).applicationFinished(any(RMApp.class), finalState.capture()); - Assertions.assertEquals(state, finalState.getValue()); + assertEquals(state, finalState.getValue()); finalState = ArgumentCaptor.forClass(RMAppState.class); verify(publisher).appFinished(any(RMApp.class), finalState.capture(), anyLong()); - Assertions.assertEquals(state, finalState.getValue()); + assertEquals(state, finalState.getValue()); } private void verifyAppRemovedSchedulerEvent(RMApp app, RMAppState finalState) { SchedulerEvent lastEvent = schedulerDispatcher.lastSchedulerEvent; - Assertions.assertEquals(SchedulerEventType.APP_REMOVED, lastEvent.getType()); + assertEquals(SchedulerEventType.APP_REMOVED, lastEvent.getType()); if (lastEvent instanceof AppRemovedSchedulerEvent) { AppRemovedSchedulerEvent appRemovedEvent = (AppRemovedSchedulerEvent) lastEvent; - Assertions.assertEquals(finalState, appRemovedEvent.getFinalState()); - Assertions.assertEquals(app.getApplicationId().getId(), + assertEquals(finalState, appRemovedEvent.getFinalState()); + assertEquals(app.getApplicationId().getId(), appRemovedEvent.getApplicationID().getId()); } } From b3aaa47a39bb88ea7464104077cdde06ae34653f Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sun, 9 Mar 2025 08:40:27 +0800 Subject: [PATCH 3/5] YARN-11262. Fix CheckStyle & Junit Test. --- .../planning/TestGreedyReservationAgent.java | 76 ++-- .../resource/TestResourceProfiles.java | 32 +- .../TestRMNMRPCResponseId.java | 2 +- .../rmapp/TestApplicationLifetimeMonitor.java | 98 ++--- .../rmapp/TestNodesListManager.java | 41 +- .../rmapp/TestRMAppTransitions.java | 8 +- .../attempt/TestAMLivelinessMonitor.java | 7 +- .../TestRMAppAttemptImplDiagnostics.java | 27 +- .../attempt/TestRMAppAttemptTransitions.java | 414 +++++++++++------- .../rmcontainer/TestRMContainerImpl.java | 42 +- 10 files changed, 413 insertions(+), 334 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/reservation/planning/TestGreedyReservationAgent.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java index 07f5af82cccb6..fc3e17fe70f25 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java @@ -170,17 +170,13 @@ public void testSimple(boolean pAllocateLeft, if(allocateLeft){ for (long i = 5 * step; i < 15 * step; i++) { - assertTrue( - - Resources.equals(cs.getResourcesAtTime(i), - Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected"); + assertTrue(Resources.equals(cs.getResourcesAtTime(i), + Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected"); } } else { for (long i = 10 * step; i < 20 * step; i++) { - assertTrue( - - Resources.equals(cs.getResourcesAtTime(i), - Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected"); + assertTrue(Resources.equals(cs.getResourcesAtTime(i), + Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected"); } } } @@ -264,30 +260,22 @@ public void testSharingPolicyFeedback(boolean pAllocateLeft, if (allocateLeft) { for (long i = 5 * step; i < 15 * step; i++) { - assertTrue( - - Resources.equals(cs.getResourcesAtTime(i), - Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); + assertTrue(Resources.equals(cs.getResourcesAtTime(i), + Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); } for (long i = 15 * step; i < 25 * step; i++) { // RR2 is pushed out by the presence of RR - assertTrue( - - Resources.equals(cs2.getResourcesAtTime(i), - Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); + assertTrue(Resources.equals(cs2.getResourcesAtTime(i), + Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); } } else { for (long i = 90 * step; i < 100 * step; i++) { - assertTrue( - - Resources.equals(cs.getResourcesAtTime(i), - Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); + assertTrue(Resources.equals(cs.getResourcesAtTime(i), + Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); } for (long i = 80 * step; i < 90 * step; i++) { - assertTrue( - - Resources.equals(cs2.getResourcesAtTime(i), - Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); + assertTrue(Resources.equals(cs2.getResourcesAtTime(i), + Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected"); } } } @@ -376,13 +364,11 @@ public void testOrderNoGapImpossible(boolean pAllocateLeft, ReservationDefinition rDef = ReservationSystemTestUtil .createSimpleReservationDefinition(30, 30 * step + f.length * step, f.length * step, 1, recurrenceExpression); - assertTrue( - - plan.addReservation(new InMemoryReservationAllocation( - ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", - "dedicated", 30 * step, 30 * step + f.length * step, - ReservationSystemTestUtil.generateAllocation(30 * step, step, f), - res, minAlloc), false), plan.toString()); + assertTrue(plan.addReservation(new InMemoryReservationAllocation( + ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", + "dedicated", 30 * step, 30 * step + f.length * step, + ReservationSystemTestUtil.generateAllocation(30 * step, step, f), + res, minAlloc), false), plan.toString()); // create a chain of 4 RR, mixing gang and non-gang ReservationDefinition rr = new ReservationDefinitionPBImpl(); @@ -416,8 +402,8 @@ public void testOrderNoGapImpossible(boolean pAllocateLeft, // validate assertFalse(result, "Agent-based allocation should have failed"); - assertTrue(plan - .getAllReservations().size() == 3, "Agent-based allocation should have failed"); + assertTrue(plan.getAllReservations().size() == 3, + "Agent-based allocation should have failed"); System.out .println("--------AFTER ORDER_NO_GAP IMPOSSIBLE ALLOCATION (queue: " @@ -618,8 +604,8 @@ public void testAnyImpossible(boolean pAllocateLeft, } // validate results, we expect the second one to be accepted assertFalse(result, "Agent-based allocation should have failed"); - assertTrue(plan - .getAllReservations().size() == 2, "Agent-based allocation should have failed"); + assertTrue(plan.getAllReservations().size() == 2, + "Agent-based allocation should have failed"); System.out.println("--------AFTER ANY IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------"); @@ -719,8 +705,8 @@ public void testAllImpossible(boolean pAllocateLeft, // validate results, we expect the second one to be accepted assertFalse(result, "Agent-based allocation failed"); - assertTrue(plan.getAllReservations() - .size() == 2, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations().size() == 2, + "Agent-based allocation failed"); System.out.println("--------AFTER ALL IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------"); @@ -738,19 +724,17 @@ private void prepareBasicPlan() throws PlanningException { ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( 0, 0 + f.length * step, f.length * step); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation( - ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", - "dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil - .generateAllocation(0, step, f), res, minAlloc), false), plan.toString()); + assertTrue(plan.addReservation(new InMemoryReservationAllocation( + ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", + "dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil + .generateAllocation(0, step, f), res, minAlloc), false), plan.toString()); int[] f2 = { 5, 5, 5, 5, 5, 5, 5 }; Map alloc = ReservationSystemTestUtil.generateAllocation(5000, step, f2); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation( - ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", - "dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc), + assertTrue(plan.addReservation(new InMemoryReservationAllocation( + ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", + "dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc), false), plan.toString()); System.out.println("--------BEFORE AGENT----------"); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java index 798b7f6701da6..a459a595acf94 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java @@ -18,6 +18,10 @@ package org.apache.hadoop.yarn.server.resourcemanager.resource; +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 org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse; import org.apache.hadoop.yarn.api.records.Resource; @@ -36,10 +40,6 @@ import java.util.HashMap; import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - /** * Common test class for resource profile related tests. */ @@ -87,10 +87,10 @@ public void testLoadProfiles() throws Exception { for (Map.Entry entry : expected.entrySet()) { String profile = entry.getKey(); Resource res = entry.getValue(); - assertTrue( - profiles.containsKey(profile), "Mandatory profile '" + profile + "' missing"); - assertEquals(res -, manager.getProfile(profile), "Profile " + profile + "' resources don't match"); + assertTrue(profiles.containsKey(profile), + "Mandatory profile '" + profile + "' missing"); + assertEquals(res, manager.getProfile(profile), + "Profile " + profile + "' resources don't match"); } } @@ -132,8 +132,8 @@ public void testGetProfile() throws Exception { for (Map.Entry entry : expected.entrySet()) { String profile = entry.getKey(); Resource res = entry.getValue(); - assertEquals(res -, manager.getProfile(profile), "Profile " + profile + "' resources don't match"); + assertEquals(res, manager.getProfile(profile), + "Profile " + profile + "' resources don't match"); } } @@ -150,12 +150,12 @@ public void testGetMandatoryProfiles() throws Exception { expected.put("default", Resource.newInstance(2048, 2)); expected.put("maximum", Resource.newInstance(8192, 4)); - assertEquals( - expected.get("minimum"), manager.getMinimumProfile(), "Profile 'minimum' resources don't match"); - assertEquals( - expected.get("default"), manager.getDefaultProfile(), "Profile 'default' resources don't match"); - assertEquals( - expected.get("maximum"), manager.getMaximumProfile(), "Profile 'maximum' resources don't match"); + assertEquals(expected.get("minimum"), manager.getMinimumProfile(), + "Profile 'minimum' resources don't match"); + assertEquals(expected.get("default"), manager.getDefaultProfile(), + "Profile 'default' resources don't match"); + assertEquals(expected.get("maximum"), manager.getMaximumProfile(), + "Profile 'maximum' resources don't match"); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java index 72380c51369a6..3466f59dcadb6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java @@ -127,7 +127,7 @@ public void testRPCResponseId() throws IOException, YarnException { nodeStatus.setResponseId(response.getResponseId()); response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest); - assertTrue(response.getResponseId() == 2); + assertTrue(response.getResponseId() == 2); /* try calling with less response id */ response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java index 565b4fbc8d7d2..0f6e2c79d2520 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java @@ -168,8 +168,8 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter) rm.sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId()); am1.registerAppAttempt(); rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); - assertTrue( - (System.currentTimeMillis() - app1.getSubmitTime()) > 10000, "Application killed before lifetime value"); + assertTrue((System.currentTimeMillis() - app1.getSubmitTime()) > 10000, + "Application killed before lifetime value"); Map updateTimeout = new HashMap(); @@ -197,8 +197,8 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter) long afterUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME); - assertTrue( - afterUpdate > beforeUpdate, "Application lifetime value not updated"); + assertTrue(afterUpdate > beforeUpdate, + "Application lifetime value not updated"); // verify for application report. RecordFactory recordFactory = @@ -209,17 +209,16 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter) Map appTimeouts = rm .getRMContext().getClientRMService().getApplicationReport(appRequest) .getApplicationReport().getApplicationTimeouts(); - assertTrue( - !appTimeouts.isEmpty(), "Application Timeout are empty."); + assertTrue(!appTimeouts.isEmpty(), "Application Timeout are empty."); ApplicationTimeout timeout = appTimeouts.get(ApplicationTimeoutType.LIFETIME); - assertTrue( - timeout.getRemainingTime() > 0, "Application remaining time is incorrect"); + assertTrue(timeout.getRemainingTime() > 0, + "Application remaining time is incorrect"); rm.waitForState(app2.getApplicationId(), RMAppState.KILLED); // verify for app killed with updated lifetime - assertTrue( - app2.getFinishTime() > afterUpdate, "Application killed before lifetime value"); + assertTrue(app2.getFinishTime() > afterUpdate, + "Application killed before lifetime value"); if (scheduler.equals(CapacityScheduler.class)) { // Supported only on capacity scheduler @@ -229,11 +228,10 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter) // so killed after queue max lifetime. rm.waitForState(app4.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app4.getFinishTime() - app4.getSubmitTime(); - assertTrue( - totalTimeRun > (maxLifetime * 1000), "Application killed before lifetime value"); - assertTrue( - - totalTimeRun < ((maxLifetime + 10L) * 1000), "Application killed before lifetime value " + totalTimeRun); + assertTrue(totalTimeRun > (maxLifetime * 1000), + "Application killed before lifetime value"); + assertTrue(totalTimeRun < ((maxLifetime + 10L) * 1000), + "Application killed before lifetime value " + totalTimeRun); } } finally { stopRM(rm); @@ -314,9 +312,8 @@ public void testApplicationLifetimeOnRMRestart(Class schedulerParameter) throws // wait for app life time and application to be in killed state. rm2.waitForState(recoveredApp1.getApplicationId(), RMAppState.KILLED); - assertTrue( - recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime() - + appLifetime * 1000), "Application killed before lifetime value"); + assertTrue(recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime() + + appLifetime * 1000), "Application killed before lifetime value"); } @Timeout(value = 60) @@ -382,8 +379,8 @@ public synchronized void updateApplicationStateInternal( fail("Update application should fail."); } catch (YarnException e) { // expected - assertTrue( - e.getMessage().contains(app1.getApplicationId().toString()), "State-store exception does not containe appId"); + assertTrue(e.getMessage().contains(app1.getApplicationId().toString()), + "State-store exception does not containe appId"); } applicationTimeouts = app1.getApplicationTimeouts(); @@ -391,12 +388,12 @@ public synchronized void updateApplicationStateInternal( long afterUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME); - assertEquals(beforeUpdate -, afterUpdate, "Application timeout is updated"); + assertEquals(beforeUpdate, afterUpdate, + "Application timeout is updated"); rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED); // verify for app killed with updated lifetime - assertTrue( - app1.getFinishTime() > afterUpdate, "Application killed before lifetime value"); + assertTrue(app1.getFinishTime() > afterUpdate, + "Application killed before lifetime value"); } finally { stopRM(rm1); } @@ -446,21 +443,20 @@ public void testInheritAppLifetimeFromParentQueue(Class schedulerParameter) thro rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // Child queue should have inherited parent max and default lifetimes. - assertEquals( - maxRootLifetime -, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden" + assertEquals(maxRootLifetime, + csched.getQueue(CQ1).getMaximumApplicationLifetime(), + "Child queue max lifetime should have overridden" + " parent value"); - assertEquals( - defaultRootLifetime -, csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have" + assertEquals(defaultRootLifetime, + csched.getQueue(CQ1).getDefaultApplicationLifetime(), + "Child queue default lifetime should have" + " overridden parent value"); // app1 (run in the 'child1' queue) should have run longer than the // default lifetime but less than the max lifetime. - assertTrue( - totalTimeRun > (defaultRootLifetime * 1000), "Application killed before default lifetime value"); - assertTrue( - - totalTimeRun < (maxRootLifetime * 1000), "Application killed after max lifetime value " + totalTimeRun); + assertTrue(totalTimeRun > (defaultRootLifetime * 1000), + "Application killed before default lifetime value"); + assertTrue(totalTimeRun < (maxRootLifetime * 1000), + "Application killed after max lifetime value " + totalTimeRun); } } finally { stopRM(rm); @@ -514,14 +510,12 @@ public void testOverrideParentQueueMaxAppLifetime(Class schedulerParameter) thro rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // Child queue's max lifetime can override parent's and be larger. - assertTrue( - (maxRootLifetime < maxChildLifetime) - && (totalTimeRun > (maxChildLifetime * 1000)), "Application killed before default lifetime value"); - assertEquals( - maxRootLifetime -, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly"); - assertEquals(maxChildLifetime -, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden" + assertTrue((maxRootLifetime < maxChildLifetime) && (totalTimeRun > (maxChildLifetime * 1000)), + "Application killed before default lifetime value"); + assertEquals(maxRootLifetime, csched.getRootQueue().getMaximumApplicationLifetime(), + "Root queue max lifetime property set incorrectly"); + assertEquals(maxChildLifetime, csched.getQueue(CQ1).getMaximumApplicationLifetime(), + "Child queue max lifetime should have overridden" + " parent value"); } } finally { @@ -577,18 +571,16 @@ public void testOverrideParentQueueDefaultAppLifetime( long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // app1 (run in 'child1' queue) should have overridden the parent's // default lifetime. - assertTrue( - totalTimeRun > (defaultChildLifetime * 1000), "Application killed before default lifetime value"); + assertTrue(totalTimeRun > (defaultChildLifetime * 1000), + "Application killed before default lifetime value"); // Root and child queue's max lifetime should be -1. - assertEquals( - maxRootLifetime -, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly"); - assertEquals( - maxChildLifetime -, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime property set incorrectly"); + assertEquals(maxRootLifetime, csched.getRootQueue().getMaximumApplicationLifetime(), + "Root queue max lifetime property set incorrectly"); + assertEquals(maxChildLifetime, csched.getQueue(CQ1).getMaximumApplicationLifetime(), + "Child queue max lifetime property set incorrectly"); // 'child1' queue's default lifetime should have overridden parent's. - assertEquals(defaultChildLifetime -, csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have" + assertEquals(defaultChildLifetime, csched.getQueue(CQ1).getDefaultApplicationLifetime(), + "Child queue default lifetime should have" + " overridden parent value"); } } finally { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java index 35f0145dcaf5f..3779c90b932dd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestNodesListManager.java @@ -18,6 +18,10 @@ package org.apache.hadoop.yarn.server.resourcemanager.rmapp; +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.argThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.spy; @@ -44,7 +48,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; import org.apache.hadoop.yarn.util.ControlledClock; import org.slf4j.event.Level; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentMatcher; @@ -89,10 +92,8 @@ protected Dispatcher createDispatcher() { // Should not have RMAppNodeUpdateEvent to AsyncDispatcher. dispatcher.getEventHandler().handle(new NodesListManagerEvent( NodesListManagerEventType.NODE_USABLE, rmnode)); - Assertions.assertFalse( - getIsRMAppEvent(), "Got unexpected RM app event"); - Assertions.assertTrue( - getIsNodesListEvent(), "Received no NodesListManagerEvent"); + assertFalse(getIsRMAppEvent(), "Got unexpected RM app event"); + assertTrue(getIsNodesListEvent(), "Received no NodesListManagerEvent"); } @Test @@ -106,28 +107,28 @@ public void testCachedResolver() throws Exception { resolver.init(new YarnConfiguration()); resolver.start(); resolver.addToCache("testCachedResolverHost1", "1.1.1.1"); - Assertions.assertEquals("1.1.1.1", + assertEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); resolver.addToCache("testCachedResolverHost2", "1.1.1.2"); - Assertions.assertEquals("1.1.1.1", + assertEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assertions.assertEquals("1.1.1.2", + assertEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); // test removeFromCache resolver.removeFromCache("testCachedResolverHost1"); - Assertions.assertNotEquals("1.1.1.1", + assertNotEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assertions.assertEquals("1.1.1.2", + assertEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); // test expiry clock.tickMsec(CACHE_EXPIRY_INTERVAL_SECS * 1000 + 1); resolver.getExpireChecker().run(); - Assertions.assertNotEquals("1.1.1.1", + assertNotEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assertions.assertNotEquals("1.1.1.2", + assertNotEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); } @@ -142,8 +143,8 @@ public void testDefaultResolver() throws Exception { NodesListManager nodesListManager = rm.getNodesListManager(); NodesListManager.Resolver resolver = nodesListManager.getResolver(); - Assertions.assertTrue( - resolver instanceof NodesListManager.DirectResolver, "default resolver should be DirectResolver"); + assertTrue(resolver instanceof NodesListManager.DirectResolver, + "default resolver should be DirectResolver"); } @Test @@ -164,9 +165,9 @@ public void testCachedResolverWithEvent() throws Exception { resolver.addToCache("testCachedResolverHost1", "1.1.1.1"); resolver.addToCache("testCachedResolverHost2", "1.1.1.2"); - Assertions.assertEquals("1.1.1.1", + assertEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assertions.assertEquals("1.1.1.2", + assertEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); RMNode rmnode1 = MockNodes.newNodeInfo(1, Resource.newInstance(28000, 8), @@ -177,17 +178,17 @@ public void testCachedResolverWithEvent() throws Exception { nodesListManager.handle( new NodesListManagerEvent(NodesListManagerEventType.NODE_USABLE, rmnode1)); - Assertions.assertNotEquals("1.1.1.1", + assertNotEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assertions.assertEquals("1.1.1.2", + assertEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); nodesListManager.handle( new NodesListManagerEvent(NodesListManagerEventType.NODE_USABLE, rmnode2)); - Assertions.assertNotEquals("1.1.1.1", + assertNotEquals("1.1.1.1", resolver.resolve("testCachedResolverHost1")); - Assertions.assertNotEquals("1.1.1.2", + assertNotEquals("1.1.1.2", resolver.resolve("testCachedResolverHost2")); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java index 565e00ccd73d1..4b00b60384655 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -500,8 +500,8 @@ private void assertKilled(RMApp application) { assertAppState(RMAppState.KILLED, application); assertFinalAppStatus(FinalApplicationStatus.KILLED, application); StringBuilder diag = application.getDiagnostics(); - assertEquals("application diagnostics is not correct", - "Application killed by user.", diag.toString()); + assertEquals("Application killed by user.", diag.toString(), + "application diagnostics is not correct"); } private void assertFailed(RMApp application, String regex) { @@ -1185,8 +1185,8 @@ public void testAppFinishedFinished(boolean pIsSecurityEnabled) throws Exception assertAppState(RMAppState.FINISHED, application); assertEquals(0, application.getRanNodes().size()); StringBuilder diag = application.getDiagnostics(); - assertEquals("application diagnostics is not correct", - "", diag.toString()); + assertEquals("", diag.toString(), + "application diagnostics is not correct"); verifyApplicationFinished(RMAppState.FINISHED); verifyAppRemovedSchedulerEvent(application, RMAppState.FINISHED); verifyRMAppFieldsForFinalTransitions(application); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestAMLivelinessMonitor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestAMLivelinessMonitor.java index f23ae4a51bdee..a47271e529406 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestAMLivelinessMonitor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestAMLivelinessMonitor.java @@ -26,10 +26,11 @@ import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore; import org.apache.hadoop.yarn.util.ControlledClock; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.mock; public class TestAMLivelinessMonitor { @@ -60,7 +61,7 @@ public synchronized RMState loadState() throws Exception { dispatcher, clock) { @Override protected void expire(ApplicationAttemptId id) { - Assertions.assertEquals(id, attemptId); + assertEquals(id, attemptId); expired[0] = true; } }; @@ -77,7 +78,7 @@ protected AMLivelinessMonitor createAMLivelinessMonitor() { Thread.sleep(100); } // expired[0] would be set to true without resetTimer - Assertions.assertFalse(expired[0]); + assertFalse(expired[0]); 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/rmapp/attempt/TestRMAppAttemptImplDiagnostics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptImplDiagnostics.java index 852375722e51b..f6089a1aa0d30 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptImplDiagnostics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptImplDiagnostics.java @@ -27,22 +27,18 @@ import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.server.resourcemanager.RMContext; import org.apache.hadoop.yarn.util.BoundedAppender; -import org.junit.Rule; import org.junit.jupiter.api.Test; -import org.junit.rules.ExpectedException; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** - * Testing {@link RMAppAttemptImpl#diagnostics} scenarios. + * Testing {@link RMAppAttemptImpl#getDiagnostics} scenarios. */ public class TestRMAppAttemptImplDiagnostics { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Test public void whenCreatedWithDefaultConfigurationSuccess() { final Configuration configuration = new Configuration(); @@ -54,12 +50,11 @@ public void whenCreatedWithDefaultConfigurationSuccess() { @Test public void whenCreatedWithWrongConfigurationError() { - final Configuration configuration = new Configuration(); - configuration.setInt(YarnConfiguration.APP_ATTEMPT_DIAGNOSTICS_LIMIT_KC, 0); - - expectedException.expect(YarnRuntimeException.class); - - createRMAppAttemptImpl(configuration); + assertThrows(YarnRuntimeException.class, () -> { + final Configuration configuration = new Configuration(); + configuration.setInt(YarnConfiguration.APP_ATTEMPT_DIAGNOSTICS_LIMIT_KC, 0); + createRMAppAttemptImpl(configuration); + }); } @Test @@ -72,8 +67,8 @@ public void whenAppendedWithinLimitMessagesArePreserved() { final String withinLimit = RandomStringUtils.random(1024); appAttempt.appendDiagnostics(withinLimit); - assertEquals(withinLimit -, appAttempt.getDiagnostics(), "messages within limit should be preserved"); + assertEquals(withinLimit, + appAttempt.getDiagnostics(), "messages within limit should be preserved"); } @Test @@ -90,8 +85,8 @@ public void whenAppendedBeyondLimitMessagesAreTruncated() { BoundedAppender.TRUNCATED_MESSAGES_TEMPLATE, 1024, 1025, beyondLimit.substring(1)); - assertEquals(truncated -, appAttempt.getDiagnostics(), "messages beyond limit should be truncated"); + assertEquals(truncated, + appAttempt.getDiagnostics(), "messages beyond limit should be truncated"); } private RMAppAttemptImpl createRMAppAttemptImpl( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java index 0bdcd50ead00f..02f5956ccd389 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java @@ -21,9 +21,10 @@ 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.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.argThat; @@ -43,6 +44,8 @@ import java.util.List; import java.util.Set; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; @@ -114,19 +117,13 @@ import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.webapp.util.WebAppUtils; 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.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -@RunWith(value = Parameterized.class) public class TestRMAppAttemptTransitions { private static final Logger LOG = @@ -224,7 +221,6 @@ public void handle(AMLauncherEvent event) { private ApplicationSubmissionContext submissionContext = null; private boolean unmanagedAM; - @Parameterized.Parameters public static Collection getTestParameters() { return Arrays.asList(new Object[][] { { Boolean.FALSE }, @@ -232,12 +228,13 @@ public static Collection getTestParameters() { }); } - public TestRMAppAttemptTransitions(Boolean isSecurityEnabled) { - this.isSecurityEnabled = isSecurityEnabled; + private void initTestRMAppAttemptTransitions(boolean pIsSecurityEnabled) + throws Exception { + this.isSecurityEnabled = pIsSecurityEnabled; + setUp(); } @SuppressWarnings("deprecation") - @BeforeEach public void setUp() throws Exception { AuthenticationMethod authMethod = AuthenticationMethod.SIMPLE; if (isSecurityEnabled) { @@ -332,7 +329,7 @@ masterService, submissionContext, new Configuration(), protected void onInvalidTranstion( RMAppAttemptEventType rmAppAttemptEventType, RMAppAttemptState state) { - Assertions.assertTrue(false, "RMAppAttemptImpl can't handle " + assertTrue(false, "RMAppAttemptImpl can't handle " + rmAppAttemptEventType + " at state " + state); } }; @@ -352,7 +349,7 @@ public void tearDown() throws Exception { private String getProxyUrl(RMAppAttempt appAttempt) { String url = rmContext.getAppProxyUrl(conf, appAttempt.getAppAttemptId().getApplicationId()); - Assertions.assertNotEquals("N/A", url); + assertNotEquals("N/A", url); return url; } @@ -589,7 +586,7 @@ private void testAppAttemptFinishedState(Container container, verifyAttemptFinalStateSaved(); assertEquals(finishedContainerCount, applicationAttempt .getJustFinishedContainers().size()); - Assertions.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) + assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) .size()); assertEquals(container, applicationAttempt.getMasterContainer()); assertEquals(finalStatus, applicationAttempt.getFinalApplicationStatus()); @@ -753,8 +750,10 @@ private void sendAttemptUpdateSavedEvent(RMAppAttempt applicationAttempt) { RMAppAttemptEventType.ATTEMPT_UPDATE_SAVED)); } - @Test - public void testUsageReport() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testUsageReport(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); // scheduler has info on running apps ApplicationAttemptId attemptId = applicationAttempt.getAppAttemptId(); ApplicationResourceUsageReport appResUsgRpt = @@ -774,8 +773,8 @@ public void testUsageReport() { // expect usage stats to come from the scheduler report ApplicationResourceUsageReport report = applicationAttempt.getApplicationResourceUsageReport(); - Assertions.assertEquals(123456L, report.getMemorySeconds()); - Assertions.assertEquals(55544L, report.getVcoreSeconds()); + assertEquals(123456L, report.getMemorySeconds()); + assertEquals(55544L, report.getVcoreSeconds()); // finish app attempt and remove it from scheduler when(appResUsgRpt.getMemorySeconds()).thenReturn(223456L); @@ -790,12 +789,15 @@ public void testUsageReport() { when(scheduler.getSchedulerAppInfo(eq(attemptId))).thenReturn(null); report = applicationAttempt.getApplicationResourceUsageReport(); - Assertions.assertEquals(223456, report.getMemorySeconds()); - Assertions.assertEquals(75544, report.getVcoreSeconds()); + assertEquals(223456, report.getMemorySeconds()); + assertEquals(75544, report.getVcoreSeconds()); } - @Test - public void testUnmanagedAMUnexpectedRegistration() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testUnmanagedAMUnexpectedRegistration(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); unmanagedAM = true; when(submissionContext.getUnmanagedAM()).thenReturn(true); @@ -813,8 +815,11 @@ public void testUnmanagedAMUnexpectedRegistration() { "Unmanaged AM must register after AM attempt reaches LAUNCHED state."); } - @Test - public void testUnmanagedAMContainersCleanup() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testUnmanagedAMContainersCleanup(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); unmanagedAM = true; when(submissionContext.getUnmanagedAM()).thenReturn(true); when(submissionContext.getKeepContainersAcrossApplicationAttempts()) @@ -830,8 +835,10 @@ public void testUnmanagedAMContainersCleanup() { assertFalse(transferStateFromPreviousAttempt); } - @Test - public void testNewToKilled() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testNewToKilled(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); applicationAttempt.handle( new RMAppAttemptEvent( applicationAttempt.getAppAttemptId(), @@ -840,10 +847,12 @@ public void testNewToKilled() { applicationAttempt.createApplicationAttemptState()); testAppAttemptKilledState(null, EMPTY_DIAGNOSTICS); verifyTokenCount(applicationAttempt.getAppAttemptId(), 1); - } - - @Test - public void testNewToRecovered() { + } + + @ParameterizedTest + @MethodSource("getTestParameters") + public void testNewToRecovered(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); applicationAttempt.handle( new RMAppAttemptEvent( applicationAttempt.getAppAttemptId(), @@ -851,8 +860,10 @@ public void testNewToRecovered() { testAppAttemptRecoveredState(); } - @Test - public void testSubmittedToKilled() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testSubmittedToKilled(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); submitApplicationAttempt(); applicationAttempt.handle( new RMAppAttemptEvent( @@ -863,8 +874,10 @@ public void testSubmittedToKilled() { testAppAttemptKilledState(null, EMPTY_DIAGNOSTICS); } - @Test - public void testScheduledToKilled() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testScheduledToKilled(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); scheduleApplicationAttempt(); applicationAttempt.handle( new RMAppAttemptEvent( @@ -875,8 +888,10 @@ public void testScheduledToKilled() { testAppAttemptKilledState(null, EMPTY_DIAGNOSTICS); } - @Test - public void testAMCrashAtScheduled() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAMCrashAtScheduled(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); // This is to test sending CONTAINER_FINISHED event at SCHEDULED state. // Verify the state transition is correct. scheduleApplicationAttempt(); @@ -902,8 +917,10 @@ public void testAMCrashAtScheduled() { verifyApplicationAttemptFinished(RMAppAttemptState.FAILED); } - @Test - public void testAllocatedToKilled() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAllocatedToKilled(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); applicationAttempt.handle( new RMAppAttemptEvent( @@ -914,8 +931,10 @@ public void testAllocatedToKilled() { testAppAttemptKilledState(amContainer, EMPTY_DIAGNOSTICS); } - @Test - public void testAllocatedToFailed() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAllocatedToFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); String diagnostics = "Launch Failed"; applicationAttempt.handle( @@ -926,18 +945,22 @@ public void testAllocatedToFailed() { testAppAttemptFailedState(amContainer, diagnostics); } - @Test + @ParameterizedTest + @MethodSource("getTestParameters") @Timeout(value = 10) - public void testAllocatedToRunning() { + public void testAllocatedToRunning(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); // Register attempt event arrives before launched attempt event runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); launchApplicationAttempt(amContainer, RMAppAttemptState.RUNNING); } - @Test + @ParameterizedTest + @MethodSource("getTestParameters") @Timeout(value = 10) - public void testCreateAppAttemptReport() { + public void testCreateAppAttemptReport(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); RMAppAttemptState[] attemptStates = RMAppAttemptState.values(); applicationAttempt.handle(new RMAppAttemptEvent( applicationAttempt.getAppAttemptId(), RMAppAttemptEventType.KILL)); @@ -949,9 +972,11 @@ public void testCreateAppAttemptReport() { } } - @Test @Timeout(value = 10) - public void testLaunchedAtFinalSaving() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testLaunchedAtFinalSaving(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); // ALLOCATED->FINAL_SAVING @@ -982,9 +1007,11 @@ public void testLaunchedAtFinalSaving() { applicationAttempt.getAppAttemptState()); } - @Test @Timeout(value = 10) - public void testAttemptAddedAtFinalSaving() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAttemptAddedAtFinalSaving(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); submitApplicationAttempt(); // SUBMITTED->FINAL_SAVING @@ -1000,9 +1027,11 @@ public void testAttemptAddedAtFinalSaving() { applicationAttempt.getAppAttemptState()); } - @Test @Timeout(value = 10) - public void testAttemptRegisteredAtFailed() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAttemptRegisteredAtFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); @@ -1027,8 +1056,10 @@ public void testAttemptRegisteredAtFailed() { applicationAttempt.getAppAttemptState()); } - @Test - public void testAttemptLaunchFailedAtFailed() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAttemptLaunchFailedAtFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); //send CONTAINER_FINISHED event @@ -1051,8 +1082,10 @@ public void testAttemptLaunchFailedAtFailed() { applicationAttempt.getAppAttemptState()); } - @Test - public void testAMCrashAtAllocated() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAMCrashAtAllocated(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); String containerDiagMsg = "some error"; int exitCode = 123; @@ -1074,9 +1107,11 @@ public void testAMCrashAtAllocated() { verifyAMCrashAtAllocatedDiagnosticInfo(applicationAttempt.getDiagnostics(), exitCode, shouldCheckURL); } - - @Test - public void testRunningToFailed() { + + @ParameterizedTest + @MethodSource("getTestParameters") + public void testRunningToFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1118,8 +1153,10 @@ public void testRunningToFailed() { verifyApplicationAttemptFinished(RMAppAttemptState.FAILED); } - @Test - public void testRunningToKilled() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testRunningToKilled(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1158,9 +1195,11 @@ public void testRunningToKilled() { verifyApplicationAttemptFinished(RMAppAttemptState.KILLED); } - @Test @Timeout(value = 10) - public void testLaunchedExpire() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testLaunchedExpire(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); applicationAttempt.handle(new RMAppAttemptEvent( @@ -1181,9 +1220,11 @@ public void testLaunchedExpire() { } @SuppressWarnings("unchecked") - @Test @Timeout(value = 10) - public void testLaunchedFailWhileAHSEnabled() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testLaunchedFailWhileAHSEnabled(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Configuration myConf = new Configuration(conf); myConf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED, true); ApplicationId applicationId = MockApps.newAppID(appId); @@ -1254,9 +1295,11 @@ public void testLaunchedFailWhileAHSEnabled() { assertEquals(rmAppPageUrl, myApplicationAttempt.getTrackingUrl()); } - @Test @Timeout(value = 20) - public void testRunningExpire() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testRunningExpire(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1278,8 +1321,10 @@ public void testRunningExpire() { verifyApplicationAttemptFinished(RMAppAttemptState.FAILED); } - @Test - public void testUnregisterToKilledFinishing() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testUnregisterToKilledFinishing(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1288,33 +1333,45 @@ public void testUnregisterToKilledFinishing() { "Killed by user"); } - @Test - public void testTrackingUrlUnmanagedAM() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testTrackingUrlUnmanagedAM(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); testUnmanagedAMSuccess("oldTrackingUrl"); } - @Test - public void testEmptyTrackingUrlUnmanagedAM() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testEmptyTrackingUrlUnmanagedAM(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); testUnmanagedAMSuccess(""); } - @Test - public void testNullTrackingUrlUnmanagedAM() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testNullTrackingUrlUnmanagedAM(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); testUnmanagedAMSuccess(null); } - @Test - public void testManagedAMWithTrackingUrl() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testManagedAMWithTrackingUrl(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); testTrackingUrlManagedAM("theTrackingUrl"); } - @Test - public void testManagedAMWithEmptyTrackingUrl() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testManagedAMWithEmptyTrackingUrl(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); testTrackingUrlManagedAM(""); } - @Test - public void testManagedAMWithNullTrackingUrl() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testManagedAMWithNullTrackingUrl(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); testTrackingUrlManagedAM(null); } @@ -1326,8 +1383,10 @@ private void testTrackingUrlManagedAM(String url) { FinalApplicationStatus.SUCCEEDED, url, "Successful"); } - @Test - public void testUnregisterToSuccessfulFinishing() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testUnregisterToSuccessfulFinishing(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1335,8 +1394,10 @@ public void testUnregisterToSuccessfulFinishing() { FinalApplicationStatus.SUCCEEDED, "mytrackingurl", "Successful"); } - @Test - public void testFinishingKill() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFinishingKill(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1353,8 +1414,10 @@ public void testFinishingKill() { diagnostics); } - @Test - public void testFinishingExpire() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFinishingExpire(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1371,8 +1434,10 @@ public void testFinishingExpire() { diagnostics, 0, false); } - @Test - public void testFinishingToFinishing() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFinishingToFinishing(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1395,8 +1460,10 @@ public void testFinishingToFinishing() { diagnostics); } - @Test - public void testSuccessfulFinishingToFinished() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testSuccessfulFinishingToFinished(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1420,9 +1487,11 @@ public void testSuccessfulFinishingToFinished() { // Attempt_Saved event, we stay on FINAL_SAVING on Container_Finished event // and then directly jump from FINAL_SAVING to FINISHED state on Attempt_Saved // event - @Test - public void - testFinalSavingToFinishedWithContainerFinished() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFinalSavingToFinishedWithContainerFinished(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1453,8 +1522,11 @@ public void testSuccessfulFinishingToFinished() { // While attempt is at FINAL_SAVING, Expire event may come before // Attempt_Saved event, we stay on FINAL_SAVING on Expire event and then // directly jump from FINAL_SAVING to FINISHED state on Attempt_Saved event. - @Test - public void testFinalSavingToFinishedWithExpire() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFinalSavingToFinishedWithExpire(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1479,8 +1551,10 @@ public void testFinalSavingToFinishedWithExpire() { diagnostics, 0, false); } - @Test - public void testFinishedContainer() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFinishedContainer(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1506,37 +1580,37 @@ public void testFinishedContainer() { ArgumentCaptor.forClass(RMNodeFinishedContainersPulledByAMEvent.class); // Verify justFinishedContainers - Assertions.assertEquals(1, applicationAttempt.getJustFinishedContainers() + assertEquals(1, applicationAttempt.getJustFinishedContainers() .size()); - Assertions.assertEquals(container1.getId(), applicationAttempt + assertEquals(container1.getId(), applicationAttempt .getJustFinishedContainers().get(0).getContainerId()); - Assertions.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) + assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) .size()); // Verify finishedContainersSentToAM gets container after pull List containerStatuses = applicationAttempt .pullJustFinishedContainers(); - Assertions.assertEquals(1, containerStatuses.size()); + assertEquals(1, containerStatuses.size()); Mockito.verify(rmnodeEventHandler, never()).handle(Mockito .any(RMNodeEvent.class)); - Assertions.assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); - Assertions.assertEquals(1, getFinishedContainersSentToAM(applicationAttempt) + assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); + assertEquals(1, getFinishedContainersSentToAM(applicationAttempt) .size()); // Verify container is acked to NM via the RMNodeEvent after second pull containerStatuses = applicationAttempt.pullJustFinishedContainers(); - Assertions.assertEquals(0, containerStatuses.size()); + assertEquals(0, containerStatuses.size()); Mockito.verify(rmnodeEventHandler).handle(captor.capture()); - Assertions.assertEquals(container1.getId(), captor.getValue().getContainers() + assertEquals(container1.getId(), captor.getValue().getContainers() .get(0)); - Assertions.assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); - Assertions.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) + assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); + assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) .size()); // verify if no containers to acknowledge to NM then event should not be // triggered. Number of times event invoked is 1 i.e on second pull containerStatuses = applicationAttempt.pullJustFinishedContainers(); - Assertions.assertEquals(0, containerStatuses.size()); + assertEquals(0, containerStatuses.size()); Mockito.verify(rmnodeEventHandler, times(1)) .handle(Mockito.any(RMNodeEvent.class)); } @@ -1545,8 +1619,11 @@ public void testFinishedContainer() { * Check a completed container that is not yet pulled by AM heartbeat, * is ACKed to NM for cleanup when the AM container exits. */ - @Test - public void testFinishedContainerNotBeingPulledByAMHeartbeat() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFinishedContainerNotBeingPulledByAMHeartbeat( + boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1570,11 +1647,11 @@ public void testFinishedContainerNotBeingPulledByAMHeartbeat() { // Verify justFinishedContainers ArgumentCaptor captor = ArgumentCaptor.forClass(RMNodeFinishedContainersPulledByAMEvent.class); - Assertions.assertEquals(1, applicationAttempt.getJustFinishedContainers() + assertEquals(1, applicationAttempt.getJustFinishedContainers() .size()); - Assertions.assertEquals(container1.getId(), applicationAttempt + assertEquals(container1.getId(), applicationAttempt .getJustFinishedContainers().get(0).getContainerId()); - Assertions.assertTrue( + assertTrue( getFinishedContainersSentToAM(applicationAttempt).isEmpty()); // finish AM container to emulate AM exit event @@ -1589,15 +1666,15 @@ public void testFinishedContainerNotBeingPulledByAMHeartbeat() { List containerPulledEvents = captor.getAllValues(); // Verify AM container is acked to NM via the RMNodeEvent immediately - Assertions.assertEquals(amContainer.getId(), + assertEquals(amContainer.getId(), containerPulledEvents.get(0).getContainers().get(0)); // Verify the non-AM container is acked to NM via the RMNodeEvent - Assertions.assertEquals(container1.getId(), + assertEquals(container1.getId(), containerPulledEvents.get(1).getContainers().get(0)); - Assertions.assertTrue( + assertTrue( applicationAttempt.getJustFinishedContainers().isEmpty(), "No container shall be added to justFinishedContainers" + " as soon as AM container exits"); - Assertions.assertTrue( + assertTrue( getFinishedContainersSentToAM(applicationAttempt).isEmpty()); } @@ -1605,8 +1682,10 @@ public void testFinishedContainerNotBeingPulledByAMHeartbeat() { * Check a completed container is ACKed to NM for cleanup after the AM * container has exited. */ - @Test - public void testFinishedContainerAfterAMExit() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFinishedContainerAfterAMExit(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1626,7 +1705,7 @@ public void testFinishedContainerAfterAMExit() { ArgumentCaptor captor = ArgumentCaptor.forClass(RMNodeFinishedContainersPulledByAMEvent.class); Mockito.verify(rmnodeEventHandler).handle(captor.capture()); - Assertions.assertEquals(amContainer.getId(), + assertEquals(amContainer.getId(), captor.getValue().getContainers().get(0)); // Complete a non-AM container @@ -1645,12 +1724,12 @@ public void testFinishedContainerAfterAMExit() { captor = ArgumentCaptor.forClass( RMNodeFinishedContainersPulledByAMEvent.class); Mockito.verify(rmnodeEventHandler, times(2)).handle(captor.capture()); - Assertions.assertEquals(container1.getId(), + assertEquals(container1.getId(), captor.getAllValues().get(1).getContainers().get(0)); - Assertions.assertTrue( + assertTrue( applicationAttempt.getJustFinishedContainers().isEmpty(), "No container shall be added to justFinishedContainers" + " after AM container exited"); - Assertions.assertTrue( + assertTrue( getFinishedContainersSentToAM(applicationAttempt).isEmpty()); } @@ -1667,22 +1746,24 @@ private static List getFinishedContainersSentToAM( // this is to test user can get client tokens only after the client token // master key is saved in the state store and also registered in // ClientTokenSecretManager - @Test - public void testGetClientToken() throws Exception { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testGetClientToken(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); assumeTrue(isSecurityEnabled); Container amContainer = allocateApplicationAttempt(); // before attempt is launched, can not get ClientToken Token token = applicationAttempt.createClientToken(null); - Assertions.assertNull(token); + assertNull(token); launchApplicationAttempt(amContainer); // after attempt is launched , can get ClientToken token = applicationAttempt.createClientToken(null); - Assertions.assertNull(token); + assertNull(token); token = applicationAttempt.createClientToken("clientuser"); - Assertions.assertNotNull(token); + assertNotNull(token); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt .getAppAttemptId(), RMAppAttemptEventType.KILL)); @@ -1691,24 +1772,26 @@ public void testGetClientToken() throws Exception { sendAttemptUpdateSavedEvent(applicationAttempt); // after attempt is killed, can not get Client Token token = applicationAttempt.createClientToken(null); - Assertions.assertNull(token); + assertNull(token); token = applicationAttempt.createClientToken("clientuser"); - Assertions.assertNull(token); + assertNull(token); } // this is to test master key is saved in the secret manager only after // attempt is launched and in secure-mode - @Test - public void testApplicationAttemptMasterKey() throws Exception { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testApplicationAttemptMasterKey(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); ApplicationAttemptId appid = applicationAttempt.getAppAttemptId(); boolean isMasterKeyExisted = clientToAMTokenManager.hasMasterKey(appid); if (isSecurityEnabled) { - Assertions.assertTrue(isMasterKeyExisted); - Assertions.assertNotNull(clientToAMTokenManager.getMasterKey(appid)); + assertTrue(isMasterKeyExisted); + assertNotNull(clientToAMTokenManager.getMasterKey(appid)); } else { - Assertions.assertFalse(isMasterKeyExisted); + assertFalse(isMasterKeyExisted); } launchApplicationAttempt(amContainer); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt @@ -1718,11 +1801,13 @@ public void testApplicationAttemptMasterKey() throws Exception { sendAttemptUpdateSavedEvent(applicationAttempt); // after attempt is killed, can not get MasterKey isMasterKeyExisted = clientToAMTokenManager.hasMasterKey(appid); - Assertions.assertFalse(isMasterKeyExisted); + assertFalse(isMasterKeyExisted); } - @Test - public void testFailedToFailed() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testFailedToFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); // create a failed attempt. when(submissionContext.getKeepContainersAcrossApplicationAttempts()) .thenReturn(true); @@ -1766,8 +1851,10 @@ public void testFailedToFailed() { assertTrue(found); } - @Test - public void testContainerRemovedBeforeAllocate() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testContainerRemovedBeforeAllocate(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); scheduleApplicationAttempt(); // Mock the allocation of AM container @@ -1796,8 +1883,10 @@ public void testContainerRemovedBeforeAllocate() { } @SuppressWarnings("deprecation") - @Test - public void testContainersCleanupForLastAttempt() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testContainersCleanupForLastAttempt(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); // create a failed attempt. applicationAttempt = new RMAppAttemptImpl(applicationAttempt.getAppAttemptId(), spyRMContext, @@ -1828,8 +1917,11 @@ scheduler, masterService, submissionContext, new Configuration(), } @SuppressWarnings("unchecked") - @Test - public void testScheduleTransitionReplaceAMContainerRequestWithDefaults() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testScheduleTransitionReplaceAMContainerRequestWithDefaults( + boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); YarnScheduler mockScheduler = mock(YarnScheduler.class); when(mockScheduler.allocate(any(ApplicationAttemptId.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class), @@ -1871,9 +1963,11 @@ public Allocation answer(InvocationOnMock invocation) (RMAppAttemptImpl) applicationAttempt, null); } - @Test @Timeout(value = 30) - public void testNewToFailed() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testNewToFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt .getAppAttemptId(), RMAppAttemptEventType.FAIL, FAILED_DIAGNOSTICS)); assertEquals(YarnApplicationAttemptState.NEW, @@ -1882,9 +1976,11 @@ public void testNewToFailed() { verifyTokenCount(applicationAttempt.getAppAttemptId(), 1); } - @Test @Timeout(value = 30) - public void testSubmittedToFailed() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testSubmittedToFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); submitApplicationAttempt(); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt .getAppAttemptId(), RMAppAttemptEventType.FAIL, FAILED_DIAGNOSTICS)); @@ -1893,9 +1989,11 @@ public void testSubmittedToFailed() { testAppAttemptFailedState(null, FAILED_DIAGNOSTICS); } - @Test @Timeout(value = 30) - public void testScheduledToFailed() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testScheduledToFailed(boolean pIsSecurityEnabled) throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); scheduleApplicationAttempt(); applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt .getAppAttemptId(), RMAppAttemptEventType.FAIL, FAILED_DIAGNOSTICS)); @@ -1904,9 +2002,12 @@ public void testScheduledToFailed() { testAppAttemptFailedState(null, FAILED_DIAGNOSTICS); } - @Test @Timeout(value = 30) - public void testAllocatedToFailedUserTriggeredFailEvent() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testAllocatedToFailedUserTriggeredFailEvent(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); assertEquals(YarnApplicationAttemptState.ALLOCATED, applicationAttempt.createApplicationAttemptState()); @@ -1915,9 +2016,12 @@ public void testAllocatedToFailedUserTriggeredFailEvent() { testAppAttemptFailedState(amContainer, FAILED_DIAGNOSTICS); } - @Test @Timeout(value = 30) - public void testRunningToFailedUserTriggeredFailEvent() { + @ParameterizedTest + @MethodSource("getTestParameters") + public void testRunningToFailedUserTriggeredFailEvent(boolean pIsSecurityEnabled) + throws Exception { + initTestRMAppAttemptTransitions(pIsSecurityEnabled); Container amContainer = allocateApplicationAttempt(); launchApplicationAttempt(amContainer); runApplicationAttempt(amContainer, "host", 8042, "oldtrackingurl", false); @@ -1995,12 +2099,12 @@ private void verifyApplicationAttemptFinished(RMAppAttemptState state) { ArgumentCaptor.forClass(RMAppAttemptState.class); verify(writer).applicationAttemptFinished( any(RMAppAttempt.class), finalState.capture()); - Assertions.assertEquals(state, finalState.getValue()); + assertEquals(state, finalState.getValue()); finalState = ArgumentCaptor.forClass(RMAppAttemptState.class); verify(publisher).appAttemptFinished(any(RMAppAttempt.class), finalState.capture(), any(RMApp.class), anyLong()); - Assertions.assertEquals(state, finalState.getValue()); + assertEquals(state, finalState.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/rmcontainer/TestRMContainerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java index b0508d27e5a79..8187a9b1ae92a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmcontainer/TestRMContainerImpl.java @@ -19,15 +19,19 @@ package org.apache.hadoop.yarn.server.resourcemanager.rmcontainer; 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.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.anyLong; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.reset; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; @@ -74,12 +78,10 @@ import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey; import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.resource.Resources; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; -import org.mockito.Mockito; @SuppressWarnings({ "unchecked", "rawtypes" }) public class TestRMContainerImpl { @@ -111,7 +113,7 @@ public void testReleaseWhileRunning() { spy(new ConcurrentHashMap()); RMApp rmApp = mock(RMApp.class); when(rmApp.getRMAppAttempt(any())).thenReturn(null); - Mockito.doReturn(rmApp) + doReturn(rmApp) .when(rmApps).get(ArgumentMatchers.any()); RMApplicationHistoryWriter writer = mock(RMApplicationHistoryWriter.class); @@ -299,7 +301,7 @@ public void testExistenceOfResourceRequestInRMContainer() throws Exception { // Verify whether list of ResourceRequest is present in RMContainer // while moving to ALLOCATED state - Assertions.assertNotNull( + assertNotNull( scheduler.getRMContainer(containerId2).getContainerRequest()); // Allocate container @@ -309,7 +311,7 @@ public void testExistenceOfResourceRequestInRMContainer() throws Exception { // After RMContainer moving to ACQUIRED state, list of ResourceRequest will // be empty - Assertions.assertNull( + assertNull( scheduler.getRMContainer(containerId2).getContainerRequest()); } @@ -421,7 +423,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() spy(new ConcurrentHashMap()); RMApp rmApp = mock(RMApp.class); when(rmApp.getRMAppAttempt(any())).thenReturn(null); - Mockito.doReturn(rmApp).when(rmApps).get( + doReturn(rmApp).when(rmApps).get( ArgumentMatchers.any()); RMApplicationHistoryWriter writer = mock(RMApplicationHistoryWriter.class); @@ -449,7 +451,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() SchedulerRequestKey.extractFrom(container), appAttemptId, nodeId, "user", rmContext); - Assertions.assertEquals(0, + assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags( TestUtils.getMockApplicationId(1), null), @@ -459,7 +461,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.START)); schedulerNode.allocateContainer(rmContainer); - Assertions.assertEquals(1, + assertEquals(1, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -469,7 +471,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.KILL)); schedulerNode.releaseContainer(container.getId(), true); - Assertions.assertEquals(0, + assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -479,7 +481,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() SchedulerRequestKey.extractFrom(container), appAttemptId, nodeId, "user", rmContext); - Assertions.assertEquals(0, + assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -489,7 +491,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.START)); schedulerNode.allocateContainer(rmContainer); - Assertions.assertEquals(1, + assertEquals(1, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -502,7 +504,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.FINISHED)); schedulerNode.releaseContainer(container.getId(), true); - Assertions.assertEquals(0, + assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -513,7 +515,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() nodeId, "user", rmContext); rmContainer.setAllocationTags(ImmutableSet.of("mapper")); - Assertions.assertEquals(0, + assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -522,7 +524,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.START)); schedulerNode.allocateContainer(rmContainer); - Assertions.assertEquals(1, + assertEquals(1, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -538,7 +540,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() RMContainerEventType.FINISHED)); schedulerNode.releaseContainer(container.getId(), true); - Assertions.assertEquals(0, + assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -549,7 +551,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() "user", rmContext); rmContainer.setAllocationTags(ImmutableSet.of("mapper")); - Assertions.assertEquals(0, + assertEquals(0, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -562,7 +564,7 @@ public void testContainerTransitionNotifyAllocationTagsManager() rmContainer .handle(new RMContainerRecoverEvent(containerId, containerStatus)); - Assertions.assertEquals(1, + assertEquals(1, tagsManager.getNodeCardinalityByOp(nodeId, AllocationTags.createSingleAppAllocationTags(appId, null), Long::max)); @@ -620,7 +622,7 @@ public void testContainerAcquiredAtKilled() { @Override protected void onInvalidStateTransition( RMContainerEventType rmContainerEventType, RMContainerState state) { - Assertions.fail("RMContainerImpl: can't handle " + rmContainerEventType + fail("RMContainerImpl: can't handle " + rmContainerEventType + " at state " + state); } }; From 5eb10d1401b264cae43e60de7e67ddb7478fb032 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sun, 9 Mar 2025 15:12:25 +0800 Subject: [PATCH 4/5] YARN-11262. Fix CheckStyle. --- .../server/resourcemanager/rmapp/TestRMAppTransitions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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/rmapp/TestRMAppTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java index 4b00b60384655..5e6069042991c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -1071,7 +1071,7 @@ public void testAppRunningFailed(boolean pIsSecurityEnabled) throws Exception { RMApp application = testCreateAppRunning(null); RMAppAttempt appAttempt = application.getCurrentAppAttempt(); int expectedAttemptId = 1; - assertEquals(expectedAttemptId, + assertEquals(expectedAttemptId, appAttempt.getAppAttemptId().getAttemptId()); // RUNNING => FAILED/RESTARTING event RMAppEventType.ATTEMPT_FAILED assertTrue(maxAppAttempts > 1); @@ -1083,7 +1083,7 @@ public void testAppRunningFailed(boolean pIsSecurityEnabled) throws Exception { rmDispatcher.await(); assertAppState(RMAppState.ACCEPTED, application); appAttempt = application.getCurrentAppAttempt(); - assertEquals(++expectedAttemptId, + assertEquals(++expectedAttemptId, appAttempt.getAppAttemptId().getAttemptId()); event = new RMAppEvent(application.getApplicationId(), From c1960d50c4ac3981966518fe76732f4228bacaff Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Mon, 10 Mar 2025 09:42:18 +0800 Subject: [PATCH 5/5] YARN-11262. Fix CheckStyle. --- .../placement/TestPlacementRuleFS.java | 16 +-- .../TestCSMappingPlacementRule.java | 13 +- .../TestMappingRuleMatchers.java | 2 +- .../recovery/RMStateStoreTestBase.java | 4 +- .../recovery/TestFSRMStateStore.java | 3 +- .../recovery/TestZKRMStateStore.java | 10 +- .../TestCapacitySchedulerPlanFollower.java | 4 - .../TestFairSchedulerPlanFollower.java | 4 - .../TestReservationInputValidator.java | 8 +- .../planning/TestAlignedPlanner.java | 126 +++++++++--------- .../planning/TestGreedyReservationAgent.java | 11 +- .../planning/TestSimpleCapacityReplanner.java | 7 +- .../resourcetracker/TestNMExpiry.java | 2 +- .../rmapp/TestApplicationLifetimeMonitor.java | 3 +- .../rmapp/TestRMAppTransitions.java | 17 ++- .../attempt/TestRMAppAttemptTransitions.java | 39 +++--- 16 files changed, 128 insertions(+), 141 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/placement/TestPlacementRuleFS.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java index 85d8a4fbcbfeb..0e8bd594691be 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementRuleFS.java @@ -140,12 +140,12 @@ private void ruleCreateBoolean(Class ruleClass) { PlacementRule rule = getPlacementRule(ruleClass, true); String name = ruleClass.getName(); assertNotNull(rule, "Rule object should not be null for " + name); - assertTrue( - getCreateFlag(rule), "Create flag was not set to true on " + name); + assertTrue(getCreateFlag(rule), + "Create flag was not set to true on " + name); rule = getPlacementRule(ruleClass, false); assertNotNull(rule, "Rule object should not be null for " + name); - assertFalse( - getCreateFlag(rule), "Create flag was not set to false on " + name); + assertFalse(getCreateFlag(rule), + "Create flag was not set to false on " + name); } private void ruleCreateElement(Class ruleClass) { @@ -154,14 +154,14 @@ private void ruleCreateElement(Class ruleClass) { PlacementRule rule = getPlacementRule(ruleClass, conf); String name = ruleClass.getName(); assertNotNull(rule, "Rule object should not be null for " + name); - assertTrue( - getCreateFlag(rule), "Create flag was not set to true on " + name); + assertTrue(getCreateFlag(rule), + "Create flag was not set to true on " + name); str = ""; conf = createConf(str); rule = getPlacementRule(ruleClass, conf); assertNotNull(rule, "Rule object should not be null for " + name); - assertFalse( - getCreateFlag(rule), "Create flag was not set to false on " + name); + assertFalse(getCreateFlag(rule), + "Create flag was not set to false on " + name); } private void ruleInit(Class ruleClass) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java index 7b8b2b5a2d539..d2da49001766e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestCSMappingPlacementRule.java @@ -65,7 +65,7 @@ public class TestCSMappingPlacementRule { .getLogger(TestCSMappingPlacementRule.class); @TempDir - static Path folder; + private Path folder; private Map> userGroups = ImmutableMap.>builder() @@ -632,12 +632,11 @@ void assertConfigTestResult(List rules) { assertEquals(1, rules.size(), "We only specified one rule"); MappingRule rule = rules.get(0); String ruleStr = rule.toString(); - assertTrue( - ruleStr.contains("variable='%user'"), "Rule's matcher variable should be %user"); - assertTrue( - ruleStr.contains("value='bob'"), "Rule's match value should be bob"); - assertTrue(ruleStr.contains( - "action=PlaceToQueueAction{queueName='%primary_group'"), "Rule's action should be place to queue"); + assertTrue(ruleStr.contains("variable='%user'"), + "Rule's matcher variable should be %user"); + assertTrue(ruleStr.contains("value='bob'"), "Rule's match value should be bob"); + assertTrue(ruleStr.contains("action=PlaceToQueueAction{queueName='%primary_group'"), + "Rule's action should be place to queue"); } @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/placement/csmappingrule/TestMappingRuleMatchers.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java index 654cf3af9a243..eba4b88649d13 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/csmappingrule/TestMappingRuleMatchers.java @@ -124,7 +124,7 @@ public void testVariableMatcherSubstitutions() { assertFalse(userCustom.match(mismatchingContext), "%user (dave) should NOT match %custom (bob) in mismatching context"); assertFalse(userCusTom.match(mismatchingContext), - "%user (dave) should NOT match %cus%tom (b+ob) in mismatching context"); + "%user (dave) should NOT match %cus%tom (b+ob) in mismatching context"); assertTrue(userUser.match(mismatchingContext), "%user should match %user in any context"); assertFalse(userStatic.match(mismatchingContext), diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java index 73a92da17b859..202ecf811b16b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/RMStateStoreTestBase.java @@ -874,8 +874,8 @@ public void testReservationStateStore( assertNotNull(reservations); ReservationAllocationStateProto storedReservationAllocation = reservations.get(r1); - assertNull( - storedReservationAllocation, "Removed reservation should not be available in store"); + assertNull(storedReservationAllocation, + "Removed reservation should not be available in store"); storedReservationAllocation = reservations.get(r2); assertAllocationStateEqual( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java index 83f76d043663e..15319a7e51585 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestFSRMStateStore.java @@ -300,7 +300,8 @@ private void verifyFilesUnreadablebyHDFS(MiniDFSCluster cluster, try { LOG.warn("\n\n ##Testing path [" + p + "]\n\n"); fs.open(p); - fail("Super user should not be able to read ["+ UserGroupInformation.getCurrentUser() + "] [" + p.getName() + "]"); + fail("Super user should not be able to read ["+ + UserGroupInformation.getCurrentUser() + "] [" + p.getName() + "]"); } catch (AccessControlException e) { assertTrue(e.getMessage().contains("superuser is not allowed to perform this operation")); } catch (Exception e) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java index 630e8a47f0226..47ed376084256 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/recovery/TestZKRMStateStore.java @@ -380,7 +380,7 @@ protected synchronized void storeVersion() throws Exception { Version defaultVersion = zkTester.getCurrentVersion(); store.checkVersion(); assertEquals( - defaultVersion, store.loadVersion(), "Store had wrong version"); + defaultVersion, store.loadVersion(), "Store had wrong version"); } public static Configuration createHARMConf(String rmIds, String rmId, @@ -514,8 +514,8 @@ public void testFencing() throws Exception { } } assertEquals(HAServiceProtocol.HAServiceState.STANDBY, - rm1.getRMContext().getRMAdminService().getServiceStatus().getState(), - "RM should have been fenced"); + rm1.getRMContext().getRMAdminService().getServiceStatus().getState(), + "RM should have been fenced"); assertEquals(HAServiceProtocol.HAServiceState.ACTIVE, rm2.getRMContext().getRMAdminService().getServiceStatus().getState(), "RM should be Active"); @@ -758,8 +758,8 @@ private static void verifyLoadedApp(RMState rmState, } } } else { - assertEquals( - 0, appState.attempts.size(), "Attempts loaded for app " + appId); + assertEquals(0, appState.attempts.size(), + "Attempts loaded for app " + appId); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java index de0d0b3f26c52..5ba5eb8821a0a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestCapacitySchedulerPlanFollower.java @@ -32,7 +32,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.AccessControlException; -import org.apache.hadoop.test.TestName; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.server.resourcemanager.RMContext; @@ -67,9 +66,6 @@ public class TestCapacitySchedulerPlanFollower extends private CapacitySchedulerContext csContext; private CapacityScheduler cs; - @RegisterExtension - public TestName methodName = new TestName(); - @BeforeEach public void setUp() throws Exception { CapacityScheduler spyCs = new CapacityScheduler(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java index c3a1edc309f9d..efc7a3a88e3e0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestFairSchedulerPlanFollower.java @@ -33,7 +33,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.AccessControlException; -import org.apache.hadoop.test.TestName; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.conf.YarnConfiguration; @@ -70,9 +69,6 @@ public class TestFairSchedulerPlanFollower extends private Configuration conf; private FairSchedulerTestBase testHelper = new FairSchedulerTestBase(); - @RegisterExtension - public TestName methodName = new TestName(); - protected Configuration createConfiguration() { Configuration conf = testHelper.createConfiguration(); conf.setClass(YarnConfiguration.RM_SCHEDULER, FairScheduler.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/reservation/TestReservationInputValidator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java index 458667c5669b2..95fa1726063a9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/TestReservationInputValidator.java @@ -442,8 +442,8 @@ public void testUpdateReservationNoDefinition() { } catch (YarnException e) { assertNull(plan); String message = e.getMessage(); - assertTrue(message.startsWith("Missing reservation definition. " + - "Please try again by specifying a reservation definition.")); + assertTrue(message.startsWith("Missing reservation definition. " + + "Please try again by specifying a reservation definition.")); LOG.info(message); } } @@ -631,8 +631,8 @@ public void testDeleteReservationNoID() { } catch (YarnException e) { assertNull(plan); String message = e.getMessage(); - assertTrue(message - .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); + assertTrue(message.startsWith("Missing reservation id. " + + "Please try again by specifying a reservation id.")); LOG.info(message); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java index b2e154be3a74b..9b847324e4ab9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestAlignedPlanner.java @@ -136,8 +136,8 @@ public void testSingleReservationAccept(String pRecurrenceExpression) throws Pla ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue( - check(alloc1, 10 * step, 20 * step, 10, 2048, 2), alloc1.toString()); + assertTrue(check(alloc1, 10 * step, 20 * step, + 10, 2048, 2), alloc1.toString()); System.out.println("--------AFTER AGENT----------"); System.out.println(plan.toString()); @@ -180,8 +180,8 @@ public void testOrderNoGapImpossible(String pRecurrenceExpression) throws Planni } // CHECK: allocation was not accepted - assertTrue(plan - .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); + assertTrue(plan.getAllReservations().size() == numJobsInScenario, + "Agent-based allocation should have failed"); } @@ -221,8 +221,8 @@ public void testOrderNoGapImpossible2(String pRecurrenceExpression) throws Plann } // CHECK: allocation was not accepted - assertTrue(plan - .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); + assertTrue(plan.getAllReservations().size() == numJobsInScenario, + "Agent-based allocation should have failed"); } @@ -262,8 +262,8 @@ public void testOrderImpossible(String pRecurrenceExpression) throws PlanningExc } // CHECK: allocation was not accepted - assertTrue(plan - .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); + assertTrue(plan.getAllReservations().size() == numJobsInScenario, + "Agent-based allocation should have failed"); } @@ -303,8 +303,8 @@ public void testAnyImpossible(String pRecurrenceExpression) throws PlanningExcep } // CHECK: allocation was not accepted - assertTrue(plan - .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); + assertTrue(plan.getAllReservations().size() == numJobsInScenario, + "Agent-based allocation should have failed"); } @@ -347,8 +347,8 @@ public void testAnyAccept(String pRecurrenceExpression) throws PlanningException ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue( - check(alloc1, 14 * step, 15 * step, 20, 1024, 1), alloc1.toString()); + assertTrue(check(alloc1, 14 * step, 15 * step, 20, 1024, 1), + alloc1.toString()); } @@ -391,10 +391,10 @@ public void testAllAccept(String pRecurrenceExpression) throws PlanningException ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue( - check(alloc1, 10 * step, 11 * step, 20, 1024, 1), alloc1.toString()); - assertTrue( - check(alloc1, 14 * step, 15 * step, 20, 1024, 1), alloc1.toString()); + assertTrue(check(alloc1, 10 * step, 11 * step, 20, 1024, 1), + alloc1.toString()); + assertTrue(check(alloc1, 14 * step, 15 * step, 20, 1024, 1), + alloc1.toString()); } @@ -434,8 +434,8 @@ public void testAllImpossible(String pRecurrenceExpression) throws PlanningExcep } // CHECK: allocation was not accepted - assertTrue(plan - .getAllReservations().size() == numJobsInScenario, "Agent-based allocation should have failed"); + assertTrue(plan.getAllReservations().size() == numJobsInScenario, + "Agent-based allocation should have failed"); } @@ -520,8 +520,8 @@ public void testImpossibleDuration(String pRecurrenceExpression) throws Planning } // CHECK: allocation was not accepted - assertTrue(plan - .getAllReservations().size() == 0, "Agent-based allocation should have failed"); + assertTrue(plan.getAllReservations().size() == 0, + "Agent-based allocation should have failed"); } @@ -557,12 +557,12 @@ public void testLoadedDurationIntervals(String pRecurrenceExpression) throws Pla ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue( - check(alloc1, 10 * step, 11 * step, 20, 1024, 1), alloc1.toString()); - assertTrue( - check(alloc1, 11 * step, 12 * step, 20, 1024, 1), alloc1.toString()); - assertTrue( - check(alloc1, 12 * step, 13 * step, 40, 1024, 1), alloc1.toString()); + assertTrue(check(alloc1, 10 * step, 11 * step, 20, 1024, 1), + alloc1.toString()); + assertTrue(check(alloc1, 11 * step, 12 * step, 20, 1024, 1), + alloc1.toString()); + assertTrue(check(alloc1, 12 * step, 13 * step, 40, 1024, 1), + alloc1.toString()); } @ParameterizedTest(name = "Testing: periodicity {0}") @@ -621,10 +621,10 @@ public void testCostFunction(String pRecurrenceExpression) throws PlanningExcept // Get reservation ReservationAllocation alloc3 = plan.getReservationById(reservationID3); - assertTrue( - check(alloc3, 10 * step, 11 * step, 0, 1024, 1), alloc3.toString()); - assertTrue( - check(alloc3, 11 * step, 12 * step, 1, 1024, 1), alloc3.toString()); + assertTrue(check(alloc3, 10 * step, 11 * step, 0, 1024, 1), + alloc3.toString()); + assertTrue(check(alloc3, 11 * step, 12 * step, 1, 1024, 1), + alloc3.toString()); } @@ -748,8 +748,8 @@ public void testFromCluster(String pRecurrenceExpression) throws PlanningExcepti } // CHECK: allocation was accepted - assertTrue(plan.getAllReservations() - .size() == list.size(), "Agent-based allocation failed"); + assertTrue(plan.getAllReservations().size() == list.size(), + "Agent-based allocation failed"); } @@ -783,15 +783,15 @@ public void testSingleReservationAcceptAllocateLeft(String pRecurrenceExpression // CHECK: allocation was accepted assertTrue(reservationID != null, "Agent-based allocation failed"); - assertTrue(plan.getAllReservations() - .size() == 1, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations().size() == 1, + "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(reservationID); // Verify allocation - assertTrue( - check(alloc1, 10 * step, 30 * step, 20, 1024, 1), alloc1.toString()); + assertTrue(check(alloc1, 10 * step, 30 * step, 20, 1024, 1), + alloc1.toString()); } @@ -837,15 +837,14 @@ public void testLeftSucceedsRightFails(String pRecurrenceExpression) throws Plan // CHECK: allocation was accepted assertTrue(reservationID1 != null, "Agent-based allocation failed"); - assertTrue(plan.getAllReservations() - .size() == numJobsInScenario + 1, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations().size() == numJobsInScenario + 1, + "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc1 = plan.getReservationById(reservationID1); // Verify allocation - assertTrue( - check(alloc1, 7 * step, 11 * step, 20, 1024, 1), alloc1.toString()); + assertTrue(check(alloc1, 7 * step, 11 * step, 20, 1024, 1), alloc1.toString()); // Add second reservation ReservationId reservationID2 = @@ -854,15 +853,15 @@ public void testLeftSucceedsRightFails(String pRecurrenceExpression) throws Plan // CHECK: allocation was accepted assertTrue(reservationID2 != null, "Agent-based allocation failed"); - assertTrue(plan.getAllReservations() - .size() == numJobsInScenario + 2, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations().size() == numJobsInScenario + 2, + "Agent-based allocation failed"); // Get reservation ReservationAllocation alloc2 = plan.getReservationById(reservationID2); // Verify allocation - assertTrue( - check(alloc2, 14 * step, 16 * step, 100, 1024, 1), alloc2.toString()); + assertTrue(check(alloc2, 14 * step, 16 * step, 100, 1024, 1), + alloc2.toString()); agentLeft.deleteReservation(reservationID1, "u1", plan); agentLeft.deleteReservation(reservationID2, "u2", plan); @@ -876,8 +875,8 @@ public void testLeftSucceedsRightFails(String pRecurrenceExpression) throws Plan // CHECK: allocation was accepted assertTrue(reservationID3 != null, "Agent-based allocation failed"); - assertTrue(plan.getAllReservations() - .size() == numJobsInScenario + 1, "Agent-based allocation failed"); + assertTrue(plan.getAllReservations().size() == numJobsInScenario + 1, + "Agent-based allocation failed"); // Add 2nd reservation try { @@ -916,44 +915,44 @@ public void testValidateOrderNoGap(String pRecurrenceExpression) { curAlloc.clear(); curAlloc.put(new ReservationInterval(9 * step, 10 * step), Resource.newInstance(1024, 1)); - assertTrue( - IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), "validateOrderNoFap() should have succeeded"); + assertTrue(IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), + "validateOrderNoFap() should have succeeded"); // 2. allocateLeft = false, fail when curAlloc has a gap curAlloc.put(new ReservationInterval(7 * step, 8 * step), Resource.newInstance(1024, 1)); - assertFalse( - IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), "validateOrderNoGap() failed to identify a gap in curAlloc"); + assertFalse(IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), + "validateOrderNoGap() failed to identify a gap in curAlloc"); // 3. allocateLeft = false, fail when there is a gap between curAlloc and // allocations curAlloc.clear(); curAlloc.put(new ReservationInterval(8 * step, 9 * step), Resource.newInstance(1024, 1)); - assertFalse( - IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), "validateOrderNoGap() failed to identify a gap between " + assertFalse(IterativePlanner.validateOrderNoGap(allocation, curAlloc, false), + "validateOrderNoGap() failed to identify a gap between " + "allocations and curAlloc"); // 4. allocateLeft = true, succeed when there is no gap curAlloc.clear(); curAlloc.put(new ReservationInterval(13 * step, 14 * step), Resource.newInstance(1024, 1)); - assertTrue( - IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), "validateOrderNoFap() should have succeeded"); + assertTrue(IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), + "validateOrderNoFap() should have succeeded"); // 5. allocateLeft = true, fail when there is a gap between curAlloc and // allocations curAlloc.put(new ReservationInterval(15 * step, 16 * step), Resource.newInstance(1024, 1)); - assertFalse( - IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), "validateOrderNoGap() failed to identify a gap in curAlloc"); + assertFalse(IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), + "validateOrderNoGap() failed to identify a gap in curAlloc"); // 6. allocateLeft = true, fail when curAlloc has a gap curAlloc.clear(); curAlloc.put(new ReservationInterval(14 * step, 15 * step), Resource.newInstance(1024, 1)); - assertFalse( - IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), "validateOrderNoGap() failed to identify a gap between " + assertFalse(IterativePlanner.validateOrderNoGap(allocation, curAlloc, true), + "validateOrderNoGap() failed to identify a gap between " + "allocations and curAlloc"); } @@ -1183,12 +1182,11 @@ private void addFixedAllocation(long start, long step, int[] f) ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( start, start + f.length * step, f.length * step); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation( - ReservationSystemTestUtil.getNewReservationId(), rDef, - "user_fixed", "dedicated", start, start + f.length * step, - ReservationSystemTestUtil.generateAllocation(start, step, f), res, - minAlloc), false), plan.toString()); + assertTrue(plan.addReservation(new InMemoryReservationAllocation( + ReservationSystemTestUtil.getNewReservationId(), rDef, + "user_fixed", "dedicated", start, start + f.length * step, + ReservationSystemTestUtil.generateAllocation(start, step, f), res, + minAlloc), false), plan.toString()); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java index fc3e17fe70f25..ee410846c5105 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java @@ -295,12 +295,11 @@ public void testOrder(boolean pAllocateLeft, ReservationSystemTestUtil.createSimpleReservationDefinition(30 * step, 30 * step + f.length * step, f.length * step, 1, recurrenceExpression); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation( - ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", - "dedicated", 30 * step, 30 * step + f.length * step, - ReservationSystemTestUtil.generateAllocation(30 * step, step, f), - res, minAlloc), false), plan.toString()); + assertTrue(plan.addReservation(new InMemoryReservationAllocation( + ReservationSystemTestUtil.getNewReservationId(), rDef, "u1", + "dedicated", 30 * step, 30 * step + f.length * step, + ReservationSystemTestUtil.generateAllocation(30 * step, step, f), + res, minAlloc), false), plan.toString()); // create a chain of 4 RR, mixing gang and non-gang ReservationDefinition rr = new ReservationDefinitionPBImpl(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java index 1a78f609cd12b..6b9a4612d2823 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestSimpleCapacityReplanner.java @@ -117,10 +117,9 @@ public void testReplanningPlanCapacityLoss() throws PlanningException { minAlloc), false), plan.toString()); when(clock.getTime()).thenReturn(4L); ReservationId r5 = ReservationId.newInstance(ts, 5); - assertTrue( - plan.addReservation(new InMemoryReservationAllocation(r5, rDef, "u7", - "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, - minAlloc), false), plan.toString()); + assertTrue(plan.addReservation(new InMemoryReservationAllocation(r5, rDef, "u7", + "dedicated", 0, 0 + f5.length, generateAllocation(0, f5), res, + minAlloc), false), plan.toString()); int[] f6 = { 50, 50, 50, 50, 50 }; ReservationId r6 = ReservationId.newInstance(ts, 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/resourcetracker/TestNMExpiry.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java index 41920a5d7451d..7a0b49b878b11 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestNMExpiry.java @@ -178,7 +178,7 @@ public void testNMExpiry() throws Exception { /* test to see if hostanme 3 does not expire */ stopT = false; new ThirdNodeHeartBeatThread().start(); - assertEquals(2,ClusterMetrics.getMetrics().getNumLostNMs()); + assertEquals(2, ClusterMetrics.getMetrics().getNumLostNMs()); stopT = true; } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java index 0f6e2c79d2520..c45b50b85be4c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java @@ -510,7 +510,8 @@ public void testOverrideParentQueueMaxAppLifetime(Class schedulerParameter) thro rm.waitForState(app1.getApplicationId(), RMAppState.KILLED); long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime(); // Child queue's max lifetime can override parent's and be larger. - assertTrue((maxRootLifetime < maxChildLifetime) && (totalTimeRun > (maxChildLifetime * 1000)), + assertTrue((maxRootLifetime < maxChildLifetime) && + (totalTimeRun > (maxChildLifetime * 1000)), "Application killed before default lifetime value"); assertEquals(maxRootLifetime, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly"); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java index 5e6069042991c..b78fe3a438c5b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -1163,8 +1163,8 @@ public void testAppFinalSavingToFinished(boolean pIsSecurityEnabled) throws Exce assertTimesAtFinish(application); // finished without a proper unregister implies failed assertFinalAppStatus(FinalApplicationStatus.FAILED, application); - assertTrue(application - .getDiagnostics().indexOf(diagMsg) != -1, "Finished app missing diagnostics"); + assertTrue(application.getDiagnostics().indexOf(diagMsg) != -1, + "Finished app missing diagnostics"); verifyRMAppFieldsForFinalTransitions(application); } @@ -1359,13 +1359,13 @@ public void testRecoverApplication(ApplicationStateData appState, // Trigger RECOVER event. application.handle(recoverEvent); // Application final status looked from recoveredFinalStatus - assertTrue( - RMAppImpl.isAppInFinalState(application), "Application is not in recoveredFinalStatus."); + assertTrue(RMAppImpl.isAppInFinalState(application), + "Application is not in recoveredFinalStatus."); rmDispatcher.await(); RMAppState finalState = appState.getState(); - assertEquals(finalState -, application.getState(), "Application is not in finalState."); + assertEquals(finalState, application.getState(), + "Application is not in finalState."); verifyRMAppFieldsForFinalTransitions(application); } @@ -1392,9 +1392,8 @@ public void testGetAppReport(boolean pIsSecurityEnabled) throws Exception { isEqualTo(RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT); report = app.createAndGetApplicationReport("clientuser", true); assertNotNull(report.getApplicationResourceUsageReport()); - assertTrue( - report.getTrackingUrl().endsWith("/proxy/" + app.getApplicationId() - + "/"), "bad proxy url for app"); + assertTrue(report.getTrackingUrl().endsWith("/proxy/" + app.getApplicationId() + + "/"), "bad proxy url for app"); } private void verifyAppBeforeFinishEvent(RMApp app) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java index 02f5956ccd389..d740d7b777a9d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java @@ -1209,8 +1209,8 @@ public void testLaunchedExpire(boolean pIsSecurityEnabled) throws Exception { sendAttemptUpdateSavedEvent(applicationAttempt); assertEquals(RMAppAttemptState.FAILED, applicationAttempt.getAppAttemptState()); - assertTrue( - applicationAttempt.getDiagnostics().contains("timed out"), "expire diagnostics missing"); + assertTrue(applicationAttempt.getDiagnostics().contains("timed out"), + "expire diagnostics missing"); String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app", applicationAttempt.getAppAttemptId().getApplicationId()); assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl()); @@ -1310,8 +1310,8 @@ public void testRunningExpire(boolean pIsSecurityEnabled) throws Exception { sendAttemptUpdateSavedEvent(applicationAttempt); assertEquals(RMAppAttemptState.FAILED, applicationAttempt.getAppAttemptState()); - assertTrue( - applicationAttempt.getDiagnostics().contains("timed out"), "expire diagnostics missing"); + assertTrue(applicationAttempt.getDiagnostics().contains("timed out"), + "expire diagnostics missing"); String rmAppPageUrl = pjoin(RM_WEBAPP_ADDR, "cluster", "app", applicationAttempt.getAppAttemptId().getApplicationId()); assertEquals(rmAppPageUrl, applicationAttempt.getOriginalTrackingUrl()); @@ -1671,9 +1671,9 @@ public void testFinishedContainerNotBeingPulledByAMHeartbeat( // Verify the non-AM container is acked to NM via the RMNodeEvent assertEquals(container1.getId(), containerPulledEvents.get(1).getContainers().get(0)); - assertTrue( - applicationAttempt.getJustFinishedContainers().isEmpty(), "No container shall be added to justFinishedContainers" + - " as soon as AM container exits"); + assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty(), + "No container shall be added to justFinishedContainers" + + " as soon as AM container exits"); assertTrue( getFinishedContainersSentToAM(applicationAttempt).isEmpty()); } @@ -1726,11 +1726,10 @@ public void testFinishedContainerAfterAMExit(boolean pIsSecurityEnabled) throws Mockito.verify(rmnodeEventHandler, times(2)).handle(captor.capture()); assertEquals(container1.getId(), captor.getAllValues().get(1).getContainers().get(0)); - assertTrue( - applicationAttempt.getJustFinishedContainers().isEmpty(), "No container shall be added to justFinishedContainers" + - " after AM container exited"); - assertTrue( - getFinishedContainersSentToAM(applicationAttempt).isEmpty()); + assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty(), + "No container shall be added to justFinishedContainers" + + " after AM container exited"); + assertTrue(getFinishedContainersSentToAM(applicationAttempt).isEmpty()); } private static List getFinishedContainersSentToAM( @@ -2054,15 +2053,15 @@ public void testRunningToFailedUserTriggeredFailEvent(boolean pIsSecurityEnabled private void verifyAMCrashAtAllocatedDiagnosticInfo(String diagnostics, int exitCode, boolean shouldCheckURL) { - assertTrue( - diagnostics.contains("logs"), "Diagnostic information does not point the logs to the users"); - assertTrue( - diagnostics.contains(applicationAttempt.getAppAttemptId().toString()), "Diagnostic information does not contain application attempt id"); - assertTrue( - diagnostics.contains("exitCode: " + exitCode), "Diagnostic information does not contain application exit code"); + assertTrue(diagnostics.contains("logs"), + "Diagnostic information does not point the logs to the users"); + assertTrue(diagnostics.contains(applicationAttempt.getAppAttemptId().toString()), + "Diagnostic information does not contain application attempt id"); + assertTrue(diagnostics.contains("exitCode: " + exitCode), + "Diagnostic information does not contain application exit code"); if (shouldCheckURL) { - assertTrue( - diagnostics.contains(applicationAttempt.getTrackingUrl()), "Diagnostic information does not contain application proxy URL"); + assertTrue(diagnostics.contains(applicationAttempt.getTrackingUrl()), + "Diagnostic information does not contain application proxy URL"); } }