Skip to content

Commit b2d027d

Browse files
Minor refactor
1 parent eb0d359 commit b2d027d

File tree

1 file changed

+39
-28
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity

1 file changed

+39
-28
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerConfiguration.java

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,68 @@
1818

1919
import org.apache.hadoop.conf.Configuration;
2020
import org.apache.hadoop.security.authorize.AccessControlList;
21-
import org.apache.hadoop.util.StringUtils;
2221
import org.apache.hadoop.yarn.api.records.QueueACL;
23-
import org.junit.Assert;
2422
import org.junit.Test;
2523

2624
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.ROOT;
2725
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.getQueuePrefix;
26+
import static org.junit.Assert.assertFalse;
27+
import static org.junit.Assert.assertTrue;
2828

2929
public class TestCapacitySchedulerConfiguration {
3030

31+
private CapacitySchedulerConfiguration createDefaultCsConf() {
32+
return new CapacitySchedulerConfiguration(new Configuration(false), false);
33+
}
34+
35+
private AccessControlList getSubmitAcl(CapacitySchedulerConfiguration csConf, String queue) {
36+
return csConf.getAcl(queue, QueueACL.SUBMIT_APPLICATIONS);
37+
}
38+
39+
private void setSubmitAppsConfig(CapacitySchedulerConfiguration csConf, String queue, String value) {
40+
csConf.set(getSubmitAppsConfigKey(queue), value);
41+
}
42+
43+
private String getSubmitAppsConfigKey(String queue) {
44+
return getQueuePrefix(queue) + "acl_submit_applications";
45+
}
46+
3147
@Test
3248
public void testDefaultSubmitACLForRootAllAllowed() {
33-
CapacitySchedulerConfiguration csConf =
34-
new CapacitySchedulerConfiguration(new Configuration(false), false);
49+
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
3550
AccessControlList acl = csConf.getAcl(ROOT, QueueACL.SUBMIT_APPLICATIONS);
36-
Assert.assertTrue(acl.getUsers().isEmpty());
37-
Assert.assertTrue(acl.getGroups().isEmpty());
38-
Assert.assertTrue(acl.isAllAllowed());
51+
assertTrue(acl.getUsers().isEmpty());
52+
assertTrue(acl.getGroups().isEmpty());
53+
assertTrue(acl.isAllAllowed());
3954
}
4055

4156
@Test
4257
public void testDefaultSubmitACLForRootChildNoneAllowed() {
43-
CapacitySchedulerConfiguration csConf =
44-
new CapacitySchedulerConfiguration(new Configuration(false), false);
45-
AccessControlList acl = csConf.getAcl(ROOT + ".test", QueueACL.SUBMIT_APPLICATIONS);
46-
Assert.assertTrue(acl.getUsers().isEmpty());
47-
Assert.assertTrue(acl.getGroups().isEmpty());
48-
Assert.assertFalse(acl.isAllAllowed());
58+
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
59+
AccessControlList acl = getSubmitAcl(csConf, ROOT + ".test");
60+
assertTrue(acl.getUsers().isEmpty());
61+
assertTrue(acl.getGroups().isEmpty());
62+
assertFalse(acl.isAllAllowed());
4963
}
5064

5165
@Test
5266
public void testSpecifiedEmptySubmitACLForRoot() {
53-
CapacitySchedulerConfiguration csConf =
54-
new CapacitySchedulerConfiguration(new Configuration(false), false);
55-
String configKey = getQueuePrefix(ROOT) + "acl_submit_applications";
56-
csConf.set(configKey, "");
67+
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
68+
setSubmitAppsConfig(csConf, ROOT, "");
5769
AccessControlList acl = csConf.getAcl(ROOT, QueueACL.SUBMIT_APPLICATIONS);
58-
Assert.assertTrue(acl.getUsers().isEmpty());
59-
Assert.assertTrue(acl.getGroups().isEmpty());
60-
Assert.assertFalse(acl.isAllAllowed());
70+
assertTrue(acl.getUsers().isEmpty());
71+
assertTrue(acl.getGroups().isEmpty());
72+
assertFalse(acl.isAllAllowed());
6173
}
6274

6375
@Test
6476
public void testSpecifiedEmptySubmitACLForRootIsNotInherited() {
65-
CapacitySchedulerConfiguration csConf =
66-
new CapacitySchedulerConfiguration(new Configuration(false), false);
67-
String configKey = getQueuePrefix(ROOT) + "acl_submit_applications";
68-
csConf.set(configKey, "");
69-
AccessControlList acl = csConf.getAcl(ROOT + ".test", QueueACL.SUBMIT_APPLICATIONS);
70-
Assert.assertTrue(acl.getUsers().isEmpty());
71-
Assert.assertTrue(acl.getGroups().isEmpty());
72-
Assert.assertFalse(acl.isAllAllowed());
77+
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
78+
setSubmitAppsConfig(csConf, ROOT, "");
79+
AccessControlList acl = getSubmitAcl(csConf, ROOT + ".test");
80+
assertTrue(acl.getUsers().isEmpty());
81+
assertTrue(acl.getGroups().isEmpty());
82+
assertFalse(acl.isAllAllowed());
7383
}
84+
7485
}

0 commit comments

Comments
 (0)