From 9f181b9ddff11547b163cf8f61813f5c68978f76 Mon Sep 17 00:00:00 2001 From: Dean Wette Date: Mon, 10 Apr 2023 11:06:19 -0500 Subject: [PATCH 1/4] Remove flapdoodle for testing and update docs. --- gradle/libs.versions.toml | 2 - mongo-core/build.gradle | 1 - .../test/AbstractMongoProcessFactory.java | 81 ------------------- .../mongo/core/test/MongoProcessFactory.java | 65 --------------- src/main/docs/guide/breaks.adoc | 2 + src/main/docs/guide/testing.adoc | 9 +-- src/main/docs/guide/toc.yml | 3 +- 7 files changed, 7 insertions(+), 156 deletions(-) delete mode 100644 mongo-core/src/main/java/io/micronaut/configuration/mongo/core/test/AbstractMongoProcessFactory.java delete mode 100644 mongo-core/src/main/java/io/micronaut/configuration/mongo/core/test/MongoProcessFactory.java create mode 100644 src/main/docs/guide/breaks.adoc diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 78ff9e30..73b77616 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,6 @@ testcontainers = "1.17.6" managed-mongo = "4.8.0" managed-mongo-reactive = "4.8.0" -flapdoodle = "2.2.0" micronaut-micrometer = "5.0.0-SNAPSHOT" micronaut-serde = "2.0.0-M1" @@ -27,7 +26,6 @@ micronaut-serde = { module = "io.micronaut.serde:micronaut-serde-bom", version.r micronaut-test = { module = "io.micronaut.test:micronaut-test-bom", version.ref = "micronaut-test" } micronaut-validation = { module = "io.micronaut.validation:micronaut-validation-bom", version.ref = "micronaut-validation" } -flapdoodle = { module = 'de.flapdoodle.embed:de.flapdoodle.embed.mongo', version.ref = 'flapdoodle'} testcontainers = { module = "org.testcontainers:testcontainers", version.ref = "testcontainers" } # PLUGINS diff --git a/mongo-core/build.gradle b/mongo-core/build.gradle index 8e916579..1f350048 100644 --- a/mongo-core/build.gradle +++ b/mongo-core/build.gradle @@ -6,7 +6,6 @@ dependencies { annotationProcessor mn.micronaut.inject.java annotationProcessor(mnValidation.micronaut.validation.processor) - compileOnly libs.flapdoodle compileOnly mnSerde.micronaut.serde.bson compileOnly mnSerde.micronaut.serde.support diff --git a/mongo-core/src/main/java/io/micronaut/configuration/mongo/core/test/AbstractMongoProcessFactory.java b/mongo-core/src/main/java/io/micronaut/configuration/mongo/core/test/AbstractMongoProcessFactory.java deleted file mode 100644 index 0deaf046..00000000 --- a/mongo-core/src/main/java/io/micronaut/configuration/mongo/core/test/AbstractMongoProcessFactory.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2017-2020 original authors - * - * 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 - * - * https://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 io.micronaut.configuration.mongo.core.test; - -import com.mongodb.ConnectionString; -import com.mongodb.ServerAddress; -import com.mongodb.connection.ClusterSettings; -import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodProcess; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.IMongodConfig; -import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; -import de.flapdoodle.embed.mongo.config.Net; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.process.runtime.Network; -import io.micronaut.core.io.socket.SocketUtils; - -import io.micronaut.core.annotation.Nullable; -import java.io.IOException; -import java.util.List; - -/** - * Abstract process factory implementation for embedding MongoDB. - * - * @author Graeme Rocher - * @since 1.0 - */ -public abstract class AbstractMongoProcessFactory { - protected MongodProcess process; - - /** - * Starts a MongoDB process if possible. - * - * @param connectionString The optional connection string - * @param clusterSettings The optional cluster settings - * @throws IOException If an error occurs starting the process - */ - protected void startEmbeddedMongoIfPossible( - @Nullable ConnectionString connectionString, - @Nullable ClusterSettings.Builder clusterSettings) throws IOException { - if (connectionString != null) { - String first = connectionString.getHosts().get(0); - int port = new ServerAddress(first).getPort(); - if (SocketUtils.isTcpPortAvailable(port)) { - startMongoProcess(port); - } - } else if (clusterSettings != null) { - ClusterSettings settings = clusterSettings.build(); - List hosts = settings.getHosts(); - if (hosts.size() == 1) { - int port = hosts.get(0).getPort(); - if (SocketUtils.isTcpPortAvailable(port)) { - startMongoProcess(port); - } - } - } - } - - private void startMongoProcess(int port) throws IOException { - IMongodConfig mongodConfig = new MongodConfigBuilder() - .version(Version.Main.PRODUCTION) - .net(new Net("localhost", port, Network.localhostIsIPv6())) - .build(); - - MongodExecutable mongodExecutable = MongodStarter.getDefaultInstance().prepare(mongodConfig); - this.process = mongodExecutable.start(); - } -} diff --git a/mongo-core/src/main/java/io/micronaut/configuration/mongo/core/test/MongoProcessFactory.java b/mongo-core/src/main/java/io/micronaut/configuration/mongo/core/test/MongoProcessFactory.java deleted file mode 100644 index 4be0dea6..00000000 --- a/mongo-core/src/main/java/io/micronaut/configuration/mongo/core/test/MongoProcessFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2017-2020 original authors - * - * 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 - * - * https://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 io.micronaut.configuration.mongo.core.test; - -import com.mongodb.ConnectionString; -import de.flapdoodle.embed.mongo.MongodProcess; -import io.micronaut.configuration.mongo.core.DefaultMongoConfiguration; -import io.micronaut.configuration.mongo.core.MongoSettings; -import io.micronaut.context.annotation.Requires; -import io.micronaut.context.env.Environment; -import io.micronaut.context.event.BeanCreatedEvent; -import io.micronaut.context.event.BeanCreatedEventListener; -import io.micronaut.context.exceptions.ConfigurationException; -import io.micronaut.core.util.StringUtils; - -import jakarta.annotation.PreDestroy; -import jakarta.inject.Singleton; -import java.io.Closeable; -import java.io.IOException; -import java.util.Optional; - -/** - * @author graemerocher - * @since 1.0 - */ -@Requires(classes = MongodProcess.class) -@Requires(beans = DefaultMongoConfiguration.class) -@Requires(env = Environment.TEST) -@Requires(property = MongoSettings.EMBEDDED, notEquals = StringUtils.FALSE, defaultValue = StringUtils.TRUE) -@Singleton -public class MongoProcessFactory extends AbstractMongoProcessFactory implements BeanCreatedEventListener, Closeable { - - @Override - public DefaultMongoConfiguration onCreated(BeanCreatedEvent event) { - DefaultMongoConfiguration configuration = event.getBean(); - try { - Optional connectionString = configuration.getConnectionString(); - startEmbeddedMongoIfPossible(connectionString.orElse(null), null); - } catch (IOException e) { - throw new ConfigurationException("Error starting Embedded MongoDB server: " + e.getMessage(), e); - } - return configuration; - } - - @Override - @PreDestroy - public void close() throws IOException { - if (process != null) { - process.stop(); - } - } -} diff --git a/src/main/docs/guide/breaks.adoc b/src/main/docs/guide/breaks.adoc new file mode 100644 index 00000000..dae15d84 --- /dev/null +++ b/src/main/docs/guide/breaks.adoc @@ -0,0 +1,2 @@ +=== Version 5.0.0 +Support for etsting with `flapdoogle` has been removed. Please use `test-containers` instead as described under xref:#testing[MongoDB and Testing]. diff --git a/src/main/docs/guide/testing.adoc b/src/main/docs/guide/testing.adoc index e861ffcf..51535538 100644 --- a/src/main/docs/guide/testing.adoc +++ b/src/main/docs/guide/testing.adoc @@ -1,4 +1,6 @@ -https://www.testcontainers.org/[Test Containers] is the recommended way to test Mongo interaction. For Spock tests this is a simple matter of: +The MongoDb support in https://micronaut-projects.github.io/micronaut-test-resources/latest/guide/#modules-mongodb[Micronaut Test Resources] – which uses the Testcontainers library for Java – is the recommended way to test Mongo interaction. + +Alternatively, https://www.testcontainers.org/[Testcontainers for Java] can be used directly to test Mongo interaction. For Spock tests this is a simple matter of: [source,groovy] ---- @@ -9,8 +11,3 @@ https://www.testcontainers.org/[Test Containers] is the recommended way to test def setupSpec() { mongo.start() } ----- - -Alternatively, you can add a dependency on https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo[Embedded MongoDB] and if the MongoDB server is not available on the configured port for the test environment an embedded MongoDB will be bootstrapped and made available for testing: - -dependency:de.flapdoodle.embed.mongo[groupId="de.flapdoodle.embed", version="2.0.1", scope="test"] diff --git a/src/main/docs/guide/toc.yml b/src/main/docs/guide/toc.yml index 3c9a7219..3002ef47 100644 --- a/src/main/docs/guide/toc.yml +++ b/src/main/docs/guide/toc.yml @@ -1,6 +1,7 @@ introduction: Introduction releaseHistory: Release History +breaks: Breaking Changes setup: Setting up the Mongo Driver config: Configuring the Mongo Driver testing: MongoDB and Testing -repository: Repository \ No newline at end of file +repository: Repository From 3ab9cbc29f6d856eda63d3eaa72527821c056182 Mon Sep 17 00:00:00 2001 From: Dean Wette Date: Mon, 10 Apr 2023 11:44:33 -0500 Subject: [PATCH 2/4] fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Álvaro Sánchez-Mariscal --- src/main/docs/guide/breaks.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/docs/guide/breaks.adoc b/src/main/docs/guide/breaks.adoc index dae15d84..29d6719e 100644 --- a/src/main/docs/guide/breaks.adoc +++ b/src/main/docs/guide/breaks.adoc @@ -1,2 +1,2 @@ === Version 5.0.0 -Support for etsting with `flapdoogle` has been removed. Please use `test-containers` instead as described under xref:#testing[MongoDB and Testing]. +Support for testing with `flapdoodle` has been removed. Please use `test-containers` instead as described under xref:#testing[MongoDB and Testing]. From 2186dae73203f917168a76897092fc6e173046aa Mon Sep 17 00:00:00 2001 From: Dean Wette Date: Mon, 10 Apr 2023 12:37:29 -0500 Subject: [PATCH 3/4] delete unused, out-of-date docs properties --- gradle.properties | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index cbff1695..c73e1930 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,3 @@ developers=Graeme Rocher githubCoreBranch=4.0.x bomProperty=micronautMongoVersion bomProperties=mongoVersion,mongoReactiveVersion - -hibernateapi=http://docs.jboss.org/hibernate/orm/current/javadocs -jdkapi=https://docs.oracle.com/javase/8/docs/api -jeeapi=https://docs.oracle.com/javaee/6/api From f319458067c32cff81d49e8df6c73c36ecea3bf6 Mon Sep 17 00:00:00 2001 From: Dean Wette Date: Mon, 10 Apr 2023 12:37:49 -0500 Subject: [PATCH 4/4] disable binaryCompatibility checks for mn4 --- .../io.micronaut.build.internal.mongodb-module.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/buildSrc/src/main/groovy/io.micronaut.build.internal.mongodb-module.gradle b/buildSrc/src/main/groovy/io.micronaut.build.internal.mongodb-module.gradle index 1f7564c4..468af5e1 100644 --- a/buildSrc/src/main/groovy/io.micronaut.build.internal.mongodb-module.gradle +++ b/buildSrc/src/main/groovy/io.micronaut.build.internal.mongodb-module.gradle @@ -2,3 +2,9 @@ plugins { id 'io.micronaut.build.internal.mongodb-base' id 'io.micronaut.build.internal.module' } + +micronautBuild { + binaryCompatibility { + enabled.set(false) + } +}