From 042ea16b37ea1c6418c9b955e43a4bb56de79331 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Tue, 18 Jul 2023 00:12:33 +0100 Subject: [PATCH] HHH-16963 Avoid H2's capability to register a JVM shutdown hook: causes classloader leaks during tests --- gradle/databases.gradle | 2 +- .../org/hibernate/orm/test/jpa/pack/cfgxmlpar/hibernate.cfg.xml | 2 +- .../org/hibernate/orm/test/cache/RefreshUpdatedDataTest.java | 2 +- .../hibernate/orm/test/connection/ConnectionCreatorTest.java | 2 +- .../orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java | 2 +- .../orm/test/resource/common/DatabaseConnectionInfo.java | 2 +- .../hibernate/orm/test/schemaupdate/ConnectionsReleaseTest.java | 2 +- .../orm/test/schemaupdate/H2DialectDataBaseToUpperTest.java | 2 +- hibernate-envers/src/demo/resources/META-INF/persistence.xml | 2 +- .../src/test/resources/hibernate.test.session-cfg.xml | 2 +- .../src/test/resources/META-INF/persistence.xml | 2 +- .../org/hibernate/orm/test/jcache/RefreshUpdatedDataTest.java | 2 +- .../src/test/java/org/hibernate/orm/test/jcache/TestHelper.java | 2 +- hibernate-proxool/src/test/resources/pool-one.properties | 2 +- hibernate-proxool/src/test/resources/pool-two.properties | 2 +- .../org/hibernate/testing/env/ConnectionProviderBuilder.java | 2 +- .../java/org/hibernate/testing/env/TestingDatabaseInfo.java | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gradle/databases.gradle b/gradle/databases.gradle index b3fb8547e6..46e808bbdd 100644 --- a/gradle/databases.gradle +++ b/gradle/databases.gradle @@ -18,7 +18,7 @@ ext { 'jdbc.driver': 'org.h2.Driver', 'jdbc.user' : 'sa', 'jdbc.pass' : '', - 'jdbc.url' : 'jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000', + 'jdbc.url' : 'jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE', 'connection.init_sql' : '', 'hibernate.dialect.native_param_markers' : 'true' ], diff --git a/hibernate-core/src/test/bundles/templates/cfgxmlpar/org/hibernate/orm/test/jpa/pack/cfgxmlpar/hibernate.cfg.xml b/hibernate-core/src/test/bundles/templates/cfgxmlpar/org/hibernate/orm/test/jpa/pack/cfgxmlpar/hibernate.cfg.xml index 55fe571e17..1181a62bdc 100644 --- a/hibernate-core/src/test/bundles/templates/cfgxmlpar/org/hibernate/orm/test/jpa/pack/cfgxmlpar/hibernate.cfg.xml +++ b/hibernate-core/src/test/bundles/templates/cfgxmlpar/org/hibernate/orm/test/jpa/pack/cfgxmlpar/hibernate.cfg.xml @@ -15,7 +15,7 @@ sa - jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 + jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE true hibernate.test 0 diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cache/RefreshUpdatedDataTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cache/RefreshUpdatedDataTest.java index e1b893fd18..3d614e10f4 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cache/RefreshUpdatedDataTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cache/RefreshUpdatedDataTest.java @@ -50,7 +50,7 @@ public class RefreshUpdatedDataTest extends BaseCoreFunctionalTestCase { super.configure( cfg ); Properties properties = Environment.getProperties(); if ( H2Dialect.class.getName().equals( properties.get( Environment.DIALECT ) ) ) { - cfg.setProperty( Environment.URL, "jdbc:h2:mem:db-mvcc" ); + cfg.setProperty( Environment.URL, "jdbc:h2:mem:db-mvcc;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" ); } cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" ); cfg.setProperty( Environment.GENERATE_STATISTICS, "true" ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/connection/ConnectionCreatorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/connection/ConnectionCreatorTest.java index 8ef09471f9..96274699d2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/connection/ConnectionCreatorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/connection/ConnectionCreatorTest.java @@ -46,7 +46,7 @@ public class ConnectionCreatorTest extends BaseUnitTestCase { Collections.emptyList(), Collections.emptyMap() ), - "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat", + "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat;DB_CLOSE_ON_EXIT=FALSE", new Properties(), false, null, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java index 2e6fa69916..88b7d0e13a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java @@ -150,7 +150,7 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT // We want a fresh db after emf close // Unfortunately we have to use this dirty hack because the db seems not to be closed otherwise settings.put( "hibernate.connection.url", "jdbc:h2:mem:db-schemagen" + schemagenNumber++ - + ";LOCK_TIMEOUT=10000" ); + + ";DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" ); EntityManagerFactoryBuilder emfb = Bootstrap.getEntityManagerFactoryBuilder( buildPersistenceUnitDescriptor(), settings diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/resource/common/DatabaseConnectionInfo.java b/hibernate-core/src/test/java/org/hibernate/orm/test/resource/common/DatabaseConnectionInfo.java index c2b37fd038..a7b3df9747 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/resource/common/DatabaseConnectionInfo.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/resource/common/DatabaseConnectionInfo.java @@ -24,7 +24,7 @@ public class DatabaseConnectionInfo { public static final DatabaseConnectionInfo INSTANCE = new DatabaseConnectionInfo(); public static final String DRIVER = "org.h2.Driver"; - public static final String URL = "jdbc:h2:mem:hibernate-core"; + public static final String URL = "jdbc:h2:mem:hibernate-core;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"; public static final String USER = "hibernate"; public static final String PASS = "hibernate"; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/ConnectionsReleaseTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/ConnectionsReleaseTest.java index c951521153..3b7adf9388 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/ConnectionsReleaseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/ConnectionsReleaseTest.java @@ -45,7 +45,7 @@ public class ConnectionsReleaseTest extends BaseUnitTestCase { public static Properties getConnectionProviderProperties() { Properties props = new Properties(); props.put( Environment.DRIVER, "org.h2.Driver" ); - props.put( Environment.URL, String.format( "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1", "db1" ) ); + props.put( Environment.URL, String.format( "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE", "db1" ) ); props.put( Environment.USER, "sa" ); props.put( Environment.PASS, "" ); return props; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/H2DialectDataBaseToUpperTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/H2DialectDataBaseToUpperTest.java index b0741a9ce3..7d9d4ce1fa 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/H2DialectDataBaseToUpperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/H2DialectDataBaseToUpperTest.java @@ -42,7 +42,7 @@ public class H2DialectDataBaseToUpperTest extends BaseUnitTestCase { ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.URL, - "jdbc:h2:mem:databaseToUpper;DATABASE_TO_UPPER=" + databaseToUpper + "jdbc:h2:mem:databaseToUpper;DATABASE_TO_UPPER=" + databaseToUpper + ";DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" ) .build(); final MetadataSources metadataSources = new MetadataSources( ssr ); diff --git a/hibernate-envers/src/demo/resources/META-INF/persistence.xml b/hibernate-envers/src/demo/resources/META-INF/persistence.xml index ef7c303ed0..f1e27239bd 100644 --- a/hibernate-envers/src/demo/resources/META-INF/persistence.xml +++ b/hibernate-envers/src/demo/resources/META-INF/persistence.xml @@ -13,7 +13,7 @@ - + diff --git a/hibernate-envers/src/test/resources/hibernate.test.session-cfg.xml b/hibernate-envers/src/test/resources/hibernate.test.session-cfg.xml index b19a2ebe85..9fb07e305d 100644 --- a/hibernate-envers/src/test/resources/hibernate.test.session-cfg.xml +++ b/hibernate-envers/src/test/resources/hibernate.test.session-cfg.xml @@ -17,7 +17,7 @@ false org.hibernate.dialect.H2Dialect - jdbc:h2:mem:envers + jdbc:h2:mem:envers;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE org.h2.Driver sa diff --git a/hibernate-integrationtest-java-modules/src/test/resources/META-INF/persistence.xml b/hibernate-integrationtest-java-modules/src/test/resources/META-INF/persistence.xml index 9491fdb511..60bc0f6644 100644 --- a/hibernate-integrationtest-java-modules/src/test/resources/META-INF/persistence.xml +++ b/hibernate-integrationtest-java-modules/src/test/resources/META-INF/persistence.xml @@ -14,7 +14,7 @@ - + diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/RefreshUpdatedDataTest.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/RefreshUpdatedDataTest.java index 768af2229c..2285ef7249 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/RefreshUpdatedDataTest.java +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/RefreshUpdatedDataTest.java @@ -58,7 +58,7 @@ public class RefreshUpdatedDataTest { .configure( "hibernate-config/hibernate.cfg.xml" ); if ( H2Dialect.class.equals( DialectContext.getDialect().getClass() ) ) { - ssrb.applySetting( AvailableSettings.URL, "jdbc:h2:mem:db-mvcc" ); + ssrb.applySetting( AvailableSettings.URL, "jdbc:h2:mem:db-mvcc;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" ); } ssrb.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" ); diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/TestHelper.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/TestHelper.java index 991abcd457..6eb2e3ca75 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/TestHelper.java +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/TestHelper.java @@ -123,7 +123,7 @@ public class TestHelper { .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ); if ( H2Dialect.class.equals( DialectContext.getDialect().getClass() ) ) { - ssrb.applySetting( AvailableSettings.URL, "jdbc:h2:mem:db-mvcc" ); + ssrb.applySetting( AvailableSettings.URL, "jdbc:h2:mem:db-mvcc;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" ); } return ssrb; } diff --git a/hibernate-proxool/src/test/resources/pool-one.properties b/hibernate-proxool/src/test/resources/pool-one.properties index d3b9463cc6..e496ca4e61 100644 --- a/hibernate-proxool/src/test/resources/pool-one.properties +++ b/hibernate-proxool/src/test/resources/pool-one.properties @@ -5,7 +5,7 @@ # See the lgpl.txt file in the root directory or . # jdbc-0.proxool.alias=pool-one -jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 +jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE jdbc-0.proxool.driver-class=org.h2.Driver jdbc-0.user=sa jdbc-0.password= diff --git a/hibernate-proxool/src/test/resources/pool-two.properties b/hibernate-proxool/src/test/resources/pool-two.properties index eedb426a50..1246107910 100644 --- a/hibernate-proxool/src/test/resources/pool-two.properties +++ b/hibernate-proxool/src/test/resources/pool-two.properties @@ -5,7 +5,7 @@ # See the lgpl.txt file in the root directory or . # jdbc-0.proxool.alias=pool-two -jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 +jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE jdbc-0.proxool.driver-class=org.h2.Driver jdbc-0.user=sa jdbc-0.password= diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java b/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java index a5cd4959bf..66f4c694db 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java @@ -34,7 +34,7 @@ public class ConnectionProviderBuilder implements DialectCheck { public static final String DRIVER = "org.h2.Driver"; public static final String DATA_SOURCE = "org.h2.jdbcx.JdbcDataSource"; // public static final String URL = "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1"; - public static final String URL_FORMAT = "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1"; + public static final String URL_FORMAT = "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"; public static final String URL = URL_FORMAT; public static final String USER = "sa"; public static final String PASS = ""; diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/env/TestingDatabaseInfo.java b/hibernate-testing/src/main/java/org/hibernate/testing/env/TestingDatabaseInfo.java index 47a828664a..1d778752e9 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/env/TestingDatabaseInfo.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/env/TestingDatabaseInfo.java @@ -16,7 +16,7 @@ import org.hibernate.dialect.H2Dialect; */ public final class TestingDatabaseInfo { public static volatile String DRIVER = "org.h2.Driver"; - public static volatile String URL = "jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1"; + public static volatile String URL = "jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"; public static volatile String USER = "sa"; public static volatile String PASS = "";