use of org.apache.ignite.testframework.GridTestSafeThreadFactory in project ignite by apache.
the class AbstractCacheJtaSelfTest method testAsyncOpAwait.
/**
* @throws Exception If failed.
*/
public void testAsyncOpAwait() throws Exception {
final IgniteCache<String, Integer> cache = jcache();
GridTestSafeThreadFactory factory = new GridTestSafeThreadFactory("JtaThread");
final CountDownLatch latch = new CountDownLatch(1);
Callable<Object> c = new Callable<Object>() {
@Override
public Object call() throws Exception {
assertNull(grid(0).transactions().tx());
UserTransaction jtaTx = jotm.getUserTransaction();
jtaTx.begin();
try {
cache.put("key1", 1);
cache.putAsync("key", 1);
assertEquals(grid(0).transactions().tx().state(), ACTIVE);
latch.countDown();
info("Before JTA commit.");
} finally {
jtaTx.commit();
}
info("After JTA commit.");
assertEquals((Integer) 1, cache.get("key"));
return null;
}
};
Thread task = factory.newThread(c);
try (Transaction tx = ignite(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
cache.put("key", 0);
task.start();
latch.await();
while (task.getState() != Thread.State.WAITING) factory.checkError();
info("Before cache TX commit.");
tx.commit();
}
}
Aggregations