HHH-5949 : Migrate, complete and integrate TransactionFactory as a service

This commit is contained in:
Gail Badner 2011-03-09 15:12:30 -08:00
parent 4b130da83e
commit 7c5f2ae5db
9 changed files with 32 additions and 28 deletions

View File

@ -45,7 +45,7 @@ public class ExtendsTest extends UnitTestCase {
cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" ); cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" );
cfg.addResource( getBaseForMappings() + "extendshbm/Employee.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.Customer" ) );
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); 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.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" ); fail( "Should not be able to build sessionfactory without a Person" );
} }
@ -117,7 +117,7 @@ public class ExtendsTest extends UnitTestCase {
try { try {
cfg.addResource( getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml" ); 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.Customer" ) );
assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) );

View File

@ -27,7 +27,7 @@ public class MigrationTest extends UnitTestCase {
v1cfg.addResource( resource1 ); v1cfg.addResource( resource1 );
new SchemaExport( v1cfg ).execute( false, true, true, false ); 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 ); v1schemaUpdate.execute( true, true );
assertEquals( 0, v1schemaUpdate.getExceptions().size() ); assertEquals( 0, v1schemaUpdate.getExceptions().size() );
@ -35,11 +35,11 @@ public class MigrationTest extends UnitTestCase {
Configuration v2cfg = new Configuration(); Configuration v2cfg = new Configuration();
v2cfg.addResource( resource2 ); v2cfg.addResource( resource2 );
SchemaUpdate v2schemaUpdate = new SchemaUpdate( getJdbcServices(), v2cfg ); SchemaUpdate v2schemaUpdate = new SchemaUpdate( getJdbcServices( v2cfg.getProperties() ), v2cfg );
v2schemaUpdate.execute( true, true ); v2schemaUpdate.execute( true, true );
assertEquals( 0, v2schemaUpdate.getExceptions().size() ); assertEquals( 0, v2schemaUpdate.getExceptions().size() );
new SchemaExport( getJdbcServices(), v2cfg ).drop( false, true ); new SchemaExport( getJdbcServices( v2cfg.getProperties() ), v2cfg ).drop( false, true );
} }

View File

