Author: manik.surtani(a)jboss.com
Date: 2009-01-07 13:02:48 -0500 (Wed, 07 Jan 2009)
New Revision: 7393
Added:
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderWithRollbackTest.java
Log:
JBCACHE-1455 - Rollback corrupts nodes loaded from cache loader (test only so far)
Added: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderWithRollbackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderWithRollbackTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderWithRollbackTest.java 2009-01-07
18:02:48 UTC (rev 7393)
@@ -0,0 +1,72 @@
+package org.jboss.cache.loader;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.loader.testloaders.DummyInMemoryCacheLoader;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.jboss.cache.util.TestingUtil;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+
+@Test(groups = "functional")
+public class CacheLoaderWithRollbackTest
+{
+ final Fqn fqn = Fqn.fromString("/a/b");
+ final String key = "key";
+
+ public Cache<String, String> init(boolean passivation) throws Exception
+ {
+ CacheLoaderConfig cacheLoaderConfig =
UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(passivation, "",
DummyInMemoryCacheLoader.class.getName(), "", false, true, false, false,
false);
+ Configuration cfg = new Configuration();
+ cfg.setCacheLoaderConfig(cacheLoaderConfig);
+ cfg.getRuntimeConfig().setTransactionManager(new DummyTransactionManager());
+ Cache<String, String> cache = new DefaultCacheFactory<String,
String>().createCache(cfg);
+ cache.put(fqn, key, "value");
+
+ // evict the node, so we have to go to the loader to do anything with it
+ cache.evict(fqn);
+ return cache;
+ }
+
+ public void testWithPassivation() throws Exception
+ {
+ doTest(true);
+ }
+
+ public void testWithoutPassivation() throws Exception
+ {
+ doTest(false);
+ }
+
+ private void doTest(boolean passivation) throws Exception
+ {
+ Cache<String, String> cache = null;
+ try
+ {
+ cache = init(passivation);
+ TransactionManager tm =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+
+ tm.begin();
+ assert cache.getNode(fqn.getParent().getParent()).getChildrenNames().size() ==
1;
+ assert cache.getNode(fqn.getParent()).getChildrenNames().size() == 1;
+ tm.rollback();
+
+ // in the fail scenario the rollback corrupts the parent node
+ tm.begin();
+ assert cache.getNode(fqn.getParent().getParent()).getChildrenNames().size() ==
1;
+ // watch here:
+ int sz = cache.getNode(fqn.getParent()).getChildrenNames().size();
+ assert sz == 1 : "Expecting 1, was " + sz;
+ tm.commit();
+ }
+ finally
+ {
+ TestingUtil.killCaches(cache);
+ }
+ }
+}
Show replies by date