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

[Improve][Test] Remove docker image after test finish on jdbc suite #5568

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}