Author: bstansberry(a)jboss.com
Date: 2008-01-14 22:51:56 -0500 (Mon, 14 Jan 2008)
New Revision: 5130
Modified:
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
Log:
[JBCACHE-1265] Setting cacheModeLocal=true ineffective for addChild(Fqn) call
Duplicate the other tests using the Node API.
Modified:
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java 2008-01-15
00:19:02 UTC (rev 5129)
+++
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java 2008-01-15
03:51:56 UTC (rev 5130)
@@ -10,9 +10,11 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -156,6 +158,57 @@
}
}
+ public void testPutKeyValueViaNodeAPI() throws Exception
+ {
+ Node node1 = cache1.getRoot().addChild(fqn);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node1.put(key, "value");
+ delay();
+ // cache1 should still have this
+ assertEquals("value", cache1.get(fqn, key));
+
+ // cache 2 should not
+ assertNull("Should be null", cache2.get(fqn, key));
+
+ // now try again with passing the default options
+ cache1.getInvocationContext().getOptionOverrides().reset();
+ node1.put(key, "value");
+ delay();
+ // cache1 should still have this
+ assertEquals("value", cache1.get(fqn, key));
+
+ // cache 2 should as well
+ if (!isInvalidation)
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertNull("should be invalidated", cache2.get(fqn, key));
+ }
+
+ // now cache2
+ Node node2 = cache2.getRoot().getChild(fqn);
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node2.put(key, "value2");
+ delay();
+ assertEquals("value2", cache2.get(fqn, key));
+ assertEquals("value", cache1.get(fqn, key));
+
+ cache2.getInvocationContext().getOptionOverrides().reset();
+ node2.put(key, "value2");
+ delay();
+ assertEquals("value2", cache2.get(fqn, key));
+ if (!isInvalidation)
+ {
+ assertEquals("value2", cache1.get(fqn, key));
+ }
+ else
+ {
+ assertNull("should be invalidated", cache1.get(fqn, key));
+ }
+ }
+
public void testPutData() throws Exception
{
Map<String, String> map = new HashMap<String, String>();
@@ -207,6 +260,59 @@
}
}
+ public void testPutDataViaNodeAPI() throws Exception
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(key, "value");
+
+ Node node1 = cache1.getRoot().addChild(fqn);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node1.putAll(map);
+ delay();
+ // cache1 should still have this
+ assertEquals("value", cache1.get(fqn, key));
+ // cache 2 should not
+ assertNull("Should be null", cache2.get(fqn, key));
+
+ // now try again with passing the default options
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ node1.putAll(map);
+ delay();
+ // cache1 should still have this
+ assertEquals("value", cache1.get(fqn, key));
+ // cache 2 should as well
+ if (!isInvalidation)
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertNull("should be invalidated", cache2.get(fqn, key));
+ }
+
+ // now cache2
+ Node node2 = cache2.getRoot().getChild(fqn);
+ map.put(key, "value2");
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node2.putAll(map);
+ delay();
+ assertEquals("value2", cache2.get(fqn, key));
+ assertEquals("value", cache1.get(fqn, key));
+
+ cache2.getInvocationContext().getOptionOverrides().reset();
+ node2.put(key, "value2");
+ delay();
+ assertEquals("value2", cache2.get(fqn, key));
+ if (!isInvalidation)
+ {
+ assertEquals("value2", cache1.get(fqn, key));
+ }
+ else
+ {
+ assertNull("should be invalidated", cache1.get(fqn, key));
+ }
+ }
+
public void testRemoveNode() throws Exception
{
// put some stuff in the cache first
@@ -263,6 +369,62 @@
assertNull("should be null", cache2.get(fqn, key));
}
+ public void testRemoveNodeViaNodeAPI() throws Exception
+ {
+ // put some stuff in the cache first
+ // make sure we cleanup thread local vars.
+ cache1.getInvocationContext().setOptionOverrides(null);
+ cache1.put(fqn, key, "value");
+ delay();
+ assertEquals("value", cache1.get(fqn, key));
+ if (isInvalidation)
+ {
+ assertNull("Should be null", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.getRoot().removeChild(fqn);
+ delay();
+
+ // should be removed in cache1
+ assertNull("should be null", cache1.get(fqn, key));
+ // Not in cache2
+ if (isInvalidation)
+ {
+ assertNull("Should be null", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+
+ // replace cache entries
+ cache1.put(fqn, key, "value");
+ delay();
+ assertEquals("value", cache1.get(fqn, key));
+ if (isInvalidation)
+ {
+ assertNull("Should be null", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+
+ // now try again with passing the default options
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ cache1.getRoot().removeChild(fqn);
+ delay();
+
+ // both should be null
+ assertNull("should be null", cache1.get(fqn, key));
+ assertNull("should be null", cache2.get(fqn, key));
+ }
+
public void testRemoveKey() throws Exception
{
// put some stuff in the cache first
@@ -318,6 +480,62 @@
assertNull("should be null", cache2.get(fqn, key));
}
+ public void testRemoveKeyViaNodeAPI() throws Exception
+ {
+ // put some stuff in the cache first
+ Node node1 = cache1.getRoot().addChild(fqn);
+ cache1.getInvocationContext().setOptionOverrides(null);
+ node1.put(key, "value");
+ delay();
+ assertEquals("value", cache1.get(fqn, key));
+ if (isInvalidation)
+ {
+ assertNull("Should be null", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node1.remove(key);
+ delay();
+
+ // should be removed in cache1
+ assertNull("should be null", cache1.get(fqn, key));
+ // Not in cache2
+ if (isInvalidation)
+ {
+ assertNull("Should be null", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+
+ // replace cache entries
+ node1.put(key, "value");
+ delay();
+ assertEquals("value", cache1.get(fqn, key));
+ if (isInvalidation)
+ {
+ assertNull("Should be null", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+
+ // now try again with passing the default options
+ cache1.getInvocationContext().getOptionOverrides().reset();
+ node1.remove(key);
+ delay();
+
+ // both should be null
+ assertNull("should be null", cache1.get(fqn, key));
+ assertNull("should be null", cache2.get(fqn, key));
+ }
+
public void testTransactionalBehaviour() throws Exception
{
TransactionManager mgr = cache1.getTransactionManager();
@@ -401,6 +619,120 @@
}
+ public void testTransactionalBehaviourViaNodeAPI() throws Exception
+ {
+ Node node1 = cache1.getRoot().addChild(fqn);
+ TransactionManager mgr = cache1.getTransactionManager();
+ mgr.begin();
+ cache1.getInvocationContext().getOptionOverrides().reset();
+ node1.put(key, "value1");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node1.put(key, "value2");
+ mgr.commit();
+ delay();
+ // cache1 should still have this
+ assertEquals("value2", cache1.get(fqn, key));
+
+ if (!isInvalidation)
+ {
+ assertEquals("value1", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertNull(cache2.get(fqn, key));
+ }
+
+ // now try again with passing the default options
+ mgr.begin();
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node1.put(key, "value3");
+ cache1.getInvocationContext().getOptionOverrides().reset();
+ node1.put(key, "value");
+ mgr.commit();
+ delay();
+ // cache1 should still have this
+ assertEquals("value", cache1.get(fqn, key));
+
+ // cache 2 should as well
+ if (!isInvalidation)
+ {
+ assertEquals("value", cache2.get(fqn, key));
+ }
+ else
+ {
+ assertNull("should be invalidated", cache2.get(fqn, key));
+ }
+
+ // now cache2
+ Node node2 = cache2.getRoot().addChild(fqn);
+ mgr = cache2.getTransactionManager();
+ mgr.begin();
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ node2.put(key, "value3");
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node2.put(key, "value2");
+ mgr.commit();
+ delay();
+
+ assertEquals("value2", cache2.get(fqn, key));
+
+ if (!isInvalidation)
+ {
+ assertEquals("value3", cache1.get(fqn, key));
+ }
+ else
+ {
+ assertNull(cache1.get(fqn, key));
+ }
+
+ mgr.begin();
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ node2.put(key, "value2");
+ cache2.getInvocationContext().getOptionOverrides().reset();
+ node2.put(key, "value2");
+ mgr.commit();
+ delay();
+ assertEquals("value2", cache2.get(fqn, key));
+ if (!isInvalidation)
+ {
+ assertEquals("value2", cache1.get(fqn, key));
+ }
+ else
+ {
+ assertNull("should be invalidated", cache1.get(fqn, key));
+ }
+
+ }
+
+ public void testAddChild() throws Exception
+ {
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.getRoot().addChild(fqn);
+ delay();
+ // cache1 should still have this
+ assertTrue(cache1.getRoot().hasChild(fqn));
+ // cache 2 should not
+ Node node2 = cache2.getRoot().getChild(fqn);
+ assertTrue("Should be null", node2 == null || (isInvalidation &&
!node2.isValid()));
+
+ // now try again with passing the default options
+ cache1.getRoot().removeChild(fqn);
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ cache1.getRoot().addChild(fqn);
+ delay();
+ // cache1 should still have this
+ assertTrue(cache1.getRoot().hasChild(fqn));
+ // cache 2 should as well
+ if (!isInvalidation)
+ {
+ assertTrue(cache2.getRoot().hasChild(fqn));
+ }
+ else
+ {
+ assertTrue("Should be null", node2 == null || !node2.isValid());
+ }
+ }
+
protected abstract void delay();
}
\ No newline at end of file