Permalink
Browse files

ISPN-2325 Fix the JMX domain conflict failing tests

* Convert tests to using test cache manager factory.
* Solve issues related to cache managers not being closed.
* Create alternative cache manager factories for CDI and Spring tests.
  • Loading branch information...
galderz authored and tristantarrant committed Sep 20, 2012
1 parent 3b08d1d commit 097fd4d6746952e104229021cb9a20bcd3aba433
Showing with 710 additions and 358 deletions.
  1. +3 −3 cachestore/hbase/src/test/java/org/infinispan/loaders/hbase/HBaseCacheStoreTestStandalone.java
  2. +6 −0 cdi/extension/pom.xml
  3. +66 −0 cdi/extension/src/test/java/org/infinispan/cdi/test/DefaultTestEmbeddedCacheManagerProducer.java
  4. +3 −1 cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/DefaultCacheTest.java
  5. +3 −1 ...xtension/src/test/java/org/infinispan/cdi/test/cache/embedded/configured/ConfiguredCacheTest.java
  6. +21 −4 cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/specific/Config.java
  7. +3 −1 ...nsion/src/test/java/org/infinispan/cdi/test/cache/embedded/specific/SpecificCacheManagerTest.java
  8. +4 −2 cdi/extension/src/test/java/org/infinispan/cdi/test/cache/remote/DefaultCacheTest.java
  9. +3 −1 ...tension/src/test/java/org/infinispan/cdi/test/cachemanager/embedded/DefaultConfigurationTest.java
  10. +18 −2 cdi/extension/src/test/java/org/infinispan/cdi/test/cachemanager/embedded/external/Config.java
  11. +19 −4 cdi/extension/src/test/java/org/infinispan/cdi/test/cachemanager/embedded/programmatic/Config.java
  12. +3 −1 ...c/test/java/org/infinispan/cdi/test/cachemanager/embedded/registration/CacheRegistrationTest.java
  13. +6 −2 cdi/extension/src/test/java/org/infinispan/cdi/test/cachemanager/embedded/registration/Config.java
  14. +18 −2 cdi/extension/src/test/java/org/infinispan/cdi/test/cachemanager/embedded/xml/Config.java
  15. +3 −1 cdi/extension/src/test/java/org/infinispan/cdi/test/distexec/DistributedExecutorCDITest.java
  16. +3 −1 cdi/extension/src/test/java/org/infinispan/cdi/test/distexec/WordCountMapReduceCDITest.java
  17. +3 −1 cdi/extension/src/test/java/org/infinispan/cdi/test/interceptor/CachePutInterceptorTest.java
  18. +3 −1 cdi/extension/src/test/java/org/infinispan/cdi/test/interceptor/CacheRemoveAllInterceptorTest.java
  19. +3 −1 cdi/extension/src/test/java/org/infinispan/cdi/test/interceptor/CacheRemoveEntryInterceptorTest.java
  20. +3 −1 cdi/extension/src/test/java/org/infinispan/cdi/test/interceptor/CacheResultInterceptorTest.java
  21. +20 −4 cdi/extension/src/test/java/org/infinispan/cdi/test/interceptor/config/Config.java
  22. +7 −1 cdi/extension/src/test/java/org/infinispan/cdi/test/testutil/Deployments.java
  23. +1 −0 cdi/extension/src/test/resources/beans.xml
  24. +1 −1 cdi/tck-runner/pom.xml
  25. +5 −0 cdi/tck-runner/src/test/resources/META-INF/beans.xml
  26. +2 −3 core/src/test/java/org/infinispan/config/TransactionalCacheConfigTest.java
  27. +2 −4 core/src/test/java/org/infinispan/profiling/CacheCreationStressTest.java
  28. +2 −3 core/src/test/java/org/infinispan/stress/CreateThousandCachesTest.java
  29. +4 −2 core/src/test/java/org/infinispan/stress/MapStressTest.java
  30. +2 −2 core/src/test/java/org/infinispan/stress/MemoryCleanupTest.java
  31. +10 −7 core/src/test/java/org/infinispan/xsite/BackupForConfigTest.java
  32. +2 −3 lucene-directory/src/test/java/org/infinispan/lucene/CacheTestSupport.java
  33. +2 −2 server/hotrod/src/test/scala/org/infinispan/server/hotrod/HotRodServerTest.scala
  34. +2 −2 server/memcached/src/test/scala/org/infinispan/server/memcached/MemcachedServerTest.scala
  35. +2 −2 server/websocket/src/test/java/org/infinispan/server/websocket/handlers/MockClient.java
  36. +6 −0 spring/pom.xml
  37. +6 −1 spring/src/main/java/org/infinispan/spring/AbstractEmbeddedCacheManagerFactory.java
  38. +2 −5 spring/src/test/java/org/infinispan/spring/provider/SpringCacheCacheTest.java
  39. +2 −3 spring/src/test/java/org/infinispan/spring/provider/SpringEmbeddedCacheManagerTest.java
  40. +52 −0 spring/src/test/java/org/infinispan/spring/provider/TestSpringEmbeddedCacheManagerFactoryBean.java
  41. +4 −4 spring/src/test/java/org/infinispan/spring/support/InfinispanDefaultCacheFactoryBeanTest.java
  42. +310 −255 ...st/java/org/infinispan/spring/support/embedded/InfinispanEmbeddedCacheManagerFactoryBeanTest.java
  43. +0 −11 ...va/org/infinispan/spring/support/embedded/InfinispanNamedEmbeddedCacheFactoryBeanContextTest.java
  44. +1 −2 ...test/java/org/infinispan/spring/support/embedded/InfinispanNamedEmbeddedCacheFactoryBeanTest.java
  45. +52 −0 ...st/java/org/infinispan/spring/support/embedded/TestInfinispanEmbeddedCacheManagerFactoryBean.java
  46. +3 −3 ...est/resources/org/infinispan/spring/provider/SpringEmbeddedCacheManagerFactoryBeanContextTest.xml
  47. +3 −1 ...src/test/resources/org/infinispan/spring/support/InfinispanDefaultCacheFactoryBeanContextTest.xml
  48. +3 −3 ...s/org/infinispan/spring/support/embedded/InfinispanEmbeddedCacheManagerFactoryBeanContextTest.xml
  49. +1 −1 ...ces/org/infinispan/spring/support/embedded/InfinispanNamedEmbeddedCacheFactoryBeanContextTest.xml
  50. +7 −3 tree/src/test/java/org/infinispan/api/tree/TreeCacheAPITest.java
