Skip to content

Commit 2fdd667

Browse files
Add more testcases
1 parent b2d027d commit 2fdd667

File tree

1 file changed

+84
-15
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

+84
-15
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: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,31 @@
1818

1919
import org.apache.hadoop.conf.Configuration;
2020
import org.apache.hadoop.security.authorize.AccessControlList;
21+
import org.apache.hadoop.util.Sets;
2122
import org.apache.hadoop.yarn.api.records.QueueACL;
2223
import org.junit.Test;
2324

25+
import java.util.Set;
26+
2427
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.ROOT;
2528
import static org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.getQueuePrefix;
29+
import static org.junit.Assert.assertEquals;
2630
import static org.junit.Assert.assertFalse;
2731
import static org.junit.Assert.assertTrue;
2832

2933
public class TestCapacitySchedulerConfiguration {
3034

35+
private static final String ROOT_TEST = ROOT + ".test";
36+
private static final String EMPTY_ACL = "";
37+
private static final String SPACE_ACL = " ";
38+
private static final String USER1 = "user1";
39+
private static final String USER2 = "user2";
40+
private static final String GROUP1 = "group1";
41+
private static final String GROUP2 = "group2";
42+
public static final String ONE_USER_ONE_GROUP_ACL = USER1 + " " + GROUP1;
43+
public static final String TWO_USERS_TWO_GROUPS_ACL =
44+
USER1 + "," + USER2 + " " + GROUP1 + ", " + GROUP2;
45+
3146
private CapacitySchedulerConfiguration createDefaultCsConf() {
3247
return new CapacitySchedulerConfiguration(new Configuration(false), false);
3348
}
@@ -44,10 +59,45 @@ private String getSubmitAppsConfigKey(String queue) {
4459
return getQueuePrefix(queue) + "acl_submit_applications";
4560
}
4661

62+
private void testWithGivenAclNoOneHasAccess(String queue, String aclValue) {
63+
testWithGivenAclNoOneHasAccessInternal(queue, queue, aclValue);
64+
}
65+
66+
private void testWithGivenAclNoOneHasAccess(String queueToSet, String queueToVerify, String aclValue) {
67+
testWithGivenAclNoOneHasAccessInternal(queueToSet, queueToVerify, aclValue);
68+
}
69+
70+
private void testWithGivenAclNoOneHasAccessInternal(String queueToSet, String queueToVerify, String aclValue) {
71+
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
72+
setSubmitAppsConfig(csConf, queueToSet, aclValue);
73+
AccessControlList acl = getSubmitAcl(csConf, queueToVerify);
74+
assertTrue(acl.getUsers().isEmpty());
75+
assertTrue(acl.getGroups().isEmpty());
76+
assertFalse(acl.isAllAllowed());
77+
}
78+
79+
private void testWithGivenAclCorrectUserAndGroupHasAccess(String queue, String aclValue,
80+
Set<String> expectedUsers, Set<String> expectedGroups) {
81+
testWithGivenAclCorrectUserAndGroupHasAccessInternal(queue, queue, aclValue, expectedUsers, expectedGroups);
82+
}
83+
84+
private void testWithGivenAclCorrectUserAndGroupHasAccessInternal(String queueToSet,
85+
String queueToVerify, String aclValue, Set<String> expectedUsers,
86+
Set<String> expectedGroups) {
87+
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
88+
setSubmitAppsConfig(csConf, queueToSet, aclValue);
89+
AccessControlList acl = getSubmitAcl(csConf, queueToVerify);
90+
assertFalse(acl.getUsers().isEmpty());
91+
assertFalse(acl.getGroups().isEmpty());
92+
assertEquals(expectedUsers, acl.getUsers());
93+
assertEquals(expectedGroups, acl.getGroups());
94+
assertFalse(acl.isAllAllowed());
95+
}
96+
4797
@Test
4898
public void testDefaultSubmitACLForRootAllAllowed() {
4999
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
50-
AccessControlList acl = csConf.getAcl(ROOT, QueueACL.SUBMIT_APPLICATIONS);
100+
AccessControlList acl = getSubmitAcl(csConf, ROOT);
51101
assertTrue(acl.getUsers().isEmpty());
52102
assertTrue(acl.getGroups().isEmpty());
53103
assertTrue(acl.isAllAllowed());
@@ -56,30 +106,49 @@ public void testDefaultSubmitACLForRootAllAllowed() {
56106
@Test
57107
public void testDefaultSubmitACLForRootChildNoneAllowed() {
58108
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
59-
AccessControlList acl = getSubmitAcl(csConf, ROOT + ".test");
109+
AccessControlList acl = getSubmitAcl(csConf, ROOT_TEST);
60110
assertTrue(acl.getUsers().isEmpty());
61111
assertTrue(acl.getGroups().isEmpty());
62112
assertFalse(acl.isAllAllowed());
63113
}
64114

65115
@Test
66116
public void testSpecifiedEmptySubmitACLForRoot() {
67-
CapacitySchedulerConfiguration csConf = createDefaultCsConf();
68-
setSubmitAppsConfig(csConf, ROOT, "");
69-
AccessControlList acl = csConf.getAcl(ROOT, QueueACL.SUBMIT_APPLICATIONS);
70-
assertTrue(acl.getUsers().isEmpty());
71-
assertTrue(acl.getGroups().isEmpty());
72-
assertFalse(acl.isAllAllowed());
117+
testWithGivenAclNoOneHasAccess(ROOT, EMPTY_ACL);
73118
}
74119

75120
@Test
76121
public void testSpecifiedEmptySubmitACLForRootIsNotInherited() {
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());
122+
testWithGivenAclNoOneHasAccess(ROOT, ROOT_TEST, EMPTY_ACL);
123+
}
124+
125+
@Test
126+
public void testSpecifiedSpaceSubmitACLForRoot() {
127+
testWithGivenAclNoOneHasAccess(ROOT, SPACE_ACL);
128+
}
129+
130+
@Test
131+
public void testSpecifiedSpaceSubmitACLForRootIsNotInherited() {
132+
testWithGivenAclNoOneHasAccess(ROOT, ROOT_TEST, SPACE_ACL);
83133
}
84-
134+
135+
@Test
136+
public void testSpecifiedSubmitACLForRoot() {
137+
Set<String> expectedUsers = Sets.newHashSet(USER1);
138+
Set<String> expectedGroups = Sets.newHashSet(GROUP1);
139+
testWithGivenAclCorrectUserAndGroupHasAccess(ROOT, ONE_USER_ONE_GROUP_ACL, expectedUsers, expectedGroups);
140+
}
141+
142+
@Test
143+
public void testSpecifiedSubmitACLForRootIsNotInherited() {
144+
testWithGivenAclNoOneHasAccess(ROOT, ROOT_TEST, ONE_USER_ONE_GROUP_ACL);
145+
}
146+
147+
@Test
148+
public void testSpecifiedSubmitACLTwoUsersTwoGroupsForRoot() {
149+
Set<String> expectedUsers = Sets.newHashSet(USER1, USER2);
150+
Set<String> expectedGroups = Sets.newHashSet(GROUP1, GROUP2);
151+
testWithGivenAclCorrectUserAndGroupHasAccess(ROOT, TWO_USERS_TWO_GROUPS_ACL, expectedUsers, expectedGroups);
152+
}
153+
85154
}

0 commit comments

Comments
 (0)