RYA-174 Removing Mongo Test Factory from non-test code

Closes #118


Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/f0b11e2c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/f0b11e2c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/f0b11e2c

Branch: refs/heads/master
Commit: f0b11e2cd3d276ae1207c8d3ecb8dd2b7827df84
Parents: 961b16a
Author: Aaron Mihalik <aaron.miha...@gmail.com>
Authored: Thu Oct 20 23:23:59 2016 -0400
Committer: Aaron Mihalik <aaron.miha...@gmail.com>
Committed: Tue Nov 1 11:44:47 2016 -0400

----------------------------------------------------------------------
 .../apache/rya/mongodb/MockMongoFactory.java    | 97 ++++++++++++++++++++
 .../rya/mongodb/MongoConnectorFactory.java      | 35 ++-----
 .../rya/mongodb/MongoDBRdfConfiguration.java    |  9 --
 .../org/apache/rya/mongodb/MongoDBRyaDAO.java   |  4 -
 .../rya/mongodb/MongoDBQueryEngineTest.java     |  1 -
 .../org/apache/rya/mongodb/MongoDBRyaDAOIT.java |  1 -
 .../apache/rya/mongodb/MongoDBRyaDAOTest.java   |  1 -
 .../apache/rya/mongodb/MongoRyaTestBase.java    | 73 +--------------
 .../indexing/mongodb/AbstractMongoIndexer.java  |  6 +-
 .../mongo/MongoFreeTextIndexerTest.java         |  1 -
 .../mongo/MongoTemporalIndexerTest.java         |  1 -
 .../src/main/java/MongoRyaDirectExample.java    | 32 +++++--
 .../indexing/mongo/MongoGeoIndexerSfTest.java   |  1 -
 .../rya/indexing/mongo/MongoGeoIndexerTest.java |  1 -
 14 files changed, 141 insertions(+), 122 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MockMongoFactory.java
