[infinispan-commits] Infinispan SVN: r1373 - in trunk/core/src/test/java/org/infinispan: replication and 2 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Jan 15 09:01:57 EST 2010


Author: mircea.markus
Date: 2010-01-15 09:01:57 -0500 (Fri, 15 Jan 2010)
New Revision: 1373

Added:
   trunk/core/src/test/java/org/infinispan/stress/MemoryCleanupTest.java
Modified:
   trunk/core/src/test/java/org/infinispan/jmx/ActivationAndPassivationInterceptorMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/CacheLoaderAndCacheStoreInterceptorMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/CacheMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/CacheManagerMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/CacheMgmtInterceptorMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/jmx/MvccLockManagerMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/RpcManagerMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/TxInterceptorMBeanTest.java
   trunk/core/src/test/java/org/infinispan/replication/SyncCacheListenerTest.java
   trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java
Log:
[ISPN-285]-Enhance test fwk to avoid JMX domains collisions

Modified: trunk/core/src/test/java/org/infinispan/jmx/ActivationAndPassivationInterceptorMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/ActivationAndPassivationInterceptorMBeanTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/ActivationAndPassivationInterceptorMBeanTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -33,13 +33,14 @@
    ObjectName activationInterceptorObjName;
    ObjectName passivationInterceptorObjName;
    CacheStore cacheStore;
+   private static final String JMX_DOMAIN = ActivationAndPassivationInterceptorMBeanTest.class.getName();
 
    protected CacheManager createCacheManager() throws Exception {
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getNonClusteredDefault();
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
-      globalConfiguration.setJmxDomain("ActivationAndPassivationInterceptorMBeanTest");
+      globalConfiguration.setJmxDomain(JMX_DOMAIN);
       globalConfiguration.setExposeGlobalJmxStatistics(true);
-      cacheManager = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      cacheManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration);
       DummyInMemoryCacheStore.Cfg cfg = new DummyInMemoryCacheStore.Cfg();
       CacheLoaderManagerConfig clManagerConfig = new CacheLoaderManagerConfig();
       clManagerConfig.setPassivation(true);
@@ -50,8 +51,8 @@
 
       cacheManager.defineConfiguration("test", configuration);
       cache = cacheManager.getCache("test");
-      activationInterceptorObjName = new ObjectName("ActivationAndPassivationInterceptorMBeanTest:cache-name=test(local),jmx-resource=Activation");
-      passivationInterceptorObjName = new ObjectName("ActivationAndPassivationInterceptorMBeanTest:cache-name=test(local),jmx-resource=Passivation");
+      activationInterceptorObjName = new ObjectName(JMX_DOMAIN + ":cache-name=test(local),jmx-resource=Activation");
+      passivationInterceptorObjName = new ObjectName(JMX_DOMAIN + ":cache-name=test(local),jmx-resource=Passivation");
 
       threadMBeanServer = PerThreadMBeanServerLookup.getThreadMBeanServer();
       cacheStore = TestingUtil.extractComponent(cache, CacheLoaderManager.class).getCacheStore();

Modified: trunk/core/src/test/java/org/infinispan/jmx/CacheLoaderAndCacheStoreInterceptorMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/CacheLoaderAndCacheStoreInterceptorMBeanTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/CacheLoaderAndCacheStoreInterceptorMBeanTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -28,13 +28,14 @@
    private ObjectName storeInterceptorObjName;
    private MBeanServer threadMBeanServer;
    private CacheStore cacheStore;
+   private static final String JMX_DOMAIN = CacheLoaderAndCacheStoreInterceptorMBeanTest.class.getName();
 
    protected CacheManager createCacheManager() throws Exception {
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getNonClusteredDefault();
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
-      globalConfiguration.setJmxDomain("CacheLoaderAndCacheStoreInterceptorMBeanTest");
+      globalConfiguration.setJmxDomain(JMX_DOMAIN);
       globalConfiguration.setExposeGlobalJmxStatistics(true);
-      cacheManager = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      cacheManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration);
 
       DummyInMemoryCacheStore.Cfg cfg = new DummyInMemoryCacheStore.Cfg();
 
@@ -47,8 +48,8 @@
 
       cacheManager.defineConfiguration("test", configuration);
       cache = cacheManager.getCache("test");
