gaborgsomogyi commented on a change in pull request #24305: [SPARK-27294][SS]
Add multi-cluster Kafka delegation token
URL: https://github.com/apache/spark/pull/24305#discussion_r279317267
##########
File path:
external/kafka-0-10-token-provider/src/test/scala/org/apache/spark/kafka010/KafkaTokenUtilSuite.scala
##########
@@ -202,24 +177,74 @@ class KafkaTokenUtilSuite extends SparkFunSuite with
KafkaDelegationTokenTest {
assert(KafkaTokenUtil.isGlobalJaasConfigurationProvided)
}
- test("isTokenAvailable without token should return false") {
- assert(!KafkaTokenUtil.isTokenAvailable())
+ test("findMatchingToken without token should return None") {
+ assert(KafkaTokenUtil.findMatchingToken(sparkConf, bootStrapServers) ===
None)
+ }
+
+ test("findMatchingToken with non-matching tokens should return None") {
+ sparkConf.set(s"spark.kafka.clusters.$identifier1.bootstrap.servers",
bootStrapServers)
+
sparkConf.set(s"spark.kafka.clusters.$identifier1.target.bootstrap.servers.regex",
+ nonMatchingTargetServersRegex)
+ sparkConf.set(s"spark.kafka.clusters.$identifier2.bootstrap.servers",
bootStrapServers)
+
sparkConf.set(s"spark.kafka.clusters.$identifier2.target.bootstrap.servers.regex",
+ matchingTargetServersRegex)
+ addTokenToUGI(identifier1)
+ addTokenToUGI(identifier2, Some("intentionally_garbage"))
+
+ assert(KafkaTokenUtil.findMatchingToken(sparkConf, bootStrapServers) ===
None)
}
- test("isTokenAvailable with token should return true") {
- addTokenToUGI()
+ test("findMatchingToken with one matching token should return cluster
configuration") {
+ sparkConf.set(s"spark.kafka.clusters.$identifier1.bootstrap.servers",
bootStrapServers)
+
sparkConf.set(s"spark.kafka.clusters.$identifier1.target.bootstrap.servers.regex",
+ matchingTargetServersRegex)
+ addTokenToUGI(identifier1)
- assert(KafkaTokenUtil.isTokenAvailable())
+ assert(KafkaTokenUtil.findMatchingToken(sparkConf, bootStrapServers) ===
+ Some(KafkaTokenSparkConf.getClusterConfig(sparkConf, identifier1)))
+ }
+
+ test("findMatchingToken with multiple matching tokens should throw
exception") {
+ sparkConf.set(s"spark.kafka.clusters.$identifier1.bootstrap.servers",
bootStrapServers)
+
sparkConf.set(s"spark.kafka.clusters.$identifier1.target.bootstrap.servers.regex",
+ matchingTargetServersRegex)
+ sparkConf.set(s"spark.kafka.clusters.$identifier2.bootstrap.servers",
bootStrapServers)
+
sparkConf.set(s"spark.kafka.clusters.$identifier2.target.bootstrap.servers.regex",
+ matchingTargetServersRegex)
+ addTokenToUGI(identifier1)
+ addTokenToUGI(identifier2)
+
+ val thrown = intercept[IllegalArgumentException] {
+ KafkaTokenUtil.findMatchingToken(sparkConf, bootStrapServers)
+ }
+ assert(thrown.getMessage contains
Review comment:
Fixed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]