AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY);
atomicMap.put(1, "existing");
tm().begin();
atomicMap.put(1, "newVal");
final ValueFuture responseBeforeCommit = new ValueFuture();
final ValueFuture responseAfterCommit = new ValueFuture();
final CountDownLatch commitLatch = new CountDownLatch(1);
Future<Object> future = fork(new Callable<Object>() {
@Override
public Object call() throws Exception {
tm().begin();
try {
AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY);
responseBeforeCommit.set(otMap.get(1));
// wait until the main thread commits the transaction
commitLatch.await();
responseAfterCommit.set(otMap.get(1));
} finally {
tm().rollback();
}
return null;
}
});
assertEquals(responseBeforeCommit.get(), "existing");
tm().commit();
commitLatch.countDown();
future.get(10, TimeUnit.SECONDS);
assertEquals(atomicMap.get(1), "newVal");
assertEquals(responseAfterCommit.get(), "newVal");
}