Skip to content

Commit baf393d

Browse files
slfan1989cnaurothzhtttylz
authored
YARN-11262. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-yarn-server-resourcemanager Part2. (apache#7484)
Co-authored-by: Chris Nauroth <[email protected]> Co-authored-by: Hualong Zhang <[email protected]> Reviewed-by: Chris Nauroth <[email protected]> Reviewed-by: Hualong Zhang <[email protected]> Signed-off-by: Shilun Fan <[email protected]>
1 parent 7d143b7 commit baf393d

File tree

53 files changed

+2205
-1879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2205
-1879
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestAppNameMappingPlacementRule.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager;
3131
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping;
3232
import org.apache.hadoop.yarn.util.Records;
33-
import org.junit.Assert;
34-
import org.junit.Before;
35-
import org.junit.Test;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
3635

3736
import java.io.IOException;
3837
import java.util.Collections;
3938

4039
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT;
40+
import static org.junit.jupiter.api.Assertions.assertEquals;
4141
import static org.mockito.ArgumentMatchers.isNull;
4242
import static org.mockito.Mockito.mock;
4343
import static org.mockito.Mockito.when;
@@ -55,7 +55,7 @@ public class TestAppNameMappingPlacementRule {
5555

5656
private YarnConfiguration conf = new YarnConfiguration();
5757

58-
@Before
58+
@BeforeEach
5959
public void setup() {
6060
conf.setClass(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
6161
SimpleGroupsMapping.class, GroupMappingServiceProvider.class);
@@ -108,7 +108,7 @@ private void verifyQueueMapping(QueueMapping queueMapping,
108108
asc.setApplicationName(appName);
109109
ApplicationPlacementContext ctx = engine.getPlacementForApp(asc,
110110
user);
111-
Assert.assertEquals(expectedQueue,
111+
assertEquals(expectedQueue,
112112
ctx != null ? ctx.getQueue() : inputQueue);
113113
}
114114

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestFairQueuePlacementUtils.java

+54-56
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818

1919
package org.apache.hadoop.yarn.server.resourcemanager.placement;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT;
2424
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.DOT_REPLACEMENT;
2525
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.ROOT_QUEUE;
2626
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.assureRoot;
2727
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.cleanName;
2828
import static org.apache.hadoop.yarn.server.resourcemanager.placement.FairQueuePlacementUtils.isValidQueueName;
29-
import static org.junit.Assert.assertEquals;
30-
import static org.junit.Assert.assertFalse;
31-
import static org.junit.Assert.assertNotEquals;
32-
import static org.junit.Assert.assertNull;
33-
import static org.junit.Assert.assertTrue;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertFalse;
31+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
32+
import static org.junit.jupiter.api.Assertions.assertNull;
33+
import static org.junit.jupiter.api.Assertions.assertTrue;
3434

3535
/**
3636
* Tests of the utility methods from {@link FairQueuePlacementUtils}.
@@ -50,27 +50,27 @@ public void testCleanName() {
5050
final String unTrimmed = " .invalid. "; // not really a valid queue
5151

5252
String cleaned = cleanName(clean);
53-
assertEquals("Name was changed and it should not", clean, cleaned);
53+
assertEquals(clean, cleaned, "Name was changed and it should not");
5454
cleaned = cleanName(dotted);
55-
assertFalse("Cleaned name contains dots and it should not",
56-
cleaned.contains(DOT));
55+
assertFalse(cleaned.contains(DOT),
56+
"Cleaned name contains dots and it should not");
5757
cleaned = cleanName(multiDot);
58-
assertFalse("Cleaned name contains dots and it should not",
59-
cleaned.contains(DOT));
60-
assertNotEquals("Multi dot failed: wrong replacements found",
61-
cleaned.indexOf(DOT_REPLACEMENT),
62-
cleaned.lastIndexOf(DOT_REPLACEMENT));
58+
assertFalse(cleaned.contains(DOT),
59+
"Cleaned name contains dots and it should not");
60+
assertNotEquals(cleaned.indexOf(DOT_REPLACEMENT),
61+
cleaned.lastIndexOf(DOT_REPLACEMENT),
62+
"Multi dot failed: wrong replacements found");
6363
cleaned = cleanName(seqDot);
64-
assertFalse("Cleaned name contains dots and it should not",
65-
cleaned.contains(DOT));
66-
assertNotEquals("Sequential dot failed: wrong replacements found",
67-
cleaned.indexOf(DOT_REPLACEMENT),
68-
cleaned.lastIndexOf(DOT_REPLACEMENT));
64+
assertFalse(cleaned.contains(DOT),
65+
"Cleaned name contains dots and it should not");
66+
assertNotEquals(cleaned.indexOf(DOT_REPLACEMENT),
67+
cleaned.lastIndexOf(DOT_REPLACEMENT),
68+
"Sequential dot failed: wrong replacements found");
6969
cleaned = cleanName(unTrimmed);
70-
assertTrue("Trimming start failed: space not removed or dot not replaced",
71-
cleaned.startsWith(DOT_REPLACEMENT));
72-
assertTrue("Trimming end failed: space not removed or dot not replaced",
73-
cleaned.endsWith(DOT_REPLACEMENT));
70+
assertTrue(cleaned.startsWith(DOT_REPLACEMENT),
71+
"Trimming start failed: space not removed or dot not replaced");
72+
assertTrue(cleaned.endsWith(DOT_REPLACEMENT),
73+
"Trimming end failed: space not removed or dot not replaced");
7474
}
7575

7676
@Test
@@ -82,23 +82,22 @@ public void testAssureRoot() {
8282
final String alreadyRoot = "root.base";
8383

8484
String rooted = assureRoot(queueName);
85-
assertTrue("Queue should have root prefix (base)",
86-
rooted.startsWith(ROOT_QUEUE + DOT));
85+
assertTrue(rooted.startsWith(ROOT_QUEUE + DOT),
86+
"Queue should have root prefix (base)");
8787
rooted = assureRoot(rootOnly);
88-
assertEquals("'root' queue should not have root prefix (root)",
89-
rootOnly, rooted);
88+
assertEquals(rootOnly, rooted,
89+
"'root' queue should not have root prefix (root)");
9090
rooted = assureRoot(rootNoDot);
91-
assertTrue("Queue should have root prefix (rootbase)",
92-
rooted.startsWith(ROOT_QUEUE + DOT));
93-
assertEquals("'root' queue base was replaced and not prefixed", 5,
94-
rooted.lastIndexOf(ROOT_QUEUE));
91+
assertTrue(rooted.startsWith(ROOT_QUEUE + DOT),
92+
"Queue should have root prefix (rootbase)");
93+
assertEquals(5, rooted.lastIndexOf(ROOT_QUEUE),
94+
"'root' queue base was replaced and not prefixed");
9595
rooted = assureRoot(alreadyRoot);
96-
assertEquals("Root prefixed queue changed and it should not (root.base)",
97-
rooted, alreadyRoot);
98-
assertNull("Null queue did not return null queue",
99-
assureRoot(null));
100-
assertEquals("Empty queue did not return empty name", "",
101-
assureRoot(""));
96+
assertEquals(rooted, alreadyRoot,
97+
"Root prefixed queue changed and it should not (root.base)");
98+
assertNull(assureRoot(null), "Null queue did not return null queue");
99+
assertEquals("", assureRoot(""),
100+
"Empty queue did not return empty name");
102101
}
103102

104103
@Test
@@ -113,25 +112,24 @@ public void testIsValidQueueName() {
113112
final String endSpace = "invalid ";
114113
final String unicodeSpace = "\u00A0invalid";
115114

116-
assertFalse("'null' queue was not marked as invalid",
117-
isValidQueueName(null));
118-
assertTrue("empty queue was not tagged valid", isValidQueueName(""));
119-
assertTrue("Simple queue name was not tagged valid (valid)",
120-
isValidQueueName(valid));
121-
assertTrue("Root only queue was not tagged valid (root)",
122-
isValidQueueName(rootOnly));
123-
assertTrue("Root prefixed queue was not tagged valid (root.valid)",
124-
isValidQueueName(validRooted));
125-
assertFalse("Queue starting with dot was not tagged invalid (.invalid)",
126-
isValidQueueName(startDot));
127-
assertFalse("Queue ending with dot was not tagged invalid (invalid.)",
128-
isValidQueueName(endDot));
129-
assertFalse("Queue starting with space was not tagged invalid ( invalid)",
130-
isValidQueueName(startSpace));
131-
assertFalse("Queue ending with space was not tagged invalid (invalid )",
132-
isValidQueueName(endSpace));
115+
assertFalse(isValidQueueName(null), "'null' queue was not marked as invalid");
116+
assertTrue(isValidQueueName(""), "empty queue was not tagged valid");
117+
assertTrue(isValidQueueName(valid),
118+
"Simple queue name was not tagged valid (valid)");
119+
assertTrue(isValidQueueName(rootOnly),
120+
"Root only queue was not tagged valid (root)");
121+
assertTrue(isValidQueueName(validRooted),
122+
"Root prefixed queue was not tagged valid (root.valid)");
123+
assertFalse(isValidQueueName(startDot),
124+
"Queue starting with dot was not tagged invalid (.invalid)");
125+
assertFalse(isValidQueueName(endDot),
126+
"Queue ending with dot was not tagged invalid (invalid.)");
127+
assertFalse(isValidQueueName(startSpace),
128+
"Queue starting with space was not tagged invalid ( invalid)");
129+
assertFalse(isValidQueueName(endSpace),
130+
"Queue ending with space was not tagged invalid (invalid )");
133131
// just one for sanity check extensive tests are in the scheduler utils
134-
assertFalse("Queue with unicode space was not tagged as invalid (unicode)",
135-
isValidQueueName(unicodeSpace));
132+
assertFalse(isValidQueueName(unicodeSpace),
133+
"Queue with unicode space was not tagged as invalid (unicode)");
136134
}
137135
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementFactory.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818

1919
package org.apache.hadoop.yarn.server.resourcemanager.placement;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertNotNull;
25-
import static org.junit.Assert.fail;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertNotNull;
25+
import static org.junit.jupiter.api.Assertions.assertThrows;
26+
import static org.junit.jupiter.api.Assertions.fail;
2627

2728
/**
2829
* Test for the {@link PlacementFactory}.
@@ -34,10 +35,12 @@ public class TestPlacementFactory {
3435
*
3536
* @throws ClassNotFoundException
3637
*/
37-
@Test(expected = ClassNotFoundException.class)
38+
@Test
3839
public void testGetNonExistRuleText() throws ClassNotFoundException {
39-
final String nonExist = "my.placement.Rule";
40-
PlacementFactory.getPlacementRule(nonExist, null);
40+
assertThrows(ClassNotFoundException.class, ()->{
41+
final String nonExist = "my.placement.Rule";
42+
PlacementFactory.getPlacementRule(nonExist, null);
43+
});
4144
}
4245

4346
/**
@@ -53,8 +56,8 @@ public void testGetExistRuleText() {
5356
} catch (ClassNotFoundException cnfe) {
5457
fail("Class should have been found");
5558
}
56-
assertNotNull("Rule object is null", rule);
57-
assertEquals("Names not equal", rule.getName(), exists);
59+
assertNotNull(rule, "Rule object is null");
60+
assertEquals(rule.getName(), exists, "Names not equal");
5861
}
5962

6063
/**
@@ -65,11 +68,11 @@ public void testGetExistRuleText() {
6568
public void testGetRuleClass() {
6669
PlacementRule rule = PlacementFactory.getPlacementRule(
6770
DefaultPlacementRule.class, null);
68-
assertNotNull("Rule object is null", rule);
71+
assertNotNull(rule, "Rule object is null");
6972
// Should take anything as the second object: ignores unknown types in the
7073
// default implementation.
7174
rule = PlacementFactory.getPlacementRule(
7275
DefaultPlacementRule.class, "");
73-
assertNotNull("Rule object is null", rule);
76+
assertNotNull(rule, "Rule object is null");
7477
}
7578
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/placement/TestPlacementManager.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@
2828
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
2929
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
3030
import org.apache.hadoop.yarn.util.Records;
31-
import org.junit.After;
32-
import org.junit.Assert;
33-
import org.junit.Before;
34-
import org.junit.Test;
31+
import org.junit.jupiter.api.AfterEach;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
3534

3635
import java.util.ArrayList;
3736
import java.util.List;
3837

3938
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
4039
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.TestCapacitySchedulerAutoCreatedQueueBase.setupQueueConfiguration;
40+
import static org.junit.jupiter.api.Assertions.assertEquals;
41+
import static org.junit.jupiter.api.Assertions.assertNotNull;
42+
import static org.junit.jupiter.api.Assertions.assertNull;
4143

4244
public class TestPlacementManager {
4345

@@ -56,7 +58,7 @@ private String getQueueMapping(String parentQueue, String leafQueue) {
5658
return parentQueue + DOT + leafQueue;
5759
}
5860

59-
@Before
61+
@BeforeEach
6062
public void setup() {
6163
conf = new CapacitySchedulerConfiguration();
6264
setupQueueConfiguration(conf);
@@ -96,8 +98,7 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception {
9698
asc.setQueue(YarnConfiguration.DEFAULT_QUEUE_NAME);
9799
asc.setApplicationName(APP_NAME);
98100

99-
Assert.assertNull("Placement should be null",
100-
pm.placeApplication(asc, USER2));
101+
assertNull(pm.placeApplication(asc, USER2), "Placement should be null");
101102
QueueMapping queueMappingEntity = QueueMapping.QueueMappingBuilder.create()
102103
.type(MappingType.APPLICATION)
103104
.source(APP_NAME)
@@ -112,7 +113,7 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception {
112113
queuePlacementRules.add(anRule);
113114
pm.updateRules(queuePlacementRules);
114115
ApplicationPlacementContext pc = pm.placeApplication(asc, USER2);
115-
Assert.assertNotNull(pc);
116+
assertNotNull(pc);
116117
}
117118

118119
@Test
@@ -135,13 +136,13 @@ public void testPlacementRuleUpdationOrder() throws Exception {
135136

136137
// As we are setting placement rule, It shouldn't update default
137138
// placement rule ie user-group. Number of placement rules should be 1.
138-
Assert.assertEquals(1, pm.getPlacementRules().size());
139+
assertEquals(1, pm.getPlacementRules().size());
139140
// Verifying if placement rule set is same as the one we configured
140-
Assert.assertEquals(ugRule.getName(),
141+
assertEquals(ugRule.getName(),
141142
pm.getPlacementRules().get(0).getName());
142143
}
143144

144-
@After
145+
@AfterEach
145146
public void tearDown() {
146147
if (null != mockRM) {
147148
mockRM.stop();

0 commit comments

Comments
 (0)