[jbosscache-commits] JBoss Cache SVN: r5504 - in core/trunk/src: test/java/org/jboss/cache/buddyreplication and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Apr 7 04:45:18 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-07 04:45:18 -0400 (Mon, 07 Apr 2008)
New Revision: 5504

Modified:
   core/trunk/src/main/java/org/jboss/cache/factories/BuddyManagerFactory.java
   core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
Log:
JBCACHE-1319: NPE with CacheMode.LOCAL and buddy replication enabled

Modified: core/trunk/src/main/java/org/jboss/cache/factories/BuddyManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/BuddyManagerFactory.java	2008-04-07 08:44:57 UTC (rev 5503)
+++ core/trunk/src/main/java/org/jboss/cache/factories/BuddyManagerFactory.java	2008-04-07 08:45:18 UTC (rev 5504)
@@ -1,6 +1,7 @@
 package org.jboss.cache.factories;
 
 import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.annotations.DefaultFactoryFor;
 
 /**
@@ -15,7 +16,7 @@
    @Override
    public <T> T construct(String componentName, Class<T> componentType)
    {
-      if (configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled())
+      if (configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled() && configuration.getCacheMode() != Configuration.CacheMode.LOCAL)
       {
          return super.construct(componentName, componentType);
       }

Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java	2008-04-07 08:44:57 UTC (rev 5503)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java	2008-04-07 08:45:18 UTC (rev 5504)
@@ -160,7 +160,7 @@
 
    private boolean isUsingBuddyReplication()
    {
-      return configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled();
+      return configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled() && configuration.getCacheMode() != Configuration.CacheMode.LOCAL;
    }
 
    public Interceptor setFirstInterceptor(Class<? extends Interceptor> clazz) throws IllegalAccessException, InstantiationException

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java	2008-04-07 08:44:57 UTC (rev 5503)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java	2008-04-07 08:45:18 UTC (rev 5504)
@@ -8,6 +8,7 @@
 
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
 import org.jboss.cache.config.BuddyReplicationConfig;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.XmlConfigurationParser;
@@ -38,7 +39,7 @@
 
    public void testNullConfig() throws Exception
    {
-      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
       cache.getConfiguration().setBuddyReplicationConfig(null);
       assertNull(cache.getBuddyManager());
    }
@@ -48,7 +49,7 @@
       String xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>";
       Element element = XmlHelper.stringToElement(xmlConfig);
       BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
-      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
       cache.getConfiguration().setBuddyReplicationConfig(config);
       assertNull(cache.getBuddyManager());
    }
@@ -58,7 +59,7 @@
       String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
       Element element = XmlHelper.stringToElement(xmlConfig);
       BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
-      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
       cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
       cache.getConfiguration().setBuddyReplicationConfig(config);
       cache.create();
@@ -75,7 +76,7 @@
 
    public void testXmlConfig() throws Exception
    {
-      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(new XmlConfigurationParser().parseFile("META-INF/buddy-replication-cache-service.xml"), false);
+      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(new XmlConfigurationParser().parseFile("META-INF/buddy-replication-cache-service.xml"), false);
       cache.create();
       cache.start();
       BuddyManager bm = cache.getBuddyManager();
@@ -100,4 +101,19 @@
 
       assertTrue("Should have a data gravitator!!", hasDG);
    }
+
+   public void testLocalModeConfig() throws Exception
+   {
+      String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
+      Element element = XmlHelper.stringToElement(xmlConfig);
+      BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element);
+      cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
+      cache.getConfiguration().setBuddyReplicationConfig(config);
+      cache.create();
+      cache.start();
+      assert cache.getBuddyManager() == null;
+
+      cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
+      cache.getNode(Fqn.fromString("/nonexistent")); // should not barf!
+   }
 }
\ No newline at end of file




More information about the jbosscache-commits mailing list