[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...
Manik Surtani
manik at jboss.org
Thu Jul 12 12:35:19 EDT 2007
User: msurtani
Date: 07/07/12 12:35:19
Modified: tests/functional/org/jboss/cache/loader
UnnecessaryLoadingTest.java
Log:
JBCACHE-1133
Revision Changes Path
1.3 +44 -2 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UnnecessaryLoadingTest.java 12 Jul 2007 14:29:04 -0000 1.2
+++ UnnecessaryLoadingTest.java 12 Jul 2007 16:35:19 -0000 1.3
@@ -3,12 +3,18 @@
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.CacheLoaderConfig;
import org.jboss.cache.factories.InterceptorChainFactory;
import org.jboss.cache.interceptors.Interceptor;
import org.jmock.Mock;
import org.jmock.MockObjectTestCase;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
/**
* //TODO: MANIK: Javadoc this class
*
@@ -18,8 +24,8 @@
public class UnnecessaryLoadingTest extends MockObjectTestCase
{
private CacheSPI cache;
- private Fqn parent = Fqn.fromString("/a");
- private Fqn child = Fqn.fromString("/a/b");
+ private Fqn parent = Fqn.fromString("/parent");
+ private Fqn child = Fqn.fromString("/parent/child");
private String k = "k", v = "v";
private Mock mockCacheLoader;
@@ -140,4 +146,40 @@
// should be NO cache loading involved whatsoever
}
+ public void testUnnecessaryMultipleLoading()
+ {
+ 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();
+
+ Map m = new HashMap();
+ m.put("foo", "bar");
+
+ // expecting a put on parent and child
+ mockCacheLoader.expects(once()).method("get").with(eq(parent));
+ mockCacheLoader.expects(once()).method("put").with(eq(child), eq(m));
+ mockCacheLoader.expects(once()).method("get").with(eq(child));
+ cache.put(child, m);
+ assertTrue(cache.peek(child, false).isDataLoaded());
+ // should not load anything
+ cache.get(child, "foo");
+ assertTrue(cache.peek(child, false).isDataLoaded());
+ cache.get(child, "foo");
+ assertTrue(cache.peek(child, false).isDataLoaded());
+ Node node = cache.getRoot().getChild(parent);
+ assertTrue(cache.peek(child, false).isDataLoaded());
+
+ // needs to load children at this stage in case there are other children that have been evicted.
+ mockCacheLoader.expects(once()).method("getChildrenNames").with(eq(parent)).will(returnValue(Collections.singleton(child.getLastElementAsString())));
+
+ Set children = node.getChildren(); //getchildrennames /parent
+ assertEquals(1, children.size());
+ assertTrue(cache.peek(child, false).isDataLoaded());
+ cache.get(child, "foo"); //get /parent/child
+ assertTrue(cache.peek(child, false).isDataLoaded());
+ }
+
}
More information about the jboss-cvs-commits
mailing list