-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Combine DB container tests into single module, and improve error handling/display #243
Changes from all commits
6b08454
4f939b3
6a40eda
65811f8
60277c9
408e983
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import com.github.dockerjava.api.exception.DockerException; | ||
import com.github.dockerjava.api.exception.InternalServerErrorException; | ||
import com.github.dockerjava.api.exception.NotFoundException; | ||
import com.github.dockerjava.api.model.Container; | ||
import com.github.dockerjava.api.model.Network; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -67,6 +68,8 @@ public void registerContainerForCleanup(String containerId, String imageName) { | |
*/ | ||
public void stopAndRemoveContainer(String containerId) { | ||
stopContainer(containerId, registeredContainers.get(containerId)); | ||
|
||
registeredContainers.remove(containerId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should do it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually even though it's a little brittle I'd prefer to keep it that way. If |
||
} | ||
|
||
/** | ||
|
@@ -83,6 +86,13 @@ public void stopAndRemoveContainer(String containerId, String imageName) { | |
|
||
private void stopContainer(String containerId, String imageName) { | ||
|
||
List<Container> allContainers = dockerClient.listContainersCmd().withShowAll(true).exec(); | ||
|
||
if (allContainers.stream().map(Container::getId).noneMatch(containerId::equals)) { | ||
LOGGER.trace("Was going to clean up container but it apparently no longer exists: {}"); | ||
return; | ||
} | ||
|
||
boolean running; | ||
try { | ||
InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(containerId).exec(); | ||
|
@@ -105,6 +115,13 @@ private void stopContainer(String containerId, String imageName) { | |
} | ||
} | ||
|
||
try { | ||
dockerClient.inspectContainerCmd(containerId).exec(); | ||
} catch (NotFoundException e) { | ||
LOGGER.trace("Was going to remove container but it apparently no longer exists: {}"); | ||
return; | ||
} | ||
|
||
try { | ||
LOGGER.trace("Removing container: {}", containerId); | ||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers-parent</artifactId> | ||
<version>1.1.7-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>jdbc-test</artifactId> | ||
<name>TestContainers :: JDBC :: Tests</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mysql</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mariadb</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- Database drivers for testing --> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>9.3-1101-jdbc41</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>5.1.35</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mariadb.jdbc</groupId> | ||
<artifactId>mariadb-java-client</artifactId> | ||
<version>1.4.6</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Database connection pools for testing --> | ||
<dependency> | ||
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP-java6</artifactId> | ||
<version>2.3.8</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.tomcat</groupId> | ||
<artifactId>tomcat-jdbc</artifactId> | ||
<version>8.5.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.vibur</groupId> | ||
<artifactId>vibur-dbcp</artifactId> | ||
<version>9.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-dbutils</groupId> | ||
<artifactId>commons-dbutils</artifactId> | ||
<version>1.6</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>proprietary-deps</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>oracle-xe</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- Oracle JDBC Driver --> | ||
<dependency> | ||
<groupId>com.oracle</groupId> | ||
<artifactId>ojdbc6</artifactId> | ||
<version>11.2.0.4</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.19.1</version> | ||
<executions> | ||
<execution> | ||
<id>test-proprietary-deps</id> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
<configuration> | ||
<testSourceDirectory>src/testProprietary/java</testSourceDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch!