Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions docker_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,34 +172,57 @@ postgresql() {
postgresql_13() {
$CONTAINER_CLI rm -f postgres || true
$CONTAINER_CLI run --name postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -p5432:5432 -d ${DB_IMAGE_POSTGRESQL_13:-docker.io/postgis/postgis:13-3.1}
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-13-pgvector && psql -U hibernate_orm_test -d hibernate_orm_test -c "create extension vector;"'
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-13-pgvector'
postgresql_setup
}

postgresql_14() {
$CONTAINER_CLI rm -f postgres || true
$CONTAINER_CLI run --name postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -p5432:5432 -d ${DB_IMAGE_POSTGRESQL_14:-docker.io/postgis/postgis:14-3.3}
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-14-pgvector && psql -U hibernate_orm_test -d hibernate_orm_test -c "create extension vector;"'
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-14-pgvector'
postgresql_setup
}

postgresql_15() {
$CONTAINER_CLI rm -f postgres || true
$CONTAINER_CLI run --name postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -p5432:5432 --tmpfs /pgtmpfs:size=131072k -d ${DB_IMAGE_POSTGRESQL_15:-docker.io/postgis/postgis:15-3.3} \
-c fsync=off -c synchronous_commit=off -c full_page_writes=off -c shared_buffers=256MB -c maintenance_work_mem=256MB -c max_wal_size=1GB -c checkpoint_timeout=1d
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-15-pgvector && psql -U hibernate_orm_test -d hibernate_orm_test -c "create extension vector;"'
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-15-pgvector'
postgresql_setup
}

postgresql_16() {
$CONTAINER_CLI rm -f postgres || true
$CONTAINER_CLI run --name postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -p5432:5432 --tmpfs /pgtmpfs:size=131072k -d ${DB_IMAGE_POSTGRESQL_16:-docker.io/postgis/postgis:16-3.4} \
-c fsync=off -c synchronous_commit=off -c full_page_writes=off -c shared_buffers=256MB -c maintenance_work_mem=256MB -c max_wal_size=1GB -c checkpoint_timeout=1d
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-16-pgvector && psql -U hibernate_orm_test -d hibernate_orm_test -c "create extension vector;"'
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-16-pgvector'
postgresql_setup
}

postgresql_17() {
$CONTAINER_CLI rm -f postgres || true
$CONTAINER_CLI run --name postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -p5432:5432 --tmpfs /pgtmpfs:size=131072k -d ${DB_IMAGE_POSTGRESQL_17:-docker.io/postgis/postgis:17-3.5} \
-c fsync=off -c synchronous_commit=off -c full_page_writes=off -c shared_buffers=256MB -c maintenance_work_mem=256MB -c max_wal_size=1GB -c checkpoint_timeout=1d
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-17-pgvector && psql -U hibernate_orm_test -d hibernate_orm_test -c "create extension vector;"'
$CONTAINER_CLI exec postgres bash -c '/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && apt install -y postgresql-17-pgvector'
postgresql_setup
}

postgresql_setup() {
databases=()
for n in $(seq 1 $(($(nproc)/2)))
do
databases+=("hibernate_orm_test_${n}")
done
create_cmd=
for i in "${!databases[@]}";do
create_cmd+="psql -U hibernate_orm_test -d postgres -c \"create database ${databases[i]};\";"
done
$CONTAINER_CLI exec postgres bash -c "until pg_isready -U hibernate_orm_test; do sleep 1; done"
$CONTAINER_CLI exec postgres bash -c "${create_cmd}"
$CONTAINER_CLI exec postgres bash -c 'psql -U hibernate_orm_test -d hibernate_orm_test -c "create extension vector;"'
for i in "${!databases[@]}";do
$CONTAINER_CLI exec postgres bash -c "psql -U hibernate_orm_test -d ${databases[i]} -c \"create extension vector; create extension postgis;\""
done
}

gaussdb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.hibernate.community.dialect.TiDBDialect;
import org.hibernate.community.dialect.GaussDBDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.agroal.internal.AgroalConnectionProvider;

import org.hibernate.test.agroal.util.GradleParallelTestingAgroalConnectionProvider;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.common.connections.BaseTransactionIsolationConfigTest;

Expand All @@ -22,6 +22,6 @@
public class AgroalTransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest {
@Override
protected ConnectionProvider getConnectionProviderUnderTest() {
return new AgroalConnectionProvider();
return new GradleParallelTestingAgroalConnectionProvider();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.test.agroal.util;

import org.hibernate.HibernateException;
import org.hibernate.agroal.internal.AgroalConnectionProvider;

import java.util.Map;

import static org.hibernate.testing.jdbc.GradleParallelTestingResolver.resolveFromSettings;

/**
* @author Loïc Lefèvre
*/
public class GradleParallelTestingAgroalConnectionProvider extends AgroalConnectionProvider {
@Override
public void configure(Map<String, Object> properties) throws HibernateException {
resolveFromSettings( properties );
super.configure( properties );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.ArrayList;
import java.util.List;

import org.hibernate.agroal.internal.AgroalConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;

import org.hibernate.testing.jdbc.JdbcSpies;
Expand All @@ -21,7 +20,7 @@
*
* @author Vlad Mihalcea
*/
public class PreparedStatementSpyConnectionProvider extends AgroalConnectionProvider {
public class PreparedStatementSpyConnectionProvider extends GradleParallelTestingAgroalConnectionProvider {
public final JdbcSpies.SpyContext spyContext = new JdbcSpies.SpyContext();

private final List<Connection> acquiredConnections = new ArrayList<>( );
Expand Down
2 changes: 1 addition & 1 deletion hibernate-agroal/src/test/resources/hibernate.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ hibernate.connection.password @jdbc.pass@
hibernate.connection.init_sql @connection.init_sql@

hibernate.jdbc.batch_size 10
hibernate.connection.provider_class AgroalConnectionProvider
hibernate.connection.provider_class org.hibernate.test.agroal.util.GradleParallelTestingAgroalConnectionProvider

hibernate.agroal.maxSize 2
hibernate.agroal.acquisitionTimeout PT1s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.spi.ServiceRegistryImplementor;

import org.hibernate.test.c3p0.util.GradleParallelTestingC3P0ConnectionProvider;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.common.connections.BaseTransactionIsolationConfigTest;
import org.junit.Before;
Expand All @@ -35,7 +36,7 @@ public void setUp() {

@Override
protected ConnectionProvider getConnectionProviderUnderTest() {
C3P0ConnectionProvider provider = new C3P0ConnectionProvider();
C3P0ConnectionProvider provider = new GradleParallelTestingC3P0ConnectionProvider();
provider.injectServices( (ServiceRegistryImplementor) ssr );
return provider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import jakarta.persistence.SqlResultSetMappings;
import jakarta.persistence.StoredProcedureParameter;

import org.hibernate.c3p0.internal.C3P0ConnectionProvider;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.OracleDialect;

import org.hibernate.test.c3p0.util.GradleParallelTestingC3P0ConnectionProvider;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
Expand All @@ -41,7 +41,7 @@ public class OracleSQLCallableStatementProxyTest extends
protected void configure(Configuration configuration) {
configuration.setProperty(
org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER,
C3P0ConnectionProvider.class
GradleParallelTestingC3P0ConnectionProvider.class
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.test.c3p0.util;

import org.hibernate.HibernateException;
import org.hibernate.c3p0.internal.C3P0ConnectionProvider;

import java.util.Map;

import static org.hibernate.testing.jdbc.GradleParallelTestingResolver.resolveFromSettings;

/**
* @author Loïc Lefèvre
*/
public class GradleParallelTestingC3P0ConnectionProvider extends C3P0ConnectionProvider {
@Override
public void configure(Map<String, Object> properties) throws HibernateException {
resolveFromSettings( properties );
super.configure( properties );
}
}
2 changes: 1 addition & 1 deletion hibernate-c3p0/src/test/resources/hibernate.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ hibernate.c3p0.testConnectionOnCheckout true
hibernate.show_sql false

hibernate.max_fetch_depth 5
hibernate.connection.provider_class C3P0ConnectionProvider
hibernate.connection.provider_class org.hibernate.test.c3p0.util.GradleParallelTestingC3P0ConnectionProvider

hibernate.cache.region_prefix hibernate.test
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
16 changes: 11 additions & 5 deletions hibernate-core/hibernate-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,18 @@ tasks.withType( Test.class ).each { test ->
//Avoid Log4J2 classloader leaks:
test.jvmArgs( ['-Dlog4j2.disableJmx=true'] )

test.beforeTest { descriptor ->
//println "Starting test: " + descriptor
// see GradleParallelTestingResolver for how the test worker id is resolved in JDBC configs
if ( project.db == "h2" || project.db == "hsqldb" || project.db == "pgsql_ci" ) {
// Most systems have multi-threading and maxing out a core on both threads will hurt performance
// Also, as soon as we hit 16+ threads, the returns are diminishing, so divide by 4
def threadCount = Runtime.runtime.availableProcessors()
test.maxParallelForks = threadCount >= 16 ? threadCount.intdiv( 4 ) : (threadCount.intdiv( 2 ) ?: 1)
test.systemProperty 'maxParallelForks', test.maxParallelForks
}
if ( project.db == "h2" || project.db == "hsqldb" ) {
// Parallel test runs when running with in-memory databases
test.maxParallelForks = Runtime.runtime.availableProcessors().intdiv( 2 ) ?: 1
else if ( project.db == "oracle_test_pilot_database" ) {
// Since Oracle TestPilot databases run on separate machines, use all threads for testing
test.maxParallelForks = Runtime.runtime.availableProcessors()
test.systemProperty 'maxParallelForks', test.maxParallelForks
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<session-factory>
<property name="hibernate.dialect">@db.dialect@</property>
<property name="hibernate.connection.driver_class">@jdbc.driver@</property>
<property name="hibernate.connection.creator_factory_class">org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl</property>
<property name="hibernate.connection.username">@jdbc.user@</property>
<property name="hibernate.connection.password">@jdbc.pass@</property>
<property name="hibernate.connection.init_sql">@connection.init_sql@</property>
Expand All @@ -30,4 +31,4 @@
<collection-cache collection="org.hibernate.orm.test.jpa.Item.distributors" usage="read-write" region="RegionName"/>
<event type="pre-insert"/>
</session-factory>
</hibernate-configuration>
</hibernate-configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<properties>
<property name="hibernate.dialect" value="@db.dialect@"/>
<property name="hibernate.connection.driver_class" value="@jdbc.driver@"/>
<property name="hibernate.connection.creator_factory_class" value="org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl" />
<property name="hibernate.connection.username" value="@jdbc.user@"/>
<property name="hibernate.connection.password" value="@jdbc.pass@"/>
<property name="hibernate.connection.url" value="@jdbc.url@"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<properties>
<property name="hibernate.dialect" value="@db.dialect@"/>
<property name="hibernate.connection.driver_class" value="@jdbc.driver@"/>
<property name="hibernate.connection.creator_factory_class" value="org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl" />
<property name="hibernate.connection.username" value="@jdbc.user@"/>
<property name="hibernate.connection.password" value="@jdbc.pass@"/>
<property name="hibernate.connection.url" value="@jdbc.url@"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<properties>
<property name="hibernate.dialect" value="@db.dialect@"/>
<property name="hibernate.connection.driver_class" value="@jdbc.driver@"/>
<property name="hibernate.connection.creator_factory_class" value="org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl" />
<property name="hibernate.connection.username" value="@jdbc.user@"/>
<property name="hibernate.connection.password" value="@jdbc.pass@"/>
<property name="hibernate.connection.url" value="@jdbc.url@"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<property name="hibernate.dialect" value="@db.dialect@"/>
<property name="hibernate.connection.driver_class" value="@jdbc.driver@"/>
<property name="hibernate.connection.creator_factory_class" value="org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl" />
<property name="hibernate.connection.username" value="@jdbc.user@"/>
<property name="hibernate.connection.password" value="@jdbc.pass@"/>
<property name="hibernate.connection.url" value="@jdbc.url@"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<properties>
<property name="hibernate.dialect" value="@db.dialect@"/>
<property name="hibernate.connection.driver_class" value="@jdbc.driver@"/>
<property name="hibernate.connection.creator_factory_class" value="org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl" />
<property name="hibernate.connection.username" value="@jdbc.user@"/>
<property name="hibernate.connection.password" value="@jdbc.pass@"/>
<property name="hibernate.connection.url" value="@jdbc.url@"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<properties>
<property name="hibernate.dialect" value="@db.dialect@"/>
<property name="hibernate.connection.driver_class" value="@jdbc.driver@"/>
<property name="hibernate.connection.creator_factory_class" value="org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl" />
<property name="hibernate.connection.username" value="@jdbc.user@"/>
<property name="hibernate.connection.password" value="@jdbc.pass@"/>
<property name="hibernate.connection.url" value="@jdbc.url@"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Copyright Red Hat Inc. and Hibernate Authors
#
hibernate.connection.driver_class @jdbc.driver@
hibernate.connection.creator_factory_class org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl
hibernate.connection.url @jdbc.url@
hibernate.connection.username @jdbc.user@
hibernate.connection.password @jdbc.pass@
hibernate.connection.init_sql @connection.init_sql@
hibernate.connection.init_sql @connection.init_sql@
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<properties>
<property name="hibernate.dialect" value="@db.dialect@"/>
<property name="hibernate.connection.driver_class" value="@jdbc.driver@"/>
<property name="hibernate.connection.creator_factory_class" value="org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl" />
<property name="hibernate.connection.username" value="@jdbc.user@"/>
<property name="hibernate.connection.password" value="@jdbc.pass@"/>
<property name="hibernate.connection.url" value="@jdbc.url@"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<properties>
<property name="hibernate.dialect" value="@db.dialect@"/>
<property name="hibernate.connection.driver_class" value="@jdbc.driver@"/>
<property name="hibernate.connection.creator_factory_class" value="org.hibernate.testing.jdbc.GradleParallelTestingConnectionCreatorFactoryImpl" />
<property name="hibernate.connection.username" value="@jdbc.user@"/>
<property name="hibernate.connection.password" value="@jdbc.pass@"/>
<property name="hibernate.connection.url" value="@jdbc.url@"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


import static org.hibernate.internal.util.StringHelper.split;
import static org.hibernate.testing.jdbc.GradleParallelTestingResolver.resolveUrl;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Jpa(annotatedClasses = DataSourceTest.TestEntity.class,
Expand All @@ -36,7 +37,7 @@ void test(EntityManagerFactoryScope scope) {
scope.getEntityManagerFactory();
LogInspectionHelper.clearAllListeners( ConnectionInfoLogger.INSTANCE );
Dialect dialect = scope.getDialect();
assertTrue( dialect instanceof OracleDialect od && od.isAutonomous()
assertTrue( dialect instanceof OracleDialect
|| dialect instanceof DB2Dialect
|| dialect instanceof InformixDialect // Informix metadata does not include the URL
|| listener.seen );
Expand All @@ -54,7 +55,7 @@ private static class Listener implements LogListener {
@Override
public void loggedEvent(Logger.Level level, String renderedMessage, Throwable thrown) {
if ( renderedMessage.contains( "Database info:" ) ) {
final String url = Environment.getProperties().getProperty( JdbcSettings.URL );
final String url = resolveUrl( Environment.getProperties().getProperty( JdbcSettings.URL ) );
final String firstUrlPart = split( "?", split( ";", url )[0])[0];
final String baseUrl = firstUrlPart.endsWith( "/" ) ? firstUrlPart.substring( 0, firstUrlPart.length() - 1 ) : firstUrlPart;
seen = renderedMessage.contains( baseUrl );
Expand Down
Loading
Loading