diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java index e457658c41..eeba82168b 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractNonFunctionalTestCase.java @@ -8,6 +8,7 @@ package org.hibernate.test.cache.infinispan; import java.util.Set; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.infinispan.Cache; import org.jboss.logging.Logger; import org.junit.After; @@ -15,6 +16,7 @@ import org.junit.Before; import org.hibernate.cache.spi.RegionFactory; import org.hibernate.test.cache.infinispan.util.CacheTestSupport; +import org.junit.Rule; /** * Base class for all non-functional tests of Infinispan integration. @@ -25,6 +27,9 @@ import org.hibernate.test.cache.infinispan.util.CacheTestSupport; public abstract class AbstractNonFunctionalTestCase extends org.hibernate.testing.junit4.BaseUnitTestCase { private static final Logger log = Logger.getLogger(AbstractNonFunctionalTestCase.class); + @Rule + public InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + public static final String REGION_PREFIX = "test"; private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack"; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java index b5b6bc1d4c..34fcc3d047 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java @@ -26,9 +26,11 @@ import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatfor import org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform; import org.hibernate.service.ServiceRegistry; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase; import org.hibernate.testing.boot.ServiceRegistryTestingImpl; +import org.junit.Rule; import org.junit.Test; import org.infinispan.AdvancedCache; @@ -59,6 +61,9 @@ public class InfinispanRegionFactoryTestCase { private static final CacheDataDescription MUTABLE_NON_VERSIONED = new CacheDataDescriptionImpl(true, false, null, null); private static final CacheDataDescription IMMUTABLE_NON_VERSIONED = new CacheDataDescriptionImpl(false, false, null, null); + @Rule + public InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + @Test public void testConfigurationProcessing() { final String person = "com.acme.Person"; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/access/PutFromLoadValidatorUnitTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/access/PutFromLoadValidatorUnitTestCase.java index 066b118470..5d7875c03d 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/access/PutFromLoadValidatorUnitTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/access/PutFromLoadValidatorUnitTestCase.java @@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.hibernate.cache.infinispan.access.PutFromLoadValidator; import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.infinispan.AdvancedCache; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.test.CacheManagerCallable; @@ -27,6 +28,7 @@ import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import static org.infinispan.test.TestingUtil.withCacheManager; @@ -48,6 +50,9 @@ public class PutFromLoadValidatorUnitTestCase { private static final Log log = LogFactory.getLog( PutFromLoadValidatorUnitTestCase.class); + @Rule + public InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + private Object KEY1 = "KEY1"; private TransactionManager tm; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java index 342ea4efc8..fe753fb4e1 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java @@ -29,6 +29,7 @@ import org.hibernate.internal.util.compare.ComparableComparator; import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.NodeEnvironment; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.test.cache.infinispan.util.TestingKeyFactory; import org.infinispan.test.CacheManagerCallable; import org.infinispan.test.fwk.TestCacheManagerFactory; @@ -36,6 +37,7 @@ import org.infinispan.transaction.tm.BatchModeTransactionManager; import org.jboss.logging.Logger; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import static org.infinispan.test.TestingUtil.withCacheManager; @@ -52,6 +54,10 @@ import static org.junit.Assert.assertTrue; */ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends AbstractNonFunctionalTestCase { private static final Logger log = Logger.getLogger( AbstractCollectionRegionAccessStrategyTestCase.class ); + + @Rule + public InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + public static final String REGION_NAME = "test/com.foo.test"; public static final String KEY_BASE = "KEY"; public static final String VALUE1 = "VALUE1"; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java index adc3442b5e..f010b1ec8a 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java @@ -17,9 +17,11 @@ import org.hibernate.internal.util.compare.ComparableComparator; import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.NodeEnvironment; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.test.cache.infinispan.util.TestingKeyFactory; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertNull; @@ -32,6 +34,9 @@ import static org.junit.Assert.assertNull; */ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase { + @Rule + public InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + public static final String REGION_NAME = "test/com.foo.test"; public static final Object KEY = TestingKeyFactory.generateCollectionCacheKey( "KEY" ); public static final CacheDataDescription CACHE_DATA_DESCRIPTION diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java index ab4bd4f6c4..e65841b357 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java @@ -24,6 +24,7 @@ import org.hibernate.internal.util.compare.ComparableComparator; import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.NodeEnvironment; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.test.cache.infinispan.util.TestingKeyFactory; import org.infinispan.Cache; import org.infinispan.test.TestingUtil; @@ -31,6 +32,7 @@ import org.infinispan.transaction.tm.BatchModeTransactionManager; import org.jboss.logging.Logger; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -47,6 +49,9 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac private static final Logger log = Logger.getLogger(AbstractEntityRegionAccessStrategyTestCase.class); + @Rule + public InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + public static final String REGION_NAME = "test/com.foo.test"; public static final String KEY_BASE = "KEY"; public static final String VALUE1 = "VALUE1"; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java index cb61c53ec5..d07bf6054d 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java @@ -16,9 +16,11 @@ import org.hibernate.internal.util.compare.ComparableComparator; import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.NodeEnvironment; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.test.cache.infinispan.util.TestingKeyFactory; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.assertFalse; @@ -35,6 +37,10 @@ import static org.junit.Assert.assertNull; * @since 3.5 */ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase { + + @Rule + public InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + public static final String REGION_NAME = "test/com.foo.test"; public static final Object KEY = TestingKeyFactory.generateEntityCacheKey( "KEY" ); public static final String VALUE1 = "VALUE1"; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/SingleNodeTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/SingleNodeTestCase.java index 8a99d3c7a8..4b5d12481b 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/SingleNodeTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/SingleNodeTestCase.java @@ -19,6 +19,7 @@ import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.resource.transaction.TransactionCoordinatorBuilder; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.cache.infinispan.tm.JtaPlatformImpl; import org.junit.Before; @@ -28,6 +29,7 @@ import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.test.fwk.TestCacheManagerFactory; import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; +import org.junit.ClassRule; /** * @author Galder ZamarreƱo @@ -37,6 +39,9 @@ public abstract class SingleNodeTestCase extends BaseNonConfigCoreFunctionalTest private static final Log log = LogFactory.getLog( SingleNodeTestCase.class ); protected TransactionManager tm; + @ClassRule + public static final InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + @Before public void prepare() { tm = getTransactionManager(); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/bulk/BulkOperationsTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/bulk/BulkOperationsTestCase.java index 03d873eff1..63dac18200 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/bulk/BulkOperationsTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/bulk/BulkOperationsTestCase.java @@ -24,11 +24,13 @@ import org.hibernate.resource.transaction.TransactionCoordinatorBuilder; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.stat.SecondLevelCacheStatistics; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.cache.infinispan.functional.Contact; import org.hibernate.test.cache.infinispan.functional.Customer; import org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase; import org.hibernate.test.cache.infinispan.tm.JtaPlatformImpl; +import org.junit.ClassRule; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -42,6 +44,10 @@ import static org.junit.Assert.assertNull; * @since 3.5 */ public class BulkOperationsTestCase extends BaseNonConfigCoreFunctionalTestCase { + + @ClassRule + public static final InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + private TransactionManager tm; @Override diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java index d4dde0b666..3a5d8e2968 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java @@ -18,20 +18,26 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.resource.transaction.TransactionCoordinatorBuilder; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.After; import org.junit.Before; import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; +import org.junit.ClassRule; /** * @author Galder ZamarreƱo * @since 3.5 */ public abstract class DualNodeTestCase extends BaseNonConfigCoreFunctionalTestCase { + private static final Log log = LogFactory.getLog( DualNodeTestCase.class ); + @ClassRule + public static final InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + public static final String NODE_ID_PROP = "hibernate.test.cluster.node.id"; public static final String NODE_ID_FIELD = "nodeId"; public static final String LOCAL = "local"; @@ -74,6 +80,8 @@ public abstract class DualNodeTestCase extends BaseNonConfigCoreFunctionalTestCa @Before public void prepare() throws Exception { + // In some cases tests are multi-threaded, so they have to join the group + infinispanTestIdentifier.joinContext(); secondNodeEnvironment = new SecondNodeEnvironment(); } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java index 782e144914..9464d8b13c 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java @@ -127,10 +127,6 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase { assertEquals( 0, getValidKeyCount( localCollectionCache.keySet() ) ); assertEquals( 0, getValidKeyCount( localCustomerCache.keySet() ) ); } - catch (Exception e) { - log.error( "Error", e ); - throw e; - } finally { // cleanup the db log.debug( "Cleaning up" ); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/JBossStandaloneJtaExampleTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/JBossStandaloneJtaExampleTest.java index 42708bc5cf..6fbb49e189 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/JBossStandaloneJtaExampleTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/JBossStandaloneJtaExampleTest.java @@ -32,11 +32,13 @@ import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoo import org.hibernate.service.ServiceRegistry; import org.hibernate.stat.Statistics; +import org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup; import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.testing.jta.JtaAwareConnectionProviderImpl; import org.hibernate.test.cache.infinispan.functional.Item; import org.junit.After; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; import org.infinispan.configuration.cache.ConfigurationBuilder; @@ -70,6 +72,9 @@ public class JBossStandaloneJtaExampleTest { Main jndiServer; private ServiceRegistry serviceRegistry; + @ClassRule + public static final InfinispanTestingSetup infinispanTestIdentifier = new InfinispanTestingSetup(); + @Before public void setUp() throws Exception { jndiServer = startJndiServer(); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/InfinispanTestingSetup.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/InfinispanTestingSetup.java new file mode 100644 index 0000000000..4d663b9f2b --- /dev/null +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/InfinispanTestingSetup.java @@ -0,0 +1,50 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.cache.infinispan.util; + +import org.infinispan.test.fwk.TestResourceTracker; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * Infinispan testing utilities take great care to verify isolation between concurrent tests + * and resource teardown. + * These utilities need to be integrated with the test lifecycle; use this as a Rule as one + * way to achieve that integration. + * + * @author Sanne Grinovero + */ +public final class InfinispanTestingSetup implements TestRule { + + private volatile String runningTest; + + public InfinispanTestingSetup() { + } + + public Statement apply(Statement base, Description d) { + final String methodName = d.getMethodName(); + final String testName = methodName == null ? d.getClassName() : d.getClassName() + "#" + d.getMethodName(); + runningTest = testName; + return new Statement() { + @Override + public void evaluate() throws Throwable { + TestResourceTracker.testStarted( testName ); + try { + base.evaluate(); + } finally { + TestResourceTracker.testFinished( testName ); + } + } + }; + } + + public void joinContext() { + TestResourceTracker.setThreadTestName( runningTest ); + } + +}