From fd7727869f8d37c914927e7912b39d06387af0c7 Mon Sep 17 00:00:00 2001 From: Jia Fan Date: Wed, 27 Sep 2023 21:17:36 +0800 Subject: [PATCH] [Improve][Test] Remove docker image after test finish on jdbc suite (#5568) --- .../seatunnel/jdbc/AbstractJdbcIT.java | 18 ++++++++++++++++++ .../seatunnel/e2e/common/TestSuiteBase.java | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-common/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/AbstractJdbcIT.java b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-common/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/AbstractJdbcIT.java index a38fb2217f2..4f3da341753 100644 --- a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-common/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/AbstractJdbcIT.java +++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-common/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/AbstractJdbcIT.java @@ -40,6 +40,7 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.lifecycle.Startables; +import com.github.dockerjava.api.model.Image; import lombok.extern.slf4j.Slf4j; import java.io.IOException; @@ -239,6 +240,23 @@ public void startUp() { public void tearDown() throws SQLException { if (dbServer != null) { dbServer.close(); + String images = + dockerClient.listImagesCmd().exec().stream() + .map(Image::getId) + .collect(Collectors.joining(",")); + log.info( + "before remove image {}, list images: {}", + dbServer.getDockerImageName(), + images); + dockerClient.removeImageCmd(dbServer.getDockerImageName()).exec(); + images = + dockerClient.listImagesCmd().exec().stream() + .map(Image::getId) + .collect(Collectors.joining(",")); + log.info( + "after remove image {}, list images: {}", + dbServer.getDockerImageName(), + images); } if (connection != null) { diff --git a/seatunnel-e2e/seatunnel-e2e-common/src/test/java/org/apache/seatunnel/e2e/common/TestSuiteBase.java b/seatunnel-e2e/seatunnel-e2e-common/src/test/java/org/apache/seatunnel/e2e/common/TestSuiteBase.java index 00f2c6502c2..9e47eb856bc 100644 --- a/seatunnel-e2e/seatunnel-e2e-common/src/test/java/org/apache/seatunnel/e2e/common/TestSuiteBase.java +++ b/seatunnel-e2e/seatunnel-e2e-common/src/test/java/org/apache/seatunnel/e2e/common/TestSuiteBase.java @@ -27,8 +27,11 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.extension.ExtendWith; +import org.testcontainers.DockerClientFactory; import org.testcontainers.containers.Network; +import com.github.dockerjava.api.DockerClient; + @ExtendWith({ ContainerTestingExtension.class, TestLoggerExtension.class, @@ -41,4 +44,6 @@ public abstract class TestSuiteBase { @TestContainers private TestContainersFactory containersFactory = ContainerUtil::discoverTestContainers; + + protected DockerClient dockerClient = DockerClientFactory.lazyClient(); }