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 cleanup unused docker images
- Loading branch information
Showing
19 changed files
with
280 additions
and
156 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(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...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,58 @@ | ||
package org.apache.flink.connector.jdbc.testutils.resources; | ||
|
||
import org.apache.flink.connector.jdbc.testutils.DatabaseResource; | ||
|
||
import com.github.dockerjava.api.DockerClient; | ||
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 { | ||
|
||
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) { | ||
System.out.println("ERROR:"); | ||
ignore.printStackTrace(); | ||
} | ||
} | ||
} |
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.