forked from apache/flink-connector-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-35363] Modify tests to clean up unused docker images
- Loading branch information
1 parent
9d535c6
commit 39ba942
Showing
18 changed files
with
270 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...r-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/testutils/DatabaseResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.apache.flink.connector.jdbc.testutils; | ||
|
||
import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource; | ||
|
||
/** Database resource for testing. */ | ||
public interface DatabaseResource extends CloseableResource { | ||
|
||
void start(); | ||
|
||
void stop(); | ||
|
||
default void close() throws Throwable { | ||
stop(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ore/src/test/java/org/apache/flink/connector/jdbc/testutils/resources/DockerResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.apache.flink.connector.jdbc.testutils.resources; | ||
|
||
import org.apache.flink.connector.jdbc.testutils.DatabaseResource; | ||
|
||
import com.github.dockerjava.api.DockerClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.DockerClientFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.JdbcDatabaseContainer; | ||
|
||
import java.util.Arrays; | ||
|
||
/** Docker based database resource. */ | ||
public class DockerResource implements DatabaseResource { | ||
|
||
protected static final Logger LOG = LoggerFactory.getLogger(DockerResource.class); | ||
|
||
private final JdbcDatabaseContainer<?> container; | ||
|
||
public DockerResource(JdbcDatabaseContainer<?> container) { | ||
this.container = container; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
this.container.start(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
this.container.stop(); | ||
} | ||
|
||
@Override | ||
public void close() throws Throwable { | ||
stop(); | ||
cleanContainers(container); | ||
} | ||
|
||
public static void cleanContainers(GenericContainer<?> container) { | ||
try { | ||
DockerClient client = DockerClientFactory.instance().client(); | ||
// client.removeImageCmd(container.getDockerImageName()).exec(); | ||
client.listImagesCmd().exec().stream() | ||
.filter( | ||
image -> | ||
Arrays.stream(image.getRepoTags()) | ||
.anyMatch( | ||
tag -> | ||
!tag.contains("testcontainers/ryuk") | ||
&& !tag.contains( | ||
container | ||
.getDockerImageName()))) | ||
.forEach(image -> client.removeImageCmd(image.getId()).exec()); | ||
|
||
} catch (Exception ignore) { | ||
LOG.warn("Error deleting image."); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ore/src/test/java/org/apache/flink/connector/jdbc/testutils/resources/MemoryResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.apache.flink.connector.jdbc.testutils.resources; | ||
|
||
import org.apache.flink.connector.jdbc.testutils.DatabaseResource; | ||
|
||
/** Memory based database resource. */ | ||
public interface MemoryResource extends DatabaseResource {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.