Skip to content

Commit 3a4e484

Browse files
committed
HBASE-28106 TestShadeSaslAuthenticationProvider fails for branch-2.x (#5433)
Signed-off-by: Nihal Jain <[email protected]> (cherry picked from commit 8d91cd2)
1 parent 4a48dbe commit 3a4e484

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

hbase-examples/src/test/java/org/apache/hadoop/hbase/security/provider/example/TestShadeSaslAuthenticationProvider.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import static org.junit.Assert.assertFalse;
2121
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertThrows;
2223
import static org.junit.Assert.assertTrue;
23-
import static org.junit.Assert.fail;
2424

2525
import java.io.BufferedWriter;
2626
import java.io.File;
@@ -37,7 +37,6 @@
3737
import org.apache.hadoop.fs.Path;
3838
import org.apache.hadoop.hbase.Cell;
3939
import org.apache.hadoop.hbase.CellUtil;
40-
import org.apache.hadoop.hbase.DoNotRetryIOException;
4140
import org.apache.hadoop.hbase.HBaseClassTestRule;
4241
import org.apache.hadoop.hbase.HBaseTestingUtility;
4342
import org.apache.hadoop.hbase.HConstants;
@@ -50,6 +49,7 @@
5049
import org.apache.hadoop.hbase.client.Get;
5150
import org.apache.hadoop.hbase.client.Put;
5251
import org.apache.hadoop.hbase.client.Result;
52+
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
5353
import org.apache.hadoop.hbase.client.Table;
5454
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
5555
import 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

Comments
 (0)