Introducing MongoDB functionality. Tests are still WIP
authorChristos KK Loverdos <loverdos@gmail.com>
Tue, 22 Nov 2011 16:02:18 +0000 (18:02 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Tue, 22 Nov 2011 16:02:18 +0000 (18:02 +0200)
12 files changed:
logic/pom.xml
logic/src/main/scala/gr/grnet/aquarium/store/MessageID.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/store/MessageStore.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBConnection.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBStore.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/store/mongodb/confmodel/MongoDBConfigurationModel.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/store/mongodb/confmodel/ServerAddressConfigurationModel.scala [new file with mode: 0644]
logic/src/main/scala/gr/grnet/aquarium/util/xstream/XStreamHelpers.scala
logic/src/test/resources/mongodb/local-message-store.xml [new file with mode: 0644]
logic/src/test/scala/gr/grnet/aquarium/messaging/MessagingTest.scala
logic/src/test/scala/gr/grnet/aquarium/store/mongodb/MongoDBStoreTest.scala [new file with mode: 0644]
project/build/Aquarium.scala

index 5a7d506..dcd928c 100644 (file)
       <artifactId>xstream</artifactId>
       <version>1.4.1</version>
     </dependency>
+
+    <dependency>
+      <groupId>org.mongodb</groupId>
+      <artifactId>mongo-java-driver</artifactId>
+      <version>2.7.2</version>
+    </dependency>
+
+    <!-- Official MongoDB scala driver -->
+    <!-- For issues with the driver see: https://jira.mongodb.org/browse/SCALA -->
+    <dependency>
+      <groupId>com.mongodb.casbah</groupId>
+      <artifactId>casbah-core_2.9.1</artifactId>
+      <version>2.1.5-1</version>
+    </dependency>
   </dependencies>
 </project>
diff --git a/logic/src/main/scala/gr/grnet/aquarium/store/MessageID.scala b/logic/src/main/scala/gr/grnet/aquarium/store/MessageID.scala
new file mode 100644 (file)
index 0000000..19e8b23
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.store
+
+/**
+ * Represents an ID given to a message by the store.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+case class MessageID(id: String)
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/store/MessageStore.scala b/logic/src/main/scala/gr/grnet/aquarium/store/MessageStore.scala
new file mode 100644 (file)
index 0000000..59dd761
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.store
+
+import com.ckkloverdos.maybe.Maybe
+import net.liftweb.json.JsonAST.JValue
+
+
+/**
+ * An abstraction for message stores. We assume that our messages are
+ * documents with a string representation, e.g. `JSON`.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+trait MessageStore {
+  def storeString(message: String): Maybe[MessageID]
+
+  def storeJson(json: JValue): Maybe[MessageID] = {
+    storeString(json.toString)
+  }
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBConnection.scala b/logic/src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBConnection.scala
new file mode 100644 (file)
index 0000000..cb9c731
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.store
+package mongodb
+
+import confmodel.MongoDBConfigurationModel
+import com.mongodb.casbah.MongoConnection
+import com.mongodb.{WriteConcern, ServerAddress}
+import gr.grnet.aquarium.util.Loggable
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class MongoDBConnection(val confModel: MongoDBConfigurationModel) extends Loggable {
+
+  private[mongodb] lazy val _mongoConnection = {
+    val hosts = confModel.hosts
+    val serverAddresses = hosts.map(sacm => new ServerAddress(sacm.host, sacm.port))
+
+    val mongo = MongoConnection(serverAddresses)
+    logger.info("Created MongoDB connection %s".format(mongo))
+
+    if(confModel.slaveOK) {
+      mongo.slaveOk()
+      logger.info("Set slaveOK for MongoDB connection %s".format(mongo))
+    }
+    val writeConcern = WriteConcern.valueOf(confModel.writeConcern)
+    mongo.setWriteConcern(writeConcern)
+    logger.info("Set WriteConcern %s for MongoDB connection %s".format(confModel.writeConcern, mongo))
+
+    mongo
+  }
+}
+
+object MongoDBConnection {
+  object RCFolders {
+    val mongodb = "mongodb"
+  }
+
+  object PropFiles {
+    val local_message_store = "local-message-store.xml"
+  }
+  
+  object DBNames {
+    val test = "test"
+  }
+
+  object CollectionNames {
+      val test = "test"
+    }
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBStore.scala b/logic/src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBStore.scala
new file mode 100644 (file)
index 0000000..afcf9a4
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.store.mongodb
+
+import gr.grnet.aquarium.store.MessageStore
+import com.ckkloverdos.maybe.NoVal
+
+/**
+ * Mongodb implementation of the message store.
+ *
+ * Using Casbah as the underlying library.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class MongoDBStore(connection: MongoDBConnection) extends MessageStore {
+  def storeString(message: String) = {
+    val mongo = connection._mongoConnection
+
+    // FIXME: implement
+    NoVal
+  }
+}
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/store/mongodb/confmodel/MongoDBConfigurationModel.scala b/logic/src/main/scala/gr/grnet/aquarium/store/mongodb/confmodel/MongoDBConfigurationModel.scala
new file mode 100644 (file)
index 0000000..9799162
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.store.mongodb
+package confmodel
+
+import com.mongodb.ServerAddress
+
+////////////////////////////////////////////////////////////////////////////
+// The WriteConcerns are as follows:
+////////////////////////////////////////////////////////////////////////////
+// NONE: No exceptions are raised, even for network issues
+// NORMAL: Exceptions are raised for network issues, but not server errors
+// SAFE: Exceptions are raised for network issues, and server errors; waits on a server for the write operation
+// MAJORITY: Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation
+// FSYNC_SAFE: Exceptions are raised for network issues, and server errors; the write operation waits for the server to flush the data to disk
+// JOURNAL_SAFE: Exceptions are raised for network issues, and server errors; the write operation waits for the server to group commit to the journal file on disk
+// REPLICAS_SAFE: Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation
+////////////////////////////////////////////////////////////////////////////
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+case class MongoDBConfigurationModel(
+    hosts: List[ServerAddressConfigurationModel],
+    slaveOK: Boolean,
+    writeConcern: String)
\ No newline at end of file
diff --git a/logic/src/main/scala/gr/grnet/aquarium/store/mongodb/confmodel/ServerAddressConfigurationModel.scala b/logic/src/main/scala/gr/grnet/aquarium/store/mongodb/confmodel/ServerAddressConfigurationModel.scala
new file mode 100644 (file)
index 0000000..17e44a2
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.store.mongodb.confmodel
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+case class ServerAddressConfigurationModel(host: String, port: Int)
\ No newline at end of file
index 6d43b13..4fd1c34 100644 (file)
@@ -40,6 +40,7 @@ import com.thoughtworks.xstream.XStream
 import com.ckkloverdos.maybe.{Failed, Just, Maybe}
 import com.ckkloverdos.resource.StreamResource
 import gr.grnet.aquarium.messaging.amqp.rabbitmq.v091.confmodel._
+import gr.grnet.aquarium.store.mongodb.confmodel._
 
 
 /**
@@ -59,12 +60,17 @@ object XStreamHelpers {
   }
   
   def prepareXStreamAliases(xs: XStream): XStream = {
+    // RabbitMQ
     prepareXStreamAlias[RabbitMQConfigurationsModel](xs)
     prepareXStreamAlias[RabbitMQConfigurationModel](xs)
     prepareXStreamAlias[RabbitMQConnectionModel](xs)
     prepareXStreamAlias[RabbitMQProducerModel](xs)
     prepareXStreamAlias[RabbitMQConsumerModel](xs)
 
+    // MongoDB
+    prepareXStreamAlias[MongoDBConfigurationModel](xs)
+    prepareXStreamAlias[ServerAddressConfigurationModel](xs)
+
     xs.alias("List", classOf[::[_]])
     xs.alias("Nil", manifest[Nil.type].erasure)
     xs
diff --git a/logic/src/test/resources/mongodb/local-message-store.xml b/logic/src/test/resources/mongodb/local-message-store.xml
new file mode 100644 (file)
index 0000000..a50a83a
--- /dev/null
@@ -0,0 +1,10 @@
+<MongoDBConfigurationModel>
+  <slaveOK>true</slaveOK>
+  <writeConcern>SAFE</writeConcern>
+  <hosts class="List">
+    <ServerAddressConfigurationModel>
+      <host>aquarium.dev.grnet.gr</host>
+      <port>27017</port>
+    </ServerAddressConfigurationModel>
+  </hosts>
+</MongoDBConfigurationModel>
index b813c58..df10f04 100644 (file)
@@ -97,6 +97,7 @@ class MessagingTest extends Loggable {
 
     xml
   }
+
   @Test
   def testConfigurationsExist {
     assertTrue(rabbitmqRC.getResource(PropFiles.configurations).isJust)
diff --git a/logic/src/test/scala/gr/grnet/aquarium/store/mongodb/MongoDBStoreTest.scala b/logic/src/test/scala/gr/grnet/aquarium/store/mongodb/MongoDBStoreTest.scala
new file mode 100644 (file)
index 0000000..5f31646
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.store
+package mongodb
+
+import confmodel.{ServerAddressConfigurationModel, MongoDBConfigurationModel}
+import org.junit.Test
+import org.junit.Assert._
+
+import com.ckkloverdos.resource.DefaultResourceContext
+import MongoDBConnection.{RCFolders, PropFiles, DBNames, CollectionNames}
+import gr.grnet.aquarium.util.xstream.XStreamHelpers
+import com.mongodb.casbah.commons.MongoDBObject
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class MongoDBStoreTest {
+  val baseRC = DefaultResourceContext
+  val mongodbRC = baseRC / RCFolders.mongodb
+  val xs = XStreamHelpers.newXStream
+
+  private def _getTestConf: String = {
+    val address1 = ServerAddressConfigurationModel("aquarium.dev.grnet.gr", 27017)
+    val model = new MongoDBConfigurationModel(List(address1), true, "SAFE")
+    val xml = xs.toXML(model)
+    xml
+  }
+
+  @Test
+  def testConfigurationExists: Unit = {
+    assertTrue(mongodbRC.getLocalResource(PropFiles.local_message_store).isJust)
+  }
+
+  @Test
+  def testConnection: Unit = {
+    for {
+      confResource <- mongodbRC.getLocalResource(PropFiles.local_message_store)
+    } {
+      val xs = XStreamHelpers.newXStream
+      val maybeModel = XStreamHelpers.parseType[MongoDBConfigurationModel](confResource, xs)
+      assertTrue(maybeModel.isJust)
+      for(model <- maybeModel) {
+        val mongo = new MongoDBConnection(model)
+        println(mongo._mongoConnection)
+        println(mongo._mongoConnection.getAllAddress())
+        println(mongo._mongoConnection.getConnectPoint())
+        val db = mongo._mongoConnection(DBNames.test)
+        val collection = db.apply(CollectionNames.test)
+        val obj = MongoDBObject("1" -> "one", "2" -> "two")
+        collection.insert(obj)
+      }
+    }
+  }
+}
\ No newline at end of file
index ed03a27..98d289d 100644 (file)
@@ -62,7 +62,9 @@ class Aquarium(info: ProjectInfo) extends ParentProject(info) {
                val lib_yaml      = "org.yaml"       % "snakeyaml"       % "1.9"  withSources()
                val lib_jcrontab  = "com.kenai.crontab-parser" % "crontab-parser" % "1.0.1" withSources()
                val lib_xstream   = "com.thoughtworks.xstream" % "xstream"     % "1.4.1" withSources()
-               val lib_rabbit    = "com.rabbitmq"   % "amqp-client"     % "2.7.0" withSources()
+               val lib_rabbit    = "com.rabbitmq"   % "amqp-client"       % "2.7.0" withSources()
+//    val lib_mongo     = "org.mongodb"    % "mongo-java-driver" % "2.7.2" withSources()
+    val lib_casbah    = "com.mongodb.casbah" % "casbah-core_2.9.1"  % "2.1.5-1" withSources()
 
                val lib_converter      = "com.ckkloverdos" % "converter_2.9.1"      % "0.3.0" withSources()
                val lib_streamresource = "com.ckkloverdos" % "streamresource_2.9.1" % "0.2.0" withSources()