use of com.google.firestore.v1.ListenRequest in project java-firestore by googleapis.
the class WatchTest method awaitAddTarget.
private void awaitAddTarget() throws InterruptedException {
ListenRequest listenRequest = requests.take();
assertEquals(DATABASE_NAME, listenRequest.getDatabase());
assertEquals(TARGET_ID, listenRequest.getAddTarget().getTargetId());
}
use of com.google.firestore.v1.ListenRequest in project java-firestore by googleapis.
the class FirestoreClientTest method listenTest.
@Test
public void listenTest() throws Exception {
ListenResponse expectedResponse = ListenResponse.newBuilder().build();
mockFirestore.addResponse(expectedResponse);
ListenRequest request = ListenRequest.newBuilder().setDatabase("database1789464955").putAllLabels(new HashMap<String, String>()).build();
MockStreamObserver<ListenResponse> responseObserver = new MockStreamObserver<>();
BidiStreamingCallable<ListenRequest, ListenResponse> callable = client.listenCallable();
ApiStreamObserver<ListenRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
List<ListenResponse> actualResponses = responseObserver.future().get();
Assert.assertEquals(1, actualResponses.size());
Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
use of com.google.firestore.v1.ListenRequest in project firebase-android-sdk by firebase.
the class WatchStream method unwatchTarget.
/**
* Unregisters interest in the results of the query associated with the given target ID.
*/
public void unwatchTarget(int targetId) {
hardAssert(isOpen(), "Unwatching targets requires an open stream");
ListenRequest request = ListenRequest.newBuilder().setDatabase(serializer.databaseName()).setRemoveTarget(targetId).build();
writeRequest(request);
}
use of com.google.firestore.v1.ListenRequest in project java-firestore by googleapis.
the class WatchTest method awaitResumeToken.
private void awaitResumeToken() throws InterruptedException {
ListenRequest listenRequest = requests.take();
assertEquals(DATABASE_NAME, listenRequest.getDatabase());
assertEquals(TARGET_ID, listenRequest.getAddTarget().getTargetId());
assertEquals(RESUME_TOKEN, listenRequest.getAddTarget().getResumeToken());
}
use of com.google.firestore.v1.ListenRequest in project java-firestore by googleapis.
the class FirestoreClientTest method listenExceptionTest.
@Test
public void listenExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
ListenRequest request = ListenRequest.newBuilder().setDatabase("database1789464955").putAllLabels(new HashMap<String, String>()).build();
MockStreamObserver<ListenResponse> responseObserver = new MockStreamObserver<>();
BidiStreamingCallable<ListenRequest, ListenResponse> callable = client.listenCallable();
ApiStreamObserver<ListenRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
try {
List<ListenResponse> actualResponses = responseObserver.future().get();
Assert.fail("No exception thrown");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);
InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}
Aggregations