Skip to content

Commit

Permalink
Mysql tests with testcontainers.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus committed Sep 22, 2023
1 parent 565ef6d commit 76b2107
Show file tree
Hide file tree
Showing 10 changed files with 494 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ protected PreparedStatement prepareStatement(DbClientServiceContext serviceConte
* @return statement
*/
protected PreparedStatement prepareStatement(String stmtName, String stmt) {
return prepareStatement(connectionPool.connection(), stmtName, stmt);
Connection connection = connectionPool.connection();
try {
connection.setAutoCommit(true);
} catch (SQLException e) {
throw new DbClientException("Failed to set autocommit to true", e);
}
return prepareStatement(connection, stmtName, stmt);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*/
package io.helidon.dbclient.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import io.helidon.dbclient.DbClientException;
import io.helidon.dbclient.DbStatement;

/**
Expand Down Expand Up @@ -44,6 +47,12 @@ protected JdbcTransactionStatement(JdbcConnectionPool connectionPool,

@Override
protected PreparedStatement prepareStatement(String stmtName, String stmt) {
return prepareStatement(transactionContext.connection(), stmtName, stmt);
Connection connection = transactionContext.connection();
try {
connection.setAutoCommit(false);
} catch (SQLException e) {
throw new DbClientException("Failed to set autocommit to false", e);
}
return prepareStatement(connection, stmtName, stmt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.tests.integration.dbclient.jdbc;
package io.helidon.tests.integration.dbclient.h2;

import java.nio.file.Paths;
import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
requires io.helidon.tests.integration.dbclient.common;

provides io.helidon.tests.integration.dbclient.common.spi.SetupProvider
with io.helidon.tests.integration.dbclient.jdbc.H2SetupProvider;
with io.helidon.tests.integration.dbclient.h2.H2SetupProvider;

}
2 changes: 1 addition & 1 deletion tests/integration/dbclient/h2/src/test/resources/h2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ db:
password: "password"
database: "test"
connection:
url: jdbc:h2:tcp://${db.host}:${db.port}/${db.database};DATABASE_TO_UPPER=FALSE
url: jdbc:h2:tcp://localhost:9092/test;DATABASE_TO_UPPER=FALSE
health-check:
type: query
statement: "SELECT 0"
Expand Down
179 changes: 179 additions & 0 deletions tests/integration/dbclient/mysql/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.tests.integration.dbclient</groupId>
<artifactId>helidon-tests-integration-dbclient-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>helidon-tests-integration-dbclient-mysql</artifactId>
<name>Helidon Tests Integration Database Client MySQL</name>

<properties>
<maven.test.redirectTestOutputToFile>false</maven.test.redirectTestOutputToFile>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>1.19.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.helidon.tests.integration.dbclient</groupId>
<artifactId>helidon-tests-integration-dbclient-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.db</groupId>
<artifactId>helidon-integrations-db-mysql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-mapper</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-hikari</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.tests.integration</groupId>
<artifactId>helidon-tests-integration-harness</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IT</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>${maven.test.redirectTestOutputToFile}</redirectTestOutputToFile>
<parallel>methods</parallel>
<threadCount>10</threadCount>
<systemPropertyVariables>
<junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
</systemPropertyVariables>
<dependenciesToScan>
<dependency>io.helidon.tests.integration.dbclient:helidon-tests-integration-dbclient-common</dependency>
</dependenciesToScan>
<includes>
<include>io.helidon.tests.integration.dbclient.common.tests.*IT</include>
</includes>
</configuration>
<executions>
<execution>
<id>test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

0 comments on commit 76b2107

Please sign in to comment.