Search in sources :

Example 1 with ReadOptions

use of com.google.datastore.v1.ReadOptions in project google-cloud-java by GoogleCloudPlatform.

the class DatastoreTest method testLookupEventualConsistency.

@Test
public void testLookupEventualConsistency() {
    ReadOptions readOption = ReadOptions.newBuilder().setReadConsistencyValue(ReadConsistency.EVENTUAL_VALUE).build();
    com.google.datastore.v1.Key key = com.google.datastore.v1.Key.newBuilder().setPartitionId(PartitionId.newBuilder().setProjectId(PROJECT_ID).build()).addPath(com.google.datastore.v1.Key.PathElement.newBuilder().setKind("kind1").setName("name").build()).build();
    LookupRequest lookupRequest = LookupRequest.newBuilder().setReadOptions(readOption).addKeys(key).build();
    EasyMock.expect(rpcMock.lookup(lookupRequest)).andReturn(LookupResponse.newBuilder().build()).times(3);
    EasyMock.replay(rpcFactoryMock, rpcMock);
    Datastore datastore = rpcMockOptions.getService();
    datastore.get(KEY1, ReadOption.eventualConsistency());
    datastore.get(ImmutableList.of(KEY1), ReadOption.eventualConsistency());
    datastore.fetch(ImmutableList.of(KEY1), ReadOption.eventualConsistency());
    EasyMock.verify(rpcFactoryMock, rpcMock);
}
Also used : ReadOptions(com.google.datastore.v1.ReadOptions) LookupRequest(com.google.datastore.v1.LookupRequest) Test(org.junit.Test)

Example 2 with ReadOptions

use of com.google.datastore.v1.ReadOptions in project google-cloud-java by GoogleCloudPlatform.

the class DatastoreTest method testEventualConsistencyQuery.

@Test
public void testEventualConsistencyQuery() {
    ReadOptions readOption = ReadOptions.newBuilder().setReadConsistencyValue(ReadConsistency.EVENTUAL_VALUE).build();
    com.google.datastore.v1.GqlQuery query = com.google.datastore.v1.GqlQuery.newBuilder().setQueryString("FROM * SELECT *").build();
    RunQueryRequest.Builder expectedRequest = RunQueryRequest.newBuilder().setReadOptions(readOption).setGqlQuery(query).setPartitionId(PartitionId.newBuilder().setProjectId(PROJECT_ID).build());
    EasyMock.expect(rpcMock.runQuery(expectedRequest.build())).andReturn(RunQueryResponse.newBuilder().build());
    EasyMock.replay(rpcFactoryMock, rpcMock);
    Datastore datastore = rpcMockOptions.getService();
    datastore.run(Query.newGqlQueryBuilder("FROM * SELECT *").build(), ReadOption.eventualConsistency());
    EasyMock.verify(rpcFactoryMock, rpcMock);
}
Also used : ReadOptions(com.google.datastore.v1.ReadOptions) RunQueryRequest(com.google.datastore.v1.RunQueryRequest) Test(org.junit.Test)

Aggregations

ReadOptions (com.google.datastore.v1.ReadOptions)2 Test (org.junit.Test)2 LookupRequest (com.google.datastore.v1.LookupRequest)1 RunQueryRequest (com.google.datastore.v1.RunQueryRequest)1