Author: manik.surtani(a)jboss.com
Date: 2008-01-09 06:52:25 -0500 (Wed, 09 Jan 2008)
New Revision: 5103
Added:
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderConfig.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java
core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
Log:
Fixed stuff, plus JBCACHE-1204 - shutdown hook
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-09 00:45:11 UTC (rev
5102)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-09 11:52:25 UTC (rev
5103)
@@ -51,6 +51,7 @@
import org.jgroups.util.Rsp;
import org.jgroups.util.RspList;
+import javax.management.MBeanServerFactory;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
@@ -684,26 +685,37 @@
private void addShutdownHook()
{
- // *Always* register a shutdown hook. If cache.stop() is called manually or from
an MBean server or microcontainer,
- // cache.stop will de-register the shutdown hook to prevent shutdown from happening
again when the JVM exits.
+ ArrayList al = MBeanServerFactory.findMBeanServer(null);
+ boolean registerShutdownHook = (configuration.getShutdownHookBehavior() ==
Configuration.ShutdownHookBehavior.DEFAULT && al.size() == 0)
+ || configuration.getShutdownHookBehavior() ==
Configuration.ShutdownHookBehavior.REGISTER;
- shutdownHook = new Thread()
+ if (registerShutdownHook)
{
- public void run()
+ if (trace)
+ log.trace("Registering a shutdown hook. Configured behavior = " +
configuration.getShutdownHookBehavior());
+ shutdownHook = new Thread()
{
- try
+ public void run()
{
- invokedFromShutdownHook = true;
- CacheImpl.this.stop();
+ try
+ {
+ invokedFromShutdownHook = true;
+ CacheImpl.this.stop();
+ }
+ finally
+ {
+ invokedFromShutdownHook = false;
+ }
}
- finally
- {
- invokedFromShutdownHook = false;
- }
- }
- };
+ };
- Runtime.getRuntime().addShutdownHook(shutdownHook);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+ else
+ {
+ if (trace)
+ log.trace("Not registering a shutdown hook. Configured behavior =
" + configuration.getShutdownHookBehavior());
+ }
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2008-01-09
00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -6,6 +6,7 @@
*/
package org.jboss.cache.config;
+import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.SingletonStoreCacheLoader;
import org.jboss.cache.xml.XmlHelper;
@@ -181,6 +182,7 @@
private Properties properties;
private SingletonStoreConfig singletonStoreConfig;
+ private CacheLoader cacheLoader;
protected void populateFromBaseConfig(IndividualCacheLoaderConfig base)
{
@@ -287,6 +289,30 @@
this.singletonStoreConfig = singletonStoreConfig;
}
+ /**
+ * Provides the ability to get and set a running cache loader, which, if exists,
will be used rather than
+ * constructing a new one. Primarily to facilitate testing with mock objects.
+ *
+ * @return cache loader, if one exists
+ * @since 2.1.0
+ */
+ public CacheLoader getCacheLoader()
+ {
+ return cacheLoader;
+ }
+
+ /**
+ * Provides the ability to get and set a running cache loader, which, if exists,
will be used rather than
+ * constructing a new one. Primarily to facilitate testing with mock objects.
+ *
+ * @param cacheLoader cacheLoader to set
+ * @since 2.1.0
+ */
+ public void setCacheLoader(CacheLoader cacheLoader)
+ {
+ this.cacheLoader = cacheLoader;
+ }
+
@Override
public boolean equals(Object obj)
{
@@ -342,7 +368,6 @@
.toString();
}
-
@Override
public IndividualCacheLoaderConfig clone() throws CloneNotSupportedException
{
@@ -351,10 +376,10 @@
clone.properties = (Properties) properties.clone();
if (singletonStoreConfig != null)
clone.setSingletonStoreConfig(singletonStoreConfig.clone());
+ clone.cacheLoader = cacheLoader;
return clone;
}
-
/**
* Configuration for a SingletonStoreCacheLoader
*/
@@ -460,8 +485,6 @@
clone.singletonStoreproperties = (Properties)
singletonStoreproperties.clone();
return clone;
}
-
-
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-01-09 00:45:11
UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-01-09 11:52:25
UTC (rev 5103)
@@ -40,6 +40,25 @@
}
/**
+ * Behavior of the JVM shutdown hook registered by the cache
+ */
+ public enum ShutdownHookBehavior
+ {
+ /**
+ * By default a shutdown hook is registered if no MBean server (apart from the JDK
default) is detected.
+ */
+ DEFAULT,
+ /**
+ * Forces the cache to register a shutdown hook even if an MBean server is
detected.
+ */
+ REGISTER,
+ /**
+ * Forces the cache NOT to register a shutdown hook, even if no MBean server is
detected.
+ */
+ DONT_REGISTER
+ }
+
+ /**
* Cache replication mode.
*/
public enum CacheMode
@@ -165,7 +184,8 @@
private String muxStackName = null;
private boolean usingMultiplexer = false;
private transient RuntimeConfig runtimeConfig;
- private String marshallerClass;// =
"org.jboss.cache.marshall.VersionAwareMarshaller";
+ private String marshallerClass;
+ private ShutdownHookBehavior shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
//
------------------------------------------------------------------------------------------------------------
// SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
@@ -347,13 +367,6 @@
this.nodeLockingOptimistic = nodeLockingOptimistic;
}
- @Deprecated
- public void setInitialStateRetrievalTimeout(long stateRetrievalTimeout)
- {
- log.info("Do not use InitialStateRetrievalTimeout - this is deprecated and may
disappear in future releases. Use StateRetrievalTimeout instead.");
- setStateRetrievalTimeout(stateRetrievalTimeout);
- }
-
public void setStateRetrievalTimeout(long stateRetrievalTimeout)
{
testImmutability("stateRetrievalTimeout");
@@ -444,11 +457,35 @@
this.usingMultiplexer = usingMultiplexer;
}
+ public void setShutdownHookBehavior(ShutdownHookBehavior shutdownHookBehavior)
+ {
+ testImmutability("shutdownHookBehavior");
+ this.shutdownHookBehavior = shutdownHookBehavior;
+ }
+
+ public void setShutdownHookBehavior(String shutdownHookBehavior)
+ {
+ testImmutability("shutdownHookBehavior");
+ if (shutdownHookBehavior == null)
+ throw new ConfigurationException("Shutdown hook behavior cannot be
null", "ShutdownHookBehavior");
+ this.shutdownHookBehavior =
ShutdownHookBehavior.valueOf(uc(shutdownHookBehavior));
+ if (this.shutdownHookBehavior == null)
+ {
+ log.warn("Unknown shutdown hook behavior '" + shutdownHookBehavior
+ "', using defaults.");
+ this.shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
+ }
+ }
+
//
------------------------------------------------------------------------------------------------------------
// GETTERS
//
------------------------------------------------------------------------------------------------------------
+ public ShutdownHookBehavior getShutdownHookBehavior()
+ {
+ return this.shutdownHookBehavior;
+ }
+
public boolean isNodeLockingOptimistic()
{
return nodeLockingOptimistic;
@@ -570,12 +607,6 @@
return nodeLockingScheme;
}
- @Deprecated
- public long getInitialStateRetrievalTimeout()
- {
- return getStateRetrievalTimeout();
- }
-
public long getStateRetrievalTimeout()
{
return stateRetrievalTimeout;
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-01-09
00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -352,9 +352,14 @@
unregisterComponent(CacheSPI.class.getName());
unregisterComponent("remoteDelegate");
+ overallState = CONSTRUCTED;
+
registerComponent(CacheImpl.class.getName(), ci, CacheImpl.class);
registerComponent(CacheSPI.class.getName(), spi, CacheSPI.class);
registerComponent("remoteDelegate", rcid,
RemoteCacheInvocationDelegate.class);
+
+ overallState = originalState;
+ moveComponentsToState(overallState);
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2008-01-09
00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -11,6 +11,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManager;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import
org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
@@ -69,10 +70,12 @@
private CacheLoader loader;
private boolean fetchPersistentState;
private Configuration configuration;
+ private RegionManager regionManager;
@Inject
- private void injectDependencies(CacheSPI cache, Configuration configuration)
+ private void injectDependencies(CacheSPI cache, Configuration configuration,
RegionManager regionManager)
{
+ this.regionManager = regionManager;
this.config = configuration.getCacheLoaderConfig();
this.cache = cache;
this.configuration = configuration;
@@ -174,7 +177,7 @@
{
CacheLoaderConfig.IndividualCacheLoaderConfig cfg =
config.getIndividualCacheLoaderConfigs().get(0);
tmpLoader = createCacheLoader(cfg, cache);
- finalConfigs.add(tmpLoader.getConfig());
+ finalConfigs.add(tmpLoader.getConfig() == null ? cfg : tmpLoader.getConfig());
fetchPersistentState = cfg.isFetchPersistentState();
}
@@ -196,7 +199,7 @@
private CacheLoader createCacheLoader(CacheLoaderConfig.IndividualCacheLoaderConfig
cfg, CacheSPI cache) throws Exception
{
// create loader
- CacheLoader tmpLoader = createInstance(cfg.getClassName());
+ CacheLoader tmpLoader = cfg.getCacheLoader() == null ?
createInstance(cfg.getClassName()) : cfg.getCacheLoader();
if (tmpLoader != null)
{
@@ -247,7 +250,7 @@
// tmpLoader.start();
if (configuration != null &&
configuration.isUseRegionBasedMarshalling())
{
- tmpLoader.setRegionManager(cache.getRegionManager());
+ tmpLoader.setRegionManager(regionManager);
}
}
return tmpLoader;
@@ -371,17 +374,6 @@
}
/**
- * Overrides generated cache loader with the one provided,for backward compat.
Deprecated, may not prote to all interceptors that need it.
- *
- * @param loader
- */
- @Deprecated
- public void setCacheLoader(CacheLoader loader)
- {
- this.loader = loader;
- }
-
- /**
* Tests if we're using passivation
*/
public boolean isPassivation()
Modified: core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java 2008-01-09
00:45:11 UTC (rev 5102)
+++
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -40,18 +40,13 @@
IndividualCacheLoaderConfig config;
CacheSPI delegate = null;
- public LocalDelegatingCacheLoader()
- {
- }
-
- public LocalDelegatingCacheLoader(CacheSPI delegate)
- {
- this.delegate = delegate;
- }
-
public void setConfig(IndividualCacheLoaderConfig config)
{
this.config = config;
+ if (config instanceof LocalDelegatingCacheLoaderConfig)
+ {
+ delegate = (CacheSPI) ((LocalDelegatingCacheLoaderConfig)
config).getDelegate();
+ }
}
public IndividualCacheLoaderConfig getConfig()
Copied:
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderConfig.java
(from rev 5102,
core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderConfig.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderConfig.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -0,0 +1,65 @@
+package org.jboss.cache.loader;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+
+import java.util.Properties;
+
+public class LocalDelegatingCacheLoaderConfig extends IndividualCacheLoaderConfig
+{
+ private static final long serialVersionUID = 4626734068542420865L;
+
+ private Cache delegate;
+
+ public LocalDelegatingCacheLoaderConfig()
+ {
+ setClassName(LocalDelegatingCacheLoader.class.getName());
+ }
+
+ /**
+ * For use by {@link org.jboss.cache.loader.FileCacheLoader}.
+ *
+ * @param base generic config object created by XML parsing.
+ */
+ LocalDelegatingCacheLoaderConfig(IndividualCacheLoaderConfig base)
+ {
+ setClassName(LocalDelegatingCacheLoader.class.getName());
+ populateFromBaseConfig(base);
+ }
+
+ @Override
+ public void setProperties(Properties props)
+ {
+ super.setProperties(props);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return obj instanceof LocalDelegatingCacheLoaderConfig &&
equalsExcludingProperties(obj) && delegate == ((LocalDelegatingCacheLoaderConfig)
obj).delegate;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return 31 * hashCodeExcludingProperties() + (delegate == null ? 0 :
delegate.hashCode());
+ }
+
+ @Override
+ public LocalDelegatingCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ LocalDelegatingCacheLoaderConfig clone = (LocalDelegatingCacheLoaderConfig)
super.clone();
+ clone.delegate = delegate;
+ return clone;
+ }
+
+ public Cache getDelegate()
+ {
+ return delegate;
+ }
+
+ public void setDelegate(Cache delegate)
+ {
+ this.delegate = delegate;
+ }
+}
\ No newline at end of file
Modified:
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java 2008-01-09
00:45:11 UTC (rev 5102)
+++
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -8,15 +8,18 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
/**
* A simple non-failing unit test to measure how many times each method on a cache loader
is called.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
*/
+@Test(groups = "functional")
public class CacheLoaderMethodCallCounterTest extends AbstractCacheLoaderTestBase
{
private CacheSPI cache;
@@ -35,12 +38,7 @@
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- if (cache != null)
- {
- cache.stop();
- }
- cache.destroy();
- cache = null;
+ TestingUtil.killCaches(cache);
}
Modified:
core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java 2008-01-09
00:45:11 UTC (rev 5102)
+++
core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -43,7 +43,8 @@
//setCacheLoader(new TestSlowCacheLoader());
CacheLoaderConfig clc = new CacheLoaderConfig();
IndividualCacheLoaderConfig iclc = new IndividualCacheLoaderConfig();
- iclc.setClassName(TestSlowCacheLoader.class.getName());
+ //iclc.setClassName(TestSlowCacheLoader.class.getName());
+ iclc.setCacheLoader(new TestSlowCacheLoader());
clc.addIndividualCacheLoaderConfig(iclc);
cache.getConfiguration().setCacheLoaderConfig(clc);
cache.start();
Modified:
core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java 2008-01-09
00:45:11 UTC (rev 5102)
+++
core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -2,11 +2,8 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.interceptors.ActivationInterceptor;
-import org.jboss.cache.interceptors.PassivationInterceptor;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.util.reflect.ReflectionUtil;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -22,14 +19,13 @@
delegating_cache.create();
delegating_cache.start();
- // setCache first ...
-
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
"org.jboss.cache.loader.LocalDelegatingCacheLoader", "", false, false,
false));
-
- // force our own cache loader instance
- LocalDelegatingCacheLoader cacheLoader = new
LocalDelegatingCacheLoader(delegating_cache);
-
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache,
PassivationInterceptor.class), "loader", cacheLoader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache,
ActivationInterceptor.class), "loader", cacheLoader);
+ LocalDelegatingCacheLoaderConfig cfg = new LocalDelegatingCacheLoaderConfig();
+ cfg.setDelegate(delegating_cache);
+ cfg.setAsync(false);
+ cfg.setFetchPersistentState(false);
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(cfg);
+ cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
}
protected void postConfigure()
Modified: core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java 2008-01-09
00:45:11 UTC (rev 5102)
+++ core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -1,16 +1,11 @@
package org.jboss.cache.loader;
-import org.easymock.EasyMock;
import static org.easymock.EasyMock.*;
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.interceptors.CacheLoaderInterceptor;
-import org.jboss.cache.interceptors.CacheStoreInterceptor;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.util.reflect.ReflectionUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -35,31 +30,55 @@
private CacheLoader mockCacheLoader;
@BeforeMethod(alwaysRun = true)
- public void setUp()
+ public void setUp() throws Exception
{
cache = (CacheSPI<Object, Object>) new
DefaultCacheFactory().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 = EasyMock.createMock(CacheLoader.class);
+ mockCacheLoader = createMock(CacheLoader.class);
- cache.getCacheLoaderManager().setCacheLoader(mockCacheLoader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache,
CacheLoaderInterceptor.class), "loader", mockCacheLoader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache,
CacheStoreInterceptor.class), "loader", mockCacheLoader);
-
- // lifecycle stuff
+ expect(mockCacheLoader.getConfig()).andReturn(null).anyTimes();
+ mockCacheLoader.setCache((CacheSPI) anyObject());
+ expectLastCall().anyTimes();
+ mockCacheLoader.setConfig((CacheLoaderConfig.IndividualCacheLoaderConfig)
anyObject());
+ expectLastCall().anyTimes();
+ mockCacheLoader.create();
+ expectLastCall().anyTimes();
+ mockCacheLoader.start();
+ expectLastCall().anyTimes();
mockCacheLoader.stop();
- EasyMock.expectLastCall().times(0, 1);
+ expectLastCall().anyTimes();
mockCacheLoader.destroy();
- EasyMock.expectLastCall().times(0, 1);
+ expectLastCall().anyTimes();
+ replay(mockCacheLoader);
+
+ iclc.setCacheLoader(mockCacheLoader);
+ cache.start();
+
+ reset(mockCacheLoader);
}
@AfterMethod(alwaysRun = true)
- public void tearDown()
+ public void tearDown() throws Exception
{
+ reset(mockCacheLoader);
+ expect(mockCacheLoader.getConfig()).andReturn(null).anyTimes();
+ mockCacheLoader.setCache((CacheSPI) anyObject());
+ expectLastCall().anyTimes();
+ mockCacheLoader.setConfig((CacheLoaderConfig.IndividualCacheLoaderConfig)
anyObject());
+ expectLastCall().anyTimes();
+ mockCacheLoader.create();
+ expectLastCall().anyTimes();
+ mockCacheLoader.start();
+ expectLastCall().anyTimes();
+ mockCacheLoader.stop();
+ expectLastCall().anyTimes();
+ mockCacheLoader.destroy();
+ expectLastCall().anyTimes();
+ replay(mockCacheLoader);
+
cache.stop();
}
Modified:
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java 2008-01-09
00:45:11 UTC (rev 5102)
+++
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java 2008-01-09
11:52:25 UTC (rev 5103)
@@ -2,13 +2,10 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.interceptors.ActivationInterceptor;
-import org.jboss.cache.interceptors.PassivationInterceptor;
import org.jboss.cache.loader.CacheLoader;
-import org.jboss.cache.loader.LocalDelegatingCacheLoader;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.util.reflect.ReflectionUtil;
+import org.jboss.cache.loader.LocalDelegatingCacheLoaderConfig;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -24,20 +21,21 @@
CacheSPI delegating_cache;
CacheLoader cache_loader;
- @SuppressWarnings("deprecation")
protected void configureCache() throws Exception
{
delegating_cache = (CacheSPI) new DefaultCacheFactory().createCache(false);
delegating_cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
delegating_cache.create();
delegating_cache.start();
- cache_loader = new LocalDelegatingCacheLoader(delegating_cache);
- // setCache first ...
- cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig("",
"org.jboss.cache.loader.LocalDelegatingCacheLoader", "", false,
false));
- cache.getCacheLoaderManager().setCacheLoader(cache_loader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache,
PassivationInterceptor.class), "loader", cache_loader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache,
ActivationInterceptor.class), "loader", cache_loader);
+ LocalDelegatingCacheLoaderConfig cfg = new LocalDelegatingCacheLoaderConfig();
+ cfg.setDelegate(delegating_cache);
+ cfg.setAsync(false);
+ cfg.setFetchPersistentState(false);
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(cfg);
+ cacheLoaderConfig.setPassivation(true);
+ cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
}
@AfterMethod(alwaysRun = true)