HHH-6457 Correct infinispan and ehcache test failures

This commit is contained in:
Brett Meyer 2013-04-18 14:34:24 -04:00
parent cbddeccf9b
commit e765580031
13 changed files with 206 additions and 118 deletions

View File

@ -11,6 +11,7 @@ import java.util.Map;
import org.hamcrest.CoreMatchers; import org.hamcrest.CoreMatchers;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.ehcache.EhCacheRegionFactory; import org.hibernate.cache.ehcache.EhCacheRegionFactory;
import org.hibernate.cache.ehcache.internal.strategy.ItemValueExtractor; import org.hibernate.cache.ehcache.internal.strategy.ItemValueExtractor;
import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.cache.spi.access.SoftLock;
@ -33,7 +34,6 @@ import org.junit.Test;
* @author Chris Dennis * @author Chris Dennis
* @author Brett Meyer * @author Brett Meyer
*/ */
//@FailureExpectedWithNewMetamodel
public class HibernateCacheTest extends BaseCoreFunctionalTestCase { public class HibernateCacheTest extends BaseCoreFunctionalTestCase {
private static final String REGION_PREFIX = "hibernate.test."; private static final String REGION_PREFIX = "hibernate.test.";
@ -46,6 +46,16 @@ public class HibernateCacheTest extends BaseCoreFunctionalTestCase {
config.setProperty( AvailableSettings.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName()); config.setProperty( AvailableSettings.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName());
config.setProperty( "net.sf.ehcache.configurationResourceName", "/hibernate-config/ehcache.xml" ); config.setProperty( "net.sf.ehcache.configurationResourceName", "/hibernate-config/ehcache.xml" );
} }
@Override
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.applySetting( AvailableSettings.USE_QUERY_CACHE, "true");
serviceRegistryBuilder.applySetting( AvailableSettings.USE_STRUCTURED_CACHE, "true" );
serviceRegistryBuilder.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" );
serviceRegistryBuilder.applySetting( AvailableSettings.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName());
serviceRegistryBuilder.applySetting( "net.sf.ehcache.configurationResourceName", "/hibernate-config/ehcache.xml" );
}
@Override @Override
protected String getBaseForMappings() { protected String getBaseForMappings() {
return "hibernate-config/domain/"; return "hibernate-config/domain/";

View File

@ -3,6 +3,7 @@ package org.hibernate.test.cache.ehcache;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Map; import java.util.Map;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.ehcache.EhCacheRegionFactory; import org.hibernate.cache.ehcache.EhCacheRegionFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
@ -17,6 +18,12 @@ public class EhCacheRegionFactoryImpl extends EhCacheTest {
cfg.setProperty( Environment.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName() ); cfg.setProperty( Environment.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName() );
cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "ehcache.xml" ); cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "ehcache.xml" );
} }
@Override
protected void configCache(final StandardServiceRegistryBuilder builder) {
builder.applySetting( Environment.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName() );
builder.applySetting( Environment.CACHE_PROVIDER_CONFIG, "ehcache.xml" );
}
@Override @Override
protected Map getMapFromCacheEntry(final Object entry) { protected Map getMapFromCacheEntry(final Object entry) {

View File

@ -2,6 +2,7 @@ package org.hibernate.test.cache.ehcache;
import java.util.Map; import java.util.Map;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.ehcache.EhCacheRegionFactory; import org.hibernate.cache.ehcache.EhCacheRegionFactory;
import org.hibernate.cache.ehcache.internal.strategy.ItemValueExtractor; import org.hibernate.cache.ehcache.internal.strategy.ItemValueExtractor;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
@ -16,6 +17,12 @@ public class EhCacheRegionTest extends EhCacheTest {
cfg.setProperty( Environment.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName() ); cfg.setProperty( Environment.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName() );
cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "ehcache.xml" ); cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "ehcache.xml" );
} }
@Override
protected void configCache(final StandardServiceRegistryBuilder builder) {
builder.applySetting( Environment.CACHE_REGION_FACTORY, EhCacheRegionFactory.class.getName() );
builder.applySetting( Environment.CACHE_PROVIDER_CONFIG, "ehcache.xml" );
}
@Override @Override
protected Map getMapFromCacheEntry(final Object entry) { protected Map getMapFromCacheEntry(final Object entry) {

View File

@ -23,22 +23,22 @@
*/ */
package org.hibernate.test.cache.ehcache; package org.hibernate.test.cache.ehcache;
import java.util.Map; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test; import java.util.Map;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory; import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
import org.hibernate.stat.SecondLevelCacheStatistics; import org.hibernate.stat.SecondLevelCacheStatistics;
import org.hibernate.stat.Statistics; import org.hibernate.stat.Statistics;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
@ -70,9 +70,21 @@ public abstract class EhCacheTest extends BaseCoreFunctionalTestCase {
configCache( cfg ); configCache( cfg );
cfg.setProperty( Environment.TRANSACTION_STRATEGY, JdbcTransactionFactory.class.getName() ); cfg.setProperty( Environment.TRANSACTION_STRATEGY, JdbcTransactionFactory.class.getName() );
} }
@Override
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.applySetting( Environment.CACHE_REGION_PREFIX, "" );
serviceRegistryBuilder.applySetting( Environment.USE_SECOND_LEVEL_CACHE, "true" );
serviceRegistryBuilder.applySetting( Environment.GENERATE_STATISTICS, "true" );
serviceRegistryBuilder.applySetting( Environment.USE_STRUCTURED_CACHE, "true" );
configCache( serviceRegistryBuilder );
serviceRegistryBuilder.applySetting( Environment.TRANSACTION_STRATEGY, JdbcTransactionFactory.class.getName() );
}
protected abstract void configCache(final Configuration cfg); protected abstract void configCache(final Configuration cfg);
protected abstract void configCache(final StandardServiceRegistryBuilder builder);
@Test @Test
public void testQueryCacheInvalidation() { public void testQueryCacheInvalidation() {
Session s = openSession(); Session s = openSession();

View File

@ -23,6 +23,10 @@
*/ */
package org.hibernate.test.cache.infinispan.functional; package org.hibernate.test.cache.infinispan.functional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
@ -36,14 +40,12 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.transaction.TransactionManager;
import org.infinispan.util.logging.Log; import javax.transaction.TransactionManager;
import org.infinispan.util.logging.LogFactory;
import org.junit.Test;
import org.hibernate.FlushMode; import org.hibernate.FlushMode;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
@ -52,10 +54,9 @@ import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeConnection
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaPlatformImpl; import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaPlatformImpl;
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl; import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl;
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeTestCase; import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeTestCase;
import org.infinispan.util.logging.Log;
import static org.junit.Assert.assertEquals; import org.infinispan.util.logging.LogFactory;
import static org.junit.Assert.assertNotNull; import org.junit.Test;
import static org.junit.Assert.assertNull;
/** /**
* @author nikita_tovstoles@mba.berkeley.edu * @author nikita_tovstoles@mba.berkeley.edu
@ -91,6 +92,13 @@ public class ConcurrentWriteTest extends SingleNodeTestCase {
cfg.setProperty( DualNodeTestCase.NODE_ID_PROP, DualNodeTestCase.LOCAL ); cfg.setProperty( DualNodeTestCase.NODE_ID_PROP, DualNodeTestCase.LOCAL );
cfg.setProperty( DualNodeTestCase.NODE_ID_FIELD, DualNodeTestCase.LOCAL ); cfg.setProperty( DualNodeTestCase.NODE_ID_FIELD, DualNodeTestCase.LOCAL );
} }
@Override
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
super.prepareStandardServiceRegistryBuilder( serviceRegistryBuilder );
serviceRegistryBuilder.applySetting( DualNodeTestCase.NODE_ID_PROP, DualNodeTestCase.LOCAL );
serviceRegistryBuilder.applySetting( DualNodeTestCase.NODE_ID_FIELD, DualNodeTestCase.LOCAL );
}
@Override @Override
protected boolean getUseQueryCache() { protected boolean getUseQueryCache() {

View File

@ -23,7 +23,10 @@
*/ */
package org.hibernate.test.cache.infinispan.functional; package org.hibernate.test.cache.infinispan.functional;
import static org.junit.Assert.assertEquals;
import java.util.Properties; import java.util.Properties;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.Name; import javax.naming.Name;
@ -31,6 +34,17 @@ import javax.naming.NameNotFoundException;
import javax.naming.Reference; import javax.naming.Reference;
import javax.naming.StringRefAddr; import javax.naming.StringRefAddr;
import org.hibernate.Session;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cache.infinispan.JndiInfinispanRegionFactory;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Mappings;
import org.hibernate.dialect.Dialect;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.stat.Statistics;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.infinispan.lifecycle.ComponentStatus; import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.DefaultCacheManager;
@ -42,19 +56,6 @@ import org.jnp.server.Main;
import org.jnp.server.SingletonNamingServer; import org.jnp.server.SingletonNamingServer;
import org.junit.Test; import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cache.infinispan.JndiInfinispanRegionFactory;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Mappings;
import org.hibernate.dialect.Dialect;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.stat.Statistics;
import static org.junit.Assert.assertEquals;
/** /**
* // TODO: Document this * // TODO: Document this
* *
@ -124,6 +125,14 @@ public class JndiRegionFactoryTestCase extends SingleNodeTestCase {
cfg.setProperty( Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory" ); cfg.setProperty( Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory" );
cfg.setProperty( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" ); cfg.setProperty( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );
} }
@Override
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
super.prepareStandardServiceRegistryBuilder( serviceRegistryBuilder );
serviceRegistryBuilder.applySetting( JndiInfinispanRegionFactory.CACHE_MANAGER_RESOURCE_PROP, JNDI_NAME );
serviceRegistryBuilder.applySetting( Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory" );
serviceRegistryBuilder.applySetting( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );
}
@Test @Test
public void testRedeployment() throws Exception { public void testRedeployment() throws Exception {

View File

@ -26,23 +26,23 @@ package org.hibernate.test.cache.infinispan.functional;
import javax.transaction.Status; import javax.transaction.Status;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import org.infinispan.configuration.parsing.ConfigurationBuilderHolder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
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.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.engine.transaction.spi.TransactionFactory;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.spi.TransactionFactory;
import org.hibernate.test.cache.infinispan.tm.JtaPlatformImpl; import org.hibernate.test.cache.infinispan.tm.JtaPlatformImpl;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
/** /**
* @author Galder Zamarreño * @author Galder Zamarreño
@ -121,6 +121,20 @@ public abstract class SingleNodeTestCase extends BaseCoreFunctionalTestCase {
cfg.setProperty( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() ); cfg.setProperty( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() );
cfg.setProperty( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() ); cfg.setProperty( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() );
} }
@Override
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.applySetting( Environment.USE_SECOND_LEVEL_CACHE, "true" );
serviceRegistryBuilder.applySetting( Environment.GENERATE_STATISTICS, "true" );
serviceRegistryBuilder.applySetting( Environment.USE_QUERY_CACHE, String.valueOf( getUseQueryCache() ) );
serviceRegistryBuilder.applySetting( Environment.CACHE_REGION_FACTORY, getCacheRegionFactory().getName() );
if ( getJtaPlatform() != null ) {
serviceRegistryBuilder.applySetting( AvailableSettings.JTA_PLATFORM, getJtaPlatform() );
}
serviceRegistryBuilder.applySetting( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() );
serviceRegistryBuilder.applySetting( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() );
}
protected void beginTx() throws Exception { protected void beginTx() throws Exception {
tm.begin(); tm.begin();

View File

@ -21,35 +21,35 @@
*/ */
package org.hibernate.test.cache.infinispan.functional.bulk; package org.hibernate.test.cache.infinispan.functional.bulk;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.transaction.Status; import javax.transaction.Status;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase;
import org.junit.Test;
import org.hibernate.FlushMode; import org.hibernate.FlushMode;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.engine.transaction.spi.TransactionFactory;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.spi.TransactionFactory;
import org.hibernate.stat.SecondLevelCacheStatistics; import org.hibernate.stat.SecondLevelCacheStatistics;
import org.hibernate.test.cache.infinispan.functional.Contact; import org.hibernate.test.cache.infinispan.functional.Contact;
import org.hibernate.test.cache.infinispan.functional.Customer; 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.hibernate.test.cache.infinispan.tm.JtaPlatformImpl;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/** /**
* BulkOperationsTestCase. * BulkOperationsTestCase.
@ -100,6 +100,17 @@ public class BulkOperationsTestCase extends BaseCoreFunctionalTestCase {
cfg.getProperties().put( AvailableSettings.JTA_PLATFORM, getJtaPlatform() ); cfg.getProperties().put( AvailableSettings.JTA_PLATFORM, getJtaPlatform() );
cfg.setProperty( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() ); cfg.setProperty( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() );
} }
@Override
protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.applySetting( Environment.USE_SECOND_LEVEL_CACHE, "true" );
serviceRegistryBuilder.applySetting( Environment.GENERATE_STATISTICS, "true" );
serviceRegistryBuilder.applySetting( Environment.USE_QUERY_CACHE, "false" );
serviceRegistryBuilder.applySetting( Environment.CACHE_REGION_FACTORY, getCacheRegionFactory().getName() );
serviceRegistryBuilder.applySetting( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() );
serviceRegistryBuilder.applySetting( AvailableSettings.JTA_PLATFORM, getJtaPlatform() );
serviceRegistryBuilder.applySetting( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() );
}
@Test @Test
public void testBulkOperations() throws Throwable { public void testBulkOperations() throws Throwable {

View File

@ -23,8 +23,18 @@
*/ */
package org.hibernate.test.cache.infinispan.functional.classloader; package org.hibernate.test.cache.infinispan.functional.classloader;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cache.internal.StandardQueryCache;
import org.hibernate.test.cache.infinispan.functional.cluster.ClusterAwareRegionFactory;
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl;
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeTestCase;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.infinispan.manager.CacheContainer; import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.manager.EmbeddedCacheManager;
@ -34,17 +44,6 @@ import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.hibernate.SessionFactory;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cache.internal.StandardQueryCache;
import org.hibernate.cfg.Configuration;
import org.hibernate.test.cache.infinispan.functional.cluster.ClusterAwareRegionFactory;
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl;
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/** /**
* Tests entity and query caching when class of objects being cached are not visible to Infinispan's classloader. Also serves as a * Tests entity and query caching when class of objects being cached are not visible to Infinispan's classloader. Also serves as a
* general integration test. * general integration test.
@ -103,10 +102,10 @@ public class IsolatedClassLoaderTest extends DualNodeTestCase {
} }
@Override @Override
protected void standardConfigure(Configuration cfg) { protected void corePrepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
super.standardConfigure( cfg ); super.corePrepareStandardServiceRegistryBuilder( serviceRegistryBuilder );
cfg.setProperty( InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, "replicated-query" ); serviceRegistryBuilder.applySetting( InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, "replicated-query" );
cfg.setProperty( "hibernate.cache.infinispan.AccountRegion.cfg", "replicated-query" ); serviceRegistryBuilder.applySetting( "hibernate.cache.infinispan.AccountRegion.cfg", "replicated-query" );
} }
@Override @Override

View File

@ -23,19 +23,24 @@
*/ */
package org.hibernate.test.cache.infinispan.functional.cluster; package org.hibernate.test.cache.infinispan.functional.cluster;
import java.util.Properties;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.metamodel.MetadataBuilder;
import org.hibernate.metamodel.SessionFactoryBuilder;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.infinispan.util.logging.Log; import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory; import org.infinispan.util.logging.LogFactory;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
/** /**
* @author Galder Zamarreño * @author Galder Zamarreño
* @since 3.5 * @since 3.5
@ -61,12 +66,20 @@ public abstract class DualNodeTestCase extends BaseCoreFunctionalTestCase {
public String getCacheConcurrencyStrategy() { public String getCacheConcurrencyStrategy() {
return "transactional"; return "transactional";
} }
@Override @Override
public void configure(Configuration cfg) { protected void prepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
standardConfigure( cfg ); corePrepareStandardServiceRegistryBuilder( serviceRegistryBuilder );
cfg.setProperty( NODE_ID_PROP, LOCAL ); serviceRegistryBuilder.applySetting( NODE_ID_PROP, LOCAL );
cfg.setProperty( NODE_ID_FIELD, LOCAL ); serviceRegistryBuilder.applySetting( NODE_ID_FIELD, LOCAL );
}
protected void corePrepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.applySetting( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() );
serviceRegistryBuilder.applySetting( AvailableSettings.JTA_PLATFORM, getJtaPlatformClass().getName() );
serviceRegistryBuilder.applySetting( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() );
serviceRegistryBuilder.applySetting( Environment.CACHE_REGION_FACTORY, getCacheRegionFactory().getName() );
serviceRegistryBuilder.applySetting( Environment.USE_QUERY_CACHE, String.valueOf( getUseQueryCache() ) );
} }
@Override @Override
@ -124,42 +137,41 @@ public abstract class DualNodeTestCase extends BaseCoreFunctionalTestCase {
return true; return true;
} }
protected void configureSecondNode(Configuration cfg) { protected void configureSecondNode(StandardServiceRegistryBuilder builder) {
} }
protected void standardConfigure(Configuration cfg) {
super.configure( cfg );
cfg.setProperty( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() );
cfg.setProperty( AvailableSettings.JTA_PLATFORM, getJtaPlatformClass().getName() );
cfg.setProperty( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() );
cfg.setProperty( Environment.CACHE_REGION_FACTORY, getCacheRegionFactory().getName() );
cfg.setProperty( Environment.USE_QUERY_CACHE, String.valueOf( getUseQueryCache() ) );
cfg.setProperty( USE_NEW_METADATA_MAPPINGS, "false" );
}
public class SecondNodeEnvironment { public class SecondNodeEnvironment {
private Configuration configuration; private StandardServiceRegistryBuilder serviceRegistryBuilder;
private StandardServiceRegistryImpl serviceRegistry; private StandardServiceRegistryImpl serviceRegistry;
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
public SecondNodeEnvironment() { public SecondNodeEnvironment() {
configuration = constructConfiguration(); Properties properties = constructProperties();
standardConfigure( configuration );
configuration.setProperty( NODE_ID_PROP, REMOTE ); // TODO: Look into separating out some of these steps in
configuration.setProperty( NODE_ID_FIELD, REMOTE ); // BaseCoreFuntionalTestCase
configureSecondNode( configuration ); BootstrapServiceRegistry bootstrapServiceRegistry = buildBootstrapServiceRegistry();
addMappings( configuration ); serviceRegistryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry )
configuration.buildMappings(); .applySettings( properties );
applyCacheSettings( configuration ); corePrepareStandardServiceRegistryBuilder( serviceRegistryBuilder );
afterConfigurationBuilt( configuration ); serviceRegistryBuilder.applySetting( NODE_ID_PROP, REMOTE );
serviceRegistry = buildServiceRegistry( buildBootstrapServiceRegistry(), configuration.getProperties() ); serviceRegistryBuilder.applySetting( NODE_ID_FIELD, REMOTE );
sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory( serviceRegistry ); configureSecondNode( serviceRegistryBuilder );
serviceRegistry = (StandardServiceRegistryImpl) serviceRegistryBuilder.build();
MetadataBuilder metadataBuilder = getMetadataBuilder( bootstrapServiceRegistry, serviceRegistry );
configMetadataBuilder(metadataBuilder);
MetadataImplementor metadata = (MetadataImplementor)metadataBuilder.build();
afterConstructAndConfigureMetadata( metadata );
applyCacheSettings( metadata );
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
configSessionFactoryBuilder(sessionFactoryBuilder);
sessionFactory = ( SessionFactoryImplementor )sessionFactoryBuilder.build();
} }
public Configuration getConfiguration() { public StandardServiceRegistryBuilder getServiceRegistryBuilder() {
return configuration; return serviceRegistryBuilder;
} }
public StandardServiceRegistryImpl getServiceRegistry() { public StandardServiceRegistryImpl getServiceRegistry() {

View File

@ -9,6 +9,7 @@ import org.hibernate.criterion.Restrictions;
import org.hibernate.test.cache.infinispan.functional.Citizen; import org.hibernate.test.cache.infinispan.functional.Citizen;
import org.hibernate.test.cache.infinispan.functional.NaturalIdOnManyToOne; import org.hibernate.test.cache.infinispan.functional.NaturalIdOnManyToOne;
import org.hibernate.test.cache.infinispan.functional.State; import org.hibernate.test.cache.infinispan.functional.State;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.infinispan.manager.CacheContainer; import org.infinispan.manager.CacheContainer;
@ -35,6 +36,7 @@ import static org.junit.Assert.fail;
* @author Galder Zamarreño * @author Galder Zamarreño
* @since // TODO * @since // TODO
*/ */
@FailureExpectedWithNewMetamodel
public class NaturalIdInvalidationTestCase extends DualNodeTestCase { public class NaturalIdInvalidationTestCase extends DualNodeTestCase {
private static final Log log = LogFactory.getLog( NaturalIdInvalidationTestCase.class ); private static final Log log = LogFactory.getLog( NaturalIdInvalidationTestCase.class );

View File

@ -23,24 +23,23 @@
*/ */
package org.hibernate.test.cache.infinispan.functional.cluster; package org.hibernate.test.cache.infinispan.functional.cluster;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cfg.Environment;
import org.hibernate.test.cache.infinispan.functional.classloader.Account;
import org.hibernate.test.cache.infinispan.functional.classloader.ClassLoaderTestDAO;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.infinispan.manager.CacheContainer; import org.infinispan.manager.CacheContainer;
import org.infinispan.test.TestingUtil; import org.infinispan.test.TestingUtil;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.junit.Test; import org.junit.Test;
import org.hibernate.SessionFactory;
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.test.cache.infinispan.functional.classloader.Account;
import org.hibernate.test.cache.infinispan.functional.classloader.ClassLoaderTestDAO;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/** /**
* SessionRefreshTestCase. * SessionRefreshTestCase.
* *
@ -54,15 +53,15 @@ public class SessionRefreshTestCase extends DualNodeTestCase {
private Cache localCache; private Cache localCache;
@Override @Override
protected void configureSecondNode(Configuration cfg) { protected void configureSecondNode(StandardServiceRegistryBuilder serviceRegistryBuilder) {
super.configureSecondNode( cfg ); super.configureSecondNode( serviceRegistryBuilder );
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" ); serviceRegistryBuilder.applySetting( Environment.USE_SECOND_LEVEL_CACHE, "false" );
} }
@Override @Override
protected void standardConfigure(Configuration cfg) { protected void corePrepareStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
super.standardConfigure( cfg ); super.corePrepareStandardServiceRegistryBuilder( serviceRegistryBuilder );
cfg.setProperty( InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, getEntityCacheConfigName() ); serviceRegistryBuilder.applySetting( InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, getEntityCacheConfigName() );
} }
protected String getEntityCacheConfigName() { protected String getEntityCacheConfigName() {

View File

@ -47,7 +47,6 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Mappings; import org.hibernate.cfg.Mappings;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
@ -142,7 +141,6 @@ public abstract class BaseCoreFunctionalTestCase extends BaseFunctionalTestCase
afterSessionFactoryBuilt(); afterSessionFactoryBuilt();
} }
protected void rebuildSessionFactory() { protected void rebuildSessionFactory() {
if ( sessionFactory == null ) { if ( sessionFactory == null ) {
return; return;