Skip to content

Commit

Permalink
Merge pull request quarkusio#19648 from geoand/tc-116
Browse files Browse the repository at this point in the history
Bump testcontainers to 1.16
  • Loading branch information
geoand authored Aug 26, 2021
2 parents 5930131 + 0e69d68 commit 6299721
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 44 deletions.
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@
<avro.version>1.10.2</avro.version>
<apicurio-registry.version>2.0.1.Final</apicurio-registry.version>
<jacoco.version>0.8.7</jacoco.version>
<testcontainers.version>1.15.3</testcontainers.version>
<docker-java.version>3.2.8</docker-java.version> <!-- must be the version Testcontainers use -->
<testcontainers.version>1.16.0</testcontainers.version>
<docker-java.version>3.2.11</docker-java.version> <!-- must be the version Testcontainers use -->
<aesh-readline.version>2.1</aesh-readline.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public static String configureSharedNetwork(GenericContainer<?> container, Strin
String hostName = hostNamePrefix + "-" + Base58.randomString(5);
container.setNetworkAliases(Collections.singletonList(hostName));

// we need to clear the exposed ports as they don't make sense when the application is going to
// to be communicating with the DB over the same network
container.setExposedPorts(Collections.emptyList());
return hostName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ DevServicesDatasourceProviderBuildItem setupDB2(
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode) {
Db2Container container = new QuarkusDb2Container(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent())
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
QuarkusDb2Container container = new QuarkusDb2Container(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent());
container.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
additionalProperties.forEach(container::withUrlParam);
container.start();

LOG.info("Dev Services for IBM Db2 started.");

return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
return new RunningDevServicesDatasource(container.getEffectiveJdbcUrl(), container.getUsername(),
container.getPassword(),
new Closeable() {
@Override
Expand Down Expand Up @@ -86,8 +86,11 @@ protected void configure() {
}
}

@Override
public String getJdbcUrl() {
// this is meant to be called by Quarkus code and is not strictly needed
// in the DB2 case as testcontainers does not try to establish
// a connection to determine if the container is ready, but we do it anyway to be consistent across
// DB containers
public String getEffectiveJdbcUrl() {
if (useSharedNetwork) {
// in this case we expose the URL using the network alias we created in 'configure'
// and the container port since the application communicating with this container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ DevServicesDatasourceProviderBuildItem setupMariaDB(
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode) {
MariaDBContainer container = new QuarkusMariaDBContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent())
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
QuarkusMariaDBContainer container = new QuarkusMariaDBContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent());
container.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
additionalProperties.forEach(container::withUrlParam);
container.start();

LOG.info("Dev Services for MariaDB started.");

return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
return new RunningDevServicesDatasource(container.getEffectiveJdbcUrl(), container.getUsername(),
container.getPassword(),
new Closeable() {
@Override
Expand Down Expand Up @@ -84,8 +84,9 @@ protected void configure() {
}
}

@Override
public String getJdbcUrl() {
// this is meant to be called by Quarkus code and is needed in order to not disrupt testcontainers
// from being able to determine the status of the container (which it does by trying to acquire a connection)
public String getEffectiveJdbcUrl() {
if (useSharedNetwork) {
String additionalUrlParams = constructUrlParameters("?", "&");
return "jdbc:mariadb://" + hostName + ":" + PORT + "/" + getDatabaseName() + additionalUrlParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.OptionalInt;

import org.jboss.logging.Logger;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.utility.DockerImageName;

Expand Down Expand Up @@ -36,15 +35,15 @@ DevServicesDatasourceProviderBuildItem setupMSSQL(
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode) {
JdbcDatabaseContainer container = new QuarkusMSSQLServerContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent())
.withPassword(password.orElse("Quarkuspassword1"));
QuarkusMSSQLServerContainer container = new QuarkusMSSQLServerContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent());
container.withPassword(password.orElse("Quarkuspassword1"));
additionalProperties.forEach(container::withUrlParam);
container.start();

LOG.info("Dev Services for Microsoft SQL Server started.");

return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
return new RunningDevServicesDatasource(container.getEffectiveJdbcUrl(), container.getUsername(),
container.getPassword(),
new Closeable() {
@Override
Expand Down Expand Up @@ -86,8 +85,9 @@ protected void configure() {
}
}

@Override
public String getJdbcUrl() {
// this is meant to be called by Quarkus code and is needed in order to not disrupt testcontainers
// from being able to determine the status of the container (which it does by trying to acquire a connection)
public String getEffectiveJdbcUrl() {
if (useSharedNetwork) {
// in this case we expose the URL using the network alias we created in 'configure'
// and the container port since the application communicating with this container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ DevServicesDatasourceProviderBuildItem setupMysql(
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode) {
MySQLContainer container = new QuarkusMySQLContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent())
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
QuarkusMySQLContainer container = new QuarkusMySQLContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent());
container.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
additionalProperties.forEach(container::withUrlParam);
container.start();

LOG.info("Dev Services for MySQL started.");

return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
return new RunningDevServicesDatasource(container.getEffectiveJdbcUrl(), container.getUsername(),
container.getPassword(),
new Closeable() {
@Override
Expand Down Expand Up @@ -83,8 +83,9 @@ protected void configure() {
}
}

@Override
public String getJdbcUrl() {
// this is meant to be called by Quarkus code and is needed in order to not disrupt testcontainers
// from being able to determine the status of the container (which it does by trying to acquire a connection)
public String getEffectiveJdbcUrl() {
if (useSharedNetwork) {
// in this case we expose the URL using the network alias we created in 'configure'
// and the container port since the application communicating with this container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ DevServicesDatasourceProviderBuildItem setupPostgres(
public RunningDevServicesDatasource startDatabase(Optional<String> username, Optional<String> password,
Optional<String> datasourceName, Optional<String> imageName, Map<String, String> additionalProperties,
OptionalInt fixedExposedPort, LaunchMode launchMode) {
PostgreSQLContainer container = new QuarkusPostgreSQLContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent())
.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
QuarkusPostgreSQLContainer container = new QuarkusPostgreSQLContainer(imageName, fixedExposedPort,
devServicesSharedNetworkBuildItem.isPresent());
container.withPassword(password.orElse("quarkus"))
.withUsername(username.orElse("quarkus"))
.withDatabaseName(datasourceName.orElse("default"));
additionalProperties.forEach(container::withUrlParam);

container.start();

LOG.info("Dev Services for PostgreSQL started.");

return new RunningDevServicesDatasource(container.getJdbcUrl(), container.getUsername(),
return new RunningDevServicesDatasource(container.getEffectiveJdbcUrl(), container.getUsername(),
container.getPassword(),
new Closeable() {
@Override
Expand Down Expand Up @@ -84,8 +84,11 @@ protected void configure() {
}
}

@Override
public String getJdbcUrl() {
// this is meant to be called by Quarkus code and is not strictly needed
// in the PostgreSQL case as testcontainers does not try to establish
// a connection to determine if the container is ready, but we do it anyway to be consistent across
// DB containers
public String getEffectiveJdbcUrl() {
if (useSharedNetwork) {
// in this case we expose the URL using the network alias we created in 'configure'
// and the container port since the application communicating with this container
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/container-image/maven-invoker-way/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
</goals>
</execution>
</executions>
<configuration>
<skip>${skipTests}</skip>
</configuration>
</plugin>
</plugins>
</build>
Expand Down

0 comments on commit 6299721

Please sign in to comment.