[infinispan-commits] Infinispan SVN: r2357 - in branches/4.2.x/core/src: test/java/org/infinispan/jmx and 1 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Sep 14 04:18:05 EDT 2010


Author: galder.zamarreno at jboss.com
Date: 2010-09-14 04:18:05 -0400 (Tue, 14 Sep 2010)
New Revision: 2357

Modified:
   branches/4.2.x/core/src/main/java/org/infinispan/jmx/AbstractJmxRegistration.java
   branches/4.2.x/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java
   branches/4.2.x/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java
Log:
[ISPN-644] (Stopping a CacheManager started with isStarted=false throws NullPointerException) Fixed.

Modified: branches/4.2.x/core/src/main/java/org/infinispan/jmx/AbstractJmxRegistration.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/jmx/AbstractJmxRegistration.java	2010-09-14 08:17:30 UTC (rev 2356)
+++ branches/4.2.x/core/src/main/java/org/infinispan/jmx/AbstractJmxRegistration.java	2010-09-14 08:18:05 UTC (rev 2357)
@@ -50,8 +50,10 @@
    }
 
    protected void unregisterMBeans(Set<AbstractComponentRegistry.Component> components) {
-      ComponentsJmxRegistration registrar = buildRegistrar(components);
-      registrar.unregisterMBeans();
+      if (mBeanServer != null) {
+         ComponentsJmxRegistration registrar = buildRegistrar(components);
+         registrar.unregisterMBeans();
+      }
    }
 
    protected MBeanServer getMBeanServer(GlobalConfiguration configuration) {

Modified: branches/4.2.x/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java
===================================================================
--- branches/4.2.x/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java	2010-09-14 08:17:30 UTC (rev 2356)
+++ branches/4.2.x/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java	2010-09-14 08:18:05 UTC (rev 2357)
@@ -296,6 +296,14 @@
       assert !existsObject(jmxDomain2 + ":cache-name=remote_cache(repl_sync),jmx-resource=Statistics");
    }
 
+   public void testStopUnstartedCacheManager() {
+      GlobalConfiguration globalConfiguration = GlobalConfiguration.getNonClusteredDefault();
+      globalConfiguration.setExposeGlobalJmxStatistics(true);
+      globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
+      cm = TestCacheManagerFactory.createCacheManager(false, globalConfiguration);
+      cm.stop();
+   }
+
    static boolean existsObject(String s) {
       try {
          ObjectName objectName = new ObjectName(s);

Modified: branches/4.2.x/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java
===================================================================
--- branches/4.2.x/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java	2010-09-14 08:17:30 UTC (rev 2356)
+++ branches/4.2.x/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java	2010-09-14 08:18:05 UTC (rev 2357)
@@ -44,11 +44,11 @@
       }
    };
 
