DBZ-4339 Migrate from JUnit 4 to 5, rename utility class, fix formatting.

This commit is contained in:
Bobby Tiernay 2022-11-28 10:14:46 -05:00 committed by Jiri Pechanec
parent 950a2a8bdf
commit adb672a87c
6 changed files with 19 additions and 14 deletions

View File

@ -83,7 +83,6 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<!-- By default we need to run these 5 containers, although the two init containers exit quickly -->

View File

@ -27,6 +27,7 @@
import org.testcontainers.shaded.com.fasterxml.jackson.databind.JsonNode;
import io.debezium.testing.testcontainers.MongoDbContainer.Address;
import io.debezium.testing.testcontainers.util.MoreStartables;
/**
* A MongoDB replica set.
@ -146,7 +147,7 @@ public void start() {
// Start all containers in parallel
LOGGER.info("[{}] Starting {} node replica set...", name, memberCount);
MongoDbStartables.deepStart(getDependencies().stream());
MoreStartables.deepStartSync(getDependencies().stream());
// Initialize the configured replica set to contain all the cluster's members
LOGGER.info("[{}] Initializing replica set...", name);
@ -165,7 +166,7 @@ public void start() {
@Override
public void stop() {
LOGGER.info("[{}] Stopping...", name);
MongoDbStartables.deepStop(members.stream());
MoreStartables.deepStopSync(members.stream());
network.close();
}

View File

@ -23,6 +23,8 @@
import org.testcontainers.containers.Network;
import org.testcontainers.lifecycle.Startable;
import io.debezium.testing.testcontainers.util.MoreStartables;
/**
* A MongoDB sharded cluster.
*/
@ -100,7 +102,7 @@ public void start() {
}
LOGGER.info("Starting {} shard cluster...", shards.size());
MongoDbStartables.deepStart(stream());
MoreStartables.deepStartSync(stream());
addShards();
@ -114,7 +116,7 @@ public void start() {
public void stop() {
// Idempotent
LOGGER.info("Stopping {} shard cluster...", shards.size());
MongoDbStartables.deepStop(stream());
MoreStartables.deepStopSync(stream());
network.close();
}

View File

@ -3,7 +3,7 @@
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.testing.testcontainers;
package io.debezium.testing.testcontainers.util;
import static java.util.concurrent.CompletableFuture.runAsync;
@ -15,9 +15,11 @@
import org.testcontainers.lifecycle.Startables;
/**
* Utilities for working with {@link Startable}s in a MongoDB context.
* Utilities for working with {@link Startable}s.
* <p>
* Extends the utilities found in {@link Startables}.
*/
public final class MongoDbStartables {
public final class MoreStartables {
/**
* Start every supplied {@link Startable} recursively and, to the extent possible, in parallel, waiting synchronously
@ -25,7 +27,7 @@ public final class MongoDbStartables {
*
* @param startables the list of startables to {@link Startable#start())
*/
public static void deepStart(Stream<? extends Startable> startables) {
public static void deepStartSync(Stream<? extends Startable> startables) {
try {
Startables.deepStart(startables).get();
}
@ -39,8 +41,9 @@ public static void deepStart(Stream<? extends Startable> startables) {
* on the result.
*
* @param startables the list of startables to {@link Startable#stop())
* @see <a href="https://github.com/testcontainers/testcontainers-java/pull/1404#discussion_r1030949285">deepStop</a>
*/
public static void deepStop(Stream<? extends Startable> startables) {
public static void deepStopSync(Stream<? extends Startable> startables) {
try {
CompletableFuture.allOf(startables
.map(node -> runAsync(node::stop))
@ -52,7 +55,7 @@ public static void deepStop(Stream<? extends Startable> startables) {
}
}
private MongoDbStartables() {
private MoreStartables() {
throw new AssertionError("Should not be instantiated");
}

View File

@ -12,7 +12,7 @@
import org.bson.BsonDocument;
import org.bson.Document;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -14,7 +14,7 @@
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ListAssert;
import org.bson.Document;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -80,7 +80,7 @@ private static ListAssert<Document> assertThatCollection(MongoCollection<Documen
}
private static ListAssert<Document> assertThatShards(MongoClient client) {
return Assertions.assertThat(client
return assertThat(client
.getDatabase("admin")
.runCommand(new BasicDBObject("listShards", 1))
.getList("shards", Document.class));