Author: manik.surtani(a)jboss.com
Date: 2008-01-11 09:07:10 -0500 (Fri, 11 Jan 2008)
New Revision: 5116
Added:
core/trunk/src/test/java/org/jboss/cache/factories/LateConfigurationTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
Log:
Ensure that late configuration of transaction managers, etc are allowed. Added test for
tis.
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-10 15:56:22 UTC (rev
5115)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-11 14:07:10 UTC (rev
5116)
@@ -549,6 +549,16 @@
}
}
+ private void removeConfigurationDependentComponents()
+ {
+ // remove the Interceptor.class component though, since it may pertain to an old
config
+ componentRegistry.unregisterComponent(Interceptor.class);
+ componentRegistry.unregisterComponent(Marshaller.class);
+ componentRegistry.unregisterComponent(TransactionManager.class);
+ componentRegistry.unregisterComponent(BuddyManager.class);
+ componentRegistry.unregisterComponent(CacheLoaderManager.class);
+ }
+
/**
* The actual start implementation.
*
@@ -559,9 +569,10 @@
{
// re-wire all dependencies in case stuff has changed since the cache was created
- // remove the Interceptor.class component though, since it may pertain to an old
config
- componentRegistry.unregisterComponent(Interceptor.class);
+ // remove any components whose construction may have depended upon a configuration
that may have changed.
+ removeConfigurationDependentComponents();
+ // this will recreate any missing components based on the current config
componentRegistry.updateDependencies();
componentRegistry.wireDependencies(root);
Added: core/trunk/src/test/java/org/jboss/cache/factories/LateConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/LateConfigurationTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/factories/LateConfigurationTest.java 2008-01-11
14:07:10 UTC (rev 5116)
@@ -0,0 +1,115 @@
+package org.jboss.cache.factories;
+
+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.interceptors.OptimisticLockingInterceptor;
+import org.jboss.cache.loader.DummyInMemoryCacheLoader;
+import org.jboss.cache.marshall.AbstractMarshaller;
+import org.jboss.cache.marshall.VersionAwareMarshaller;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 2.1.0
+ */
+@Test(groups = "functional")
+public class LateConfigurationTest
+{
+ CacheSPI c;
+
+ @BeforeMethod
+ public void setUp()
+ {
+ c = (CacheSPI) new DefaultCacheFactory().createCache(false);
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(c);
+ }
+
+ public void testTransactionManager()
+ {
+ assert c.getTransactionManager() == null;
+
+
c.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+
+ assert c.getTransactionManager() == null;
+ c.start();
+ assert c.getTransactionManager() == DummyTransactionManager.getInstance();
+ }
+
+ public void testTransactionManagerinRuntime()
+ {
+ assert c.getTransactionManager() == null;
+
+
c.getConfiguration().getRuntimeConfig().setTransactionManager(DummyTransactionManager.getInstance());
+
+ assert c.getTransactionManager() == null;
+ c.start();
+ assert c.getTransactionManager() == DummyTransactionManager.getInstance();
+ }
+
+
+ public void testCacheLoader()
+ {
+ assert c.getCacheLoaderManager() != null;
+ assert c.getCacheLoaderManager().getCacheLoader() == null;
+
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new
CacheLoaderConfig.IndividualCacheLoaderConfig();
+ iclc.setCacheLoader(new DummyInMemoryCacheLoader());
+ clc.addIndividualCacheLoaderConfig(iclc);
+ c.getConfiguration().setCacheLoaderConfig(clc);
+
+ c.start();
+ assert c.getCacheLoaderManager() != null;
+ assert c.getCacheLoaderManager().getCacheLoader() instanceof
DummyInMemoryCacheLoader;
+ }
+
+ public void testInterceptors()
+ {
+ assert TestingUtil.findInterceptor(c, OptimisticLockingInterceptor.class) == null;
+
+ c.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
+ assert TestingUtil.findInterceptor(c, OptimisticLockingInterceptor.class) == null;
+ c.start();
+ assert TestingUtil.findInterceptor(c, OptimisticLockingInterceptor.class) != null;
+ }
+
+ public void testCacheMarshaller()
+ {
+ assert c.getMarshaller() instanceof VersionAwareMarshaller;
+
+ c.getConfiguration().setCacheMarshaller(new AbstractMarshaller()
+ {
+ public void objectToObjectStream(Object obj, ObjectOutputStream out) throws
Exception
+ {
+ }
+
+ public Object objectFromObjectStream(ObjectInputStream in) throws Exception
+ {
+ return null;
+ }
+
+ public void objectToObjectStream(Object obj, ObjectOutputStream out, Fqn
region)
+ {
+ }
+ });
+
+ c.start();
+
+ assert !(c.getMarshaller() instanceof VersionAwareMarshaller) &&
c.getMarshaller() != null;
+ }
+}
Show replies by date