Java Code Examples for com.google.appengine.api.datastore.DatastoreServiceFactory#getAsyncDatastoreService()

The following examples show how to use com.google.appengine.api.datastore.DatastoreServiceFactory#getAsyncDatastoreService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionsTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 2
Source File: AsyncTestBase.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
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
    }
}
 
Example 3
Source File: AsyncTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: AsyncTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@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));
    }
}
 
Example 5
Source File: AsyncTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@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));
    }
}
 
Example 6
Source File: AsyncTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testBeginTx() throws Exception {
    final AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService();

    Transaction tx = waitOnFuture(service.beginTransaction(TransactionOptions.Builder.withXG(true)));
    Key key, key2;
    try {
        key = waitOnFuture(service.put(tx, new Entity("AsyncTx")));
        key2 = waitOnFuture(service.put(tx, new Entity("AsyncTx")));
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e;
    }

    if (key != null && key2 != null) {
        tx = waitOnFuture(service.beginTransaction(TransactionOptions.Builder.withXG(true)));
        try {
            try {
                try {
                    Assert.assertNotNull(waitOnFuture(service.get(tx, key)));
                    Assert.assertNotNull(waitOnFuture(service.get(tx, Collections.singleton(key2))));
                } finally {
                    service.delete(tx, key2);
                }
            } finally {
                service.delete(tx, Collections.singleton(key));
            }
        } finally {
            tx.rollback();
        }
    }
}
 
Example 7
Source File: AsyncServiceTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: AsyncServiceTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 9
Source File: ConfigTest.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testTranManagePolicyAsyncInvalidConfig() {
    DatastoreServiceConfig config = DatastoreServiceConfig.Builder.withImplicitTransactionManagementPolicy(ImplicitTransactionManagementPolicy.AUTO);
    // Async Service does not support AUTO
    DatastoreServiceFactory.getAsyncDatastoreService(config);
}