[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...
Manik Surtani
manik at jboss.org
Thu Jul 12 10:26:34 EDT 2007
User: msurtani
Date: 07/07/12 10:26:34
Modified: tests/functional/org/jboss/cache/loader
CacheLoaderMethodCallCounterTest.java
Added: tests/functional/org/jboss/cache/loader
UnnecessaryLoadingTest.java
Log:
JBCACHE-1133
Revision Changes Path
1.15 +1 -1 JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderMethodCallCounterTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- CacheLoaderMethodCallCounterTest.java 11 Jan 2007 13:49:06 -0000 1.14
+++ CacheLoaderMethodCallCounterTest.java 12 Jul 2007 14:26:34 -0000 1.15
@@ -84,7 +84,7 @@
// we should see this put in the cl
assertEquals(1, dummyLoader.getPutCount());
// the cloader interceptor does a get as well when doing the put ... ?
- assertEquals(0, dummyLoader.getGetCount());
+ assertEquals(1, dummyLoader.getGetCount());
for (int i = 0; i < 2000; i++)
{
1.1 date: 2007/07/12 14:26:34; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/loader/UnnecessaryLoadingTest.java
Index: UnnecessaryLoadingTest.java
===================================================================
package org.jboss.cache.loader;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
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;
/**
* //TODO: MANIK: Javadoc this class
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
public class UnnecessaryLoadingTest extends MockObjectTestCase
{
private CacheSPI cache;
private Fqn parent = Fqn.fromString("/a");
private Fqn child = Fqn.fromString("/a/b");
private String k = "k", v = "v";
private Mock mockCacheLoader;
protected void setUp()
{
cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
CacheLoaderConfig clc = new CacheLoaderConfig();
CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
iclc.setClassName(DummyInMemoryCacheLoader.class.getName());
clc.addIndividualCacheLoaderConfig(iclc);
cache.getConfiguration().setCacheLoaderConfig(clc);
cache.start();
mockCacheLoader = mock(CacheLoader.class);
cache.getCacheLoaderManager().setCacheLoader((CacheLoader) mockCacheLoader.proxy());
// re-set the cache so that the mock CL is registered with the inerceptors.
InterceptorChainFactory.getInstance().initialiseInterceptors((Interceptor) cache.getInterceptorChain().get(0), cache);
// lifecycle stuff
mockCacheLoader.expects(atMostOnce()).method("stop").withNoArguments();
mockCacheLoader.expects(atMostOnce()).method("destroy").withNoArguments();
}
protected void tearDown()
{
cache.stop();
}
public void testNoLoading()
{
// we expect these nodes to be stored.
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(once()).method("put").with(eq(parent), eq(k), eq(v));
mockCacheLoader.expects(once()).method("put").with(eq(child), 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));
mockCacheLoader.expects(once()).method("get").with(eq(child));
cache.put(parent, k, v);
cache.put(child, k, v);
// should be NO cache loading involved whatsoever
// so no exceptions should be thrown by the mock CL
}
public void testLoadChild()
{
// we expect these nodes to be stored.
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(once()).method("put").with(eq(parent), eq(k), eq(v));
mockCacheLoader.expects(once()).method("put").with(eq(child), 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));
mockCacheLoader.expects(once()).method("get").with(eq(child));
cache.put(parent, k, v);
cache.put(child, k, v);
mockCacheLoader.expects(once()).method("get").with(eq(child));
cache.evict(child, false);
// there is no REAL cache loader so this return value should not be tested
cache.get(child, k);
// should be NO cache loading involved whatsoever
// so no exceptions should be thrown by the mock CL
}
public void testDontLoadChild()
{
// we expect these nodes to be stored.
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(once()).method("put").with(eq(parent), eq(k), eq(v));
mockCacheLoader.expects(once()).method("put").with(eq(child), 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));
mockCacheLoader.expects(once()).method("get").with(eq(child));
cache.put(parent, k, v);
cache.put(child, k, v);
// nodes should be marked as having data loaded.
assertTrue(cache.peek(parent, false).getDataLoaded());
assertTrue(cache.peek(child, false).getDataLoaded());
// now evict the parent
cache.evict(parent, false);
// only the evicted parent should have getDataLoaded() set to false. Not the child.
assertFalse(cache.peek(parent, false).getDataLoaded());
assertTrue(cache.peek(child, false).getDataLoaded());
assertNotNull(cache.peek(child, false));
// there is no REAL cache loader so this return value should not be tested
cache.get(child, k);
// should be NO cache loading involved whatsoever
}
}
More information about the jboss-cvs-commits
mailing list