SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionContext entry = (OptimisticTransactionContext) table.get(gtx);
assertNotNull(mgr.getTransaction());
WriteCommand command = entry.getModifications().get(0);
mgr.commit();
//test local calls
List<?> calls = dummy.getAllCalledIds();
assertEquals(OptimisticPrepareCommand.METHOD_ID, calls.get(0));
assertEquals(CommitCommand.METHOD_ID, calls.get(1));
assertNull(mgr.getTransaction());
assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
GlobalTransaction remoteGtx = new GlobalTransaction();
remoteGtx.setAddress(new DummyAddress());
// hack the method call to make it have the remote globalTransaction
command.setGlobalTransaction(remoteGtx);
//call our remote method
OptimisticPrepareCommand prepareCommand = new OptimisticPrepareCommand(remoteGtx, injectDataVersion(entry.getModifications()), (Address) remoteGtx.getAddress(), Boolean.FALSE);
try
{
TestingUtil.replicateCommand(cache, prepareCommand);
}
catch (Throwable t)
{
fail();
}
//our thread should be null
assertNull(mgr.getTransaction());
assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
// there should be a registration for the remote globalTransaction
assertNotNull(table.get(remoteGtx));
assertNotNull(table.getLocalTransaction(remoteGtx));
//this is not populated until replication interceptor is used
// assertEquals(1, table.get(remoteGtx).getModifications().size());
calls = dummy.getAllCalledIds();
assertEquals(OptimisticPrepareCommand.METHOD_ID, calls.get(2));
assertNull(mgr.getTransaction());
// call our remote method
CommitCommand commitCommand = new CommitCommand(remoteGtx);
try
{
TestingUtil.replicateCommand(cache, commitCommand);
}
catch (Throwable t)
{
fail();
}
assertNull(table.get(remoteGtx));
assertNull(table.getLocalTransaction(remoteGtx));
assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertNull(mgr.getTransaction());
TestingUtil.killCaches(cache);