Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,10 @@ public void processElement(ProcessContext c) {
List<Cursor> cursors = new ArrayList<>(partitionQueryResponse.getPartitionsList());
cursors.sort(CURSOR_REFERENCE_VALUE_COMPARATOR);
final int size = cursors.size();
if (size == 0) {
emit(c, dbRoot, structuredQuery.toBuilder());
return;
}
final int lastIdx = size - 1;
for (int i = 0; i < size; i++) {
Cursor curr = cursors.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,41 @@ public void endToEnd() throws Exception {
assertEquals(expected, allValues);
}

@Test
public void endToEnd_emptyCursors() throws Exception {
// First page of the response
PartitionQueryRequest request1 =
PartitionQueryRequest.newBuilder()
.setParent(String.format("projects/%s/databases/(default)/document", projectId))
.build();
PartitionQueryResponse response1 = PartitionQueryResponse.newBuilder().build();
when(callable.call(request1)).thenReturn(pagedResponse1);
when(page1.getResponse()).thenReturn(response1);
when(pagedResponse1.iteratePages()).thenReturn(ImmutableList.of(page1));

when(stub.partitionQueryPagedCallable()).thenReturn(callable);

when(ff.getFirestoreStub(any())).thenReturn(stub);
RpcQosOptions options = RpcQosOptions.defaultOptions();
when(ff.getRpcQos(any()))
.thenReturn(FirestoreStatefulComponentFactory.INSTANCE.getRpcQos(options));

ArgumentCaptor<PartitionQueryPair> responses =
ArgumentCaptor.forClass(PartitionQueryPair.class);

doNothing().when(processContext).output(responses.capture());

when(processContext.element()).thenReturn(request1);

PartitionQueryFn fn = new PartitionQueryFn(clock, ff, options);

runFunction(fn);

List<PartitionQueryPair> expected = newArrayList(new PartitionQueryPair(request1, response1));
List<PartitionQueryPair> allValues = responses.getAllValues();
assertEquals(expected, allValues);
}

@Override
public void resumeFromLastReadValue() throws Exception {
when(ff.getFirestoreStub(any())).thenReturn(stub);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,39 @@ public void ensureCursorPairingWorks() {
assertEquals(expectedQueries, actualQueries);
}

@Test
public void ensureCursorPairingWorks_emptyCursorsInResponse() {
StructuredQuery query =
StructuredQuery.newBuilder()
.addFrom(
CollectionSelector.newBuilder()
.setAllDescendants(true)
.setCollectionId("c1")
.build())
.build();

List<StructuredQuery> expectedQueries = newArrayList(query);

PartitionQueryPair partitionQueryPair =
new PartitionQueryPair(
PartitionQueryRequest.newBuilder().setStructuredQuery(query).build(),
PartitionQueryResponse.newBuilder().build());

ArgumentCaptor<RunQueryRequest> captor = ArgumentCaptor.forClass(RunQueryRequest.class);
when(processContext.element()).thenReturn(partitionQueryPair);
doNothing().when(processContext).output(captor.capture());

PartitionQueryResponseToRunQueryRequest fn = new PartitionQueryResponseToRunQueryRequest();
fn.processElement(processContext);

List<StructuredQuery> actualQueries =
captor.getAllValues().stream()
.map(RunQueryRequest::getStructuredQuery)
.collect(Collectors.toList());

assertEquals(expectedQueries, actualQueries);
}

private static Cursor referenceValueCursor(String referenceValue) {
return Cursor.newBuilder()
.addValues(Value.newBuilder().setReferenceValue(referenceValue).build())
Expand Down