From 09946b1eca592e1da8041a3aa912f3c8aaa87603 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Sun, 24 Sep 2023 21:43:08 +0800 Subject: [PATCH] HBASE-28106 TestShadeSaslAuthenticationProvider fails for branch-2.x (#5433) Signed-off-by: Nihal Jain (cherry picked from commit 8d91cd204cebfc891a4bb5c10646ef483d036703) (cherry picked from commit e8aa715ccb9eaf289ffa64b35f1322ec33d277ef) Change-Id: I6b808870868fd5c681d0007d5976a3ea729d8e69 --- .../TestShadeSaslAuthenticationProvider.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/hbase-examples/src/test/java/org/apache/hadoop/hbase/security/provider/example/TestShadeSaslAuthenticationProvider.java b/hbase-examples/src/test/java/org/apache/hadoop/hbase/security/provider/example/TestShadeSaslAuthenticationProvider.java index 36a0bd0fa3e4..1fcea26d0d40 100644 --- a/hbase-examples/src/test/java/org/apache/hadoop/hbase/security/provider/example/TestShadeSaslAuthenticationProvider.java +++ b/hbase-examples/src/test/java/org/apache/hadoop/hbase/security/provider/example/TestShadeSaslAuthenticationProvider.java @@ -19,8 +19,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.BufferedWriter; import java.io.File; @@ -36,7 +36,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; @@ -49,6 +48,7 @@ import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.RetriesExhaustedException; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; @@ -216,7 +216,7 @@ public Void run() throws Exception { } } - @Test(expected = DoNotRetryIOException.class) + @Test public void testNegativeAuthentication() throws Exception { // Validate that we can read that record back out as the user with our custom auth'n final Configuration clientConf = new Configuration(CONF); @@ -226,17 +226,20 @@ public void testNegativeAuthentication() throws Exception { UserGroupInformation.createUserForTesting("user1", new String[0]); user1.addToken( ShadeClientTokenUtil.obtainToken(conn, "user1", "not a real password".toCharArray())); - user1.doAs(new PrivilegedExceptionAction() { - @Override - public Void run() throws Exception { - try (Connection conn = ConnectionFactory.createConnection(clientConf); - Table t = conn.getTable(tableName)) { - t.get(new Get(Bytes.toBytes("r1"))); - fail("Should not successfully authenticate with HBase"); - return null; + // Server will close the connection directly once auth failed, so at client side, we do not + // know what is the real problem so we will keep retrying, until reached the max retry times + // limitation + assertThrows("Should not successfully authenticate with HBase", + RetriesExhaustedException.class, () -> user1.doAs(new PrivilegedExceptionAction() { + @Override + public Void run() throws Exception { + try (Connection conn = ConnectionFactory.createConnection(clientConf); + Table t = conn.getTable(tableName)) { + t.get(new Get(Bytes.toBytes("r1"))); + return null; + } } - } - }); + })); } } }