-      loaderInterceptorObjName = new ObjectName("CacheLoaderAndCacheStoreInterceptorMBeanTest:cache-name=test(local),jmx-resource=CacheLoader");
-      storeInterceptorObjName = new ObjectName("CacheLoaderAndCacheStoreInterceptorMBeanTest:cache-name=test(local),jmx-resource=CacheStore");
+      loaderInterceptorObjName = new ObjectName(JMX_DOMAIN + ":cache-name=test(local),jmx-resource=CacheLoader");
+      storeInterceptorObjName = new ObjectName(JMX_DOMAIN + ":cache-name=test(local),jmx-resource=CacheStore");
 
       threadMBeanServer = PerThreadMBeanServerLookup.getThreadMBeanServer();
       cacheStore = TestingUtil.extractComponent(cache, CacheLoaderManager.class).getCacheStore();

Modified: trunk/core/src/test/java/org/infinispan/jmx/CacheMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/CacheMBeanTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/CacheMBeanTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -46,7 +46,7 @@
 
    @Override
    protected CacheManager createCacheManager() throws Exception {
-      cacheManager = TestCacheManagerFactory.createJmxEnabledCacheManager(JMX_DOMAIN);
+      cacheManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(JMX_DOMAIN);
       server = PerThreadMBeanServerLookup.getThreadMBeanServer();
       return cacheManager;
    }
@@ -85,7 +85,7 @@
       ObjectName defaultOn = new ObjectName(otherJmxDomain + ":cache-name=" + DefaultCacheManager.DEFAULT_CACHE_NAME + "(local),jmx-resource=Cache");
       ObjectName galderOn = new ObjectName(otherJmxDomain + ":cache-name=galder(local),jmx-resource=Cache");
       ObjectName managerON = new ObjectName(otherJmxDomain + ":cache-name=[global],jmx-resource=CacheManager");
-      CacheManager otherManager = TestCacheManagerFactory.createJmxEnabledCacheManager(otherJmxDomain);
+      CacheManager otherManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(otherJmxDomain);
       server.invoke(managerON, "startCache", new Object[]{}, new String[]{});
       server.invoke(managerON, "startCache", new Object[]{"galder"}, new String[]{String.class.getName()});
       assert ComponentStatus.RUNNING.toString().equals(server.getAttribute(defaultOn, "CacheStatus"));
