Skip to content

Commit

Permalink
Shut down MongoDriver after MongoDriverHanoiTest
Browse files Browse the repository at this point in the history
  • Loading branch information
prdoyle committed Jul 6, 2024
1 parent bec9472 commit c2a6630
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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<Runnable> 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())
Expand All @@ -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")
Expand Down

0 comments on commit c2a6630

Please sign in to comment.