Skip to content

Commit

Permalink
[e2e] Remove db docker image after test cases are executed. (#2508)
Browse files Browse the repository at this point in the history
(cherry picked from commit aec2a91)
  • Loading branch information
GOODBOY008 committed Oct 30, 2023
1 parent 31b7b79 commit e850811
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ververica.cdc.connectors.tests.utils.JdbcProxy;
import com.ververica.cdc.connectors.tests.utils.TestUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
Expand Down Expand Up @@ -55,15 +56,17 @@ public class Db2E2eITCase extends FlinkContainerTestEnvironment {
private static final Path db2CdcJar = TestUtils.getResource("db2-cdc-connector.jar");
private static final Path mysqlDriverJar = TestUtils.getResource("mysql-driver.jar");

public static final String DB2_IMAGE = "ibmcom/db2";
public static final String DB2_CUSTOM_IMAGE = "custom/db2-cdc:1.4";
private static final DockerImageName DEBEZIUM_DOCKER_IMAGE_NAME =
DockerImageName.parse(
new ImageFromDockerfile("custom/db2-cdc:1.4")
new ImageFromDockerfile(DB2_CUSTOM_IMAGE)
.withDockerfile(getFilePath("docker/db2/Dockerfile"))
.get())
.asCompatibleSubstituteFor("ibmcom/db2");
.asCompatibleSubstituteFor(DB2_IMAGE);
private static boolean db2AsnAgentRunning = false;

private Db2Container db2Container;
private static Db2Container db2Container;

@Before
public void before() {
Expand Down Expand Up @@ -111,6 +114,23 @@ public void after() {
super.after();
}

@AfterClass
public static void afterClass() {
// Cleanup the db2 image, because it's too large and will cause the next test to fail.
db2Container.getDockerClient().removeImageCmd(DB2_CUSTOM_IMAGE).exec();
db2Container
.getDockerClient()
.listImagesCmd()
.withImageNameFilter(DB2_IMAGE)
.exec()
.forEach(
image ->
db2Container
.getDockerClient()
.removeImageCmd(image.getId())
.exec());
}

@Test
public void testDb2CDC() throws Exception {
List<String> sqlLines =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ververica.cdc.connectors.tests.utils.JdbcProxy;
import com.ververica.cdc.connectors.tests.utils.TestUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
Expand Down Expand Up @@ -53,13 +54,13 @@ public class OracleE2eITCase extends FlinkContainerTestEnvironment {

private static final Path oracleCdcJar = TestUtils.getResource("oracle-cdc-connector.jar");
private static final Path mysqlDriverJar = TestUtils.getResource("mysql-driver.jar");

public OracleContainer oracle;
private static OracleContainer oracle;

@Before
public void before() {
super.before();
LOG.info("Starting containers...");

oracle =
new OracleContainer(ORACLE_IMAGE)
.withNetwork(NETWORK)
Expand All @@ -77,6 +78,16 @@ public void after() {
super.after();
}

@AfterClass
public static void afterClass() {
// Cleanup the oracle image, because it's too large and will cause the next test to fail.
oracle.getDockerClient()
.listImagesCmd()
.withImageNameFilter(ORACLE_IMAGE)
.exec()
.forEach(image -> oracle.getDockerClient().removeImageCmd(image.getId()).exec());
}

@Test
public void testOracleCDC() throws Exception {
List<String> sqlLines =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import com.ververica.cdc.connectors.tests.utils.JdbcProxy;
import com.ververica.cdc.connectors.tests.utils.TestUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.lifecycle.Startables;
Expand Down Expand Up @@ -58,6 +60,7 @@ public class SqlServerE2eITCase extends FlinkContainerTestEnvironment {
private static final Path sqlServerCdcJar =
TestUtils.getResource("sqlserver-cdc-connector.jar");
private static final Path mysqlDriverJar = TestUtils.getResource("mysql-driver.jar");
public static final String MSSQL_SERVER_IMAGE = "mcr.microsoft.com/mssql/server:2019-latest";

@Parameterized.Parameter(1)
public boolean parallelismSnapshot;
Expand All @@ -75,7 +78,7 @@ public static List<Object[]> parameters() {

@Rule
public MSSQLServerContainer sqlServer =
new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2019-latest")
new MSSQLServerContainer<>(MSSQL_SERVER_IMAGE)
.withPassword("Password!")
.withEnv("MSSQL_AGENT_ENABLED", "true")
.withEnv("MSSQL_PID", "Standard")
Expand All @@ -100,6 +103,12 @@ public void after() {
super.after();
}

@AfterClass
public static void afterClass() {
// Cleanup the sqlserver image, because it's too large and will cause the next test to fail.
DockerClientFactory.instance().client().removeImageCmd(MSSQL_SERVER_IMAGE).exec();
}

@Test
public void testSqlServerCDC() throws Exception {
List<String> sqlLines =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ververica.cdc.connectors.tests.utils.JdbcProxy;
import com.ververica.cdc.connectors.tests.utils.TestUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
Expand Down Expand Up @@ -141,6 +142,16 @@ public void after() {
super.after();
}

@AfterClass
public static void afterClass() {
// Cleanup the TIDB image, because it's too large and will cause the next test to fail.
TIDB.getDockerClient()
.listImagesCmd()
.withImageNameFilter("pingcap/tikv")
.exec()
.forEach(image -> TIDB.getDockerClient().removeImageCmd(image.getId()).exec());
}

@Test
public void testTIDBCDC() throws Exception {
List<String> sqlLines =
Expand Down
2 changes: 1 addition & 1 deletion tools/azure-pipelines/jobs-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
displayName: "Set JDK"
# Compile
- script: |
./tools/ci/compile.sh default || exit $?
./tools/ci/compile.sh || exit $?
./tools/azure-pipelines/create_build_artifact.sh
displayName: Compile
Expand Down

0 comments on commit e850811

Please sign in to comment.