Skip to content

Commit e8aa715

Browse files
committed
HBASE-28106 TestShadeSaslAuthenticationProvider fails for branch-2.x (apache#5433)
Signed-off-by: Nihal Jain <nihaljain@apache.org> (cherry picked from commit 8d91cd2)
1 parent 6eae477 commit e8aa715

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

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;
@@ -36,7 +36,6 @@
3636
import org.apache.hadoop.fs.Path;
3737
import org.apache.hadoop.hbase.Cell;
3838
import org.apache.hadoop.hbase.CellUtil;
39-
import org.apache.hadoop.hbase.DoNotRetryIOException;
4039
import org.apache.hadoop.hbase.HBaseClassTestRule;
4140
import org.apache.hadoop.hbase.HBaseTestingUtility;
4241
import org.apache.hadoop.hbase.HConstants;
@@ -49,6 +48,7 @@
4948
import org.apache.hadoop.hbase.client.Get;
5049
import org.apache.hadoop.hbase.client.Put;
5150
import org.apache.hadoop.hbase.client.Result;
51+
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
5252
import org.apache.hadoop.hbase.client.Table;
5353
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
5454
import 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

Comments
 (0)