|
21 | 21 | import static org.junit.Assert.assertEquals; |
22 | 22 | import static org.junit.Assert.assertFalse; |
23 | 23 | import static org.junit.Assert.assertNull; |
| 24 | +import static org.junit.Assert.assertThrows; |
24 | 25 | import static org.junit.Assert.assertTrue; |
25 | 26 | import static org.mockito.ArgumentMatchers.isA; |
26 | 27 | import static org.mockito.Mockito.doAnswer; |
|
41 | 42 | import com.google.cloud.bigtable.hbase.wrappers.DataClientWrapper; |
42 | 43 | import com.google.common.collect.ImmutableList; |
43 | 44 | import com.google.protobuf.ByteString; |
| 45 | +import io.grpc.Status; |
| 46 | +import io.grpc.StatusRuntimeException; |
44 | 47 | import java.io.IOException; |
45 | 48 | import java.util.Collections; |
46 | 49 | import java.util.List; |
|
55 | 58 | import org.apache.hadoop.hbase.client.Put; |
56 | 59 | import org.apache.hadoop.hbase.client.Result; |
57 | 60 | import org.apache.hadoop.hbase.client.ResultScanner; |
| 61 | +import org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException; |
58 | 62 | import org.apache.hadoop.hbase.client.RowMutations; |
59 | 63 | import org.apache.hadoop.hbase.client.Scan; |
60 | 64 | import org.apache.hadoop.hbase.client.coprocessor.Batch.Call; |
@@ -416,4 +420,27 @@ public void testToString() { |
416 | 420 | assertThat(abstractTableToStr, containsString("table=" + TEST_TABLE)); |
417 | 421 | assertThat(abstractTableToStr, containsString("host=" + "localhost")); |
418 | 422 | } |
| 423 | + |
| 424 | + @Test |
| 425 | + public void testExceptions() { |
| 426 | + Exception exception = |
| 427 | + new StatusRuntimeException(Status.DEADLINE_EXCEEDED.withCause(new Throwable("test cause"))); |
| 428 | + when(mockBigtableDataClient.readRowAsync( |
| 429 | + isA(String.class), isA(ByteString.class), isA(Filters.Filter.class))) |
| 430 | + .thenThrow(exception); |
| 431 | + |
| 432 | + RetriesExhaustedWithDetailsException exhaustedWithDetailsException = |
| 433 | + assertThrows( |
| 434 | + RetriesExhaustedWithDetailsException.class, |
| 435 | + () -> |
| 436 | + table.get( |
| 437 | + new Get(Bytes.toBytes("rowKey1")) |
| 438 | + .addColumn(Bytes.toBytes("family"), Bytes.toBytes("qualifier")))); |
| 439 | + |
| 440 | + assertThat( |
| 441 | + exhaustedWithDetailsException.getCause().getMessage(), containsString("DEADLINE_EXCEEDED")); |
| 442 | + assertThat( |
| 443 | + exhaustedWithDetailsException.getCause().getCause().getMessage(), |
| 444 | + containsString("test cause")); |
| 445 | + } |
419 | 446 | } |
0 commit comments