{
groupIncreaser++;
CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
ReplicationListener replListener = new ReplicationListener(cache);
CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
LockManager lockManager = TestingUtil.extractLockManager(cache);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
mgr.begin();
Transaction tx = mgr.getTransaction();
assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
mgr.suspend();
assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionContext entry = (OptimisticTransactionContext) table.get(gtx);
assertEquals(3, entry.getTransactionWorkSpace().getNodes().size());
assertNull(mgr.getTransaction());
mgr.begin();
SamplePojo pojo2 = new SamplePojo(22, "test2");
cache2.put("/one/two", "key1", pojo2);
mgr.commit();
// let async calls propagate
TestingUtil.sleepThread((long) 1000);
assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
mgr.resume(tx);
try
{
mgr.commit();
assert false : "Expecting an exception";
}
catch (RollbackException expected)
{
// this is good
}
assertNull(mgr.getTransaction());
assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertEquals(0, entry.getTransactionWorkSpace().getNodes().size());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getNode("/one"));
assertEquals(false, lockManager.isLocked(cache.getRoot()));
assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
destroyCache(cache2);