Skip to content

Commit

Permalink
[#929] Adapted tests to exclude H2 dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
blafond committed Mar 30, 2022
1 parent 0702ecd commit fe8ede8
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ReactiveConnectionPool initiateService(Map configurationValues, ServiceRe
Object configValue = configurationValues.get( Settings.SQL_CLIENT_POOL );

String dbType = (String) configurationValues.get( "db" );
if ( dbType.equalsIgnoreCase( "h2" ) ) {
if ( dbType != null && dbType.equalsIgnoreCase( "h2" ) ) {
configValue = "org.hibernate.reactive.pool.impl.H2SqlClientPool";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ protected Configuration constructConfiguration() {
configuration.setProperty( Settings.HBM2DDL_IMPORT_FILES, "/db2.sql" );
doneTablespace = true;
}

configuration.setProperty( Settings.URL, DatabaseConfiguration.getJdbcUrl() );
//Use JAVA_TOOL_OPTIONS='-Dhibernate.show_sql=true'
configuration.setProperty( Settings.SHOW_SQL, System.getProperty(Settings.SHOW_SQL, "false") );
configuration.setProperty( Settings.FORMAT_SQL, System.getProperty(Settings.FORMAT_SQL, "false") );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@
import org.hibernate.reactive.pool.impl.OracleParameters;
import org.hibernate.reactive.pool.impl.PostgresParameters;
import org.hibernate.reactive.pool.impl.SQLServerParameters;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;

public class BatchQueryOnConnectionTest extends BaseReactiveTest {

private static final int BATCH_SIZE = 20;

@Rule
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( H2 );

@Override
protected Set<Class<?>> annotatedEntities() {
return Set.of( DataPoint.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@
import org.hibernate.reactive.pool.impl.SqlClientConnection;
import org.hibernate.reactive.stage.impl.StageSessionImpl;
import org.hibernate.reactive.stage.impl.StageStatelessSessionImpl;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.util.impl.CompletionStages.loop;
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;

public class BatchingConnectionTest extends ReactiveSessionTest {

@Rule
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( H2 );

@Override
protected Configuration constructConfiguration() {
Configuration configuration = super.constructConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration;
import org.hibernate.reactive.provider.Settings;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import io.vertx.sqlclient.SqlConnectOptions;
import org.assertj.core.api.Assertions;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;

/**
* Test the default port is set correctly when using {@link DefaultSqlClientPoolConfiguration}
*/
public class DefaultPortTest {

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );

@Test
public void testDefaultPortIsSet() throws URISyntaxException {
DefaultSqlClientPoolConfiguration configuration = new DefaultSqlClientPoolConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
import java.util.Collection;
import java.util.List;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;

public class FormulaTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( MARIA, MYSQL );
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( MARIA, MYSQL, H2 );

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
import org.hibernate.HibernateException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.exception.ConstraintViolationException;
import org.hibernate.reactive.mutiny.Mutiny;

import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;

public class MutinyExceptionsTest extends BaseReactiveTest {

@Override
Expand Down Expand Up @@ -48,7 +52,12 @@ public void testDuplicateKeyException(TestContext context) {
.onItem().call( Mutiny.Session::flush )
.onItem().invoke( ignore -> context.fail( "Expected exception not thrown" ) )
.onFailure().recoverWithItem( err -> {
context.assertEquals( getExpectedException(), err.getClass() );
if( dbType() == DatabaseConfiguration.DBType.H2 ) {
context.assertTrue( ConstraintViolationException.class == err.getClass() ||
getExpectedException() == err.getClass() );
} else {
context.assertEquals( getExpectedException(), err.getClass() );
}
return null;
} )
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.vertx.ext.unit.TestContext;

import static java.util.Arrays.asList;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
Expand Down Expand Up @@ -105,7 +106,7 @@ public String toString() {
public static class ForOtherDbsTest extends UUIDAsBinaryType {

@Rule // Select a UUID field doesn't work with Oracle
public DatabaseSelectionRule rule = skipTestsFor( MYSQL, MARIA, ORACLE );
public DatabaseSelectionRule rule = skipTestsFor( MYSQL, MARIA, ORACLE, H2 );

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.provider.Settings;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;

public class UriConfigTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );

@Override
protected Configuration constructConfiguration() {
Class<? extends Dialect> dialect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.provider.Settings;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;

/**
* Check that the right exception is thrown when there is an error with the credentials.
Expand All @@ -28,6 +31,9 @@
*/
public class WrongCredentialsTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );

@Override
protected Configuration constructConfiguration() {
Configuration configuration = super.constructConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import org.hibernate.HibernateError;
import org.hibernate.reactive.pool.impl.DefaultSqlClientPool;
import org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.sqlclient.SqlConnectOptions;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.createJdbcUrl;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
import static org.junit.Assert.assertThrows;
Expand All @@ -33,6 +36,9 @@ public class JdbcUrlParserTest {

private static final String DEFAULT_DB = "hreactDB";

@Rule
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( H2 );

@Test
public void exceptionWhenNull() {
final HibernateError error = assertThrows( HibernateError.class, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum DBType {
POSTGRESQL( PostgreSQLDatabase.INSTANCE, 5432, "POSTGRES", "PG" ),
COCKROACHDB( CockroachDBDatabase.INSTANCE, 26257, "COCKROACH" ),
SQLSERVER( MSSQLServerDatabase.INSTANCE, 1433, "MSSQL", "MSSQLSERVER" ),
ORACLE( OracleDatabase.INSTANCE, 1521 );
ORACLE( OracleDatabase.INSTANCE, 1521 ),
H2( H2Database.INSTANCE, -1 );

private final TestableDatabase configuration;
private final int defaultPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected Configuration constructConfiguration(String hbm2DdlOption) {
}

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2 );
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2, H2 );

protected Configuration constructConfiguration(String action) {
Configuration configuration = super.constructConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.persistence.Table;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY;

Expand Down Expand Up @@ -59,7 +60,7 @@ protected Configuration constructConfiguration(String hbm2DdlOption) {
}

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2 );
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2, H2 );

protected Configuration constructConfiguration(String action) {
Configuration configuration = super.constructConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;

Expand All @@ -34,7 +35,7 @@
public class JsonTypeTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE);
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE, H2);

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.function.Consumer;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;
Expand All @@ -35,7 +36,7 @@
public class StringToJsonTypeTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, MARIA, ORACLE );
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, MARIA, ORACLE, H2 );

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;

Expand All @@ -36,7 +37,7 @@
public class UserJsonTypeTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE );
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE, H2 );

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down

0 comments on commit fe8ede8

Please sign in to comment.