use of com.google.appengine.api.datastore.Query 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.Query 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.Query 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.Query in project iosched by google.
the class ServingUrlManagerTest method testGetServingUrl_withSourceUrl.
@Test
public void testGetServingUrl_withSourceUrl() throws Exception {
PreparedQuery mockPreparedQuery = mock(PreparedQuery.class);
when(mockDatastoreService.prepare(any(Query.class))).thenReturn(mockPreparedQuery);
when(mockPreparedQuery.asList(any(FetchOptions.class))).thenAnswer(new Answer<List<Entity>>() {
@Override
public List<Entity> answer(InvocationOnMock invocation) throws Throwable {
Key key = mock(Key.class);
when(key.getKind()).thenReturn(ServingUrlManager.ENTITY_KIND);
when(key.getName()).thenReturn(GCS_FULLPATH);
Entity entity = new Entity(key);
entity.setProperty(ServingUrlManager.SERVING_URL_PROPERTY, SERVING_URL);
return new ArrayList<>(Arrays.asList(entity));
}
});
assertEquals(SERVING_URL, ServingUrlManager.INSTANCE.getServingUrl(SOURCE_URL));
ArgumentCaptor<Query> queryCaptor = ArgumentCaptor.forClass(Query.class);
verify(mockDatastoreService).prepare(queryCaptor.capture());
Query query = queryCaptor.getValue();
assertEquals(ServingUrlManager.ENTITY_KIND, query.getKind());
assertEquals(new FilterPredicate(ServingUrlManager.SOURCE_URL_PROPERTY, FilterOperator.EQUAL, SOURCE_URL), query.getFilter());
}
use of com.google.appengine.api.datastore.Query in project CodeU-Spring-2018 by maksymko.
the class PersistentDataStore method loadUsers.
/**
* Loads all User objects from the Datastore service and returns them in a List.
*
* @throws PersistentDataStoreException if an error was detected during the load from the
* Datastore service
*/
public List<User> loadUsers() throws PersistentDataStoreException {
List<User> users = new ArrayList<>();
// Retrieve all users from the datastore.
Query query = new Query("chat-users");
PreparedQuery results = datastore.prepare(query);
for (Entity entity : results.asIterable()) {
try {
UUID uuid = UUID.fromString((String) entity.getProperty("uuid"));
String userName = (String) entity.getProperty("username");
String password = (String) entity.getProperty("password");
Instant creationTime = Instant.parse((String) entity.getProperty("creation_time"));
User user = new User(uuid, userName, password, creationTime);
users.add(user);
} catch (Exception e) {
// database entity definition mismatches, or service mismatches.
throw new PersistentDataStoreException(e);
}
}
return users;
}
Aggregations