JBoss Cache SVN: r7319 - core/trunk/src/test/java/org/jboss/cache/invocationcontext.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-12-12 18:59:35 -0500 (Fri, 12 Dec 2008)
New Revision: 7319
Added:
core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TwoPcTransactionTest.java
Removed:
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
refacotred for performance
Copied: core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java (from rev 7308, core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java 2008-12-12 23:59:35 UTC (rev 7319)
@@ -0,0 +1,93 @@
+package org.jboss.cache.invocationcontext;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.AbstractSingleCacheTest;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.transaction.TransactionContext;
+import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.transaction.GenericTransactionManagerLookup;
+import org.jboss.cache.util.TestingUtil;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Map;
+
+/**
+ * A test to ensure the transactional context is properly set up in the IC
+ *
+ * @author <a href="mailto:manik AT jboss DOT org">Manik Surtani</a>
+ */
+@Test(groups = {"functional", "transaction"}, testName = "invocationcontext.OnePcTransactionTest")
+public class OnePcTransactionTest extends AbstractSingleCacheTest
+{
+ private TransactionManager tm;
+
+ protected CacheSPI createCache()
+ {
+ Configuration config = new Configuration();
+ config.setTransactionManagerLookupClass(GenericTransactionManagerLookup.class.getName());
+ config.setCacheMode(CacheMode.REPL_ASYNC);
+ cache = (CacheSPI) new UnitTestCacheFactory().createCache(config, true, getClass());
+ tm = cache.getTransactionManager();
+ return cache;
+ }
+
+ public void testTxExistenceAfterWrite() throws Exception
+ {
+ // make sure we have a running transaction.
+ tm.begin();
+
+ assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
+ assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
+
+ // now make a WRITE call into the cache (should start a tx)
+ cache.getRoot().put("k", "v");
+ Map data = cache.getRoot().getData();
+ assertEquals("Data map should not empty", 1, data.size());
+
+ // but now we should have a local tx registered in the invocation context
+ assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
+ assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
+ assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+
+ tm.commit();
+ }
+
+ public void testTxExistenceAfterRead() throws Exception
+ {
+ // make sure we have a running transaction.
+ tm.begin();
+
+ assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
+ assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
+
+ // now make a WRITE call into the cache (should start a tx)
+ Object value = cache.get(Fqn.ROOT, "k");
+ assertNull("Value should be null", value);
+
+ // but now we should have a local tx registered in the invocation context
+ assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
+ assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
+ assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+
+ tm.commit();
+ }
+
+ public void testScrubbingAfterOnePhaseCommit() throws Exception
+ {
+ TwoPcTransactionTest.doScrubbingTest(cache, tm, true);
+ }
+
+ public void testScrubbingAfterOnePhaseRollback() throws Exception
+ {
+ TwoPcTransactionTest.doScrubbingTest(cache, tm, false);
+ }
+
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/invocationcontext/OnePcTransactionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-12-12 23:28:06 UTC (rev 7318)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-12-12 23:59:35 UTC (rev 7319)
@@ -1,159 +0,0 @@
-package org.jboss.cache.invocationcontext;
-
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.UnitTestCacheFactory;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.transaction.TransactionContext;
-import org.jboss.cache.transaction.TransactionTable;
-import org.jboss.cache.util.TestingUtil;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import java.util.Map;
-
-/**
- * A test to ensure the transactional context is properly set up in the IC
- *
- * @author <a href="mailto:manik AT jboss DOT org">Manik Surtani</a>
- */
-@Test(groups = {"functional", "transaction"}, testName = "invocationcontext.TransactionTest")
-public class TransactionTest
-{
- private CacheSPI<Object, Object> cache;
- private TransactionManager tm;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp()
- {
- cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache("configs/local-tx.xml", getClass());
- tm = cache.getTransactionManager();
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown()
- {
- TestingUtil.killCaches(cache);
- cache = null;
- }
-
- public void testTxExistenceAfterWrite() throws Exception
- {
- // make sure we have a running transaction.
- tm.begin();
-
- assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
- assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
-
- // now make a WRITE call into the cache (should start a tx)
- cache.getRoot().put("k", "v");
- Map data = cache.getRoot().getData();
- assertEquals("Data map should not empty", 1, data.size());
-
- // but now we should have a local tx registered in the invocation context
- assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
- assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
- assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
-
- tm.commit();
- }
-
- public void testTxExistenceAfterRead() throws Exception
- {
- // make sure we have a running transaction.
- tm.begin();
-
- assertNull("Tx should not have been set up yet", cache.getInvocationContext().getTransaction());
- assertNull("Gtx should not have been set up yet", cache.getInvocationContext().getGlobalTransaction());
-
- // now make a WRITE call into the cache (should start a tx)
- Object value = cache.get(Fqn.ROOT, "k");
- assertNull("Value should be null", value);
-
- // but now we should have a local tx registered in the invocation context
- assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
- assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
- assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
-
- tm.commit();
- }
-
- public void testScrubbingAfterCommit() throws Exception
- {
- doScrubbingTest(true);
- }
-
- public void testScrubbingAfterOnePhaseCommit() throws Exception
- {
- setUpOnePhaseCache();
-
- doScrubbingTest(true);
- }
-
- public void testScrubbingAfterRollback() throws Exception
- {
- doScrubbingTest(false);
- }
-
- public void testScrubbingAfterOnePhaseRollback() throws Exception
- {
- setUpOnePhaseCache();
-
- doScrubbingTest(true);
- }
-
- @SuppressWarnings("deprecation")
- private void doScrubbingTest(boolean commit) throws Exception
- {
- // Start clean
- cache.getInvocationContext().reset();
-
- tm.begin();
- TransactionTable tt = cache.getTransactionTable();
- cache.getRoot().put("key", "value");
-
- assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
- assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
- assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
-
- Transaction tx = tm.getTransaction();
- TransactionContext transactionContext = tt.get(tt.get(tx));
-
- if (commit)
- {
- tm.commit();
- }
- else
- {
- tm.rollback();
- }
-
- assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
- assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
- assertEquals("Method call should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
- assertEquals("Cache command should have been scrubbed", null, cache.getInvocationContext().getCommand());
-
- // check that the transaction transactionContext hasn't leaked stuff.
- assert transactionContext.getModifications().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
- assert transactionContext.getLocks().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
- assert transactionContext.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
- }
-
- private void setUpOnePhaseCache()
- {
- if (cache != null)
- {
- cache.stop();
- cache = null;
- }
-
- cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache("configs/replSync.xml", false, getClass());
- cache.getConfiguration().setCacheMode(CacheMode.REPL_ASYNC);
- cache.start();
- tm = cache.getTransactionManager();
- }
-}
Added: core/trunk/src/test/java/org/jboss/cache/invocationcontext/TwoPcTransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/TwoPcTransactionTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/TwoPcTransactionTest.java 2008-12-12 23:59:35 UTC (rev 7319)
@@ -0,0 +1,77 @@
+package org.jboss.cache.invocationcontext;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.AbstractSingleCacheTest;
+import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.transaction.TransactionContext;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+
+import javax.transaction.TransactionManager;
+import javax.transaction.Transaction;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class TwoPcTransactionTest extends AbstractSingleCacheTest
+{
+ private TransactionManager tm;
+
+ protected CacheSPI createCache()
+ {
+ cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache("configs/local-tx.xml", getClass());
+ tm = cache.getTransactionManager();
+ return cache;
+ }
+
+ @SuppressWarnings("deprecation")
+ static void doScrubbingTest(CacheSPI cache, TransactionManager tm, boolean commit) throws Exception
+ {
+ // Start clean
+ cache.getInvocationContext().reset();
+
+ tm.begin();
+ TransactionTable tt = cache.getTransactionTable();
+ cache.getRoot().put("key", "value");
+
+ assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
+ assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
+ assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());
+
+ Transaction tx = tm.getTransaction();
+ TransactionContext transactionContext = tt.get(tt.get(tx));
+
+ if (commit)
+ {
+ tm.commit();
+ } else
+ {
+ tm.rollback();
+ }
+
+ assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
+ assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
+ assertEquals("Method call should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
+ assertEquals("Cache command should have been scrubbed", null, cache.getInvocationContext().getCommand());
+
+ // check that the transaction transactionContext hasn't leaked stuff.
+ assert transactionContext.getModifications().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
+ assert transactionContext.getLocks().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
+ assert transactionContext.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
+ }
+
+ public void testScrubbingAfterCommit() throws Exception
+ {
+ doScrubbingTest(cache, tm, true);
+ }
+
+ public void testScrubbingAfterRollback() throws Exception
+ {
+ doScrubbingTest(cache, tm, false);
+ }
+
+
+
+}
16 years
JBoss Cache SVN: r7318 - core/trunk/src/test/java/org/jboss/cache/invalidation.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-12-12 18:28:06 -0500 (Fri, 12 Dec 2008)
New Revision: 7318
Added:
core/trunk/src/test/java/org/jboss/cache/invalidation/AbstractMultipleCachesSyncInvalidationTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/CacheLoaderInvalidationTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/OptSyncInvalidationTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/PessAsyncInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/PessSyncInvalidationTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/PessWithCacheLoaderInvalidationTest.java
Removed:
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java
Log:
optimized tests
Added: core/trunk/src/test/java/org/jboss/cache/invalidation/AbstractMultipleCachesSyncInvalidationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/AbstractMultipleCachesSyncInvalidationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/AbstractMultipleCachesSyncInvalidationTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -0,0 +1,179 @@
+package org.jboss.cache.invalidation;
+
+import org.jboss.cache.AbstractMultipleCachesTest;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Node;
+import org.jboss.cache.Fqn;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.fail;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public abstract class AbstractMultipleCachesSyncInvalidationTest extends AbstractMultipleCachesTest
+{
+ protected CacheSPI<Object, Object> cache1;
+ protected CacheSPI<Object, Object> cache2;
+
+ public void nodeRemovalTest() throws Exception
+ {
+ Node<Object, Object> root1 = cache1.getRoot();
+ Node<Object, Object> root2 = cache2.getRoot();
+
+ // this fqn is relative, but since it is from the root it may as well be absolute
+ Fqn fqn = Fqn.fromString("/test/fqn");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertFalse(root1.hasChild(fqn));
+ Node<Object, Object> remoteNode = root2.getChild(fqn);
+ CacheLoaderInvalidationTest.checkRemoteNodeIsRemoved(remoteNode);
+ assertEquals(false, cache1.removeNode(fqn));
+
+ Fqn child = Fqn.fromString("/test/fqn/child");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put(child, "key", "value");
+ assertEquals("value", cache1.get(child, "key"));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put(child, "key", "value");
+ assertEquals("value", cache2.get(child, "key"));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertFalse(root1.hasChild(fqn));
+ remoteNode = root2.getChild(fqn);
+ CacheLoaderInvalidationTest.checkRemoteNodeIsRemoved(remoteNode);
+ assertEquals(false, cache1.removeNode(fqn));
+ }
+
+ public void nodeResurrectionTest() throws Exception
+ {
+ // this fqn is relative, but since it is from the root it may as well be absolute
+ Fqn fqn = Fqn.fromString("/test/fqn1");
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+ // Change the value in order to increment the version if Optimistic is used
+ cache1.put(fqn, "key", "newValue");
+ assertEquals("newValue", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertEquals(null, cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ // Restore locally
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ // Repeat, but now restore the node on the remote cache
+ fqn = Fqn.fromString("/test/fqn2");
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+ // Change the value in order to increment the version if Optimistic is used
+ cache1.put(fqn, "key", "newValue");
+ assertEquals("newValue", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertEquals(null, cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ // Restore on remote cache
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
+ assertEquals(null, cache1.get(fqn, "key"));
+ }
+
+ /**
+ * Here we model a scenario where a parent node represents
+ * a structural node, and then child nodes represent different
+ * data elements.
+ * <p/>
+ * Such data structures are set up on both caches, and then the parent node
+ * is removed (globally) and re-added (locally) on one cache. This
+ * represents an attempt to clear the region -- removing a node and
+ * re-adding is one of the only ways to do this.
+ * <p/>
+ * On the second cache, the fact that the structural node is missing is
+ * detected, and an attempt is made to re-add it locally.
+ *
+ * @param optimistic should the cache be configured for optimistic locking
+ * @throws Exception
+ */
+ private void nodeResurrectionTest2() throws Exception
+ {
+ Node root1 = cache1.getRoot();
+ Node root2 = cache2.getRoot();
+
+ // this fqn is relative, but since it is from the root it may as well be absolute
+ Fqn fqn = Fqn.fromString("/test/fqn");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(fqn);
+ assertEquals(true, root1.hasChild(fqn));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(fqn);
+ assertEquals(true, root1.hasChild(fqn));
+
+ Fqn child = Fqn.fromRelativeElements(fqn, "child");
+ cache1.putForExternalRead(child, "key", "value");
+ cache2.putForExternalRead(child, "key", "value");
+ assertEquals("value", cache1.get(child, "key"));
+ assertEquals("value", cache2.get(child, "key"));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertFalse(root1.hasChild(fqn));
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(fqn);
+ assertEquals(true, root1.hasChild(fqn));
+
+ Node remoteNode = root2.getChild(fqn);
+ CacheLoaderInvalidationTest.checkRemoteNodeIsRemoved(remoteNode);
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root2.addChild(fqn);
+ assertEquals(true, root2.hasChild(fqn));
+ }
+
+ public void deleteNonExistentTest() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+
+ assertNull("Should be null", cache1.getNode(fqn));
+ assertNull("Should be null", cache2.getNode(fqn));
+
+ cache1.putForExternalRead(fqn, "key", "value");
+
+ assertEquals("value", cache1.getNode(fqn).get("key"));
+ assertNull("Should be null", cache2.getNode(fqn));
+
+ // OK, here's the real test
+ TransactionManager tm = cache2.getTransactionManager();
+ tm.begin();
+ try
+ {
+ // Remove a node that doesn't exist in cache2
+ cache2.removeNode(fqn);
+ tm.commit();
+ }
+ catch (Exception e)
+ {
+ String msg = "Unable to remove non-existent node " + fqn;
+ fail(msg + " -- " + e);
+ }
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache1.getNode(fqn), "Should have been invalidated");
+ assertNull("Should be null", cache2.getNode(fqn));
+ }
+
+
+}
Copied: core/trunk/src/test/java/org/jboss/cache/invalidation/CacheLoaderInvalidationTest.java (from rev 7308, core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/CacheLoaderInvalidationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/CacheLoaderInvalidationTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.invalidation;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.util.TestingUtil;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Tests the async interceptor
+ *
+ * @author <a href="mailto:manik AT jboss DOT org">Manik Surtani (manik AT jboss DOT org)</a>
+ */
+@Test(groups = {"functional", "jgroups"}, testName = "invalidation.CacheLoaderInvalidationTest")
+public class CacheLoaderInvalidationTest
+{
+ private static Log log = LogFactory.getLog(CacheLoaderInvalidationTest.class);
+ private CacheSPI<Object, Object> cache1, cache2;
+ private Set<CacheSPI> toClean = new HashSet<CacheSPI>();
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache1, cache2);
+ for (CacheSPI c : toClean) TestingUtil.killCaches(c);
+ toClean.clear();
+ }
+
+
+ public void testOptimisticWithCacheLoader() throws Exception
+ {
+ List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(true);
+ cache1 = caches.get(0);
+ cache2 = caches.get(1);
+
+ Fqn fqn = Fqn.fromString("/a/b");
+ TransactionManager mgr = caches.get(0).getTransactionManager();
+ assertNull("Should be null", caches.get(0).get(fqn, "key"));
+ assertNull("Should be null", caches.get(1).get(fqn, "key"));
+ mgr.begin();
+ caches.get(0).put(fqn, "key", "value");
+ assertEquals("value", caches.get(0).get(fqn, "key"));
+ assertNull("Should be null", caches.get(1).get(fqn, "key"));
+ mgr.commit();
+ assertEquals("value", caches.get(1).get(fqn, "key"));
+ assertEquals("value", caches.get(0).get(fqn, "key"));
+
+ mgr.begin();
+ caches.get(0).put(fqn, "key2", "value2");
+ assertEquals("value2", caches.get(0).get(fqn, "key2"));
+ assertNull("Should be null", caches.get(1).get(fqn, "key2"));
+ mgr.rollback();
+ assertEquals("value", caches.get(1).get(fqn, "key"));
+ assertEquals("value", caches.get(0).get(fqn, "key"));
+ assertNull("Should be null", caches.get(0).get(fqn, "key2"));
+ assertNull("Should be null", caches.get(1).get(fqn, "key2"));
+ }
+
+
+ protected CacheSPI<Object, Object> createUnstartedCache(boolean optimistic) throws Exception
+ {
+ Configuration c = new Configuration();
+ //c.setClusterName("MyCluster");
+ c.setStateRetrievalTimeout(3000);
+ c.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
+ if (optimistic) c.setNodeLockingScheme("OPTIMISTIC");
+ c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c, false, getClass());
+ toClean.add(cache);
+ return cache;
+ }
+
+ protected CacheSPI<Object, Object> createCache(boolean optimistic) throws Exception
+ {
+ CacheSPI<Object, Object> cache = createUnstartedCache(optimistic);
+ cache.start();
+ toClean.add(cache);
+ return cache;
+ }
+
+ protected List<CacheSPI<Object, Object>> createCachesWithSharedCL(boolean optimistic) throws Exception
+ {
+ List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
+ caches.add(createUnstartedCache(optimistic));
+ caches.add(createUnstartedCache(optimistic));
+
+ caches.get(0).getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(getClass()));
+ caches.get(1).getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(getClass()));
+
+ caches.get(0).start();
+ caches.get(1).start();
+ toClean.addAll(caches);
+ return caches;
+ }
+
+ protected void doRegionBasedTest(boolean optimistic) throws Exception
+ {
+ List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
+ caches.add(createUnstartedCache(false));
+ caches.add(createUnstartedCache(false));
+ cache1 = caches.get(0);
+ cache2 = caches.get(1);
+
+ caches.get(0).getConfiguration().setUseRegionBasedMarshalling(true);
+ caches.get(1).getConfiguration().setUseRegionBasedMarshalling(true);
+
+ if (optimistic)
+ {
+ caches.get(0).getConfiguration().setNodeLockingScheme("OPTIMISTIC");
+ caches.get(1).getConfiguration().setNodeLockingScheme("OPTIMISTIC");
+ }
+
+ caches.get(0).start();
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 5000);
+
+ Fqn fqn = Fqn.fromString("/a/b");
+
+ assertNull("Should be null", caches.get(0).getNode(fqn));
+ assertNull("Should be null", caches.get(1).getNode(fqn));
+
+ caches.get(0).put(fqn, "key", "value");
+ assertEquals("expecting value", "value", caches.get(0).get(fqn, "key"));
+ Node n = caches.get(1).getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
+
+ // now put in caches.get(1), should fire an eviction
+ caches.get(1).put(fqn, "key", "value2");
+ assertEquals("expecting value2", "value2", caches.get(1).get(fqn, "key"));
+ n = caches.get(0).getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
+ }
+
+
+
+ static CacheLoaderConfig getCacheLoaderConfig(Class requestor) throws Exception
+ {
+ return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(false, "",
+ "org.jboss.cache.loader.DummySharedInMemoryCacheLoader", "bin=" + requestor , false, false, false, false, false);
+ }
+
+ static void assertHasBeenInvalidated(Node n, String message)
+ {
+ // depending on how n was retrieved!
+ if (n == null)
+ {
+ assert true : message;
+ }
+ else
+ {
+ assert !n.isValid() : message;
+ }
+ }
+
+ static void checkRemoteNodeIsRemoved(Node<Object, Object> remoteNode)
+ {
+ assertHasBeenInvalidated(remoteNode, "Should have been removed");
+ // Recursively check any children
+ if (remoteNode != null)
+ {
+ for (Node<Object, Object> child : remoteNode.getChildren())
+ {
+ checkRemoteNodeIsRemoved(child);
+ }
+ }
+ }
+
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/invalidation/CacheLoaderInvalidationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2008-12-12 12:39:13 UTC (rev 7317)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -1,923 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.invalidation;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.UnitTestCacheFactory;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.util.internals.replicationlisteners.ReplicationListener;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
-
-import javax.transaction.RollbackException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Tests the async interceptor
- *
- * @author <a href="mailto:manik AT jboss DOT org">Manik Surtani (manik AT jboss DOT org)</a>
- */
-@Test(groups = {"functional", "jgroups"}, testName = "invalidation.InvalidationInterceptorTest")
-public class InvalidationInterceptorTest
-{
- private static Log log = LogFactory.getLog(InvalidationInterceptorTest.class);
- private CacheSPI<Object, Object> cache1, cache2;
- private Set<CacheSPI> toClean = new HashSet<CacheSPI>();
-
- @AfterMethod
- public void tearDown()
- {
- TestingUtil.killCaches(cache1, cache2);
- for (CacheSPI c : toClean) TestingUtil.killCaches(c);
- toClean.clear();
- }
-
-
- public void testPessimisticNonTransactional() throws Exception
- {
- cache1 = createCache(false);
- cache2 = createCache(false);
-
- Fqn fqn = Fqn.fromString("/a/b");
- cache1.put(fqn, "key", "value");
-
- // test that this has NOT replicated, but rather has been invalidated:
- assertEquals("value", cache1.get(fqn, "key"));
- assertNull("Should NOT have replicated!", cache2.getNode(fqn));
-
- log.info("***** Node not replicated, as expected.");
-
- // now make sure cache2 is in sync with cache1:
- cache2.put(fqn, "key", "value");
-
- // since the node already exists even PL will not remove it - but will invalidate it's data
- Node n = cache1.getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
- assertEquals("value", cache2.get(fqn, "key"));
-
- // now test the invalidation:
- cache1.put(fqn, "key2", "value2");
- assertEquals("value2", cache1.get(fqn, "key2"));
- n = cache2.getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
- }
-
- public void testUnnecessaryEvictions() throws Exception
- {
- cache1 = createCache(false);
- cache2 = createCache(false);
-
- Fqn fqn1 = Fqn.fromString("/a/b/c");
- Fqn fqn2 = Fqn.fromString("/a/b/d");
-
- cache1.put(fqn1, "hello", "world");
-
- assertEquals("world", cache1.get(fqn1, "hello"));
- assertNull(cache2.get(fqn1, "hello"));
-
- cache2.put(fqn2, "hello", "world");
- assertEquals("world", cache1.get(fqn1, "hello"));
- assertNull(cache2.get(fqn1, "hello"));
- assertEquals("world", cache2.get(fqn2, "hello"));
- assertNull(cache1.get(fqn2, "hello"));
-
- cache2.put(fqn1, "hello", "world");
- assertEquals("world", cache2.get(fqn1, "hello"));
- assertEquals("world", cache2.get(fqn2, "hello"));
- assertNull(cache1.get(fqn1, "hello"));
- assertNull(cache1.get(fqn2, "hello"));
- }
-
-
- public void testPessimisticNonTransactionalAsync() throws Exception
- {
- cache1 = createUnstartedCache(false);
- cache2 = createUnstartedCache(false);
- cache1.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
- cache2.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
- cache1.start();
- cache2.start();
-
- Fqn fqn = Fqn.fromString("/a/b");
- ReplicationListener replListener1 = ReplicationListener.getReplicationListener(cache1);
- ReplicationListener replListener2 = ReplicationListener.getReplicationListener(cache2);
-
- replListener2.expect(PutKeyValueCommand.class);
- cache1.put(fqn, "key", "value");
- replListener2.waitForReplicationToOccur();
-// TestingUtil.sleepThread(500);// give it time to broadcast the evict call
- // test that this has NOT replicated, but rather has been invalidated:
- assertEquals("value", cache1.get(fqn, "key"));
- assertNull("Should NOT have replicated!", cache2.getNode(fqn));
-
- replListener1.expect(PutKeyValueCommand.class);
- // now make sure cache2 is in sync with cache1:
- cache2.put(fqn, "key", "value");
-// TestingUtil.sleepThread(500);// give it time to broadcast the evict call
- replListener1.waitForReplicationToOccur(500);
-
- // since the node already exists even PL will not remove it - but will invalidate it's data
- Node n = cache1.getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
- assertEquals("value", cache2.get(fqn, "key"));
-
- replListener2.expect(PutKeyValueCommand.class);
- // now test the invalidation:
- cache1.put(fqn, "key2", "value2");
- assertEquals("value2", cache1.get(fqn, "key2"));
-// TestingUtil.sleepThread(500);// give it time to broadcast the evict call
- replListener2.waitForReplicationToOccur(500);
-
- // since the node already exists even PL will not remove it - but will invalidate it's data
- n = cache2.getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
- }
-
-
- public void testPessimisticTransactional() throws Exception
- {
- cache1 = createCache(false);
- cache2 = createCache(false);
-
- Fqn fqn = Fqn.fromString("/a/b");
- cache1.put(fqn, "key", "value");
-
- // test that this has NOT replicated, but rather has been invalidated:
- assertEquals("value", cache1.get(fqn, "key"));
- assertNull("Should NOT have replicated!", cache2.getNode(fqn));
-
- log.info("***** Node not replicated, as expected.");
-
- // now make sure cache2 is in sync with cache1:
- // make sure this is in a tx
- TransactionManager txm = cache2.getTransactionManager();
- assertEquals("value", cache1.get(fqn, "key"));
-
- txm.begin();
- cache2.put(fqn, "key", "value");
- assertEquals("value", cache2.get(fqn, "key"));
- txm.commit();
-
- // since the node already exists even PL will not remove it - but will invalidate it's data
- Node n = cache1.getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
- assertEquals("value", cache2.get(fqn, "key"));
-
- // now test the invalidation again
- txm = cache1.getTransactionManager();
- assertEquals("value", cache2.get(fqn, "key"));
-
- txm.begin();
- cache1.put(fqn, "key2", "value2");
- assertEquals("value2", cache1.get(fqn, "key2"));
- txm.commit();
-
- assertEquals("value2", cache1.get(fqn, "key2"));
- // since the node already exists even PL will not remove it - but will invalidate it's data
- n = cache2.getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
-
- // test a rollback
- txm = cache2.getTransactionManager();
- assertEquals("value2", cache1.get(fqn, "key2"));
-
- txm.begin();
- cache2.put(fqn, "key", "value");
- assertEquals("value", cache2.get(fqn, "key"));
- txm.rollback();
-
- assertEquals("value2", cache1.get(fqn, "key2"));
- n = cache2.getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
- }
-
-
- public void testOptSyncUnableToEvict() throws Exception
- {
- cache1 = createCache(true);
- cache2 = createCache(true);
-
- Fqn fqn = Fqn.fromString("/a/b");
-
- cache2.put(fqn, "key", "value");
- assertEquals("value", cache2.get(fqn, "key"));
- Node n = cache1.getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
- assertHasBeenInvalidated(cache1.peek(fqn, true, true), "Should have been invalidated");
-
- // start a tx that cache1 will have to send out an evict ...
- TransactionManager mgr1 = cache1.getTransactionManager();
- TransactionManager mgr2 = cache2.getTransactionManager();
-
- mgr1.begin();
- cache1.put(fqn, "key2", "value2");
- Transaction tx1 = mgr1.suspend();
- mgr2.begin();
- cache2.put(fqn, "key3", "value3");
- Transaction tx2 = mgr2.suspend();
- mgr1.resume(tx1);
- // this oughtta fail
- try
- {
- mgr1.commit();
- assertTrue("Ought to have succeeded!", true);
- }
- catch (RollbackException roll)
- {
- assertTrue("Ought to have succeeded!", false);
- }
-
- mgr2.resume(tx2);
- try
- {
- mgr2.commit();
- assertTrue("Ought to have failed!", false);
- }
- catch (RollbackException roll)
- {
- assertTrue("Ought to have failed!", true);
- }
- }
-
- public void testPessTxSyncUnableToEvict() throws Exception
- {
- cache1 = createCache(false);
- cache2 = createCache(false);
-
- Fqn fqn = Fqn.fromString("/a/b");
-
- cache1.put("/a/b", "key", "value");
- assertEquals("value", cache1.get(fqn, "key"));
- assertNull(cache2.getNode(fqn));
-
- // start a tx that cacahe1 will have to send out an evict ...
- TransactionManager mgr1 = cache1.getTransactionManager();
- TransactionManager mgr2 = cache2.getTransactionManager();
-
- mgr1.begin();
- cache1.put(fqn, "key2", "value2");
- Transaction tx1 = mgr1.suspend();
- mgr2.begin();
- cache2.put(fqn, "key3", "value3");
- Transaction tx2 = mgr2.suspend();
- mgr1.resume(tx1);
- // this oughtta fail
- try
- {
- mgr1.commit();
- assertTrue("Ought to have failed!", false);
- }
- catch (RollbackException roll)
- {
- assertTrue("Ought to have failed!", true);
- }
-
- mgr2.resume(tx2);
- try
- {
- mgr2.commit();
- assertTrue("Ought to have succeeded!", true);
- }
- catch (RollbackException roll)
- {
- assertTrue("Ought to have succeeded!", false);
- }
- }
-
- public void testPessTxAsyncUnableToEvict() throws Exception
- {
- cache1 = createUnstartedCache(false);
- cache2 = createUnstartedCache(false);
- cache1.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
- cache2.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
- cache1.start();
- cache2.start();
-
- Fqn fqn = Fqn.fromString("/a/b");
-
- cache1.put("/a/b", "key", "value");
- assertEquals("value", cache1.get(fqn, "key"));
- assertNull(cache2.getNode(fqn));
-
- // start a tx that cacahe1 will have to send out an evict ...
- TransactionManager mgr1 = cache1.getTransactionManager();
- TransactionManager mgr2 = cache2.getTransactionManager();
-
- mgr1.begin();
- cache1.put(fqn, "key2", "value2");
- Transaction tx1 = mgr1.suspend();
- mgr2.begin();
- cache2.put(fqn, "key3", "value3");
- Transaction tx2 = mgr2.suspend();
- mgr1.resume(tx1);
- // this oughtta fail
- try
- {
- mgr1.commit();
- assertTrue("Ought to have succeeded!", true);
- }
- catch (RollbackException roll)
- {
- assertTrue("Ought to have succeeded!", false);
- }
-
- mgr2.resume(tx2);
- try
- {
- mgr2.commit();
- assertTrue("Ought to have succeeded!", true);
- }
- catch (RollbackException roll)
- {
- assertTrue("Ought to have succeeded!", false);
- }
- }
-
- public void testPessimisticNodeRemoval() throws Exception
- {
- nodeRemovalTest(false);
- }
-
- public void testOptimisticNodeRemoval() throws Exception
- {
- nodeRemovalTest(true);
- }
-
- private void nodeRemovalTest(boolean optimistic) throws Exception
- {
- cache1 = createCache(optimistic);
- cache2 = createCache(optimistic);
-
- Node<Object, Object> root1 = cache1.getRoot();
- Node<Object, Object> root2 = cache2.getRoot();
-
- // this fqn is relative, but since it is from the root it may as well be absolute
- Fqn fqn = Fqn.fromString("/test/fqn");
- cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- cache1.put(fqn, "key", "value");
- assertEquals("value", cache1.get(fqn, "key"));
- cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- cache2.put(fqn, "key", "value");
- assertEquals("value", cache2.get(fqn, "key"));
-
- assertEquals(true, cache1.removeNode(fqn));
- assertFalse(root1.hasChild(fqn));
- Node<Object, Object> remoteNode = root2.getChild(fqn);
- checkRemoteNodeIsRemoved(remoteNode);
- assertEquals(false, cache1.removeNode(fqn));
-
- Fqn child = Fqn.fromString("/test/fqn/child");
- cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- cache1.put(child, "key", "value");
- assertEquals("value", cache1.get(child, "key"));
- cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- cache2.put(child, "key", "value");
- assertEquals("value", cache2.get(child, "key"));
-
- assertEquals(true, cache1.removeNode(fqn));
- assertFalse(root1.hasChild(fqn));
- remoteNode = root2.getChild(fqn);
- checkRemoteNodeIsRemoved(remoteNode);
- assertEquals(false, cache1.removeNode(fqn));
- }
-
- private void checkRemoteNodeIsRemoved(Node<Object, Object> remoteNode)
- {
- assertHasBeenInvalidated(remoteNode, "Should have been removed");
- // Recursively check any children
- if (remoteNode != null)
- {
- for (Node<Object, Object> child : remoteNode.getChildren())
- {
- checkRemoteNodeIsRemoved(child);
- }
- }
- }
-
- public void testPessimisticNodeResurrection() throws Exception
- {
- nodeResurrectionTest(false);
- }
-
- public void testOptimisticNodeResurrection() throws Exception
- {
- nodeResurrectionTest(true);
- }
-
- private void nodeResurrectionTest(boolean optimistic) throws Exception
- {
- cache1 = createCache(optimistic);
- cache2 = createCache(optimistic);
-
- // this fqn is relative, but since it is from the root it may as well be absolute
- Fqn fqn = Fqn.fromString("/test/fqn1");
- cache1.put(fqn, "key", "value");
- assertEquals("value", cache1.get(fqn, "key"));
- assertEquals(null, cache2.get(fqn, "key"));
- // Change the value in order to increment the version if Optimistic is used
- cache1.put(fqn, "key", "newValue");
- assertEquals("newValue", cache1.get(fqn, "key"));
- assertEquals(null, cache2.get(fqn, "key"));
-
- assertEquals(true, cache1.removeNode(fqn));
- assertEquals(null, cache1.get(fqn, "key"));
- assertEquals(null, cache2.get(fqn, "key"));
-
- // Restore locally
- cache1.put(fqn, "key", "value");
- assertEquals("value", cache1.get(fqn, "key"));
- assertEquals(null, cache2.get(fqn, "key"));
-
- // Repeat, but now restore the node on the remote cache
- fqn = Fqn.fromString("/test/fqn2");
- cache1.put(fqn, "key", "value");
- assertEquals("value", cache1.get(fqn, "key"));
- assertEquals(null, cache2.get(fqn, "key"));
- // Change the value in order to increment the version if Optimistic is used
- cache1.put(fqn, "key", "newValue");
- assertEquals("newValue", cache1.get(fqn, "key"));
- assertEquals(null, cache2.get(fqn, "key"));
-
- assertEquals(true, cache1.removeNode(fqn));
- assertEquals(null, cache1.get(fqn, "key"));
- assertEquals(null, cache2.get(fqn, "key"));
-
- // Restore on remote cache
- cache2.put(fqn, "key", "value");
- assertEquals("value", cache2.get(fqn, "key"));
- assertEquals(null, cache1.get(fqn, "key"));
- }
-
- /**
- * Test for JBCACHE-1251.
- *
- * @throws Exception
- */
- public void testPessimisticNodeResurrection2() throws Exception
- {
- nodeResurrectionTest2(false);
- }
-
- /**
- * OPTIMISTIC locking verion of test for JBCACHE-1251. JBCACHE-1251
- * did not effect optimistic, but we add the test to guard against
- * regressions.
- *
- * @throws Exception
- */
- public void testOptimisticNodeResurrection2() throws Exception
- {
- nodeResurrectionTest2(true);
- }
-
- /**
- * Here we model a scenario where a parent node represents
- * a structural node, and then child nodes represent different
- * data elements.
- * <p/>
- * Such data structures are set up on both caches, and then the parent node
- * is removed (globally) and re-added (locally) on one cache. This
- * represents an attempt to clear the region -- removing a node and
- * re-adding is one of the only ways to do this.
- * <p/>
- * On the second cache, the fact that the structural node is missing is
- * detected, and an attempt is made to re-add it locally.
- *
- * @param optimistic should the cache be configured for optimistic locking
- * @throws Exception
- */
- private void nodeResurrectionTest2(boolean optimistic) throws Exception
- {
- cache1 = createCache(optimistic);
- cache2 = createCache(optimistic);
-
- Node root1 = cache1.getRoot();
- Node root2 = cache2.getRoot();
-
- // this fqn is relative, but since it is from the root it may as well be absolute
- Fqn fqn = Fqn.fromString("/test/fqn");
- cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- root1.addChild(fqn);
- assertEquals(true, root1.hasChild(fqn));
- cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- root1.addChild(fqn);
- assertEquals(true, root1.hasChild(fqn));
-
- Fqn child = Fqn.fromRelativeElements(fqn, "child");
- cache1.putForExternalRead(child, "key", "value");
- cache2.putForExternalRead(child, "key", "value");
- assertEquals("value", cache1.get(child, "key"));
- assertEquals("value", cache2.get(child, "key"));
-
- assertEquals(true, cache1.removeNode(fqn));
- assertFalse(root1.hasChild(fqn));
-
- cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- root1.addChild(fqn);
- assertEquals(true, root1.hasChild(fqn));
-
- Node remoteNode = root2.getChild(fqn);
- checkRemoteNodeIsRemoved(remoteNode);
- cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- root2.addChild(fqn);
- assertEquals(true, root2.hasChild(fqn));
- }
-
- private void dumpVersionInfo(CacheSPI c1, CacheSPI c2, Fqn fqn)
- {
- NodeSPI n1 = c1.getRoot().getChildDirect(fqn);
-
- NodeSPI n2 = c2.getRoot().getChildDirect(fqn);
- }
-
-
- public void testOptimistic() throws Exception
- {
- cache1 = createCache(true);
- cache2 = createCache(true);
-
- Fqn fqn = Fqn.fromString("/a/b");
- cache1.put(fqn, "key", "value");
-
- dumpVersionInfo(cache1, cache2, fqn);
-
- // test that this has NOT replicated, but rather has been invalidated:
- assertEquals("value", cache1.get(fqn, "key"));
- Node n2 = cache2.getNode(fqn);
- assertHasBeenInvalidated(n2, "Should have been invalidated");
- assertHasBeenInvalidated(cache2.peek(fqn, true, true), "Should have been invalidated");
-
- // now make sure cache2 is in sync with cache1:
- cache2.put(fqn, "key", "value");
-
- dumpVersionInfo(cache1, cache2, fqn);
-
- Node n1 = cache1.getNode(fqn);
- assertHasBeenInvalidated(n1, "Should have been invalidated");
- assertHasBeenInvalidated(cache1.peek(fqn, true, true), "Should have been invalidated");
-
- assertEquals("value", cache2.get(fqn, "key"));
-
- // now test the invalidation:
- cache1.put(fqn, "key2", "value2");
-
- dumpVersionInfo(cache1, cache2, fqn);
-
- assertEquals("value2", cache1.get(fqn, "key2"));
- n2 = cache2.getNode(fqn);
- assertHasBeenInvalidated(n2, "Should have been invalidated");
- assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
-
- // with tx's
- TransactionManager txm = cache2.getTransactionManager();
-
- txm.begin();
- cache2.put(fqn, "key", "value");
- assertEquals("value", cache2.get(fqn, "key"));
- assertEquals("value2", cache1.get(fqn, "key2"));
- txm.commit();
-
- n1 = cache1.getNode(fqn);
- assertHasBeenInvalidated(n1, "Should have been invalidated");
- assertHasBeenInvalidated(cache1.peek(fqn, false, false), "Should have been invalidated");
- assertEquals("value", cache2.get(fqn, "key"));
-
- // now test the invalidation again
- txm = cache1.getTransactionManager();
-
- txm.begin();
- cache1.put(fqn, "key2", "value2");
- assertEquals("value", cache2.get(fqn, "key"));
- assertEquals("value2", cache1.get(fqn, "key2"));
- txm.commit();
-
- assertEquals("value2", cache1.get(fqn, "key2"));
- n2 = cache2.getNode(fqn);
- assertHasBeenInvalidated(n2, "Should have been invalidated");
- assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
-
- // test a rollback
- txm = cache2.getTransactionManager();
-
- txm.begin();
- cache2.put(fqn, "key", "value");
- assertEquals("value2", cache1.get(fqn, "key2"));
- assertEquals("value", cache2.get(fqn, "key"));
- txm.rollback();
-
- assertEquals("value2", cache1.get(fqn, "key2"));
- n2 = cache2.getNode(fqn);
- assertHasBeenInvalidated(n2, "Should have been invalidated");
- assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
- }
-
- public void testPessimisticNonTransactionalWithCacheLoader() throws Exception
- {
- List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(false);
- cache1 = caches.get(0);
- cache2 = caches.get(1);
-
- Fqn fqn = Fqn.fromString("/a/b");
- caches.get(0).put(fqn, "key", "value");
-
- assertEquals("value", caches.get(0).get(fqn, "key"));
- assertEquals("value", caches.get(1).get(fqn, "key"));
-
- // now make sure cache2 is in sync with cache1:
- caches.get(1).put(fqn, "key", "value");
- assertEquals("value", caches.get(1).get(fqn, "key"));
- assertEquals("value", caches.get(0).get(fqn, "key"));
-
- // now test the invalidation:
- caches.get(0).put(fqn, "key2", "value2");
- assertEquals("value2", caches.get(0).get(fqn, "key2"));
- assertEquals("value2", caches.get(1).get(fqn, "key2"));
- assertEquals("value", caches.get(0).get(fqn, "key"));
- assertEquals("value", caches.get(1).get(fqn, "key"));
- }
-
- public void testPessimisticTransactionalWithCacheLoader() throws Exception
- {
- List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(false);
- cache1 = caches.get(0);
- cache2 = caches.get(1);
-
- Fqn fqn = Fqn.fromString("/a/b");
- TransactionManager mgr = caches.get(0).getTransactionManager();
- assertNull("Should be null", caches.get(0).get(fqn, "key"));
- assertNull("Should be null", caches.get(1).get(fqn, "key"));
- mgr.begin();
- caches.get(0).put(fqn, "key", "value");
- assertEquals("value", caches.get(0).get(fqn, "key"));
- mgr.commit();
- assertEquals("value", caches.get(1).get(fqn, "key"));
- assertEquals("value", caches.get(0).get(fqn, "key"));
-
- mgr.begin();
- caches.get(0).put(fqn, "key2", "value2");
- assertEquals("value2", caches.get(0).get(fqn, "key2"));
- mgr.rollback();
- assertEquals("value", caches.get(1).get(fqn, "key"));
- assertEquals("value", caches.get(0).get(fqn, "key"));
- assertNull("Should be null", caches.get(0).get(fqn, "key2"));
- assertNull("Should be null", caches.get(1).get(fqn, "key2"));
- }
-
- public void testOptimisticWithCacheLoader() throws Exception
- {
- List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(true);
- cache1 = caches.get(0);
- cache2 = caches.get(1);
-
- Fqn fqn = Fqn.fromString("/a/b");
- TransactionManager mgr = caches.get(0).getTransactionManager();
- assertNull("Should be null", caches.get(0).get(fqn, "key"));
- assertNull("Should be null", caches.get(1).get(fqn, "key"));
- mgr.begin();
- caches.get(0).put(fqn, "key", "value");
- assertEquals("value", caches.get(0).get(fqn, "key"));
- assertNull("Should be null", caches.get(1).get(fqn, "key"));
- mgr.commit();
- assertEquals("value", caches.get(1).get(fqn, "key"));
- assertEquals("value", caches.get(0).get(fqn, "key"));
-
- mgr.begin();
- caches.get(0).put(fqn, "key2", "value2");
- assertEquals("value2", caches.get(0).get(fqn, "key2"));
- assertNull("Should be null", caches.get(1).get(fqn, "key2"));
- mgr.rollback();
- assertEquals("value", caches.get(1).get(fqn, "key"));
- assertEquals("value", caches.get(0).get(fqn, "key"));
- assertNull("Should be null", caches.get(0).get(fqn, "key2"));
- assertNull("Should be null", caches.get(1).get(fqn, "key2"));
- }
-
- public void testInvalidationWithRegionBasedMarshalling() throws Exception
- {
- doRegionBasedTest(false);
- }
-
- public void testInvalidationWithRegionBasedMarshallingOptimistic() throws Exception
- {
- doRegionBasedTest(true);
- }
-
- protected void doRegionBasedTest(boolean optimistic) throws Exception
- {
- List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
- caches.add(createUnstartedCache(false));
- caches.add(createUnstartedCache(false));
- cache1 = caches.get(0);
- cache2 = caches.get(1);
-
- caches.get(0).getConfiguration().setUseRegionBasedMarshalling(true);
- caches.get(1).getConfiguration().setUseRegionBasedMarshalling(true);
-
- if (optimistic)
- {
- caches.get(0).getConfiguration().setNodeLockingScheme("OPTIMISTIC");
- caches.get(1).getConfiguration().setNodeLockingScheme("OPTIMISTIC");
- }
-
- caches.get(0).start();
- caches.get(1).start();
-
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 5000);
-
- Fqn fqn = Fqn.fromString("/a/b");
-
- assertNull("Should be null", caches.get(0).getNode(fqn));
- assertNull("Should be null", caches.get(1).getNode(fqn));
-
- caches.get(0).put(fqn, "key", "value");
- assertEquals("expecting value", "value", caches.get(0).get(fqn, "key"));
- Node n = caches.get(1).getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
-
- // now put in caches.get(1), should fire an eviction
- caches.get(1).put(fqn, "key", "value2");
- assertEquals("expecting value2", "value2", caches.get(1).get(fqn, "key"));
- n = caches.get(0).getNode(fqn);
- assertHasBeenInvalidated(n, "Should have been invalidated");
- }
-
- public void testDeleteNonExistentPessimistic() throws Exception
- {
- deleteNonExistentTest(false);
- }
-
- /**
- * Test for JBCACHE-1297
- *
- * @throws Exception
- */
- public void testDeleteNonExistentOptimistic() throws Exception
- {
- deleteNonExistentTest(true);
- }
-
- private void deleteNonExistentTest(boolean optimistic) throws Exception
- {
- List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
- caches.add(createUnstartedCache(optimistic));
- caches.add(createUnstartedCache(optimistic));
- cache1 = caches.get(0);
- cache2 = caches.get(1);
-
- cache1.start();
- cache2.start();
-
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 5000);
-
- Fqn fqn = Fqn.fromString("/a/b");
-
- assertNull("Should be null", cache1.getNode(fqn));
- assertNull("Should be null", cache2.getNode(fqn));
-
- cache1.putForExternalRead(fqn, "key", "value");
-
- assertEquals("value", cache1.getNode(fqn).get("key"));
- assertNull("Should be null", cache2.getNode(fqn));
-
- // OK, here's the real test
- TransactionManager tm = cache2.getTransactionManager();
- tm.begin();
- try
- {
- // Remove a node that doesn't exist in cache2
- cache2.removeNode(fqn);
- tm.commit();
- }
- catch (Exception e)
- {
- String msg = "Unable to remove non-existent node " + fqn;
- log.error(msg, e);
- fail(msg + " -- " + e);
- }
-
- assertHasBeenInvalidated(cache1.getNode(fqn), "Should have been invalidated");
- assertNull("Should be null", cache2.getNode(fqn));
- }
-
- /**
- * Test for JBCACHE-1298.
- *
- * @throws Exception
- */
- public void testAddOfDeletedNonExistent() throws Exception
- {
- cache1 = createCache(true);
- cache2 = createCache(true);
-
- TestingUtil.blockUntilViewsReceived(5000, cache1, cache2);
-
- Fqn fqn = Fqn.fromString("/a/b");
-
- assertNull("Should be null", cache1.getNode(fqn));
- assertNull("Should be null", cache2.getNode(fqn));
-
- // OK, here's the real test
- TransactionManager tm = cache2.getTransactionManager();
- tm.begin();
- try
- {
- // Remove a node that doesn't exist in cache2
- cache2.removeNode(fqn);
- tm.commit();
- }
- catch (Exception e)
- {
- String msg = "Unable to remove non-existent node " + fqn;
- log.error(msg, e);
- fail(msg + " -- " + e);
- }
-
- // Actually, it shouldn't have been invalidated, should be null
- // But, this assertion will pass if it is null, and we want
- assertHasBeenInvalidated(cache1.getNode(fqn), "Should have been invalidated");
- assertNull("Should be null", cache2.getNode(fqn));
-
- cache1.getInvocationContext().getOptionOverrides().setDataVersion(new DefaultDataVersion());
- cache1.put(fqn, "key", "value");
-
- assertEquals("value", cache1.getNode(fqn).get("key"));
- assertHasBeenInvalidated(cache2.getNode(fqn), "Should have been invalidated");
- }
-
- protected CacheSPI<Object, Object> createUnstartedCache(boolean optimistic) throws Exception
- {
- Configuration c = new Configuration();
- //c.setClusterName("MyCluster");
- c.setStateRetrievalTimeout(3000);
- c.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
- if (optimistic) c.setNodeLockingScheme("OPTIMISTIC");
- c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
-
- CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c, false, getClass());
- toClean.add(cache);
- return cache;
- }
-
- protected CacheSPI<Object, Object> createCache(boolean optimistic) throws Exception
- {
- CacheSPI<Object, Object> cache = createUnstartedCache(optimistic);
- cache.start();
- toClean.add(cache);
- return cache;
- }
-
- protected List<CacheSPI<Object, Object>> createCachesWithSharedCL(boolean optimistic) throws Exception
- {
- List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
- caches.add(createUnstartedCache(optimistic));
- caches.add(createUnstartedCache(optimistic));
-
- caches.get(0).getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig());
- caches.get(1).getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig());
-
- caches.get(0).start();
- caches.get(1).start();
- toClean.addAll(caches);
- return caches;
- }
-
-
- protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
- {
- return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(false, "",
- "org.jboss.cache.loader.DummySharedInMemoryCacheLoader", "bin=" + getClass(), false, false, false, false, false);
- }
-
- protected void assertHasBeenInvalidated(Node n, String message)
- {
- // depending on how n was retrieved!
- if (n == null)
- {
- assert true : message;
- }
- else
- {
- assert !n.isValid() : message;
- }
- }
-}
Added: core/trunk/src/test/java/org/jboss/cache/invalidation/OptSyncInvalidationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/OptSyncInvalidationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/OptSyncInvalidationTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -0,0 +1,187 @@
+package org.jboss.cache.invalidation;
+
+import org.jboss.cache.*;
+import org.jboss.cache.optimistic.DefaultDataVersion;
+import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.assertFalse;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+import javax.transaction.Transaction;
+import javax.transaction.RollbackException;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */ //
+@Test( groups = "functional", testName = "invalidation.OptSyncInvalidationTest")
+public class OptSyncInvalidationTest extends AbstractMultipleCachesSyncInvalidationTest
+{
+ protected void createCaches() throws Throwable
+ {
+ Configuration c = new Configuration();
+ c.setStateRetrievalTimeout(3000);
+ c.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
+ c.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+ c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ cache1 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c, true, getClass());
+ cache2 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c.clone(), true, getClass());
+ TestingUtil.blockUntilViewReceived(cache1, 2, 10000);
+ registerCaches(cache1, cache2);
+
+ }
+
+ public void testOptSyncUnableToEvict() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
+ Node n = cache1.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache1.peek(fqn, true, true), "Should have been invalidated");
+
+ // start a tx that cache1 will have to send out an evict ...
+ TransactionManager mgr1 = cache1.getTransactionManager();
+ TransactionManager mgr2 = cache2.getTransactionManager();
+
+ mgr1.begin();
+ cache1.put(fqn, "key2", "value2");
+ Transaction tx1 = mgr1.suspend();
+ mgr2.begin();
+ cache2.put(fqn, "key3", "value3");
+ Transaction tx2 = mgr2.suspend();
+ mgr1.resume(tx1);
+ // this oughtta fail
+ try
+ {
+ mgr1.commit();
+ assertTrue("Ought to have succeeded!", true);
+ }
+ catch (RollbackException roll)
+ {
+ assertTrue("Ought to have succeeded!", false);
+ }
+
+ mgr2.resume(tx2);
+ try
+ {
+ mgr2.commit();
+ assertTrue("Ought to have failed!", false);
+ }
+ catch (RollbackException roll)
+ {
+ assertTrue("Ought to have failed!", true);
+ }
+ }
+
+ public void testOptimistic() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+ cache1.put(fqn, "key", "value");
+
+ // test that this has NOT replicated, but rather has been invalidated:
+ assertEquals("value", cache1.get(fqn, "key"));
+ Node n2 = cache2.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n2, "Should have been invalidated");
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache2.peek(fqn, true, true), "Should have been invalidated");
+
+ // now make sure cache2 is in sync with cache1:
+ cache2.put(fqn, "key", "value");
+
+ Node n1 = cache1.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n1, "Should have been invalidated");
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache1.peek(fqn, true, true), "Should have been invalidated");
+
+ assertEquals("value", cache2.get(fqn, "key"));
+
+ // now test the invalidation:
+ cache1.put(fqn, "key2", "value2");
+
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ n2 = cache2.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n2, "Should have been invalidated");
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
+
+ // with tx's
+ TransactionManager txm = cache2.getTransactionManager();
+
+ txm.begin();
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ txm.commit();
+
+ n1 = cache1.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n1, "Should have been invalidated");
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache1.peek(fqn, false, false), "Should have been invalidated");
+ assertEquals("value", cache2.get(fqn, "key"));
+
+ // now test the invalidation again
+ txm = cache1.getTransactionManager();
+
+ txm.begin();
+ cache1.put(fqn, "key2", "value2");
+ assertEquals("value", cache2.get(fqn, "key"));
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ txm.commit();
+
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ n2 = cache2.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n2, "Should have been invalidated");
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
+
+ // test a rollback
+ txm = cache2.getTransactionManager();
+
+ txm.begin();
+ cache2.put(fqn, "key", "value");
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ assertEquals("value", cache2.get(fqn, "key"));
+ txm.rollback();
+
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ n2 = cache2.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n2, "Should have been invalidated");
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
+ }
+
+ public void dataInconsistency() throws Exception
+ {
+ Fqn node = Fqn.fromString("/a");
+ TransactionManager tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
+ TransactionManager tm2 = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
+ tm1.begin();
+ cache1.put(node, "k", "v-older");
+ Transaction t1 = tm1.suspend();
+
+ tm2.begin();
+ cache2.put(node, "k", "v-newer");
+ tm2.commit();
+
+ tm1.resume(t1);
+ try
+ {
+ tm1.commit();
+ assert false : "Should not be allowed to commit with older data!!";
+ }
+ catch (Exception good)
+ {
+ }
+
+ // the NEWER version of the data should be available, not the OLDER one.
+
+ Object val = cache1.get(node, "k");
+ assert val == null : "Older data should not have committed";
+
+ val = cache2.get(node, "k");
+ assert val.equals("v-newer");
+
+ // test node versions
+ NodeSPI n = ((CacheSPI) cache1).peek(node, true, true);
+ assert ((DefaultDataVersion) n.getVersion()).getRawVersion() == 1 : "Version should be 1";
+ }
+
+}
Added: core/trunk/src/test/java/org/jboss/cache/invalidation/PessAsyncInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/PessAsyncInterceptorTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/PessAsyncInterceptorTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -0,0 +1,83 @@
+package org.jboss.cache.invalidation;
+
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.*;
+import org.jboss.cache.util.TestingUtil;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+import javax.transaction.Transaction;
+import javax.transaction.RollbackException;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+@Test (groups = "functional", testName = "invalidation.PessAsyncInterceptorTest")
+public class PessAsyncInterceptorTest extends AbstractMultipleCachesTest
+{
+ private CacheSPI<Object, Object> cache1;
+ private CacheSPI<Object, Object> cache2;
+
+
+ protected void createCaches() throws Throwable
+ {
+ Configuration c = new Configuration();
+ c.setStateRetrievalTimeout(3000);
+ c.setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
+ c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ cache1 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c, true, getClass());
+ cache2 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c.clone(), true, getClass());
+ TestingUtil.blockUntilViewReceived(cache1, 2, 10000);
+ registerCaches(cache1, cache2);
+ }
+
+ public void testPessTxAsyncUnableToEvict() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+
+ cache1.put("/a/b", "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertNull(cache2.getNode(fqn));
+
+ // start a tx that cacahe1 will have to send out an evict ...
+ TransactionManager mgr1 = cache1.getTransactionManager();
+ TransactionManager mgr2 = cache2.getTransactionManager();
+
+ mgr1.begin();
+ cache1.put(fqn, "key2", "value2");
+ Transaction tx1 = mgr1.suspend();
+ mgr2.begin();
+ cache2.put(fqn, "key3", "value3");
+ Transaction tx2 = mgr2.suspend();
+ mgr1.resume(tx1);
+ // this oughtta fail
+ try
+ {
+ mgr1.commit();
+ assertTrue("Ought to have succeeded!", true);
+ }
+ catch (RollbackException roll)
+ {
+ assertTrue("Ought to have succeeded!", false);
+ }
+
+ mgr2.resume(tx2);
+ try
+ {
+ mgr2.commit();
+ assertTrue("Ought to have succeeded!", true);
+ }
+ catch (RollbackException roll)
+ {
+ assertTrue("Ought to have succeeded!", false);
+ }
+ }
+
+
+
+}
Added: core/trunk/src/test/java/org/jboss/cache/invalidation/PessSyncInvalidationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/PessSyncInvalidationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/PessSyncInvalidationTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -0,0 +1,214 @@
+package org.jboss.cache.invalidation;
+
+import org.jboss.cache.*;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.optimistic.DefaultDataVersion;
+import org.jboss.cache.util.TestingUtil;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
+
+import javax.transaction.RollbackException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+@Test(groups = "functional", testName = "invalidation.PessSyncInvalidationTest")
+public class PessSyncInvalidationTest extends AbstractMultipleCachesSyncInvalidationTest
+{
+
+ protected void createCaches() throws Throwable
+ {
+ Configuration c = new Configuration();
+ c.setStateRetrievalTimeout(3000);
+ c.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
+ c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ cache1 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c, true, getClass());
+ cache2 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c.clone(), true, getClass());
+ TestingUtil.blockUntilViewReceived(cache1, 2, 10000);
+ registerCaches(cache1, cache2);
+ }
+
+ public void testPessimisticNonTransactional() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+ cache1.put(fqn, "key", "value");
+
+ // test that this has NOT replicated, but rather has been invalidated:
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertNull("Should NOT have replicated!", cache2.getNode(fqn));
+
+ // now make sure cache2 is in sync with cache1:
+ cache2.put(fqn, "key", "value");
+
+ // since the node already exists even PL will not remove it - but will invalidate it's data
+ Node n = cache1.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
+ assertEquals("value", cache2.get(fqn, "key"));
+
+ // now test the invalidation:
+ cache1.put(fqn, "key2", "value2");
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ n = cache2.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
+ }
+
+
+ public void testUnnecessaryEvictions() throws Exception
+ {
+ Fqn fqn1 = Fqn.fromString("/a/b/c");
+ Fqn fqn2 = Fqn.fromString("/a/b/d");
+
+ cache1.put(fqn1, "hello", "world");
+
+ assertEquals("world", cache1.get(fqn1, "hello"));
+ assertNull(cache2.get(fqn1, "hello"));
+
+ cache2.put(fqn2, "hello", "world");
+ assertEquals("world", cache1.get(fqn1, "hello"));
+ assertNull(cache2.get(fqn1, "hello"));
+ assertEquals("world", cache2.get(fqn2, "hello"));
+ assertNull(cache1.get(fqn2, "hello"));
+
+ cache2.put(fqn1, "hello", "world");
+ assertEquals("world", cache2.get(fqn1, "hello"));
+ assertEquals("world", cache2.get(fqn2, "hello"));
+ assertNull(cache1.get(fqn1, "hello"));
+ assertNull(cache1.get(fqn2, "hello"));
+ }
+
+ public void testPessimisticTransactional() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+ cache1.put(fqn, "key", "value");
+
+ // test that this has NOT replicated, but rather has been invalidated:
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertNull("Should NOT have replicated!", cache2.getNode(fqn));
+
+ // now make sure cache2 is in sync with cache1:
+ // make sure this is in a tx
+ TransactionManager txm = cache2.getTransactionManager();
+ assertEquals("value", cache1.get(fqn, "key"));
+
+ txm.begin();
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
+ txm.commit();
+
+ // since the node already exists even PL will not remove it - but will invalidate it's data
+ Node n = cache1.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
+ assertEquals("value", cache2.get(fqn, "key"));
+
+ // now test the invalidation again
+ txm = cache1.getTransactionManager();
+ assertEquals("value", cache2.get(fqn, "key"));
+
+ txm.begin();
+ cache1.put(fqn, "key2", "value2");
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ txm.commit();
+
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ // since the node already exists even PL will not remove it - but will invalidate it's data
+ n = cache2.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
+
+ // test a rollback
+ txm = cache2.getTransactionManager();
+ assertEquals("value2", cache1.get(fqn, "key2"));
+
+ txm.begin();
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
+ txm.rollback();
+
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ n = cache2.getNode(fqn);
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(n, "Should have been invalidated");
+ }
+
+ public void testPessTxSyncUnableToEvict() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+
+ cache1.put("/a/b", "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertNull(cache2.getNode(fqn));
+
+ // start a tx that cacahe1 will have to send out an evict ...
+ TransactionManager mgr1 = cache1.getTransactionManager();
+ TransactionManager mgr2 = cache2.getTransactionManager();
+
+ mgr1.begin();
+ cache1.put(fqn, "key2", "value2");
+ Transaction tx1 = mgr1.suspend();
+ mgr2.begin();
+ cache2.put(fqn, "key3", "value3");
+ Transaction tx2 = mgr2.suspend();
+ mgr1.resume(tx1);
+ // this oughtta fail
+ try
+ {
+ mgr1.commit();
+ assertTrue("Ought to have failed!", false);
+ }
+ catch (RollbackException roll)
+ {
+ assertTrue("Ought to have failed!", true);
+ }
+
+ mgr2.resume(tx2);
+ try
+ {
+ mgr2.commit();
+ assertTrue("Ought to have succeeded!", true);
+ }
+ catch (RollbackException roll)
+ {
+ assertTrue("Ought to have succeeded!", false);
+ }
+ }
+
+ /**
+ * Test for JBCACHE-1298.
+ *
+ * @throws Exception
+ */
+ public void testAddOfDeletedNonExistent() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+
+ assertNull("Should be null", cache1.getNode(fqn));
+ assertNull("Should be null", cache2.getNode(fqn));
+
+ // OK, here's the real test
+ TransactionManager tm = cache2.getTransactionManager();
+ tm.begin();
+ try
+ {
+ // Remove a node that doesn't exist in cache2
+ cache2.removeNode(fqn);
+ tm.commit();
+ }
+ catch (Exception e)
+ {
+ String msg = "Unable to remove non-existent node " + fqn;
+ fail(msg + " -- " + e);
+ }
+
+ // Actually, it shouldn't have been invalidated, should be null
+ // But, this assertion will pass if it is null, and we want
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache1.getNode(fqn), "Should have been invalidated");
+ assertNull("Should be null", cache2.getNode(fqn));
+
+ cache1.getInvocationContext().getOptionOverrides().setDataVersion(new DefaultDataVersion());
+ cache1.put(fqn, "key", "value");
+
+ assertEquals("value", cache1.getNode(fqn).get("key"));
+ CacheLoaderInvalidationTest.assertHasBeenInvalidated(cache2.getNode(fqn), "Should have been invalidated");
+ }
+
+}
Added: core/trunk/src/test/java/org/jboss/cache/invalidation/PessWithCacheLoaderInvalidationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/PessWithCacheLoaderInvalidationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/PessWithCacheLoaderInvalidationTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -0,0 +1,88 @@
+package org.jboss.cache.invalidation;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.AbstractMultipleCachesTest;
+import org.jboss.cache.loader.DummyInMemoryCacheLoaderPessimisticTest;
+import org.jboss.cache.loader.DummySharedInMemoryCacheLoader;
+import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+@Test(groups = "functional", testName = "invalidation.PessWithCacheLoaderInvalidationTest")
+public class PessWithCacheLoaderInvalidationTest extends AbstractMultipleCachesTest
+{
+ private CacheSPI<Object, Object> cache1;
+ private CacheSPI<Object, Object> cache2;
+
+ protected void createCaches() throws Throwable
+ {
+ Configuration c = new Configuration();
+ c.setStateRetrievalTimeout(3000);
+ c.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
+ c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ c.setCacheLoaderConfig(CacheLoaderInvalidationTest.getCacheLoaderConfig(getClass()));
+ cache1 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c, true, getClass());
+ cache2 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c.clone(), true, getClass());
+ registerCaches(cache1, cache2);
+ }
+
+ @BeforeMethod
+ public void clearCacheLoaderBetweenTests() throws Exception
+ {
+ DummySharedInMemoryCacheLoader sharedCl = (DummySharedInMemoryCacheLoader) cache1.getCacheLoaderManager().getCacheLoader();
+ sharedCl.remove(Fqn.ROOT);
+ }
+
+ public void testPessimisticNonTransactionalWithCacheLoader() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+ cache1.put(fqn, "key", "value");
+
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertEquals("value", cache2.get(fqn, "key"));
+
+ // now make sure cache2 is in sync with cache1:
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
+ assertEquals("value", cache1.get(fqn, "key"));
+
+ // now test the invalidation:
+ cache1.put(fqn, "key2", "value2");
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ assertEquals("value2", cache2.get(fqn, "key2"));
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertEquals("value", cache2.get(fqn, "key"));
+ }
+
+ public void testPessimisticTransactionalWithCacheLoader() throws Exception
+ {
+ Fqn fqn = Fqn.fromString("/a/b");
+ TransactionManager mgr = cache1.getTransactionManager();
+ assertNull("Should be null", cache1.get(fqn, "key"));
+ assertNull("Should be null", cache2.get(fqn, "key"));
+ mgr.begin();
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ mgr.commit();
+ assertEquals("value", cache2.get(fqn, "key"));
+ assertEquals("value", cache1.get(fqn, "key"));
+
+ mgr.begin();
+ cache1.put(fqn, "key2", "value2");
+ assertEquals("value2", cache1.get(fqn, "key2"));
+ mgr.rollback();
+ assertEquals("value", cache2.get(fqn, "key"));
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertNull("Should be null", cache1.get(fqn, "key2"));
+ assertNull("Should be null", cache2.get(fqn, "key2"));
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java 2008-12-12 12:39:13 UTC (rev 7317)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -2,9 +2,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.*;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
@@ -26,7 +24,7 @@
* @since 2.1.0
*/
@Test(groups = {"functional", "optimistic"}, testName = "invalidation.TombstoneEvictionTest")
-public class TombstoneEvictionTest
+public class TombstoneEvictionTest extends AbstractMultipleCachesTest
{
private CacheSPI c1, c2;
private Fqn fqn = Fqn.fromString("/data/test");
@@ -34,13 +32,11 @@
private EvictionController ec1;
private EvictionController ec2;
- @BeforeMethod
- public void setUp() throws Exception
+
+ protected void createCaches() throws Throwable
{
- log.trace("**** setup called");
+ Configuration c = new Configuration();
- Configuration c = new Configuration();
-
// the FIFO policy cfg
FIFOAlgorithmConfig cfg = new FIFOAlgorithmConfig();
cfg.setMaxNodes(1);
@@ -58,7 +54,7 @@
EvictionConfig ec = new EvictionConfig();
- ec.setWakeupInterval(2000);
+ ec.setWakeupInterval(-1);
ec.setEvictionRegionConfigs(evictionRegionConfigs);
c.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
@@ -73,19 +69,25 @@
c2.start();
ec1 = new EvictionController(c1);
ec2 = new EvictionController(c2);
-
-
TestingUtil.blockUntilViewsReceived(60000, c1, c2);
+ registerCaches(c1, c2);
}
- @AfterMethod
- public void tearDown()
+ @BeforeMethod
+ public void clearQueues()
{
- TestingUtil.killCaches(c1, c2);
- c1 = null;
- c2 = null;
+ clearRegions(c1.getRegionManager().getAllRegions(Region.Type.ANY));
+ clearRegions(c2.getRegionManager().getAllRegions(Region.Type.ANY));
}
+ private void clearRegions(List<Region> regionList)
+ {
+ for (Region region : regionList)
+ {
+ region.resetEvictionQueues();
+ }
+ }
+
private static final Log log = LogFactory.getLog(TombstoneEvictionTest.class);
public void testControl()
Deleted: core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java 2008-12-12 12:39:13 UTC (rev 7317)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java 2008-12-12 23:28:06 UTC (rev 7318)
@@ -1,100 +0,0 @@
-package org.jboss.cache.invalidation;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.UnitTestCacheFactory;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.util.TestingUtil;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-/**
- * This test simulates the problem described in JBCACHE-1155
- *
- * @author <a href="mailto:manik AT jboss DOT org">Manik Surtani</a>
- * @since 2.1.0
- */
-@Test(groups = {"functional", "optimistic"}, testName = "invalidation.VersionInconsistencyTest")
-public class VersionInconsistencyTest
-{
- private Cache cache1, cache2;
- private TransactionManager tm1, tm2;
- private Fqn node = Fqn.fromString("/a");
-
- @BeforeMethod
- public void setUp()
- {
-
- Configuration c1 = new Configuration();
- Configuration c2 = new Configuration();
-
- c1.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
- c2.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
-
- c1.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
- c2.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
-
- c1.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- c2.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
-
- cache1 = new UnitTestCacheFactory<Object, Object>().createCache(c1, false, getClass());
- cache2 = new UnitTestCacheFactory<Object, Object>().createCache(c2, false, getClass());
-
- cache1.start();
- cache2.start();
-
- tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
- tm2 = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
-
- TestingUtil.blockUntilViewsReceived(1000, cache1, cache2);
- }
-
- @AfterMethod
- public void tearDown()
- {
- TestingUtil.killCaches(cache1, cache2);
- cache1 = null;
- cache2 = null;
- }
-
- public void dataInconsistency() throws Exception
- {
- tm1.begin();
- cache1.put(node, "k", "v-older");
- Transaction t1 = tm1.suspend();
-
- tm2.begin();
- cache2.put(node, "k", "v-newer");
- tm2.commit();
-
- tm1.resume(t1);
- try
- {
- tm1.commit();
- assert false : "Should not be allowed to commit with older data!!";
- }
- catch (Exception good)
- {
- }
-
- // the NEWER version of the data should be available, not the OLDER one.
-
- Object val = cache1.get(node, "k");
- assert val == null : "Older data should not have committed";
-
- val = cache2.get(node, "k");
- assert val.equals("v-newer");
-
- // test node versions
- NodeSPI n = ((CacheSPI) cache1).peek(node, true, true);
- assert ((DefaultDataVersion) n.getVersion()).getRawVersion() == 1 : "Version should be 1";
- }
-}
16 years
JBoss Cache SVN: r7317 - in core/branches/flat/src/main/java/org/jboss/starobrno: util and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-12-12 07:39:13 -0500 (Fri, 12 Dec 2008)
New Revision: 7317
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/config/NonOverridable.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java
core/branches/flat/src/main/java/org/jboss/starobrno/util/ReflectionUtil.java
Log:
Override application code in place
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-12-12 12:17:09 UTC (rev 7316)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-12-12 12:39:13 UTC (rev 7317)
@@ -24,10 +24,12 @@
import org.jboss.cache.Version;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.starobrno.CacheException;
import org.jboss.starobrno.config.parsing.JGroupsStackParser;
import org.jboss.starobrno.factories.annotations.NonVolatile;
import org.jboss.starobrno.factories.annotations.Start;
import org.jboss.starobrno.marshall.ExtendedMarshaller;
+import org.jboss.starobrno.util.ReflectionUtil;
import org.w3c.dom.Element;
import java.net.URL;
@@ -153,7 +155,9 @@
// CONFIGURATION OPTIONS
// ------------------------------------------------------------------------------------------------------------
+ @NonOverridable
private String clusterName = "JBossCache-Cluster";
+ @NonOverridable
private String clusterConfig = null;
private boolean useReplQueue = false;
@Dynamic
@@ -201,6 +205,7 @@
private int listenerAsyncQueueSize = 50000;
private int serializationExecutorPoolSize = 0;
private int serializationExecutorQueueSize = 50000;
+ @NonOverridable
private URL jgroupsConfigFile;
@Start(priority = 1)
@@ -225,6 +230,7 @@
public void setCacheMarshaller(ExtendedMarshaller instance)
{
+ testImmutability("marshaller");
marshaller = instance;
}
@@ -1038,6 +1044,24 @@
public void applyOverrides(Configuration overrides)
{
- // TODO: Manik: Implement me
+ // loop through all overridden elements in the incoming configuration and apply
+ for (String overriddenField : overrides.overriddenConfigurationElements)
+ {
+ assertAllowedToOverride(overriddenField);
+ ReflectionUtil.setValue(this, overriddenField, ReflectionUtil.getValue(overrides, overriddenField));
+ }
}
+
+ private void assertAllowedToOverride(String fieldname)
+ {
+ try
+ {
+ if (getClass().getDeclaredField(fieldname).isAnnotationPresent(NonOverridable.class))
+ throw new ConfigurationException("Configuration field " + fieldname + " cannot be overridden!");
+ }
+ catch (NoSuchFieldException e)
+ {
+ throw new CacheException("Field " + fieldname + " does not exist on Configuration!");
+ }
+ }
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java 2008-12-12 12:17:09 UTC (rev 7316)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java 2008-12-12 12:39:13 UTC (rev 7317)
@@ -29,10 +29,7 @@
import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.factories.annotations.Start;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
/**
* Base superclass of Cache configuration classes that expose some properties
@@ -52,6 +49,7 @@
private transient ComponentRegistry cr;
// a workaround to get over immutability checks
private boolean accessible;
+ protected List<String> overriddenConfigurationElements = new LinkedList<String>();
protected ConfigurationComponent()
{
@@ -132,6 +130,9 @@
{
accessible = false;
}
+
+ // now mark this as overridden
+ overriddenConfigurationElements.add(fieldName);
}
public void setCache(CacheSPI cache)
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/NonOverridable.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/NonOverridable.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/NonOverridable.java 2008-12-12 12:39:13 UTC (rev 7317)
@@ -0,0 +1,22 @@
+package org.jboss.starobrno.config;
+
+import java.lang.annotation.*;
+
+/**
+ * This annotation marks configuration attributes as non-overridable by named caches.
+ *
+ * @author Manik Surtani
+ */
+// ensure this annotation is available at runtime.
+(a)Retention(RetentionPolicy.RUNTIME)
+
+// ensure that this annotation is documented on fields in Configuration
+@Documented
+
+// only applies to fields.
+(a)Target(ElementType.FIELD)
+
+public @interface NonOverridable
+{
+
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/util/ReflectionUtil.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/util/ReflectionUtil.java 2008-12-12 12:17:09 UTC (rev 7316)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/util/ReflectionUtil.java 2008-12-12 12:39:13 UTC (rev 7317)
@@ -150,4 +150,24 @@
}
}
+ /**
+ * Retrieves the value of a field of an object instance via reflection
+ *
+ * @param instance to inspect
+ * @param fieldName name of field to retrieve
+ * @return a value
+ */
+ public static Object getValue(Object instance, String fieldName)
+ {
+ Field f = findFieldRecursively(instance.getClass(), fieldName);
+ try
+ {
+ f.setAccessible(true);
+ return f.get(instance);
+ }
+ catch (IllegalAccessException iae)
+ {
+ throw new CacheException("Cannot access field " + f, iae);
+ }
+ }
}
16 years
JBoss Cache SVN: r7316 - in core/branches/flat/src/main/java/org/jboss/starobrno: manager and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-12-12 07:17:09 -0500 (Fri, 12 Dec 2008)
New Revision: 7316
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
Log:
Fleshed out cache manager stuff
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-12-12 11:55:35 UTC (rev 7315)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-12-12 12:17:09 UTC (rev 7316)
@@ -31,11 +31,7 @@
import org.w3c.dom.Element;
import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
/**
* Encapsulates the configuration of a Cache.
@@ -1039,4 +1035,9 @@
{
return getEvictionConfig() != null;
}
+
+ public void applyOverrides(Configuration overrides)
+ {
+ // TODO: Manik: Implement me
+ }
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java 2008-12-12 11:55:35 UTC (rev 7315)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java 2008-12-12 12:17:09 UTC (rev 7316)
@@ -21,12 +21,15 @@
*/
package org.jboss.starobrno.manager;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.starobrno.Cache;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.parsing.XmlConfigurationParserJBC3;
+import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
+import org.jboss.starobrno.config.parsing.XmlConfigurationParserImpl;
import org.jboss.starobrno.lifecycle.Lifecycle;
+import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -126,10 +129,9 @@
* path.
*
* @param configurationFile name of configuration file to use as a template for all caches created
- * @throws org.jboss.starobrno.config.ConfigurationException
- * if there is a problem with the configuration file.
+ * @throws java.io.IOException if there is a problem with the configuration file.
*/
- public CacheManager(String configurationFile) throws ConfigurationException
+ public CacheManager(String configurationFile) throws IOException
{
this(configurationFile, true);
}
@@ -141,22 +143,14 @@
*
* @param configurationFile name of configuration file to use as a template for all caches created
* @param start if true, the cache manager is started
- * @throws org.jboss.starobrno.config.ConfigurationException
- * if there is a problem with the configuration file.
+ * @throws java.io.IOException if there is a problem with the configuration file.
*/
- public CacheManager(String configurationFile, boolean start) throws ConfigurationException
+ public CacheManager(String configurationFile, boolean start) throws IOException
{
try
{
- // todo - need to update parser as per https://docspace.corp.redhat.com/clearspace/docs/DOC-16643
- // todo - need to store named cache overrides
- XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
- configuration = parser.parseFile(configurationFile);
+ initialize(new XmlConfigurationParserImpl(configurationFile));
}
- catch (ConfigurationException ce)
- {
- throw ce;
- }
catch (RuntimeException re)
{
throw new ConfigurationException(re);
@@ -168,10 +162,9 @@
* Constructs and starts a new instance of the CacheManager, using the input stream passed in to read configuration file contents.
*
* @param configurationStream stream containing configuration file contents, to use as a template for all caches created
- * @throws org.jboss.starobrno.config.ConfigurationException
- * if there is a problem with the configuration stream.
+ * @throws java.io.IOException if there is a problem with the configuration stream.
*/
- public CacheManager(InputStream configurationStream) throws ConfigurationException
+ public CacheManager(InputStream configurationStream) throws IOException
{
this(configurationStream, true);
}
@@ -181,22 +174,14 @@
*
* @param configurationStream stream containing configuration file contents, to use as a template for all caches created
* @param start if true, the cache manager is started
- * @throws org.jboss.starobrno.config.ConfigurationException
- * if there is a problem with the configuration stream.
+ * @throws java.io.IOException if there is a problem reading the configuration stream
*/
- public CacheManager(InputStream configurationStream, boolean start) throws ConfigurationException
+ public CacheManager(InputStream configurationStream, boolean start) throws IOException
{
try
{
- // todo - need to update parser as per https://docspace.corp.redhat.com/clearspace/docs/DOC-16643
- // todo - need to store named cache overrides
- XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
- configuration = parser.parseStream(configurationStream);
+ initialize(new XmlConfigurationParserImpl(configurationStream));
}
- catch (ConfigurationException ce)
- {
- throw ce;
- }
catch (RuntimeException re)
{
throw new ConfigurationException(re);
@@ -204,6 +189,12 @@
if (start) start();
}
+ private void initialize(XmlConfigurationParser initializedParser)
+ {
+ configuration = initializedParser.parseDefaultConfiguration();
+ configurationOverrides.putAll(initializedParser.parseNamedConfigurations());
+ }
+
/**
* Defines a named cache. Named caches can be defined by using this method, in which case the configuration
* passed in is used to override the default configuration used when this cache manager instance was created.
@@ -237,13 +228,20 @@
*/
public Cache getCache()
{
- return getOrCreateCache(DEFAULT_CACHE_NAME);
+ try
+ {
+ return getCache(DEFAULT_CACHE_NAME);
+ }
+ catch (NamedCacheNotFoundException e)
+ {
+ throw new RuntimeException("Default cache not found; this should NEVER happen!", e);
+ }
}
/**
- * Retrieves a named cache from the system. The named cache must have been created previously using the {@link #createCache(String)}
- * or {@link #getOrCreateCache(String)} methods, or have been declared in the configuration file used by this <tt>CacheManager</tt>
- * instance, or this method will throw a {@link org.jboss.starobrno.manager.NamedCacheNotFoundException}.
+ * Retrieves a named cache from the system. The named cache must have been defined previously using the {@link #defineCache(String, org.jboss.starobrno.config.Configuration)}
+ * method or have been declared in the configuration file used by this <tt>CacheManager</tt>
+ * instance, otherwise this method will throw a {@link org.jboss.starobrno.manager.NamedCacheNotFoundException}.
*
* @param cacheName name of cache to retrieve
* @return a cache instance identified by cacheName
@@ -251,26 +249,38 @@
*/
public Cache getCache(String cacheName) throws NamedCacheNotFoundException
{
- if (cacheName == null) throw new NullPointerException("Null arguments not allowed");
- return getOrCreateCache(cacheName);
- }
+ if (cacheName == null)
+ throw new NullPointerException("Null arguments not allowed");
- private Cache getOrCreateCache(String cacheName)
- {
- // todo
- return null;
+ if (caches.containsKey(cacheName))
+ return caches.get(cacheName);
+
+ if (!cacheName.equals(DEFAULT_CACHE_NAME) && !configurationOverrides.containsKey(cacheName))
+ throw new NamedCacheNotFoundException("No such cache named " + cacheName + " defined or declared with this CacheManager!");
+
+ return createCache(cacheName);
}
-
private Cache createCache(String cacheName)
{
- // todo
-// if (!caches.containsKey(cacheName))
-// caches.putIfAbsent(cacheName, createNewCache());
+ Configuration c = configuration.clone();
+ if (!cacheName.equals(DEFAULT_CACHE_NAME))
+ {
+ Configuration overrides = configurationOverrides.get(cacheName);
+ c.applyOverrides(overrides);
+ }
- Cache c = caches.get(cacheName);
- c.start();
- return c;
+ Cache cache = new DefaultCacheFactory().createCache(c, false);
+ Cache other = caches.putIfAbsent(cacheName, cache);
+ if (other == null)
+ {
+ cache.start();
+ return cache;
+ }
+ else
+ {
+ return other;
+ }
}
public void start()
@@ -280,6 +290,6 @@
public void stop()
{
- // todo
+ for (Cache cache : caches.values()) cache.stop();
}
}
16 years
JBoss Cache SVN: r7315 - in core/branches/flat/src: main/java/org/jboss/starobrno/config/parsing and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-12-12 06:55:35 -0500 (Fri, 12 Dec 2008)
New Revision: 7315
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserJBC3.java
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java
Modified:
core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/CacheConfigsXmlParser.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlParserBase.java
core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java
Log:
configuration parsers that parse named configurations
Modified: core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-12-12 09:49:01 UTC (rev 7314)
+++ core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -28,7 +28,7 @@
import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
+import org.jboss.starobrno.config.parsing.XmlConfigurationParserJBC3;
import org.jboss.starobrno.factories.ComponentFactory;
import org.jboss.starobrno.factories.ComponentRegistry;
@@ -79,7 +79,7 @@
public org.jboss.starobrno.Cache<K, V> createCache(String configFileName, boolean start) throws ConfigurationException
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
Configuration c;
c = parser.parseFile(configFileName);
return createCache(c, start);
@@ -160,7 +160,7 @@
public Cache<K, V> createCache(InputStream is) throws ConfigurationException
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
Configuration c = null;
c = parser.parseStream(is);
return createCache(c);
@@ -168,7 +168,7 @@
public Cache<K, V> createCache(InputStream is, boolean start) throws ConfigurationException
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
Configuration c = parser.parseStream(is);
return createCache(c, start);
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/CacheConfigsXmlParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/CacheConfigsXmlParser.java 2008-12-12 09:49:01 UTC (rev 7314)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/CacheConfigsXmlParser.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -117,7 +117,7 @@
if (name == null || name.trim().length() == 0)
throw new ConfigurationException("Element " + element + " has no name attribute");
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
Configuration c = null;
if (parser.isValidElementRoot(element))
{
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java 2008-12-12 09:49:01 UTC (rev 7314)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -1,421 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.config.parsing;
-
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.starobrno.config.*;
-import org.jboss.starobrno.config.Configuration.CacheMode;
-import org.jboss.starobrno.config.parsing.element.BuddyElementParser;
-import org.jboss.starobrno.config.parsing.element.CustomInterceptorsElementParser;
-import org.jboss.starobrno.config.parsing.element.EvictionElementParser;
-import org.jboss.starobrno.config.parsing.element.LoadersElementParser;
-import org.jboss.starobrno.util.FileLookup;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.ErrorHandler;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.List;
-
-/**
- * Reads in XMLconfiguration files and spits out a {@link org.jboss.cache.config.Configuration} object.
- * By default this class uses a validating parser (configurable).
- * <p/>
- * Following system properties can be used for customizing parser behavior:
- * <ul>
- * <li> <b>-Djbosscache.config.validate=false</b> will make the parser non-validating </li>
- * <li> <b>-Djbosscache.config.schemaLocation=url</b> allows one to specify a validation schema that would override the one specified in the the xml document </li>
- * </ul>
- * This class is stateful and one instance should be used for parsing a single configuration file.
- *
- * @author Mircea.Markus(a)jboss.com
- * @see org.jboss.cache.config.parsing.RootElementBuilder
- * @since 3.0
- */
-public class XmlConfigurationParser extends XmlParserBase
-{
- private RootElementBuilder rootElementBuilder;
-
- /**
- * the resulting configuration.
- */
- private Configuration config = new Configuration();
- private Element root;
-
- /**
- * If validation is on (default) one can specify an error handler for handling validation errors.
- * The default error handler just logs parsing errors received.
- */
- public XmlConfigurationParser(ErrorHandler errorHandler)
- {
- rootElementBuilder = new RootElementBuilder(errorHandler);
- }
-
- /**
- * Same as {@link #XmlConfigurationParser(org.xml.sax.ErrorHandler)}.
- *
- * @param validating should the underlaying parser disable the validation?
- */
- public XmlConfigurationParser(boolean validating, ErrorHandler errorHandler)
- {
- rootElementBuilder = new RootElementBuilder(errorHandler, validating);
- }
-
- /**
- * Constructs a parser having validation enabled with a ErrorHandler that only logs the parser errors.
- */
- public XmlConfigurationParser()
- {
- rootElementBuilder = new RootElementBuilder();
- }
-
- /**
- * Parses an XML file and returns a new configuration.
- * For looking up the file, {@link org.jboss.starobrno.util.FileLookup} is used.
- *
- * @see org.jboss.starobrno.util.FileLookup
- */
- public Configuration parseFile(String filename)
- {
- InputStream is = new FileLookup().lookupFile(filename);
- if (is == null)
- {
- throw new ConfigurationException("Unable to find config file " + filename + " either in classpath or on the filesystem!");
- }
- return parseStream(is);
- }
-
- /**
- * Similar to {@link #parseFile(String)}, just that it does not create the input stream.
- */
- public Configuration parseStream(InputStream configStream)
- {
- readRoot(configStream);
- return processElements(false);
- }
-
- /**
- * Root should be the <b>jbosscache</b> element in the configuration file.
- */
- public Configuration parseElement(Element root)
- {
- this.root = root;
- this.root.normalize();
- return processElements(false);
- }
-
- public Configuration parseElementIgnoringRoot(Element root)
- {
- this.root = root;
- this.root.normalize();
- return processElements(true);
- }
-
- public boolean isValidating()
- {
- return rootElementBuilder.isValidating();
- }
-
- private Configuration processElements(boolean ignoreRoot)
- {
- if (!ignoreRoot &&
- (!"jbosscache".equals(root.getLocalName()) || !RootElementBuilder.JBOSSCACHE_CORE_NS.equals(root.getNamespaceURI())))
- {
- throw new ConfigurationException("Expected root element {" + RootElementBuilder.JBOSSCACHE_CORE_NS + "}" + "jbosscache");
- }
-
- try
- {
- configureLocking(getSingleElement("locking"));
- configureTransaction(getSingleElement("transaction"));
- configureClustering(getSingleElement("clustering"));
- configureSerialization(getSingleElement("serialization"));
- configureInvalidation(getSingleElement("invalidation"));
- configureStartup(getSingleElement("startup"));
- configureShutdown(getSingleElement("shutdown"));
- configureJmxStatistics(getSingleElement("jmxStatistics"));
- configureEviction(getSingleElement("eviction"));
- configureCacheLoaders(getSingleElement("loaders"));
- configureCustomInterceptors(getSingleElement("customInterceptors"));
- configureListeners(getSingleElement("listeners"));
- configureInvocationBatching(getSingleElement("invocationBatching"));
- }
- catch (Exception e)
- {
- throw new ConfigurationException("Unexpected exception while parsing the configuration file", e);
- }
- return config;
- }
-
- private void configureClustering(Element e)
- {
- if (e == null) return; //we might not have this configured
- // there are 2 attribs - mode and clusterName
- boolean repl = true;
- String mode = getAttributeValue(e, "mode").toUpperCase();
- if (mode.startsWith("R"))
- repl = true;
- else if (mode.startsWith("I"))
- repl = false;
-
- Element asyncEl = getSingleElementInCoreNS("async", e);
- Element syncEl = getSingleElementInCoreNS("sync", e);
- if (syncEl != null && asyncEl != null)
- throw new ConfigurationException("Cannot have sync and async elements within the same cluster element!");
- boolean sync = asyncEl == null; // even if both are null, we default to sync
- if (sync)
- {
- config.setCacheMode(repl ? CacheMode.REPL_SYNC : CacheMode.INVALIDATION_SYNC);
- configureSyncMode(syncEl);
- }
- else
- {
- config.setCacheMode(repl ? CacheMode.REPL_ASYNC : CacheMode.INVALIDATION_ASYNC);
- configureAsyncMode(asyncEl);
- }
- String cn = getAttributeValue(e, "clusterName");
- if (existsAttribute(cn)) config.setClusterName(cn);
- configureBuddyReplication(getSingleElementInCoreNS("buddy", e));
- configureStateRetrieval(getSingleElementInCoreNS("stateRetrieval", e));
- configureTransport(getSingleElementInCoreNS("jgroupsConfig", e));
- }
-
- private void configureStateRetrieval(Element element)
- {
- if (element == null) return; //we might not have this configured
- String fetchInMemoryState = getAttributeValue(element, "fetchInMemoryState");
- if (existsAttribute(fetchInMemoryState)) config.setFetchInMemoryState(getBoolean(fetchInMemoryState));
- String stateRetrievalTimeout = getAttributeValue(element, "timeout");
- if (existsAttribute(stateRetrievalTimeout)) config.setStateRetrievalTimeout(getLong(stateRetrievalTimeout));
-
- }
-
- private void configureTransaction(Element element)
- {
- if (element == null) return;
- String attrName = "transactionManagerLookupClass";
- String txMngLookupClass = getAttributeValue(element, attrName);
- if (existsAttribute(txMngLookupClass)) config.setTransactionManagerLookupClass(txMngLookupClass);
- String syncRollbackPhase = getAttributeValue(element, "syncRollbackPhase");
- if (existsAttribute(syncRollbackPhase)) config.setSyncRollbackPhase(getBoolean(syncRollbackPhase));
- String syncCommitPhase = getAttributeValue(element, "syncCommitPhase");
- if (existsAttribute(syncCommitPhase)) config.setSyncCommitPhase(getBoolean(syncCommitPhase));
- }
-
- private void configureSerialization(Element element)
- {
- if (element == null) return;
- String objectInputStreamPoolSize = getAttributeValue(element, "objectInputStreamPoolSize");
- if (existsAttribute(objectInputStreamPoolSize))
- config.setObjectInputStreamPoolSize(getInt(objectInputStreamPoolSize));
- String objectOutputStreamPoolSize = getAttributeValue(element, "objectOutputStreamPoolSize");
- if (existsAttribute(objectOutputStreamPoolSize))
- config.setObjectOutputStreamPoolSize(getInt(objectOutputStreamPoolSize));
- String version = getAttributeValue(element, "version");
- if (existsAttribute(version)) config.setReplVersionString(version);
- String marshallerClass = getAttributeValue(element, "marshallerClass");
- if (existsAttribute(marshallerClass)) config.setMarshallerClass(marshallerClass);
- String useLazyDeserialization = getAttributeValue(element, "useLazyDeserialization");
- if (existsAttribute(useLazyDeserialization)) config.setUseLazyDeserialization(getBoolean(useLazyDeserialization));
- String useRegionBasedMarshalling = getAttributeValue(element, "useRegionBasedMarshalling");
- if (existsAttribute(useRegionBasedMarshalling))
- config.setUseRegionBasedMarshalling(getBoolean(useRegionBasedMarshalling));
- }
-
- private void configureCustomInterceptors(Element element)
- {
- if (element == null) return; //this element might be missing
- CustomInterceptorsElementParser parser = new CustomInterceptorsElementParser();
- List<CustomInterceptorConfig> interceptorConfigList = parser.parseCustomInterceptors(element);
- config.setCustomInterceptors(interceptorConfigList);
- }
-
- private void configureListeners(Element element)
- {
- if (element == null) return; //this element is optional
- String asyncPoolSizeStr = getAttributeValue(element, "asyncPoolSize");
- if (existsAttribute(asyncPoolSizeStr)) config.setListenerAsyncPoolSize(getInt(asyncPoolSizeStr));
-
- String asyncQueueSizeStr = getAttributeValue(element, "asyncQueueSize");
- if (existsAttribute(asyncQueueSizeStr)) config.setListenerAsyncQueueSize(getInt(asyncQueueSizeStr));
- }
-
- private void configureInvocationBatching(Element element)
- {
- if (element == null) return; //this element is optional
- boolean enabled = getBoolean(getAttributeValue(element, "enabled"));
- config.setInvocationBatchingEnabled(enabled);
- }
-
- private void configureBuddyReplication(Element element)
- {
- if (element == null) return;//buddy config might not exist, expect that
- BuddyElementParser buddyElementParser = new BuddyElementParser();
- BuddyReplicationConfig brConfig = buddyElementParser.parseBuddyElement(element);
- config.setBuddyReplicationConfig(brConfig);
- }
-
- private void configureCacheLoaders(Element element)
- {
- if (element == null) return; //null cache loaders are allowed
- LoadersElementParser clElementParser = new LoadersElementParser();
- CacheLoaderConfig cacheLoaderConfig = clElementParser.parseLoadersElement(element);
- config.setCacheLoaderConfig(cacheLoaderConfig);
- }
-
- private void configureEviction(Element element)
- {
- if (element == null) return; //no eviction might be configured
- EvictionElementParser evictionElementParser = new EvictionElementParser();
- //config.setEvictionConfig(evictionElementParser.parseEvictionElement(element));
- }
-
- private void configureJmxStatistics(Element element)
- {
- if (element == null) return; //might not be specified
- String enabled = getAttributeValue(element, "enabled");
- config.setExposeManagementStatistics(getBoolean(enabled));
- }
-
- private void configureShutdown(Element element)
- {
- if (element == null) return;
- String hookBehavior = getAttributeValue(element, "hookBehavior");
- if (existsAttribute(hookBehavior)) config.setShutdownHookBehavior(hookBehavior);
- }
-
- private void configureTransport(Element element)
- {
- if (element == null) return; //transport might be missing
-
- // first see if a configFile is provided
- String cfgFile = getAttributeValue(element, "configFile");
- if (existsAttribute(cfgFile))
- {
- // try and load this file
- URL u = new FileLookup().lookupFileLocation(cfgFile);
- config.setJgroupsConfigFile(u);
- }
- else
- {
- String multiplexerStack = getAttributeValue(element, "multiplexerStack");
- if (existsAttribute(multiplexerStack))
- {
- config.setMultiplexerStack(multiplexerStack);
- }
- else
- {
- JGroupsStackParser stackParser = new JGroupsStackParser();
- String clusterConfigStr = stackParser.parseClusterConfigXml(element);
- if (clusterConfigStr != null && clusterConfigStr.trim().length() > 0)
- config.setClusterConfig(clusterConfigStr);
- }
- }
- }
-
- private void configureStartup(Element element)
- {
- if (element == null) return; //we might not have this configured
- String inactiveOnStartup = getAttributeValue(element, "regionsInactiveOnStartup");
- if (existsAttribute(inactiveOnStartup)) config.setInactiveOnStartup(getBoolean(inactiveOnStartup));
- }
-
- private void configureInvalidation(Element element)
- {
- if (element == null) return; //might be replication
- Element async = getSingleElement("async");
- if (async != null)
- {
- config.setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
- configureAsyncMode(getSingleElementInCoreNS("async", element));
- }
- Element sync = getSingleElement("sync");
- if (sync != null)
- {
- config.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
- configureSyncMode(getSingleElementInCoreNS("sync", element));
- }
- }
-
- private void configureSyncMode(Element element)
- {
- String replTimeout = getAttributeValue(element, "replTimeout");
- if (existsAttribute(replTimeout)) config.setSyncReplTimeout(getLong(replTimeout));
- }
-
- private void configureAsyncMode(Element element)
- {
- String useReplQueue = getAttributeValue(element, "useReplQueue");
- if (existsAttribute(useReplQueue)) config.setUseReplQueue(getBoolean(useReplQueue));
- String replQueueInterval = getAttributeValue(element, "replQueueInterval");
- if (existsAttribute(replQueueInterval)) config.setReplQueueInterval(getLong(replQueueInterval));
- String replQueueMaxElements = getAttributeValue(element, "replQueueMaxElements");
-
- if (existsAttribute(replQueueMaxElements)) config.setReplQueueMaxElements(getInt(replQueueMaxElements));
- String serializationExecutorPoolSize = getAttributeValue(element, "serializationExecutorPoolSize");
- if (existsAttribute(serializationExecutorPoolSize))
- config.setSerializationExecutorPoolSize(getInt(serializationExecutorPoolSize));
-
- String serializationExecutorQueueSize = getAttributeValue(element, "serializationExecutorQueueSize");
- if (existsAttribute(serializationExecutorQueueSize))
- config.setSerializationExecutorQueueSize(getInt(serializationExecutorQueueSize));
- }
-
- private void configureLocking(Element element)
- {
- String isolationLevel = getAttributeValue(element, "isolationLevel");
- if (existsAttribute(isolationLevel)) config.setIsolationLevel(IsolationLevel.valueOf(isolationLevel));
- String lockParentForChildInsertRemove = getAttributeValue(element, "lockParentForChildInsertRemove");
- if (existsAttribute(lockParentForChildInsertRemove))
- config.setLockParentForChildInsertRemove(getBoolean(lockParentForChildInsertRemove));
- String lockAcquisitionTimeout = getAttributeValue(element, "lockAcquisitionTimeout");
- if (existsAttribute(lockAcquisitionTimeout)) config.setLockAcquisitionTimeout(getLong(lockAcquisitionTimeout));
- String writeSkewCheck = getAttributeValue(element, "writeSkewCheck");
- if (existsAttribute(writeSkewCheck)) config.setWriteSkewCheck(getBoolean(writeSkewCheck));
- String concurrencyLevel = getAttributeValue(element, "concurrencyLevel");
- if (existsAttribute(concurrencyLevel)) config.setConcurrencyLevel(getInt(concurrencyLevel));
- }
-
- private Element getSingleElement(String elementName)
- {
- return getSingleElementInCoreNS(elementName, root);
- }
-
- private void readRoot(InputStream config)
- {
- root = rootElementBuilder.readRoot(config);
- }
-
- /**
- * Tests whether the element passed in is a modern (3.0) config element rather than a legacy one.
- *
- * @param element element to test
- * @return true of the element is a modern one and can be parsed using the current parser.
- */
- public boolean isValidElementRoot(Element element)
- {
- // simply test for the "jbosscache" element.
- NodeList elements = element.getElementsByTagName("jbosscache");
- return elements != null && elements.getLength() > 0;
- }
-}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -0,0 +1,50 @@
+package org.jboss.starobrno.config.parsing;
+
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+/**
+ * Implementations of this interface are responsible for parsing XML configuration files.
+ *
+ * @author Manik Surtani
+ */
+public interface XmlConfigurationParser
+{
+ /**
+ * Initializes the parser with a String that represents the name of the configuration file to parse. Parsers would
+ * attempt to find this file on the classpath first, and failing that, treat the String as an absolute path name on
+ * the file system.
+ *
+ * @param fileName name of file that contains the XML configuration
+ * @throws java.io.IOException if there is a problem reading the configuration file
+ */
+ void initialize(String fileName) throws IOException;
+
+ /**
+ * Initializes the parser with a stream that contains the contents of an XML configuration file to parse.
+ *
+ * @param inputStream stream to read from
+ * @throws IOException if there is a problem reading from the stream
+ */
+ void initialize(InputStream inputStream) throws IOException;
+
+ /**
+ * Parses and retrieves the default configuration. This is typically used to configure the {@link org.jboss.starobrno.manager.CacheManager}.
+ *
+ * @return a Configuration
+ * @throws ConfigurationException if there is a problem parsing the configuration XML
+ */
+ Configuration parseDefaultConfiguration() throws ConfigurationException;
+
+ /**
+ * Parses and retrieves configuration overrides for named caches.
+ *
+ * @return a Map of Configuration overrides keyed on cache name
+ * @throws ConfigurationException if there is a problem parsing the configuration XML
+ */
+ Map<String, Configuration> parseNamedConfigurations() throws ConfigurationException;
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserImpl.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserImpl.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -0,0 +1,101 @@
+package org.jboss.starobrno.config.parsing;
+
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.util.FileLookup;
+import org.w3c.dom.Element;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * The default XML configuration parser
+ *
+ * @author Manik Surtani
+ */
+public class XmlConfigurationParserImpl extends XmlParserBase implements XmlConfigurationParser
+{
+ boolean initialized = false;
+ Element rootElement;
+
+ /**
+ * Constructs a new parser
+ */
+ public XmlConfigurationParserImpl()
+ {
+ }
+
+ /**
+ * Constructs a parser and initializes it with the file name passed in, by calling {@link #initialize(String)}.
+ *
+ * @param fileName file name to initialize the parser with
+ * @throws IOException if there is a problem reading or locating the file.
+ */
+ public XmlConfigurationParserImpl(String fileName) throws IOException
+ {
+ initialize(fileName);
+ }
+
+ /**
+ * Constructs a parser and initializes it with the input stream passed in, by calling {@link #initialize(InputStream)}.
+ *
+ * @param inputStream input stream to initialize the parser with
+ * @throws IOException if there is a problem reading the stream
+ */
+ public XmlConfigurationParserImpl(InputStream inputStream) throws IOException
+ {
+ initialize(inputStream);
+ }
+
+ public void initialize(String fileName) throws IOException
+ {
+ if (fileName == null) throw new NullPointerException("File name cannot be null!");
+ FileLookup fileLookup = new FileLookup();
+ InputStream is = fileLookup.lookupFile(fileName);
+ if (is == null)
+ throw new FileNotFoundException("File " + fileName + " could not be found, either on the classpath or on the file system!");
+ initialize(is);
+ }
+
+ public void initialize(InputStream inputStream) throws IOException
+ {
+ if (inputStream == null) throw new NullPointerException("Input stream cannot be null!");
+ initialized = true;
+ rootElement = new RootElementBuilder().readRoot(inputStream);
+ }
+
+ public Configuration parseDefaultConfiguration() throws ConfigurationException
+ {
+ assertInitialized();
+ Element defaultConfiguration = getSingleElementInCoreNS("default", rootElement);
+ return new XmlConfigurationParserJBC3().parseElementIgnoringRoot(defaultConfiguration);
+ }
+
+ public Map<String, Configuration> parseNamedConfigurations() throws ConfigurationException
+ {
+ assertInitialized();
+ Set<Element> elements = getAllElementsInCoreNS("namedCache", rootElement);
+ if (elements.isEmpty()) return Collections.emptyMap();
+ Map<String, Configuration> namedConfigurations = new HashMap<String, Configuration>(elements.size(), 1.0f);
+ for (Element e : elements)
+ {
+ String configurationName = getAttributeValue(e, "name");
+ if (namedConfigurations.containsKey(configurationName))
+ throw new ConfigurationException("Named cache " + configurationName + " contains duplicate entries!");
+ namedConfigurations.put(configurationName, new XmlConfigurationParserJBC3().parseElementIgnoringRoot(e));
+ }
+
+ return namedConfigurations;
+ }
+
+ private void assertInitialized()
+ {
+ if (!initialized)
+ throw new ConfigurationException("Parser not initialized. Please invoke initialize() first, or use a constructor that initializes the parser.");
+ }
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserJBC3.java (from rev 7277, core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserJBC3.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserJBC3.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -0,0 +1,421 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing;
+
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.starobrno.config.*;
+import org.jboss.starobrno.config.Configuration.CacheMode;
+import org.jboss.starobrno.config.parsing.element.BuddyElementParser;
+import org.jboss.starobrno.config.parsing.element.CustomInterceptorsElementParser;
+import org.jboss.starobrno.config.parsing.element.EvictionElementParser;
+import org.jboss.starobrno.config.parsing.element.LoadersElementParser;
+import org.jboss.starobrno.util.FileLookup;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.ErrorHandler;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+
+/**
+ * Reads in XMLconfiguration files and spits out a {@link org.jboss.cache.config.Configuration} object.
+ * By default this class uses a validating parser (configurable).
+ * <p/>
+ * Following system properties can be used for customizing parser behavior:
+ * <ul>
+ * <li> <b>-Djbosscache.config.validate=false</b> will make the parser non-validating </li>
+ * <li> <b>-Djbosscache.config.schemaLocation=url</b> allows one to specify a validation schema that would override the one specified in the the xml document </li>
+ * </ul>
+ * This class is stateful and one instance should be used for parsing a single configuration file.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @see org.jboss.cache.config.parsing.RootElementBuilder
+ * @since 3.0
+ */
+public class XmlConfigurationParserJBC3 extends XmlParserBase
+{
+ private RootElementBuilder rootElementBuilder;
+
+ /**
+ * the resulting configuration.
+ */
+ private Configuration config = new Configuration();
+ private Element root;
+
+ /**
+ * If validation is on (default) one can specify an error handler for handling validation errors.
+ * The default error handler just logs parsing errors received.
+ */
+ public XmlConfigurationParserJBC3(ErrorHandler errorHandler)
+ {
+ rootElementBuilder = new RootElementBuilder(errorHandler);
+ }
+
+ /**
+ * Same as {@link #XmlConfigurationParserJBC3(org.xml.sax.ErrorHandler)}.
+ *
+ * @param validating should the underlaying parser disable the validation?
+ */
+ public XmlConfigurationParserJBC3(boolean validating, ErrorHandler errorHandler)
+ {
+ rootElementBuilder = new RootElementBuilder(errorHandler, validating);
+ }
+
+ /**
+ * Constructs a parser having validation enabled with a ErrorHandler that only logs the parser errors.
+ */
+ public XmlConfigurationParserJBC3()
+ {
+ rootElementBuilder = new RootElementBuilder();
+ }
+
+ /**
+ * Parses an XML file and returns a new configuration.
+ * For looking up the file, {@link org.jboss.starobrno.util.FileLookup} is used.
+ *
+ * @see org.jboss.starobrno.util.FileLookup
+ */
+ public Configuration parseFile(String filename)
+ {
+ InputStream is = new FileLookup().lookupFile(filename);
+ if (is == null)
+ {
+ throw new ConfigurationException("Unable to find config file " + filename + " either in classpath or on the filesystem!");
+ }
+ return parseStream(is);
+ }
+
+ /**
+ * Similar to {@link #parseFile(String)}, just that it does not create the input stream.
+ */
+ public Configuration parseStream(InputStream configStream)
+ {
+ readRoot(configStream);
+ return processElements(false);
+ }
+
+ /**
+ * Root should be the <b>jbosscache</b> element in the configuration file.
+ */
+ public Configuration parseElement(Element root)
+ {
+ this.root = root;
+ this.root.normalize();
+ return processElements(false);
+ }
+
+ public Configuration parseElementIgnoringRoot(Element root)
+ {
+ this.root = root;
+ this.root.normalize();
+ return processElements(true);
+ }
+
+ public boolean isValidating()
+ {
+ return rootElementBuilder.isValidating();
+ }
+
+ private Configuration processElements(boolean ignoreRoot)
+ {
+ if (!ignoreRoot &&
+ (!"jbosscache".equals(root.getLocalName()) || !RootElementBuilder.JBOSSCACHE_CORE_NS.equals(root.getNamespaceURI())))
+ {
+ throw new ConfigurationException("Expected root element {" + RootElementBuilder.JBOSSCACHE_CORE_NS + "}" + "jbosscache");
+ }
+
+ try
+ {
+ configureLocking(getSingleElement("locking"));
+ configureTransaction(getSingleElement("transaction"));
+ configureClustering(getSingleElement("clustering"));
+ configureSerialization(getSingleElement("serialization"));
+ configureInvalidation(getSingleElement("invalidation"));
+ configureStartup(getSingleElement("startup"));
+ configureShutdown(getSingleElement("shutdown"));
+ configureJmxStatistics(getSingleElement("jmxStatistics"));
+ configureEviction(getSingleElement("eviction"));
+ configureCacheLoaders(getSingleElement("loaders"));
+ configureCustomInterceptors(getSingleElement("customInterceptors"));
+ configureListeners(getSingleElement("listeners"));
+ configureInvocationBatching(getSingleElement("invocationBatching"));
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unexpected exception while parsing the configuration file", e);
+ }
+ return config;
+ }
+
+ private void configureClustering(Element e)
+ {
+ if (e == null) return; //we might not have this configured
+ // there are 2 attribs - mode and clusterName
+ boolean repl = true;
+ String mode = getAttributeValue(e, "mode").toUpperCase();
+ if (mode.startsWith("R"))
+ repl = true;
+ else if (mode.startsWith("I"))
+ repl = false;
+
+ Element asyncEl = getSingleElementInCoreNS("async", e);
+ Element syncEl = getSingleElementInCoreNS("sync", e);
+ if (syncEl != null && asyncEl != null)
+ throw new ConfigurationException("Cannot have sync and async elements within the same cluster element!");
+ boolean sync = asyncEl == null; // even if both are null, we default to sync
+ if (sync)
+ {
+ config.setCacheMode(repl ? CacheMode.REPL_SYNC : CacheMode.INVALIDATION_SYNC);
+ configureSyncMode(syncEl);
+ }
+ else
+ {
+ config.setCacheMode(repl ? CacheMode.REPL_ASYNC : CacheMode.INVALIDATION_ASYNC);
+ configureAsyncMode(asyncEl);
+ }
+ String cn = getAttributeValue(e, "clusterName");
+ if (existsAttribute(cn)) config.setClusterName(cn);
+ configureBuddyReplication(getSingleElementInCoreNS("buddy", e));
+ configureStateRetrieval(getSingleElementInCoreNS("stateRetrieval", e));
+ configureTransport(getSingleElementInCoreNS("jgroupsConfig", e));
+ }
+
+ private void configureStateRetrieval(Element element)
+ {
+ if (element == null) return; //we might not have this configured
+ String fetchInMemoryState = getAttributeValue(element, "fetchInMemoryState");
+ if (existsAttribute(fetchInMemoryState)) config.setFetchInMemoryState(getBoolean(fetchInMemoryState));
+ String stateRetrievalTimeout = getAttributeValue(element, "timeout");
+ if (existsAttribute(stateRetrievalTimeout)) config.setStateRetrievalTimeout(getLong(stateRetrievalTimeout));
+
+ }
+
+ private void configureTransaction(Element element)
+ {
+ if (element == null) return;
+ String attrName = "transactionManagerLookupClass";
+ String txMngLookupClass = getAttributeValue(element, attrName);
+ if (existsAttribute(txMngLookupClass)) config.setTransactionManagerLookupClass(txMngLookupClass);
+ String syncRollbackPhase = getAttributeValue(element, "syncRollbackPhase");
+ if (existsAttribute(syncRollbackPhase)) config.setSyncRollbackPhase(getBoolean(syncRollbackPhase));
+ String syncCommitPhase = getAttributeValue(element, "syncCommitPhase");
+ if (existsAttribute(syncCommitPhase)) config.setSyncCommitPhase(getBoolean(syncCommitPhase));
+ }
+
+ private void configureSerialization(Element element)
+ {
+ if (element == null) return;
+ String objectInputStreamPoolSize = getAttributeValue(element, "objectInputStreamPoolSize");
+ if (existsAttribute(objectInputStreamPoolSize))
+ config.setObjectInputStreamPoolSize(getInt(objectInputStreamPoolSize));
+ String objectOutputStreamPoolSize = getAttributeValue(element, "objectOutputStreamPoolSize");
+ if (existsAttribute(objectOutputStreamPoolSize))
+ config.setObjectOutputStreamPoolSize(getInt(objectOutputStreamPoolSize));
+ String version = getAttributeValue(element, "version");
+ if (existsAttribute(version)) config.setReplVersionString(version);
+ String marshallerClass = getAttributeValue(element, "marshallerClass");
+ if (existsAttribute(marshallerClass)) config.setMarshallerClass(marshallerClass);
+ String useLazyDeserialization = getAttributeValue(element, "useLazyDeserialization");
+ if (existsAttribute(useLazyDeserialization)) config.setUseLazyDeserialization(getBoolean(useLazyDeserialization));
+ String useRegionBasedMarshalling = getAttributeValue(element, "useRegionBasedMarshalling");
+ if (existsAttribute(useRegionBasedMarshalling))
+ config.setUseRegionBasedMarshalling(getBoolean(useRegionBasedMarshalling));
+ }
+
+ private void configureCustomInterceptors(Element element)
+ {
+ if (element == null) return; //this element might be missing
+ CustomInterceptorsElementParser parser = new CustomInterceptorsElementParser();
+ List<CustomInterceptorConfig> interceptorConfigList = parser.parseCustomInterceptors(element);
+ config.setCustomInterceptors(interceptorConfigList);
+ }
+
+ private void configureListeners(Element element)
+ {
+ if (element == null) return; //this element is optional
+ String asyncPoolSizeStr = getAttributeValue(element, "asyncPoolSize");
+ if (existsAttribute(asyncPoolSizeStr)) config.setListenerAsyncPoolSize(getInt(asyncPoolSizeStr));
+
+ String asyncQueueSizeStr = getAttributeValue(element, "asyncQueueSize");
+ if (existsAttribute(asyncQueueSizeStr)) config.setListenerAsyncQueueSize(getInt(asyncQueueSizeStr));
+ }
+
+ private void configureInvocationBatching(Element element)
+ {
+ if (element == null) return; //this element is optional
+ boolean enabled = getBoolean(getAttributeValue(element, "enabled"));
+ config.setInvocationBatchingEnabled(enabled);
+ }
+
+ private void configureBuddyReplication(Element element)
+ {
+ if (element == null) return;//buddy config might not exist, expect that
+ BuddyElementParser buddyElementParser = new BuddyElementParser();
+ BuddyReplicationConfig brConfig = buddyElementParser.parseBuddyElement(element);
+ config.setBuddyReplicationConfig(brConfig);
+ }
+
+ private void configureCacheLoaders(Element element)
+ {
+ if (element == null) return; //null cache loaders are allowed
+ LoadersElementParser clElementParser = new LoadersElementParser();
+ CacheLoaderConfig cacheLoaderConfig = clElementParser.parseLoadersElement(element);
+ config.setCacheLoaderConfig(cacheLoaderConfig);
+ }
+
+ private void configureEviction(Element element)
+ {
+ if (element == null) return; //no eviction might be configured
+ EvictionElementParser evictionElementParser = new EvictionElementParser();
+ //config.setEvictionConfig(evictionElementParser.parseEvictionElement(element));
+ }
+
+ private void configureJmxStatistics(Element element)
+ {
+ if (element == null) return; //might not be specified
+ String enabled = getAttributeValue(element, "enabled");
+ config.setExposeManagementStatistics(getBoolean(enabled));
+ }
+
+ private void configureShutdown(Element element)
+ {
+ if (element == null) return;
+ String hookBehavior = getAttributeValue(element, "hookBehavior");
+ if (existsAttribute(hookBehavior)) config.setShutdownHookBehavior(hookBehavior);
+ }
+
+ private void configureTransport(Element element)
+ {
+ if (element == null) return; //transport might be missing
+
+ // first see if a configFile is provided
+ String cfgFile = getAttributeValue(element, "configFile");
+ if (existsAttribute(cfgFile))
+ {
+ // try and load this file
+ URL u = new FileLookup().lookupFileLocation(cfgFile);
+ config.setJgroupsConfigFile(u);
+ }
+ else
+ {
+ String multiplexerStack = getAttributeValue(element, "multiplexerStack");
+ if (existsAttribute(multiplexerStack))
+ {
+ config.setMultiplexerStack(multiplexerStack);
+ }
+ else
+ {
+ JGroupsStackParser stackParser = new JGroupsStackParser();
+ String clusterConfigStr = stackParser.parseClusterConfigXml(element);
+ if (clusterConfigStr != null && clusterConfigStr.trim().length() > 0)
+ config.setClusterConfig(clusterConfigStr);
+ }
+ }
+ }
+
+ private void configureStartup(Element element)
+ {
+ if (element == null) return; //we might not have this configured
+ String inactiveOnStartup = getAttributeValue(element, "regionsInactiveOnStartup");
+ if (existsAttribute(inactiveOnStartup)) config.setInactiveOnStartup(getBoolean(inactiveOnStartup));
+ }
+
+ private void configureInvalidation(Element element)
+ {
+ if (element == null) return; //might be replication
+ Element async = getSingleElement("async");
+ if (async != null)
+ {
+ config.setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
+ configureAsyncMode(getSingleElementInCoreNS("async", element));
+ }
+ Element sync = getSingleElement("sync");
+ if (sync != null)
+ {
+ config.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
+ configureSyncMode(getSingleElementInCoreNS("sync", element));
+ }
+ }
+
+ private void configureSyncMode(Element element)
+ {
+ String replTimeout = getAttributeValue(element, "replTimeout");
+ if (existsAttribute(replTimeout)) config.setSyncReplTimeout(getLong(replTimeout));
+ }
+
+ private void configureAsyncMode(Element element)
+ {
+ String useReplQueue = getAttributeValue(element, "useReplQueue");
+ if (existsAttribute(useReplQueue)) config.setUseReplQueue(getBoolean(useReplQueue));
+ String replQueueInterval = getAttributeValue(element, "replQueueInterval");
+ if (existsAttribute(replQueueInterval)) config.setReplQueueInterval(getLong(replQueueInterval));
+ String replQueueMaxElements = getAttributeValue(element, "replQueueMaxElements");
+
+ if (existsAttribute(replQueueMaxElements)) config.setReplQueueMaxElements(getInt(replQueueMaxElements));
+ String serializationExecutorPoolSize = getAttributeValue(element, "serializationExecutorPoolSize");
+ if (existsAttribute(serializationExecutorPoolSize))
+ config.setSerializationExecutorPoolSize(getInt(serializationExecutorPoolSize));
+
+ String serializationExecutorQueueSize = getAttributeValue(element, "serializationExecutorQueueSize");
+ if (existsAttribute(serializationExecutorQueueSize))
+ config.setSerializationExecutorQueueSize(getInt(serializationExecutorQueueSize));
+ }
+
+ private void configureLocking(Element element)
+ {
+ String isolationLevel = getAttributeValue(element, "isolationLevel");
+ if (existsAttribute(isolationLevel)) config.setIsolationLevel(IsolationLevel.valueOf(isolationLevel));
+ String lockParentForChildInsertRemove = getAttributeValue(element, "lockParentForChildInsertRemove");
+ if (existsAttribute(lockParentForChildInsertRemove))
+ config.setLockParentForChildInsertRemove(getBoolean(lockParentForChildInsertRemove));
+ String lockAcquisitionTimeout = getAttributeValue(element, "lockAcquisitionTimeout");
+ if (existsAttribute(lockAcquisitionTimeout)) config.setLockAcquisitionTimeout(getLong(lockAcquisitionTimeout));
+ String writeSkewCheck = getAttributeValue(element, "writeSkewCheck");
+ if (existsAttribute(writeSkewCheck)) config.setWriteSkewCheck(getBoolean(writeSkewCheck));
+ String concurrencyLevel = getAttributeValue(element, "concurrencyLevel");
+ if (existsAttribute(concurrencyLevel)) config.setConcurrencyLevel(getInt(concurrencyLevel));
+ }
+
+ private Element getSingleElement(String elementName)
+ {
+ return getSingleElementInCoreNS(elementName, root);
+ }
+
+ private void readRoot(InputStream config)
+ {
+ root = rootElementBuilder.readRoot(config);
+ }
+
+ /**
+ * Tests whether the element passed in is a modern (3.0) config element rather than a legacy one.
+ *
+ * @param element element to test
+ * @return true of the element is a modern one and can be parsed using the current parser.
+ */
+ public boolean isValidElementRoot(Element element)
+ {
+ // simply test for the "jbosscache" element.
+ NodeList elements = element.getElementsByTagName("jbosscache");
+ return elements != null && elements.getLength() > 0;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParserJBC3.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlParserBase.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlParserBase.java 2008-12-12 09:49:01 UTC (rev 7314)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlParserBase.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -23,8 +23,13 @@
import org.jboss.util.StringPropertyReplacer;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Contains utility methods that might be useful to most of the parsers.
*
@@ -72,15 +77,28 @@
protected Element getSingleElement(String namespace, String elementName, Element parent)
{
NodeList nodeList = parent.getElementsByTagNameNS(namespace, elementName);
- if (nodeList.getLength() == 0)
+ if (nodeList.getLength() == 0) return null;
+ return (Element) nodeList.item(0);
+ }
+
+ /**
+ * Convenience method for retrieving all child elements bearing the same element name
+ */
+ protected Set<Element> getAllElements(String namespace, String elementName, Element parent)
+ {
+ NodeList nodeList = parent.getElementsByTagNameNS(namespace, elementName);
+ if (nodeList.getLength() == 0) return Collections.emptySet();
+ Set<Element> elements = new HashSet<Element>();
+ for (int i = 0; i < nodeList.getLength(); i++)
{
- return null;
+ Node n = nodeList.item(i);
+ if (n instanceof Element) elements.add((Element) n);
}
- return (Element) nodeList.item(0);
+ return elements;
}
/**
- * Convenient method for retrieving a single element with the give name.
+ * Convenient method for retrieving a single element with the give name, in the core namespace
*/
protected Element getSingleElementInCoreNS(String elementName, Element parent)
{
@@ -88,6 +106,14 @@
}
/**
+ * Convenience method for retrieving all child elements bearing the same element name, in the core namespace
+ */
+ protected Set<Element> getAllElementsInCoreNS(String elementName, Element parent)
+ {
+ return getAllElements(RootElementBuilder.JBOSSCACHE_CORE_NS, elementName, parent);
+ }
+
+ /**
* Beside querying the element for its attribute value, it will look into the value, if any, and replace the
* jboss properties(e.g. ${someValue:defaultValue}.
* <p/>
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java 2008-12-12 09:49:01 UTC (rev 7314)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -24,7 +24,7 @@
import org.jboss.starobrno.Cache;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
+import org.jboss.starobrno.config.parsing.XmlConfigurationParserJBC3;
import org.jboss.starobrno.lifecycle.Lifecycle;
import java.io.InputStream;
@@ -150,7 +150,7 @@
{
// todo - need to update parser as per https://docspace.corp.redhat.com/clearspace/docs/DOC-16643
// todo - need to store named cache overrides
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
configuration = parser.parseFile(configurationFile);
}
catch (ConfigurationException ce)
@@ -190,7 +190,7 @@
{
// todo - need to update parser as per https://docspace.corp.redhat.com/clearspace/docs/DOC-16643
// todo - need to store named cache overrides
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
configuration = parser.parseStream(configurationStream);
}
catch (ConfigurationException ce)
Modified: core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java 2008-12-12 09:49:01 UTC (rev 7314)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java 2008-12-12 11:55:35 UTC (rev 7315)
@@ -6,9 +6,15 @@
*/
package org.jboss.starobrno;
-import org.jboss.cache.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.parsing.XmlConfigurationParserJBC3;
+import org.jboss.starobrno.util.TestingUtil;
+import org.jgroups.conf.XmlConfigurator;
import java.io.InputStream;
import java.net.URL;
@@ -17,11 +23,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
-import org.jboss.starobrno.util.TestingUtil;
-import org.jgroups.conf.XmlConfigurator;
/**
* @author <a href="mailto:dpospisi@redhat.com">Dominik Pospisil (dpospisi(a)redhat.com)</a>
@@ -99,7 +100,7 @@
public Cache<K, V> createCache(String configFileName, boolean start) throws ConfigurationException
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
Configuration c;
c = parser.parseFile(configFileName);
return createCache(c, start);
@@ -117,7 +118,7 @@
public Cache<K, V> createCache(InputStream is, boolean start) throws ConfigurationException
{
- XmlConfigurationParser parser = new XmlConfigurationParser();
+ XmlConfigurationParserJBC3 parser = new XmlConfigurationParserJBC3();
Configuration c = parser.parseStream(is);
return createCache(c, start);
}
@@ -323,11 +324,12 @@
}
return null;
}
-
- private String getDefaultClusterConfiguration() {
+
+ private String getDefaultClusterConfiguration()
+ {
return getClusterConfigFromFile(new Configuration().getDefaultClusterConfig());
}
-
+
/**
* Helper method that takes a <b>JGroups</b> configuration file and creates an old-style JGroups config {@link String} that can be used
* in {@link org.jboss.cache.config.Configuration#setClusterConfig(String)}. Note that expressions
@@ -355,5 +357,5 @@
throw new RuntimeException("Problems with url " + url, e);
}
}
-
+
}
16 years
JBoss Cache SVN: r7314 - core/trunk/src/test/java/org/jboss/cache/eviction.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-12-12 04:49:01 -0500 (Fri, 12 Dec 2008)
New Revision: 7314
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java
Log:
no need to create a JChannel for local caches
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java 2008-12-12 09:42:15 UTC (rev 7313)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java 2008-12-12 09:49:01 UTC (rev 7314)
@@ -6,12 +6,9 @@
*/
package org.jboss.cache.eviction;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.*;
import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
@@ -208,10 +205,11 @@
private CacheSPI<Object, Object> setupCache(String configurationName)
{
- CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(configurationName, false, getClass());
- cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
- cache.start();
- return cache;
+ UnitTestCacheFactory<Object, Object> testCacheFactory = new UnitTestCacheFactory<Object, Object>();
+ Configuration config = testCacheFactory.getConfigurationFromFile(configurationName);
+ config.setCacheMode(Configuration.CacheMode.LOCAL);
+ config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ config.setIsolationLevel(IsolationLevel.SERIALIZABLE);
+ return (CacheSPI<Object, Object>) testCacheFactory.createCache(config, getClass());
}
}
16 years
JBoss Cache SVN: r7313 - core/trunk/src/test/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-12-12 04:42:15 -0500 (Fri, 12 Dec 2008)
New Revision: 7313
Modified:
core/trunk/src/test/java/org/jboss/cache/UnitTestCacheFactory.java
Log:
fixed bug
Modified: core/trunk/src/test/java/org/jboss/cache/UnitTestCacheFactory.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/UnitTestCacheFactory.java 2008-12-12 09:37:21 UTC (rev 7312)
+++ core/trunk/src/test/java/org/jboss/cache/UnitTestCacheFactory.java 2008-12-12 09:42:15 UTC (rev 7313)
@@ -91,17 +91,17 @@
public Cache<K, V> createCache(Class ownerClass) throws ConfigurationException
{
- return createCache(true, getClass());
+ return createCache(true, ownerClass);
}
public Cache<K, V> createCache(boolean start, Class ownerClass) throws ConfigurationException
{
- return createCache(new Configuration(), start, getClass());
+ return createCache(new Configuration(), start, ownerClass);
}
public Cache<K, V> createCache(String configFileName, Class ownerClass) throws ConfigurationException
{
- return createCache(configFileName, true, getClass());
+ return createCache(configFileName, true, ownerClass);
}
public Cache<K, V> createCache(String configFileName, boolean start, Class ownerClass) throws ConfigurationException
@@ -117,7 +117,7 @@
XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();
c = oldParser.parseFile(configFileName);
}
- return createCache(c, start, getClass());
+ return createCache(c, start, ownerClass);
}
public Cache<K, V> createCache(Configuration configuration, Class ownerClass) throws ConfigurationException
16 years
JBoss Cache SVN: r7312 - core/trunk/src/test/java/org/jboss/cache/eviction.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-12-12 04:37:21 -0500 (Fri, 12 Dec 2008)
New Revision: 7312
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java
Log:
use in memroyCL to increase performance
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java 2008-12-12 09:36:40 UTC (rev 7311)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java 2008-12-12 09:37:21 UTC (rev 7312)
@@ -54,7 +54,6 @@
void initCaches() throws Exception
{
- TestingUtil.recursiveFileRemove(tmpDir + cacheLoaderDir);
UnitTestCacheFactory<Integer, String> factory = new UnitTestCacheFactory<Integer, String>();
Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
conf.setEvictionConfig(buildEvictionConfig());
16 years
JBoss Cache SVN: r7311 - core/trunk/src/test/java/org/jboss/cache/eviction.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-12-12 04:36:40 -0500 (Fri, 12 Dec 2008)
New Revision: 7311
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java
Log:
use in memroyCL to increase performance
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java 2008-12-12 09:22:34 UTC (rev 7310)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java 2008-12-12 09:36:40 UTC (rev 7311)
@@ -50,7 +50,6 @@
{
fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis);
}
-
}
void initCaches() throws Exception
@@ -72,10 +71,7 @@
cacheLoaderConfig.setPreload("/");
cacheLoaderConfig.setShared(false);
CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
- iclc.setClassName("org.jboss.cache.loader.FileCacheLoader");
- Properties p = new Properties();
- p.put("location", tmpDir + cacheLoaderDir);
- iclc.setProperties(p);
+ iclc.setClassName("org.jboss.cache.loader.DummyInMemoryCacheLoader");
iclc.setAsync(false);
iclc.setFetchPersistentState(true);
iclc.setIgnoreModifications(false);
@@ -96,9 +92,7 @@
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- TestingUtil.recursiveFileRemove(tmpDir + cacheLoaderDir);
TestingUtil.killCaches(cache);
- cache = null;
}
public void testConcurrentEviction() throws Exception
16 years
JBoss Cache SVN: r7310 - in core/trunk/src/test/java/org/jboss/cache: api/pfer and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-12-12 04:22:34 -0500 (Fri, 12 Dec 2008)
New Revision: 7310
Modified:
core/trunk/src/test/java/org/jboss/cache/api/CacheSPITest.java
core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java
core/trunk/src/test/java/org/jboss/cache/util/internals/replicationlisteners/ReplicationListener.java
Log:
made replication listeners more stronger
Modified: core/trunk/src/test/java/org/jboss/cache/api/CacheSPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/CacheSPITest.java 2008-12-12 08:57:24 UTC (rev 7309)
+++ core/trunk/src/test/java/org/jboss/cache/api/CacheSPITest.java 2008-12-12 09:22:34 UTC (rev 7310)
@@ -55,13 +55,13 @@
cache2.start();
memb1 = cache1.getMembers();
- TestingUtil.blockUntilViewsReceived(5000, false, cache1, cache2);
+ TestingUtil.blockUntilViewsReceived(10000, false, cache1, cache2);
List memb2 = cache2.getMembers();
assertEquals("View has two members", 2, memb1.size());
assertEquals("Both caches have same view", memb1, memb2);
cache1.stop();
- TestingUtil.blockUntilViewsReceived(5000, false, cache2);
+ TestingUtil.blockUntilViewsReceived(10000, false, cache2);
memb2 = cache2.getMembers();
assertEquals("View has one member", 1, memb2.size());
assertFalse("Coordinator changed", coord.equals(memb2.get(0)));
Modified: core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java 2008-12-12 08:57:24 UTC (rev 7309)
+++ core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java 2008-12-12 09:22:34 UTC (rev 7310)
@@ -139,7 +139,10 @@
// cleanup
TestingUtil.extractComponentRegistry(cache1).registerComponent(originalRpcManager, RPCManager.class);
TestingUtil.extractComponentRegistry(cache1).rewire();
+
+ replListener2.expect(RemoveNodeCommand.class);
cache1.removeNode(fqn);
+ replListener2.waitForReplicationToOccur();
}
public void testTxSuspension() throws Exception
@@ -284,7 +287,7 @@
tm1.begin();
cache1.putForExternalRead(fqn, key, value);
tm1.commit();
- replListener2.waitForReplicationToOccur(10000);
+ replListener2.waitForReplicationToOccur();
assert cache1.getTransactionTable().getNumGlobalTransactions() == 0 : "Cache 1 should have no stale global TXs";
@@ -362,7 +365,10 @@
verify(rpcManager);
// cleanup
cache1.getConfiguration().getRuntimeConfig().setRPCManager(originalRpcManager);
+
+ replListener2.expect(RemoveNodeCommand.class);
cache1.removeNode(fqn);
+ replListener2.waitForReplicationToOccur();
}
protected abstract void assertLocked(Fqn fqn, CacheSPI cache, boolean writeLocked);
Modified: core/trunk/src/test/java/org/jboss/cache/util/internals/replicationlisteners/ReplicationListener.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/internals/replicationlisteners/ReplicationListener.java 2008-12-12 08:57:24 UTC (rev 7309)
+++ core/trunk/src/test/java/org/jboss/cache/util/internals/replicationlisteners/ReplicationListener.java 2008-12-12 09:22:34 UTC (rev 7310)
@@ -58,7 +58,6 @@
*/
abstract public class ReplicationListener
{
-
public static final long DEFAULT_TIMEOUT = 10000;
private CountDownLatch latch = new CountDownLatch(1);
protected List<Class<? extends ReplicableCommand>> expectedCommands;
@@ -195,6 +194,7 @@
}
finally
{
+ System.out.println("Processed command: " + realOne);
if (realOne instanceof ReplicateCommand)
{
postReplicateExecution((ReplicateCommand)realOne);
16 years