Skip to content

Commit 90c3da6

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 13827 b: refs/heads/autosynth-logging c: a1679e4 h: refs/heads/master i: 13825: 2bc4ec4 13823: 0d10c48
1 parent af97808 commit 90c3da6

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
@@ -105,7 +105,7 @@ refs/tags/v0.61.0: e4b526656bb1bf5eefd0ee578b7405147821225e
105105
refs/tags/v0.62.0: bbede7385d48ba08f487bdd29ec10668ace96396
106106
refs/heads/0.60.0-alpha: 10939381ffe0b8da32db4fe3087c86e3aa7f3e55
107107
refs/heads/autosynth-dlp: 90e4efe3be392e89dc36bce22afab981a905b1bc
108-
refs/heads/autosynth-logging: 07ab94105146ef83558985e100ac86ef2785a11c
108+
refs/heads/autosynth-logging: a1679e4551b3bc0f9f78db47cc0e7747121a88cf
109109
refs/heads/dupes: 3478c5d81fd242d0e985656645a679420a2060c2
110110
refs/tags/v0.63.0: 94f19b71d40f46b36120e7b9d78a1a3d41bfcbd6
111111
refs/tags/v0.64.0: 456e8fbd129deced3ca025f239a2d8a82bde1d0a

branches/autosynth-logging/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-logging/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-logging/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)