Skip to content

Commit

Permalink
[Improve][Test] Remove docker image after test finish on jdbc suite (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hisoka-X authored Sep 27, 2023
1 parent c687050 commit fd77278
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,4 +44,6 @@ public abstract class TestSuiteBase {

@TestContainers
private TestContainersFactory containersFactory = ContainerUtil::discoverTestContainers;

protected DockerClient dockerClient = DockerClientFactory.lazyClient();
}

0 comments on commit fd77278

Please sign in to comment.