rawKeys.add(obKey.getRaw()); Future<Map<com.google.appengine.api.datastore.Key, Entity>> futureEntities = this.ads.get(this.txn, rawKeys); Future<Map<Key<T>, T>> wrapped = new SimpleFutureWrapper<Map<com.google.appengine.api.datastore.Key, Entity>, Map<Key<T>, T>>(futureEntities) { @Override
protected Entity getSingleEntity(AsyncDatastoreService ds, Key key) { Map<Key, Entity> map = waitOnFuture(ds.get(Collections.singleton(key))); return (map.isEmpty() ? null : map.values().iterator().next()); }
public Void run(AsyncDatastoreService ads) throws Exception { Key key = k1.get(); Assert.assertNotNull(key); Future<Entity> fe1 = ads.get(key); Assert.assertNotNull(fe1); Assert.assertEquals(e1, fe1.get()); return null; } };
@Override public <T> FutureObject<T> fetchAsync(IdRef<T> id) { Key key = IdRefToKey.toKey(r, id); Future<Entity> futureEntity = asyncDatastore().get(key); return new FutureObject<>(r, new FutureEntityToObject(r, id.getClazz(), futureEntity)); }
@Test public void testDataGet() throws Exception { long randomLong = new Random().nextLong(); Entity newRec = new Entity(ASYNC_ENTITY); newRec.setProperty("count", randomLong); newRec.setProperty("timestamp", new Date()); Key ekey = service.put(newRec); Future<Entity> futureE = asyncService.get(ekey); Entity e = futureE.get(); if (e != null) { assertEquals(randomLong, e.getProperty("count")); } }
@Test public void testMultipleDataGet() throws Exception { Entity parent = createTestEntityWithUniqueMethodNameKey(ASYNC_ENTITY, "testMultipleDataGet"); Key key = parent.getKey(); final int recordCount = 10; List<Entity> lisRec = new ArrayList<Entity>(); for (int i = 0; i < recordCount; i++) { Entity newRec = new Entity(ASYNC_ENTITY, key); newRec.setProperty("count", i); newRec.setProperty("timestamp", new Date()); lisRec.add(newRec); } List<Key> eKeys = service.put(lisRec); Future<Map<Key, Entity>> futureKeyEntity = asyncService.get(eKeys); Map<Key, Entity> es = futureKeyEntity.get(); assertTaskIsDoneAndNotCancelled(futureKeyEntity); assertEquals(recordCount, es.size()); asyncService.delete(eKeys); }
@Test public void testCRUD() throws Exception { AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService(); Entity e1 = new Entity("ASYNC"); e1.setProperty("foo", "bar"); Future<Key> k1 = service.put(e1); Assert.assertNotNull(k1); Key key = k1.get(); Assert.assertNotNull(key); Future<Entity> fe1 = service.get(key); Assert.assertNotNull(fe1); Assert.assertEquals(e1, fe1.get()); Future<Void> fd1 = service.delete(key); Assert.assertNotNull(fd1); fd1.get(); assertStoreDoesNotContain(key); }