use of com.google.firestore.v1beta1.ListDocumentsResponse in project grpc-gcp-java by GoogleCloudPlatform.
the class ListDocuments method listDocumentsCall.
public void listDocumentsCall() {
System.out.println("\n:: Listing all Documents ::\n");
FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
ListDocumentsRequest ldr = ListDocumentsRequest.newBuilder().setParent("projects/firestoretestclient/databases/(default)/documents").setCollectionId("GrpcTestData").build();
try {
ListDocumentsResponse listDocumentsResponse = blockingStub.listDocuments(ldr);
List<Document> allDocs = listDocumentsResponse.getDocumentsList();
DrawDocument dd = new DrawDocument();
for (Document doc : allDocs) {
dd.draw(doc);
}
Menu menu = new Menu();
menu.draw();
System.out.println("Finished call...");
} catch (Exception e) {
System.out.println("Error executing streaming stub call: " + (e.getMessage() + "\n" + e.getCause().toString()));
}
}
use of com.google.firestore.v1beta1.ListDocumentsResponse in project java-firestore by googleapis.
the class FirestoreClientTest method listDocumentsTest.
@Test
public void listDocumentsTest() throws Exception {
Document responsesElement = Document.newBuilder().build();
ListDocumentsResponse expectedResponse = ListDocumentsResponse.newBuilder().setNextPageToken("").addAllDocuments(Arrays.asList(responsesElement)).build();
mockFirestore.addResponse(expectedResponse);
ListDocumentsRequest request = ListDocumentsRequest.newBuilder().setParent("parent-995424086").setCollectionId("collectionId1636075609").setPageSize(883849137).setPageToken("pageToken873572522").setOrderBy("orderBy-1207110587").setMask(DocumentMask.newBuilder().build()).setShowMissing(true).build();
ListDocumentsPagedResponse pagedListResponse = client.listDocuments(request);
List<Document> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDocumentsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockFirestore.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDocumentsRequest actualRequest = ((ListDocumentsRequest) actualRequests.get(0));
Assert.assertEquals(request.getParent(), actualRequest.getParent());
Assert.assertEquals(request.getCollectionId(), actualRequest.getCollectionId());
Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
Assert.assertEquals(request.getOrderBy(), actualRequest.getOrderBy());
Assert.assertEquals(request.getMask(), actualRequest.getMask());
Assert.assertEquals(request.getTransaction(), actualRequest.getTransaction());
Assert.assertEquals(request.getReadTime(), actualRequest.getReadTime());
Assert.assertEquals(request.getShowMissing(), actualRequest.getShowMissing());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.firestore.v1beta1.ListDocumentsResponse in project beam by apache.
the class FirestoreV1FnListDocumentsTest method endToEnd.
@Test
public void endToEnd() throws Exception {
// First page of the response
ListDocumentsRequest request1 = ListDocumentsRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).build();
ListDocumentsResponse response1 = ListDocumentsResponse.newBuilder().addDocuments(Document.newBuilder().setName("doc_1-1").putAllFields(ImmutableMap.of("foo", Value.newBuilder().setStringValue("bar").build())).build()).addDocuments(Document.newBuilder().setName("doc_1-2").putAllFields(ImmutableMap.of("foo", Value.newBuilder().setStringValue("bar").build())).build()).addDocuments(Document.newBuilder().setName("doc_1-3").putAllFields(ImmutableMap.of("foo", Value.newBuilder().setStringValue("bar").build())).build()).setNextPageToken("page2").build();
when(page1.getNextPageToken()).thenReturn(response1.getNextPageToken());
when(page1.getResponse()).thenReturn(response1);
when(page1.hasNextPage()).thenReturn(true);
// Second page of the response
ListDocumentsResponse response2 = ListDocumentsResponse.newBuilder().addDocuments(Document.newBuilder().setName("doc_2-1").putAllFields(ImmutableMap.of("foo", Value.newBuilder().setStringValue("bar").build())).build()).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.listDocumentsPagedCallable()).thenReturn(callable);
when(ff.getFirestoreStub(any())).thenReturn(stub);
RpcQosOptions options = RpcQosOptions.defaultOptions();
when(ff.getRpcQos(any())).thenReturn(FirestoreStatefulComponentFactory.INSTANCE.getRpcQos(options));
ArgumentCaptor<ListDocumentsResponse> responses = ArgumentCaptor.forClass(ListDocumentsResponse.class);
doNothing().when(processContext).output(responses.capture());
when(processContext.element()).thenReturn(request1);
ListDocumentsFn fn = new ListDocumentsFn(clock, ff, options);
runFunction(fn);
List<ListDocumentsResponse> expected = newArrayList(response1, response2);
List<ListDocumentsResponse> allValues = responses.getAllValues();
assertEquals(expected, allValues);
}
use of com.google.firestore.v1beta1.ListDocumentsResponse in project beam by apache.
the class FirestoreV1FnListDocumentsTest 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
ListDocumentsRequest request1 = ListDocumentsRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).build();
ListDocumentsResponse response1 = ListDocumentsResponse.newBuilder().addDocuments(Document.newBuilder().setName("doc_1-1").putAllFields(ImmutableMap.of("foo", Value.newBuilder().setStringValue("bar").build())).build()).addDocuments(Document.newBuilder().setName("doc_1-2").putAllFields(ImmutableMap.of("foo", Value.newBuilder().setStringValue("bar").build())).build()).addDocuments(Document.newBuilder().setName("doc_1-3").putAllFields(ImmutableMap.of("foo", Value.newBuilder().setStringValue("bar").build())).build()).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<ListDocumentsPage>() {
@Override
public Iterator<ListDocumentsPage> iterator() {
return new AbstractIterator<ListDocumentsPage>() {
private boolean first = true;
@Override
protected ListDocumentsPage computeNext() {
if (first) {
first = false;
return page1;
} else {
throw RETRYABLE_ERROR;
}
}
};
}
});
// Second page of the response
ListDocumentsRequest request2 = ListDocumentsRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).setPageToken("page2").build();
ListDocumentsResponse response2 = ListDocumentsResponse.newBuilder().addDocuments(Document.newBuilder().setName("doc_2-1").putAllFields(ImmutableMap.of("foo", Value.newBuilder().setStringValue("bar").build())).build()).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.listDocumentsPagedCallable()).thenReturn(callable);
when(ff.getFirestoreStub(any())).thenReturn(stub);
ArgumentCaptor<ListDocumentsResponse> responses = ArgumentCaptor.forClass(ListDocumentsResponse.class);
doNothing().when(processContext).output(responses.capture());
when(processContext.element()).thenReturn(request1);
ListDocumentsFn fn = new ListDocumentsFn(clock, ff, rpcQosOptions);
runFunction(fn);
List<ListDocumentsResponse> expected = newArrayList(response1, response2);
List<ListDocumentsResponse> allValues = responses.getAllValues();
assertEquals(expected, allValues);
}
Aggregations