nodeInterceptor.setNext(dummy);
cache.setInterceptorChain(validateInterceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
temp.put("key1", pojo);
cache.put("/one/two", temp);
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
GlobalTransaction gtx = table.get(tx);
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
/*GlobalTransaction.class,
List.class,
Address.class,
boolean.class*/
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
assertTrue(entry.getLocks().isEmpty());
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
//lets change one of the underlying version numbers
//now let us do a prepare
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
try
{
cache._replicate(prepareMethod);
fail();
}
catch (Throwable t)
{
assertTrue(true);
}
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{gtx});
try
{
cache._replicate(commitMethod);
}
catch (Throwable t)
{
fail();
}
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
assertTrue(entry.getLocks().isEmpty());
assertEquals(1, entry.getModifications().size());
assertEquals(null, dummy.getCalled());
OptimisticTreeNode node = (OptimisticTreeNode) workspace.getNode(Fqn.fromString("/")).getNode();
//assert we can navigate
assertNotNull(node);
node = (OptimisticTreeNode) node.getChild("one");
assertEquals(new DefaultDataVersion(1), node.getVersion());
assertNotNull(node);
assertTrue(cache.exists(node.getFqn()));
assertEquals(new DefaultDataVersion(1), node.getVersion());
node = (OptimisticTreeNode) node.getChild("two");
assertNotNull(node);
assertTrue(cache.exists(node.getFqn()));
assertEquals(new DefaultDataVersion(1), node.getVersion());
assertEquals(pojo, node.get("key1"));
mgr.commit();
destroyCache(cache);
}