Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from hmrc/honor-mongo-connection-options
Browse files Browse the repository at this point in the history
[PLATOPS-328] pass mongoOptions into ReactiveMongoHelper
  • Loading branch information
ashusingh committed Feb 3, 2016
2 parents 3df3d46 + df01fd9 commit ca663ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion project/HmrcBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object HmrcBuild extends Build {
object Dependencies {

object Compile {
val reactiveMongoJson = "uk.gov.hmrc" %% "reactivemongo-json" % "2.2.1"
val reactiveMongoJson = "uk.gov.hmrc" %% "reactivemongo-json" % "2.3.0"
//NOTE: 0.11.6 Netty 3.10.4.Final clashes with Play (2.3.10) version of Netty 3.9.8
val reactiveMongo = "org.reactivemongo" %% "reactivemongo" % "0.11.5"
val playJson = "com.typesafe.play" %% "play-json" % "2.3.10" % "provided"
Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/uk/gov/hmrc/mongo/SimpleMongoConnection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ trait SimpleMongoConnection {

private def connect = helper.db

val channelsPerNode: Option[Int]

lazy val helper = MongoConnection.parseURI(mongoConnectionUri) match {
case Success(MongoConnection.ParsedURI(hosts, options, ignoreOptions, Some(db), auth)) =>
ReactiveMongoHelper(db, hosts.map(h => h._1 + ":" + h._2).toList, auth.toList, channelsPerNode, failoverStrategy)
ReactiveMongoHelper(db, hosts.map(h => h._1 + ":" + h._2), auth.toList, failoverStrategy, options)
case Success(MongoConnection.ParsedURI(_, _, _, None, _)) =>
throw new Exception(s"Missing database name in mongodb.uri '$mongoConnectionUri'")
case Failure(e) => throw new Exception(s"Invalid mongodb.uri '$mongoConnectionUri'", e)
Expand All @@ -36,4 +34,4 @@ trait SimpleMongoConnection {

}

case class MongoConnector(val mongoConnectionUri: String, channelsPerNode: Option[Int] = None, failoverStrategy : Option[FailoverStrategy] = None) extends SimpleMongoConnection
case class MongoConnector(mongoConnectionUri: String, failoverStrategy : Option[FailoverStrategy] = None) extends SimpleMongoConnection
19 changes: 19 additions & 0 deletions src/test/scala/uk/gov/hmrc/mongo/MongoConnectorSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package uk.gov.hmrc.mongo

import org.scalatest.{Matchers, WordSpec}

/**
*
* https://docs.mongodb.org/manual/reference/connection-string/#connections-connection-options
*/
class MongoConnectorSpec extends WordSpec with Matchers {

"MongoConnector" should {
"create a Mongo connection with the given options" in {

val connector = MongoConnector("mongodb://mongo-host:2000/mongo?connectTimeoutMS=1000&socketTimeoutMS=2000", failoverStrategy = None)

connector.db().connection.options.connectTimeoutMS shouldBe 1000
}
}
}

0 comments on commit ca663ac

Please sign in to comment.