@ -83,7 +83,7 @@ public class StatsTest extends FunctionalTestCase {
Collection coll = getCfg().getCollectionMapping(Continent.class.getName() + ".countries"); Collection coll = getCfg().getCollectionMapping(Continent.class.getName() + ".countries");
coll.setFetchMode(FetchMode.JOIN); coll.setFetchMode(FetchMode.JOIN);
coll.setLazy(false); coll.setLazy(false);
SessionFactory sf = getCfg().buildSessionFactory( getServiceRegistry() ); SessionFactory sf = getCfg().buildSessionFactory( getServiceRegistry( getCfg().getProperties()) );
stats = sf.getStatistics(); stats = sf.getStatistics();
stats.clear(); stats.clear();
stats.setStatisticsEnabled(true); stats.setStatisticsEnabled(true);
@ -105,7 +105,7 @@ public class StatsTest extends FunctionalTestCase {
coll = getCfg().getCollectionMapping(Continent.class.getName() + ".countries"); coll = getCfg().getCollectionMapping(Continent.class.getName() + ".countries");
coll.setFetchMode(FetchMode.SELECT); coll.setFetchMode(FetchMode.SELECT);
coll.setLazy(false); coll.setLazy(false);
sf = getCfg().buildSessionFactory( getServiceRegistry() ); sf = getCfg().buildSessionFactory( getServiceRegistry( getCfg().getProperties() ) );
stats = sf.getStatistics(); stats = sf.getStatistics();
stats.clear(); stats.clear();
stats.setStatisticsEnabled(true); stats.setStatisticsEnabled(true);

View File

@ -20,17 +20,20 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.testing.junit; package org.hibernate.testing.junit;
import static org.hibernate.TestLogger.LOG; import static org.hibernate.TestLogger.LOG;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.hibernate.AssertionFailure;
import org.hibernate.TestLogger; import org.hibernate.TestLogger;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
@ -48,6 +51,7 @@ import org.jboss.logging.Logger;
public abstract class UnitTestCase extends junit.framework.TestCase { public abstract class UnitTestCase extends junit.framework.TestCase {
private ServiceRegistry serviceRegistry; private ServiceRegistry serviceRegistry;
private Properties serviceRegistryProperties;
public UnitTestCase(String string) { public UnitTestCase(String string) {
super( 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 ) { 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; return serviceRegistry;
} }
protected JdbcServices getJdbcServices() { protected JdbcServices getJdbcServices(Properties properties) {
return getServiceRegistry().getService( JdbcServices.class ); return getServiceRegistry( properties ).getService( JdbcServices.class );
}
protected ConnectionProvider getConnectionProvider() {
return getJdbcServices().getConnectionProvider();
} }
private static class FailureExpectedTestPassedException extends Exception { private static class FailureExpectedTestPassedException extends Exception {

View File

@ -73,7 +73,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveTest() throws Exception { private void evictOrRemoveTest() throws Exception {
Configuration cfg = createConfiguration(); Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
getServiceRegistry(), cfg, getCacheTestSupport() getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
); );
CacheAdapter localCache = getInfinispanCache(regionFactory); CacheAdapter localCache = getInfinispanCache(regionFactory);
boolean invalidation = localCache.isClusteredInvalidation(); boolean invalidation = localCache.isClusteredInvalidation();
@ -86,7 +86,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg = createConfiguration(); cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory( regionFactory = CacheTestUtil.startRegionFactory(
getServiceRegistry(), cfg, getCacheTestSupport() getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
); );
GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory, GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory,
@ -126,7 +126,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveAllTest(String configName) throws Exception { private void evictOrRemoveAllTest(String configName) throws Exception {
Configuration cfg = createConfiguration(); Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
getServiceRegistry(), cfg, getCacheTestSupport() getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
); );
CacheAdapter localCache = getInfinispanCache(regionFactory); CacheAdapter localCache = getInfinispanCache(regionFactory);
@ -138,7 +138,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg = createConfiguration(); cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory( regionFactory = CacheTestUtil.startRegionFactory(
getServiceRegistry(), cfg, getCacheTestSupport() getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
); );
CacheAdapter remoteCache = getInfinispanCache(regionFactory); CacheAdapter remoteCache = getInfinispanCache(regionFactory);

View File

@ -54,7 +54,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase
if (getCollectionAccessStrategy() == null) { if (getCollectionAccessStrategy() == null) {
Configuration cfg = createConfiguration(); Configuration cfg = createConfiguration();
InfinispanRegionFactory rf = CacheTestUtil.startRegionFactory( InfinispanRegionFactory rf = CacheTestUtil.startRegionFactory(
getServiceRegistry(), cfg, getCacheTestSupport() getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
); );
// Sleep a bit to avoid concurrent FLUSH problem // Sleep a bit to avoid concurrent FLUSH problem

View File

@ -60,7 +60,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase
if (getEntityAccessStrategy() == null) { if (getEntityAccessStrategy() == null) {
Configuration cfg = createConfiguration(); Configuration cfg = createConfiguration();
InfinispanRegionFactory rf = CacheTestUtil.startRegionFactory( InfinispanRegionFactory rf = CacheTestUtil.startRegionFactory(
getServiceRegistry(), cfg, getCacheTestSupport() getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport()
); );
// Sleep a bit to avoid concurrent FLUSH problem // Sleep a bit to avoid concurrent FLUSH problem

View File

@ -92,7 +92,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
private void putDoesNotBlockGetTest() throws Exception { private void putDoesNotBlockGetTest() throws Exception {
Configuration cfg = createConfiguration(); 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 // Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush(); avoidConcurrentFlush();
@ -177,7 +177,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
private void getDoesNotBlockPutTest() throws Exception { private void getDoesNotBlockPutTest() throws Exception {
Configuration cfg = createConfiguration(); 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 // Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush(); avoidConcurrentFlush();

View File

@ -81,14 +81,14 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
public void testClearTimestampsRegionInIsolated() throws Exception { public void testClearTimestampsRegionInIsolated() throws Exception {
Configuration cfg = createConfiguration(); Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
getServiceRegistry(), cfg, getCacheTestSupport() getServiceRegistry(cfg.getProperties()), cfg, getCacheTestSupport()
); );
// Sleep a bit to avoid concurrent FLUSH problem // Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush(); avoidConcurrentFlush();
Configuration cfg2 = createConfiguration(); Configuration cfg2 = createConfiguration();
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory( InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(
getServiceRegistry(), cfg2, getCacheTestSupport() getServiceRegistry(cfg2.getProperties()), cfg2, getCacheTestSupport()
); );
// Sleep a bit to avoid concurrent FLUSH problem // Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush(); avoidConcurrentFlush();