Search in sources :

Example 1 with ListCollectionIdsResponse

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

the class FirestoreV1FnListCollectionIdsTest method endToEnd.

@Test
public void endToEnd() throws Exception {
    // First page of the response
    ListCollectionIdsRequest request1 = ListCollectionIdsRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).build();
    ListCollectionIdsResponse response1 = ListCollectionIdsResponse.newBuilder().addCollectionIds("col_1-1").addCollectionIds("col_1-2").addCollectionIds("col_1-3").setNextPageToken("page2").build();
    when(page1.getNextPageToken()).thenReturn(response1.getNextPageToken());
    when(page1.getResponse()).thenReturn(response1);
    when(page1.hasNextPage()).thenReturn(true);
    // Second page of the response
    ListCollectionIdsResponse response2 = ListCollectionIdsResponse.newBuilder().addCollectionIds("col_2-1").build();
    when(page2.getResponse()).thenReturn(response2);
    when(page2.hasNextPage()).thenReturn(false);
    when(pagedResponse1.iteratePages()).thenReturn(ImmutableList.of(page1, page2));
    when(callable.call(request1)).thenReturn(pagedResponse1);
    when(stub.listCollectionIdsPagedCallable()).thenReturn(callable);
    when(ff.getFirestoreStub(any())).thenReturn(stub);
    RpcQosOptions options = RpcQosOptions.defaultOptions();
    when(ff.getRpcQos(any())).thenReturn(FirestoreStatefulComponentFactory.INSTANCE.getRpcQos(options));
    ArgumentCaptor<ListCollectionIdsResponse> responses = ArgumentCaptor.forClass(ListCollectionIdsResponse.class);
    doNothing().when(processContext).output(responses.capture());
    when(processContext.element()).thenReturn(request1);
    ListCollectionIdsFn fn = new ListCollectionIdsFn(clock, ff, options);
    runFunction(fn);
    List<ListCollectionIdsResponse> expected = newArrayList(response1, response2);
    List<ListCollectionIdsResponse> allValues = responses.getAllValues();
    assertEquals(expected, allValues);
}
Also used : ListCollectionIdsResponse(com.google.firestore.v1.ListCollectionIdsResponse) ListCollectionIdsRequest(com.google.firestore.v1.ListCollectionIdsRequest) ListCollectionIdsFn(org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.ListCollectionIdsFn) Test(org.junit.Test)

Example 2 with ListCollectionIdsResponse

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

the class FirestoreV1FnListCollectionIdsTest method resumeFromLastReadValue.

@Override
public void resumeFromLastReadValue() throws Exception {
    when(ff.getFirestoreStub(any())).thenReturn(stub);
    when(ff.getRpcQos(any())).thenReturn(rpcQos);
    when(rpcQos.newReadAttempt(any())).thenReturn(attempt);
    when(attempt.awaitSafeToProceed(any())).thenReturn(true);
    // First page of the response
    ListCollectionIdsRequest request1 = ListCollectionIdsRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).build();
    ListCollectionIdsResponse response1 = ListCollectionIdsResponse.newBuilder().addCollectionIds("col_1-1").addCollectionIds("col_1-2").addCollectionIds("col_1-3").setNextPageToken("page2").build();
    when(page1.getNextPageToken()).thenReturn(response1.getNextPageToken());
    when(page1.getResponse()).thenReturn(response1);
    when(page1.hasNextPage()).thenReturn(true);
    when(callable.call(request1)).thenReturn(pagedResponse1);
    doNothing().when(attempt).checkCanRetry(any(), eq(RETRYABLE_ERROR));
    when(pagedResponse1.iteratePages()).thenAnswer(invocation -> new Iterable<ListCollectionIdsPage>() {

        @Override
        public Iterator<ListCollectionIdsPage> iterator() {
            return new AbstractIterator<ListCollectionIdsPage>() {

                private boolean first = true;

                @Override
                protected ListCollectionIdsPage computeNext() {
                    if (first) {
                        first = false;
                        return page1;
                    } else {
                        throw RETRYABLE_ERROR;
                    }
                }
            };
        }
    });
    // Second page of the response
    ListCollectionIdsRequest request2 = ListCollectionIdsRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).setPageToken("page2").build();
    ListCollectionIdsResponse response2 = ListCollectionIdsResponse.newBuilder().addCollectionIds("col_2-1").build();
    when(page2.getResponse()).thenReturn(response2);
    when(page2.hasNextPage()).thenReturn(false);
    when(callable.call(request2)).thenReturn(pagedResponse2);
    when(pagedResponse2.iteratePages()).thenReturn(ImmutableList.of(page2));
    when(stub.listCollectionIdsPagedCallable()).thenReturn(callable);
    when(ff.getFirestoreStub(any())).thenReturn(stub);
    ArgumentCaptor<ListCollectionIdsResponse> responses = ArgumentCaptor.forClass(ListCollectionIdsResponse.class);
    doNothing().when(processContext).output(responses.capture());
    when(processContext.element()).thenReturn(request1);
    ListCollectionIdsFn fn = new ListCollectionIdsFn(clock, ff, rpcQosOptions);
    runFunction(fn);
    List<ListCollectionIdsResponse> expected = newArrayList(response1, response2);
    List<ListCollectionIdsResponse> allValues = responses.getAllValues();
    assertEquals(expected, allValues);
}
Also used : ListCollectionIdsResponse(com.google.firestore.v1.ListCollectionIdsResponse) ListCollectionIdsPage(com.google.cloud.firestore.v1.FirestoreClient.ListCollectionIdsPage) ListCollectionIdsRequest(com.google.firestore.v1.ListCollectionIdsRequest) Iterator(java.util.Iterator) AbstractIterator(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.AbstractIterator) ListCollectionIdsFn(org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.ListCollectionIdsFn)

