Skip to content

Commit

Permalink
Update Scala versions and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
MichealZub committed Aug 15, 2023
1 parent 4c74667 commit 9be96be
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 53 deletions.
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ publishMavenStyle := true
publishConfiguration := publishConfiguration.value.withOverwrite(true)


scalaVersion := "3.2.2"
scalaVersion := "3.3.0"

crossScalaVersions := Seq("2.12.17", "2.13.10")
crossScalaVersions := Seq("2.12.18", "2.13.11")

scalacOptions ++= Seq(
"-deprecation"
Expand All @@ -53,13 +53,13 @@ scalacOptions ++= Seq(
Test / parallelExecution := false
Test / fork := true

libraryDependencies += "io.spray" %% "spray-json" % "1.3.6" cross CrossVersion.for3Use2_13
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "4.9.0" cross CrossVersion.for3Use2_13
libraryDependencies += "io.spray" %% "spray-json" % "1.3.6"
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "4.10.2" cross CrossVersion.for3Use2_13


libraryDependencies += "org.slf4j" % "slf4j-api" % "2.0.5"
libraryDependencies += "org.slf4j" % "slf4j-simple" % "2.0.5" % Test
libraryDependencies += "org.slf4j" % "slf4j-api" % "2.0.7"
libraryDependencies += "org.slf4j" % "slf4j-simple" % "2.0.7" % Test

libraryDependencies += "de.flapdoodle.embed" % "de.flapdoodle.embed.mongo" % "3.5.4" % Test
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.15" % Test
libraryDependencies += "org.immutables" % "value" % "2.9.2" % Test
libraryDependencies += "de.flapdoodle.embed" % "de.flapdoodle.embed.mongo" % "4.8.0" % Test
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test
libraryDependencies += "org.immutables" % "value" % "2.9.3" % Test
85 changes: 41 additions & 44 deletions src/test/scala/io/github/greenleafoss/mongo/TestMongoServer.scala
Original file line number Diff line number Diff line change
@@ -1,68 +1,65 @@
package io.github.greenleafoss.mongo


import de.flapdoodle.embed.mongo.config.Defaults._
import de.flapdoodle.embed.mongo.config.{MongoCmdOptions, MongodConfig, Net}
import de.flapdoodle.embed.mongo.commands.{ImmutableMongodArguments, MongodArguments}
import de.flapdoodle.embed.mongo.config.Net
import de.flapdoodle.embed.mongo.distribution.Version
import de.flapdoodle.embed.mongo.packageresolver.Command
import de.flapdoodle.embed.mongo.{MongodExecutable, MongodStarter}
import de.flapdoodle.embed.process.runtime.Network
import de.flapdoodle.embed.mongo.transitions.{ImmutableMongod, Mongod, RunningMongodProcess}
import de.flapdoodle.embed.process.io.{ImmutableProcessOutput, ProcessOutput, Processors, Slf4jLevel}
import de.flapdoodle.reverse.TransitionWalker
import de.flapdoodle.reverse.transitions.Start
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AsyncWordSpec
import org.slf4j.{Logger, LoggerFactory}

object TestMongoServer {

// https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo#usage---optimization

private val command = Command.MongoD

private val runtimeConfig = runtimeConfigFor(command)
.artifactStore(extractedArtifactStoreFor(command).withDownloadConfig(downloadConfigFor(command).build()))
// .processOutput(new ProcessOutput(new ConsoleOutputStreamProcessor(), new ConsoleOutputStreamProcessor(), new ConsoleOutputStreamProcessor()))
.build()

protected lazy val mongodExe: MongodExecutable = MongodStarter.getInstance(runtimeConfig).prepare(
MongodConfig.builder()
.version(Version.Main.V6_0)
.net(new Net("localhost", 27027, Network.localhostIsIPv6()))
.cmdOptions(
MongoCmdOptions.builder()
.storageEngine("ephemeralForTest")
// https://docs.mongodb.com/manual/reference/configuration-options/#storage.syncPeriodSecs
// If you set storage.syncPeriodSecs to 0, MongoDB will not sync the memory mapped files to disk.
// If you set storage.syncPeriodSecs to 0 for testing purposes, you should also set --nojournal to true.
.syncDelay(0)
.useNoJournal(true)
.build())
.build())
private val logger: Logger = LoggerFactory.getLogger(getClass)

private val mongoPort: Int = 27027
private val mongoVersion: Version.Main = Version.Main.V6_0

private val processOutput: ImmutableProcessOutput = ProcessOutput.builder
.commands(Processors.logTo(logger, Slf4jLevel.DEBUG))
.output(Processors.logTo(logger, Slf4jLevel.INFO))
.error(Processors.logTo(logger, Slf4jLevel.ERROR))
.build

// @see https://www.mongodb.com/docs/manual/reference/program/mongod/
private val mongodArguments: ImmutableMongodArguments = MongodArguments.defaults
.withSyncDelay(0)
.withStorageEngine("ephemeralForTest")
.withUseNoJournal(true)
.withUseNoPrealloc(true)

private val mongod: ImmutableMongod = Mongod.instance
.withNet(Start.to(classOf[Net]).initializedWith(Net.defaults.withPort(mongoPort)))
.withProcessOutput(Start.to(classOf[ProcessOutput]).initializedWith(processOutput))
.withMongodArguments(Start.to(classOf[MongodArguments]).initializedWith(mongodArguments))

def start(): TransitionWalker.ReachedState[RunningMongodProcess] =
mongod.start(mongoVersion)

def stop(runningMongod: TransitionWalker.ReachedState[RunningMongodProcess]): Unit =
if (runningMongod.current().isAlive) runningMongod.close()
}

trait TestMongoServer extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
private val mongod = TestMongoServer.mongodExe.start()
private val runningMongoDb = TestMongoServer.start()

// we can preload test data here if needed
override protected def beforeAll(): Unit = super.beforeAll()

override protected def afterAll(): Unit = if (mongod.isProcessRunning) mongod.stop()
override protected def afterAll(): Unit = TestMongoServer.stop(runningMongoDb)
}

object TestMongoServerApp {

def main(args: Array[String]): Unit = {
val runtimeCfg = runtimeConfigFor(Command.MongoD)
// .processOutput(new ProcessOutput(new ConsoleOutputStreamProcessor(), new ConsoleOutputStreamProcessor(), new ConsoleOutputStreamProcessor()))
.build()

val starter: MongodStarter = MongodStarter.getInstance(runtimeCfg)
object TestMongoServerApp extends App {
import scala.io.StdIn.readLine

val mongoCfg = MongodConfig.builder()
.version(Version.Main.V6_0)
.net(new Net("localhost", 27027, Network.localhostIsIPv6()))
.build()
private val runningMongod = TestMongoServer.start()

starter.prepare(mongoCfg).start()
}
readLine("Press 'Enter' to shutdown MongoDB")

TestMongoServer.stop(runningMongod)
}

0 comments on commit 9be96be

Please sign in to comment.