[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/replicated ...
Manik Surtani
msurtani at jboss.com
Sat Dec 30 12:50:05 EST 2006
User: msurtani
Date: 06/12/30 12:50:05
Modified: tests/functional/org/jboss/cache/replicated
SyncReplTxTest.java ReplicationExceptionTest.java
SyncCacheListenerTest.java AsyncReplTest.java
SyncReplTest.java
Log:
Major changes to restructure cache and node object model
Revision Changes Path
1.16 +18 -18 JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTxTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SyncReplTxTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTxTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- SyncReplTxTest.java 15 Dec 2006 15:18:48 -0000 1.15
+++ SyncReplTxTest.java 30 Dec 2006 17:50:05 -0000 1.16
@@ -15,8 +15,8 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCache;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.TimeoutException;
@@ -36,17 +36,17 @@
import java.util.Map;
/**
- * Replicated unit test for sync transactional TreeCache
+ * Replicated unit test for sync transactional CacheImpl
* Note: we use DummyTransactionManager for Tx purpose instead of relying on
* jta.
*
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
*/
public class SyncReplTxTest extends TestCase
{
private static Log log = LogFactory.getLog(SyncReplTxTest.class);
- private TreeCache cache1;
- private TreeCache cache2;
+ private CacheImpl cache1;
+ private CacheImpl cache2;
private String old_factory = null;
private final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
@@ -90,8 +90,8 @@
private void initCaches(Configuration.CacheMode caching_mode) throws Exception
{
- cache1 = new TreeCache();
- cache2 = new TreeCache();
+ cache1 = new CacheImpl();
+ cache2 = new CacheImpl();
cache1.getConfiguration().setCacheMode(caching_mode);
cache2.getConfiguration().setCacheMode(caching_mode);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -652,8 +652,8 @@
{
Object myMutex = new Object();
- final TreeCache c1 = new TreeCache();
- final TreeCache c2 = new TreeCache();
+ final CacheImpl c1 = new CacheImpl();
+ final CacheImpl c2 = new CacheImpl();
c1.getConfiguration().setClusterName("TempCluster");
c2.getConfiguration().setClusterName("TempCluster");
c1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
@@ -778,8 +778,8 @@
public void testConcurrentPutsOnTwoInstances() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
- final TreeCache c1 = this.cache1;
- final TreeCache c2 = this.cache2;
+ final CacheImpl c1 = this.cache1;
+ final CacheImpl c2 = this.cache2;
Thread t1 = new Thread()
{
@@ -846,7 +846,7 @@
public void testPut() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
- final TreeCache c1 = this.cache1;
+ final CacheImpl c1 = this.cache1;
Thread t1 = new Thread()
@@ -987,7 +987,7 @@
public void testPutTx1() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
- final TreeCache c1 = this.cache1;
+ final CacheImpl c1 = this.cache1;
Thread t1 = new Thread()
{
public void run()
@@ -1085,7 +1085,7 @@
public void testPutTxWithRollback() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
- final TreeCache c2 = this.cache1;
+ final CacheImpl c2 = this.cache1;
Thread t1 = new Thread()
{
public void run()
@@ -1193,12 +1193,12 @@
static class CallbackListener extends AbstractCacheListener
{
- TreeCache callbackCache;
+ CacheImpl callbackCache;
Object callbackKey;
Exception ex;
Object mutex = new Object();
- CallbackListener(TreeCache cache, Object callbackKey)
+ CallbackListener(CacheImpl cache, Object callbackKey)
{
this.callbackCache = cache;
this.callbackKey = callbackKey;
@@ -1241,7 +1241,7 @@
TransactionManager callbackTM;
- TransactionAborterCallbackListener(TreeCache cache, Object callbackKey)
+ TransactionAborterCallbackListener(CacheImpl cache, Object callbackKey)
{
super(cache, callbackKey);
callbackTM = callbackCache.getTransactionManager();
@@ -1283,7 +1283,7 @@
Object mutex = new Object();
Exception ex;
- TransactionAborterListener(TreeCache cache)
+ TransactionAborterListener(CacheImpl cache)
{
callbackTM = cache.getTransactionManager();
cache.getNotifier().addCacheListener(this);
1.5 +84 -63 JBossCache/tests/functional/org/jboss/cache/replicated/ReplicationExceptionTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ReplicationExceptionTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/ReplicationExceptionTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- ReplicationExceptionTest.java 20 Jul 2006 10:32:03 -0000 1.4
+++ ReplicationExceptionTest.java 30 Dec 2006 17:50:05 -0000 1.5
@@ -12,30 +12,31 @@
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.TreeCache;
+import org.jboss.cache.CacheImpl;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManager;
import javax.naming.Context;
import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
-import javax.transaction.RollbackException;
import java.io.NotSerializableException;
import java.io.Serializable;
/**
* Teting of replication exception for a Nonerislizable object
*
- * @version $Revision: 1.4 $
* @author Ben Wang
+ * @version $Revision: 1.5 $
*/
-public class ReplicationExceptionTest extends TestCase {
- TreeCache cache1, cache2;
- Configuration.CacheMode caching_mode= Configuration.CacheMode.REPL_SYNC;
- final String group_name="TreeCacheTestGroup";
- String props=
+public class ReplicationExceptionTest extends TestCase
+{
+ CacheImpl cache1, cache2;
+ Configuration.CacheMode caching_mode = Configuration.CacheMode.REPL_SYNC;
+ final String group_name = "TreeCacheTestGroup";
+ String props =
"UDP(ip_mcast=true;ip_ttl=64;loopback=false;mcast_addr=228.1.2.3;" +
"mcast_port=45566;mcast_recv_buf_size=80000;mcast_send_buf_size=150000;" +
"ucast_recv_buf_size=80000;ucast_send_buf_size=150000):" +
@@ -51,44 +52,50 @@
"pbcast.GMS(join_retry_timeout=2000;join_timeout=5000;print_local_addr=true;shun=true):" +
"pbcast.STATE_TRANSFER(down_thread=true;up_thread=true)";
- final static Log log_=LogFactory.getLog(ReplicationExceptionTest.class);
- String old_factory=null;
- final String FACTORY="org.jboss.cache.transaction.DummyContextFactory";
+ final static Log log_ = LogFactory.getLog(ReplicationExceptionTest.class);
+ String old_factory = null;
+ final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
DummyTransactionManager tx_mgr;
- Throwable t1_ex, t2_ex, ex=null;
+ Throwable t1_ex, t2_ex, ex = null;
- public ReplicationExceptionTest(String name) {
+ public ReplicationExceptionTest(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);
- tx_mgr=DummyTransactionManager.getInstance();
- t1_ex=t2_ex=ex=null;
+ tx_mgr = DummyTransactionManager.getInstance();
+ t1_ex = t2_ex = ex = null;
}
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
super.tearDown();
DummyTransactionManager.destroy();
destroyCaches();
- if(old_factory != null) {
+ if (old_factory != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old_factory);
- old_factory=null;
+ old_factory = null;
}
}
- Transaction beginTransaction() throws SystemException, NotSupportedException {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ Transaction beginTransaction() throws SystemException, NotSupportedException
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
return mgr.getTransaction();
}
- void initCaches(Configuration.CacheMode caching_mode) throws Exception {
- this.caching_mode=caching_mode;
- cache1=new TreeCache();
- cache2=new TreeCache();
+ void initCaches(Configuration.CacheMode caching_mode) throws Exception
+ {
+ this.caching_mode = caching_mode;
+ cache1 = new CacheImpl();
+ cache2 = new CacheImpl();
cache1.getConfiguration().setCacheMode(caching_mode);
cache2.getConfiguration().setCacheMode(caching_mode);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -106,17 +113,20 @@
cache2.start();
}
- void destroyCaches() throws Exception {
- if(cache1 != null)
+ void destroyCaches() throws Exception
+ {
+ if (cache1 != null)
cache1.stop();
- if(cache2 != null)
+ if (cache2 != null)
cache2.stop();
- cache1=null;
- cache2=null;
+ cache1 = null;
+ cache2 = null;
}
- public void testNonSerializableRepl() throws Exception {
- try {
+ public void testNonSerializableRepl() throws Exception
+ {
+ try
+ {
initCaches(Configuration.CacheMode.REPL_SYNC);
cache1.put("/a/b/c", "test", new ContainerData());
@@ -124,43 +134,52 @@
// We should not come here.
assertNotNull("NonSerializableData should not be null on cache2", cache2.get("/a/b/c", "test"));
}
- catch(RuntimeException runtime) {
- Throwable t=runtime.getCause();
- if(t instanceof NotSerializableException) {
+ catch (RuntimeException runtime)
+ {
+ Throwable t = runtime.getCause();
+ if (t instanceof NotSerializableException)
+ {
System.out.println("received NotSerializableException - as expected");
}
- else {
+ else
+ {
fail("should have received NotSerializableException, but received " + t.getClass());
}
}
- catch(Exception exc) {
+ catch (Exception exc)
+ {
fail("failure - we should not get here: " + exc);
}
}
- public void testNonSerizlableReplWithTx() throws Exception {
+ public void testNonSerizlableReplWithTx() throws Exception
+ {
Transaction tx;
- try {
+ try
+ {
initCaches(Configuration.CacheMode.REPL_SYNC);
- tx=beginTransaction();
+ tx = beginTransaction();
cache1.put("/a/b/c", "test", new ContainerData());
tx.commit();
// We should not come here.
assertNotNull("NonSerializableData should not be null on cache2", cache2.get("/a/b/c", "test"));
}
- catch(RollbackException rollback) {
+ catch (RollbackException rollback)
+ {
System.out.println("received RollbackException - as expected");
}
- catch(Exception e) {
+ catch (Exception e)
+ {
// We should also examine that it is indeed throwing a NonSerilaizable exception.
fail(e.toString());
}
}
- public static Test suite() throws Exception {
+ public static Test suite() throws Exception
+ {
return new TestSuite(ReplicationExceptionTest.class);
}
@@ -170,14 +189,16 @@
int i;
}
- static class ContainerData implements Serializable {
+ static class ContainerData implements Serializable
+ {
int i;
NonSerializabeData non_serializable_data;
private static final long serialVersionUID = -8322197791060897247L;
- public ContainerData() {
- i=99;
- non_serializable_data=new NonSerializabeData();
+ public ContainerData()
+ {
+ i = 99;
+ non_serializable_data = new NonSerializabeData();
}
}
}
1.12 +5 -5 JBossCache/tests/functional/org/jboss/cache/replicated/SyncCacheListenerTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SyncCacheListenerTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/SyncCacheListenerTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- SyncCacheListenerTest.java 15 Dec 2006 15:18:48 -0000 1.11
+++ SyncCacheListenerTest.java 30 Dec 2006 17:50:05 -0000 1.12
@@ -14,8 +14,8 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCache;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManager;
@@ -31,11 +31,11 @@
/**
* Test out the TreeCacheListener
*
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class SyncCacheListenerTest extends TestCase
{
- private TreeCache cache1, cache2;
+ private CacheImpl cache1, cache2;
private final static Log log_ = LogFactory.getLog(SyncCacheListenerTest.class);
private String old_factory = null;
private final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
@@ -79,8 +79,8 @@
private void initCaches() throws Exception
{
- cache1 = new TreeCache();
- cache2 = new TreeCache();
+ cache1 = new CacheImpl();
+ cache2 = new CacheImpl();
cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
1.12 +13 -13 JBossCache/tests/functional/org/jboss/cache/replicated/AsyncReplTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AsyncReplTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/AsyncReplTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- AsyncReplTest.java 6 Sep 2006 15:31:00 -0000 1.11
+++ AsyncReplTest.java 30 Dec 2006 17:50:05 -0000 1.12
@@ -13,22 +13,22 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCache;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.misc.TestingUtil;
import javax.transaction.TransactionManager;
/**
- * Unit test for replicated async TreeCache. Use locking and multiple threads to test
+ * Unit test for replicated async CacheImpl. Use locking and multiple threads to test
* concurrent access to the tree.
*
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class AsyncReplTest extends TestCase
{
- TreeCache cache1, cache2;
+ CacheImpl cache1, cache2;
String props = null;
public AsyncReplTest(String name)
@@ -47,14 +47,14 @@
cache2 = createCache("CacheGroup");
}
- private TreeCache createCache(String name) throws Exception
+ private CacheImpl createCache(String name) throws Exception
{
- TreeCache tree = new TreeCache();
- tree.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replAsync-service.xml"));
- tree.getConfiguration().setClusterName(name);
- tree.create();
- tree.start();
- return tree;
+ CacheImpl cache = new CacheImpl();
+ cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replAsync-service.xml"));
+ cache.getConfiguration().setClusterName(name);
+ cache.create();
+ cache.start();
+ return cache;
}
protected void tearDown() throws Exception
@@ -130,7 +130,7 @@
public void testPutShouldNotReplicateToDifferentCluster()
{
- TreeCache cache3 = null;
+ CacheImpl cache3 = null;
try
{
cache3 = createCache("DifferentGroup");
@@ -155,7 +155,7 @@
public void testStateTransfer()
{
- TreeCache cache4 = null;
+ CacheImpl cache4 = null;
try
{
cache1.put("a/b/c", "age", new Integer(38));
1.4 +7 -9 JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SyncReplTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/replicated/SyncReplTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- SyncReplTest.java 31 Oct 2006 06:57:28 -0000 1.3
+++ SyncReplTest.java 30 Dec 2006 17:50:05 -0000 1.4
@@ -8,11 +8,9 @@
import junit.framework.TestCase;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
-import org.jboss.cache.TreeCacheProxyImpl;
import org.jboss.cache.config.Option;
import org.jboss.cache.factories.DefaultCacheFactory;
import org.jboss.cache.misc.TestingUtil;
@@ -58,10 +56,10 @@
Fqn f = Fqn.fromString("/test/data");
String k = "key", v = "value";
- assertNull("Should be null", caches[0].getChild(f));
- assertNull("Should be null", caches[1].getChild(f));
+ assertNull("Should be null", caches[0].getRoot().getChild(f));
+ assertNull("Should be null", caches[1].getRoot().getChild(f));
- Node node = caches[0].addChild(f);
+ Node node = caches[0].getRoot().addChild(f);
assertNotNull("Should not be null", node);
@@ -92,13 +90,13 @@
{
for (Cache c : caches)
{
- assertClusterSize(message, size, (TreeCacheProxyImpl) c);
+ assertClusterSize(message, size, c);
}
}
- private void assertClusterSize(String message, int size, TreeCacheProxyImpl tcpi)
+ private void assertClusterSize(String message, int size, Cache c)
{
- assertEquals(message, size, tcpi.treeCache.getMembers().size());
+ assertEquals(message, size, c.getMembers().size());
}
private void assertInvocationContextInitState()
@@ -111,7 +109,7 @@
private void assertInvocationContextInitState(Cache c)
{
- InvocationContext ctx = ((CacheSPI) c).getInvocationContext();
+ InvocationContext ctx = c.getInvocationContext();
InvocationContext control = null;
try
{
More information about the jboss-cvs-commits
mailing list