1919
2020import  static  org .junit .Assert .assertFalse ;
2121import  static  org .junit .Assert .assertNotNull ;
22+ import  static  org .junit .Assert .assertThrows ;
2223import  static  org .junit .Assert .assertTrue ;
23- import  static  org .junit .Assert .fail ;
2424
2525import  java .io .BufferedWriter ;
2626import  java .io .File ;
3737import  org .apache .hadoop .fs .Path ;
3838import  org .apache .hadoop .hbase .Cell ;
3939import  org .apache .hadoop .hbase .CellUtil ;
40- import  org .apache .hadoop .hbase .DoNotRetryIOException ;
4140import  org .apache .hadoop .hbase .HBaseClassTestRule ;
4241import  org .apache .hadoop .hbase .HBaseTestingUtility ;
4342import  org .apache .hadoop .hbase .HConstants ;
5049import  org .apache .hadoop .hbase .client .Get ;
5150import  org .apache .hadoop .hbase .client .Put ;
5251import  org .apache .hadoop .hbase .client .Result ;
52+ import  org .apache .hadoop .hbase .client .RetriesExhaustedException ;
5353import  org .apache .hadoop .hbase .client .Table ;
5454import  org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
5555import  org .apache .hadoop .hbase .coprocessor .CoprocessorHost ;
@@ -217,7 +217,7 @@ public Void run() throws Exception {
217217    }
218218  }
219219
220-   @ Test ( expected  =  DoNotRetryIOException . class ) 
220+   @ Test 
221221  public  void  testNegativeAuthentication () throws  Exception  {
222222    // Validate that we can read that record back out as the user with our custom auth'n 
223223    final  Configuration  clientConf  = new  Configuration (CONF );
@@ -227,17 +227,20 @@ public void testNegativeAuthentication() throws Exception {
227227        UserGroupInformation .createUserForTesting ("user1" , new  String [0 ]);
228228      user1 .addToken (
229229        ShadeClientTokenUtil .obtainToken (conn , "user1" , "not a real password" .toCharArray ()));
230-       user1 .doAs (new  PrivilegedExceptionAction <Void >() {
231-         @ Override 
232-         public  Void  run () throws  Exception  {
233-           try  (Connection  conn  = ConnectionFactory .createConnection (clientConf );
234-             Table  t  = conn .getTable (tableName )) {
235-             t .get (new  Get (Bytes .toBytes ("r1" )));
236-             fail ("Should not successfully authenticate with HBase" );
237-             return  null ;
230+       // Server will close the connection directly once auth failed, so at client side, we do not 
231+       // know what is the real problem so we will keep retrying, until reached the max retry times 
232+       // limitation 
233+       assertThrows ("Should not successfully authenticate with HBase" ,
234+         RetriesExhaustedException .class , () -> user1 .doAs (new  PrivilegedExceptionAction <Void >() {
235+           @ Override 
236+           public  Void  run () throws  Exception  {
237+             try  (Connection  conn  = ConnectionFactory .createConnection (clientConf );
238+               Table  t  = conn .getTable (tableName )) {
239+               t .get (new  Get (Bytes .toBytes ("r1" )));
240+               return  null ;
241+             }
238242          }
239-         }
240-       });
243+         }));
241244    }
242245  }
243246}
0 commit comments