Permalink
Browse files

[reactivemongo] Support ReactiveMongo 0.11.x

  • Loading branch information...
cchantep
cchantep committed Dec 31, 2015
1 parent d60d07e commit de0179bd758b93861fb9405869743005ec31ff09
View
@@ -3,5 +3,7 @@ jdk:
- openjdk6
- oraclejdk8
env: JAVA_OPTS="-Xms32m -Xmx128m"
+before_install:
+- sudo ./.travis_scripts/beforeInstall.sh $TRAVIS_SCALA_VERSION
scala:
- 2.11.7
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+# Travis OpenJDK workaround
+cat /etc/hosts # optionally check the content *before*
+hostname "$(hostname | cut -c1-63)"
+sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts | tee /etc/hosts
+cat /etc/hosts # optionally check the content *after*
View
@@ -16,14 +16,14 @@ object Acolyte extends Build with Dependencies
else "1.6"
lazy val root = Project(id = "acolyte", base = file(".")).
- aggregate(scalacPlugin/*, reactiveMongo*/,
+ aggregate(scalacPlugin, reactiveMongo,
jdbcDriver, jdbcScala, jdbcClojure, studio).
settings(
organization in ThisBuild := "org.eu.acolyte",
version in ThisBuild := s"1.0.35${versionVariant}",
javaOptions in ThisBuild ++= Seq(
"-source", javaVersion, "-target", javaVersion),
- scalaVersion in ThisBuild := "2.10.4",
+ scalaVersion in ThisBuild := "2.11.7",
crossScalaVersions in ThisBuild := Seq("2.10.4", "2.11.7"),
publishTo in ThisBuild := Some(Resolver.file("file",
new File(Path.userHome.absolutePath+"/.m2/repository"))),
@@ -34,8 +34,9 @@ trait ReactiveMongo { deps: Dependencies ⇒
},
resolvers ++= reactiveResolvers,
libraryDependencies ++= Seq(
- "org.reactivemongo" %% "reactivemongo" % "0.10.5.0.akka23",
+ "org.reactivemongo" %% "reactivemongo" % "0.11.10",
"com.jsuereth" %% "scala-arm" % "1.4",
+ "org.slf4j" % "slf4j-simple" % "1.7.13" % Test,
"com.chuusai" % "shapeless" % "2.0.0" % Test cross CrossVersion.
binaryMapped {
case "2.10" => scalaVersion.value
@@ -9,7 +9,7 @@ import scala.util.{ Failure, Success }
import com.typesafe.config.ConfigFactory
import akka.actor.{ ActorRef, ActorSystem AkkaSystem, Props }
-import reactivemongo.core.commands.GetLastError
+import reactivemongo.api.commands.GetLastError
import reactivemongo.core.actors.{
Close,
CheckedWriteRequestExpectingResponse CheckedWriteRequestExResp,
@@ -44,13 +44,26 @@ object Akka {
}
}
-/** Acolyte Mongo actor */
private[reactivemongo] class Actor(
- handler: ConnectionHandler) extends akka.actor.Actor {
+ handler: ConnectionHandler) extends reactivemongo.core.actors.MongoDBSystem {
- def receive = {
+ import reactivemongo.core.nodeset.{ Authenticate, ChannelFactory, Connection }
+
+ val initialAuthenticates = Seq.empty[Authenticate]
+
+ protected def authReceive: PartialFunction[Any, Unit] = { case _ => () }
+
+ val seeds = Seq.empty[String]
+
+ val options = reactivemongo.api.MongoConnectionOptions()
+
+ protected def sendAuthenticate(connection: Connection,authentication: Authenticate): Connection = ???
+
+ val channelFactory: ChannelFactory = new ChannelFactory(options)
+
+ override lazy val receive: Receive = {
case msg @ CheckedWriteRequestExResp(
- r @ CheckedWriteRequest(op, doc, GetLastError(_, _, _, _)))
+ r @ CheckedWriteRequest(op, doc, GetLastError(_, _, _, _))) {
val req = Request(op.fullCollectionName, doc.merged)
val exp = new ExpectingResponse(msg)
@@ -60,8 +73,8 @@ private[reactivemongo] class Actor(
case Success(err) err
case _ MongoDB.MkWriteError(cid)
}
- }) { wop
- handler.writeHandler(cid, wop, req).
+ }) {
+ handler.writeHandler(cid, _, req).
fold(NoWriteResponse(cid, msg.toString))(_ match {
case Success(r) r
case Failure(e) MongoDB.WriteError(cid, Option(e.getMessage).
@@ -73,9 +86,11 @@ private[reactivemongo] class Actor(
}
exp.promise.success(resp)
+ }
case msg @ RequestMakerExpectingResponse(RequestMaker(
- op @ RQuery(_ /*flags*/ , coln, off, len), doc, _ /*pref*/ , chanId))
+ op @ RQuery(_ /*flags*/ , coln, off, len),
+ doc, _ /*pref*/ , chanId), _) {
val exp = new ExpectingResponse(msg)
val cid = chanId getOrElse 1
val resp = handler.queryHandler(cid, Request(coln, doc.merged)).
@@ -89,6 +104,7 @@ private[reactivemongo] class Actor(
})
resp.error.fold(exp.promise.success(resp))(exp.promise.failure(_))
+ }
case close @ Close /* Do nothing: next forward close */
case msg
@@ -17,7 +17,7 @@ object DriverManager {
/** Manager instance based on connection handler. */
implicit object Default extends DriverManager {
- def open = new MongoDriver(Some(Akka.actorSystem()))
+ def open = MongoDriver()
/** Releases driver if necessary. */
def releaseIfNecessary(driver: MongoDriver): Boolean = try {
@@ -43,7 +43,6 @@ trait ConnectionManager[T] {
/** Connection manage companion. */
object ConnectionManager {
import akka.actor.Props
- import reactivemongo.core.actors.MonitorActor
import reactivemongo.api.MongoConnectionOptions
/** Manager instance based on connection handler. */
@@ -52,9 +51,9 @@ object ConnectionManager {
def open(driver: MongoDriver, handler: ConnectionHandler) = {
val sys = driver.system
- val actor = sys.actorOf(Props(classOf[Actor], handler))
- val monitor = sys.actorOf(Props(new MonitorActor(actor)))
- new MongoConnection(sys, actor, monitor, MongoConnectionOptions())
+ val actorRef = sys.actorOf(Props(classOf[Actor], handler))
+
+ new MongoConnection(sys, actorRef, MongoConnectionOptions())
}
/** Releases connection if necessary. */
@@ -1,7 +1,7 @@
package acolyte.reactivemongo
import scala.concurrent.{ ExecutionContext, Future }
-import reactivemongo.api.collections.default.BSONCollection
+import reactivemongo.api.collections.bson.BSONCollection
import reactivemongo.api.{ DB, MongoConnection, MongoDriver }
/** Functions to work with a Mongo collection (provided DB functions). */
@@ -0,0 +1 @@
+org.slf4j.simpleLogger.defaultLogLevel=WARN
@@ -7,7 +7,7 @@ import scala.concurrent.duration.Duration
import resource.{ ManagedResource, managed }
import reactivemongo.api.{ MongoDriver, MongoConnection, DefaultDB }
-import reactivemongo.api.collections.default.BSONCollection
+import reactivemongo.api.collections.bson.BSONCollection
import reactivemongo.bson.{
BSONBoolean,
BSONDocument,
@@ -16,7 +16,7 @@ import reactivemongo.bson.{
BSONString
}
import reactivemongo.core.errors.DetailedDatabaseException
-import reactivemongo.core.commands.LastError
+import reactivemongo.api.commands.{ LastError, WriteResult }
object DriverSpec extends org.specs2.mutable.Specification
with QueryHandlerFixtures with WriteHandlerFixtures
@@ -180,7 +180,8 @@ object DriverSpec extends org.specs2.mutable.Specification
"when is successful #1" in {
awaitRes(AcolyteDSL.withFlatCollection(chandler1, query1.collection) {
- col col.find(query1.body.head).cursor[BSONDocument].collect[List]()
+ col col.find(query1.body.head).
+ cursor[BSONDocument]().collect[List]()
}) aka "query result" must beSuccessfulTry[List[BSONDocument]].like {
case ValueDocument(("b", BSONInteger(3)) :: Nil) :: Nil ok
}
@@ -189,7 +190,7 @@ object DriverSpec extends org.specs2.mutable.Specification
"when is successful #2" in {
awaitRes(AcolyteDSL.withFlatDB(chandler1) { db
db(query2.collection).find(query2.body.head).
- cursor[BSONDocument].collect[List]()
+ cursor[BSONDocument]().collect[List]()
}) aka ("query result") must beSuccessfulTry[List[BSONDocument]].like {
case ValueDocument(("d", BSONDouble(4.56d)) :: Nil) ::
ValueDocument(("ef", BSONString("ghi")) :: Nil) :: Nil ok
@@ -203,7 +204,7 @@ object DriverSpec extends org.specs2.mutable.Specification
AcolyteDSL.withFlatConnection(driver) { con
val db = con("anyDb")
db("anyCol").find(query1.body.head).
- cursor[BSONDocument].collect[List]()
+ cursor[BSONDocument]().collect[List]()
}
}) aka "query result" must beSuccessfulTry[List[BSONDocument]].
like {
@@ -216,7 +217,7 @@ object DriverSpec extends org.specs2.mutable.Specification
awaitRes(AcolyteDSL.withFlatQueryResult(
List(BSONDocument("doc" -> 1), BSONDocument("doc" -> 2.3d))) { d
AcolyteDSL.withFlatCollection(d, "anyCol") {
- _.find(query1.body.head).cursor[BSONDocument].collect[List]()
+ _.find(query1.body.head).cursor[BSONDocument]().collect[List]()
}
}) aka "query result" must beSuccessfulTry[List[BSONDocument]].
like {
@@ -228,7 +229,7 @@ object DriverSpec extends org.specs2.mutable.Specification
"for an explicit error" in {
awaitRes(AcolyteDSL.withFlatQueryResult("Error" -> 7) { driver
AcolyteDSL.withFlatCollection(driver, query1.collection) {
- _.find(query1.body.head).cursor[BSONDocument].collect[List]()
+ _.find(query1.body.head).cursor[BSONDocument]().collect[List]()
}
}) aka "query result" must beFailedTry.
withThrowable[DetailedDatabaseException](".*Error.*code = 7.*")
@@ -237,7 +238,7 @@ object DriverSpec extends org.specs2.mutable.Specification
"when undefined" in {
awaitRes(AcolyteDSL.withFlatQueryResult(None) { driver
AcolyteDSL.withFlatCollection(driver, query1.collection) {
- _.find(query1.body.head).cursor[BSONDocument].collect[List]()
+ _.find(query1.body.head).cursor[BSONDocument]().collect[List]()
}
}) aka "query result" must beFailedTry.
withThrowable[DetailedDatabaseException](".*No response:.*")
@@ -248,7 +249,7 @@ object DriverSpec extends org.specs2.mutable.Specification
awaitRes(AcolyteDSL.withFlatQueryHandler(
{ _: Request QueryResponse.empty }) { d
AcolyteDSL.withFlatCollection(d, query3.collection) {
- _.find(query3.body.head).cursor[BSONDocument].collect[List]()
+ _.find(query3.body.head).cursor[BSONDocument]().collect[List]()
}
}) aka "query result" must beSuccessfulTry.like {
case res if res.isEmpty ok
@@ -258,7 +259,7 @@ object DriverSpec extends org.specs2.mutable.Specification
"as error when connection handler is empty" in {
awaitRes(AcolyteDSL.withFlatCollection(AcolyteDSL.handle,
query3.collection) {
- _.find(query3.body.head).cursor[BSONDocument].collect[List]()
+ _.find(query3.body.head).cursor[BSONDocument]().collect[List]()
}) aka "query result" must beFailedTry.
withThrowable[DetailedDatabaseException](".*No response: .*")
}
@@ -270,7 +271,7 @@ object DriverSpec extends org.specs2.mutable.Specification
awaitRes(AcolyteDSL.withFlatConnection(handler) { con
val db = con("anyDb")
db(query3.collection).find(query3.body.head).
- cursor[BSONDocument].collect[List]()
+ cursor[BSONDocument]().collect[List]()
}) aka "query result" must beFailedTry.
withThrowable[DetailedDatabaseException](".*No response: .*")
@@ -292,16 +293,11 @@ object DriverSpec extends org.specs2.mutable.Specification
awaitRes(AcolyteDSL.withFlatDB(chandler1) {
_(write2._2.collection).insert(write2._2.body.head)
}) aka "result" must beSuccessfulTry.like {
- case lastError
- lastError.elements.toList aka "body" must beLike {
- case ("ok", BSONInteger(1)) ::
- ("updatedExisting", BSONBoolean(false)) ::
- ("n", BSONInteger(0)) :: Nil ok
- } and (lastError.ok aka "ok" must beTrue) and (
- lastError.n aka "updated" must_== 0) and (
- lastError.inError aka "in-error" must beFalse) and (
- lastError.err aka "err" must beNone) and (
- lastError.errMsg aka "errmsg" must beNone)
+ case result
+ result.ok aka "ok" must beTrue and (
+ result.n aka "updated" must_== 0) and (
+ result.inError aka "in-error" must beFalse) and (
+ result.errmsg aka "errmsg" must beNone)
}
}
@@ -379,9 +375,9 @@ object DriverSpec extends org.specs2.mutable.Specification
WriteResponse.successful(1, false)
}) { driver
AcolyteDSL.withFlatCollection(driver, "col1") {
- _.save(BSONDocument("a" -> "val", "b" -> 2))
+ _.insert(BSONDocument("a" -> "val", "b" -> 2))
}
- }) aka "write result" must beSuccessfulTry[LastError]
+ }) aka "write result" must beSuccessfulTry[WriteResult]
}
"for update" in {
@@ -394,7 +390,7 @@ object DriverSpec extends org.specs2.mutable.Specification
AcolyteDSL.withFlatCollection(driver, "col2") {
_.update(BSONDocument("sel" -> "hector"), write3._2.body.head)
}
- }) aka "write result" must beSuccessfulTry[LastError]
+ }) aka "write result" must beSuccessfulTry[WriteResult]
}
"for delete" in {
@@ -406,7 +402,7 @@ object DriverSpec extends org.specs2.mutable.Specification
AcolyteDSL.withFlatCollection(driver, "col3") {
_.remove(BSONDocument("a" -> "val"))
}
- }) aka "write result" must beSuccessfulTry[LastError]
+ }) aka "write result" must beSuccessfulTry[WriteResult]
}
}
}

0 comments on commit de0179b

Please sign in to comment.