From 2bd4a9e50ef0c6a47a7f1e4dfd490cd07e987662 Mon Sep 17 00:00:00 2001 From: Jia Fan Date: Wed, 27 Sep 2023 10:57:31 +0800 Subject: [PATCH] [Improve][Test] Remove docker image after test finish on jdbc suite --- .../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(); }