@@ -110,7 +110,7 @@
 
 
    public void testDuplicateJmxDomainOnlyCacheExposesJmxStatistics() throws Exception {
-      CacheManager otherManager = TestCacheManagerFactory.createJmxEnabledCacheManager(JMX_DOMAIN, false, true);
+      CacheManager otherManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(JMX_DOMAIN, false, true);
       try {
          otherManager.getCache();
          assert false : "Failure expected, " + JMX_DOMAIN + " is a duplicate!";
@@ -121,7 +121,7 @@
 
    public void testMalformedCacheName(Method m) throws Exception {
       final String otherJmxDomain = JMX_DOMAIN + '.' + m.getName();
-      CacheManager otherManager = TestCacheManagerFactory.createJmxEnabledCacheManager(otherJmxDomain);
+      CacheManager otherManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(otherJmxDomain);
       otherManager.getCache("persistence.unit:unitName=#helloworld.MyRegion");
    }
 }

Modified: trunk/core/src/test/java/org/infinispan/jmx/CacheManagerMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/CacheManagerMBeanTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/CacheManagerMBeanTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -29,7 +29,7 @@
    private ObjectName name;
 
    protected CacheManager createCacheManager() throws Exception {
-      cacheManager = TestCacheManagerFactory.createJmxEnabledCacheManager(JMX_DOMAIN, true, false);
+      cacheManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(JMX_DOMAIN, true, false);
       name = new ObjectName(JMX_DOMAIN + ":cache-name=[global],jmx-resource=CacheManager");
       server = PerThreadMBeanServerLookup.getThreadMBeanServer();
       server.invoke(name, "startCache", new Object[]{}, new String[]{});
@@ -78,7 +78,7 @@
    
    public void testJmxRegistrationAtStartupAndStop(Method method) throws Exception {
       final String otherJmxDomain = JMX_DOMAIN + '.' + method.getName();
-      CacheManager otherManager = TestCacheManagerFactory.createJmxEnabledCacheManager(otherJmxDomain, true, false);
+      CacheManager otherManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(otherJmxDomain, true, false);
       ObjectName otherName = new ObjectName(otherJmxDomain + ":cache-name=[global],jmx-resource=CacheManager");
       try {
          assert server.getAttribute(otherName, "CreatedCacheCount").equals("0");

Modified: trunk/core/src/test/java/org/infinispan/jmx/CacheMgmtInterceptorMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/CacheMgmtInterceptorMBeanTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/CacheMgmtInterceptorMBeanTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -24,20 +24,21 @@
    private ObjectName mgmtInterceptor;
    private MBeanServer threadMBeanServer;
    AdvancedCache advanced;
+   private static final String JMX_DOMAIN = CacheMgmtInterceptorMBeanTest.class.getName();
 
    protected CacheManager createCacheManager() throws Exception {
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getNonClusteredDefault();
       globalConfiguration.setExposeGlobalJmxStatistics(true);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
-      globalConfiguration.setJmxDomain("CacheMgmtInterceptorMBeanTest");
-      cacheManager = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      globalConfiguration.setJmxDomain(JMX_DOMAIN);
+      cacheManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration);
 
       Configuration configuration = getDefaultClusteredConfig(Configuration.CacheMode.LOCAL);
       configuration.setExposeJmxStatistics(true);
       cacheManager.defineConfiguration("test", configuration);
       cache = cacheManager.getCache("test");
       advanced = cache.getAdvancedCache();
-      mgmtInterceptor = new ObjectName("CacheMgmtInterceptorMBeanTest:cache-name=test(local),jmx-resource=Statistics");
+      mgmtInterceptor = new ObjectName(JMX_DOMAIN + ":cache-name=test(local),jmx-resource=Statistics");
 
       threadMBeanServer = PerThreadMBeanServerLookup.getThreadMBeanServer();
       return cacheManager;

Modified: trunk/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -32,23 +32,30 @@
    private CacheManager cm, cm2, cm3;
 
 
-   @AfterMethod(alwaysRun=true)
+   @AfterMethod(alwaysRun = true)
    public void destroyCacheManager() {
       TestingUtil.killCacheManagers(cm, cm2, cm3);
-      cm=null;cm2=null;cm3=null;
-      server=null;
-      assert !existsDomains("infinispan");
+      cm = null;
+      cm2 = null;
+      cm3 = null;
+      server = null;
+      if (cm != null)
+         assert !existsDomains(cm.getGlobalConfiguration().getJmxDomain());
+      if (cm2 != null)
+         assert !existsDomains(cm2.getGlobalConfiguration().getJmxDomain());
+      if (cm3 != null)
+         assert !existsDomains(cm3.getGlobalConfiguration().getJmxDomain());
    }
 
    /**
     * Create a local cache, two replicated caches and see that everithing is correctly registered.
     */
    public void testDefaultDomain() {
-      assert !existsDomains("infinispan");
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
       globalConfiguration.setExposeGlobalJmxStatistics(true);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       cm = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      String jmxDomain = cm.getGlobalConfiguration().getJmxDomain();
 
       Configuration localCache = config();//local by default
       cm.defineConfiguration("local_cache", localCache);
@@ -63,43 +70,41 @@
       cm.getCache("remote1");
       cm.getCache("remote2");
 
-      assert existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
-      assert existsObject("infinispan:cache-name=remote1(repl_sync),jmx-resource=RpcManager");
-      assert existsObject("infinispan:cache-name=remote1(repl_sync),jmx-resource=Statistics");
-      assert existsObject("infinispan:cache-name=remote2(invalidation_async),jmx-resource=RpcManager");
-      assert existsObject("infinispan:cache-name=remote2(invalidation_async),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=remote1(repl_sync),jmx-resource=RpcManager");
+      assert existsObject(jmxDomain + ":cache-name=remote1(repl_sync),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=remote2(invalidation_async),jmx-resource=RpcManager");
+      assert existsObject(jmxDomain + ":cache-name=remote2(invalidation_async),jmx-resource=Statistics");
 
       TestingUtil.killCacheManagers(cm);
 
-      assert !existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
-      assert !existsObject("infinispan:cache-name=remote1(repl_sync),jmx-resource=RpcManager");
-      assert !existsObject("infinispan:cache-name=remote1(repl_sync),jmx-resource=Statistics");
-      assert !existsObject("infinispan:cache-name=remote2(invalidation_async),jmx-resource=RpcManager");
-      assert !existsObject("infinispan:cache-name=remote2(invalidation_async),jmx-resource=Statistics");
+      assert !existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
+      assert !existsObject(jmxDomain + ":cache-name=remote1(repl_sync),jmx-resource=RpcManager");
+      assert !existsObject(jmxDomain + ":cache-name=remote1(repl_sync),jmx-resource=Statistics");
+      assert !existsObject(jmxDomain + ":cache-name=remote2(invalidation_async),jmx-resource=RpcManager");
+      assert !existsObject(jmxDomain + ":cache-name=remote2(invalidation_async),jmx-resource=Statistics");
    }
 
    public void testDifferentDomain() {
-      assert !existsDomains("infinispan");
-      assert !existsDomains("mircea_jmx_domain");
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
-      globalConfiguration.setJmxDomain("mircea_jmx_domain");
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       cm = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      String jmxDomain = cm.getGlobalConfiguration().getJmxDomain();
 
       Configuration localCache = config();//local by default
       cm.defineConfiguration("local_cache", localCache);
       cm.getCache("local_cache");
 
-      assert existsObject("mircea_jmx_domain:cache-name=local_cache(local),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
    }
 
 
    public void testOnlyGlobalJmxStatsEnabled() {
-      assert !existsDomains("infinispan");
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
       globalConfiguration.setExposeGlobalJmxStatistics(true);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       cm = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      String jmxDomain = globalConfiguration.getJmxDomain();
 
       Configuration localCache = config();//local by default
       localCache.setExposeJmxStatistics(false);
@@ -112,17 +117,17 @@
       cm.getCache("local_cache");
       cm.getCache("remote1");
 
-      assert !existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
-      assert existsObject("infinispan:cache-name=[global],jmx-resource=CacheManager");
-      assert !existsObject("infinispan:cache-name=remote1(repl_sync),jmx-resource=Statistics");
+      assert !existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=[global],jmx-resource=CacheManager");
+      assert !existsObject(jmxDomain + ":cache-name=remote1(repl_sync),jmx-resource=Statistics");
    }
 
    public void testOnlyPerCacheJmxStatsEnabled() {
-      assert !existsDomains("infinispan");
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
       globalConfiguration.setExposeGlobalJmxStatistics(false);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       cm = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      String jmxDomain = globalConfiguration.getJmxDomain();
 
       Configuration localCache = config();//local by default
       localCache.setExposeJmxStatistics(true);
@@ -135,18 +140,17 @@
       cm.getCache("local_cache");
       cm.getCache("remote1");
 
-      assert existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
-      assert !existsObject("infinispan:cache-name=[global],jmx-resource=RpcManager");
-      assert existsObject("infinispan:cache-name=remote1(repl_sync),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
+      assert !existsObject(jmxDomain + ":cache-name=[global],jmx-resource=RpcManager");
+      assert existsObject(jmxDomain + ":cache-name=remote1(repl_sync),jmx-resource=Statistics");
    }
 
    public void testMultipleManagersOnSameServerFails(Method method) throws Exception {
-      assert !existsDomains("infinispan");
       final String jmxDomain = JMX_DOMAIN + '.' + method.getName();
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
       globalConfiguration.setJmxDomain(jmxDomain);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
-      cm = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      cm = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration);
       Configuration localCache = config();//local by default
       localCache.setExposeJmxStatistics(true);
       cm.defineConfiguration("local_cache", localCache);
@@ -159,14 +163,14 @@
       globalConfiguration2.setAllowDuplicateDomains(false);
       globalConfiguration2.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       try {
-         TestCacheManagerFactory.createCacheManager(globalConfiguration2);
+         TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration2);
          assert false : "Failure expected, '" + jmxDomain + "' duplicate!";
       } catch (JmxDomainConflictException e) {
       }
-      
+
       server = PerThreadMBeanServerLookup.getThreadMBeanServer();
       globalConfiguration2.setAllowDuplicateDomains(true);
-      CacheManager duplicateAllowedManager = TestCacheManagerFactory.createCacheManager(globalConfiguration2);
+      CacheManager duplicateAllowedManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration2);
       try {
          final String duplicateName = jmxDomain + "2";
          ObjectName duplicateObjectName = new ObjectName(duplicateName + ":cache-name=[global],jmx-resource=CacheManager");
@@ -175,9 +179,8 @@
          duplicateAllowedManager.stop();
       }
    }
-   
+
    public void testMultipleManagersOnSameServerWithCloneFails() {
-      assert !existsDomains("infinispan");
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       cm = TestCacheManagerFactory.createCacheManager(globalConfiguration);
@@ -185,42 +188,44 @@
       localCache.setExposeJmxStatistics(true);
       cm.defineConfiguration("local_cache", localCache);
       cm.getCache("local_cache");
-      assert existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
+      String jmxDomain = globalConfiguration.getJmxDomain();
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
 
       GlobalConfiguration globalConfigurationClone = globalConfiguration.clone();
       globalConfigurationClone.setExposeGlobalJmxStatistics(true);
       globalConfigurationClone.setAllowDuplicateDomains(false);
       globalConfigurationClone.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       try {
-         TestCacheManagerFactory.createCacheManager(globalConfigurationClone);
-         assert false : "Failure expected, 'infinispan' duplicate!";
+         TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfigurationClone);
+         assert false : "Failure expected!";
       } catch (JmxDomainConflictException e) {
       }
    }
 
    public void testMultipleManagersOnSameServer() {
-      assert !existsDomains("infinispan");
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
       globalConfiguration.setAllowDuplicateDomains(true);
       globalConfiguration.setExposeGlobalJmxStatistics(true);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       cm = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      String jmxDomain = globalConfiguration.getJmxDomain();
       Configuration localCache = config();//local by default
       localCache.setExposeJmxStatistics(true);
       cm.defineConfiguration("local_cache", localCache);
       cm.getCache("local_cache");
-      assert existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
 
       GlobalConfiguration globalConfiguration2 = GlobalConfiguration.getClusteredDefault();
       globalConfiguration2.setExposeGlobalJmxStatistics(true);
       globalConfiguration2.setAllowDuplicateDomains(true);
       globalConfiguration2.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       cm2 = TestCacheManagerFactory.createCacheManager(globalConfiguration2);
+      String jmxDomain2 = cm2.getGlobalConfiguration().getJmxDomain();
       Configuration localCache2 = config();//local by default
       localCache2.setExposeJmxStatistics(true);
       cm2.defineConfiguration("local_cache", localCache);
       cm2.getCache("local_cache");
-      assert existsObject("infinispan2:cache-name=local_cache(local),jmx-resource=Statistics");
+      assert existsObject(jmxDomain2 + ":cache-name=local_cache(local),jmx-resource=Statistics");
 
       GlobalConfiguration globalConfiguration3 = GlobalConfiguration.getClusteredDefault();
       globalConfiguration3.setExposeGlobalJmxStatistics(true);
@@ -231,11 +236,11 @@
       localCache3.setExposeJmxStatistics(true);
       cm3.defineConfiguration("local_cache", localCache);
       cm3.getCache("local_cache");
-      assert existsObject("infinispan3:cache-name=local_cache(local),jmx-resource=Statistics");
+      String jmxDomain3 = cm3.getGlobalConfiguration().getJmxDomain();
+      assert existsObject(jmxDomain3 + ":cache-name=local_cache(local),jmx-resource=Statistics");
    }
 
    public void testUnregisterJmxInfoOnStop() {
-      assert !existsDomains("infinispan");
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
       globalConfiguration.setExposeGlobalJmxStatistics(true);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
@@ -244,12 +249,13 @@
       localCache.setExposeJmxStatistics(true);
       cm.defineConfiguration("local_cache", localCache);
       cm.getCache("local_cache");
-      assert existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
+      String jmxDomain = globalConfiguration.getJmxDomain();
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
 
       TestingUtil.killCacheManagers(cm);
 
-      assert !existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
-      assert !existsDomains("infinispan");
+      assert !existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
+      assert !existsDomains(jmxDomain);
    }
 
    public void testCorrectUnregistering() {
@@ -260,8 +266,9 @@
       Configuration localCache = config();//local by default
       cm.defineConfiguration("local_cache", localCache);
       cm.getCache("local_cache");
-      assert existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
-      assert existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Cache");
+      String jmxDomain = cm.getGlobalConfiguration().getJmxDomain();
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Cache");
 
       //now register a global one
       GlobalConfiguration globalConfiguration2 = GlobalConfiguration.getClusteredDefault();
@@ -274,17 +281,18 @@
       remoteCache.setCacheMode(Configuration.CacheMode.REPL_SYNC);
       cm2.defineConfiguration("remote_cache", remoteCache);
       cm2.getCache("remote_cache");
-      assert existsObject("infinispan2:cache-name=remote_cache(repl_sync),jmx-resource=Cache");
-      assert existsObject("infinispan2:cache-name=remote_cache(repl_sync),jmx-resource=Statistics");
+      String jmxDomain2 = cm2.getGlobalConfiguration().getJmxDomain();
+      assert existsObject(jmxDomain2 + ":cache-name=remote_cache(repl_sync),jmx-resource=Cache");
+      assert existsObject(jmxDomain2 + ":cache-name=remote_cache(repl_sync),jmx-resource=Statistics");
 
       cm2.stop();
-      assert existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
-      assert !existsObject("infinispan2:cache-name=remote_cache(repl_sync),jmx-resource=Cache");
-      assert !existsObject("infinispan2:cache-name=remote_cache(repl_sync),jmx-resource=Statistics");
+      assert existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
+      assert !existsObject(jmxDomain2 + ":cache-name=remote_cache(repl_sync),jmx-resource=Cache");
+      assert !existsObject(jmxDomain2 + ":cache-name=remote_cache(repl_sync),jmx-resource=Statistics");
 
       cm.stop();
-      assert !existsObject("infinispan:cache-name=local_cache(local),jmx-resource=Statistics");
-      assert !existsObject("infinispan2:cache-name=remote_cache(repl_sync),jmx-resource=Statistics");
+      assert !existsObject(jmxDomain + ":cache-name=local_cache(local),jmx-resource=Statistics");
+      assert !existsObject(jmxDomain2 + ":cache-name=remote_cache(repl_sync),jmx-resource=Statistics");
    }
 
    static boolean existsObject(String s) {

Modified: trunk/core/src/test/java/org/infinispan/jmx/MvccLockManagerMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/MvccLockManagerMBeanTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/MvccLockManagerMBeanTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -23,13 +23,14 @@
 
    private ObjectName lockManagerObjName;
    private MBeanServer threadMBeanServer;
+   private static final String JMX_DOMAIN = "MvccLockManagerMBeanTest";
 
    protected CacheManager createCacheManager() throws Exception {
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getNonClusteredDefault();
       globalConfiguration.setExposeGlobalJmxStatistics(true);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
-      globalConfiguration.setJmxDomain("MvccLockManagerMBeanTest");
-      cacheManager = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      globalConfiguration.setJmxDomain(JMX_DOMAIN);
+      cacheManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration);
 
       Configuration configuration = getDefaultStandaloneConfig(true);
       configuration.setExposeJmxStatistics(true);
@@ -37,7 +38,7 @@
 
       cacheManager.defineConfiguration("test", configuration);
       cache = cacheManager.getCache("test");
-      lockManagerObjName = new ObjectName("MvccLockManagerMBeanTest:cache-name=test(local),jmx-resource=LockManager");
+      lockManagerObjName = new ObjectName(JMX_DOMAIN + ":cache-name=test(local),jmx-resource=LockManager");
 
       threadMBeanServer = PerThreadMBeanServerLookup.getThreadMBeanServer();
       return cacheManager;

Modified: trunk/core/src/test/java/org/infinispan/jmx/RpcManagerMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/RpcManagerMBeanTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/RpcManagerMBeanTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -49,7 +49,7 @@
       globalConfiguration.setAllowDuplicateDomains(true);
       globalConfiguration.setJmxDomain(JMX_DOMAIN);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
-      CacheManager cacheManager1 = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      CacheManager cacheManager1 = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration);
       cacheManager1.start();
 
       GlobalConfiguration globalConfiguration2 = GlobalConfiguration.getClusteredDefault();
@@ -57,7 +57,7 @@
       globalConfiguration2.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       globalConfiguration2.setJmxDomain(JMX_DOMAIN);
       globalConfiguration2.setAllowDuplicateDomains(true);
-      CacheManager cacheManager2 = TestCacheManagerFactory.createCacheManager(globalConfiguration2);
+      CacheManager cacheManager2 = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration2);
       cacheManager2.start();
 
       registerCacheManager(cacheManager1, cacheManager2);

Modified: trunk/core/src/test/java/org/infinispan/jmx/TxInterceptorMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/TxInterceptorMBeanTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/jmx/TxInterceptorMBeanTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -29,9 +29,9 @@
       globalConfiguration.setAllowDuplicateDomains(true);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       globalConfiguration.setJmxDomain("TxInterceptorMBeanTest");
-      CacheManager cacheManager1 = TestCacheManagerFactory.createCacheManager(globalConfiguration);
+      CacheManager cacheManager1 = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration);
       registerCacheManager(cacheManager1);