@@ -30,7 +30,7 @@
import java.util.Set;
import org.infinispan.Cache;
-import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -71,9 +71,9 @@ public void setup() throws Exception {
System.setProperty("java.net.preferIPv4Stack", "true");
if (USE_EMBEDDED) {
- CACHE = new DefaultCacheManager("hbase-cachestore-ispn-embedded.xml").getCache();
+ CACHE = TestCacheManagerFactory.fromXml("hbase-cachestore-ispn-embedded.xml").getCache();
} else {
- CACHE = new DefaultCacheManager("hbase-cachestore-ispn.xml").getCache();
+ CACHE = TestCacheManagerFactory.fromXml("hbase-cachestore-ispn.xml").getCache();
}
}
View
@@ -115,6 +115,12 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>infinispan-server-core</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-hotrod</artifactId>
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other
+ * contributors as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.cdi.test;
+
+import org.infinispan.cdi.OverrideDefault;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+
+/**
+ * <p>The alternative default {@link EmbeddedCacheManager} producer for the test environment.</p>
+ *
+ * @author Galder Zamarreño
+ */
+public class DefaultTestEmbeddedCacheManagerProducer {
+
+ /**
+ * Produces the default embedded cache manager.
+ *
+ * @param providedDefaultEmbeddedCacheManager the provided default embedded cache manager.
+ * @param defaultConfiguration the default configuration produced by the {@link DefaultTestEmbeddedCacheManagerProducer}.
+ * @return the default embedded cache manager used by the application.
+ */
+ @Produces
+ @ApplicationScoped
+ public EmbeddedCacheManager getDefaultEmbeddedCacheManager(@OverrideDefault Instance<EmbeddedCacheManager> providedDefaultEmbeddedCacheManager, Configuration defaultConfiguration) {
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+ builder.read(defaultConfiguration);
+ return TestCacheManagerFactory.createCacheManager(builder);
+ }
+
+ /**
+ * Stops the default embedded cache manager when the corresponding instance is released.
+ *
+ * @param defaultEmbeddedCacheManager the default embedded cache manager.
+ */
+ private void stopCacheManager(@Disposes EmbeddedCacheManager defaultEmbeddedCacheManager) {
+ defaultEmbeddedCacheManager.stop();
+ }
+}
@@ -24,6 +24,7 @@
import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
+import org.infinispan.cdi.test.DefaultTestEmbeddedCacheManagerProducer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
@@ -47,7 +48,8 @@
@Deployment
public static Archive<?> deployment() {
return baseDeployment()
- .addClass(DefaultCacheTest.class);
+ .addClass(DefaultCacheTest.class)
+ .addClass(DefaultTestEmbeddedCacheManagerProducer.class);
}
@Inject
@@ -23,6 +23,7 @@
package org.infinispan.cdi.test.cache.embedded.configured;
import org.infinispan.AdvancedCache;
+import org.infinispan.cdi.test.DefaultTestEmbeddedCacheManagerProducer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
@@ -46,7 +47,8 @@
@Deployment
public static Archive<?> deployment() {
return baseDeployment()
- .addPackage(ConfiguredCacheTest.class.getPackage());
+ .addPackage(ConfiguredCacheTest.class.getPackage())
+ .addClass(DefaultTestEmbeddedCacheManagerProducer.class);
}
@Inject
@@ -26,16 +26,19 @@
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.eviction.EvictionStrategy;
-import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
/**
* @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI
*/
public class Config {
+
/**
* Associates the "large" cache with the qualifier {@link Large}.
*
@@ -45,6 +48,7 @@
@Large
@ConfigureCache("large")
@Produces
+ @SuppressWarnings("unused")
public Configuration largeConfiguration(@Large EmbeddedCacheManager cacheManager) {
return new ConfigurationBuilder()
.read(cacheManager.getDefaultCacheConfiguration())
@@ -61,6 +65,7 @@ public Configuration largeConfiguration(@Large EmbeddedCacheManager cacheManager
@Small
@ConfigureCache("small")
@Produces
+ @SuppressWarnings("unused")
public Configuration smallConfiguration(@Small EmbeddedCacheManager cacheManager) {
return new ConfigurationBuilder()
.read(cacheManager.getDefaultCacheConfiguration())
@@ -75,9 +80,21 @@ public Configuration smallConfiguration(@Small EmbeddedCacheManager cacheManager
@Small
@Produces
@ApplicationScoped
+ @SuppressWarnings("unused")
public EmbeddedCacheManager specificCacheManager() {
- return new DefaultCacheManager(new ConfigurationBuilder()
- .eviction().maxEntries(4000).strategy(EvictionStrategy.LIRS)
- .build());
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+ builder.eviction().maxEntries(4000).strategy(EvictionStrategy.LIRS);
+ return TestCacheManagerFactory.createCacheManager(builder);
}
+
+ /**
+ * Stops cache manager.
+ *
+ * @param cacheManager to be stopped
+ */
+ @SuppressWarnings("unused")
+ public void killCacheManager(@Disposes @Small @Large EmbeddedCacheManager cacheManager) {
+ TestingUtil.killCacheManagers(cacheManager);
+ }
+
}
@@ -23,6 +23,7 @@
package org.infinispan.cdi.test.cache.embedded.specific;
import org.infinispan.Cache;
+import org.infinispan.cdi.test.DefaultTestEmbeddedCacheManagerProducer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
@@ -49,7 +50,8 @@
@Deployment
public static Archive<?> deployment() {
return baseDeployment()
- .addPackage(SpecificCacheManagerTest.class.getPackage());
+ .addPackage(SpecificCacheManagerTest.class.getPackage())
+ .addClass(DefaultTestEmbeddedCacheManagerProducer.class);
}
@Inject
@@ -27,7 +27,9 @@
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.server.core.test.ServerTestingUtil;
import org.infinispan.server.hotrod.HotRodServer;
+import org.infinispan.test.TestingUtil;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
@@ -79,8 +81,8 @@ public void beforeMethod() {
@AfterTest(alwaysRun = true)
public void afterMethod() {
- embeddedCacheManager.stop();
- hotRodServer.stop();
+ TestingUtil.killCacheManagers(embeddedCacheManager);
+ ServerTestingUtil.killServer(hotRodServer);
}
public void testDefaultCache() {
@@ -23,6 +23,7 @@
package org.infinispan.cdi.test.cachemanager.embedded;
import org.infinispan.Cache;
+import org.infinispan.cdi.test.DefaultTestEmbeddedCacheManagerProducer;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.jboss.arquillian.container.test.api.Deployment;
@@ -48,7 +49,8 @@
@Deployment
public static Archive<?> deployment() {
return baseDeployment()
- .addClass(DefaultConfigurationTest.class);
+ .addClass(DefaultConfigurationTest.class)
+ .addClass(DefaultTestEmbeddedCacheManagerProducer.class);
}
@Inject
@@ -25,10 +25,12 @@
import org.infinispan.cdi.ConfigureCache;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
/**
@@ -44,6 +46,7 @@
@Large
@ConfigureCache("large")
@Produces
+ @SuppressWarnings("unused")
public Configuration largeConfiguration;
/**
@@ -52,15 +55,17 @@
@Quick
@ConfigureCache("quick")
@Produces
+ @SuppressWarnings("unused")
public Configuration quickConfiguration;
/**
* Overrides the default embedded cache manager to define the quick and large cache configurations externally.
*/
@Produces
@ApplicationScoped
+ @SuppressWarnings("unused")
public EmbeddedCacheManager defaultCacheManager() {
- EmbeddedCacheManager externalCacheContainerManager = new DefaultCacheManager();
+ EmbeddedCacheManager externalCacheContainerManager = TestCacheManagerFactory.createLocalCacheManager(false);
// define large configuration
externalCacheContainerManager.defineConfiguration("large", new ConfigurationBuilder()
@@ -74,4 +79,15 @@ public EmbeddedCacheManager defaultCacheManager() {
return externalCacheContainerManager;
}
+
+ /**
+ * Stops cache manager.
+ *
+ * @param cacheManager to be stopped
+ */
+ @SuppressWarnings("unused")
+ public void killCacheManager(@Disposes EmbeddedCacheManager cacheManager) {
+ TestingUtil.killCacheManagers(cacheManager);
+ }
+
}
@@ -25,10 +25,12 @@
import org.infinispan.cdi.ConfigureCache;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
/**
@@ -46,16 +48,29 @@
@Small
@ConfigureCache("small")
@Produces
+ @SuppressWarnings("unused")
public Configuration smallConfiguration;
/**
* Overrides the default embedded cache manager.
*/
@Produces
@ApplicationScoped
+ @SuppressWarnings("unused")
public EmbeddedCacheManager defaultCacheManager() {
- return new DefaultCacheManager(new ConfigurationBuilder()
- .eviction().maxEntries(7)
- .build());
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+ builder.eviction().maxEntries(7);
+ return TestCacheManagerFactory.createCacheManager(builder);
}
+
+ /**
+ * Stops cache manager.
+ *
+ * @param cacheManager to be stopped
+ */
+ @SuppressWarnings("unused")
+ public void killCacheManager(@Disposes EmbeddedCacheManager cacheManager) {
+ TestingUtil.killCacheManagers(cacheManager);
+ }
+
}
@@ -31,6 +31,7 @@
import javax.inject.Inject;
import org.infinispan.Cache;
+import org.infinispan.cdi.test.DefaultTestEmbeddedCacheManagerProducer;
import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
@@ -48,7 +49,8 @@
@Deployment
public static Archive<?> deployment() {
return baseDeployment()
- .addPackage(CacheRegistrationTest.class.getPackage());
+ .addPackage(CacheRegistrationTest.class.getPackage())
+ .addClass(DefaultTestEmbeddedCacheManagerProducer.class);
}
@Inject
Oops, something went wrong.

0 comments on commit 097fd4d

Please sign in to comment.