Java Code Examples for com.google.datastore.v1.RunQueryResponse#Builder
The following examples show how to use
com.google.datastore.v1.RunQueryResponse#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatastoreV1Test.java From beam with Apache License 2.0 | 5 votes |
/** * A helper function that creates mock {@link Entity} results in response to a query. Always * indicates that more results are available, unless the batch is limited to fewer than {@link * DatastoreV1.Read#QUERY_BATCH_LIMIT} results. */ private static RunQueryResponse mockResponseForQuery(Query q) { // Every query DatastoreV1 sends should have a limit. assertTrue(q.hasLimit()); // The limit should be in the range [1, QUERY_BATCH_LIMIT] int limit = q.getLimit().getValue(); assertThat(limit, greaterThanOrEqualTo(1)); assertThat(limit, lessThanOrEqualTo(QUERY_BATCH_LIMIT)); // Create the requested number of entities. List<EntityResult> entities = new ArrayList<>(limit); for (int i = 0; i < limit; ++i) { entities.add( EntityResult.newBuilder() .setEntity(Entity.newBuilder().setKey(makeKey("key" + i, i + 1))) .build()); } // Fill out the other parameters on the returned result batch. RunQueryResponse.Builder ret = RunQueryResponse.newBuilder(); ret.getBatchBuilder() .addAllEntityResults(entities) .setEntityResultType(EntityResult.ResultType.FULL) .setMoreResults( limit == QUERY_BATCH_LIMIT ? QueryResultBatch.MoreResultsType.NOT_FINISHED : QueryResultBatch.MoreResultsType.NO_MORE_RESULTS); return ret.build(); }
Example 2
Source File: DatastoreV1Test.java From beam with Apache License 2.0 | 5 votes |
/** Builds a per-kind statistics response with the given entity size. */ private static RunQueryResponse makeStatKindResponse(long entitySizeInBytes) { RunQueryResponse.Builder statKindResponse = RunQueryResponse.newBuilder(); Entity.Builder entity = Entity.newBuilder(); entity.setKey(makeKey("dummyKind", "dummyId")); entity.putProperties("entity_bytes", makeValue(entitySizeInBytes).build()); EntityResult.Builder entityResult = EntityResult.newBuilder(); entityResult.setEntity(entity); QueryResultBatch.Builder batch = QueryResultBatch.newBuilder(); batch.addEntityResults(entityResult); statKindResponse.setBatch(batch); return statKindResponse.build(); }
Example 3
Source File: DatastoreV1Test.java From beam with Apache License 2.0 | 5 votes |
/** Builds a response of the given timestamp. */ private static RunQueryResponse makeLatestTimestampResponse(long timestamp) { RunQueryResponse.Builder timestampResponse = RunQueryResponse.newBuilder(); Entity.Builder entity = Entity.newBuilder(); entity.setKey(makeKey("dummyKind", "dummyId")); entity.putProperties("timestamp", makeValue(new Date(timestamp * 1000)).build()); EntityResult.Builder entityResult = EntityResult.newBuilder(); entityResult.setEntity(entity); QueryResultBatch.Builder batch = QueryResultBatch.newBuilder(); batch.addEntityResults(entityResult); timestampResponse.setBatch(batch); return timestampResponse.build(); }
Example 4
Source File: DatastoreTest.java From google-cloud-datastore with Apache License 2.0 | 5 votes |
@Test public void runQuery() throws Exception { RunQueryRequest.Builder request = RunQueryRequest.newBuilder(); request.getQueryBuilder(); RunQueryResponse.Builder response = RunQueryResponse.newBuilder(); response.getBatchBuilder() .setEntityResultType(EntityResult.ResultType.FULL) .setMoreResults(QueryResultBatch.MoreResultsType.NOT_FINISHED); expectRpc("runQuery", request.build(), response.build()); }