diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/GroupedMongoReactiveIdSegmentDistributorTest.java b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/GroupedMongoReactiveIdSegmentDistributorTest.java index 547b65fce2..2df95e9095 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/GroupedMongoReactiveIdSegmentDistributorTest.java +++ b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/GroupedMongoReactiveIdSegmentDistributorTest.java @@ -15,10 +15,9 @@ import me.ahoo.cosid.mongo.reactive.MongoReactiveIdSegmentDistributorFactory; import me.ahoo.cosid.mongo.reactive.MongoReactiveIdSegmentInitializer; -import me.ahoo.cosid.segment.IdSegmentDistributor; import me.ahoo.cosid.segment.IdSegmentDistributorFactory; +import me.ahoo.cosid.test.container.MongoLauncher; import me.ahoo.cosid.test.segment.distributor.GroupedIdSegmentDistributorSpec; -import me.ahoo.cosid.test.segment.distributor.IdSegmentDistributorSpec; import com.mongodb.reactivestreams.client.MongoClients; import com.mongodb.reactivestreams.client.MongoDatabase; diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentDistributorTest.java b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentDistributorTest.java index b3bd53c9e9..e28a6ac977 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentDistributorTest.java +++ b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentDistributorTest.java @@ -15,6 +15,7 @@ import me.ahoo.cosid.segment.IdSegmentDistributor; import me.ahoo.cosid.segment.IdSegmentDistributorFactory; +import me.ahoo.cosid.test.container.MongoLauncher; import me.ahoo.cosid.test.segment.distributor.IdSegmentDistributorSpec; import com.mongodb.client.MongoClients; diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentInitializerTest.java b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentInitializerTest.java index 2c584dc5d7..bfdd6df322 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentInitializerTest.java +++ b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoIdSegmentInitializerTest.java @@ -16,6 +16,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import me.ahoo.cosid.test.MockIdGenerator; +import me.ahoo.cosid.test.container.MongoLauncher; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoMachineIdDistributorTest.java b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoMachineIdDistributorTest.java index 50eb9b5539..ebc4709f0d 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoMachineIdDistributorTest.java +++ b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoMachineIdDistributorTest.java @@ -16,14 +16,13 @@ import me.ahoo.cosid.machine.ClockBackwardsSynchronizer; import me.ahoo.cosid.machine.MachineIdDistributor; import me.ahoo.cosid.machine.MachineStateStorage; +import me.ahoo.cosid.test.container.MongoLauncher; import me.ahoo.cosid.test.machine.distributor.MachineIdDistributorSpec; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; import org.junit.jupiter.api.BeforeEach; -import java.time.Duration; - class MongoMachineIdDistributorTest extends MachineIdDistributorSpec { MongoDatabase mongoDatabase; MachineIdDistributor machineIdDistributor; diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveIdSegmentDistributorTest.java b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveIdSegmentDistributorTest.java index be28943d5c..2f3a4d0db2 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveIdSegmentDistributorTest.java +++ b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveIdSegmentDistributorTest.java @@ -23,6 +23,7 @@ import me.ahoo.cosid.segment.IdSegmentDistributorFactory; import me.ahoo.cosid.segment.SegmentChainId; import me.ahoo.cosid.test.MockIdGenerator; +import me.ahoo.cosid.test.container.MongoLauncher; import me.ahoo.cosid.test.segment.distributor.IdSegmentDistributorSpec; import com.mongodb.reactivestreams.client.MongoClients; diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveMachineIdDistributorTest.java b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveMachineIdDistributorTest.java index 4a026d5d53..96dc807ff7 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveMachineIdDistributorTest.java +++ b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveMachineIdDistributorTest.java @@ -18,14 +18,13 @@ import me.ahoo.cosid.machine.MachineStateStorage; import me.ahoo.cosid.mongo.reactive.MongoReactiveMachineCollection; import me.ahoo.cosid.mongo.reactive.MongoReactiveMachineInitializer; +import me.ahoo.cosid.test.container.MongoLauncher; import me.ahoo.cosid.test.machine.distributor.MachineIdDistributorSpec; import com.mongodb.reactivestreams.client.MongoClients; import com.mongodb.reactivestreams.client.MongoDatabase; import org.junit.jupiter.api.BeforeEach; -import java.time.Duration; - class MongoReactiveMachineIdDistributorTest extends MachineIdDistributorSpec { MongoDatabase mongoDatabase; MachineIdDistributor machineIdDistributor; diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMongoMachineIdDistributorAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMongoMachineIdDistributorAutoConfigurationTest.java index 9283d8d7b3..c0d82baa7a 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMongoMachineIdDistributorAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMongoMachineIdDistributorAutoConfigurationTest.java @@ -19,8 +19,8 @@ import me.ahoo.cosid.mongo.reactive.MongoReactiveMachineCollection; import me.ahoo.cosid.mongo.reactive.MongoReactiveMachineInitializer; import me.ahoo.cosid.spring.boot.starter.CosIdAutoConfiguration; -import me.ahoo.cosid.spring.boot.starter.mongo.MongoLauncher; import me.ahoo.cosid.test.MockIdGenerator; +import me.ahoo.cosid.test.container.MongoLauncher; import org.assertj.core.api.AssertionsForInterfaceTypes; import org.junit.jupiter.api.Test; diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/mongo/MongoLauncher.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/mongo/MongoLauncher.java deleted file mode 100644 index 77b87670fa..0000000000 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/mongo/MongoLauncher.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package me.ahoo.cosid.spring.boot.starter.mongo; - - -import org.testcontainers.containers.MongoDBContainer; -import org.testcontainers.shaded.com.google.common.base.Strings; -import org.testcontainers.utility.DockerImageName; - -public class MongoLauncher { - private static final String CONNECTION_OPTIONS = "/?connectTimeoutMS=300000&maxIdleTimeMS=300000"; - private static final String DEV_CONNECTION_STRING = "mongodb://root:root@localhost" + CONNECTION_OPTIONS; - private static final MongoDBContainer MONGO_CONTAINER = new MongoDBContainer(DockerImageName.parse("mongo:6.0.12")) - .withNetworkAliases("mongo") - .withReuse(true); - - public static String getConnectionString() { - if (Strings.isNullOrEmpty(System.getenv("CI"))) { - return DEV_CONNECTION_STRING; - } - MONGO_CONTAINER.start(); - return MONGO_CONTAINER.getConnectionString() + CONNECTION_OPTIONS; - - } -} diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/segment/CosIdMongoSegmentAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/segment/CosIdMongoSegmentAutoConfigurationTest.java index 572f2a983b..681b1410f3 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/segment/CosIdMongoSegmentAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/segment/CosIdMongoSegmentAutoConfigurationTest.java @@ -17,7 +17,7 @@ import me.ahoo.cosid.mongo.MongoIdSegmentInitializer; import me.ahoo.cosid.mongo.reactive.MongoReactiveIdSegmentDistributorFactory; import me.ahoo.cosid.mongo.reactive.MongoReactiveIdSegmentInitializer; -import me.ahoo.cosid.spring.boot.starter.mongo.MongoLauncher; +import me.ahoo.cosid.test.container.MongoLauncher; import org.assertj.core.api.AssertionsForInterfaceTypes; import org.junit.jupiter.api.Test; diff --git a/cosid-test/build.gradle.kts b/cosid-test/build.gradle.kts index 51ecd9de56..f86e6398eb 100644 --- a/cosid-test/build.gradle.kts +++ b/cosid-test/build.gradle.kts @@ -13,8 +13,18 @@ description = "CosId test specification module" +java { + registerFeature("mongoSupport") { + usingSourceSet(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]) + capability(group.toString(), "mongo-support", version.toString()) + } +} + dependencies { implementation(project(":cosid-core")) implementation("org.junit.jupiter:junit-jupiter-api") implementation("org.hamcrest:hamcrest") + "mongoSupportImplementation"("org.testcontainers:testcontainers") + "mongoSupportImplementation"("org.testcontainers:junit-jupiter") + "mongoSupportImplementation"("org.testcontainers:mongodb") } diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoLauncher.java b/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java similarity index 97% rename from cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoLauncher.java rename to cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java index 44498390c3..5d0d607386 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoLauncher.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java @@ -11,7 +11,7 @@ * limitations under the License. */ -package me.ahoo.cosid.mongo; +package me.ahoo.cosid.test.container; import org.testcontainers.containers.MongoDBContainer;