[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader/deadlock ...
Manik Surtani
msurtani at jboss.com
Tue Sep 5 09:37:28 EDT 2006
User: msurtani
Date: 06/09/05 09:37:28
Modified: tests/functional/org/jboss/cache/loader/deadlock
ConcurrentCreationDeadlockTest.java
Log:
Fixed incorrect config
Revision Changes Path
1.5 +461 -396 JBossCache/tests/functional/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConcurrentCreationDeadlockTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- ConcurrentCreationDeadlockTest.java 20 Jul 2006 09:03:53 -0000 1.4
+++ ConcurrentCreationDeadlockTest.java 5 Sep 2006 13:37:28 -0000 1.5
@@ -17,7 +17,7 @@
/**
* <b>Test based on a contribution by Marian Nokolov/Paul Miodonski at Siemens AG.</b>
- *
+ * <p/>
* This test has been created to simulate a unexpected TimeoutException that is
* thrown by the JBossCache. The original scenario that has been observed: <br>
* Cache in either LOCAL or REPL_SYNC mode with CacheLoader.
@@ -58,31 +58,48 @@
* <li>Cache with CacheLoader - maybe it has something to do with the
* CacheLoader/StoreInterceptor's...</li>
* </ul>
- *
*/
-public class ConcurrentCreationDeadlockTest extends AbstractCacheLoaderTestBase {
- /** The number of worker threads to start concurrently. */
+public class ConcurrentCreationDeadlockTest extends AbstractCacheLoaderTestBase
+{
+ /**
+ * The number of worker threads to start concurrently.
+ */
private static final int NUM_WORKERS = 10;
- /** The number of test runs to perform. */
+ /**
+ * The number of test runs to perform.
+ */
private static final int NUM_RUNS = 100;
- /** The number of FQN's per test run. */
+ /**
+ * The number of FQN's per test run.
+ */
private static final int NUM_FQNS_PER_RUN = 10;
- /** The initial context factory properties. */
+ /**
+ * The initial context factory properties.
+ */
private static final Properties PROPERTIES;
- /** The context factory to be used for the test. */
+ /**
+ * The context factory to be used for the test.
+ */
private static final String CONTEXT_FACTORY =
"org.jboss.cache.transaction.DummyContextFactory";
- /** The original context factory to be restored after the test. */
+ /**
+ * The original context factory to be restored after the test.
+ */
private String m_contextFactory = null;
- /** Exception recorded if any of the worker threads fails. */
+ /**
+ * Exception recorded if any of the worker threads fails.
+ */
private static volatile Exception mcl_exception = null;
- /** The cache under test. */
+ /**
+ * The cache under test.
+ */
private TreeCache m_cache = null;
- static {
+ static
+ {
PROPERTIES = new Properties();
PROPERTIES.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.cache.transaction.DummyContextFactory");
@@ -93,14 +110,16 @@
*
* @param name The test name.
*/
- public ConcurrentCreationDeadlockTest(String name) {
+ public ConcurrentCreationDeadlockTest(String name)
+ {
super(name);
}
/**
* {@inheritDoc}
*/
- public void setUp() throws Exception {
+ public void setUp() throws Exception
+ {
super.setUp();
mcl_exception = null;
m_contextFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
@@ -118,12 +137,14 @@
/**
* {@inheritDoc}
*/
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
super.tearDown();
DummyTransactionManager.destroy();
m_cache.stopService();
m_cache = null;
- if (m_contextFactory != null) {
+ if (m_contextFactory != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
m_contextFactory);
m_contextFactory = null;
@@ -138,10 +159,12 @@
* @throws Exception Any exception if thrown by the cache.
*/
private void startCache(Configuration.CacheMode cacheMode, String cacheLoaderClass)
- throws Exception {
+ throws Exception
+ {
m_cache.getConfiguration().setCacheMode(cacheMode);
- if (cacheLoaderClass != null) {
- m_cache.getConfiguration().setClusterConfig(getSingleCacheLoaderConfig("", cacheLoaderClass, "", false, false, false));
+ if (cacheLoaderClass != null)
+ {
+ m_cache.getConfiguration().setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", cacheLoaderClass, "", false, false, false));
}
m_cache.createService();
m_cache.startService();
@@ -154,7 +177,8 @@
*
* @throws Exception Any exception if thrown by the cache.
*/
- public void disabledtestLocalNoCacheLoader1Modification() throws Exception {
+ public void disabledtestLocalNoCacheLoader1Modification() throws Exception
+ {
startCache(Configuration.CacheMode.LOCAL, null);
performTest(1);
}
@@ -167,7 +191,8 @@
* @throws Exception Any exception if thrown by the cache.
*/
public void disabledtestLocalNoCacheLoader2Modifications()
- throws Exception {
+ throws Exception
+ {
startCache(Configuration.CacheMode.LOCAL, null);
performTest(2);
}
@@ -179,7 +204,8 @@
*
* @throws Exception Any exception if thrown by the cache.
*/
- public void disabledtestLocalCacheLoader1Modification() throws Exception {
+ public void disabledtestLocalCacheLoader1Modification() throws Exception
+ {
startCache(Configuration.CacheMode.LOCAL, "org.jboss.cache.loader.DummyCacheLoader");
performTest(1);
}
@@ -191,7 +217,8 @@
*
* @throws Exception Any exception if thrown by the cache.
*/
- public void testLocalCacheLoader2Modifications() throws Exception {
+ public void testLocalCacheLoader2Modifications() throws Exception
+ {
startCache(Configuration.CacheMode.LOCAL, "org.jboss.cache.loader.DummyCacheLoader");
performTest(2);
}
@@ -204,7 +231,8 @@
* @throws Exception Any exception if thrown by the cache.
*/
public void disabledtestReplAsyncNoCacheLoader1Modification()
- throws Exception {
+ throws Exception
+ {
startCache(Configuration.CacheMode.REPL_ASYNC, null);
performTest(1);
}
@@ -217,7 +245,8 @@
* @throws Exception Any exception if thrown by the cache.
*/
public void disabledtestReplAsyncNoCacheLoader2Modifications()
- throws Exception {
+ throws Exception
+ {
startCache(Configuration.CacheMode.REPL_ASYNC, null);
performTest(2);
}
@@ -230,7 +259,8 @@
* @throws Exception Any exception if thrown by the cache.
*/
public void disabledtestReplAsyncCacheLoader1Modification()
- throws Exception {
+ throws Exception
+ {
startCache(Configuration.CacheMode.REPL_ASYNC, "org.jboss.cache.loader.DummyCacheLoader");
performTest(1);
}
@@ -244,7 +274,8 @@
* @throws Exception Any exception if thrown by the cache.
*/
public void disabledtestReplAsyncCacheLoader2Modifications()
- throws Exception {
+ throws Exception
+ {
startCache(Configuration.CacheMode.REPL_ASYNC, "org.jboss.cache.loader.DummyCacheLoader");
performTest(2);
}
@@ -257,7 +288,8 @@
* @throws Exception Any exception if thrown by the cache.
*/
public void disabledtestReplSyncNoCacheLoader1Modification()
- throws Exception {
+ throws Exception
+ {
startCache(Configuration.CacheMode.REPL_SYNC, null);
performTest(1);
}
@@ -270,7 +302,8 @@
* @throws Exception Any exception if thrown by the cache.
*/
public void disabledtestReplSyncNoCacheLoader2Modifications()
- throws Exception {
+ throws Exception
+ {
startCache(Configuration.CacheMode.REPL_SYNC, null);
performTest(2);
}
@@ -282,7 +315,8 @@
*
* @throws Exception Any exception if thrown by the cache.
*/
- public void disabledtestReplSyncCacheLoader1Modification() throws Exception {
+ public void disabledtestReplSyncCacheLoader1Modification() throws Exception
+ {
startCache(Configuration.CacheMode.REPL_SYNC, "org.jboss.cache.loader.DummyCacheLoader");
performTest(1);
}
@@ -295,7 +329,8 @@
* @throws Exception Any exception if thrown by the cache.
*/
public void testReplSyncCacheLoader2Modifications()
- throws Exception {
+ throws Exception
+ {
startCache(Configuration.CacheMode.REPL_SYNC, "org.jboss.cache.loader.DummyCacheLoader");
performTest(2);
}
@@ -306,16 +341,20 @@
* @param modificationsPerTx The number of modifications per transaction.
* @throws Exception Any exception if thrown by the cache.
*/
- private void performTest(int modificationsPerTx) throws Exception {
- for (int i = 0; i < NUM_RUNS; i++) {
- if (mcl_exception != null) {
+ private void performTest(int modificationsPerTx) throws Exception
+ {
+ for (int i = 0; i < NUM_RUNS; i++)
+ {
+ if (mcl_exception != null)
+ {
// terminate the test on the first failed worker
fail("Due to an exception: " + mcl_exception);
}
// start several worker threads to work with the same set of FQN's
Worker[] t = new Worker[NUM_WORKERS];
Latch latch = new Latch();
- for (int j = 0; j < t.length; j++) {
+ for (int j = 0; j < t.length; j++)
+ {
t[j] = new Worker(latch, NUM_FQNS_PER_RUN * i,
NUM_FQNS_PER_RUN, modificationsPerTx);
t[j].start();
@@ -323,7 +362,8 @@
// fire the workers to start processing
latch.release();
// wait for all workers to complete
- for (int j = 0; j < t.length; j++) {
+ for (int j = 0; j < t.length; j++)
+ {
t[j].join();
}
}
@@ -335,7 +375,8 @@
* @return A user transaction.
* @throws Exception Any exception thrown by the context lookup.
*/
- private UserTransaction getTransaction() throws Exception {
+ private UserTransaction getTransaction() throws Exception
+ {
return (UserTransaction) new InitialContext(PROPERTIES)
.lookup("UserTransaction");
}
@@ -343,10 +384,10 @@
/**
* Log a message.
*
-
* @param msg The meessage to be logged.
*/
- private void log(String msg) {
+ private void log(String msg)
+ {
System.out.println(System.currentTimeMillis() + " "
+ Thread.currentThread() + " " + msg);
}
@@ -356,21 +397,30 @@
*
* @author Marian Nikolov
* @author $Author: msurtani $
- * @version $RCSfile: ConcurrentCreationDeadlockTest.java,v $
- * @version $Revision: 1.4 $
- * @version $Date: 2006/07/20 09:03:53 $
+ * @version $Date: 2006/09/05 13:37:28 $
+ */
+ private class Worker extends Thread
+ {
+ /**
+ * Used to fire all workers at the same time.
*/
- private class Worker extends Thread {
- /** Used to fire all workers at the same time. */
private final Latch m_latch;
- /** The start id, used as part of the node FQN. */
+ /**
+ * The start id, used as part of the node FQN.
+ */
private final int m_start;
- /** The number of nodes to create in a single run. */
+ /**
+ * The number of nodes to create in a single run.
+ */
private final int m_count;
- /** The number of modifications per single transaction. */
+ /**
+ * The number of modifications per single transaction.
+ */
private final int m_modificationsPerTx;
- /** The state of the thread, used for logging. */
+ /**
+ * The state of the thread, used for logging.
+ */
private int m_state;
/**
@@ -382,7 +432,8 @@
* @param modificationsPerTx The number of modifications per
* transaction.
*/
- public Worker(Latch latch, int start, int count, int modificationsPerTx) {
+ public Worker(Latch latch, int start, int count, int modificationsPerTx)
+ {
m_latch = latch;
m_start = start;
m_count = count;
@@ -393,39 +444,49 @@
/**
* {@inheritDoc}
*/
- public void run() {
- try {
+ public void run()
+ {
+ try
+ {
// the latch shall fire all workers at the same time
m_latch.acquire();
- for (int i = m_start; i < m_start + m_count; i++) {
+ for (int i = m_start; i < m_start + m_count; i++)
+ {
m_state = -1;
log("enter " + i);
- if (checkAndSetState()) {
+ if (checkAndSetState())
+ {
return;
}
long time = System.currentTimeMillis();
UserTransaction tx = getTransaction();
tx.begin();
- if (checkAndSetState()) {
+ if (checkAndSetState())
+ {
return;
}
// the first worker would create a new node for the FQN
// all the others would update the same node
Fqn fqn = new Fqn(new Fqn("NODE"), new Integer(i));
- for (int m = 0; m < m_modificationsPerTx; m++) {
+ for (int m = 0; m < m_modificationsPerTx; m++)
+ {
m_cache.put(fqn, new Integer(m), new Integer(i));
- if (checkAndSetState()) {
+ if (checkAndSetState())
+ {
return;
}
}
tx.commit();
- if (checkAndSetState()) {
+ if (checkAndSetState())
+ {
return;
}
time = System.currentTimeMillis() - time;
log("leave " + i + " took " + time + " msec");
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
log("caught exception in state " + m_state + ": " + e);
mcl_exception = e;
}
@@ -436,8 +497,10 @@
*
* @return True if the worker has to terminate, false otherwise.
*/
- private boolean checkAndSetState() {
- if (mcl_exception != null) {
+ private boolean checkAndSetState()
+ {
+ if (mcl_exception != null)
+ {
// another worker failed, terminate
log("detected failure in state " + m_state);
return true;
@@ -447,14 +510,16 @@
}
}
- public static Test suite() {
+ public static Test suite()
+ {
return new TestSuite(ConcurrentCreationDeadlockTest.class);
}
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception
+ {
junit.textui.TestRunner.run(suite());
More information about the jboss-cvs-commits
mailing list