* Should reproduce JBCACHE-32 problem (http://jira.jboss.com/jira/browse/JBCACHE-32)
*/
private void _testConcurrentCommits(int num_threads) throws Exception {
Object myMutex=new Object();
final TreeCache c1=new TreeCache();
final TreeCache c2=new TreeCache();
c1.setClusterName("TempCluster");
c2.setClusterName("TempCluster");
c1.setCacheMode(TreeCache.REPL_SYNC);
c2.setCacheMode(TreeCache.REPL_SYNC);
c1.setSyncCommitPhase(true);
c2.setSyncCommitPhase(true);
c1.setSyncRollbackPhase(true);
c2.setSyncRollbackPhase(true);
c1.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
c2.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
c1.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
c2.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
c1.setLockAcquisitionTimeout(5000);
c2.setLockAcquisitionTimeout(5000);
c1.start();
c2.start();
final List exceptions = new ArrayList();
class MyThread extends Thread {
Object mutex;
public MyThread(String name, Object mutex) {
super(name);
this.mutex=mutex;
}
public void run() {
Transaction tx = null;
try {
tx=beginTransaction();
c1.put("/thread/" + getName(), null);
System.out.println("Thread " + getName() + " after put(): " + c1.toString());
System.out.println("Thread " + getName() + " waiting on mutex");
synchronized(mutex) {
mutex.wait();
}
System.out.println("Thread " + getName() + " committing");
tx.commit();
System.out.println("Thread " + getName() + " committed successfully");
}
catch(Exception e) {
exceptions.add(e);
}
finally {
try
{
if (tx != null) tx.rollback();
}
catch (Exception e)
{
}
}
}
}
MyThread[] threads=new MyThread[num_threads];
for(int i=0; i < threads.length; i++) {
threads[i]=new MyThread("#" + i, myMutex);
}
for(int i=0; i < threads.length; i++) {
MyThread thread=threads[i];
System.out.println("starting thread #" + i);
thread.start();
}
_pause(6000);
synchronized(myMutex) {
System.out.println("cache is " + c1.printLockInfo());
System.out.println("******************* SIGNALLING THREADS ********************");
myMutex.notifyAll();
}
for(int i=0; i < threads.length; i++) {
MyThread thread=threads[i];
try {
thread.join();
System.out.println("Joined thread " + thread.getName());
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("FINAL c1:\n" + c1.printDetails() + "\nlocks:\n" + c1.printLockInfo());
assertEquals(0, c1.getNumberOfLocksHeld());
assertEquals(0, c2.getNumberOfLocksHeld());
c1.stop();
c2.stop();
// if(ex != null)
// {
// ex.printStackTrace();
// fail("Thread failed: " + ex);