Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Testcontainers for R2DBC MySQL Integration Testing #108 #109

8 changes: 0 additions & 8 deletions .github/workflows/ci-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,5 @@ jobs:
distribution: temurin
java-version: 8
cache: maven
- name: Shutdown the Default MySQL
run: sudo service mysql stop
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind kindly sharing with us the reason for deleting this line? We appreciate your insights

- name: Set up MySQL ${{ matrix.mysql-version }}
uses: asyncer-io/mysql-action@trunk
with:
mysql version: ${{ matrix.mysql-version }}
mysql database: r2dbc
mysql root password: r2dbc-password!@
- name: Integration test with MySQL ${{ matrix.mysql-version }}
run: ./mvnw -B verify -Dmaven.javadoc.skip=true -Dmaven.surefire.skip=true -Dtest.mysql.password=r2dbc-password!@ -Dtest.mysql.version=${{ matrix.mysql-version }} -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
25 changes: 25 additions & 0 deletions src/test/java/io/asyncer/r2dbc/mysql/IntegrationTestSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.r2dbc.spi.Result;
import org.jetbrains.annotations.Nullable;
import org.reactivestreams.Publisher;
import org.testcontainers.containers.MySQLContainer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
Expand All @@ -38,10 +39,33 @@ abstract class IntegrationTestSupport {

private final MySqlConnectionFactory connectionFactory;

private static final MySQLContainer<?> container;

IntegrationTestSupport(MySqlConnectionConfiguration configuration) {
this.connectionFactory = MySqlConnectionFactory.from(configuration);
}

static {
String password = System.getProperty("test.mysql.password");
saurabhyadav1985 marked this conversation as resolved.
Show resolved Hide resolved
String version = System.getProperty("test.mysql.version");
saurabhyadav1985 marked this conversation as resolved.
Show resolved Hide resolved

if (password == null || password.isEmpty()) {
throw new IllegalStateException("Property test.mysql.password must exists and not be empty");
}

if (version == null || version.isEmpty()) {
throw new IllegalStateException("Property test.mysql.version must exists and not be empty");
}

container = new MySQLContainer<>("mysql:" + version)
.withUsername("root")
.withPassword(password)
.withDatabaseName("r2dbc")
.withExposedPorts(MySQLContainer.MYSQL_PORT);

container.start();
}

void complete(Function<? super MySqlConnection, Publisher<?>> runner) {
process(runner).verifyComplete();
}
Expand Down Expand Up @@ -81,6 +105,7 @@ static MySqlConnectionConfiguration configuration(boolean autodetectExtensions,
.user("root")
.password(password)
.database("r2dbc")
.port(container.getMappedPort(MySQLContainer.MYSQL_PORT))
.autodetectExtensions(autodetectExtensions);

if (serverZoneId != null) {
Expand Down