2727import java .io .File ;
2828import java .io .IOException ;
2929import java .io .OutputStreamWriter ;
30- import java .io .PrintWriter ;
31- import java .io .StringWriter ;
3230import java .nio .charset .StandardCharsets ;
3331import java .security .PrivilegedExceptionAction ;
3432import java .util .ArrayList ;
6765import org .apache .hadoop .hbase .util .Bytes ;
6866import org .apache .hadoop .hbase .util .CommonFSUtils ;
6967import org .apache .hadoop .hbase .util .Pair ;
70- import org .apache .hadoop .ipc .RemoteException ;
7168import org .apache .hadoop .minikdc .MiniKdc ;
7269import org .apache .hadoop .security .UserGroupInformation ;
73- import org .apache .hadoop .security .token .SecretManager .InvalidToken ;
7470import org .junit .AfterClass ;
7571import org .junit .Before ;
7672import org .junit .BeforeClass ;
8278import org .slf4j .Logger ;
8379import org .slf4j .LoggerFactory ;
8480
85- import org .apache .hbase .thirdparty .com .google .common .base .Throwables ;
86-
8781@ Category ({ MediumTests .class , SecurityTests .class })
8882public class TestShadeSaslAuthenticationProvider {
8983 private static final Logger LOG =
@@ -210,21 +204,23 @@ public String run() throws Exception {
210204 @ Test
211205 public void testPositiveAuthentication () throws Exception {
212206 final Configuration clientConf = new Configuration (CONF );
213- try (Connection conn = ConnectionFactory .createConnection (clientConf )) {
207+ try (Connection conn1 = ConnectionFactory .createConnection (clientConf )) {
214208 UserGroupInformation user1 =
215209 UserGroupInformation .createUserForTesting ("user1" , new String [0 ]);
216- user1 .addToken (ShadeClientTokenUtil .obtainToken (conn , "user1" , USER1_PASSWORD ));
210+ user1 .addToken (ShadeClientTokenUtil .obtainToken (conn1 , "user1" , USER1_PASSWORD ));
217211 user1 .doAs (new PrivilegedExceptionAction <Void >() {
218212 @ Override
219213 public Void run () throws Exception {
220- try (Table t = conn .getTable (tableName )) {
221- Result r = t .get (new Get (Bytes .toBytes ("r1" )));
222- assertNotNull (r );
223- assertFalse ("Should have read a non-empty Result" , r .isEmpty ());
224- final Cell cell = r .getColumnLatestCell (Bytes .toBytes ("f1" ), Bytes .toBytes ("q1" ));
225- assertTrue ("Unexpected value" , CellUtil .matchingValue (cell , Bytes .toBytes ("1" )));
214+ try (Connection conn = ConnectionFactory .createConnection (clientConf )) {
215+ try (Table t = conn .getTable (tableName )) {
216+ Result r = t .get (new Get (Bytes .toBytes ("r1" )));
217+ assertNotNull (r );
218+ assertFalse ("Should have read a non-empty Result" , r .isEmpty ());
219+ final Cell cell = r .getColumnLatestCell (Bytes .toBytes ("f1" ), Bytes .toBytes ("q1" ));
220+ assertTrue ("Unexpected value" , CellUtil .matchingValue (cell , Bytes .toBytes ("1" )));
226221
227- return null ;
222+ return null ;
223+ }
228224 }
229225 }
230226 });
@@ -262,7 +258,6 @@ public Void run() throws Exception {
262258 } catch (Exception e ) {
263259 LOG .info ("Caught exception in negative Master connectivity test" , e );
264260 assertEquals ("Found unexpected exception" , pair .getSecond (), e .getClass ());
265- validateRootCause (Throwables .getRootCause (e ));
266261 }
267262 return null ;
268263 }
@@ -279,7 +274,6 @@ public Void run() throws Exception {
279274 } catch (Exception e ) {
280275 LOG .info ("Caught exception in negative RegionServer connectivity test" , e );
281276 assertEquals ("Found unexpected exception" , pair .getSecond (), e .getClass ());
282- validateRootCause (Throwables .getRootCause (e ));
283277 }
284278 return null ;
285279 }
@@ -293,19 +287,4 @@ public Void run() throws Exception {
293287 }
294288 });
295289 }
296-
297- void validateRootCause (Throwable rootCause ) {
298- LOG .info ("Root cause was" , rootCause );
299- if (rootCause instanceof RemoteException ) {
300- RemoteException re = (RemoteException ) rootCause ;
301- IOException actualException = re .unwrapRemoteException ();
302- assertEquals (InvalidToken .class , actualException .getClass ());
303- } else {
304- StringWriter writer = new StringWriter ();
305- rootCause .printStackTrace (new PrintWriter (writer ));
306- String text = writer .toString ();
307- assertTrue ("Message did not contain expected text" ,
308- text .contains (InvalidToken .class .getName ()));
309- }
310- }
311290}
0 commit comments