-   private static DefaultCacheManager newDefaultCacheManager(GlobalConfiguration gc, Configuration c, boolean keepJmxDomain) {
+   private static DefaultCacheManager newDefaultCacheManager(boolean start, GlobalConfiguration gc, Configuration c, boolean keepJmxDomain) {
       if (!keepJmxDomain) {
          gc.setJmxDomain("infinispan" + jmxDomainPostfix.incrementAndGet());
       }
-      return newDefaultCacheManager(gc, c);
+      return newDefaultCacheManager(start, gc, c);
    }
 
    public static EmbeddedCacheManager fromXml(String xmlFile, boolean allowDupeDomains) throws IOException {
@@ -82,7 +82,7 @@
 
       minimizeThreads(gc);
 
-      EmbeddedCacheManager cm = newDefaultCacheManager(gc, c, false);
+      EmbeddedCacheManager cm = newDefaultCacheManager(true, gc, c, false);
       for (Map.Entry<String, Configuration> e: named.entrySet()) cm.defineConfiguration(e.getKey(), e.getValue());
       cm.start();
       return cm;
@@ -106,7 +106,7 @@
       minimizeThreads(globalConfiguration);
       Configuration c = new Configuration();
       if (transactional) amendJTA(c);
-      return newDefaultCacheManager(globalConfiguration, c, false);
+      return newDefaultCacheManager(true, globalConfiguration, c, false);
    }
 
    private static void amendJTA(Configuration c) {
@@ -131,7 +131,7 @@
       Properties newTransportProps = new Properties();
       newTransportProps.put(JGroupsTransport.CONFIGURATION_STRING, JGroupsConfigBuilder.getJGroupsConfig());
       globalConfiguration.setTransportProperties(newTransportProps);
-      return newDefaultCacheManager(globalConfiguration, defaultCacheConfig, false);
+      return newDefaultCacheManager(true, globalConfiguration, defaultCacheConfig, false);
    }
 
    /**
@@ -139,23 +139,27 @@
     * during running tests in parallel.
     */
    public static EmbeddedCacheManager createCacheManager(GlobalConfiguration configuration) {
-      return internalCreateJmxDomain(configuration, false);
+      return internalCreateJmxDomain(true, configuration, false);
    }
 
+   public static EmbeddedCacheManager createCacheManager(boolean start, GlobalConfiguration configuration) {
+      return internalCreateJmxDomain(start, configuration, false);
+   }
+
    /**
     * Creates a cache manager that won't try to modify the configured jmx domain name: {@link org.infinispan.config.GlobalConfiguration#getJmxDomain()}}.
     * This method must be used with care, and one should make sure that no domain name collision happens when the parallel suite executes.
     * An approach to ensure this, is to set the domain name to the name of the test class that instantiates the CacheManager.
     */
    public static EmbeddedCacheManager createCacheManagerEnforceJmxDomain(GlobalConfiguration configuration) {
-      return internalCreateJmxDomain(configuration, true);
+      return internalCreateJmxDomain(true, configuration, true);
    }
 
-   private static EmbeddedCacheManager internalCreateJmxDomain(GlobalConfiguration configuration, boolean enforceJmxDomain) {
+   private static EmbeddedCacheManager internalCreateJmxDomain(boolean start, GlobalConfiguration configuration, boolean enforceJmxDomain) {
       amendMarshaller(configuration);
       minimizeThreads(configuration);
       amendTransport(configuration);
-      return newDefaultCacheManager(configuration, new Configuration(), enforceJmxDomain);
+      return newDefaultCacheManager(start, configuration, new Configuration(), enforceJmxDomain);
    }
 
    public static EmbeddedCacheManager createCacheManager(Configuration.CacheMode mode, boolean indexing) {
@@ -188,7 +192,7 @@
       amendMarshaller(globalConfiguration);
       minimizeThreads(globalConfiguration);
       if (transactional) amendJTA(defaultCacheConfig);
-      return newDefaultCacheManager(globalConfiguration, defaultCacheConfig, false);
+      return newDefaultCacheManager(true, globalConfiguration, defaultCacheConfig, false);
    }
 
    public static EmbeddedCacheManager createCacheManager(GlobalConfiguration configuration, Configuration defaultCfg) {
@@ -200,7 +204,7 @@
       amendMarshaller(configuration);
       amendTransport(configuration);
       if (transactional) amendJTA(defaultCfg);
-      return newDefaultCacheManager(configuration, defaultCfg, false);
+      return newDefaultCacheManager(true, configuration, defaultCfg, false);
    }
 
    private static EmbeddedCacheManager createCacheManager(GlobalConfiguration configuration, Configuration defaultCfg, boolean transactional, boolean keepJmxDomainName) {
@@ -212,7 +216,7 @@
       amendMarshaller(configuration);
       if (!dontFixTransport) amendTransport(configuration);
       if (transactional) amendJTA(defaultCfg);
-      return newDefaultCacheManager(configuration, defaultCfg, keepJmxDomainName);
+      return newDefaultCacheManager(true, configuration, defaultCfg, keepJmxDomainName);
    }
 
    /**
@@ -270,8 +274,8 @@
       }
    }
 
-   private static DefaultCacheManager newDefaultCacheManager(GlobalConfiguration gc, Configuration c) {
-      DefaultCacheManager defaultCacheManager = new DefaultCacheManager(gc, c, true);
+   private static DefaultCacheManager newDefaultCacheManager(boolean start, GlobalConfiguration gc, Configuration c) {
+      DefaultCacheManager defaultCacheManager = new DefaultCacheManager(gc, c, start);
       PerThreadCacheManagers threadCacheManagers = perThreadCacheManagers.get();
       String methodName = extractMethodName();
       threadCacheManagers.add(methodName, defaultCacheManager);



More information about the infinispan-commits mailing list