Skip to content

Commit a76a0fd

Browse files
fix: retry watch on InternalException (#875)
Fixes #866
1 parent 036f7f8 commit a76a0fd

File tree

2 files changed

+23
-1
lines changed
  • google-cloud-firestore/src

2 files changed

+23
-1
lines changed

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ private static Status getStatus(Throwable throwable) {
570570
return ((StatusRuntimeException) throwable).getStatus();
571571
} else if (throwable instanceof StatusException) {
572572
return ((StatusException) throwable).getStatus();
573+
} else if (throwable instanceof ApiException
574+
&& ((ApiException) throwable).getStatusCode().getTransportCode() instanceof Code) {
575+
return ((Code) ((ApiException) throwable).getStatusCode().getTransportCode()).toStatus();
573576
}
574577
return null;
575578
}

google-cloud-firestore/src/test/java/com/google/cloud/firestore/WatchTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
import static org.mockito.Mockito.doAnswer;
3333
import static org.mockito.Mockito.doReturn;
3434

35+
import com.google.api.gax.grpc.GrpcStatusCode;
3536
import com.google.api.gax.rpc.BidiStreamObserver;
3637
import com.google.api.gax.rpc.BidiStreamingCallable;
3738
import com.google.api.gax.rpc.ClientStream;
39+
import com.google.api.gax.rpc.InternalException;
3840
import com.google.cloud.firestore.Query.Direction;
3941
import com.google.cloud.firestore.WatchTest.SnapshotDocument.ChangeType;
4042
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
@@ -393,6 +395,19 @@ public void queryWatchRetriesBasedOnErrorCode() throws InterruptedException {
393395
}
394396
}
395397

398+
@Test
399+
public void queryWatchRetriesOnInternalException() throws InterruptedException {
400+
addQueryListener();
401+
awaitAddTarget();
402+
send(addTarget());
403+
destroy(new InternalException(null, GrpcStatusCode.of(Code.INTERNAL), true));
404+
awaitAddTarget();
405+
send(addTarget());
406+
send(current());
407+
send(snapshot());
408+
awaitQuerySnapshot();
409+
}
410+
396411
@Test
397412
public void queryWatchHandlesDocumentChange() throws InterruptedException {
398413
addQueryListener();
@@ -991,7 +1006,11 @@ private void send(ListenResponse response) {
9911006
}
9921007

9931008
private void destroy(Code code) {
994-
streamObserverCapture.getValue().onError(new StatusException(io.grpc.Status.fromCode(code)));
1009+
destroy(new StatusException(io.grpc.Status.fromCode(code)));
1010+
}
1011+
1012+
private void destroy(Exception e) {
1013+
streamObserverCapture.getValue().onError(e);
9951014
}
9961015

9971016
private void close() {

0 commit comments

Comments
 (0)