diff --git a/documentation/src/test/java/org/hibernate/userguide/multitenancy/AbstractMultiTenancyTest.java b/documentation/src/test/java/org/hibernate/userguide/multitenancy/AbstractMultiTenancyTest.java index dd63d3bc1a..d4bd94e194 100644 --- a/documentation/src/test/java/org/hibernate/userguide/multitenancy/AbstractMultiTenancyTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/multitenancy/AbstractMultiTenancyTest.java @@ -30,12 +30,14 @@ import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionPro import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.spi.SqlStatementLogger; import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.hibernate.service.spi.Stoppable; import org.hibernate.tool.schema.internal.HibernateSchemaManagementTool; import org.hibernate.tool.schema.internal.SchemaCreatorImpl; import org.hibernate.tool.schema.internal.SchemaDropperImpl; import org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase; import org.hibernate.tool.schema.internal.exec.JdbcConnectionContextNonSharedImpl; +import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.boot.JdbcConnectionAccessImpl; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; @@ -71,6 +73,16 @@ public abstract class AbstractMultiTenancyTest extends BaseUnitTestCase { } //end::multitenacy-hibernate-MultiTenantConnectionProvider-example[] + @AfterClassOnce + public void destroy() { + sessionFactory.close(); + for ( ConnectionProvider connectionProvider : connectionProviderMap.values() ) { + if ( connectionProvider instanceof Stoppable ) { + ( (Stoppable) connectionProvider ).stop(); + } + } + } + //tag::multitenacy-hibernate-MultiTenantConnectionProvider-example[] protected void registerConnectionProvider(String tenantIdentifier) { diff --git a/documentation/src/test/java/org/hibernate/userguide/transactions/TransactionsTest.java b/documentation/src/test/java/org/hibernate/userguide/transactions/TransactionsTest.java index f564d26fbc..6050861d55 100644 --- a/documentation/src/test/java/org/hibernate/userguide/transactions/TransactionsTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/transactions/TransactionsTest.java @@ -74,6 +74,7 @@ public class TransactionsTest extends BaseEntityManagerFunctionalTestCase { } finally { session.close(); + sessionFactory.close(); } //end::transactions-api-jdbc-example[] } @@ -123,6 +124,7 @@ public class TransactionsTest extends BaseEntityManagerFunctionalTestCase { } finally { session.close(); + sessionFactory.close(); } //end::transactions-api-cmt-example[] } @@ -176,6 +178,7 @@ public class TransactionsTest extends BaseEntityManagerFunctionalTestCase { } finally { session.close(); + sessionFactory.close(); } //end::transactions-api-bmt-example[] } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java index 59e497392f..8b797a08ed 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java @@ -30,61 +30,76 @@ import static org.junit.Assert.assertTrue; */ public class C3P0ConnectionProviderTest extends BaseCoreFunctionalTestCase { - @Test - public void testC3P0isDefaultWhenThereIsC3P0Properties() { - JdbcServices jdbcServices = serviceRegistry().getService( JdbcServices.class ); - ConnectionProviderJdbcConnectionAccess connectionAccess = - assertTyping( - ConnectionProviderJdbcConnectionAccess.class, - jdbcServices.getBootstrapJdbcConnectionAccess() + @Override + protected void releaseSessionFactory() { + super.releaseSessionFactory(); + try { + //c3p0 does not close physical connections right away, so without this hack a connection leak false alarm is triggered. + Thread.sleep( 100 ); + } + catch ( InterruptedException e ) { + } + } + + @Test + public void testC3P0isDefaultWhenThereIsC3P0Properties() { + JdbcServices jdbcServices = serviceRegistry().getService( JdbcServices.class ); + ConnectionProviderJdbcConnectionAccess connectionAccess = + assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider() instanceof C3P0ConnectionProvider ); + } + + @Test + public void testHHH6635() throws Exception { + MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); + Set set = mBeanServer.queryNames( null, null ); + boolean mbeanfound = false; + for ( ObjectName obj : set ) { + if ( obj.getKeyPropertyListString().indexOf( "PooledDataSource" ) > 0 ) { + mbeanfound = true; + + // see according c3p0 settings in META-INF/persistence.xml + + int actual_minPoolSize = (Integer) mBeanServer.getAttribute( obj, "minPoolSize" ); + assertEquals( 50, actual_minPoolSize ); + + int actual_initialPoolSize = (Integer) mBeanServer.getAttribute( obj, "initialPoolSize" ); + assertEquals( 50, actual_initialPoolSize ); + + int actual_maxPoolSize = (Integer) mBeanServer.getAttribute( obj, "maxPoolSize" ); + assertEquals( 800, actual_maxPoolSize ); + + int actual_maxStatements = (Integer) mBeanServer.getAttribute( obj, "maxStatements" ); + assertEquals( 50, actual_maxStatements ); + + int actual_maxIdleTime = (Integer) mBeanServer.getAttribute( obj, "maxIdleTime" ); + assertEquals( 300, actual_maxIdleTime ); + + int actual_idleConnectionTestPeriod = (Integer) mBeanServer.getAttribute( + obj, + "idleConnectionTestPeriod" ); - assertTrue( connectionAccess.getConnectionProvider() instanceof C3P0ConnectionProvider ); + assertEquals( 3000, actual_idleConnectionTestPeriod ); + break; + } + } - } + assertTrue( "PooledDataSource BMean not found, please verify version of c3p0", mbeanfound ); + } - @Test - public void testHHH6635() throws Exception { - MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); - Set set = mBeanServer.queryNames( null, null ); - boolean mbeanfound = false; - for ( ObjectName obj : set ) { - if ( obj.getKeyPropertyListString().indexOf( "PooledDataSource" ) > 0 ) { - mbeanfound = true; - - // see according c3p0 settings in META-INF/persistence.xml - - int actual_minPoolSize = (Integer) mBeanServer.getAttribute( obj, "minPoolSize" ); - assertEquals( 50, actual_minPoolSize ); - - int actual_initialPoolSize = (Integer) mBeanServer.getAttribute( obj, "initialPoolSize" ); - assertEquals( 50, actual_initialPoolSize ); - - int actual_maxPoolSize = (Integer) mBeanServer.getAttribute( obj, "maxPoolSize" ); - assertEquals( 800, actual_maxPoolSize ); - - int actual_maxStatements = (Integer) mBeanServer.getAttribute( obj, "maxStatements" ); - assertEquals( 50, actual_maxStatements ); - - int actual_maxIdleTime = (Integer) mBeanServer.getAttribute( obj, "maxIdleTime" ); - assertEquals( 300, actual_maxIdleTime ); - - int actual_idleConnectionTestPeriod = (Integer) mBeanServer.getAttribute( - obj, - "idleConnectionTestPeriod" - ); - assertEquals( 3000, actual_idleConnectionTestPeriod ); - break; - } - } - - assertTrue( "PooledDataSource BMean not found, please verify version of c3p0", mbeanfound ); - } - - @Test @TestForIssue(jiraKey="HHH-9498") - public void testIsolationPropertyCouldBeEmpty() { - Properties configuration = new Properties(); - configuration.setProperty( Environment.ISOLATION, "" ); - C3P0ConnectionProvider provider = new C3P0ConnectionProvider(); - provider.configure( configuration ); - } + @Test @TestForIssue(jiraKey="HHH-9498") + public void testIsolationPropertyCouldBeEmpty() { + C3P0ConnectionProvider provider = new C3P0ConnectionProvider(); + try { + Properties configuration = new Properties(); + configuration.setProperty( Environment.ISOLATION, "" ); + provider.configure( configuration ); + } + finally { + provider.stop(); + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/BootstrapServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/BootstrapServiceRegistryImpl.java index 94640a1066..1544571434 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/BootstrapServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/BootstrapServiceRegistryImpl.java @@ -214,6 +214,15 @@ public class BootstrapServiceRegistryImpl destroy( classLoaderServiceBinding ); destroy( strategySelectorBinding ); destroy( integratorServiceBinding ); + + if ( childRegistries != null ) { + for(ServiceRegistry serviceRegistry : childRegistries) { + if(serviceRegistry instanceof ServiceRegistryImplementor) { + ServiceRegistryImplementor serviceRegistryImplementor = (ServiceRegistryImplementor) serviceRegistry; + serviceRegistryImplementor.destroy(); + } + } + } } private void destroy(ServiceBinding serviceBinding) { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 3084440fbc..e45bf55d71 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -271,13 +271,12 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { } final IntegratorObserver integratorObserver = new IntegratorObserver(); this.observer.addObserver( integratorObserver ); - for ( Integrator integrator : serviceRegistry.getService( IntegratorService.class ).getIntegrators() ) { - integrator.integrate( metadata, this, this.serviceRegistry ); - integratorObserver.integrators.add( integrator ); - } try { + for ( Integrator integrator : serviceRegistry.getService( IntegratorService.class ).getIntegrators() ) { + integrator.integrate( metadata, this, this.serviceRegistry ); + integratorObserver.integrators.add( integrator ); + } //Generators: - this.identifierGenerators = new HashMap<>(); metadata.getEntityBindings().stream().filter( model -> !model.isInherited() ).forEach( model -> { IdentifierGenerator generator = model.getIdentifier().createIdentifierGenerator( @@ -377,6 +376,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { integrator.disintegrate( this, serviceRegistry ); integratorObserver.integrators.remove( integrator ); } + serviceRegistry.destroy(); throw e; } } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/NoCdiAvailableTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/NoCdiAvailableTest.java index 2808cbc347..541c7c2255 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/NoCdiAvailableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/NoCdiAvailableTest.java @@ -82,18 +82,12 @@ public class NoCdiAvailableTest extends BaseUnitTestCase { "org.hibernate.jpa.test.cdi.NoCdiAvailableTestDelegate" ); Method mainMethod = delegateClass.getMethod( "passingBeanManager" ); - EntityManagerFactory entityManagerFactory = null; try { - entityManagerFactory = (EntityManagerFactory) mainMethod.invoke( null ); + mainMethod.invoke( null ); fail( "Expecting failure from missing CDI classes" ); } catch (InvocationTargetException expected) { // hard to assert specific exception types due to classloader trickery } - finally { - if (entityManagerFactory != null ) { - entityManagerFactory.close(); - } - } } } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/NoCdiAvailableTestDelegate.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/NoCdiAvailableTestDelegate.java index 2dc8336cb9..e320feecd1 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/NoCdiAvailableTestDelegate.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/NoCdiAvailableTestDelegate.java @@ -8,6 +8,8 @@ package org.hibernate.jpa.test.cdi; import java.util.Collections; +import javax.persistence.EntityManagerFactory; + import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.HibernatePersistenceProvider; import org.hibernate.jpa.test.PersistenceUnitInfoAdapter; @@ -16,8 +18,8 @@ import org.hibernate.jpa.test.PersistenceUnitInfoAdapter; * @author Steve Ebersole */ public class NoCdiAvailableTestDelegate { - public static void passingNoBeanManager() { - new HibernatePersistenceProvider().createContainerEntityManagerFactory( + public static EntityManagerFactory passingNoBeanManager() { + return new HibernatePersistenceProvider().createContainerEntityManagerFactory( new PersistenceUnitInfoAdapter(), Collections.emptyMap() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java index 3dc3bac046..cb0dd61ebb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java @@ -6,7 +6,6 @@ */ package org.hibernate.test.annotations.entity; -import javax.persistence.OptimisticLockException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Currency; @@ -16,6 +15,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Set; +import javax.persistence.OptimisticLockException; import org.hibernate.AnnotationException; import org.hibernate.Hibernate; @@ -23,6 +23,7 @@ import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; +import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.cfg.Configuration; import org.hibernate.dialect.TeradataDialect; @@ -709,19 +710,26 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase { @Test public void testTypeDefWithoutNameAndDefaultForTypeAttributes() { - SessionFactory sf=null; + SessionFactory sf = null; + StandardServiceRegistryImpl ssr = null; try { Configuration config = new Configuration(); - config.addAnnotatedClass(LocalContactDetails.class); - sf = config.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ) ); - fail("Did not throw expected exception"); + config.addAnnotatedClass( LocalContactDetails.class ); + ssr = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ); + sf = config.buildSessionFactory( ssr ); + fail( "Did not throw expected exception" ); } - catch( AnnotationException ex ) { + catch ( AnnotationException ex ) { assertEquals( - "Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass org.hibernate.test.annotations.entity.PhoneNumberType", - ex.getMessage()); - } finally { - if( sf != null){ + "Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass org.hibernate.test.annotations.entity.PhoneNumberType", + ex.getMessage() + ); + } + finally { + if ( ssr != null ) { + ssr.destroy(); + } + if ( sf != null ) { sf.close(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java index 567fb6699e..8bead575f6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java @@ -10,6 +10,8 @@ import java.io.InputStream; import org.hibernate.MappingException; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -85,6 +87,12 @@ public class FetchProfileTest extends BaseUnitTestCase { catch ( MappingException e ) { log.trace("success"); } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Test @@ -101,6 +109,12 @@ public class FetchProfileTest extends BaseUnitTestCase { catch ( MappingException e ) { log.trace("success"); } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Test @@ -117,6 +131,12 @@ public class FetchProfileTest extends BaseUnitTestCase { catch ( MappingException e ) { log.trace("success"); } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Test @@ -152,6 +172,12 @@ public class FetchProfileTest extends BaseUnitTestCase { catch ( MappingException e ) { log.trace("success"); } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java index 839a1a5429..9cf83bfe06 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java @@ -9,38 +9,53 @@ package org.hibernate.test.annotations.fkcircularity; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; -import org.jboss.logging.Logger; - /** * Test case for ANN-722 and ANN-730. * * @author Hardy Ferentschik */ public class FkCircularityTest extends BaseUnitTestCase { - private static final Logger log = Logger.getLogger( FkCircularityTest.class ); - @Test public void testJoinedSublcassesInPK() { - new MetadataSources() - .addAnnotatedClass(A.class) - .addAnnotatedClass(B.class) - .addAnnotatedClass(C.class) - .addAnnotatedClass(D.class) - .buildMetadata(); + MetadataSources metadataSources = new MetadataSources() + .addAnnotatedClass(A.class) + .addAnnotatedClass(B.class) + .addAnnotatedClass(C.class) + .addAnnotatedClass(D.class); + try { + metadataSources.buildMetadata(); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Test public void testDeepJoinedSuclassesHierachy() { - new MetadataSources() + MetadataSources metadataSources = new MetadataSources() .addAnnotatedClass(ClassA.class) .addAnnotatedClass(ClassB.class) .addAnnotatedClass(ClassC.class) - .addAnnotatedClass(ClassD.class) - .buildMetadata(); + .addAnnotatedClass(ClassD.class); + try { + metadataSources.buildMetadata(); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java index dcd0907227..86580a60a8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java @@ -6,16 +6,18 @@ */ package org.hibernate.test.annotations.immutable; -import javax.persistence.PersistenceException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.persistence.PersistenceException; import org.hibernate.AnnotationException; -import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -222,12 +224,19 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase { @Test public void testMisplacedImmutableAnnotation() { + MetadataSources metadataSources = new MetadataSources().addAnnotatedClass( Foobar.class ); try { - new MetadataSources().addAnnotatedClass( Foobar.class ).buildMetadata(); + metadataSources.buildMetadata(); fail( "Expecting exception due to misplaced @Immutable annotation"); } catch (AnnotationException ignore) { } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java index 031a6e2640..03658267dd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/OrmVersion1SupportedTest.java @@ -38,9 +38,6 @@ public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase { public void testOrm1Support() { Triggerable triggerable = logInspection.watchForLogMessages( "HHH00196" ); - // need to call buildSessionFactory, because this test is not using org.hibernate.testing.junit4.CustomRunner - buildSessionFactory(); - Session s = openSession(); Transaction tx = s.beginTransaction(); Light light = new Light(); @@ -54,9 +51,6 @@ public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase { s.close(); assertFalse( triggerable.wasTriggered() ); - - // which means we also need to close it manually - releaseSessionFactory(); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/access/MixedAccessTestTask.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/access/MixedAccessTestTask.java index 4c26e708d7..5a0d1c7730 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/access/MixedAccessTestTask.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/access/MixedAccessTestTask.java @@ -1,11 +1,8 @@ package org.hibernate.test.bytecode.enhancement.access; -import org.hibernate.Session; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; -import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask; -import org.junit.Assert; - +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; import javax.persistence.Access; import javax.persistence.AccessType; import javax.persistence.Column; @@ -15,9 +12,13 @@ import javax.persistence.Transient; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.stream.Collectors; + +import org.hibernate.Session; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; + +import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask; +import org.junit.Assert; /** * @author Luis Barreiro @@ -40,52 +41,73 @@ public class MixedAccessTestTask extends AbstractEnhancerTestTask { Session s = getFactory().openSession(); s.beginTransaction(); - TestEntity testEntity = new TestEntity( "foo" ); - testEntity.setParamsAsString( "{\"paramName\":\"paramValue\"}" ); - s.persist( testEntity ); + try { + TestEntity testEntity = new TestEntity( "foo" ); + testEntity.setParamsAsString( "{\"paramName\":\"paramValue\"}" ); + s.persist( testEntity ); - TestOtherEntity testOtherEntity = new TestOtherEntity( "foo" ); - testOtherEntity.setParamsAsString( "{\"paramName\":\"paramValue\"}" ); - s.persist( testOtherEntity ); + TestOtherEntity testOtherEntity = new TestOtherEntity( "foo" ); + testOtherEntity.setParamsAsString( "{\"paramName\":\"paramValue\"}" ); + s.persist( testOtherEntity ); - s.getTransaction().commit(); - s.clear(); - s.close(); + s.getTransaction().commit(); + } + catch ( Exception e ) { + s.getTransaction().rollback(); + throw e; + } + finally { + s.close(); + } } public void execute() { Session s = getFactory().openSession(); s.beginTransaction(); - TestEntity testEntity = s.get( TestEntity.class, "foo" ); - Assert.assertEquals( "{\"paramName\":\"paramValue\"}", testEntity.getParamsAsString() ); + try { + TestEntity testEntity = s.get( TestEntity.class, "foo" ); + Assert.assertEquals( "{\"paramName\":\"paramValue\"}", testEntity.getParamsAsString() ); - TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, "foo" ); - Assert.assertEquals( "{\"paramName\":\"paramValue\"}", testOtherEntity.getParamsAsString() ); + TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, "foo" ); + Assert.assertEquals( "{\"paramName\":\"paramValue\"}", testOtherEntity.getParamsAsString() ); - // Clean parameters - cleanup = true; - testEntity.setParamsAsString( "{}" ); - testOtherEntity.setParamsAsString( "{}" ); + // Clean parameters + cleanup = true; + testEntity.setParamsAsString( "{}" ); + testOtherEntity.setParamsAsString( "{}" ); - s.getTransaction().commit(); - s.clear(); - s.close(); + s.getTransaction().commit(); + } + catch ( RuntimeException e ) { + s.getTransaction().rollback(); + throw e; + } + finally { + s.close(); + } } protected void cleanup() { Session s = getFactory().openSession(); s.beginTransaction(); - TestEntity testEntity = s.get( TestEntity.class, "foo" ); - Assert.assertTrue( testEntity.getParams().isEmpty() ); + try { + TestEntity testEntity = s.get( TestEntity.class, "foo" ); + Assert.assertTrue( testEntity.getParams().isEmpty() ); - TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, "foo" ); - Assert.assertTrue( testOtherEntity.getParams().isEmpty() ); + TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, "foo" ); + Assert.assertTrue( testOtherEntity.getParams().isEmpty() ); - s.getTransaction().commit(); - s.clear(); - s.close(); + s.getTransaction().commit(); + } + catch ( RuntimeException e ) { + s.getTransaction().rollback(); + throw e; + } + finally { + s.close(); + } } @Entity diff --git a/hibernate-core/src/test/java/org/hibernate/test/connections/SuppliedConnectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/connections/SuppliedConnectionTest.java index f9b886f5f9..16e440b8fb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/connections/SuppliedConnectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/connections/SuppliedConnectionTest.java @@ -38,7 +38,7 @@ import org.hibernate.testing.env.ConnectionProviderBuilder; */ @RequiresDialect(H2Dialect.class) public class SuppliedConnectionTest extends ConnectionManagementTestCase { - private ConnectionProvider cp = ConnectionProviderBuilder.buildConnectionProvider(); + private ConnectionProvider cp; private Connection connectionUnderTest; @BeforeClassOnce diff --git a/hibernate-core/src/test/java/org/hibernate/test/entitymode/dom4j/DeprecationLoggingTest.java b/hibernate-core/src/test/java/org/hibernate/test/entitymode/dom4j/DeprecationLoggingTest.java index dfe51dd742..bedc6722a8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/entitymode/dom4j/DeprecationLoggingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/entitymode/dom4j/DeprecationLoggingTest.java @@ -7,7 +7,10 @@ package org.hibernate.test.entitymode.dom4j; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.internal.log.DeprecationLogger; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.logger.LoggerInspectionRule; @@ -21,6 +24,7 @@ import org.junit.Test; * @author Steve Ebersole */ public class DeprecationLoggingTest extends BaseUnitTestCase { + @Rule public LoggerInspectionRule logInspection = new LoggerInspectionRule( DeprecationLogger.DEPRECATION_LOGGER ); @@ -28,7 +32,16 @@ public class DeprecationLoggingTest extends BaseUnitTestCase { public void basicTest() { logInspection.registerListener( LogListenerImpl.INSTANCE ); - new MetadataSources().addResource( "org/hibernate/test/entitymode/dom4j/Car.hbm.xml" ) - .buildMetadata(); + MetadataSources metadataSources = new MetadataSources() + .addResource( "org/hibernate/test/entitymode/dom4j/Car.hbm.xml" ); + try { + metadataSources.buildMetadata(); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/enums/InvalidEnumeratedJavaTypeTest.java b/hibernate-core/src/test/java/org/hibernate/test/enums/InvalidEnumeratedJavaTypeTest.java index 373d3e7f0e..26403c27fc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/enums/InvalidEnumeratedJavaTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/enums/InvalidEnumeratedJavaTypeTest.java @@ -12,6 +12,9 @@ import javax.persistence.Id; import org.hibernate.AnnotationException; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; @@ -24,14 +27,20 @@ import static org.junit.Assert.fail; public class InvalidEnumeratedJavaTypeTest extends BaseUnitTestCase { @Test public void testInvalidMapping() { + MetadataSources metadataSources = new MetadataSources( ) + .addAnnotatedClass( TheEntity.class ); try { - new MetadataSources( ) - .addAnnotatedClass( TheEntity.class ) - .buildMetadata(); + metadataSources.buildMetadata(); fail( "Was expecting failure" ); } catch (AnnotationException ignore) { } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Entity diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/query/NamedQueryTest.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/query/NamedQueryTest.java index 42553cc591..fa0b6a0f97 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hbm/query/NamedQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/query/NamedQueryTest.java @@ -2,6 +2,7 @@ package org.hibernate.test.hbm.query; import java.io.StringReader; +import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.engine.jdbc.ReaderInputStream; import org.hibernate.testing.TestForIssue; @@ -32,7 +33,8 @@ public class NamedQueryTest extends BaseUnitTestCase { Configuration cfg = new Configuration(); cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); cfg.addInputStream(new ReaderInputStream(new StringReader(NAMED_QUERY_HBM_XML))); - cfg.buildSessionFactory(); + SessionFactory sessionFactory = cfg.buildSessionFactory(); + sessionFactory.close(); } public class Bar { diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/query/QueryReturnTest.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/query/QueryReturnTest.java index 4fb063501c..e842672fe6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hbm/query/QueryReturnTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/query/QueryReturnTest.java @@ -4,11 +4,14 @@ import java.io.StringReader; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.engine.jdbc.ReaderInputStream; import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn; import org.hibernate.engine.spi.NamedSQLQueryDefinition; + import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Assert; @@ -42,19 +45,27 @@ public class QueryReturnTest extends BaseUnitTestCase { @Test public void testQueryReturn() { StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder() - .applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); - MetadataSources metadataSources = new MetadataSources(serviceRegistryBuilder.build()); - metadataSources.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML))); - Metadata metadata = metadataSources.buildMetadata(); - NamedSQLQueryDefinition myQuery = metadata.getNamedNativeQueryDefinition("myQuery"); - Assert.assertNotNull(myQuery); - NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns(); - Assert.assertNotNull(myQueryReturns); - Assert.assertEquals(1, myQueryReturns.length); - Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0])); - NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn)myQueryReturns[0]; - Assert.assertEquals("e", myQueryRootReturn.getAlias()); - Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName()); + .applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); + StandardServiceRegistry standardServiceRegistry = serviceRegistryBuilder.build(); + MetadataSources metadataSources = new MetadataSources(standardServiceRegistry); + try { + metadataSources.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML))); + Metadata metadata = metadataSources.buildMetadata(); + NamedSQLQueryDefinition myQuery = metadata.getNamedNativeQueryDefinition("myQuery"); + Assert.assertNotNull(myQuery); + NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns(); + Assert.assertNotNull(myQueryReturns); + Assert.assertEquals(1, myQueryReturns.length); + Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0])); + NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn)myQueryReturns[0]; + Assert.assertEquals("e", myQueryRootReturn.getAlias()); + Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName()); + } + finally { + if ( standardServiceRegistry instanceof StandardServiceRegistryImpl ) { + ( (StandardServiceRegistryImpl) standardServiceRegistry ).destroy(); + } + } } public class Bar { diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/version/GeneratedVersionBindingTest.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/version/GeneratedVersionBindingTest.java index eb0e1eb933..a16186993a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hbm/version/GeneratedVersionBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/version/GeneratedVersionBindingTest.java @@ -6,8 +6,10 @@ */ package org.hibernate.test.hbm.version; -import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; @@ -18,8 +20,17 @@ import org.junit.Test; public class GeneratedVersionBindingTest extends BaseUnitTestCase { @Test public void testIt() { - final Metadata metadata = new MetadataSources() - .addResource("org/hibernate/test/hbm/version/Mappings.hbm.xml") - .buildMetadata(); + MetadataSources metadataSources = new MetadataSources() + .addResource("org/hibernate/test/hbm/version/Mappings.hbm.xml"); + + try { + metadataSources.buildMetadata(); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/SessionJdbcBatchTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/SessionJdbcBatchTest.java index 97709688bc..790b07826b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/SessionJdbcBatchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/SessionJdbcBatchTest.java @@ -46,6 +46,12 @@ public class SessionJdbcBatchTest ); } + @Override + protected void releaseResources() { + super.releaseResources(); + connectionProvider.stop(); + } + @Override protected boolean rebuildSessionFactoryOnError() { return false; diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java index adc718b19f..2d9b442dec 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java @@ -29,8 +29,8 @@ import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Table; import org.hibernate.mapping.ValueVisitor; -import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl; +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -56,7 +56,9 @@ public class ValueVisitorTest extends BaseUnitTestCase { @Test public void testProperCallbacks() { - final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources().buildMetadata(); + final MetadataImplementor metadata = + (MetadataImplementor) new MetadataSources( serviceRegistry ) + .buildMetadata(); final Table tbl = new Table(); final RootClass rootClass = new RootClass( metadataBuildingContext ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/collectionJoinTableNaming/CollectionJoinTableNamingTest.java b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/collectionJoinTableNaming/CollectionJoinTableNamingTest.java index 9456e10589..7a6ab6fe3d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/collectionJoinTableNaming/CollectionJoinTableNamingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/collectionJoinTableNaming/CollectionJoinTableNamingTest.java @@ -42,8 +42,11 @@ import org.hibernate.boot.MetadataSources; import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl; import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl; import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; +import org.hibernate.service.ServiceRegistry; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.schema.TargetType; @@ -60,50 +63,75 @@ import static org.junit.Assert.assertSame; * @author Alessandro Polverini */ public class CollectionJoinTableNamingTest extends BaseUnitTestCase { + @Test @TestForIssue( jiraKey = "HHH-9908" ) public void testCollectionJoinTableNamingBase() { // really the same as the JPA compliant tests; here we just pick up the default ImplicitNamingStrategy final MetadataSources metadataSources = new MetadataSources(); - metadataSources.addAnnotatedClass( Input.class ); - metadataSources.addAnnotatedClass( Ptx.class ); + try { + metadataSources.addAnnotatedClass( Input.class ); + metadataSources.addAnnotatedClass( Ptx.class ); - final Metadata metadata = metadataSources.getMetadataBuilder() - .build(); + final Metadata metadata = metadataSources.getMetadataBuilder() + .build(); - assertSameTableUsed( metadata ); + assertSameTableUsed( metadata ); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Test @TestForIssue( jiraKey = "HHH-9908" ) public void testCollectionJoinTableNamingLegacyJpaStrategy() { final MetadataSources metadataSources = new MetadataSources(); - metadataSources.addAnnotatedClass( Input.class ); - metadataSources.addAnnotatedClass( Ptx.class ); + try { + metadataSources.addAnnotatedClass( Input.class ); + metadataSources.addAnnotatedClass( Ptx.class ); - final Metadata metadata = metadataSources.getMetadataBuilder() - .applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ) - .build(); + final Metadata metadata = metadataSources.getMetadataBuilder() + .applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ) + .build(); - assertSameTableUsed( metadata ); + assertSameTableUsed( metadata ); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Test @TestForIssue( jiraKey = "HHH-9908" ) public void testCollectionJoinTableNamingLegacyHbmStrategy() { final MetadataSources metadataSources = new MetadataSources(); - metadataSources.addAnnotatedClass( Input.class ); - metadataSources.addAnnotatedClass( Ptx.class ); + try { + metadataSources.addAnnotatedClass( Input.class ); + metadataSources.addAnnotatedClass( Ptx.class ); - final Metadata metadata = metadataSources.getMetadataBuilder() - .applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyHbmImpl.INSTANCE ) - .build(); + final Metadata metadata = metadataSources.getMetadataBuilder() + .applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyHbmImpl.INSTANCE ) + .build(); - Collection inputs1Mapping = metadata.getCollectionBinding( Ptx.class.getName() + ".inputs1" ); - assertEquals( "ptx_inputs1", inputs1Mapping.getCollectionTable().getName() ); + Collection inputs1Mapping = metadata.getCollectionBinding( Ptx.class.getName() + ".inputs1" ); + assertEquals( "ptx_inputs1", inputs1Mapping.getCollectionTable().getName() ); - Collection inputs2Mapping = metadata.getCollectionBinding( Ptx.class.getName() + ".inputs2" ); - assertEquals( "ptx_inputs2", inputs2Mapping.getCollectionTable().getName() ); + Collection inputs2Mapping = metadata.getCollectionBinding( Ptx.class.getName() + ".inputs2" ); + assertEquals( "ptx_inputs2", inputs2Mapping.getCollectionTable().getName() ); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } @Test @@ -112,14 +140,22 @@ public class CollectionJoinTableNamingTest extends BaseUnitTestCase { // Even in 4.3, with JPA compliant naming, Hibernate creates an unusable table... final MetadataSources metadataSources = new MetadataSources(); - metadataSources.addAnnotatedClass( Input.class ); - metadataSources.addAnnotatedClass( Ptx.class ); + try { + metadataSources.addAnnotatedClass( Input.class ); + metadataSources.addAnnotatedClass( Ptx.class ); - final Metadata metadata = metadataSources.getMetadataBuilder() - .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) - .build(); + final Metadata metadata = metadataSources.getMetadataBuilder() + .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) + .build(); - assertSameTableUsed( metadata ); + assertSameTableUsed( metadata ); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } private void assertSameTableUsed(Metadata metadata) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/complete/BaseNamingTests.java b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/complete/BaseNamingTests.java index a9af7c7ced..650846767f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/complete/BaseNamingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/test/namingstrategy/complete/BaseNamingTests.java @@ -9,11 +9,14 @@ package org.hibernate.test.namingstrategy.complete; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.model.naming.ImplicitNamingStrategy; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; @@ -26,23 +29,32 @@ import static org.junit.Assert.assertNotNull; * @author Steve Ebersole */ public abstract class BaseNamingTests extends BaseUnitTestCase { + @Test public void doTest() { final MetadataSources metadataSources = new MetadataSources(); - applySources( metadataSources ); + try { + applySources( metadataSources ); - final Metadata metadata = metadataSources.getMetadataBuilder() - .applyImplicitNamingStrategy( getImplicitNamingStrategyToUse() ) - .build(); + final Metadata metadata = metadataSources.getMetadataBuilder() + .applyImplicitNamingStrategy( getImplicitNamingStrategyToUse() ) + .build(); - validateCustomer( metadata ); - validateOrder( metadata ); - validateZipCode( metadata ); + validateCustomer( metadata ); + validateOrder( metadata ); + validateZipCode( metadata ); - validateCustomerRegisteredTrademarks( metadata ); - validateCustomerAddresses( metadata ); - validateCustomerOrders( metadata ); - validateCustomerIndustries( metadata ); + validateCustomerRegisteredTrademarks( metadata ); + validateCustomerAddresses( metadata ); + validateCustomerOrders( metadata ); + validateCustomerIndustries( metadata ); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } protected abstract void applySources(MetadataSources metadataSources); diff --git a/hibernate-core/src/test/java/org/hibernate/test/naturalid/inheritance/spread/SpreadNaturalIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/naturalid/inheritance/spread/SpreadNaturalIdTest.java index ce9a726d7c..9e6dacf87f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/naturalid/inheritance/spread/SpreadNaturalIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/naturalid/inheritance/spread/SpreadNaturalIdTest.java @@ -8,6 +8,9 @@ package org.hibernate.test.naturalid.inheritance.spread; import org.hibernate.AnnotationException; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -23,14 +26,21 @@ public class SpreadNaturalIdTest extends BaseUnitTestCase { @Test @SuppressWarnings("EmptyCatchBlock") public void testSpreadNaturalIdDeclarationGivesMappingException() { + final MetadataSources metadataSources = new MetadataSources() + .addAnnotatedClass( Principal.class ) + .addAnnotatedClass( User.class ); try { - new MetadataSources() - .addAnnotatedClass( Principal.class ) - .addAnnotatedClass( User.class ) - .buildMetadata(); + + metadataSources.buildMetadata(); fail( "Expected binders to throw an exception" ); } catch (AnnotationException expected) { } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemafilter/SchemaFilterTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemafilter/SchemaFilterTest.java index 8019b0b9d0..2a470bc6c8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemafilter/SchemaFilterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemafilter/SchemaFilterTest.java @@ -5,7 +5,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; - import javax.persistence.Entity; import javax.persistence.Id; @@ -14,16 +13,17 @@ import org.hibernate.boot.MetadataSources; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.Namespace; import org.hibernate.boot.model.relational.Sequence; +import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Environment; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.mapping.Table; -import org.hibernate.service.ServiceRegistry; import org.hibernate.tool.schema.internal.DefaultSchemaFilter; import org.hibernate.tool.schema.internal.SchemaCreatorImpl; import org.hibernate.tool.schema.internal.SchemaDropperImpl; import org.hibernate.tool.schema.spi.SchemaFilter; +import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.DialectChecks; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.ServiceRegistryBuilder; @@ -45,7 +45,7 @@ import static org.hibernate.test.schemafilter.RecordingTarget.Category.TABLE_DRO @RequiresDialectFeature( value = {DialectChecks.SupportSchemaCreation.class}) public class SchemaFilterTest extends BaseUnitTestCase { - private final ServiceRegistry serviceRegistry; + private final StandardServiceRegistryImpl serviceRegistry; private final Metadata metadata; public SchemaFilterTest() { @@ -65,6 +65,11 @@ public class SchemaFilterTest extends BaseUnitTestCase { this.metadata = ms.buildMetadata(); } + @AfterClassOnce + public void shutdown() { + serviceRegistry.destroy(); + } + @Test public void createSchema_unfiltered() { RecordingTarget target = doCreation( new DefaultSchemaFilter() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java index 9104ef08a2..32ceb47388 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/service/ServiceBootstrappingTest.java @@ -6,10 +6,6 @@ */ package org.hibernate.test.service; -import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.Properties; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; @@ -19,21 +15,25 @@ import org.hibernate.dialect.H2Dialect; import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; import org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; -import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; -import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator; import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; + import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.env.ConnectionProviderBuilder; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Assume; import org.junit.Test; +import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Steve Ebersole */ @RequiresDialect( H2Dialect.class ) public class ServiceBootstrappingTest extends BaseUnitTestCase { + @Test public void testBasicBuild() { // this test requires that SHOW_SQL property isn't passed from the outside (eg. via Gradle) @@ -43,16 +43,19 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase { final StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() .applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() ) .build(); - final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); - assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); - final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( - ConnectionProviderJdbcConnectionAccess.class, - jdbcServices.getBootstrapJdbcConnectionAccess() - ); - assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); - assertFalse( jdbcServices.getSqlStatementLogger().isLogToStdout() ); - - serviceRegistry.destroy(); + try { + final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); + assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); + final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); + assertFalse( jdbcServices.getSqlStatementLogger().isLogToStdout() ); + } + finally { + serviceRegistry.destroy(); + } } @Test @@ -61,20 +64,23 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase { props.put( Environment.SHOW_SQL, "true" ); StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() - .applySettings( props ) - .build(); + .applySettings( props ) + .build(); - JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); + try { + JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); - assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); - final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( - ConnectionProviderJdbcConnectionAccess.class, - jdbcServices.getBootstrapJdbcConnectionAccess() - ); - assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); - assertTrue( jdbcServices.getSqlStatementLogger().isLogToStdout() ); - - serviceRegistry.destroy(); + assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); + final ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); + assertTrue( jdbcServices.getSqlStatementLogger().isLogToStdout() ); + } + finally { + serviceRegistry.destroy(); + } } @Test @@ -82,31 +88,40 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase { StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() .applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() ) .build(); - JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); - - assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); - ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( - ConnectionProviderJdbcConnectionAccess.class, - jdbcServices.getBootstrapJdbcConnectionAccess() - ); - assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); Properties props = ConnectionProviderBuilder.getConnectionProviderProperties(); props.setProperty( Environment.DIALECT, H2Dialect.class.getName() ); - serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() - .applySettings( props ) - .addService( ConnectionProvider.class, new UserSuppliedConnectionProviderImpl() ) - .build(); - jdbcServices = serviceRegistry.getService( JdbcServices.class ); + try { + JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); - assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); - connectionAccess = assertTyping( - ConnectionProviderJdbcConnectionAccess.class, - jdbcServices.getBootstrapJdbcConnectionAccess() - ); - assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( UserSuppliedConnectionProviderImpl.class ) ); + assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); + ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) ); + } + finally { + serviceRegistry.destroy(); + } - serviceRegistry.destroy(); + try { + serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() + .applySettings( props ) + .addService( ConnectionProvider.class, new UserSuppliedConnectionProviderImpl() ) + .build(); + JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); + + assertTrue( jdbcServices.getDialect() instanceof H2Dialect ); + ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + ConnectionProviderJdbcConnectionAccess.class, + jdbcServices.getBootstrapJdbcConnectionAccess() + ); + assertTrue( connectionAccess.getConnectionProvider().isUnwrappableAs( UserSuppliedConnectionProviderImpl.class ) ); + } + finally { + serviceRegistry.destroy(); + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/tool/schema/SchemaValidatorImplTest.java b/hibernate-core/src/test/java/org/hibernate/test/tool/schema/SchemaValidatorImplTest.java index d96ea03582..53716bf269 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/tool/schema/SchemaValidatorImplTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/tool/schema/SchemaValidatorImplTest.java @@ -189,6 +189,8 @@ public class SchemaValidatorImplTest extends BaseUnitTestCase { } finally { new SchemaDropperImpl( serviceRegistry ).doDrop( metadata, false, schemaGenerator ); + serviceRegistry.destroy(); + connectionProvider.stop(); } } @@ -243,6 +245,8 @@ public class SchemaValidatorImplTest extends BaseUnitTestCase { } finally { new SchemaDropperImpl( serviceRegistry ).doDrop( metadata, false, schemaGenerator ); + serviceRegistry.destroy(); + connectionProvider.stop(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/dtd/EntityResolverTest.java b/hibernate-core/src/test/java/org/hibernate/test/util/dtd/EntityResolverTest.java index 8d8cedc5cc..844512c961 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/dtd/EntityResolverTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/dtd/EntityResolverTest.java @@ -7,6 +7,9 @@ package org.hibernate.test.util.dtd; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; @@ -21,8 +24,17 @@ public class EntityResolverTest extends BaseUnitTestCase { // // which we are expecting the Hibernate custom entity resolver to be able to resolve // locally via classpath lookup. - new MetadataSources() - .addResource( "org/hibernate/test/util/dtd/Parent.hbm.xml" ) - .buildMetadata(); + final MetadataSources metadataSources = new MetadataSources() + .addResource( "org/hibernate/test/util/dtd/Parent.hbm.xml" ); + + try { + metadataSources.buildMetadata(); + } + finally { + ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry(); + if(metaServiceRegistry instanceof BootstrapServiceRegistry ) { + BootstrapServiceRegistryBuilder.destroy( metaServiceRegistry ); + } + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/jdbc/ConnectionProviderDelegate.java b/hibernate-core/src/test/java/org/hibernate/test/util/jdbc/ConnectionProviderDelegate.java index 1012ebcc7e..9f898552b5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/jdbc/ConnectionProviderDelegate.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/jdbc/ConnectionProviderDelegate.java @@ -17,6 +17,7 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.hibernate.service.spi.Stoppable; /** * This {@link ConnectionProvider} extends any other ConnectionProvider @@ -27,7 +28,8 @@ import org.hibernate.service.spi.ServiceRegistryImplementor; public class ConnectionProviderDelegate implements ConnectionProvider, Configurable, - ServiceRegistryAwareService { + ServiceRegistryAwareService, + Stoppable { private ServiceRegistryImplementor serviceRegistry; @@ -77,4 +79,11 @@ public class ConnectionProviderDelegate implements public T unwrap(Class unwrapType) { return connectionProvider.unwrap( unwrapType ); } + + @Override + public void stop() { + if ( connectionProvider instanceof Stoppable ) { + ( (Stoppable) connectionProvider ).stop(); + } + } } diff --git a/hibernate-ehcache/src/test/java/org/hibernate/test/cache/ehcache/functional/RefreshUpdatedDataTest.java b/hibernate-ehcache/src/test/java/org/hibernate/test/cache/ehcache/functional/RefreshUpdatedDataTest.java index 0f763e3dcb..d48956667e 100644 --- a/hibernate-ehcache/src/test/java/org/hibernate/test/cache/ehcache/functional/RefreshUpdatedDataTest.java +++ b/hibernate-ehcache/src/test/java/org/hibernate/test/cache/ehcache/functional/RefreshUpdatedDataTest.java @@ -20,6 +20,9 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Environment; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.H2Dialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; @@ -47,6 +50,9 @@ public class RefreshUpdatedDataTest extends BaseNonConfigCoreFunctionalTestCase @SuppressWarnings("unchecked") protected void addSettings(Map settings) { super.addSettings( settings ); + if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) { + settings.put( Environment.URL, "jdbc:h2:mem:db-mvcc;MVCC=true" ); + } settings.put( AvailableSettings.GENERATE_STATISTICS, "true" ); } diff --git a/hibernate-ehcache/src/test/resources/hibernate-config/hibernate.cfg.xml b/hibernate-ehcache/src/test/resources/hibernate-config/hibernate.cfg.xml index fd8a0fc789..72639a97a0 100644 --- a/hibernate-ehcache/src/test/resources/hibernate-config/hibernate.cfg.xml +++ b/hibernate-ehcache/src/test/resources/hibernate-config/hibernate.cfg.xml @@ -13,23 +13,6 @@ - - - - org.h2.Driver - jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE - sa - - - - 5 - - - - org.hibernate.dialect.H2Dialect - - thread diff --git a/hibernate-hikaricp/src/test/resources/hibernate.properties b/hibernate-hikaricp/src/test/resources/hibernate.properties index 6225215d97..506b085d54 100644 --- a/hibernate-hikaricp/src/test/resources/hibernate.properties +++ b/hibernate-hikaricp/src/test/resources/hibernate.properties @@ -16,4 +16,5 @@ hibernate.connection.provider_class HikariCPConnectionProvider hibernate.hikari.poolName testPool # Purposefully low and simplisitic. hibernate.hikari.maximumPoolSize 2 +hibernate.hikari.connectionTimeout 1000 hibernate.hikari.idleTimeout 3000 \ No newline at end of file diff --git a/hibernate-jcache/src/test/java/org/hibernate/test/cache/jcache/functional/RefreshUpdatedDataTest.java b/hibernate-jcache/src/test/java/org/hibernate/test/cache/jcache/functional/RefreshUpdatedDataTest.java index 4f372f43f1..d2a652991c 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/test/cache/jcache/functional/RefreshUpdatedDataTest.java +++ b/hibernate-jcache/src/test/java/org/hibernate/test/cache/jcache/functional/RefreshUpdatedDataTest.java @@ -20,6 +20,9 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Environment; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.H2Dialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; @@ -47,6 +50,9 @@ public class RefreshUpdatedDataTest extends BaseNonConfigCoreFunctionalTestCase @SuppressWarnings("unchecked") protected void addSettings(Map settings) { super.addSettings( settings ); + if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) { + settings.put( Environment.URL, "jdbc:h2:mem:db-mvcc;MVCC=true" ); + } settings.put( AvailableSettings.GENERATE_STATISTICS, "true" ); } diff --git a/hibernate-jcache/src/test/resources/hibernate-config/hibernate.cfg.xml b/hibernate-jcache/src/test/resources/hibernate-config/hibernate.cfg.xml index aedb75dcbd..3259f10c11 100644 --- a/hibernate-jcache/src/test/resources/hibernate-config/hibernate.cfg.xml +++ b/hibernate-jcache/src/test/resources/hibernate-config/hibernate.cfg.xml @@ -13,23 +13,6 @@ - - - - org.h2.Driver - jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE - sa - - - - 5 - - - - org.hibernate.dialect.H2Dialect - - thread diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/JdbcProperties.java b/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/JdbcProperties.java index a34e91fcd7..96f0b47625 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/JdbcProperties.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/JdbcProperties.java @@ -27,8 +27,6 @@ public class JdbcProperties { private final String password; - private final Integer poolSize; - public JdbcProperties() { Properties connectionProperties = new Properties(); InputStream inputStream = null; @@ -40,8 +38,6 @@ public class JdbcProperties { connectionProperties.load( inputStream ); url = connectionProperties.getProperty( "hibernate.connection.url" ); - poolSize = Integer.valueOf( connectionProperties.getProperty( - "hibernate.connection.pool_size" ) ); user = connectionProperties.getProperty( "hibernate.connection.username" ); password = connectionProperties.getProperty( @@ -74,8 +70,4 @@ public class JdbcProperties { public String getPassword() { return password; } - - public Integer getPoolSize() { - return poolSize; - } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java index 53e53257bc..f2ca1c059b 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java @@ -47,7 +47,6 @@ public abstract class BaseUnitTestCase { @AfterClassOnce public void assertNoLeaks() { if ( enableConnectionLeakDetection ) { - log.info( "Assert no leaks!" ); connectionLeakUtil.assertNoLeaks(); } }