[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/statetransfer ...
Manik Surtani
msurtani at jboss.com
Tue Sep 12 13:12:03 EDT 2006
User: msurtani
Date: 06/09/12 13:12:03
Modified: tests/functional/org/jboss/cache/statetransfer
StateTransferUnderLoadTest.java
Log:
Updated test so it fails during state transfer
Revision Changes Path
1.3 +80 -56 JBossCache/tests/functional/org/jboss/cache/statetransfer/StateTransferUnderLoadTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StateTransferUnderLoadTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/statetransfer/StateTransferUnderLoadTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- StateTransferUnderLoadTest.java 9 Sep 2006 11:59:23 -0000 1.2
+++ StateTransferUnderLoadTest.java 12 Sep 2006 17:12:03 -0000 1.3
@@ -4,12 +4,12 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.DefaultCacheFactory;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManager;
-import org.jgroups.util.Util;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -19,129 +19,151 @@
/**
* Tests state transfer while the other node keeps sending transactional, synchronous method calls
+ *
* @author Bela Ban
- * @version $Id: StateTransferUnderLoadTest.java,v 1.2 2006/09/09 11:59:23 bela Exp $
+ * @version $Id: StateTransferUnderLoadTest.java,v 1.3 2006/09/12 17:12:03 msurtani Exp $
*/
-public class StateTransferUnderLoadTest extends TestCase {
+public class StateTransferUnderLoadTest extends TestCase
+{
Cache cache1, cache2;
- Properties p=null;
- String old_factory=null;
- final String FACTORY="org.jboss.cache.transaction.DummyContextFactory";
+ Properties p = null;
+ String old_factory = null;
+ final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
- public StateTransferUnderLoadTest(String name) {
+ public StateTransferUnderLoadTest(String name)
+ {
super(name);
}
- public void setUp() throws Exception {
+ public void setUp() throws Exception
+ {
super.setUp();
- old_factory=System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
+ old_factory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
DummyTransactionManager.getInstance();
- if(p == null) {
- p=new Properties();
+ if (p == null)
+ {
+ p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
}
}
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
super.tearDown();
- if(cache2 != null) {
+ if (cache2 != null)
+ {
cache2.stop();
- cache2=null;
+ cache2 = null;
}
- if(cache1 != null) {
+ if (cache1 != null)
+ {
cache1.stop();
- cache1=null;
+ cache1 = null;
}
// BW. kind of a hack to destroy jndi binding and thread local tx before next run.
DummyTransactionManager.destroy();
- if(old_factory != null) {
+ if (old_factory != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old_factory);
- old_factory=null;
+ old_factory = null;
}
}
- public void testStateTransferUnderLoad() throws Exception {
+ public void testStateTransferUnderLoad() throws Exception
+ {
Writer writer;
Configuration cfg1, cfg2;
- cfg1=new Configuration();
- cfg2=new Configuration();
+ cfg1 = new Configuration();
+ cfg2 = new Configuration();
cfg1.setCacheMode(Configuration.CacheMode.REPL_SYNC);
cfg2.setCacheMode(Configuration.CacheMode.REPL_SYNC);
cfg1.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
cfg2.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
- cache1=new DefaultCacheFactory().createCache(cfg1, true);
- cache2=new DefaultCacheFactory().createCache(cfg2, false);
- UserTransaction tx1=(UserTransaction)new InitialContext(p).lookup("UserTransaction");
- writer=new Writer(cache1, tx1);
- try {
+ cache1 = new DefaultCacheFactory().createCache(cfg1, true);
+ cache2 = new DefaultCacheFactory().createCache(cfg2, false);
+ UserTransaction tx1 = (UserTransaction) new InitialContext(p).lookup("UserTransaction");
+ writer = new Writer(cache1, tx1);
+ try
+ {
writer.start();
cache2.create();
- for(int i=0; i < 10; i++) {
+ for (int i = 0; i < 10; i++)
+ {
cache2.start();
// gets state
// check if state was retrieved successfully
- int num_nodes=((CacheSPI)cache2).getNumberOfNodes();
+ int num_nodes = ((CacheSPI) cache2).getNumberOfNodes();
assertTrue(num_nodes >= 1);
- Util.sleep(100);
+ TestingUtil.sleepThread(100);
cache2.stop();
}
}
- finally {
- if(writer != null)
+ finally
+ {
+ if (writer != null)
writer.stop();
}
}
- static class Writer implements Runnable {
+ static class Writer implements Runnable
+ {
Thread thread;
Cache cache;
- boolean running=false;
+ boolean running = false;
UserTransaction tx;
- public Writer(Cache cache, UserTransaction tx) {
- this.cache=cache;
- this.tx=tx;
+ public Writer(Cache cache, UserTransaction tx)
+ {
+ this.cache = cache;
+ this.tx = tx;
}
- public void start() {
- thread=new Thread(this, "cache writer");
- running=true;
+ public void start()
+ {
+ thread = new Thread(this, "cache writer");
+ running = true;
thread.start();
}
- public void stop() {
- running=false;
+ public void stop()
+ {
+ running = false;
}
- public void run() {
- Fqn fqn=Fqn.fromString("/a/b/c");
- while(running) {
- try {
+ public void run()
+ {
+ Fqn fqn = Fqn.fromString("/a/b/c");
+ while (running)
+ {
+ try
+ {
tx.begin();
cache.put(fqn, "key", "value");
tx.commit();
}
- catch(Exception e) {
+ catch (Exception e)
+ {
e.printStackTrace();
- try {tx.rollback();} catch(SystemException e1) {}
+ try {tx.rollback();} catch (SystemException e1) {}
}
- finally {
- Util.sleepRandom(1000);
+ finally
+ {
+ TestingUtil.sleepRandom(100);
}
}
}
@@ -149,17 +171,19 @@
}
- private static void log(String msg) {
+ private static void log(String msg)
+ {
System.out.println(Thread.currentThread().getName() + ": " + msg);
}
-
- public static Test suite() throws Exception {
+ public static Test suite() throws Exception
+ {
return new TestSuite(StateTransferUnderLoadTest.class);
}
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception
+ {
junit.textui.TestRunner.run(StateTransferUnderLoadTest.suite());
}
More information about the jboss-cvs-commits
mailing list