Skip to content

Commit 7038f26

Browse files
committed
YARN-11262. Fix Junit Test Error & CheckStyle Issue.
1 parent ce5ce6d commit 7038f26

File tree

44 files changed

+1290
-1111
lines changed

Some content is hidden

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

44 files changed

+1290
-1111
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

Lines changed: 2 additions & 2 deletions
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.jupiter.api.Assertions;
3433
import org.junit.jupiter.api.BeforeEach;
3534
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;
@@ -108,7 +108,7 @@ private void verifyQueueMapping(QueueMapping queueMapping,
108108
asc.setApplicationName(appName);
109109
ApplicationPlacementContext ctx = engine.getPlacementForApp(asc,
110110
user);
111-
Assertions.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

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,25 @@ public void testCleanName() {
5252
String cleaned = cleanName(clean);
5353
assertEquals(clean, cleaned, "Name was changed and it should not");
5454
cleaned = cleanName(dotted);
55-
assertFalse(
56-
cleaned.contains(DOT), "Cleaned name contains dots and it should not");
55+
assertFalse(cleaned.contains(DOT),
56+
"Cleaned name contains dots and it should not");
5757
cleaned = cleanName(multiDot);
58-
assertFalse(
59-
cleaned.contains(DOT), "Cleaned name contains dots and it should not");
60-
assertNotEquals(
61-
cleaned.indexOf(DOT_REPLACEMENT)
62-
, cleaned.lastIndexOf(DOT_REPLACEMENT), "Multi dot failed: wrong replacements found");
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(
65-
cleaned.contains(DOT), "Cleaned name contains dots and it should not");
66-
assertNotEquals(
67-
cleaned.indexOf(DOT_REPLACEMENT)
68-
, cleaned.lastIndexOf(DOT_REPLACEMENT), "Sequential dot failed: wrong replacements found");
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(
71-
cleaned.startsWith(DOT_REPLACEMENT), "Trimming start failed: space not removed or dot not replaced");
72-
assertTrue(
73-
cleaned.endsWith(DOT_REPLACEMENT), "Trimming end failed: space not removed or dot not replaced");
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(
86-
rooted.startsWith(ROOT_QUEUE + DOT), "Queue should have root prefix (base)");
85+
assertTrue(rooted.startsWith(ROOT_QUEUE + DOT),
86+
"Queue should have root prefix (base)");
8787
rooted = assureRoot(rootOnly);
88-
assertEquals(
89-
rootOnly, rooted, "'root' queue should not have root prefix (root)");
88+
assertEquals(rootOnly, rooted,
89+
"'root' queue should not have root prefix (root)");
9090
rooted = assureRoot(rootNoDot);
91-
assertTrue(
92-
rooted.startsWith(ROOT_QUEUE + DOT), "Queue should have root prefix (rootbase)");
93-
assertEquals(5
94-
, rooted.lastIndexOf(ROOT_QUEUE), "'root' queue base was replaced and not prefixed");
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(
97-
rooted, alreadyRoot, "Root prefixed queue changed and it should not (root.base)");
98-
assertNull(
99-
assureRoot(null), "Null queue did not return null queue");
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(
117-
isValidQueueName(null), "'null' queue was not marked as invalid");
115+
assertFalse(isValidQueueName(null), "'null' queue was not marked as invalid");
118116
assertTrue(isValidQueueName(""), "empty queue was not tagged valid");
119-
assertTrue(
120-
isValidQueueName(valid), "Simple queue name was not tagged valid (valid)");
121-
assertTrue(
122-
isValidQueueName(rootOnly), "Root only queue was not tagged valid (root)");
123-
assertTrue(
124-
isValidQueueName(validRooted), "Root prefixed queue was not tagged valid (root.valid)");
125-
assertFalse(
126-
isValidQueueName(startDot), "Queue starting with dot was not tagged invalid (.invalid)");
127-
assertFalse(
128-
isValidQueueName(endDot), "Queue ending with dot was not tagged invalid (invalid.)");
129-
assertFalse(
130-
isValidQueueName(startSpace), "Queue starting with space was not tagged invalid ( invalid)");
131-
assertFalse(
132-
isValidQueueName(endSpace), "Queue ending with space was not tagged invalid (invalid )");
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(
135-
isValidQueueName(unicodeSpace), "Queue with unicode space was not tagged as invalid (unicode)");
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.jupiter.api.Assertions.*;
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;
2427

2528
/**
2629
* Test for the {@link PlacementFactory}.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
3030
import org.apache.hadoop.yarn.util.Records;
3131
import org.junit.jupiter.api.AfterEach;
32-
import org.junit.jupiter.api.Assertions;
3332
import org.junit.jupiter.api.BeforeEach;
3433
import org.junit.jupiter.api.Test;
3534

@@ -38,6 +37,9 @@
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

@@ -96,8 +98,7 @@ public void testPlaceApplicationWithPlacementRuleChain() throws Exception {
9698
asc.setQueue(YarnConfiguration.DEFAULT_QUEUE_NAME);
9799
asc.setApplicationName(APP_NAME);
98100

99-
Assertions.assertNull(
100-
pm.placeApplication(asc, USER2), "Placement should be null");
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-
Assertions.assertNotNull(pc);
116+
assertNotNull(pc);
116117
}
117118

118119
@Test
@@ -135,9 +136,9 @@ 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-
Assertions.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-
Assertions.assertEquals(ugRule.getName(),
141+
assertEquals(ugRule.getName(),
141142
pm.getPlacementRules().get(0).getName());
142143
}
143144

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ private void ruleInit(Class <? extends PlacementRule> ruleClass) {
183183
} catch (IOException ioe) {
184184
exceptionThrown = true;
185185
}
186-
assertTrue(exceptionThrown, "Initialize with parent rule should have thrown exception " +
187-
name);
186+
assertTrue(exceptionThrown,
187+
"Initialize with parent rule should have thrown exception " + name);
188188
}
189189

190190
private Element createConf(String str) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

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

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
2122
import static org.mockito.Mockito.mock;
2223
import static org.mockito.Mockito.when;
2324
import static org.mockito.Mockito.isNull;
@@ -42,7 +43,6 @@
4243
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.PrimaryGroupMapping;
4344
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.SimpleGroupsMapping;
4445
import org.apache.hadoop.yarn.util.Records;
45-
import org.junit.jupiter.api.Assertions;
4646
import org.junit.jupiter.api.BeforeEach;
4747
import org.junit.jupiter.api.Test;
4848

@@ -94,11 +94,11 @@ private void verifyQueueMapping(QueueMappingTestData queueMappingTestData)
9494
ApplicationSubmissionContext.class);
9595
asc.setQueue(inputQueue);
9696
ApplicationPlacementContext ctx = engine.getPlacementForApp(asc, inputUser);
97-
Assertions.assertEquals(expectedQueue
98-
, ctx != null ? ctx.getQueue() : inputQueue, "Queue");
97+
assertEquals(expectedQueue,
98+
ctx != null ? ctx.getQueue() : inputQueue, "Queue");
9999
if (ctx != null && expectedParentQueue != null) {
100-
Assertions.assertEquals(expectedParentQueue
101-
, ctx.getParentQueue(), "Parent Queue");
100+
assertEquals(expectedParentQueue,
101+
ctx.getParentQueue(), "Parent Queue");
102102
}
103103
}
104104

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,28 @@
3333
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
3434
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager;
3535
import org.apache.hadoop.yarn.util.Records;
36-
import org.junit.Rule;
3736
import org.junit.jupiter.api.Test;
38-
import org.junit.rules.TemporaryFolder;
37+
import org.junit.jupiter.api.io.TempDir;
3938
import org.slf4j.Logger;
4039
import org.slf4j.LoggerFactory;
4140

4241
import java.io.BufferedWriter;
4342
import java.io.File;
4443
import java.io.FileWriter;
4544
import java.io.IOException;
45+
import java.nio.file.Path;
4646
import java.util.ArrayList;
4747
import java.util.List;
4848
import java.util.Map;
4949
import java.util.Set;
5050

5151
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_GROUP_MAPPING;
52-
import static org.junit.jupiter.api.Assertions.*;
52+
import static org.junit.jupiter.api.Assertions.assertEquals;
53+
import static org.junit.jupiter.api.Assertions.assertNotNull;
54+
import static org.junit.jupiter.api.Assertions.assertNull;
55+
import static org.junit.jupiter.api.Assertions.assertThrows;
56+
import static org.junit.jupiter.api.Assertions.assertTrue;
57+
import static org.junit.jupiter.api.Assertions.fail;
5358
import static org.mockito.ArgumentMatchers.isNull;
5459
import static org.mockito.Mockito.mock;
5560
import static org.mockito.Mockito.when;
@@ -59,8 +64,8 @@ public class TestCSMappingPlacementRule {
5964
private static final Logger LOG = LoggerFactory
6065
.getLogger(TestCSMappingPlacementRule.class);
6166

62-
@Rule
63-
public TemporaryFolder folder = new TemporaryFolder();
67+
@TempDir
68+
static Path folder;
6469

6570
private Map<String, Set<String>> userGroups =
6671
ImmutableMap.<String, Set<String>>builder()
@@ -185,7 +190,7 @@ private void assertPlace(String message, CSMappingPlacementRule engine,
185190
String queue = apc.getParentQueue() == null ? "" :
186191
(apc.getParentQueue() + DOT);
187192
queue += apc.getQueue();
188-
assertEquals(message, expectedQueue, queue);
193+
assertEquals(expectedQueue, queue, message);
189194
} catch (YarnException e) {
190195
LOG.error(message, e);
191196
fail(message);
@@ -706,7 +711,7 @@ public void testJSONFileConfiguration() throws IOException {
706711
conf.set(CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT,
707712
CapacitySchedulerConfiguration.MAPPING_RULE_FORMAT_JSON);
708713

709-
File jsonFile = folder.newFile("testJSONFileConfiguration.json");
714+
File jsonFile = folder.resolve("testJSONFileConfiguration.json").toFile();
710715

711716
BufferedWriter writer = new BufferedWriter(new FileWriter(jsonFile));
712717
try {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import org.apache.hadoop.yarn.server.resourcemanager.placement.VariableContext;
2121
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.jupiter.api.Assertions.*;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertSame;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.fail;
2427

2528
public class TestMappingRuleActions {
2629
void assertRejectResult(MappingRuleResult result) {

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

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public void testVariableMatcher() {
6666
new MappingRuleMatchers.VariableMatcher("%custom", "Matching string"));
6767

6868
matchers.forEach((matcherName, matcher) -> {
69-
assertTrue(
70-
matcher.match(matchingContext), matcherName + " with matchingContext should match");
71-
assertFalse(
72-
matcher.match(mismatchingContext), matcherName + " with mismatchingContext shouldn't match");
73-
assertFalse(
74-
matcher.match(emptyContext), matcherName + " with emptyContext shouldn't match");
69+
assertTrue(matcher.match(matchingContext),
70+
matcherName + " with matchingContext should match");
71+
assertFalse(matcher.match(mismatchingContext),
72+
matcherName + " with mismatchingContext shouldn't match");
73+
assertFalse(matcher.match(emptyContext),
74+
matcherName + " with emptyContext shouldn't match");
7575
});
7676
}
7777

@@ -108,31 +108,27 @@ public void testVariableMatcherSubstitutions() {
108108
MappingRuleMatcher userStatic =
109109
new MappingRuleMatchers.VariableMatcher("%user", "bob");
110110

111-
assertTrue(
112-
customUser.match(matchingContext), "%custom should match %user in matching context");
113-
assertTrue(
114-
userCustom.match(matchingContext), "%user should match %custom in matching context");
115-
assertTrue(
116-
userCusTom.match(matchingContext), "%user (bob) should match %cus%tom (b + ob) in matching context");
117-
assertTrue(
118-
userUser.match(matchingContext), "%user should match %user in any context");
119-
assertTrue(
120-
userStatic.match(matchingContext), "%user (bob) should match bob in in matching context");
121-
122-
assertFalse(
123-
124-
customUser.match(mismatchingContext), "%custom (bob) should NOT match %user (dave) in mismatching context");
125-
assertFalse(
126-
127-
userCustom.match(mismatchingContext), "%user (dave) should NOT match %custom (bob) in mismatching context");
128-
assertFalse(
129-
130-
userCusTom.match(mismatchingContext), "%user (dave) should NOT match %cus%tom (b+ob) in mismatching context");
131-
assertTrue(
132-
userUser.match(mismatchingContext), "%user should match %user in any context");
133-
assertFalse(
134-
135-
userStatic.match(mismatchingContext), "%user (dave) should NOT match match bob in in matching context");
111+
assertTrue(customUser.match(matchingContext),
112+
"%custom should match %user in matching context");
113+
assertTrue(userCustom.match(matchingContext),
114+
"%user should match %custom in matching context");
115+
assertTrue(userCusTom.match(matchingContext),
116+
"%user (bob) should match %cus%tom (b + ob) in matching context");
117+
assertTrue(userUser.match(matchingContext),
118+
"%user should match %user in any context");
119+
assertTrue(userStatic.match(matchingContext),
120+
"%user (bob) should match bob in in matching context");
121+
122+
assertFalse(customUser.match(mismatchingContext),
123+
"%custom (bob) should NOT match %user (dave) in mismatching context");
124+
assertFalse(userCustom.match(mismatchingContext),
125+
"%user (dave) should NOT match %custom (bob) in mismatching context");
126+
assertFalse(userCusTom.match(mismatchingContext),
127+
"%user (dave) should NOT match %cus%tom (b+ob) in mismatching context");
128+
assertTrue(userUser.match(mismatchingContext),
129+
"%user should match %user in any context");
130+
assertFalse(userStatic.match(mismatchingContext),
131+
"%user (dave) should NOT match match bob in in matching context");
136132
}
137133

138134
@Test

0 commit comments

Comments
 (0)