Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14065#discussion_r72493513
  
    --- Diff: 
yarn/src/test/scala/org/apache/spark/deploy/yarn/security/ConfigurableCredentialManagerSuite.scala
 ---
    @@ -0,0 +1,153 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.deploy.yarn.security
    +
    +import org.apache.hadoop.conf.Configuration
    +import org.apache.hadoop.io.Text
    +import org.apache.hadoop.security.Credentials
    +import org.apache.hadoop.security.token.Token
    +import org.scalatest.{BeforeAndAfter, Matchers}
    +
    +import org.apache.spark.{SparkConf, SparkFunSuite}
    +import org.apache.spark.deploy.yarn.config._
    +
    +class ConfigurableCredentialManagerSuite extends SparkFunSuite with 
Matchers with BeforeAndAfter {
    +  private var credentialManager: ConfigurableCredentialManager = null
    +  private var sparkConf: SparkConf = null
    +  private var hadoopConf: Configuration = null
    +
    +  override def beforeAll(): Unit = {
    +    super.beforeAll()
    +
    +    sparkConf = new SparkConf()
    +    hadoopConf = new Configuration()
    +    System.setProperty("SPARK_YARN_MODE", "true")
    +  }
    +
    +  override def afterAll(): Unit = {
    +    System.clearProperty("SPARK_YARN_MODE")
    +
    +    super.afterAll()
    +  }
    +
    +  test("Correctly load default credential providers") {
    +    credentialManager = new ConfigurableCredentialManager(sparkConf, 
hadoopConf)
    +
    +    credentialManager.getServiceCredentialProvider("hdfs") should not be 
(None)
    +    credentialManager.getServiceCredentialProvider("hbase") should not be 
(None)
    +    credentialManager.getServiceCredentialProvider("hive") should not be 
(None)
    +  }
    +
    +  test("disable hive credential provider") {
    +    sparkConf.set("spark.yarn.security.credentials.hive.enabled", "false")
    +    credentialManager = new ConfigurableCredentialManager(sparkConf, 
hadoopConf)
    +
    +    credentialManager.getServiceCredentialProvider("hdfs") should not be 
(None)
    +    credentialManager.getServiceCredentialProvider("hbase") should not be 
(None)
    +    credentialManager.getServiceCredentialProvider("hive") should be (None)
    +  }
    +
    +  test("using deprecated configurations") {
    +    sparkConf.set("spark.yarn.security.tokens.hdfs.enabled", "false")
    +    sparkConf.set("spark.yarn.security.tokens.hive.enabled", "false")
    +    credentialManager = new ConfigurableCredentialManager(sparkConf, 
hadoopConf)
    +
    +    credentialManager.getServiceCredentialProvider("hdfs") should be (None)
    +    credentialManager.getServiceCredentialProvider("hive") should be (None)
    +    credentialManager.getServiceCredentialProvider("test") should not be 
(None)
    +    credentialManager.getServiceCredentialProvider("hbase") should not be 
(None)
    +  }
    +
    +  test("plug in customized credential provider") {
    +    credentialManager = new ConfigurableCredentialManager(sparkConf, 
hadoopConf)
    +
    +    credentialManager.getServiceCredentialProvider("test") should not be 
(None)
    +  }
    +
    +  test("verify obtaining credentials from provider") {
    +    credentialManager = new ConfigurableCredentialManager(sparkConf, 
hadoopConf)
    +    val creds = new Credentials()
    +
    +    // Tokens can only be obtained from TestTokenProvider, for hdfs, hbase 
and hive tokens cannot
    +    // be obtained.
    +    credentialManager.obtainCredentials(hadoopConf, creds)
    +    val tokens = creds.getAllTokens
    +    tokens.size() should be (1)
    +    tokens.iterator().next().getService should be (new Text("test"))
    +  }
    +
    +  test("verify getting credential renewal info") {
    +    credentialManager = new ConfigurableCredentialManager(sparkConf, 
hadoopConf)
    +    val creds = new Credentials()
    +
    +    val testCredentialProvider = 
credentialManager.getServiceCredentialProvider("test").get
    +      .asInstanceOf[TestCredentialProvider]
    +    // Only TestTokenProvider can get the time of next token renewal
    +    val nextRenewal = credentialManager.obtainCredentials(hadoopConf, 
creds)
    +    nextRenewal should be (testCredentialProvider.timeOfNextTokenRenewal)
    +  }
    +
    +  test("Obtain tokens For HiveMetastore") {
    --- End diff --
    
    nit: all test descriptions start with lower case, so should this one (and 
the next)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to