Skip to content

Commit b925bc2

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 17079 b: refs/heads/autosynth-redis c: a1679e4 h: refs/heads/master i: 17077: b880d72 17075: 9e6417f 17071: 1ad7b82
1 parent 07a1367 commit b925bc2

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ refs/heads/autosynth-iot: f16fc4ba85bbb37eacecb64a2a7336f685813f6c
137137
refs/heads/autosynth-kms: 4fff8f3cf6c830f7706ac4ef272f036bb87fbaf8
138138
refs/heads/autosynth-language: 6262e2eb76944f01972c887b3e684aaf65ec999a
139139
refs/heads/autosynth-os-login: a88a337797996a205873040a63abe1d3116f5789
140-
refs/heads/autosynth-redis: 07ab94105146ef83558985e100ac86ef2785a11c
140+
refs/heads/autosynth-redis: a1679e4551b3bc0f9f78db47cc0e7747121a88cf
141141
refs/heads/autosynth-scheduler: 2f0fe714a8541dc72f88b45bddd8748e5f21cf29
142142
refs/heads/autosynth-securitycenter: 8e95447ccb176c3648880ee0cb926cd1f4065156
143143
refs/heads/autosynth-spanner: 563dc6c78c6a2579b681f441f0a9b59005212394

branches/autosynth-redis/google-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.datastore;
1818

19+
import com.google.datastore.v1.QueryResultBatch;
1920
import java.util.Iterator;
2021

2122
/**
@@ -66,4 +67,7 @@ public interface QueryResults<V> extends Iterator<V> {
6667
* }</pre>
6768
*/
6869
int getSkippedResults();
70+
71+
/** Returns MoreResults state of the query after the current batch. */
72+
QueryResultBatch.MoreResultsType getMoreResults();
6973
}

branches/autosynth-redis/google-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResultsImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class QueryResultsImpl<T> extends AbstractIterator<T> implements QueryResults<T>
3737
private boolean lastBatch;
3838
private Iterator<com.google.datastore.v1.EntityResult> entityResultPbIter;
3939
private ByteString cursor;
40+
private MoreResultsType moreResults;
4041

4142
QueryResultsImpl(
4243
DatastoreImpl datastore, com.google.datastore.v1.ReadOptions readOptionsPb, Query<T> query) {
@@ -74,7 +75,8 @@ private void sendRequest() {
7475
if (mostRecentQueryPb == null) {
7576
mostRecentQueryPb = requestPb.getQuery();
7677
}
77-
lastBatch = runQueryResponsePb.getBatch().getMoreResults() != MoreResultsType.NOT_FINISHED;
78+
moreResults = runQueryResponsePb.getBatch().getMoreResults();
79+
lastBatch = moreResults != MoreResultsType.NOT_FINISHED;
7880
entityResultPbIter = runQueryResponsePb.getBatch().getEntityResultsList().iterator();
7981
actualResultType = ResultType.fromPb(runQueryResponsePb.getBatch().getEntityResultType());
8082
if (Objects.equals(queryResultType, ResultType.PROJECTION_ENTITY)) {
@@ -117,4 +119,9 @@ public Cursor getCursorAfter() {
117119
public int getSkippedResults() {
118120
return runQueryResponsePb.getBatch().getSkippedResults();
119121
}
122+
123+
@Override
124+
public MoreResultsType getMoreResults() {
125+
return moreResults;
126+
}
120127
}

branches/autosynth-redis/google-cloud-clients/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,26 @@ public void testStructuredQueryPagination() throws DatastoreException {
585585
EasyMock.verify(rpcFactoryMock, rpcMock);
586586
}
587587

588+
@Test
589+
public void testStructuredQueryPaginationWithMoreResults() throws DatastoreException {
590+
List<RunQueryResponse> responses = buildResponsesForQueryPagination();
591+
for (int i = 0; i < responses.size(); i++) {
592+
EasyMock.expect(rpcMock.runQuery(EasyMock.anyObject(RunQueryRequest.class)))
593+
.andReturn(responses.get(i));
594+
}
595+
EasyMock.replay(rpcFactoryMock, rpcMock);
596+
Datastore datastore = rpcMockOptions.getService();
597+
QueryResults<Key> results = datastore.run(Query.newKeyQueryBuilder().build());
598+
int count = 0;
599+
while (results.hasNext()) {
600+
count += 1;
601+
results.next();
602+
}
603+
assertEquals(count, 5);
604+
assertEquals(QueryResultBatch.MoreResultsType.NO_MORE_RESULTS, results.getMoreResults());
605+
EasyMock.verify(rpcFactoryMock, rpcMock);
606+
}
607+
588608
private List<RunQueryResponse> buildResponsesForQueryPagination() {
589609
Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build();
590610
Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build();

0 commit comments

Comments
 (0)