diff --git a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverHanoiTest.java b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverHanoiTest.java index 893b280b..cb66f8ce 100644 --- a/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverHanoiTest.java +++ b/bosk-mongo/src/test/java/works/bosk/drivers/mongo/MongoDriverHanoiTest.java @@ -1,24 +1,31 @@ package works.bosk.drivers.mongo; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedDeque; import java.util.stream.Stream; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; +import works.bosk.DriverStack; import works.bosk.drivers.HanoiTest; import works.bosk.junit.ParametersByName; @DisruptsMongoService public class MongoDriverHanoiTest extends HanoiTest { private static MongoService mongoService; + private Queue shutdownOperations = new ConcurrentLinkedDeque<>(); @ParametersByName public MongoDriverHanoiTest(TestParameters.ParameterSet parameters) { MongoDriverSettings settings = parameters.driverSettingsBuilder().build(); - this.driverFactory = MongoDriver.factory( - mongoService.clientSettings(), - settings, - new BsonPlugin() + this.driverFactory = DriverStack.of( + (b,d) -> { shutdownOperations.add(((MongoDriver)d)::close); return d;}, + MongoDriver.factory( + mongoService.clientSettings(), + settings, + new BsonPlugin() + ) ); mongoService.client() .getDatabase(settings.database()) @@ -37,7 +44,9 @@ void logStart(TestInfo testInfo) { @AfterEach void logDone(TestInfo testInfo) { - AbstractMongoDriverTest.logTest("/=== Done", testInfo); + shutdownOperations.forEach(Runnable::run); + shutdownOperations.clear(); + AbstractMongoDriverTest.logTest("\\=== Done", testInfo); } @SuppressWarnings("unused")