use of com.google.appengine.api.datastore.ReadPolicy in project java-docs-samples by GoogleCloudPlatform.
the class ReadPolicyTest method readPolicy_strong_returnsAllResults.
@Test
public void readPolicy_strong_returnsAllResults() {
double deadline = 5.0;
ReadPolicy policy = new ReadPolicy(ReadPolicy.Consistency.STRONG);
DatastoreServiceConfig datastoreConfig = DatastoreServiceConfig.Builder.withReadPolicy(policy).deadline(deadline);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(datastoreConfig);
Entity parent = new Entity("Person", "a");
Entity child = new Entity("Person", "b", parent.getKey());
datastore.put(ImmutableList.<Entity>of(parent, child));
Query q = new Query("Person").setAncestor(parent.getKey());
List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
assertThat(results).named("query results").hasSize(2);
}
use of com.google.appengine.api.datastore.ReadPolicy in project java-docs-samples by GoogleCloudPlatform.
the class ReadPolicyTest method readPolicy_eventual_returnsNoResults.
@Test
public void readPolicy_eventual_returnsNoResults() {
// [START data_consistency]
double deadline = 5.0;
// Construct a read policy for eventual consistency
ReadPolicy policy = new ReadPolicy(ReadPolicy.Consistency.EVENTUAL);
// Set the read policy
DatastoreServiceConfig eventuallyConsistentConfig = DatastoreServiceConfig.Builder.withReadPolicy(policy);
// Set the call deadline
DatastoreServiceConfig deadlineConfig = DatastoreServiceConfig.Builder.withDeadline(deadline);
// Set both the read policy and the call deadline
DatastoreServiceConfig datastoreConfig = DatastoreServiceConfig.Builder.withReadPolicy(policy).deadline(deadline);
// Get Datastore service with the given configuration
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(datastoreConfig);
// [END data_consistency]
Entity parent = new Entity("Person", "a");
Entity child = new Entity("Person", "b", parent.getKey());
datastore.put(ImmutableList.<Entity>of(parent, child));
// Even though we are using an ancestor query, the policy is set to
// eventual, so we should get eventually-consistent results. Since the
// local data store test config is set to 100% unapplied jobs, there
// should be no results.
Query q = new Query("Person").setAncestor(parent.getKey());
List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
assertThat(results).named("query results").isEmpty();
}
use of com.google.appengine.api.datastore.ReadPolicy in project qi4j-sdk by Qi4j.
the class GaeEntityStoreMixin method activateGaeEntityStore.
@Override
public void activateGaeEntityStore() throws Exception {
GaeEntityStoreConfiguration conf = config.get();
// eventually consistent reads with a 5 second deadline
DatastoreServiceConfig configuration = withReadPolicy(new ReadPolicy(ReadPolicy.Consistency.valueOf(conf.readPolicy().get().toUpperCase()))).deadline(conf.deadline().get());
datastore = DatastoreServiceFactory.getDatastoreService(configuration);
entityKind = conf.entityKind().get();
System.out.println("\nActivating Google App Engine Store" + "\n----------------------------------" + "\n Read Policy: " + conf.readPolicy().get() + "\n Deadline: " + conf.deadline().get() + "\n Entity Kind: " + entityKind + "\n Datastore: " + datastore + "\n Configuration: " + configuration + "\n");
}
Aggregations