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 ;
3636import org .apache .hadoop .fs .Path ;
3737import org .apache .hadoop .hbase .Cell ;
3838import org .apache .hadoop .hbase .CellUtil ;
39- import org .apache .hadoop .hbase .DoNotRetryIOException ;
4039import org .apache .hadoop .hbase .HBaseClassTestRule ;
4140import org .apache .hadoop .hbase .HBaseTestingUtility ;
4241import org .apache .hadoop .hbase .HConstants ;
4948import org .apache .hadoop .hbase .client .Get ;
5049import org .apache .hadoop .hbase .client .Put ;
5150import org .apache .hadoop .hbase .client .Result ;
51+ import org .apache .hadoop .hbase .client .RetriesExhaustedException ;
5252import org .apache .hadoop .hbase .client .Table ;
5353import org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
5454import org .apache .hadoop .hbase .coprocessor .CoprocessorHost ;
@@ -216,7 +216,7 @@ public Void run() throws Exception {
216216 }
217217 }
218218
219- @ Test ( expected = DoNotRetryIOException . class )
219+ @ Test
220220 public void testNegativeAuthentication () throws Exception {
221221 // Validate that we can read that record back out as the user with our custom auth'n
222222 final Configuration clientConf = new Configuration (CONF );
@@ -226,17 +226,20 @@ public void testNegativeAuthentication() throws Exception {
226226 UserGroupInformation .createUserForTesting ("user1" , new String [0 ]);
227227 user1 .addToken (
228228 ShadeClientTokenUtil .obtainToken (conn , "user1" , "not a real password" .toCharArray ()));
229- user1 .doAs (new PrivilegedExceptionAction <Void >() {
230- @ Override
231- public Void run () throws Exception {
232- try (Connection conn = ConnectionFactory .createConnection (clientConf );
233- Table t = conn .getTable (tableName )) {
234- t .get (new Get (Bytes .toBytes ("r1" )));
235- fail ("Should not successfully authenticate with HBase" );
236- return null ;
229+ // Server will close the connection directly once auth failed, so at client side, we do not
230+ // know what is the real problem so we will keep retrying, until reached the max retry times
231+ // limitation
232+ assertThrows ("Should not successfully authenticate with HBase" ,
233+ RetriesExhaustedException .class , () -> user1 .doAs (new PrivilegedExceptionAction <Void >() {
234+ @ Override
235+ public Void run () throws Exception {
236+ try (Connection conn = ConnectionFactory .createConnection (clientConf );
237+ Table t = conn .getTable (tableName )) {
238+ t .get (new Get (Bytes .toBytes ("r1" )));
239+ return null ;
240+ }
237241 }
238- }
239- });
242+ }));
240243 }
241244 }
242245}
0 commit comments