[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/replicated ...
Manik Surtani
msurtani at jboss.com
Thu Jan 11 08:49:07 EST 2007
User: msurtani
Date: 07/01/11 08:49:07
Modified: tests/functional/org/jboss/cache/replicated
ReplicationExceptionTest.java
SyncCacheListenerTest.java AsyncReplTest.java
SyncReplTxTest.java SyncReplTest.java
Log:
Changed CacheImpl ctor to be protected, and changed cache factories accordingly
Revision Changes Path
1.6 +8 -3 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.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ReplicationExceptionTest.java 30 Dec 2006 17:50:05 -0000 1.5
+++ ReplicationExceptionTest.java 11 Jan 2007 13:49:07 -0000 1.6
@@ -13,6 +13,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManager;
@@ -29,7 +30,7 @@
* Teting of replication exception for a Nonerislizable object
*
* @author Ben Wang
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class ReplicationExceptionTest extends TestCase
{
@@ -94,8 +95,8 @@
void initCaches(Configuration.CacheMode caching_mode) throws Exception
{
this.caching_mode = caching_mode;
- cache1 = new CacheImpl();
- cache2 = new CacheImpl();
+ cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setCacheMode(caching_mode);
cache2.getConfiguration().setCacheMode(caching_mode);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -116,9 +117,13 @@
void destroyCaches() throws Exception
{
if (cache1 != null)
+ {
cache1.stop();
+ }
if (cache2 != null)
+ {
cache2.stop();
+ }
cache1 = null;
cache2 = null;
}
1.14 +6 -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.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- SyncCacheListenerTest.java 3 Jan 2007 17:50:31 -0000 1.13
+++ SyncCacheListenerTest.java 11 Jan 2007 13:49:07 -0000 1.14
@@ -15,6 +15,7 @@
import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
@@ -31,7 +32,7 @@
/**
* Test out the TreeCacheListener
*
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
public class SyncCacheListenerTest extends TestCase
{
@@ -79,8 +80,8 @@
private void initCaches() throws Exception
{
- cache1 = new CacheImpl();
- cache2 = new CacheImpl();
+ cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -214,7 +215,7 @@
{
if (map.size() == 0) fail("put(): map size can't be 0");
Set set = map.keySet();
- key_ = set.iterator().next(); // take anyone
+ key_ = set.iterator().next();// take anyone
cache1.put(fqn, map);
}
@@ -231,7 +232,7 @@
}
catch (CacheException e)
{
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ e.printStackTrace();//To change body of catch statement use File | Settings | File Templates.
fail("nodeModified: test failed with exception: " + e);
}
}
1.16 +12 -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.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- AsyncReplTest.java 10 Jan 2007 16:58:43 -0000 1.15
+++ AsyncReplTest.java 11 Jan 2007 13:49:07 -0000 1.16
@@ -13,13 +13,12 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-
import org.jboss.cache.Cache;
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.misc.TestingUtil;
import javax.transaction.TransactionManager;
@@ -28,7 +27,7 @@
* Unit test for replicated async CacheImpl. Use locking and multiple threads to test
* concurrent access to the tree.
*
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
*/
public class AsyncReplTest extends TestCase
{
@@ -53,7 +52,7 @@
private CacheImpl createCache(String name) throws Exception
{
- CacheImpl cache = new CacheImpl();
+ CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
cache.setConfiguration(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_ASYNC));
cache.getConfiguration().setClusterName(name);
@@ -72,7 +71,7 @@
* Provides a hook for multiplexer integration. This default implementation
* is a no-op; subclasses that test mux integration would override
* to integrate the given cache with a multiplexer.
- *
+ * <p/>
* param cache a cache that has been configured but not yet created.
*/
protected void configureMultiplexer(Cache cache) throws Exception
@@ -196,7 +195,7 @@
cache1.put("a/b/c", "age", 38);
cache4 = createCache("CacheGroup");
System.out.println("" + cache4.getMembers());
- assertEquals(3, cache4.getMembers().size()); // cache1, cache2 and cache4
+ assertEquals(3, cache4.getMembers().size());// cache1, cache2 and cache4
assertEquals("\"age\" should be 38", 38, cache4.get("/a/b/c", "age"));
}
catch (Exception e)
1.19 +51 -22 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.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- SyncReplTxTest.java 3 Jan 2007 17:50:31 -0000 1.18
+++ SyncReplTxTest.java 11 Jan 2007 13:49:07 -0000 1.19
@@ -17,6 +17,7 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
@@ -41,7 +42,7 @@
* Note: we use DummyTransactionManager for Tx purpose instead of relying on
* jta.
*
- * @version $Revision: 1.18 $
+ * @version $Revision: 1.19 $
*/
public class SyncReplTxTest extends TestCase
{
@@ -91,8 +92,8 @@
private void initCaches(Configuration.CacheMode caching_mode) throws Exception
{
- cache1 = new CacheImpl();
- cache2 = new CacheImpl();
+ cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setCacheMode(caching_mode);
cache2.getConfiguration().setCacheMode(caching_mode);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -140,9 +141,13 @@
private void destroyCaches()
{
if (cache1 != null)
+ {
cache1.stop();
+ }
if (cache2 != null)
+ {
cache2.stop();
+ }
cache1 = null;
cache2 = null;
}
@@ -604,7 +609,7 @@
{
tx = beginTransaction();
cache1.put("/bela/ban", "name", "Bela Ban");
- TestingUtil.sleepThread(2000); // Thread2 will be blocked until we commit
+ TestingUtil.sleepThread(2000);// Thread2 will be blocked until we commit
tx.commit();
System.out.println("[Thread1] ** LOCK INFO cache1: " + cache1.printLockInfo());
System.out.println("[Thread1] ** LOCK INFO cache2: " + cache2.printLockInfo());
@@ -625,7 +630,7 @@
{
try
{
- TestingUtil.sleepThread(1000); // give Thread1 time to acquire the lock
+ TestingUtil.sleepThread(1000);// give Thread1 time to acquire the lock
tx = beginTransaction();
System.out.println("[Thread2] ** LOCK INFO cache1: " + cache1.printLockInfo());
System.out.println("[Thread2] ** LOCK INFO cache2: " + cache2.printLockInfo());
@@ -653,9 +658,13 @@
t2.join();
if (t1_ex != null)
+ {
fail("Thread1 failed: " + t1_ex);
+ }
if (t2_ex != null)
+ {
fail("Thread2 failed: " + t2_ex);
+ }
assertEquals("Michelle Ban", cache1.get("/bela/ban", "name"));
}
@@ -684,8 +693,8 @@
{
Object myMutex = new Object();
- final CacheImpl c1 = new CacheImpl();
- final CacheImpl c2 = new CacheImpl();
+ final CacheImpl c1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ final CacheImpl c2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
c1.getConfiguration().setClusterName("TempCluster");
c2.getConfiguration().setClusterName("TempCluster");
c1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
@@ -790,11 +799,11 @@
c1.stop();
c2.stop();
-// if(ex != null)
-// {
-// ex.printStackTrace();
-// fail("Thread failed: " + ex);
-// }
+ // if(ex != null)
+ // {
+ // ex.printStackTrace();
+ // fail("Thread failed: " + ex);
+ // }
// we can only expect 1 thread to succeed. The others will fail. So, threads.length -1 exceptions.
// this is a timing issue - 2 threads still may succeed on a multi cpu system
@@ -824,7 +833,7 @@
tx = beginTransaction();
c1.put("/ben/wang", "name", "Ben Wang");
TestingUtil.sleepThread(8000);
- tx.commit(); // This should go thru
+ tx.commit();// This should go thru
}
catch (Throwable ex)
{
@@ -842,10 +851,10 @@
{
try
{
- TestingUtil.sleepThread(1000); // give Thread1 time to acquire the lock
+ TestingUtil.sleepThread(1000);// give Thread1 time to acquire the lock
tx = beginTransaction();
c2.put("/ben/wang", "name", "Ben Jr.");
- tx.commit(); // This will time out and rollback first because Thread1 has a tx going as well.
+ tx.commit();// This will time out and rollback first because Thread1 has a tx going as well.
}
catch (RollbackException rollback_ex)
{
@@ -868,9 +877,13 @@
t2.join();
if (t1_ex != null)
+ {
fail("Thread1 failed: " + t1_ex);
+ }
if (t2_ex != null)
+ {
fail("Thread2 failed: " + t2_ex);
+ }
assertEquals("Ben Wang", c1.get("/ben/wang", "name"));
}
@@ -964,10 +977,14 @@
t1.join();
t2.join();
if (t1_ex != null)
+ {
fail("Thread1 failed: " + t1_ex);
+ }
if (t2_ex != null)
+ {
fail("Thread2 failed: " + t2_ex);
}
+ }
/**
* Test replicated cache with transaction. Idea is to have two threads running
@@ -990,12 +1007,12 @@
tx = beginTransaction();
cache1.put("/a/b/c", "age", 38);
cache1.put("/a/b/c", "age", 39);
- Object val = cache2.get("/a/b/c", "age"); // must be null as not yet committed
+ Object val = cache2.get("/a/b/c", "age");// must be null as not yet committed
assertNull(val);
tx.commit();
tx = beginTransaction();
- assertEquals(39, cache2.get("/a/b/c", "age")); // must not be null
+ assertEquals(39, cache2.get("/a/b/c", "age"));// must not be null
tx.commit();
}
catch (Throwable t)
@@ -1073,13 +1090,13 @@
Thread.yield();
lock.acquire();
tx = beginTransaction();
- assertNull(cache2.get("/a/b/c", "age")); // must be null as not yet committed
+ assertNull(cache2.get("/a/b/c", "age"));// must be null as not yet committed
cache2.put("/a/b/c", "age", 40);
lock.release();
TestingUtil.sleepThread(300);
lock.acquire();
- assertEquals(40, cache2.get("/a/b/c", "age")); // must not be null
+ assertEquals(40, cache2.get("/a/b/c", "age"));// must not be null
tx.commit();
lock.release();
@@ -1108,10 +1125,14 @@
t2.join();
if (t1_ex != null)
+ {
fail("Thread1 failed: " + t1_ex);
+ }
if (t2_ex != null)
+ {
fail("Thread2 failed: " + t2_ex);
}
+ }
public void testPutTxWithRollback() throws Exception
@@ -1161,12 +1182,12 @@
Thread.yield();
lock.acquire();
tx = beginTransaction();
- assertNull(cache2.get("/a/b/c", "age")); // must be null as not yet committed
+ assertNull(cache2.get("/a/b/c", "age"));// must be null as not yet committed
lock.release();
TestingUtil.sleepThread(100);
lock.acquire();
- assertNull(cache2.get("/a/b/c", "age")); // must be null as rolledback
+ assertNull(cache2.get("/a/b/c", "age"));// must be null as rolledback
tx.commit();
lock.release();
}
@@ -1190,10 +1211,14 @@
t1.join();
t2.join();
if (t1_ex != null)
+ {
fail("Thread1 failed: " + t1_ex);
+ }
if (t2_ex != null)
+ {
fail("Thread2 failed: " + t2_ex);
}
+ }
static class TransactionAborter implements Synchronization
@@ -1301,10 +1326,12 @@
{
e.printStackTrace();
if (ex == null)
+ {
ex = e;
}
}
}
+ }
}
@@ -1340,11 +1367,13 @@
{
e.printStackTrace();
if (ex == null)
+ {
ex = e;
}
}
}
}
+ }
Exception getCallbackException()
{
@@ -1358,7 +1387,7 @@
public static Test suite()
{
-// return getDeploySetup(SyncTxUnitTestCase.class, "cachetest.jar");
+ // return getDeploySetup(SyncTxUnitTestCase.class, "cachetest.jar");
return new TestSuite(SyncReplTxTest.class);
}
1.7 +2 -2 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.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- SyncReplTest.java 10 Jan 2007 15:39:52 -0000 1.6
+++ SyncReplTest.java 11 Jan 2007 13:49:07 -0000 1.7
@@ -8,12 +8,12 @@
import junit.framework.TestCase;
import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
-import org.jboss.cache.config.Option;
import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.DefaultCacheFactory;
+import org.jboss.cache.config.Option;
import org.jboss.cache.factories.UnitTestCacheFactory;
import org.jboss.cache.misc.TestingUtil;
More information about the jboss-cvs-commits
mailing list