Search in sources :

Example 1 with ListenRequest

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());
}
Also used : ListenRequest(com.google.firestore.v1.ListenRequest)

Example 2 with ListenRequest

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));
}
Also used : HashMap(java.util.HashMap) ListenRequest(com.google.firestore.v1.ListenRequest) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ListenResponse(com.google.firestore.v1.ListenResponse) Test(org.junit.Test)

Example 3 with ListenRequest

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);
}
Also used : ListenRequest(com.google.firestore.v1.ListenRequest)

Example 4 with ListenRequest

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());
}
Also used : ListenRequest(com.google.firestore.v1.ListenRequest)

Example 5 with ListenRequest

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());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) HashMap(java.util.HashMap) ListenRequest(com.google.firestore.v1.ListenRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) ListenResponse(com.google.firestore.v1.ListenResponse) Test(org.junit.Test)

Aggregations

ListenRequest (com.google.firestore.v1.ListenRequest)5 MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)2 ListenResponse (com.google.firestore.v1.ListenResponse)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ExecutionException (java.util.concurrent.ExecutionException)1