Skip to content

upgrade to flapdoodle mongodb 4.5.x #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ dependencies {
api "org.grails:grails-core"
api "org.grails.profiles:plugin"
api "org.grails:grails-gorm-testing-support"
api("de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.2.0") {
api "de.flapdoodle.embed:de.flapdoodle.embed.process:4.5.0"
api("de.flapdoodle.embed:de.flapdoodle.embed.mongo:4.5.1") {
exclude group: "commons-io"
exclude group: "org.apache.commons", module: "commons-lang3"
exclude group: "net.java.dev.jna"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package org.grails.plugin.embedded.mongodb

import com.mongodb.ServerAddress
import de.flapdoodle.embed.mongo.Command
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.config.RuntimeConfigBuilder
import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion
import de.flapdoodle.embed.mongo.distribution.Version
import de.flapdoodle.embed.process.config.IRuntimeConfig
import de.flapdoodle.embed.process.config.io.ProcessOutput
import de.flapdoodle.embed.process.runtime.Network
import de.flapdoodle.embed.mongo.distribution.Versions
import de.flapdoodle.embed.mongo.transitions.Mongod
import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess
import de.flapdoodle.embed.process.io.ProcessOutput
import de.flapdoodle.reverse.TransitionWalker
import de.flapdoodle.reverse.transitions.Start
import grails.plugins.*
import grails.util.Environment
import org.grails.datastore.mapping.mongo.MongoDatastore
import de.flapdoodle.embed.process.distribution.Version

class EmbeddedMongoDBGrailsPlugin extends Plugin {

Expand All @@ -36,34 +32,31 @@ class EmbeddedMongoDBGrailsPlugin extends Plugin {
}

IFeatureAwareVersion getVersion() {
String version = config.getProperty("grails.mongodb.version", String, Version.Main.PRODUCTION.asInDownloadPath())
Version.valueOf("V" + version.replaceAll(/(\.|-)/, '_').toUpperCase())
String version = config.getProperty("grails.mongodb.version", String, de.flapdoodle.embed.mongo.distribution.Version.Main.V6_0.asInDownloadPath())
Versions.withFeatures(Version.of(version))
}

static MongodExecutable mongodExecutable = null
// static MongodExecutable mongodExecutable = null
TransitionWalker.ReachedState<RunningMongodProcess> started

Closure doWithSpring() {{->
if (Environment.current == Environment.TEST) {
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
.defaults(Command.MongoD)
.processOutput(ProcessOutput.defaultInstanceSilent)
.build()

MongodStarter starter = MongodStarter.getInstance(runtimeConfig)

IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(getVersion())
.net(new Net("127.0.0.1", getPort(), Network.localhostIsIPv6()))
.build()

mongodExecutable = starter.prepare(mongodConfig)
mongodExecutable.start()
started = Mongod.instance()
.withProcessOutput(Start.to(ProcessOutput.class)
.providedBy(ProcessOutput::silent))
.withNet(Start.to(Net.class)
.initializedWith(Net.builder()
.bindIp("127.0.0.1")
.port(getPort())
.isIpv6(de.flapdoodle.net.Net.localhostIsIPv6())
.build()))
.start(getVersion())
}
}}

void onShutdown(evt) {
if (mongodExecutable != null) {
mongodExecutable.stop()
if (started != null) {
started.close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.grails.plugin.embedded.mongodb

import com.mongodb.ServerAddress
import de.flapdoodle.embed.mongo.distribution.Version
import de.flapdoodle.embed.mongo.distribution.Versions
import grails.core.GrailsApplication
import org.grails.config.PropertySourcesConfig
import spock.lang.Specification
Expand All @@ -20,7 +21,7 @@ class EmbeddedMongoDBGrailsPluginSpec extends Specification {
}

expect:
new EmbeddedMongoDBGrailsPlugin(grailsApplication: grailsApplication).getVersion().asInDownloadPath() == Version.Main.PRODUCTION.asInDownloadPath()
new EmbeddedMongoDBGrailsPlugin(grailsApplication: grailsApplication).getVersion().asInDownloadPath() == Version.Main.V6_0.asInDownloadPath()
}

void "test version"() {
Expand All @@ -32,7 +33,7 @@ class EmbeddedMongoDBGrailsPluginSpec extends Specification {
}

expect:
new EmbeddedMongoDBGrailsPlugin(grailsApplication: grailsApplication).getVersion() == Version.V4_0_2
new EmbeddedMongoDBGrailsPlugin(grailsApplication: grailsApplication).getVersion() == Versions.withFeatures(Version.of(Version.V4_0_2.asInDownloadPath()))
}

void "test version release candidate"() {
Expand All @@ -44,7 +45,7 @@ class EmbeddedMongoDBGrailsPluginSpec extends Specification {
}

expect:
new EmbeddedMongoDBGrailsPlugin(grailsApplication: grailsApplication).getVersion() == Version.V3_2_1_RC3
new EmbeddedMongoDBGrailsPlugin(grailsApplication: grailsApplication).getVersion() == Versions.withFeatures(Version.of(Version.V3_2_1_RC3.asInDownloadPath()))
}

void "test version not found"() {
Expand All @@ -59,7 +60,7 @@ class EmbeddedMongoDBGrailsPluginSpec extends Specification {
new EmbeddedMongoDBGrailsPlugin(grailsApplication: grailsApplication).getVersion()

then:
thrown(IllegalArgumentException)
thrown(ArrayIndexOutOfBoundsException)
}

void "test default port"() {
Expand Down