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

getLivenessCheckPortNumbers() should return mapped port #5734

Merged
merged 27 commits into from Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1a5fb3e
getLivenessCheckPortNumbers() should return mapped port
aidando73 Aug 16, 2022
4b68ef3
refactor to exclude unnecessary getLivenessCheckPortNumbers override
aidando73 Aug 18, 2022
4612773
MySQL liveness check port numbers were missing
aidando73 Aug 18, 2022
707fce0
Apply formatting
aidando73 Aug 18, 2022
305ec3c
Merge remote-tracking branch 'upstream/master' into get-liveness-chec…
aidando73 Aug 19, 2022
0441361
Merge branch 'master' into get-liveness-check-mapped-port
kiview Aug 19, 2022
ccfbf79
Make fixes binary compatible
aidando73 Aug 20, 2022
851a557
Merge branch 'get-liveness-check-mapped-port' of github.com:REslim30/…
aidando73 Aug 20, 2022
6b72b41
Merge branch 'master' into get-liveness-check-mapped-port
kiview Aug 23, 2022
f6db6e4
Nginx module to use super liveness check ports
aidando73 Aug 23, 2022
d909ee3
add deprecated warnings to inherited deprecated methods
aidando73 Aug 23, 2022
94e8ad3
PostgresSQL to use super class getLivenessCheckPorts
aidando73 Aug 23, 2022
1342ae1
presto container to use correct liveness check ports and also use sup…
aidando73 Aug 23, 2022
5ad92e9
tidb container to use super class liveness check ports
aidando73 Aug 23, 2022
210e304
trino container to get liveness check ports from super class
aidando73 Aug 23, 2022
84595d7
Db2 container to use super class liveness check ports
aidando73 Aug 23, 2022
90468fb
Merge branch 'get-liveness-check-mapped-port' of github.com:REslim30/…
aidando73 Aug 23, 2022
ccf58b4
apply code formatter
aidando73 Aug 23, 2022
83ef259
Add forgotten renamed files
aidando73 Aug 25, 2022
e38c47e
undo rename on test
aidando73 Sep 3, 2022
f9a2745
undo rename on tests
aidando73 Sep 3, 2022
8069018
Use an assertion instead of an extra test
aidando73 Sep 3, 2022
d80f509
Use an assertion instead of an extra test
aidando73 Sep 3, 2022
3ea042c
spotless apply
aidando73 Sep 3, 2022
286e9d3
use static variable for mssql and db2 ports
aidando73 Sep 3, 2022
54ae626
Merge remote-tracking branch 'upstream/master' into get-liveness-chec…
aidando73 Sep 3, 2022
5e1bef9
removed @Test anotation on assertion
aidando73 Sep 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -6,7 +6,6 @@

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Set;

public class Db2Container extends JdbcDatabaseContainer<Db2Container> {
Expand Down Expand Up @@ -54,9 +53,14 @@ public Db2Container(final DockerImageName dockerImageName) {
addExposedPort(DB2_PORT);
}

/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return new HashSet<>(getMappedPort(DB2_PORT));
return super.getLivenessCheckPorts();
}

@Override
Expand Down
Expand Up @@ -21,6 +21,7 @@ public void testSimple() throws SQLException {

int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
assertHasCorrectExposedAndLivenessCheckPorts(db2);
}
}

Expand All @@ -37,4 +38,9 @@ public void testWithAdditionalUrlParamInJdbcUrl() {
assertThat(jdbcUrl).contains(":sslConnection=false;");
}
}

private void assertHasCorrectExposedAndLivenessCheckPorts(Db2Container db2) {
assertThat(db2.getExposedPorts()).containsExactly(Db2Container.DB2_PORT);
assertThat(db2.getLivenessCheckPortNumbers()).containsExactly(db2.getMappedPort(Db2Container.DB2_PORT));
}
}
@@ -1,6 +1,5 @@
package org.testcontainers.containers;

import com.google.common.collect.Sets;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.LicenseAcceptance;

Expand Down Expand Up @@ -64,7 +63,7 @@ public MSSQLServerContainer(final DockerImageName dockerImageName) {

@Override
public Set<Integer> getLivenessCheckPortNumbers() {
return Sets.newHashSet(MS_SQL_SERVER_PORT);
return super.getLivenessCheckPortNumbers();
}
aidando73 marked this conversation as resolved.
Show resolved Hide resolved

@Override
Expand Down
Expand Up @@ -25,6 +25,7 @@ public void testSimple() throws SQLException {

int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
assertHasCorrectExposedAndLivenessCheckPorts(mssqlServer);
}
}

