val serverAddresses = hosts.map(sacm => new ServerAddress(sacm.host, sacm.port))
val mongo = MongoConnection(serverAddresses)
- logger.info("Created MongoDB connection %s".format(mongo))
+ logger.info("Created MongoDB connection %s for hosts %s".format(mongo, confModel.hosts.map(h => "%s:%s".format(h.host, h.port)).mkString(", ")))
if(confModel.slaveOK) {
mongo.slaveOk()
object PropFiles {
val local_message_store = "local-message-store.xml"
+ val aquarium_message_store = "aquarium-message-store.xml"
}
object DBNames {
--- /dev/null
+<MongoDBConfigurationModel>
+ <slaveOK>true</slaveOK>
+ <writeConcern>SAFE</writeConcern>
+ <hosts class="List">
+ <ServerAddressConfigurationModel>
+ <host>aquarium.dev.grnet.gr</host>
+ <port>27017</port>
+ </ServerAddressConfigurationModel>
+ </hosts>
+</MongoDBConfigurationModel>
<writeConcern>SAFE</writeConcern>
<hosts class="List">
<ServerAddressConfigurationModel>
- <host>aquarium.dev.grnet.gr</host>
+ <host>localhost</host>
<port>27017</port>
</ServerAddressConfigurationModel>
</hosts>
private def testPropertyFalse(name: String): Boolean = !testPropertyTrue(name)
- val EnableRabbitMQTests = testPropertyFalse("test.skip.rabbitmq")
- val EnableMongoDBTests = testPropertyFalse("test.skip.mongodb")
+ val EnableRabbitMQTests = testPropertyFalse(PropertyNames.TestSkipRabbitMQ)
+ val EnableMongoDBTests = testPropertyFalse(PropertyNames.TestSkipMongoDB)
}
\ No newline at end of file
--- /dev/null
+/*
+ * 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
+
+/**
+ * Test-related proeprty names.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+object PropertyNames {
+ // Test enabling/disabling
+ val TestSkipRabbitMQ = "test.skip.rabbitmq"
+ val TestSkipMongoDB = "test.skip.mongodb"
+
+ // Test configuration files used
+ val MongoDBLocalStoreConf = "mongodb.store.conf"
+}
\ No newline at end of file
import MongoDBConnection.{RCFolders, PropFiles, DBNames, CollectionNames}
import gr.grnet.aquarium.util.xstream.XStreamHelpers
import com.mongodb.casbah.commons.MongoDBObject
+import com.ckkloverdos.sys.SysProp
+import util.Loggable
/**
*
* @author Christos KK Loverdos <loverdos@gmail.com>.
*/
-class MongoDBStoreTest {
+class MongoDBStoreTest extends Loggable {
val baseRC = DefaultResourceContext
val mongodbRC = baseRC / RCFolders.mongodb
val xs = XStreamHelpers.newXStream
+ lazy val MongoDBPropFile = {
+ val filename = SysProp(PropertyNames.MongoDBLocalStoreConf).value.getOr(PropFiles.local_message_store)
+ logger.debug("Using mongodb configuration from %s".format(filename))
+ filename
+ }
+
private def _getTestConf: String = {
val address1 = ServerAddressConfigurationModel("aquarium.dev.grnet.gr", 27017)
val model = new MongoDBConfigurationModel(List(address1), true, "SAFE")
@Test
def testConfigurationExists: Unit = {
- assertTrue(mongodbRC.getLocalResource(PropFiles.local_message_store).isJust)
+ assertTrue(mongodbRC.getLocalResource(MongoDBPropFile).isJust)
}
@Test
assumeTrue(LogicTestsAssumptions.EnableMongoDBTests)
for {
- confResource <- mongodbRC.getLocalResource(PropFiles.local_message_store)
+ confResource <- mongodbRC.getLocalResource(MongoDBPropFile)
} {
val xs = XStreamHelpers.newXStream
+ logger.debug("Reading mongodb configuration from %s".format(confResource.url))
+ logger.debug("mongodb configuration is:\n%s".format(confResource.stringContent.getOr("")))
val maybeModel = XStreamHelpers.parseType[MongoDBConfigurationModel](confResource, xs)
assertTrue(maybeModel.isJust)
+ val obj = MongoDBObject("1" -> "one", "2" -> "two")
+ logger.debug("Inserting %s into mongodb".format(obj))
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)
}
}