Example 3 with ListCollectionIdsResponse

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

the class FirestoreClientTest method listCollectionIdsTest.

@Test
public void listCollectionIdsTest() throws Exception {
    String responsesElement = "responsesElement-318365110";
    ListCollectionIdsResponse expectedResponse = ListCollectionIdsResponse.newBuilder().setNextPageToken("").addAllCollectionIds(Arrays.asList(responsesElement)).build();
    mockFirestore.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListCollectionIdsPagedResponse pagedListResponse = client.listCollectionIds(parent);
    List<String> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCollectionIdsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockFirestore.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCollectionIdsRequest actualRequest = ((ListCollectionIdsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListCollectionIdsPagedResponse(com.google.cloud.firestore.v1.FirestoreClient.ListCollectionIdsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListCollectionIdsResponse(com.google.firestore.v1.ListCollectionIdsResponse) ListCollectionIdsRequest(com.google.firestore.v1.ListCollectionIdsRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with ListCollectionIdsResponse

use of com.google.firestore.v1beta1.ListCollectionIdsResponse in project grpc-gcp-java by GoogleCloudPlatform.

the class ListCollectionIds method listCollectionIdsCall.

public void listCollectionIdsCall() {
    System.out.println("\n :: Listing all Collection Ids ::\n");
    FirestoreGrpc.FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
    ListCollectionIdsRequest listCollectionIdsRequest = ListCollectionIdsRequest.newBuilder().setParent("projects/firestoretestclient/databases/(default)").build();
    ListCollectionIdsResponse response;
    try {
        response = blockingStub.listCollectionIds(listCollectionIdsRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    ProtocolStringList psl = response.getCollectionIdsList();
    Iterator<String> collectionIdIter = psl.iterator();
    while (collectionIdIter.hasNext()) {
        System.out.println(collectionIdIter.next());
    }
    Menu menu = new Menu();
    menu.draw();
}
Also used : GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) ListCollectionIdsResponse(com.google.firestore.v1beta1.ListCollectionIdsResponse) ListCollectionIdsRequest(com.google.firestore.v1beta1.ListCollectionIdsRequest) Menu(org.roguewave.grpc.util.gfx.Menu) FirestoreGrpc(com.google.firestore.v1beta1.FirestoreGrpc) ProtocolStringList(com.google.protobuf.ProtocolStringList)

Aggregations

ListCollectionIdsRequest (com.google.firestore.v1.ListCollectionIdsRequest)3 ListCollectionIdsResponse (com.google.firestore.v1.ListCollectionIdsResponse)3 ListCollectionIdsFn (org.apache.beam.sdk.io.gcp.firestore.FirestoreV1ReadFn.ListCollectionIdsFn)2 Test (org.junit.Test)2 ListCollectionIdsPage (com.google.cloud.firestore.v1.FirestoreClient.ListCollectionIdsPage)1 ListCollectionIdsPagedResponse (com.google.cloud.firestore.v1.FirestoreClient.ListCollectionIdsPagedResponse)1 FirestoreGrpc (com.google.firestore.v1beta1.FirestoreGrpc)1 ListCollectionIdsRequest (com.google.firestore.v1beta1.ListCollectionIdsRequest)1 ListCollectionIdsResponse (com.google.firestore.v1beta1.ListCollectionIdsResponse)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 ByteString (com.google.protobuf.ByteString)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1 Iterator (java.util.Iterator)1 AbstractIterator (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.AbstractIterator)1 GRPCFirebaseClientFactory (org.roguewave.grpc.util.GRPCFirebaseClientFactory)1 Menu (org.roguewave.grpc.util.gfx.Menu)1