Search in sources :

Example 6 with BatchGetDocumentsResponse

use of com.google.firestore.v1beta1.BatchGetDocumentsResponse in project beam by apache.

the class FirestoreV1FnBatchGetDocumentsTest method endToEnd.

@Test
public void endToEnd() throws Exception {
    final BatchGetDocumentsRequest request = BatchGetDocumentsRequest.newBuilder().setDatabase(String.format("projects/%s/databases/(default)", projectId)).addDocuments("doc_1-1").addDocuments("doc_1-2").addDocuments("doc_1-3").build();
    final BatchGetDocumentsResponse response1 = newFound(1);
    final BatchGetDocumentsResponse response2 = newFound(2);
    final BatchGetDocumentsResponse response3 = newFound(3);
    List<BatchGetDocumentsResponse> responses = ImmutableList.of(response1, response2, response3);
    when(responseStream1.iterator()).thenReturn(responses.iterator());
    when(callable.call(request)).thenReturn(responseStream1);
    when(stub.batchGetDocumentsCallable()).thenReturn(callable);
    when(ff.getFirestoreStub(any())).thenReturn(stub);
    when(ff.getRpcQos(any())).thenReturn(FirestoreStatefulComponentFactory.INSTANCE.getRpcQos(rpcQosOptions));
    ArgumentCaptor<BatchGetDocumentsResponse> responsesCaptor = ArgumentCaptor.forClass(BatchGetDocumentsResponse.class);
    doNothing().when(processContext).output(responsesCaptor.capture());
    when(processContext.element()).thenReturn(request);
    runFunction(getFn(clock, ff, rpcQosOptions));
    List<BatchGetDocumentsResponse> allValues = responsesCaptor.getAllValues();
    assertEquals(responses, allValues);
}
Also used : BatchGetDocumentsResponse(com.google.firestore.v1.BatchGetDocumentsResponse) BatchGetDocumentsRequest(com.google.firestore.v1.BatchGetDocumentsRequest) Test(org.junit.Test)

Example 7 with BatchGetDocumentsResponse

use of com.google.firestore.v1beta1.BatchGetDocumentsResponse in project java-firestore by googleapis.

the class FirestoreClientTest method batchGetDocumentsExceptionTest.

@Test
public void batchGetDocumentsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockFirestore.addException(exception);
    BatchGetDocumentsRequest request = BatchGetDocumentsRequest.newBuilder().setDatabase("database1789464955").addAllDocuments(new ArrayList<String>()).setMask(DocumentMask.newBuilder().build()).build();
    MockStreamObserver<BatchGetDocumentsResponse> responseObserver = new MockStreamObserver<>();
    ServerStreamingCallable<BatchGetDocumentsRequest, BatchGetDocumentsResponse> callable = client.batchGetDocumentsCallable();
    callable.serverStreamingCall(request, responseObserver);
    try {
        List<BatchGetDocumentsResponse> 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) StatusRuntimeException(io.grpc.StatusRuntimeException) BatchGetDocumentsResponse(com.google.firestore.v1.BatchGetDocumentsResponse) ByteString(com.google.protobuf.ByteString) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) BatchGetDocumentsRequest(com.google.firestore.v1.BatchGetDocumentsRequest) Test(org.junit.Test)

Aggregations

BatchGetDocumentsResponse (com.google.firestore.v1.BatchGetDocumentsResponse)6 BatchGetDocumentsRequest (com.google.firestore.v1.BatchGetDocumentsRequest)5 ByteString (com.google.protobuf.ByteString)3 Test (org.junit.Test)3 MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)2 ArrayList (java.util.ArrayList)2 TaskCompletionSource (com.google.android.gms.tasks.TaskCompletionSource)1 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)1 DocumentKey (com.google.firebase.firestore.model.DocumentKey)1 MutableDocument (com.google.firebase.firestore.model.MutableDocument)1 Util.exceptionFromStatus (com.google.firebase.firestore.util.Util.exceptionFromStatus)1 BatchGetDocumentsRequest (com.google.firestore.v1beta1.BatchGetDocumentsRequest)1 BatchGetDocumentsResponse (com.google.firestore.v1beta1.BatchGetDocumentsResponse)1 Document (com.google.firestore.v1beta1.Document)1 FirestoreGrpc (com.google.firestore.v1beta1.FirestoreGrpc)1 Status (io.grpc.Status)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 StreamObserver (io.grpc.stub.StreamObserver)1 HashMap (java.util.HashMap)1