CommandInterceptor dummy = new MockInterceptor();
interceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
final DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
final Transaction tx = mgr.getTransaction();
Runnable run = new Runnable()
{
public void run()
{
try
{
//start a new transaction in this thread
mgr.setTransaction(tx);
SamplePojo pojo = new SamplePojo(21, "test");
setTransactionsInInvocationCtx(mgr, cache);
cache.put("/one", "key1", pojo);
OptimisticTransactionContext entry = (OptimisticTransactionContext) cache.getTransactionTable().get(cache.getCurrentTransaction());
randomSleep(minSleep, maxSleep);
cache.put("/one/two", "key2", pojo);
assertEquals(3, entry.getTransactionWorkSpace().getNodes().size());
assertTrue(entry.getTransactionWorkSpace().getNode(Fqn.fromString("/")) != null);
assertTrue(entry.getTransactionWorkSpace().getNode(Fqn.fromString("/one")) != null);
assertTrue(entry.getTransactionWorkSpace().getNode(Fqn.fromString("/one/two")) != null);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
resetInvocationCtx(cache);
}
}
};
Thread[] threads = new Thread[numThreads];
for (int i = 0; i < numThreads; i++)
{
Thread t = new Thread(run);
t.start();
threads[i] = t;
}
for (int i = 0; i < numThreads; i++)
{
threads[i].join();
}
mgr.commit();
TestingUtil.sleepThread((long) 4000);
cache.stop();
}