----------------------------------------------------------------------
diff --git 
a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MockMongoFactory.java 
b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MockMongoFactory.java
new file mode 100644
index 0000000..baafcea
--- /dev/null
+++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MockMongoFactory.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rya.mongodb;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.UnknownHostException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.mongodb.MongoClient;
+import com.mongodb.MongoException;
+import com.mongodb.ServerAddress;
+
+import de.flapdoodle.embed.mongo.Command;
+import de.flapdoodle.embed.mongo.MongodExecutable;
+import de.flapdoodle.embed.mongo.MongodProcess;
+import de.flapdoodle.embed.mongo.MongodStarter;
+import de.flapdoodle.embed.mongo.config.IMongodConfig;
+import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
+import de.flapdoodle.embed.mongo.config.Net;
+import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
+import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion;
+import de.flapdoodle.embed.mongo.distribution.Version;
+
+public class MockMongoFactory {
+    private static Logger logger = 
LoggerFactory.getLogger(MockMongoFactory.class.getName());
+
+    public static MockMongoFactory newFactory() throws IOException {
+        return MockMongoFactory.with(Version.Main.PRODUCTION);
+    }
+    
+    public static MockMongoFactory with(final IFeatureAwareVersion version) 
throws IOException {
+        return new MockMongoFactory(version);
+    }
+
+    private final MongodExecutable mongodExecutable;
+    private final MongodProcess mongodProcess;
+
+    /**
+     * Create the testing utility using the specified version of MongoDB.
+     * 
+     * @param version
+     *            version of MongoDB.
+     */
+    private MockMongoFactory(final IFeatureAwareVersion version) throws 
IOException {
+        final MongodStarter runtime = MongodStarter.getInstance(new 
RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).build());
+        mongodExecutable = runtime.prepare(newMongodConfig(version));
+        mongodProcess = mongodExecutable.start();
+    }
+
+    private IMongodConfig newMongodConfig(final IFeatureAwareVersion version) 
throws UnknownHostException, IOException {
+        Net net = new Net(findRandomOpenPortOnAllLocalInterfaces(), false);
+        return new MongodConfigBuilder().version(version).net(net).build();
+    }
+
+    private int findRandomOpenPortOnAllLocalInterfaces() throws IOException {
+        try (ServerSocket socket = new ServerSocket(0);) {
+            return socket.getLocalPort();
+        }
+    }
+
+    /**
+     * Creates a new Mongo connection.
+     * 
+     * @throws MongoException
+     * @throws UnknownHostException
+     */
+    public MongoClient newMongoClient() throws UnknownHostException, 
MongoException {
+        return new MongoClient(new 
ServerAddress(mongodProcess.getConfig().net().getServerAddress(), 
mongodProcess.getConfig().net().getPort()));
+    }
+
+    /**
+     * Cleans up the resources created by the utility.
+     */
+    public void shutdown() {
+        mongodProcess.stop();
+        mongodExecutable.stop();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java
----------------------------------------------------------------------
diff --git 
a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java
 
b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java
index bd3e86f..c240675 100644
--- 
a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java
+++ 
b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java
@@ -1,5 +1,3 @@
-package org.apache.rya.mongodb;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -8,9 +6,9 @@ package org.apache.rya.mongodb;
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ * 
  *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,12 +16,13 @@ package org.apache.rya.mongodb;
  * specific language governing permissions and limitations
  * under the License.
  */
+package org.apache.rya.mongodb;
 
-import java.net.UnknownHostException;
-import java.util.Arrays;
 import java.io.IOException;
+import java.util.Arrays;
 
 import org.apache.commons.configuration.ConfigurationRuntimeException;
+import org.apache.commons.io.IOUtils;
 import org.apache.hadoop.conf.Configuration;
 
 import com.mongodb.MongoClient;
@@ -31,9 +30,6 @@ import com.mongodb.MongoCredential;
 import com.mongodb.MongoException;
 import com.mongodb.ServerAddress;
 
-import de.flapdoodle.embed.mongo.distribution.Version;
-import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
-
 /**
  * Mongo convention generally allows for a single instance of a {@link 
MongoClient}
  * throughout the life cycle of an application.  This MongoConnectorFactory 
lazy
@@ -56,28 +52,17 @@ public class MongoConnectorFactory {
     public static synchronized MongoClient getMongoClient(final Configuration 
conf)
             throws ConfigurationRuntimeException, MongoException {
         if (mongoClient == null) {
-            // The static client has not yet created, is it a test/mock 
instance, or a service?
-            if (conf.getBoolean(MongoDBRdfConfiguration.USE_TEST_MONGO, 
false)) {
-                createMongoClientForTests();
-            } else {
-                createMongoClientForServer(conf);
-            }
+            createMongoClientForServer(conf);
         }
         return mongoClient;
     }
 
     /**
-     * Create a local temporary MongoDB instance and client object and assign 
it to this class's static mongoClient 
-     * @throws MongoException  if can't connect
+     * Silently closes the underlying Mongo client.
      */
-    private static void createMongoClientForTests() throws MongoException {
-        try {
-            MongodForTestsFactory testsFactory = 
MongodForTestsFactory.with(Version.Main.PRODUCTION);
-            mongoClient = testsFactory.newMongo();
-        } catch (IOException e) {
-            // Rethrow as an unchecked error.  Since we are in a test mode 
here, just fail fast.
-            throw new MongoException(MSG_INTRO+"creating a factory for a 
test/mock MongoDB instance.",e);
-        }
+    public static synchronized void closeMongoClient() {
+        IOUtils.closeQuietly(mongoClient);
+        mongoClient = null;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRdfConfiguration.java
----------------------------------------------------------------------
diff --git 
a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRdfConfiguration.java
 
b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRdfConfiguration.java
index 99f276b..49e74cc 100644
--- 
a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRdfConfiguration.java
+++ 
b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRdfConfiguration.java
@@ -39,7 +39,6 @@ public class MongoDBRdfConfiguration extends 
RdfCloudTripleStoreConfiguration {
     public static final String MONGO_COLLECTION_PREFIX = 
"mongo.db.collectionprefix";
     public static final String MONGO_USER = "mongo.db.user";
     public static final String  MONGO_USER_PASSWORD = "mongo.db.userpassword";
-    public static final String USE_TEST_MONGO = "mongo.db.test";
     public static final String CONF_ADDITIONAL_INDEXERS = 
"ac.additional.indexers";
        private MongoClient mongoClient;
 
@@ -56,14 +55,6 @@ public class MongoDBRdfConfiguration extends 
RdfCloudTripleStoreConfiguration {
         return new MongoDBRdfConfiguration(this);
     }
 
-    public boolean getUseTestMongo() {
-        return this.getBoolean(USE_TEST_MONGO, false);
-    }
-
-    public void setUseTestMongo(boolean useTestMongo) {
-        this.setBoolean(USE_TEST_MONGO, useTestMongo);
-    }
-
     public String getTriplesCollectionName() {
         return this.get(MONGO_COLLECTION_PREFIX, "rya") + "_triples";
     }

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java
----------------------------------------------------------------------
diff --git 
a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java 
b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java
index 8967a79..fe78f3a 100644
--- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java
+++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBRyaDAO.java
@@ -63,7 +63,6 @@ public final class MongoDBRyaDAO implements 
RyaDAO<MongoDBRdfConfiguration>{
     private MongoDBQueryEngine queryEngine;
     private MongoDBStorageStrategy storageStrategy;
     private MongoDBNamespaceManager nameSpaceManager;
-    private MongodForTestsFactory testsFactory;
 
     private List<MongoSecondaryIndex> secondaryIndexers;
 
@@ -139,9 +138,6 @@ public final class MongoDBRyaDAO implements 
RyaDAO<MongoDBRdfConfiguration>{
         if (mongoClient != null) {
             mongoClient.close();
         }
-        if (conf.getUseTestMongo()) {
-            testsFactory.shutdown();
-        }
 
         IOUtils.closeQuietly(queryEngine);
     }

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineTest.java
----------------------------------------------------------------------
diff --git 
a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineTest.java
 
b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineTest.java
index c6baf1f..1670b74 100644
--- 
a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineTest.java
+++ 
b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBQueryEngineTest.java
@@ -52,7 +52,6 @@ public class MongoDBQueryEngineTest extends MongoRyaTestBase {
     public void setUp() throws Exception {
         // Set up Mongo/Rya
         Configuration conf = new Configuration();
-        conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
         conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
         conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
         conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java
----------------------------------------------------------------------
diff --git 
a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java 
b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java
index b48f1eb..b4f7819 100644
--- a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java
+++ b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOIT.java
@@ -46,7 +46,6 @@ public class MongoDBRyaDAOIT extends MongoRyaTestBase {
     @Before
     public void setUp() throws IOException, RyaDAOException{
            final Configuration conf = new Configuration();
-            conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
             conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
             conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
             conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOTest.java
----------------------------------------------------------------------
diff --git 
a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOTest.java 
b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOTest.java
index 5b19d5a..5be4940 100644
--- 
a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOTest.java
+++ 
b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoDBRyaDAOTest.java
@@ -43,7 +43,6 @@ public class MongoDBRyaDAOTest extends MongoRyaTestBase {
        @Before
        public void setUp() throws IOException, RyaDAOException{
                final Configuration conf = new Configuration();
-        conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
         conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
         conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
         conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoRyaTestBase.java
----------------------------------------------------------------------
diff --git 
a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoRyaTestBase.java 
b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoRyaTestBase.java
index 340d5ae..cc69e76 100644
--- a/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoRyaTestBase.java
+++ b/dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/MongoRyaTestBase.java
@@ -19,39 +19,24 @@
 package org.apache.rya.mongodb;
 
 import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.UnknownHostException;
 
 import org.apache.rya.api.persist.RyaDAOException;
 import org.junit.After;
 import org.junit.Before;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.mongodb.MongoClient;
-import com.mongodb.MongoException;
-import com.mongodb.ServerAddress;
 
-import de.flapdoodle.embed.mongo.Command;
-import de.flapdoodle.embed.mongo.MongodExecutable;
-import de.flapdoodle.embed.mongo.MongodProcess;
-import de.flapdoodle.embed.mongo.MongodStarter;
-import de.flapdoodle.embed.mongo.config.IMongodConfig;
-import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
-import de.flapdoodle.embed.mongo.config.Net;
-import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
-import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion;
 import de.flapdoodle.embed.mongo.distribution.Version;
 
 public class MongoRyaTestBase {
 
-    protected RyaMongodForTestsFactory testsFactory;
+    protected MockMongoFactory testsFactory;
     protected MongoClient mongoClient;
 
     @Before
     public void MongoRyaTestBaseSetUp() throws IOException, RyaDAOException {
-        testsFactory = RyaMongodForTestsFactory.with(Version.Main.PRODUCTION);
-        mongoClient = testsFactory.newMongo();
+        testsFactory = MockMongoFactory.with(Version.Main.PRODUCTION);
+        mongoClient = testsFactory.newMongoClient();
     }
 
     @After
@@ -62,57 +47,7 @@ public class MongoRyaTestBase {
         if (testsFactory != null) {
             testsFactory.shutdown();
         }
+        MongoConnectorFactory.closeMongoClient();
     }
 
-    private static class RyaMongodForTestsFactory {
-        private static Logger logger = 
LoggerFactory.getLogger(RyaMongodForTestsFactory.class.getName());
-
-        public static RyaMongodForTestsFactory with(final IFeatureAwareVersion 
version) throws IOException {
-            return new RyaMongodForTestsFactory(version);
-        }
-
-        private final MongodExecutable mongodExecutable;
-        private final MongodProcess mongodProcess;
-
-        /**
-         * Create the testing utility using the specified version of MongoDB.
-         * 
-         * @param version
-         *            version of MongoDB.
-         */
-        private RyaMongodForTestsFactory(final IFeatureAwareVersion version) 
throws IOException {
-            final MongodStarter runtime = MongodStarter.getInstance(new 
RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).build());
-            mongodExecutable = runtime.prepare(newMongodConfig(version));
-            mongodProcess = mongodExecutable.start();
-        }
-
-        private IMongodConfig newMongodConfig(final IFeatureAwareVersion 
version) throws UnknownHostException, IOException {
-            Net net = new Net(findRandomOpenPortOnAllLocalInterfaces(), false);
-            return new MongodConfigBuilder().version(version).net(net).build();
-        }
-
-        private int findRandomOpenPortOnAllLocalInterfaces() throws 
IOException {
-            try (ServerSocket socket = new ServerSocket(0);) {
-                return socket.getLocalPort();
-            }
-        }
-
-        /**
-         * Creates a new Mongo connection.
-         * 
-         * @throws MongoException
-         * @throws UnknownHostException
-         */
-        private MongoClient newMongo() throws UnknownHostException, 
MongoException {
-            return new MongoClient(new 
ServerAddress(mongodProcess.getConfig().net().getServerAddress(), 
mongodProcess.getConfig().net().getPort()));
-        }
-
-        /**
-         * Cleans up the resources created by the utility.
-         */
-        public void shutdown() {
-            mongodProcess.stop();
-            mongodExecutable.stop();
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/AbstractMongoIndexer.java
----------------------------------------------------------------------
diff --git 
a/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/AbstractMongoIndexer.java
 
b/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/AbstractMongoIndexer.java
index c73606f..56070b7 100644
--- 
a/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/AbstractMongoIndexer.java
+++ 
b/extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/AbstractMongoIndexer.java
@@ -36,6 +36,7 @@ import com.mongodb.DBCursor;
 import com.mongodb.DBObject;
 import com.mongodb.MongoClient;
 import com.mongodb.QueryBuilder;
+import com.mongodb.ServerAddress;
 
 import info.aduna.iteration.CloseableIteration;
 import org.apache.rya.api.domain.RyaStatement;
@@ -71,14 +72,17 @@ public abstract class AbstractMongoIndexer<T extends 
IndexingMongoDBStorageStrat
         collection = 
db.getCollection(conf.get(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, 
"rya") + getCollectionName());
     }
     
+    @Override
     public void setClient(MongoClient client){
        this.mongoClient = client;
     }
 
     // TODO this method is only intended to be used in testing
     public void initIndexer(final Configuration conf, final MongoClient 
client) {
+        ServerAddress address = client.getAddress();
+        conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE, address.getHost());
+        conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT, 
Integer.toString(address.getPort()));
         setConf(conf);
-        setClient(client);
         if (!isInit) {
             init();
             isInit = true;

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoFreeTextIndexerTest.java
----------------------------------------------------------------------
diff --git 
a/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoFreeTextIndexerTest.java
 
b/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoFreeTextIndexerTest.java
index 637610d..0806349 100644
--- 
a/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoFreeTextIndexerTest.java
+++ 
b/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoFreeTextIndexerTest.java
@@ -56,7 +56,6 @@ public class MongoFreeTextIndexerTest extends 
MongoRyaTestBase {
     public void before() throws Exception {
         conf = new AccumuloRdfConfiguration();
         conf.set(ConfigUtils.USE_MONGO, "true");
-        conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
         conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
         conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
         conf.setTablePrefix("another_");

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoTemporalIndexerTest.java
----------------------------------------------------------------------
diff --git 
a/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoTemporalIndexerTest.java
 
b/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoTemporalIndexerTest.java
index 9e81c90..2b4c91c 100644
--- 
a/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoTemporalIndexerTest.java
+++ 
b/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoTemporalIndexerTest.java
@@ -177,7 +177,6 @@ public final class MongoTemporalIndexerTest extends 
MongoRyaTestBase {
     public void before() throws Exception {
         conf = new MongoDBRdfConfiguration();
         conf.set(ConfigUtils.USE_MONGO, "true");
-        conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
         conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
         conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
         conf.setTablePrefix("isthisused_");

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
----------------------------------------------------------------------
diff --git a/extras/indexingExample/src/main/java/MongoRyaDirectExample.java 
b/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
index 27ec9b9..b0fbdbd 100644
--- a/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
+++ b/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
@@ -17,6 +17,7 @@
  * under the License.
  */
 
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.commons.lang.Validate;
@@ -43,9 +44,14 @@ import org.openrdf.repository.sail.SailRepository;
 import org.openrdf.repository.sail.SailRepositoryConnection;
 import org.openrdf.sail.Sail;
 
+import com.mongodb.MongoClient;
+import com.mongodb.ServerAddress;
+
 import org.apache.rya.api.RdfCloudTripleStoreConfiguration;
 import org.apache.rya.indexing.GeoConstants;
 import org.apache.rya.indexing.accumulo.ConfigUtils;
+import org.apache.rya.mongodb.MockMongoFactory;
+import org.apache.rya.mongodb.MongoConnectorFactory;
 import org.apache.rya.mongodb.MongoDBRdfConfiguration;
 import org.apache.rya.rdftriplestore.RdfCloudTripleStore;
 import org.apache.rya.rdftriplestore.inference.InferenceEngineException;
@@ -97,6 +103,10 @@ public class MongoRyaDirectExample {
             log.info("Shutting down");
             closeQuietly(conn);
             closeQuietly(repository);
+            if (mock != null) {
+                mock.shutdown();
+            }
+            MongoConnectorFactory.closeMongoClient();
         }
     }
 
@@ -255,19 +265,27 @@ public class MongoRyaDirectExample {
         Validate.isTrue(tupleHandler.getCount() == 2);
     }
 
-    private static Configuration getConf() {
+    private static MockMongoFactory mock = null;
+    private static Configuration getConf() throws IOException {
 
         MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration();
         conf.set(ConfigUtils.USE_MONGO, "true");
 
-        // User name and password must be filled in:
-        conf.set(MongoDBRdfConfiguration.MONGO_USER, "fill this in");
-        conf.set(MongoDBRdfConfiguration.MONGO_USER_PASSWORD, "fill this in");
-        conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, 
Boolean.toString(USE_MOCK));
-        if (!USE_MOCK){
+        if (USE_MOCK) {
+            mock = MockMongoFactory.newFactory();
+            MongoClient c = mock.newMongoClient();
+            ServerAddress address = c.getAddress();
+            String url = address.getHost();
+            String port = Integer.toString(address.getPort());
+            c.close();
+            conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE, url);
+            conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT, port);
+        } else {
+            // User name and password must be filled in:
+            conf.set(MongoDBRdfConfiguration.MONGO_USER, "fill this in");
+            conf.set(MongoDBRdfConfiguration.MONGO_USER_PASSWORD, "fill this 
in");
             conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE, 
MONGO_INSTANCE_URL);
             conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT, 
MONGO_INSTANCE_PORT);
-               
         }
         conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, MONGO_DB);
         conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, 
MONGO_COLL_PREFIX);

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
----------------------------------------------------------------------
diff --git 
a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
 
b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
index 057b6c7..0021e44 100644
--- 
a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
+++ 
b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerSfTest.java
@@ -109,7 +109,6 @@ public class MongoGeoIndexerSfTest extends MongoRyaTestBase 
{
         System.out.println(UUID.randomUUID().toString());
         conf = new MongoDBRdfConfiguration();
         conf.set(ConfigUtils.USE_MONGO, "true");
-        conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
         conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
         conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
         conf.set(ConfigUtils.GEO_PREDICATES_LIST, 
"http://www.opengis.net/ont/geosparql#asWKT";);

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f0b11e2c/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
----------------------------------------------------------------------
diff --git 
a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
 
b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
index 08d15a6..fddcc0f 100644
--- 
a/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
+++ 
b/extras/rya.geoindexing/src/test/java/org/apache/rya/indexing/mongo/MongoGeoIndexerTest.java
@@ -68,7 +68,6 @@ public class MongoGeoIndexerTest extends MongoRyaTestBase {
     public void before() throws Exception {
         conf = new MongoDBRdfConfiguration();
         conf.set(ConfigUtils.USE_MONGO, "true");
-        conf.set(MongoDBRdfConfiguration.USE_TEST_MONGO, "true");
         conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, "test");
         conf.set(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya_");
         conf.set(ConfigUtils.GEO_PREDICATES_LIST, 
"http://www.opengis.net/ont/geosparql#asWKT";);

Reply via email to