From 221b871f0cb7b82fb2e590545d2a3c9e8292c3f7 Mon Sep 17 00:00:00 2001 From: Daryn Sharp Date: Mon, 4 Mar 2013 15:03:33 +0000 Subject: [PATCH] svn merge -c 1452338 FIXES: HADOOP-9352. Expose UGI.setLoginUser for tests (daryn) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1452339 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 2 ++ .../org/apache/hadoop/security/UserGroupInformation.java | 5 ++++- .../apache/hadoop/security/TestUserGroupInformation.java | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index e5931e43861..43e32c14e40 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -1065,6 +1065,8 @@ Release 0.23.7 - UNRELEASED HADOOP-9336. Allow UGI of current connection to be queried. (Daryn Sharp via kihwal) + HADOOP-9352. Expose UGI.setLoginUser for tests (daryn) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java index 855d9b22870..17d5073e0f6 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java @@ -65,6 +65,8 @@ import org.apache.hadoop.security.token.TokenIdentifier; import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Time; +import com.google.common.annotations.VisibleForTesting; + /** * User and group information for Hadoop. * This class wraps around a JAAS Subject and provides methods to determine the @@ -702,7 +704,8 @@ public class UserGroupInformation { @InterfaceAudience.Private @InterfaceStability.Unstable - synchronized static void setLoginUser(UserGroupInformation ugi) { + @VisibleForTesting + public synchronized static void setLoginUser(UserGroupInformation ugi) { // if this is to become stable, should probably logout the currently // logged in ugi if it's different loginUser = ugi; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java index 65427188ae3..f591139c650 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java @@ -608,4 +608,11 @@ public class TestUserGroupInformation { } }); } + + @Test(timeout=1000) + public void testSetLoginUser() throws IOException { + UserGroupInformation ugi = UserGroupInformation.createRemoteUser("test-user"); + UserGroupInformation.setLoginUser(ugi); + assertEquals(ugi, UserGroupInformation.getLoginUser()); + } }