Expand Down Expand Up @@ -64,4 +65,10 @@ public void testSetupDatabase() throws SQLException {
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(3);
}
}

private void assertHasCorrectExposedAndLivenessCheckPorts(MSSQLServerContainer<?> mssqlServer) {
assertThat(mssqlServer.getExposedPorts()).containsExactly(MSSQLServerContainer.MS_SQL_SERVER_PORT);
assertThat(mssqlServer.getLivenessCheckPortNumbers())
.containsExactly(mssqlServer.getMappedPort(MSSQLServerContainer.MS_SQL_SERVER_PORT));
}
aidando73 marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Up @@ -3,7 +3,6 @@
import org.jetbrains.annotations.NotNull;
import org.testcontainers.utility.DockerImageName;

import java.util.HashSet;
import java.util.Set;

/**
Expand Down Expand Up @@ -56,10 +55,15 @@ public MySQLContainer(final DockerImageName dockerImageName) {
addExposedPort(MYSQL_PORT);
}

/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return new HashSet<>(getMappedPort(MYSQL_PORT));
aidando73 marked this conversation as resolved.
Show resolved Hide resolved
return super.getLivenessCheckPorts();
aidando73 marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
Expand Up @@ -57,6 +57,7 @@ public void testSimple() throws SQLException {
int resultSetInt = resultSet.getInt(1);

assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
assertHasCorrectExposedAndLivenessCheckPorts(mysql);
}
}

Expand Down Expand Up @@ -237,4 +238,9 @@ public void testWithAdditionalUrlParamInJdbcUrl() {
mysql.stop();
}
}

private void assertHasCorrectExposedAndLivenessCheckPorts(MySQLContainer<?> mysql) {
assertThat(mysql.getExposedPorts()).containsExactly(MySQLContainer.MYSQL_PORT);
assertThat(mysql.getLivenessCheckPortNumbers()).containsExactly(mysql.getMappedPort(MySQLContainer.MYSQL_PORT));
}
}
Expand Up @@ -6,7 +6,6 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Set;

/**
Expand Down Expand Up @@ -42,10 +41,15 @@ public NginxContainer(final DockerImageName dockerImageName) {
setCommand("nginx", "-g", "daemon off;");
}

/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return Collections.singleton(getMappedPort(80));
return super.getLivenessCheckPorts();
}

public URL getBaseUrl(String scheme, int port) throws MalformedURLException {
Expand Down
Expand Up @@ -58,6 +58,12 @@ public void testSimple() throws Exception {
.as("An HTTP GET from the Nginx server returns the index.html from the custom content directory")
.contains("Hello World!");
// }
assertHasCorrectExposedAndLivenessCheckPorts(nginx);
}

private void assertHasCorrectExposedAndLivenessCheckPorts(NginxContainer<?> nginxContainer) throws Exception {
assertThat(nginxContainer.getExposedPorts()).containsExactly(80);
assertThat(nginxContainer.getLivenessCheckPortNumbers()).containsExactly(nginxContainer.getMappedPort(80));
}

private static String responseFromNginx(URL baseUrl) throws IOException {
Expand Down
Expand Up @@ -6,7 +6,6 @@

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Set;

/**
Expand Down Expand Up @@ -62,10 +61,15 @@ public PostgreSQLContainer(final DockerImageName dockerImageName) {
addExposedPort(POSTGRESQL_PORT);
}

/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return Collections.singleton(getMappedPort(POSTGRESQL_PORT));
return super.getLivenessCheckPorts();
}

@Override
Expand Down
Expand Up @@ -26,6 +26,7 @@ public void testSimple() throws SQLException {
ResultSet resultSet = performQuery(postgres, "SELECT 1");
int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1);
assertHasCorrectExposedAndLivenessCheckPorts(postgres);
}
}

Expand Down Expand Up @@ -86,4 +87,10 @@ public void testWithAdditionalUrlParamInJdbcUrl() {
assertThat(jdbcUrl).contains("charSet=UNICODE");
}
}

private void assertHasCorrectExposedAndLivenessCheckPorts(PostgreSQLContainer<?> postgres) {
assertThat(postgres.getExposedPorts()).containsExactly(PostgreSQLContainer.POSTGRESQL_PORT);
assertThat(postgres.getLivenessCheckPortNumbers())
.containsExactly(postgres.getMappedPort(PostgreSQLContainer.POSTGRESQL_PORT));
}
}
Expand Up @@ -9,7 +9,6 @@
import java.sql.SQLException;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Set;

/**
Expand Down Expand Up @@ -56,10 +55,15 @@ public PrestoContainer(final DockerImageName dockerImageName) {
addExposedPort(PRESTO_PORT);
}

/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return new HashSet<>(getMappedPort(PRESTO_PORT));
return super.getLivenessCheckPorts();
}

@Override
Expand Down
Expand Up @@ -32,6 +32,7 @@ public void testSimple() throws Exception {
assertThat(resultSet.getString("node_version"))
.as("Presto version")
.isEqualTo(PrestoContainer.DEFAULT_TAG);
assertHasCorrectExposedAndLivenessCheckPorts(prestoSql);
}
}
}
Expand Down Expand Up @@ -149,4 +150,10 @@ public void testTcJdbcUri() throws Exception {
.isEqualTo(Connection.TRANSACTION_READ_UNCOMMITTED);
}
}

private void assertHasCorrectExposedAndLivenessCheckPorts(PrestoContainer<?> prestoSql) {
assertThat(prestoSql.getExposedPorts()).containsExactly(PrestoContainer.PRESTO_PORT);
assertThat(prestoSql.getLivenessCheckPortNumbers())
.containsExactly(prestoSql.getMappedPort(PrestoContainer.PRESTO_PORT));
}
}
Expand Up @@ -6,7 +6,6 @@
import org.testcontainers.utility.DockerImageName;

import java.time.Duration;
import java.util.HashSet;
import java.util.Set;

/**
Expand Down Expand Up @@ -51,10 +50,15 @@ public TiDBContainer(final DockerImageName dockerImageName) {
);
}

/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return new HashSet<>(getMappedPort(TIDB_PORT));
return super.getLivenessCheckPorts();
}

@Override
Expand Down
Expand Up @@ -21,6 +21,7 @@ public void testSimple() throws SQLException {

int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).isEqualTo(1);
assertHasCorrectExposedAndLivenessCheckPorts(tidb);
}
}

Expand Down Expand Up @@ -51,4 +52,13 @@ public void testWithAdditionalUrlParamInJdbcUrl() {
tidb.stop();
}
}

private void assertHasCorrectExposedAndLivenessCheckPorts(TiDBContainer tidb) {
Integer tidbPort = 4000;
Integer restApiPort = 10080;

assertThat(tidb.getExposedPorts()).containsExactlyInAnyOrder(tidbPort, restApiPort);
assertThat(tidb.getLivenessCheckPortNumbers())
.containsExactlyInAnyOrder(tidb.getMappedPort(tidbPort), tidb.getMappedPort(restApiPort));
}
}
Expand Up @@ -7,7 +7,6 @@

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;

public class TrinoContainer extends JdbcDatabaseContainer<TrinoContainer> {
Expand Down Expand Up @@ -37,10 +36,15 @@ public TrinoContainer(final DockerImageName dockerImageName) {
addExposedPort(TRINO_PORT);
}

/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return new HashSet<>(getMappedPort(TRINO_PORT));
return super.getLivenessCheckPorts();
}

@Override
Expand Down
Expand Up @@ -24,6 +24,7 @@ public void testSimple() throws Exception {
assertThat(resultSet.getString("node_version"))
.as("Trino version")
.isEqualTo(TrinoContainer.DEFAULT_TAG);
assertContainerHasCorrectExposedAndLivenessCheckPorts(trino);
}
}
}
Expand Down Expand Up @@ -61,4 +62,9 @@ public void testInitScript() throws Exception {
}
}
}

private void assertContainerHasCorrectExposedAndLivenessCheckPorts(TrinoContainer trino) {
assertThat(trino.getExposedPorts()).containsExactly(8080);
assertThat(trino.getLivenessCheckPortNumbers()).containsExactly(trino.getMappedPort(8080));
}
aidando73 marked this conversation as resolved.
Show resolved Hide resolved
}