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
9 changes: 9 additions & 0 deletions vertx-mssql-client/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Documentation:

By default, the test suite runs SQL Server in a container using https://www.testcontainers.org/[TestContainers].

The container database binds to an arbitrary port to avoid conflicts.
Nevertheless, you can force the usage of the standard SQL Server port (1433) with a flag:

[source,bash]
----
mvn test -DcontainerFixedPort
----


==== Testing with an external database

You can start an external database:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

import io.vertx.mssqlclient.MSSQLConnectOptions;
import org.junit.rules.ExternalResource;
import org.testcontainers.containers.InternetProtocol;
import org.testcontainers.containers.MSSQLServerContainer;

import java.time.ZoneId;

import static org.testcontainers.containers.MSSQLServerContainer.MS_SQL_SERVER_PORT;

public class MSSQLRule extends ExternalResource {
private MSSQLServerContainer<?> server;
private ServerContainer<?> server;
private MSSQLConnectOptions options;

public static final MSSQLRule SHARED_INSTANCE = new MSSQLRule();
Expand Down Expand Up @@ -50,16 +53,20 @@ private MSSQLConnectOptions startMSSQL() {
if (containerVersion == null || containerVersion.isEmpty()) {
containerVersion = "2017-latest";
}
server = new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:" + containerVersion)
server = new ServerContainer<>("mcr.microsoft.com/mssql/server:" + containerVersion)
.acceptLicense()
.withEnv("TZ", ZoneId.systemDefault().toString())
.withInitScript("init.sql")
.withExposedPorts(MSSQLServerContainer.MS_SQL_SERVER_PORT);
.withInitScript("init.sql");
if (System.getProperties().containsKey("containerFixedPort")) {
server.withFixedExposedPort(MS_SQL_SERVER_PORT, MS_SQL_SERVER_PORT);
} else {
server.withExposedPorts(MS_SQL_SERVER_PORT);
}
server.start();

return new MSSQLConnectOptions()
.setHost(server.getContainerIpAddress())
.setPort(server.getMappedPort(MSSQLServerContainer.MS_SQL_SERVER_PORT))
.setPort(server.getMappedPort(MS_SQL_SERVER_PORT))
.setUser(server.getUsername())
.setPassword(server.getPassword());
}
Expand All @@ -77,4 +84,16 @@ private void stopMSSQL() {
public MSSQLConnectOptions options() {
return new MSSQLConnectOptions(options);
}

private static class ServerContainer<SELF extends ServerContainer<SELF>> extends MSSQLServerContainer<SELF> {

public ServerContainer(String dockerImageName) {
super(dockerImageName);
}

public SELF withFixedExposedPort(int hostPort, int containerPort) {
super.addFixedExposedPort(hostPort, containerPort, InternetProtocol.TCP);
return self();
}
}
}
8 changes: 8 additions & 0 deletions vertx-pg-client/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ The following versions of embedded Postgres are supported:
- `10.6` (default)
- `11.x` (Unix Domain Socket Test are ignored)

The embedded Postgres database binds to an arbitrary port by default to avoid conflicts.
Nevertheless, you can force the usage of the standard PostgreSQL port (5432) with a flag:

[source,bash]
----
mvn test -DcontainerFixedPort
----

=== Testing with an external database

You can run tests with an external database:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.vertx.pgclient.PgConnectOptions;
import io.vertx.sqlclient.PoolOptions;
import org.junit.rules.ExternalResource;
import org.testcontainers.containers.InternetProtocol;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.MountableFile;

Expand All @@ -29,6 +30,8 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

import static org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT;

/**
* Postgresql test database based on https://www.testcontainers.org
* Require Docker
Expand All @@ -41,7 +44,7 @@ public class ContainerPgRule extends ExternalResource {
private static final String connectionUri = System.getProperty("connection.uri");
private static final String tlsConnectionUri = System.getProperty("tls.connection.uri");

private PostgreSQLContainer server;
private ServerContainer<?> server;
private PgConnectOptions options;
private String databaseVersion;
private boolean ssl;
Expand All @@ -63,7 +66,7 @@ public PoolOptions poolOptions() {
private void initServer(String version) throws Exception {
File setupFile = getTestResource("resources" + File.separator + "create-postgres.sql");

server = (PostgreSQLContainer) new PostgreSQLContainer("postgres:" + version)
server = new ServerContainer<>("postgres:" + version)
.withDatabaseName("postgres")
.withUsername("postgres")
.withPassword("postgres")
Expand All @@ -73,6 +76,11 @@ private void initServer(String version) throws Exception {
.withCopyFileToContainer(MountableFile.forHostPath(getTestResource("resources" + File.separator + "server.key").toPath()), "/server.key")
.withCopyFileToContainer(MountableFile.forHostPath(getTestResource("ssl.sh").toPath()), "/docker-entrypoint-initdb.d/ssl.sh");
}
if (System.getProperties().containsKey("containerFixedPort")) {
server.withFixedExposedPort(POSTGRESQL_PORT, POSTGRESQL_PORT);
} else {
server.withExposedPorts(POSTGRESQL_PORT);
}
}

private static File getTestResource(String name) throws Exception {
Expand All @@ -99,7 +107,7 @@ public synchronized PgConnectOptions startServer(String databaseVersion) throws
server.start();

return new PgConnectOptions()
.setPort(server.getMappedPort(PostgreSQLContainer.POSTGRESQL_PORT))
.setPort(server.getMappedPort(POSTGRESQL_PORT))
.setHost(server.getContainerIpAddress())
.setDatabase("postgres")
.setUser("postgres")
Expand Down Expand Up @@ -170,4 +178,15 @@ protected void after() {
}
}

private static class ServerContainer<SELF extends ServerContainer<SELF>> extends PostgreSQLContainer<SELF> {

public ServerContainer(String dockerImageName) {
super(dockerImageName);
}

public SELF withFixedExposedPort(int hostPort, int containerPort) {
super.addFixedExposedPort(hostPort, containerPort, InternetProtocol.TCP);
return self();
}
}
}