-      CacheManager cacheManager2 = TestCacheManagerFactory.createCacheManager(globalConfiguration.clone());
+      CacheManager cacheManager2 = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration.clone());
       registerCacheManager(cacheManager2);
 
       Configuration configuration = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC, true);

Modified: trunk/core/src/test/java/org/infinispan/replication/SyncCacheListenerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncCacheListenerTest.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncCacheListenerTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -10,6 +10,7 @@
 import org.infinispan.Cache;
 import org.infinispan.CacheException;
 import org.infinispan.config.Configuration;
+import org.infinispan.distribution.ConsistentHash;
 import org.infinispan.notifications.Listener;
 import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
 import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;

Added: trunk/core/src/test/java/org/infinispan/stress/MemoryCleanupTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/stress/MemoryCleanupTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/stress/MemoryCleanupTest.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -0,0 +1,56 @@
+package org.infinispan.stress;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.Cache;
+
+/**
+ * // TODO: Mircea - Document this!
+ *
+ * @author Mircea.Markus at jboss.com
+ */
+ at Test
+public class MemoryCleanupTest {
+
+
+   @BeforeTest
+   public void createCm() {
+   }
+
+   public void testMemoryConsumption () throws InterruptedException {
+      DefaultCacheManager cm = new DefaultCacheManager(true);
+
+      Cache<Object,Object> cache = cm.getCache();
+
+      long freeMemBefore = freeMemKb();
+      System.out.println("freeMemBefore = " + freeMemBefore);
+
+      for (int i =0; i < 1024 * 300; i++) {
+         cache.put(i,i);
+      }
+      System.out.println("Free meme after: " + freeMemKb());
+      System.out.println("Consumed memory: " + (freeMemBefore - freeMemKb()));
+      cm.stop();
+      for (int i = 0; i<10; i++) {
+         System.gc();
+         if (isOkay(freeMemBefore)) {
+            break;
+         } else {
+            Thread.sleep(1000);
+         }
+      }
+      System.out.println("Free memory at the end:" + freeMemKb());
+      assert isOkay(freeMemBefore);
+      
+   }
+
+   private boolean isOkay(long freeMemBefore) {
+      return freeMemBefore < freeMemKb() + 0.1 * freeMemKb();
+   }
+
+
+   public long freeMemKb() {
+      return Runtime.getRuntime().freeMemory() / 1024;
+   }
+}

