Skip to content

Commit 0826c2d

Browse files
authored
chore: include the cause in retries exhausted exception (#4463)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable-hbase/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent f1f1200 commit 0826c2d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/AbstractBigtableTable.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ public Result[] get(List<Get> gets) throws IOException {
276276

277277
private RetriesExhaustedWithDetailsException createRetriesExhaustedWithDetailsException(
278278
Throwable e, Row action) {
279-
return new RetriesExhaustedWithDetailsException(
280-
Arrays.asList(e), Arrays.asList(action), Arrays.asList(settings.getDataHost()));
279+
return (RetriesExhaustedWithDetailsException)
280+
new RetriesExhaustedWithDetailsException(
281+
Arrays.asList(e), Arrays.asList(action), Arrays.asList(settings.getDataHost()))
282+
.initCause(e);
281283
}
282284

283285
/** {@inheritDoc} */

bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBigtableTable.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertFalse;
2323
import static org.junit.Assert.assertNull;
24+
import static org.junit.Assert.assertThrows;
2425
import static org.junit.Assert.assertTrue;
2526
import static org.mockito.ArgumentMatchers.isA;
2627
import static org.mockito.Mockito.doAnswer;
@@ -41,6 +42,8 @@
4142
import com.google.cloud.bigtable.hbase.wrappers.DataClientWrapper;
4243
import com.google.common.collect.ImmutableList;
4344
import com.google.protobuf.ByteString;
45+
import io.grpc.Status;
46+
import io.grpc.StatusRuntimeException;
4447
import java.io.IOException;
4548
import java.util.Collections;
4649
import java.util.List;
@@ -55,6 +58,7 @@
5558
import org.apache.hadoop.hbase.client.Put;
5659
import org.apache.hadoop.hbase.client.Result;
5760
import org.apache.hadoop.hbase.client.ResultScanner;
61+
import org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException;
5862
import org.apache.hadoop.hbase.client.RowMutations;
5963
import org.apache.hadoop.hbase.client.Scan;
6064
import org.apache.hadoop.hbase.client.coprocessor.Batch.Call;
@@ -416,4 +420,27 @@ public void testToString() {
416420
assertThat(abstractTableToStr, containsString("table=" + TEST_TABLE));
417421
assertThat(abstractTableToStr, containsString("host=" + "localhost"));
418422
}
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+
}
419446
}

0 commit comments

Comments
 (0)