Author: manik.surtani(a)jboss.com
Date: 2008-06-02 11:05:58 -0400 (Mon, 02 Jun 2008)
New Revision: 5925
Added:
core/branches/2.1.X/src/test/java/org/jboss/cache/loader/PreloadTest.java
Modified:
core/branches/2.1.X/src/main/java/org/jboss/cache/CacheImpl.java
Log:
JBCACHE-1358: Cache Loader preloading does not happen! - Added fix and test
Modified: core/branches/2.1.X/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/branches/2.1.X/src/main/java/org/jboss/cache/CacheImpl.java 2008-06-02 15:04:47
UTC (rev 5924)
+++ core/branches/2.1.X/src/main/java/org/jboss/cache/CacheImpl.java 2008-06-02 15:05:58
UTC (rev 5925)
@@ -179,7 +179,7 @@
private void injectDependencies(Notifier notifier, RegionManager regionManager,
TransactionManager transactionManager, Marshaller marshaller,
TransactionTable transactionTable, NodeFactory
nodeFactory,
CacheSPI spi,
@ComponentName("remoteDelegate")RemoteCacheInvocationDelegate remoteDelegate,
- Interceptor interceptorChain, BuddyManager
buddyManager, RPCManager rpcManager)
+ Interceptor interceptorChain, BuddyManager
buddyManager, RPCManager rpcManager, CacheLoaderManager cacheLoaderManager)
{
this.notifier = notifier;
this.regionManager = regionManager;
@@ -192,6 +192,7 @@
this.interceptorChain = interceptorChain;
this.buddyManager = buddyManager;
this.rpcManager = rpcManager;
+ this.cacheLoaderManager = cacheLoaderManager;
}
public Configuration getConfiguration()
Added: core/branches/2.1.X/src/test/java/org/jboss/cache/loader/PreloadTest.java
===================================================================
--- core/branches/2.1.X/src/test/java/org/jboss/cache/loader/PreloadTest.java
(rev 0)
+++ core/branches/2.1.X/src/test/java/org/jboss/cache/loader/PreloadTest.java 2008-06-02
15:05:58 UTC (rev 5925)
@@ -0,0 +1,69 @@
+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.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+@Test(groups = "functional")
+public class PreloadTest extends AbstractCacheLoaderTestBase
+{
+ CacheSPI<Object, Object> cache;
+ Fqn fqn = Fqn.fromString("/a/b/c");
+ Object key = "key", value = "value";
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (cache != null) TestingUtil.killCaches(cache);
+ }
+
+ public void testPreload() throws Exception
+ {
+ Configuration c =
UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL);
+ c.setCacheLoaderConfig(getSingleCacheLoaderConfig("/a",
DummySharedInMemoryCacheLoader.class.getName(), "", false, false, false));
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(c.clone());
+ cache.put(fqn, key, value);
+ assertExists();
+
+ cache.destroy();
+
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(c.clone());
+ assertExists();
+ }
+
+ public void testPreloadMultiRegions() throws Exception
+ {
+ Configuration c =
UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL);
+ c.setCacheLoaderConfig(getSingleCacheLoaderConfig("/a",
DummySharedInMemoryCacheLoader.class.getName(), "", false, false, false));
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(c.clone());
+ cache.put(fqn, key, value);
+ assertExists();
+
+ cache.destroy();
+
+ c.setCacheLoaderConfig(getSingleCacheLoaderConfig("/c,/a,/b",
DummySharedInMemoryCacheLoader.class.getName(), "", false, false, false));
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(c.clone());
+ assertExists();
+
+ c.setCacheLoaderConfig(getSingleCacheLoaderConfig("/c, /a, /b",
DummySharedInMemoryCacheLoader.class.getName(), "", false, false, false));
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(c.clone());
+ assertExists();
+
+ c.setCacheLoaderConfig(getSingleCacheLoaderConfig(" /c, /a, /b",
DummySharedInMemoryCacheLoader.class.getName(), "", false, false, false));
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(c.clone());
+ assertExists();
+ }
+
+ private void assertExists() throws Exception
+ {
+ CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
+ assert loader.get(fqn).get(key).equals(value);
+ assert cache.peek(fqn, false).getDataDirect().get(key).equals(value);
+ }
+}