-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28996][SQL][TESTS] Add tests regarding username of HiveClient #25696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4d5a389
[SPARK-28996][SQL] Add tests regarding username of HiveClient
HeartSaVioR a98c0b9
slight modification of test name
HeartSaVioR 1da9bd8
Renaming to help Github to indicate renaming
HeartSaVioR dfca82b
Reflect the change of SPARK-26929
HeartSaVioR ef220ef
Reflect review comment
HeartSaVioR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientUserNameSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * 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.sql.hive.client | ||
|
|
||
| import java.security.PrivilegedExceptionAction | ||
|
|
||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.security.UserGroupInformation | ||
| import org.scalatest.{BeforeAndAfterAll, PrivateMethodTester} | ||
|
|
||
| import org.apache.spark.util.Utils | ||
|
|
||
| class HiveClientUserNameSuite(version: String) extends HiveVersionSuite(version) { | ||
|
|
||
| test("username of HiveClient - no UGI") { | ||
| // Assuming we're not faking System username | ||
| assert(getUserNameFromHiveClient === System.getProperty("user.name")) | ||
| } | ||
|
|
||
| test("username of HiveClient - UGI") { | ||
| val ugi = UserGroupInformation.createUserForTesting( | ||
| "[email protected]", Array.empty) | ||
| ugi.doAs(new PrivilegedExceptionAction[Unit]() { | ||
| override def run(): Unit = { | ||
| assert(getUserNameFromHiveClient === ugi.getShortUserName) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| test("username of HiveClient - Proxy user") { | ||
| val ugi = UserGroupInformation.createUserForTesting( | ||
| "[email protected]", Array.empty) | ||
| val proxyUgi = UserGroupInformation.createProxyUserForTesting( | ||
| "[email protected]", ugi, Array.empty) | ||
| proxyUgi.doAs(new PrivilegedExceptionAction[Unit]() { | ||
| override def run(): Unit = { | ||
| assert(getUserNameFromHiveClient === proxyUgi.getShortUserName) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| private def getUserNameFromHiveClient: String = { | ||
| val hadoopConf = new Configuration() | ||
| hadoopConf.set("hive.metastore.warehouse.dir", Utils.createTempDir().toURI().toString()) | ||
| val client = buildClient(hadoopConf) | ||
| client.userName | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientUserNameSuites.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * 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.sql.hive.client | ||
|
|
||
| import scala.collection.immutable.IndexedSeq | ||
|
|
||
| import org.scalatest.Suite | ||
|
|
||
| class HiveClientUserNameSuites extends Suite with HiveClientVersions { | ||
| override def nestedSuites: IndexedSeq[Suite] = { | ||
| versions.map(new HiveClientUserNameSuite(_)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change user name at runtime? If we can then it should be
definstead ofval.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure, but we have been defining userName as
valfrom Spark 2.2.0, starting from this commit 344f38bChanging it to def is safer anyway (can handle both cases - whether user name is changed or not) so please let me know if we would like to make change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, that would be better to be handled via separate PR if necessary, to isolate two different things "adding test" and "fixing logic".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, we can investigate it in a separated pr