}
public void testPessimisticTransactional() throws Exception
{
TreeCache cache1 = createCache(false);
TreeCache cache2 = createCache(false);
Fqn fqn = Fqn.fromString("/a/b");
cache1.put(fqn, "key", "value");
// test that this has NOT replicated, but rather has been invalidated:
Assert.assertEquals("value", cache1.get(fqn, "key"));
Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));
log.info("***** Node not replicated, as expected.");
// now make sure cache2 is in sync with cache1:
// make sure this is in a tx
TransactionManager txm = cache2.getTransactionManager();
Assert.assertEquals("value", cache1.get(fqn, "key"));
txm.begin();
cache2.put(fqn, "key", "value");
Assert.assertEquals("value", cache2.get(fqn, "key"));
txm.commit();
Assert.assertNull("Should be null", cache1.get(fqn));
Assert.assertEquals("value", cache2.get(fqn, "key"));
// now test the invalidation again
txm = cache1.getTransactionManager();
Assert.assertEquals("value", cache2.get(fqn, "key"));
txm.begin();
cache1.put(fqn, "key2", "value2");
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
txm.commit();
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
Assert.assertNull("Should have been invalidated!", cache2.get(fqn));
// test a rollback
txm = cache2.getTransactionManager();
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
txm.begin();
cache2.put(fqn, "key", "value");
Assert.assertEquals("value", cache2.get(fqn, "key"));
txm.rollback();
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
Assert.assertNull("Should not have committed", cache2.get(fqn));
// clean up.
cache1.stopService();
cache2.stopService();
cache1 = null;
cache2 = null;
}