use of com.google.appengine.api.datastore.DatastoreService in project java-docs-samples by GoogleCloudPlatform.
the class LocalDatastoreTest method doTest.
// Run this test twice to prove we're not leaking any state across tests.
private void doTest() {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
ds.put(new Entity("yam"));
ds.put(new Entity("yam"));
assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
}
use of com.google.appengine.api.datastore.DatastoreService in project java-docs-samples by GoogleCloudPlatform.
the class ShortTest method testDisabledDatastore.
@Test(expected = ApiProxy.CapabilityDisabledException.class)
public void testDisabledDatastore() {
Capability testOne = new Capability("datastore_v3");
CapabilityStatus testStatus = CapabilityStatus.DISABLED;
// Initialize the test configuration.
LocalCapabilitiesServiceTestConfig config = new LocalCapabilitiesServiceTestConfig().setCapabilityStatus(testOne, testStatus);
helper = new LocalServiceTestHelper(config);
helper.setUp();
FetchOptions fo = FetchOptions.Builder.withLimit(10);
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
assertEquals(0, ds.prepare(new Query("yam")).countEntities(fo));
}
use of com.google.appengine.api.datastore.DatastoreService in project java-docs-samples by GoogleCloudPlatform.
the class LocalCustomPolicyHighRepDatastoreTest method testEventuallyConsistentGlobalQueryResult.
@Test
public void testEventuallyConsistentGlobalQueryResult() {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
// applies
ds.put(new Entity("yam"));
// does not apply
ds.put(new Entity("yam"));
// First global query only sees the first Entity.
assertEquals(1, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
// Second global query sees both Entities because we "groom" (attempt to
// apply unapplied jobs) after every query.
assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
}
use of com.google.appengine.api.datastore.DatastoreService 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());
assertWithMessage("query results").that(results).isEmpty();
}
use of com.google.appengine.api.datastore.DatastoreService 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());
assertWithMessage("query results").that(results).hasSize(2);
}
Aggregations