Skip to content

Commit 6f94b5a

Browse files
committed
make unit test more robust
1 parent 28b9dd3 commit 6f94b5a

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

yarn/common/src/test/scala/org/apache/spark/deploy/yarn/YarnSparkHadoopUtilSuite.scala

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,6 @@ class YarnSparkHadoopUtilSuite extends FunSuite with Matchers with Logging {
7878
}
7979

8080

81-
test("test getApplicationAclsForYarn default off") {
82-
83-
// default spark acls are off but view acls still default to current user
84-
val sparkConf = new SparkConf()
85-
val securityMgr = new SecurityManager(sparkConf)
86-
val acls = YarnSparkHadoopUtil.getApplicationAclsForYarn(securityMgr)
87-
88-
assert(acls.getOrElse(ApplicationAccessType.VIEW_APP, "invalid") ===
89-
System.getProperty("user.name", ""))
90-
assert(acls.getOrElse(ApplicationAccessType.MODIFY_APP, "invalid") ===
91-
System.getProperty("user.name", "") )
92-
}
93-
9481
test("test getApplicationAclsForYarn acls on") {
9582

9683
// spark acls on, just pick up default user
@@ -100,10 +87,27 @@ class YarnSparkHadoopUtilSuite extends FunSuite with Matchers with Logging {
10087
val securityMgr = new SecurityManager(sparkConf)
10188
val acls = YarnSparkHadoopUtil.getApplicationAclsForYarn(securityMgr)
10289

103-
assert(acls.getOrElse(ApplicationAccessType.VIEW_APP, "invalid") ===
104-
System.getProperty("user.name", ""))
105-
assert(acls.getOrElse(ApplicationAccessType.MODIFY_APP, "invalid") ===
106-
System.getProperty("user.name", "") )
90+
val viewAcls = acls.get(ApplicationAccessType.VIEW_APP)
91+
val modifyAcls = acls.get(ApplicationAccessType.MODIFY_APP)
92+
93+
viewAcls match {
94+
case Some(vacls) => {
95+
val aclSet = vacls.split(',').map(_.trim).toSet
96+
assert(aclSet.contains(System.getProperty("user.name", "invalid")))
97+
}
98+
case None => {
99+
fail()
100+
}
101+
}
102+
modifyAcls match {
103+
case Some(macls) => {
104+
val aclSet = macls.split(',').map(_.trim).toSet
105+
assert(aclSet.contains(System.getProperty("user.name", "invalid")))
106+
}
107+
case None => {
108+
fail()
109+
}
110+
}
107111
}
108112

109113
test("test getApplicationAclsForYarn acls on and specify users") {
@@ -125,7 +129,7 @@ class YarnSparkHadoopUtilSuite extends FunSuite with Matchers with Logging {
125129
val aclSet = vacls.split(',').map(_.trim).toSet
126130
assert(aclSet.contains("user1"))
127131
assert(aclSet.contains("user2"))
128-
assert(aclSet.contains(System.getProperty("user.name", "")))
132+
assert(aclSet.contains(System.getProperty("user.name", "invalid")))
129133
}
130134
case None => {
131135
fail()
@@ -136,7 +140,7 @@ class YarnSparkHadoopUtilSuite extends FunSuite with Matchers with Logging {
136140
val aclSet = macls.split(',').map(_.trim).toSet
137141
assert(aclSet.contains("user3"))
138142
assert(aclSet.contains("user4"))
139-
assert(aclSet.contains(System.getProperty("user.name", "")))
143+
assert(aclSet.contains(System.getProperty("user.name", "invalid")))
140144
}
141145
case None => {
142146
fail()

0 commit comments

Comments
 (0)