Thread t = new Thread() {
@Override
public void run() {
log.info("Concurrent " + (useTx ? "tx" : "non-tx") + " write started "
+ (sameNode ? "on same node..." : "on a different node..."));
DummyTransactionManager mgr = null;
try {
if (useTx) {
mgr = (DummyTransactionManager) TestingUtil.getTransactionManager(sameNode ? cache1 : cache2);
mgr.begin();
}
if (sameNode) {
cache1.put(k, "JBC");
} else {
cache2.put(k, "JBC");
}
if (useTx) {
if (!mgr.getTransaction().runPrepare()) { //couldn't prepare
latch.countDown();
mgr.rollback();
}
}
} catch (Exception e) {
if (useTx) {
try {
mgr.commit();
} catch (Exception e1) {
}
}
latch.countDown();
}
}
};
String name = "Infinispan";
TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
mgr.begin();
log.trace("Here is where the fun starts...Here is where the fun starts...");
// lock node and start other thread whose write should now block
cache1.getAdvancedCache().lock(k);
t.start();
// wait till the put in thread t times out
assert latch.await(10, TimeUnit.SECONDS) : "Concurrent put didn't time out!";
cache1.put(k, name);
mgr.commit();
assertNotLocked("testcache", k);
t.join();