6060import org .apache .hadoop .security .authorize .ProxyUsers ;
6161import org .apache .hadoop .security .token .Token ;
6262import org .apache .log4j .Level ;
63- import org .junit .After ;
63+ import org .junit .AfterClass ;
6464import org .junit .Assert ;
65- import org .junit .Before ;
65+ import org .junit .BeforeClass ;
6666import org .junit .Test ;
6767
6868public class TestDelegationTokenForProxyUser {
69- private MiniDFSCluster cluster ;
70- Configuration config ;
69+ private static MiniDFSCluster cluster ;
70+ private static Configuration config ;
7171 final private static String GROUP1_NAME = "group1" ;
7272 final private static String GROUP2_NAME = "group2" ;
7373 final private static String [] GROUP_NAMES = new String [] { GROUP1_NAME ,
7474 GROUP2_NAME };
7575 final private static String REAL_USER = "RealUser" ;
7676 final private static String PROXY_USER = "ProxyUser" ;
77+ private static UserGroupInformation ugi ;
78+ private static UserGroupInformation proxyUgi ;
7779
7880 private static final Log LOG = LogFactory .getLog (TestDoAsEffectiveUser .class );
7981
80- private void configureSuperUserIPAddresses (Configuration conf ,
82+ private static void configureSuperUserIPAddresses (Configuration conf ,
8183 String superUserShortName ) throws IOException {
8284 ArrayList <String > ipList = new ArrayList <String >();
8385 Enumeration <NetworkInterface > netInterfaceList = NetworkInterface
@@ -102,8 +104,8 @@ private void configureSuperUserIPAddresses(Configuration conf,
102104 builder .toString ());
103105 }
104106
105- @ Before
106- public void setUp () throws Exception {
107+ @ BeforeClass
108+ public static void setUp () throws Exception {
107109 config = new HdfsConfiguration ();
108110 config .setBoolean (DFSConfigKeys .DFS_WEBHDFS_ENABLED_KEY , true );
109111 config .setLong (
@@ -119,21 +121,20 @@ public void setUp() throws Exception {
119121 cluster = new MiniDFSCluster .Builder (config ).build ();
120122 cluster .waitActive ();
121123 ProxyUsers .refreshSuperUserGroupsConfiguration (config );
124+ ugi = UserGroupInformation .createRemoteUser (REAL_USER );
125+ proxyUgi = UserGroupInformation .createProxyUserForTesting (PROXY_USER , ugi ,
126+ GROUP_NAMES );
122127 }
123128
124- @ After
125- public void tearDown () throws Exception {
129+ @ AfterClass
130+ public static void tearDown () throws Exception {
126131 if (cluster !=null ) {
127132 cluster .shutdown ();
128133 }
129134 }
130135
131- @ Test
136+ @ Test ( timeout = 20000 )
132137 public void testDelegationTokenWithRealUser () throws IOException {
133- UserGroupInformation ugi = UserGroupInformation
134- .createRemoteUser (REAL_USER );
135- final UserGroupInformation proxyUgi = UserGroupInformation
136- .createProxyUserForTesting (PROXY_USER , ugi , GROUP_NAMES );
137138 try {
138139 Token <?>[] tokens = proxyUgi
139140 .doAs (new PrivilegedExceptionAction <Token <?>[]>() {
@@ -154,12 +155,11 @@ public Token<?>[] run() throws IOException {
154155 }
155156 }
156157
157- @ Test
158+ @ Test ( timeout = 20000 )
158159 public void testWebHdfsDoAs () throws Exception {
159160 WebHdfsTestUtil .LOG .info ("START: testWebHdfsDoAs()" );
160161 ((Log4JLogger )NamenodeWebHdfsMethods .LOG ).getLogger ().setLevel (Level .ALL );
161162 ((Log4JLogger )ExceptionHandler .LOG ).getLogger ().setLevel (Level .ALL );
162- final UserGroupInformation ugi = UserGroupInformation .createRemoteUser (REAL_USER );
163163 WebHdfsTestUtil .LOG .info ("ugi.getShortUserName()=" + ugi .getShortUserName ());
164164 final WebHdfsFileSystem webhdfs = WebHdfsTestUtil .getWebHdfsFileSystemAs (ugi , config );
165165
0 commit comments