});
}
private void assertExpectedBehavior(CacheOperation op) throws Exception {
LockManager lm = TestingUtil.extractLockManager(cache);
TransactionTable txTable = TestingUtil.getTransactionTable(cache);
TransactionManager tm = cache.getAdvancedCache().getTransactionManager();
tm.begin();
cache.put("k1", "v1");
Transaction k1LockOwner = tm.suspend();
assert lm.isLocked("k1");
assertEquals(1, txTable.getLocalTxCount());
tm.begin();
cache.put("k2", "v2");
assert lm.isLocked("k2");
assertEquals(2, txTable.getLocalTxCount());
assert tm.getTransaction() != null;
try {
op.execute();
assert false : "Timeout exception expected";
} catch (TimeoutException e) {
//expected
}
//make sure that locks acquired by that tx were released even before the transaction is rolled back, the tx object
//was marked for rollback
Transaction transaction = tm.getTransaction();
assert transaction != null;
assert transaction.getStatus() == Status.STATUS_MARKED_ROLLBACK;
assert !lm.isLocked("k2");
assert lm.isLocked("k1");
try {
cache.put("k3", "v3");
assert false;
} catch (IllegalStateException e) {
//expected
}
assertEquals(txTable.getLocalTxCount(), 2);
//now the TM is expected to rollback the tx
tm.rollback();
assertEquals(txTable.getLocalTxCount(), 1);
tm.resume(k1LockOwner);
tm.commit();
//now test that the other tx works as expected
assertEquals(0, txTable.getLocalTxCount());
assertEquals(cache.get("k1"), "v1");
assert !lm.isLocked("k1");
assertEquals(txTable.getLocalTxCount(), 0);
}