/** * You can override this to add behavior at the raw datastoreservice level. */ protected AsyncDatastoreService getRawAsyncDatastoreService(DatastoreServiceConfig cfg) { return DatastoreServiceFactory.getAsyncDatastoreService(cfg); }
private AsyncDatastoreService asyncDatastore() { if (asyncDs == null) { asyncDs = DatastoreServiceFactory.getAsyncDatastoreService(); } return asyncDs; }
private AsyncDatastoreService asyncDatastore() { return DatastoreServiceFactory.getAsyncDatastoreService(); }
/** * Get a caching AsyncDatastoreService that uses a particular EntityMemcache configuration. * Ignores the default memcacheService for this factory; that is set when you construct * your EntityMemcache. */ public static CachingAsyncDatastoreService getAsyncDatastoreService(DatastoreServiceConfig cfg, EntityMemcache em) { AsyncDatastoreService ads = DatastoreServiceFactory.getAsyncDatastoreService(cfg); return new CachingAsyncDatastoreService(ads, em); }
/** * Get a caching AsyncDatastoreService that uses a particular EntityMemcache configuration. * Ignores the default memcacheService for this factory; that is set when you construct * your EntityMemcache. */ public static CachingAsyncDatastoreService getAsyncDatastoreService(EntityMemcache em) { AsyncDatastoreService ads = DatastoreServiceFactory.getAsyncDatastoreService(); return new CachingAsyncDatastoreService(ads, em); }
@Test(expected = IllegalArgumentException.class) public void testTranManagePolicyAsyncInvalidConfig() { DatastoreServiceConfig config = DatastoreServiceConfig.Builder.withImplicitTransactionManagementPolicy(ImplicitTransactionManagementPolicy.AUTO); // Async Service does not support AUTO DatastoreServiceFactory.getAsyncDatastoreService(config); } }
@Test public void testFutureCancel() { clearData(); AsyncDatastoreService asyncService = DatastoreServiceFactory.getAsyncDatastoreService(); Entity newRec = new Entity(ASYNC_ENTITY); newRec.setProperty("count", -1); newRec.setProperty("timestamp", new Date()); Future<Key> future = asyncService.put(newRec); future.cancel(true); // The actual call may already succeeded, so just verify that cancel has been called. assertTrue(future.isCancelled()); }
@Before public void clearData() { asyncService = DatastoreServiceFactory.getAsyncDatastoreService(); List<Key> elist = new ArrayList<Key>(); Query query = new Query(ASYNC_ENTITY); for (Entity readRec : service.prepare(query).asIterable()) { elist.add(readRec.getKey()); } service.delete(elist); }
protected <T> T inTx(Action<T> action) throws Exception { AsyncDatastoreService ads = DatastoreServiceFactory.getAsyncDatastoreService(); Transaction tx = ads.beginTransaction().get(); boolean ok = false; try { T result = action.run(ads); ok = true; return result; } finally { if (ok) tx.commitAsync(); else tx.rollbackAsync(); sync(); // wait for tx to finish } }
@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); }
@Test public void testRollbackTx() throws Exception { AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService(); Transaction tx = waitOnFuture(service.beginTransaction(TransactionOptions.Builder.withDefaults())); Key key = null; try { Future<Key> fKey = service.put(tx, new Entity("AsyncTx")); key = waitOnFuture(fKey); } finally { waitOnFuture(tx.rollbackAsync()); } if (key != null) { Assert.assertNull(getSingleEntity(service, key)); } } }
@Test public void testCommitTx() throws Exception { AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService(); Transaction tx = waitOnFuture(service.beginTransaction(TransactionOptions.Builder.withDefaults())); Key key; try { Future<Key> fKey = service.put(tx, new Entity("AsyncTx")); key = waitOnFuture(fKey); waitOnFuture(tx.commitAsync()); } catch (Exception e) { waitOnFuture(tx.rollbackAsync()); throw e; } if (key != null) { Assert.assertNotNull(getSingleEntity(service, key)); } }
@Test public void testBeginTx() throws Exception { final AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService();
@Test public void testMiscOps() throws Exception { AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService(); DatastoreAttributes attributes = waitOnFuture(service.getDatastoreAttributes()); Assert.assertNotNull(attributes); Assert.assertNotNull(attributes.getDatastoreType()); Map<Index, Index.IndexState> indexes = waitOnFuture(service.getIndexes()); Assert.assertNotNull(indexes); Transaction tx = waitOnFuture(service.beginTransaction()); try { String txId = tx.getId(); Assert.assertNotNull(txId); Assert.assertEquals(txId, tx.getId()); String appId = tx.getApp(); Assert.assertNotNull(appId); Assert.assertEquals(appId, tx.getApp()); } finally { tx.rollback(); } }