[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...
Manik Surtani
manik at jboss.org
Fri Jul 13 08:37:02 EDT 2007
User: msurtani
Date: 07/07/13 08:37:02
Modified: tests/functional/org/jboss/cache/loader
CacheLoaderTestsBase.java
UnnecessaryLoadingTest.java
Log:
JBCACHE-1120
Revision Changes Path
1.56 +48 -1 JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderTestsBase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderTestsBase.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderTestsBase.java,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -b -r1.55 -r1.56
--- CacheLoaderTestsBase.java 13 Jul 2007 11:26:00 -0000 1.55
+++ CacheLoaderTestsBase.java 13 Jul 2007 12:37:02 -0000 1.56
@@ -21,6 +21,7 @@
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -33,7 +34,7 @@
* Commons tests for all CacheLoaders
*
* @author Bela Ban
- * @version $Id: CacheLoaderTestsBase.java,v 1.55 2007/07/13 11:26:00 msurtani Exp $
+ * @version $Id: CacheLoaderTestsBase.java,v 1.56 2007/07/13 12:37:02 msurtani Exp $
*/
abstract public class CacheLoaderTestsBase extends AbstractCacheLoaderTestBase
{
@@ -156,6 +157,7 @@
assertEquals(20, retval);
}
+
public void testPut2() throws Exception
{
final String NODE = "/a/b/c";
@@ -857,6 +859,51 @@
assertEquals("no more keys", 0, keys.size());
}
+ public void testRemoveData4() throws Exception
+ {
+ Set keys;
+ Fqn key = Fqn.fromString("/x/y/z/");
+ cache.put(key, "keyA", "valA");
+ cache.put(key, "keyB", "valB");
+ cache.put(key, "keyC", "valC");
+ keys = cache.getKeys(key);
+ assertEquals(3, keys.size());
+ cache.evict(key);
+ Map map = new HashMap();
+ map.put("keyA", "valA");
+ map.put("keyB", "valB");
+ map.put("keyC", "valC");
+ assertEquals(map, loader.get(key));
+ Node n = cache.getRoot().getChild(key);
+ n.clearData();
+ assertEquals(Collections.emptyMap(), loader.get(key));
+ }
+
+ public void testReplaceAll() throws Exception
+ {
+ Set keys;
+ Fqn key = Fqn.fromString("/x/y/z/");
+ cache.put(key, "keyA", "valA");
+ cache.put(key, "keyB", "valB");
+ cache.put(key, "keyC", "valC");
+ keys = cache.getKeys(key);
+ assertEquals(3, keys.size());
+ cache.evict(key);
+
+ Map map = new HashMap();
+ map.put("keyA", "valA");
+ map.put("keyB", "valB");
+ map.put("keyC", "valC");
+ Map newMap = new HashMap();
+ newMap.put("keyD", "valD");
+ newMap.put("keyE", "valE");
+
+ assertEquals(map, loader.get(key));
+ Node n = cache.getRoot().getChild(key);
+ n.replaceAll(newMap);
+ assertEquals(newMap, loader.get(key));
+ }
+
public void testRemoveKey()
{
String key = "/x/y/z/";
1.5 +108 -1 JBossCache/tests/functional/org/jboss/cache/loader/UnnecessaryLoadingTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UnnecessaryLoadingTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/UnnecessaryLoadingTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- UnnecessaryLoadingTest.java 12 Jul 2007 17:04:36 -0000 1.4
+++ UnnecessaryLoadingTest.java 13 Jul 2007 12:37:02 -0000 1.5
@@ -210,4 +210,111 @@
assertFalse(cache.peek(parent, false).isDataLoaded());
}
+ public void testDontLoadDataWhenClearingNode()
+ {
+ mockCacheLoader.expects(never()).method("get").withAnyArguments();
+ mockCacheLoader.expects(never()).method("getChildrenNames").withAnyArguments();
+ mockCacheLoader.expects(never()).method("exists").withAnyArguments();
+ mockCacheLoader.expects(never()).method("remove").withAnyArguments();
+ mockCacheLoader.expects(never()).method("removeData").withAnyArguments();
+ mockCacheLoader.expects(never()).method("put").withAnyArguments();
+
+ mockCacheLoader.expects(once()).method("put").with(eq(parent), eq(k), eq(v));
+
+ // create parent and child with data
+ // new nodes being created, will result in loading them from the cache loader first
+ mockCacheLoader.expects(once()).method("get").with(eq(parent));
+
+ cache.put(parent, k, v);
+ assertTrue(cache.peek(parent, false).isDataLoaded());
+ // evict the parent
+ cache.evict(parent, false);
+ assertNull(cache.peek(parent, false));
+
+ mockCacheLoader.expects(once()).method("exists").with(eq(parent)).will(returnValue(true));
+ // now get node.
+ Node n = cache.getRoot().getChild(parent);
+ assertNotNull(n);
+ assertFalse(cache.peek(parent, false).isDataLoaded());
+
+ // should not load node but should change isDataLoaded to true
+ // will trigger a removedata() though
+ mockCacheLoader.expects(once()).method("removeData").with(eq(parent));
+ n.clearData();
+
+ assertTrue(cache.peek(parent, false).isDataLoaded());
+ }
+
+ public void testDontLoadDataWhenReplacingNode()
+ {
+ mockCacheLoader.expects(never()).method("get").withAnyArguments();
+ mockCacheLoader.expects(never()).method("getChildrenNames").withAnyArguments();
+ mockCacheLoader.expects(never()).method("exists").withAnyArguments();
+ mockCacheLoader.expects(never()).method("remove").withAnyArguments();
+ mockCacheLoader.expects(never()).method("removeData").withAnyArguments();
+ mockCacheLoader.expects(never()).method("put").withAnyArguments();
+
+ mockCacheLoader.expects(once()).method("put").with(eq(parent), eq(k), eq(v));
+
+ // create parent and child with data
+ // new nodes being created, will result in loading them from the cache loader first
+ mockCacheLoader.expects(once()).method("get").with(eq(parent));
+
+ cache.put(parent, k, v);
+ assertTrue(cache.peek(parent, false).isDataLoaded());
+ // evict the parent
+ cache.evict(parent, false);
+ assertNull(cache.peek(parent, false));
+
+ mockCacheLoader.expects(once()).method("exists").with(eq(parent)).will(returnValue(true));
+ // now get node.
+ Node n = cache.getRoot().getChild(parent);
+ assertNotNull(n);
+ assertFalse(cache.peek(parent, false).isDataLoaded());
+
+ // should not load node but should change isDataLoaded to true
+ // will trigger a put() though
+ // for the moment this does a get as well - which while unnecessary is the best we can do for now until we bring in
+ // an AOP framework to work on nodes directly.
+ mockCacheLoader.expects(once()).method("get").with(eq(parent)).will(returnValue(Collections.singletonMap(k, v)));
+ mockCacheLoader.expects(once()).method("removeData").with(eq(parent));
+ mockCacheLoader.expects(once()).method("put").with(eq(parent), eq(Collections.singletonMap("hello", "world")));
+ n.replaceAll(Collections.singletonMap("hello", "world"));
+
+ assertTrue(cache.peek(parent, false).isDataLoaded());
+ }
+
+ public void testLazyLoadDataWhenWorkingWithNode()
+ {
+ mockCacheLoader.expects(never()).method("get").withAnyArguments();
+ mockCacheLoader.expects(never()).method("getChildrenNames").withAnyArguments();
+ mockCacheLoader.expects(never()).method("exists").withAnyArguments();
+ mockCacheLoader.expects(never()).method("remove").withAnyArguments();
+ mockCacheLoader.expects(never()).method("removeData").withAnyArguments();
+ mockCacheLoader.expects(never()).method("put").withAnyArguments();
+
+ mockCacheLoader.expects(once()).method("put").with(eq(parent), eq(k), eq(v));
+
+ // create parent and child with data
+ // new nodes being created, will result in loading them from the cache loader first
+ mockCacheLoader.expects(once()).method("get").with(eq(parent));
+
+ cache.put(parent, k, v);
+ assertTrue(cache.peek(parent, false).isDataLoaded());
+ // evict the parent
+ cache.evict(parent, false);
+ assertNull(cache.peek(parent, false));
+
+ mockCacheLoader.expects(once()).method("exists").with(eq(parent)).will(returnValue(true));
+ // now get node.
+ Node n = cache.getRoot().getChild(parent);
+ assertNotNull(n);
+ assertFalse(cache.peek(parent, false).isDataLoaded());
+
+ // will trigger a load
+ mockCacheLoader.expects(once()).method("get").with(eq(parent)).will(returnValue(Collections.singletonMap(k, v)));
+ assertEquals(v, n.get(k));
+ // should change isDataLoaded to true
+ assertTrue(cache.peek(parent, false).isDataLoaded());
+ }
}
More information about the jboss-cvs-commits
mailing list