HHH-5949 : Migrate, complete and integrate TransactionFactory as a service
This commit is contained in:
parent
4b130da83e
commit
7c5f2ae5db
|
@ -45,7 +45,7 @@ public class ExtendsTest extends UnitTestCase {
|
|||
cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" );
|
||||
cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" );
|
||||
|
||||
cfg.buildSessionFactory( getServiceRegistry() );
|
||||
cfg.buildSessionFactory( getServiceRegistry(cfg.getProperties()) );
|
||||
|
||||
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) );
|
||||
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) );
|
||||
|
@ -101,7 +101,7 @@ public class ExtendsTest extends UnitTestCase {
|
|||
);
|
||||
cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" );
|
||||
|
||||
cfg.buildSessionFactory( getServiceRegistry() );
|
||||
cfg.buildSessionFactory( getServiceRegistry( cfg.getProperties() ) );
|
||||
|
||||
fail( "Should not be able to build sessionfactory without a Person" );
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ public class ExtendsTest extends UnitTestCase {
|
|||
try {
|
||||
cfg.addResource( getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml" );
|
||||
|
||||
cfg.buildSessionFactory( getServiceRegistry() );
|
||||
cfg.buildSessionFactory( getServiceRegistry( cfg.getProperties() ) );
|
||||
|
||||
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) );
|
||||
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) );
|
||||
|
|
|
@ -27,7 +27,7 @@ public class MigrationTest extends UnitTestCase {
|
|||
v1cfg.addResource( resource1 );
|
||||
new SchemaExport( v1cfg ).execute( false, true, true, false );
|
||||
|
||||
SchemaUpdate v1schemaUpdate = new SchemaUpdate( getJdbcServices(), v1cfg );
|
||||
SchemaUpdate v1schemaUpdate = new SchemaUpdate( getJdbcServices( v1cfg.getProperties() ), v1cfg );
|
||||
v1schemaUpdate.execute( true, true );
|
||||
|
||||
assertEquals( 0, v1schemaUpdate.getExceptions().size() );
|
||||
|
@ -35,11 +35,11 @@ public class MigrationTest extends UnitTestCase {
|
|||
Configuration v2cfg = new Configuration();
|
||||
v2cfg.addResource( resource2 );
|
||||
|
||||
SchemaUpdate v2schemaUpdate = new SchemaUpdate( getJdbcServices(), v2cfg );
|
||||
SchemaUpdate v2schemaUpdate = new SchemaUpdate( getJdbcServices( v2cfg.getProperties() ), v2cfg );
|
||||
v2schemaUpdate.execute( true, true );
|
||||
assertEquals( 0, v2schemaUpdate.getExceptions().size() );
|
||||
|
||||
new SchemaExport( getJdbcServices(), v2cfg ).drop( false, true );
|
||||
new SchemaExport( getJdbcServices( v2cfg.getProperties() ), v2cfg ).drop( false, true );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ public class StatsTest extends FunctionalTestCase {
|
|||
Collection coll = getCfg().getCollectionMapping(Continent.class.getName() + ".countries");
|
||||
coll.setFetchMode(FetchMode.JOIN);
|
||||
coll.setLazy(false);
|
||||
SessionFactory sf = getCfg().buildSessionFactory( getServiceRegistry() );
|
||||
SessionFactory sf = getCfg().buildSessionFactory( getServiceRegistry( getCfg().getProperties()) );
|
||||
stats = sf.getStatistics();
|
||||
stats.clear();
|
||||
stats.setStatisticsEnabled(true);
|
||||
|
@ -105,7 +105,7 @@ public class StatsTest extends FunctionalTestCase {
|
|||
coll = getCfg().getCollectionMapping(Continent.class.getName() + ".countries");
|
||||
coll.setFetchMode(FetchMode.SELECT);
|
||||
coll.setLazy(false);
|
||||
sf = getCfg().buildSessionFactory( getServiceRegistry() );
|
||||
sf = getCfg().buildSessionFactory( getServiceRegistry( getCfg().getProperties() ) );
|
||||
stats = sf.getStatistics();
|
||||
stats.clear();
|
||||
stats.setStatisticsEnabled(true);
|
||||
|
|
|
@ -26,11 +26,14 @@ package org.hibernate.testing.junit;
|
|||
import static org.hibernate.TestLogger.LOG;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.TestLogger;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
|
@ -48,6 +51,7 @@ import org.jboss.logging.Logger;
|
|||
public abstract class UnitTestCase extends junit.framework.TestCase {
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private Properties serviceRegistryProperties;
|
||||
|
||||
public UnitTestCase(String string) {
|
||||
super( string );
|
||||
|
@ -93,19 +97,19 @@ public abstract class UnitTestCase extends junit.framework.TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
protected ServiceRegistry getServiceRegistry() {
|
||||
protected ServiceRegistry getServiceRegistry(Properties properties) {
|
||||
if ( serviceRegistry == null ) {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
serviceRegistryProperties = properties;
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( properties );
|
||||
}
|
||||
else if ( ! properties.equals( serviceRegistryProperties ) ) {
|
||||
throw new AssertionFailure( "ServiceRegistry was already build using different properties." );
|
||||
}
|
||||
return serviceRegistry;
|
||||
}
|
||||
|
||||
protected JdbcServices getJdbcServices() {
|
||||
return getServiceRegistry().getService( JdbcServices.class );
|
||||
}
|
||||
|
||||
protected ConnectionProvider getConnectionProvider() {
|
||||
return getJdbcServices().getConnectionProvider();
|
||||
protected JdbcServices getJdbcServices(Properties properties) {
|
||||
return getServiceRegistry( properties ).getService( JdbcServices.class );
|
||||
}
|
||||
|
||||
private static class FailureExpectedTestPassedException extends Exception {
|
||||
|
|
|
@ -73,7 +73,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
|||
private void evictOrRemoveTest() throws Exception {
|
||||
Configuration cfg = createConfiguration();
|
||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
||||
getServiceRegistry(), cfg, getCacheTestSupport()
|
||||
getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
|
||||
);
|
||||
CacheAdapter localCache = getInfinispanCache(regionFactory);
|
||||
boolean invalidation = localCache.isClusteredInvalidation();
|
||||
|
@ -86,7 +86,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
|||
|
||||
cfg = createConfiguration();
|
||||
regionFactory = CacheTestUtil.startRegionFactory(
|
||||
getServiceRegistry(), cfg, getCacheTestSupport()
|
||||
getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
|
||||
);
|
||||
|
||||
GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory,
|
||||
|
@ -126,7 +126,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
|||
private void evictOrRemoveAllTest(String configName) throws Exception {
|
||||
Configuration cfg = createConfiguration();
|
||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
||||
getServiceRegistry(), cfg, getCacheTestSupport()
|
||||
getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
|
||||
);
|
||||
CacheAdapter localCache = getInfinispanCache(regionFactory);
|
||||
|
||||
|
@ -138,7 +138,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
|||
|
||||
cfg = createConfiguration();
|
||||
regionFactory = CacheTestUtil.startRegionFactory(
|
||||
getServiceRegistry(), cfg, getCacheTestSupport()
|
||||
getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
|
||||
);
|
||||
CacheAdapter remoteCache = getInfinispanCache(regionFactory);
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase
|
|||
if (getCollectionAccessStrategy() == null) {
|
||||
Configuration cfg = createConfiguration();
|
||||
InfinispanRegionFactory rf = CacheTestUtil.startRegionFactory(
|
||||
getServiceRegistry(), cfg, getCacheTestSupport()
|
||||
getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
|
||||
);
|
||||
|
||||
// Sleep a bit to avoid concurrent FLUSH problem
|
||||
|
|
|
@ -60,7 +60,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase
|
|||
if (getEntityAccessStrategy() == null) {
|
||||
Configuration cfg = createConfiguration();
|
||||
InfinispanRegionFactory rf = CacheTestUtil.startRegionFactory(
|
||||
getServiceRegistry(), cfg, getCacheTestSupport()
|
||||
getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
|
||||
);
|
||||
|
||||
// Sleep a bit to avoid concurrent FLUSH problem
|
||||
|
|
|
@ -92,7 +92,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
|
|||
|
||||
private void putDoesNotBlockGetTest() throws Exception {
|
||||
Configuration cfg = createConfiguration();
|
||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(getServiceRegistry(), cfg, getCacheTestSupport());
|
||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(getServiceRegistry(cfg.getProperties()), cfg, getCacheTestSupport());
|
||||
|
||||
// Sleep a bit to avoid concurrent FLUSH problem
|
||||
avoidConcurrentFlush();
|
||||
|
@ -177,7 +177,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
|
|||
|
||||
private void getDoesNotBlockPutTest() throws Exception {
|
||||
Configuration cfg = createConfiguration();
|
||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(getServiceRegistry(), cfg, getCacheTestSupport());
|
||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(getServiceRegistry(cfg.getProperties()), cfg, getCacheTestSupport());
|
||||
|
||||
// Sleep a bit to avoid concurrent FLUSH problem
|
||||
avoidConcurrentFlush();
|
||||
|
|
|
@ -81,14 +81,14 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
|
|||
public void testClearTimestampsRegionInIsolated() throws Exception {
|
||||
Configuration cfg = createConfiguration();
|
||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
||||
getServiceRegistry(), cfg, getCacheTestSupport()
|
||||
getServiceRegistry(cfg.getProperties()), cfg, getCacheTestSupport()
|
||||
);
|
||||
// Sleep a bit to avoid concurrent FLUSH problem
|
||||
avoidConcurrentFlush();
|
||||
|
||||
Configuration cfg2 = createConfiguration();
|
||||
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(
|
||||
getServiceRegistry(), cfg2, getCacheTestSupport()
|
||||
getServiceRegistry(cfg2.getProperties()), cfg2, getCacheTestSupport()
|
||||
);
|
||||
// Sleep a bit to avoid concurrent FLUSH problem
|
||||
avoidConcurrentFlush();
|
||||
|
|
Loading…
Reference in New Issue