Author: manik.surtani(a)jboss.com
Date: 2008-06-02 11:04:47 -0400 (Mon, 02 Jun 2008)
New Revision: 5924
Added:
core/trunk/src/test/java/org/jboss/cache/loader/PreloadTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
Log:
JBCACHE-1358: Cache Loader preloading does not happen! - Added fix and test
Modified: core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2008-06-02
14:27:00 UTC (rev 5923)
+++ core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2008-06-02
15:04:47 UTC (rev 5924)
@@ -442,6 +442,8 @@
loader.start();
purgeLoaders(false);
+
+ preloadCache();
}
catch (Exception e)
{
Added: core/trunk/src/test/java/org/jboss/cache/loader/PreloadTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/PreloadTest.java
(rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/loader/PreloadTest.java 2008-06-02 15:04:47
UTC (rev 5924)
@@ -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.util.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);
+ }
+}