Modified: trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java	2010-01-14 14:28:05 UTC (rev 1372)
+++ trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java	2010-01-15 14:01:57 UTC (rev 1373)
@@ -16,20 +16,29 @@
 import java.io.InputStream;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
- * CacheManagers in unit tests should be created with this factory, in order to avoit resource clashes.
+ * CacheManagers in unit tests should be created with this factory, in order to avoid resource clashes.
+ * See http://community.jboss.org/wiki/ParallelTestSuite for more details.
  *
  * @author Mircea.Markus at jboss.com
  * @author Galder Zamarreño
  */
 public class TestCacheManagerFactory {
 
+
+   private static AtomicInteger jmxDomainPostfix = new AtomicInteger();
+
    public static final String MARSHALLER = System.getProperties().getProperty("infinispan.marshaller.class");
    private static Log log = LogFactory.getLog(TestCacheManagerFactory.class);
 
-   private static DefaultCacheManager newDefaultCacheManager(GlobalConfiguration gc, Configuration c) {
-      return new DefaultCacheManager(gc, c);
+   private static DefaultCacheManager newDefaultCacheManager(GlobalConfiguration gc, Configuration c, boolean keepJmxDomain) {
+      if (!keepJmxDomain) {
+         gc.setJmxDomain("infinispan" + jmxDomainPostfix.incrementAndGet());
+      }
+      DefaultCacheManager defaultCacheManager = new DefaultCacheManager(gc, c);
+      return defaultCacheManager;
    }
 
    public static CacheManager fromXml(String xmlFile) throws IOException {
@@ -67,12 +76,6 @@
       return createLocalCacheManager(false);
    }
 
-   private static void minimizeThreads(GlobalConfiguration gc) {
-      Properties p = new Properties();
-      p.setProperty("maxThreads", "1");
-      gc.setAsyncTransportExecutorProperties(p);
-   }
-
    /**
     * Creates an cache manager that does not support clustering.
     *
@@ -84,7 +87,7 @@
       minimizeThreads(globalConfiguration);
       Configuration c = new Configuration();
       if (transactional) amendJTA(c);
-      return newDefaultCacheManager(globalConfiguration, c);
+      return newDefaultCacheManager(globalConfiguration, c, false);
    }
 
    private static void amendJTA(Configuration c) {
@@ -101,7 +104,7 @@
       Properties newTransportProps = new Properties();
       newTransportProps.put(JGroupsTransport.CONFIGURATION_STRING, JGroupsConfigBuilder.getJGroupsConfig());
       globalConfiguration.setTransportProperties(newTransportProps);
-      return newDefaultCacheManager(globalConfiguration, new Configuration());
+      return newDefaultCacheManager(globalConfiguration, new Configuration(), false);
    }
 
    /**
@@ -114,7 +117,7 @@
       Properties newTransportProps = new Properties();
       newTransportProps.put(JGroupsTransport.CONFIGURATION_STRING, JGroupsConfigBuilder.getJGroupsConfig());
       globalConfiguration.setTransportProperties(newTransportProps);
-      return newDefaultCacheManager(globalConfiguration, defaultCacheConfig);
+      return newDefaultCacheManager(globalConfiguration, defaultCacheConfig, false);
    }
 
    /**
@@ -122,10 +125,23 @@
     * during running tests in parallel.
     */
    public static CacheManager createCacheManager(GlobalConfiguration configuration) {
+      return internalCreateJmxDomain(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 CacheManager createCacheManagerEnforceJmxDomain(GlobalConfiguration configuration) {
+      return internalCreateJmxDomain(configuration, true);
+   }
+
+   private static CacheManager internalCreateJmxDomain(GlobalConfiguration configuration, boolean enforceJmxDomain) {
       amendMarshaller(configuration);
       minimizeThreads(configuration);
       amendTransport(configuration);
-      return newDefaultCacheManager(configuration, new Configuration());
+      return newDefaultCacheManager(configuration, new Configuration(), enforceJmxDomain);
    }
 
    /**
@@ -146,35 +162,47 @@
       amendMarshaller(globalConfiguration);
       minimizeThreads(globalConfiguration);
       if (transactional) amendJTA(defaultCacheConfig);
-      return newDefaultCacheManager(globalConfiguration, defaultCacheConfig);
+      return newDefaultCacheManager(globalConfiguration, defaultCacheConfig, false);
    }
 
    public static CacheManager createCacheManager(GlobalConfiguration configuration, Configuration defaultCfg) {
-      return createCacheManager(configuration, defaultCfg, false);
+      return createCacheManager(configuration, defaultCfg, false, false);
    }
 
-   public static CacheManager createCacheManager(GlobalConfiguration configuration, Configuration defaultCfg, boolean transactional) {
+   public static CacheManager createCacheManager(GlobalConfiguration configuration, Configuration defaultCfg, boolean transactional, boolean keepJmxDomainName) {
       minimizeThreads(configuration);
       amendMarshaller(configuration);
       amendTransport(configuration);
       if (transactional) amendJTA(defaultCfg);
-      return newDefaultCacheManager(configuration, defaultCfg);
+      return newDefaultCacheManager(configuration, defaultCfg, keepJmxDomainName);
    }
 
-   public static CacheManager createJmxEnabledCacheManager(String jmxDomain) {
-      return createJmxEnabledCacheManager(jmxDomain, true, true);
+   /**
+    * @see #createCacheManagerEnforceJmxDomain(String)
+    */
+   public static CacheManager createCacheManagerEnforceJmxDomain(String jmxDomain) {
+      return createCacheManagerEnforceJmxDomain(jmxDomain, true, true);
    }
 
-   public static CacheManager createJmxEnabledCacheManager(String jmxDomain, boolean exposeGlobalJmx, boolean exposeCacheJmx) {
+   /**
+    * @see #createCacheManagerEnforceJmxDomain(String)
+    */
+   public static CacheManager createCacheManagerEnforceJmxDomain(String jmxDomain, boolean exposeGlobalJmx, boolean exposeCacheJmx) {
       GlobalConfiguration globalConfiguration = GlobalConfiguration.getNonClusteredDefault();
       globalConfiguration.setJmxDomain(jmxDomain);
       globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
       globalConfiguration.setExposeGlobalJmxStatistics(exposeGlobalJmx);
       Configuration configuration = new Configuration();
       configuration.setExposeJmxStatistics(exposeCacheJmx);
-      return createCacheManager(globalConfiguration, configuration);
+      return createCacheManager(globalConfiguration, configuration, false, true);
    }
 
+   public static Configuration getDefaultConfiguration(boolean transactional) {
+      Configuration c = new Configuration();
+      if (transactional) amendJTA(c);
+      return c;
+   }
+
    private static void amendTransport(GlobalConfiguration configuration) {
       if (configuration.getTransportClass() != null) { //this is local
          Properties newTransportProps = new Properties();
@@ -187,6 +215,12 @@
       }
    }
 
+   private static void minimizeThreads(GlobalConfiguration gc) {
+      Properties p = new Properties();
+      p.setProperty("maxThreads", "1");
+      gc.setAsyncTransportExecutorProperties(p);
+   }
+
    private static void amendMarshaller(GlobalConfiguration configuration) {
       if (MARSHALLER != null) {
          try {
@@ -197,10 +231,4 @@
          }
       }
    }
-
-   public static Configuration getDefaultConfiguration(boolean transactional) {
-      Configuration c = new Configuration();
-      if (transactional) amendJTA(c);
-      return c;
-   }
 }



More information about the infinispan-commits mailing list