[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...
Manik Surtani
manik at jboss.org
Mon Jun 18 10:50:32 EDT 2007
User: msurtani
Date: 07/06/18 10:50:32
Modified: tests/functional/org/jboss/cache/loader
CacheLoaderWithReplicationTest.java
Log:
Cleaned up test
Revision Changes Path
1.30 +102 -114 JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderWithReplicationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderWithReplicationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderWithReplicationTest.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- CacheLoaderWithReplicationTest.java 8 Jun 2007 16:33:32 -0000 1.29
+++ CacheLoaderWithReplicationTest.java 18 Jun 2007 14:50:32 -0000 1.30
@@ -11,7 +11,8 @@
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -26,22 +27,27 @@
*/
public class CacheLoaderWithReplicationTest extends AbstractCacheLoaderTestBase
{
- private CacheImpl cache1, cache2;
+ private Cache cache1, cache2;
private Fqn fqn = Fqn.fromString("/a");
private String key = "key";
private static final Log log = LogFactory.getLog(CacheLoaderWithReplicationTest.class);
+ private CacheLoader loader1, loader2;
+ private TransactionManager mgr1, mgr2;
public void setUp() throws Exception
{
- cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ cache1 = DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.DummyInMemoryCacheLoader", null, false, true, false));
cache1.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = DefaultCacheFactory.getInstance().createCache(false);
cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.DummyInMemoryCacheLoader", null, false, true, false));
cache2.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+
+ loader1 = loader2 = null;
+ mgr1 = mgr2 = null;
}
public void tearDown() throws Exception
@@ -50,13 +56,25 @@
{
try
{
- cache1.remove(fqn);
- cache1.getCacheLoaderManager().getCacheLoader().remove(fqn);
+ try
+ {
+ if (mgr1 != null) mgr1.rollback();
+ }
+ catch (Exception e)
+ {
+
+ }
+
+ loader1.remove(fqn);
+ cache1.removeNode(fqn);
cache1.stop();
+ cache1.destroy();
}
finally
{
cache1 = null;
+ mgr1 = null;
+ loader1 = null;
}
}
@@ -64,49 +82,77 @@
{
try
{
- cache2.remove(fqn);
- cache2.getCacheLoaderManager().getCacheLoader().remove(fqn);
+ try
+ {
+ if (mgr2 != null) mgr2.rollback();
+ }
+ catch (Exception e)
+ {
+
+ }
+ loader2.remove(fqn);
+ cache2.removeNode(fqn);
cache2.stop();
+ cache2.destroy();
}
finally
{
cache2 = null;
+ mgr2 = null;
+ loader2 = null;
}
}
}
- public void testPessSyncRepl() throws Exception
+ private void createCaches(boolean sync, boolean optimistic) throws Exception
+ {
+ cache1.getConfiguration().setCacheMode(sync ? Configuration.CacheMode.REPL_SYNC : Configuration.CacheMode.REPL_ASYNC);
+ cache2.getConfiguration().setCacheMode(sync ? Configuration.CacheMode.REPL_SYNC : Configuration.CacheMode.REPL_ASYNC);
+
+ if (optimistic)
{
- cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ cache1.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+ cache2.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+ }
cache1.start();
cache2.start();
- Assert.assertNull(cache1.get(fqn, key));
- Assert.assertNull(cache2.get(fqn, key));
+ TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
+ loader1 = ((CacheSPI) cache1).getCacheLoaderManager().getCacheLoader();
+ loader2 = ((CacheSPI) cache2).getCacheLoaderManager().getCacheLoader();
- CacheLoader loader1 = cache1.getCacheLoaderManager().getCacheLoader();
- CacheLoader loader2 = cache2.getCacheLoaderManager().getCacheLoader();
+ // make sure everything is empty...
+ Assert.assertNull(loader1.get(fqn));
+ Assert.assertNull(loader2.get(fqn));
+ Assert.assertNull(cache1.getRoot().getChild(fqn));
+ Assert.assertNull(cache2.getRoot().getChild(fqn));
+
+ mgr1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
+ mgr2 = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
+ }
- TransactionManager mgr = cache1.getTransactionManager();
- mgr.begin();
+ public void testPessSyncRepl() throws Exception
+ {
+ createCaches(true, false);
+
+ mgr1.begin();
cache1.put(fqn, key, "value");
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertNull(cache2.get(fqn, key));
Assert.assertNull(loader1.get(fqn));
Assert.assertNull(loader2.get(fqn));
- mgr.commit();
+ mgr1.commit();
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertEquals("value", cache2.get(fqn, key));
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- mgr.begin();
+ mgr1.begin();
cache1.put(fqn, key, "value2");
Assert.assertEquals("value2", cache1.get(fqn, key));
@@ -114,43 +160,27 @@
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- mgr.rollback();
+ mgr1.rollback();
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertEquals("value", cache2.get(fqn, key));
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- // force clean up
- tearDown();
}
public void testPessAsyncRepl() throws Exception
{
- cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
- cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+ createCaches(false, false);
- cache1.start();
- cache2.start();
-
- CacheLoader loader1 = cache1.getCacheLoaderManager().getCacheLoader();
- CacheLoader loader2 = cache2.getCacheLoaderManager().getCacheLoader();
-
- // make sure everything is empty...
- Assert.assertNull(loader1.get(fqn));
- Assert.assertNull(loader2.get(fqn));
- Assert.assertNull(cache1.get(fqn));
- Assert.assertNull(cache2.get(fqn));
-
- TransactionManager mgr = cache1.getTransactionManager();
- mgr.begin();
+ mgr1.begin();
cache1.put(fqn, key, "value");
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertNull(cache2.get(fqn, key));
Assert.assertNull(loader1.get(fqn));
Assert.assertNull(loader2.get(fqn));
- mgr.commit();
+ mgr1.commit();
TestingUtil.sleepThread(500);
@@ -159,7 +189,7 @@
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- mgr.begin();
+ mgr1.begin();
cache1.put(fqn, key, "value2");
Assert.assertEquals("value2", cache1.get(fqn, key));
@@ -167,7 +197,7 @@
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- mgr.rollback();
+ mgr1.rollback();
TestingUtil.sleepThread(500);
@@ -175,43 +205,26 @@
Assert.assertEquals("value", cache2.get(fqn, key));
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
-
- // force clean up
- tearDown();
}
public void testOptSyncRepl() throws Exception
{
- try
- {
- cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
-
- cache1.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
- cache2.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
-
- cache1.start();
- cache2.start();
-
- CacheLoader loader1 = cache1.getCacheLoaderManager().getCacheLoader();
- CacheLoader loader2 = cache2.getCacheLoaderManager().getCacheLoader();
-
- TransactionManager mgr = cache1.getTransactionManager();
- mgr.begin();
+ createCaches(true, true);
+ mgr1.begin();
cache1.put(fqn, key, "value");
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertNull(cache2.get(fqn, key));
Assert.assertNull(loader1.get(fqn));
Assert.assertNull(loader2.get(fqn));
- mgr.commit();
+ mgr1.commit();
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertEquals("value", cache2.get(fqn, key));
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- mgr.begin();
+ mgr1.begin();
cache1.put(fqn, key, "value2");
Assert.assertEquals("value2", cache1.get(fqn, key));
@@ -219,46 +232,26 @@
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- mgr.rollback();
+ mgr1.rollback();
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertEquals("value", cache2.get(fqn, key));
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
}
- catch (Exception e)
- {
- Assert.assertTrue("Caught exception " + e.getMessage(), false);
- e.printStackTrace();
- }
-
- // force clean up
- tearDown();
- }
public void testOptAsyncRepl() throws Exception
{
- cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
- cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
-
- cache1.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
- cache2.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
+ createCaches(false, true);
- cache1.start();
- cache2.start();
-
- CacheLoader loader1 = cache1.getCacheLoaderManager().getCacheLoader();
- CacheLoader loader2 = cache2.getCacheLoaderManager().getCacheLoader();
-
- TransactionManager mgr = cache1.getTransactionManager();
- mgr.begin();
+ mgr1.begin();
cache1.put(fqn, key, "value");
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertNull(cache2.get(fqn, key));
Assert.assertNull(loader1.get(fqn));
Assert.assertNull(loader2.get(fqn));
- mgr.commit();
+ mgr1.commit();
TestingUtil.sleepThread(500);
@@ -267,7 +260,7 @@
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- mgr.begin();
+ mgr1.begin();
cache1.put(fqn, key, "value2");
Assert.assertEquals("value2", cache1.get(fqn, key));
@@ -275,16 +268,13 @@
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
- mgr.rollback();
+ mgr1.rollback();
TestingUtil.sleepThread(500);
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertEquals("value", cache2.get(fqn, key));
Assert.assertEquals("value", loader1.get(fqn).get(key));
Assert.assertEquals("value", loader2.get(fqn).get(key));
-
- // force clean up
- tearDown();
}
public static Test suite()
@@ -298,5 +288,3 @@
}
}
-
-
More information about the jboss-cvs-commits
mailing list