-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added refactored testContainers tests
- Loading branch information
1 parent
416f572
commit dcfa8e1
Showing
16 changed files
with
629 additions
and
0 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
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
77 changes: 77 additions & 0 deletions
77
...-server-redis/src/test/java/io/debezium/server/redis/wip/DebeziumServerConfigBuilder.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,77 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.server.redis.wip; | ||
|
||
import static io.debezium.server.redis.wip.TestConstants.MYSQL_DATABASE; | ||
import static io.debezium.server.redis.wip.TestConstants.MYSQL_PASSWORD; | ||
import static io.debezium.server.redis.wip.TestConstants.MYSQL_PORT; | ||
import static io.debezium.server.redis.wip.TestConstants.MYSQL_USER; | ||
import static io.debezium.server.redis.wip.TestConstants.REDIS_PORT; | ||
import static io.debezium.server.redis.wip.TestConstants.REDIS_SSL_PORT; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class DebeziumServerConfigBuilder { | ||
private final Map<String, String> config = new HashMap<>(); | ||
|
||
public DebeziumServerConfigBuilder withValue(String key, String value) { | ||
config.put(key, value); | ||
return this; | ||
} | ||
|
||
public List<String> build() { | ||
return config | ||
.entrySet() | ||
.stream() | ||
.map(e -> e.getKey() + "=" + e.getValue()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static Map<String, String> baseRedisConfig(DebeziumTestContainerWrapper redis) { | ||
return Map.of( | ||
"debezium.sink.type", "redis", | ||
"debezium.sink.redis.address", redis.getContainerAddress() + ":" + REDIS_PORT); | ||
} | ||
|
||
public static Map<String, String> baseSslRedisConfig(DebeziumTestContainerWrapper redis) { | ||
return Map.of( | ||
"debezium.sink.type", "redis", | ||
"debezium.sink.redis.address", redis.getContainerAddress() + ":" + REDIS_SSL_PORT, | ||
"debezium.sink.redis.ssl.enabled", "true", | ||
"debezium.source.database.ssl.mode", "disabled", | ||
"debezium.source.offset.storage", "io.debezium.server.redis.RedisOffsetBackingStore"); | ||
} | ||
|
||
public Map<String, String> baseMySqlConfig(DebeziumTestContainerWrapper mysql) { | ||
Map<String, String> result = new HashMap<>(Map.of("debezium.source.connector.class", "io.debezium.connector.mysql.MySqlConnector", | ||
"debezium.source.offset.flush.interval.ms", "0", | ||
"debezium.source.topic.prefix", "testc", | ||
"debezium.source.database.dbname", MYSQL_DATABASE, | ||
"debezium.source.database.hostname", String.valueOf(mysql.getContainerAddress()), | ||
"debezium.source.database.port", String.valueOf(MYSQL_PORT), | ||
"debezium.source.database.user", MYSQL_USER, | ||
"debezium.source.database.password", MYSQL_PASSWORD, | ||
"debezium.source.database.server.id", "1", | ||
"debezium.source.schema.history.internal", "io.debezium.server.redis.RedisSchemaHistory")); | ||
result.put("debezium.source.offset.storage.file.filename", "offset.dat"); | ||
return result; | ||
} | ||
|
||
public DebeziumServerConfigBuilder withBaseMySqlRedisConfig(DebeziumTestContainerWrapper redis, DebeziumTestContainerWrapper mysql) { | ||
config.putAll(baseRedisConfig(redis)); | ||
config.putAll(baseMySqlConfig(mysql)); | ||
return this; | ||
} | ||
|
||
public DebeziumServerConfigBuilder withBaseMysqlSslRedisConfig(DebeziumTestContainerWrapper redis, DebeziumTestContainerWrapper mysql) { | ||
config.putAll(baseSslRedisConfig(redis)); | ||
config.putAll(baseMySqlConfig(mysql)); | ||
return this; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...server-redis/src/test/java/io/debezium/server/redis/wip/DebeziumTestContainerWrapper.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,64 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.server.redis.wip; | ||
|
||
import static org.awaitility.Awaitility.await; | ||
import static org.testcontainers.containers.output.OutputFrame.OutputType.STDOUT; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.output.OutputFrame; | ||
|
||
import lombok.NonNull; | ||
|
||
public class DebeziumTestContainerWrapper extends GenericContainer<DebeziumTestContainerWrapper> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DebeziumTestContainerWrapper.class); | ||
|
||
private String networkAlias; | ||
|
||
public DebeziumTestContainerWrapper(@NonNull String dockerImageName) { | ||
super(dockerImageName); | ||
} | ||
|
||
public void pause() { | ||
LOGGER.info("Pausing container " + getContainerName()); | ||
getDockerClient().pauseContainerCmd(getContainerId()).exec(); | ||
} | ||
|
||
public void unpause() { | ||
LOGGER.info("Unpausing container " + getContainerName()); | ||
getDockerClient().unpauseContainerCmd(getContainerId()).exec(); | ||
} | ||
|
||
public DebeziumTestContainerWrapper withNetworkAlias(String alias) { | ||
this.networkAlias = alias; | ||
return super.withNetworkAliases(alias); | ||
} | ||
|
||
public String getContainerAddress() { | ||
return networkAlias; | ||
} | ||
|
||
public String getStandardOutput() { | ||
return getLogs(STDOUT); | ||
} | ||
|
||
public void waitForContainerLog(String log) { | ||
await() | ||
.atMost(60, TimeUnit.SECONDS) | ||
.until(() -> getLogs(OutputFrame.OutputType.STDOUT).contains(log)); | ||
} | ||
|
||
public void waitForStop() { | ||
await() | ||
.atMost(60, TimeUnit.SECONDS) | ||
.until(() -> !isRunning()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
debezium-server-redis/src/test/java/io/debezium/server/redis/wip/TestConstants.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,30 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.server.redis.wip; | ||
|
||
public class TestConstants { | ||
private TestConstants() { | ||
// intentionally private | ||
} | ||
|
||
public static final int INITIAL_CUSTOMER_COUNT = 4; | ||
public static final int INITIAL_SCHEMA_HISTORY_SIZE = 16; | ||
public static final String LOCALHOST = "localhost"; | ||
|
||
// REDIS | ||
public static final String REDIS_IMAGE = "redis"; | ||
public static final int REDIS_PORT = 6379; | ||
public static final int REDIS_SSL_PORT = 6378; | ||
|
||
// MYSQL | ||
public static final String MYSQL_USER = "debezium"; | ||
public static final String MYSQL_PASSWORD = "dbz"; | ||
public static final String MYSQL_ROOT_PASSWORD = "debezium"; | ||
public static final String MYSQL_DATABASE = "inventory"; | ||
public static final String MYSQL_PRIVILEGED_USER = "mysqluser"; | ||
public static final String MYSQL_PRIVILEGED_PASSWORD = "mysqlpassword"; | ||
public static final int MYSQL_PORT = 3306; | ||
} |
77 changes: 77 additions & 0 deletions
77
...-server-redis/src/test/java/io/debezium/server/redis/wip/TestContainersRedisTestBase.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,77 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.server.redis.wip; | ||
|
||
import static io.debezium.server.redis.wip.TestConstants.LOCALHOST; | ||
import static io.debezium.server.redis.wip.TestConstants.MYSQL_PORT; | ||
import static io.debezium.server.redis.wip.TestConstants.MYSQL_PRIVILEGED_PASSWORD; | ||
import static io.debezium.server.redis.wip.TestConstants.MYSQL_PRIVILEGED_USER; | ||
import static io.debezium.server.redis.wip.TestConstants.MYSQL_ROOT_PASSWORD; | ||
import static io.debezium.server.redis.wip.TestConstants.REDIS_IMAGE; | ||
import static io.debezium.server.redis.wip.TestConstants.REDIS_PORT; | ||
import static io.debezium.server.redis.wip.TestProperties.DEBEZIUM_SERVER_IMAGE; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.testcontainers.containers.BindMode; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
import redis.clients.jedis.HostAndPort; | ||
import redis.clients.jedis.Jedis; | ||
|
||
public class TestContainersRedisTestBase { | ||
protected DebeziumTestContainerWrapper redis; | ||
protected DebeziumTestContainerWrapper server; | ||
protected DebeziumTestContainerWrapper mysql; | ||
protected Jedis jedis; | ||
|
||
public TestContainersRedisTestBase() { | ||
// provide base configuration for all components | ||
Network network = Network.newNetwork(); | ||
|
||
mysql = new DebeziumTestContainerWrapper("quay.io/debezium/example-mysql") | ||
.withNetwork(network) | ||
.withNetworkAlias("mysql") | ||
.waitingFor(Wait.forLogMessage(".*mysqld: ready for connections.*", 2)) | ||
.withEnv("MYSQL_ROOT_PASSWORD", MYSQL_ROOT_PASSWORD) | ||
.withEnv("MYSQL_USER", MYSQL_PRIVILEGED_USER) | ||
.withEnv("MYSQL_PASSWORD", MYSQL_PRIVILEGED_PASSWORD) | ||
.withExposedPorts(MYSQL_PORT) | ||
.withStartupTimeout(Duration.ofSeconds(180)); | ||
redis = new DebeziumTestContainerWrapper(REDIS_IMAGE) | ||
.withClasspathResourceMapping("redis", "/etc/redis", BindMode.READ_ONLY) | ||
.withNetwork(network) | ||
.withNetworkAlias("redis") | ||
.withExposedPorts(REDIS_PORT); | ||
server = new DebeziumTestContainerWrapper(DEBEZIUM_SERVER_IMAGE) | ||
.withNetwork(network) | ||
.withCommand("-jar", "quarkus-run.jar"); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
mysql.start(); | ||
redis.start(); | ||
jedis = new Jedis(HostAndPort.from(LOCALHOST + ":" + redis.getMappedPort(REDIS_PORT))); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
server.stop(); | ||
mysql.stop(); | ||
redis.stop(); | ||
} | ||
|
||
protected void startServerWithEnv(List<String> env) { | ||
server.setEnv(env); | ||
server.start(); | ||
} | ||
|
||
} |
Oops, something went wrong.