HHH-10001 Make the testsuite compatible with Infinispan 8

This commit is contained in:
Sanne Grinovero 2015-07-29 23:49:27 +01:00
parent 60c109c1a4
commit 44e7171edd
13 changed files with 111 additions and 4 deletions

View File

@ -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";

View File

@ -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";

View File

@ -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;

View File

@ -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";

View File

@ -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

View File

@ -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";

View File

@ -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";

View File

@ -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();

View File

@ -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

View File

@ -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();
}

View File

@ -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" );

View File

@ -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();

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 );
}
}