http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/767349da/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java
----------------------------------------------------------------------
diff --git 
a/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java 
b/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java
index e156f86..1ec8543 100644
--- 
a/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java
+++ 
b/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java
@@ -1,4 +1,4 @@
-/*
+/**
  * 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
@@ -20,12 +20,14 @@ package org.apache.rya.sail.config;
 
 import static java.util.Objects.requireNonNull;
 
-import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Objects;
 
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.Connector;
+import org.apache.commons.configuration.ConfigurationRuntimeException;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.rya.accumulo.AccumuloRdfConfiguration;
 import org.apache.rya.accumulo.AccumuloRyaDAO;
@@ -37,9 +39,10 @@ import org.apache.rya.api.layout.TablePrefixLayoutStrategy;
 import org.apache.rya.api.persist.RyaDAO;
 import org.apache.rya.api.persist.RyaDAOException;
 import org.apache.rya.indexing.accumulo.ConfigUtils;
-import org.apache.rya.mongodb.MongoConnectorFactory;
 import org.apache.rya.mongodb.MongoDBRdfConfiguration;
 import org.apache.rya.mongodb.MongoDBRyaDAO;
+import org.apache.rya.mongodb.MongoSecondaryIndex;
+import org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration;
 import org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository;
 import org.apache.rya.rdftriplestore.RdfCloudTripleStore;
 import org.apache.rya.rdftriplestore.inference.InferenceEngine;
@@ -50,6 +53,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.mongodb.MongoClient;
+import com.mongodb.MongoCredential;
+import com.mongodb.MongoException;
+import com.mongodb.ServerAddress;
 
 public class RyaSailFactory {
     private static final Logger LOG = 
LoggerFactory.getLogger(RyaSailFactory.class);
@@ -79,16 +85,38 @@ public class RyaSailFactory {
         Objects.requireNonNull(ryaInstance, "RyaInstance or table prefix is 
missing from configuration."+RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
 
         if(ConfigUtils.getUseMongo(config)) {
-            final MongoDBRdfConfiguration mongoConfig = new 
MongoDBRdfConfiguration(config);
-            rdfConfig = mongoConfig;
-            final MongoClient client = 
MongoConnectorFactory.getMongoClient(config);
+            // Get a reference to a Mongo DB configuration object.
+            final MongoDBRdfConfiguration mongoConfig = (config instanceof 
MongoDBRdfConfiguration) ?
+                    (MongoDBRdfConfiguration)config : new 
MongoDBRdfConfiguration(config);
+
+            // Create the MongoClient that will be used by the Sail object's 
components.
+            final MongoClient client = createMongoClient(mongoConfig);
+
+            // Add the Indexer and Optimizer names to the configuration object 
that are configured to be used.
+            ConfigUtils.setIndexers(mongoConfig);
+
+            // Initialize the indexer and optimizer objects that will be used 
within the Sail object.
+            final List<MongoSecondaryIndex> indexers = 
mongoConfig.getInstances(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS, 
MongoSecondaryIndex.class);
+            // TODO Optimizers the same way. They're getting the wrong 
configuration somehow.
+
+            // Populate the configuration using previously stored Rya Details 
if this instance uses them.
             try {
-                final MongoRyaInstanceDetailsRepository ryaDetailsRepo = new 
MongoRyaInstanceDetailsRepository(client, mongoConfig.getCollectionName());
+                final MongoRyaInstanceDetailsRepository ryaDetailsRepo = new 
MongoRyaInstanceDetailsRepository(client, mongoConfig.getRyaInstance());
                 
RyaDetailsToConfiguration.addRyaDetailsToConfiguration(ryaDetailsRepo.getRyaInstanceDetails(),
 mongoConfig);
             } catch (final RyaDetailsRepositoryException e) {
                LOG.info("Instance does not have a rya details collection, 
skipping.");
-           }
-            dao = getMongoDAO((MongoDBRdfConfiguration)rdfConfig, client);
+            }
+
+            // Set the configuration to the stateful configuration that is 
used to pass the constructed objects around.
+            final StatefulMongoDBRdfConfiguration statefulConfig = new 
StatefulMongoDBRdfConfiguration(mongoConfig, client, indexers);
+            rdfConfig = statefulConfig;
+
+            // Create the DAO that is able to interact with MongoDB.
+            final MongoDBRyaDAO mongoDao = new MongoDBRyaDAO();
+            mongoDao.setConf(statefulConfig);
+            mongoDao.init();
+            dao = mongoDao;
+
         } else {
             rdfConfig = new AccumuloRdfConfiguration(config);
             user = rdfConfig.get(ConfigUtils.CLOUDBASE_USER);
@@ -115,20 +143,39 @@ public class RyaSailFactory {
         return store;
     }
 
-    private static MongoDBRyaDAO getMongoDAO(final MongoDBRdfConfiguration 
config, final MongoClient client) throws RyaDAOException {
-        MongoDBRyaDAO dao = null;
-        ConfigUtils.setIndexers(config);
-        if(client != null) {
-            dao = new MongoDBRyaDAO(config, client);
+    /**
+     * Create a {@link MongoClient} that is connected to the configured 
database.
+     *
+     * @param mongoConf - Configures what will be connected to. (not null)
+     * @throws ConfigurationRuntimeException An invalid port was provided by 
{@code mongoConf}.
+     * @throws MongoException Couldn't connect to the MongoDB database.
+     */
+    private static MongoClient createMongoClient(final MongoDBRdfConfiguration 
mongoConf) throws ConfigurationRuntimeException, MongoException {
+        requireNonNull(mongoConf);
+        requireNonNull(mongoConf.getMongoHostname());
+        requireNonNull(mongoConf.getMongoPort());
+        requireNonNull(mongoConf.getMongoDBName());
+
+        // Connect to a running MongoDB server.
+        final int port;
+        try {
+            port = Integer.parseInt( mongoConf.getMongoPort() );
+        } catch(final NumberFormatException e) {
+            throw new ConfigurationRuntimeException("Port '" + 
mongoConf.getMongoPort() + "' must be an integer.");
+        }
+
+        final ServerAddress server = new 
ServerAddress(mongoConf.getMongoHostname(), port);
+
+        // Connect to a specific MongoDB Database if that information is 
provided.
+        final String username = mongoConf.getMongoUser();
+        final String database = mongoConf.getMongoDBName();
+        final String password = mongoConf.getMongoPassword();
+        if(username != null && password != null) {
+            final MongoCredential cred = 
MongoCredential.createCredential(username, database, password.toCharArray());
+            return new MongoClient(server, Arrays.asList(cred));
         } else {
-            try {
-                dao = new MongoDBRyaDAO(config);
-            } catch (NumberFormatException | UnknownHostException e) {
-                throw new RyaDAOException("Unable to connect to mongo at the 
configured location.", e);
-            }
+            return new MongoClient(server);
         }
-        dao.init();
-        return dao;
     }
 
     /**
@@ -137,7 +184,7 @@ public class RyaSailFactory {
      * tables might be created when using this method.  This method does not 
require the {@link AccumuloRyaInstanceDetailsRepository}
      * to exist.  This is for internal use, backwards compatibility and 
testing purposes only.  It is recommended that
      * {@link 
RyaSailFactory#getAccumuloDAOWithUpdatedConfig(AccumuloRdfConfiguration)} be 
used for new installations of Rya.
-     * 
+     *
      * @param config - user configuration
      * @return - AccumuloRyaDAO with Indexers configured according to user's 
specification
      * @throws AccumuloException
@@ -155,14 +202,14 @@ public class RyaSailFactory {
         dao.init();
         return dao;
     }
-    
+
     /**
      * Creates an AccumuloRyaDAO after updating the AccumuloRdfConfiguration 
so that it is consistent
      * with the configuration of the RyaInstance that the user is trying to 
connect to.  This ensures
-     * that user configuration aligns with Rya instance configuration and 
prevents the creation of 
+     * that user configuration aligns with Rya instance configuration and 
prevents the creation of
      * new index tables based on a user's query configuration.  This method 
requires the {@link AccumuloRyaInstanceDetailsRepository}
      * to exist.
-     * 
+     *
      * @param config - user's query configuration
      * @return - AccumuloRyaDAO with an updated configuration that is 
consistent with the Rya instance configuration
      * @throws AccumuloException
@@ -170,16 +217,16 @@ public class RyaSailFactory {
      * @throws RyaDAOException
      */
     public static AccumuloRyaDAO getAccumuloDAOWithUpdatedConfig(final 
AccumuloRdfConfiguration config) throws AccumuloException, 
AccumuloSecurityException, RyaDAOException {
-        
-        String ryaInstance = 
config.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
+
+        final String ryaInstance = 
config.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
         Objects.requireNonNull(ryaInstance, "RyaInstance or table prefix is 
missing from configuration."+RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
-        String user = config.get(AccumuloRdfConfiguration.CLOUDBASE_USER);
-        String pswd = config.get(AccumuloRdfConfiguration.CLOUDBASE_PASSWORD);
+        final String user = 
config.get(AccumuloRdfConfiguration.CLOUDBASE_USER);
+        final String pswd = 
config.get(AccumuloRdfConfiguration.CLOUDBASE_PASSWORD);
         Objects.requireNonNull(user, "Accumulo user name is missing from 
configuration."+AccumuloRdfConfiguration.CLOUDBASE_USER);
         Objects.requireNonNull(pswd, "Accumulo user password is missing from 
configuration."+AccumuloRdfConfiguration.CLOUDBASE_PASSWORD);
         config.setTableLayoutStrategy( new 
TablePrefixLayoutStrategy(ryaInstance) );
         updateAccumuloConfig(config, user, pswd, ryaInstance);
-        
+
         return getAccumuloDAO(config);
     }
 
@@ -192,4 +239,62 @@ public class RyaSailFactory {
             LOG.info("Instance does not have a rya details collection, 
skipping.");
         }
     }
-}
\ No newline at end of file
+}
+
+
+
+///**
+//* TODO add docs.  names for reflection
+//* @param indexers
+//*/
+//public void setMongoIndexers(final Class<? extends MongoSecondaryIndex>... 
indexers) {
+// final List<String> strs = Lists.newArrayList();
+// for (final Class<?> ai : indexers){
+//     strs.add(ai.getName());
+// }
+//
+// setStrings(CONF_ADDITIONAL_INDEXERS, strs.toArray(new String[]{}));
+//}
+
+///**
+//* TODO add docs. explain hack is used here. do reflection. eww.
+//* @return
+//*/
+//public List<MongoSecondaryIndex> getAdditionalIndexers() {
+// stateLock.lock();
+// try {
+//     if(indexers == null) {
+//         indexers = getInstances(CONF_ADDITIONAL_INDEXERS, 
MongoSecondaryIndex.class);
+//     }
+//     return indexers;
+// } finally {
+//     stateLock.unlock();
+// }
+//}
+
+//// XXX Not sure what all of this stuff is for. I'm guessing Rya Sail state 
stuff.
+//public void setAdditionalIndexers(final Class<? extends 
MongoSecondaryIndex>... indexers) {
+//  final List<String> strs = Lists.newArrayList();
+//  for (final Class<?> ai : indexers){
+//      strs.add(ai.getName());
+//  }
+//
+//  setStrings(CONF_ADDITIONAL_INDEXERS, strs.toArray(new String[]{}));
+//}
+//
+
+//conf.setStrings(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS, 
indexList.toArray(new String[] {}));
+//conf.setStrings(RdfCloudTripleStoreConfiguration.CONF_OPTIMIZERS, 
optimizers.toArray(new String[] {}));
+
+//public List<MongoSecondaryIndex> getAdditionalIndexers() {
+//  return getInstances(CONF_ADDITIONAL_INDEXERS, MongoSecondaryIndex.class);
+//}
+
+//public void setMongoClient(final MongoClient client) {
+//  requireNonNull(client);
+//  this.mongoClient = client;
+//}
+//
+//public MongoClient getMongoClient() {
+//  return mongoClient;
+//}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/767349da/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoEntityIndexIT.java
----------------------------------------------------------------------
diff --git 
a/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoEntityIndexIT.java
 
b/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoEntityIndexIT.java
index 019760d..36e1445 100644
--- 
a/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoEntityIndexIT.java
+++ 
b/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoEntityIndexIT.java
@@ -32,10 +32,9 @@ import org.apache.rya.indexing.entity.model.Type;
 import org.apache.rya.indexing.entity.storage.EntityStorage;
 import org.apache.rya.indexing.entity.storage.TypeStorage;
 import org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer;
+import org.apache.rya.mongodb.MongoDBRdfConfiguration;
 import org.apache.rya.mongodb.MongoTestBase;
 import org.apache.rya.sail.config.RyaSailFactory;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.openrdf.model.URI;
 import org.openrdf.model.Value;
@@ -54,100 +53,130 @@ import com.google.common.collect.ImmutableSet;
 
 public class MongoEntityIndexIT extends MongoTestBase {
     private static final ValueFactory VF = ValueFactoryImpl.getInstance();
-    private SailRepositoryConnection conn;
-    private MongoEntityIndexer indexer;
 
-    @Before
-    public void setUp() throws Exception {
+    @Override
+    protected void updateConfiguration(final MongoDBRdfConfiguration conf) {
         conf.setBoolean(ConfigUtils.USE_MONGO, true);
         conf.setBoolean(ConfigUtils.USE_ENTITY, true);
-
-        final Sail sail = RyaSailFactory.getInstance(conf);
-        conn = new SailRepository(sail).getConnection();
-        conn.begin();
-
-        indexer = new MongoEntityIndexer();
-        indexer.setConf(conf);
-        indexer.init();
     }
 
-    @After
-    public void tearDown() throws Exception {
-        if (conn != null) {
-            conn.clear();
-        }
-        if (indexer != null) {
-            indexer.close();
-        }
-    }
+//    private SailRepositoryConnection conn;
+//    private MongoEntityIndexer indexer;
+
+//    @Before
+//    public void setUp() throws Exception {
+//        conf.setBoolean(ConfigUtils.USE_MONGO, true);
+//        conf.setBoolean(ConfigUtils.USE_ENTITY, true);
+//
+//        final Sail sail = RyaSailFactory.getInstance(conf);
+//        conn = new SailRepository(sail).getConnection();
+//        conn.begin();
+//
+//        indexer = new MongoEntityIndexer();
+//        indexer.setConf(conf);
+//        indexer.init();
+//    }
+//
+//    @After
+//    public void tearDown() throws Exception {
+//        if (conn != null) {
+//            conn.clear();
+//        }
+//        if (indexer != null) {
+//            indexer.close();
+//        }
+//    }
 
     @Test
     public void ensureInEntityStore_Test() throws Exception {
-        setupTypes();
-        addStatements();
+        final Sail sail = RyaSailFactory.getInstance(conf);
+        SailRepositoryConnection conn = new 
SailRepository(sail).getConnection();
+        conn.begin();
 
-        final EntityStorage entities = indexer.getEntityStorage(conf);
-        final RyaURI subject = new RyaURI("urn:alice");
-        final Optional<Entity> alice = entities.get(subject);
-        assertTrue(alice.isPresent());
+        try(MongoEntityIndexer indexer = new MongoEntityIndexer()) {
+            setupTypes(indexer);
+            addStatements(conn);
+
+            final EntityStorage entities = indexer.getEntityStorage(conf);
+            final RyaURI subject = new RyaURI("urn:alice");
+            final Optional<Entity> alice = entities.get(subject);
+            assertTrue(alice.isPresent());
+        } finally {
+            conn.close();
+        }
     }
 
     @Test
     public void sparqlQuery_Test() throws Exception {
-        setupTypes();
-        addStatements();
-        //conn.commit();
-
-        final String query = "SELECT * WHERE { " +
-                "<urn:strawberry> <" + RDF.TYPE + "> <urn:icecream> ."+
-                "<urn:strawberry> <urn:brand> ?brand . " +
-                "<urn:strawberry> <urn:flavor> ?flavor . " +
-            "}";
-
-        final TupleQueryResult rez = 
conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
-        final Set<BindingSet> results = new HashSet<>();
-        while(rez.hasNext()) {
-            final BindingSet bs = rez.next();
-            results.add(bs);
-        }
-        final MapBindingSet expected = new MapBindingSet();
-        expected.addBinding("flavor", 
ValueFactoryImpl.getInstance().createLiteral("Strawberry"));
-        expected.addBinding("brand", 
ValueFactoryImpl.getInstance().createLiteral("Awesome Icecream"));
+        final Sail sail = RyaSailFactory.getInstance(conf);
+        SailRepositoryConnection conn = new 
SailRepository(sail).getConnection();
+        conn.begin();
 
-        assertEquals(1, results.size());
-        assertEquals(expected, results.iterator().next());
+        try(MongoEntityIndexer indexer = new MongoEntityIndexer()) {
+            setupTypes(indexer);
+            addStatements(conn);
+
+            final String query = "SELECT * WHERE { " +
+                    "<urn:strawberry> <" + RDF.TYPE + "> <urn:icecream> ."+
+                    "<urn:strawberry> <urn:brand> ?brand . " +
+                    "<urn:strawberry> <urn:flavor> ?flavor . " +
+                    "}";
+
+            final TupleQueryResult rez = 
conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+            final Set<BindingSet> results = new HashSet<>();
+            while(rez.hasNext()) {
+                final BindingSet bs = rez.next();
+                results.add(bs);
+            }
+            final MapBindingSet expected = new MapBindingSet();
+            expected.addBinding("flavor", 
ValueFactoryImpl.getInstance().createLiteral("Strawberry"));
+            expected.addBinding("brand", 
ValueFactoryImpl.getInstance().createLiteral("Awesome Icecream"));
+
+            assertEquals(1, results.size());
+            assertEquals(expected, results.iterator().next());
+        } finally {
+            conn.close();
+        }
     }
 
     @Test
     public void partialQuery_Test() throws Exception {
-        setupTypes();
-        addStatements();
-        conn.commit();
-
-        final String query = "SELECT * WHERE { " +
-                "<urn:george> <" + RDF.TYPE + "> <urn:person> ."+
-                "<urn:george> <urn:name> ?name . " +
-                "<urn:george> <urn:eye> ?eye . " +
-            "}";
-
-        final TupleQueryResult rez = 
conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
-        final Set<BindingSet> results = new HashSet<>();
-        while(rez.hasNext()) {
-            final BindingSet bs = rez.next();
-            System.out.println(bs);
-            results.add(bs);
+        final Sail sail = RyaSailFactory.getInstance(conf);
+        SailRepositoryConnection conn = new 
SailRepository(sail).getConnection();
+        conn.begin();
+
+        try(MongoEntityIndexer indexer = new MongoEntityIndexer()) {
+            setupTypes(indexer);
+            addStatements(conn);
+            conn.commit();
+
+            final String query = "SELECT * WHERE { " +
+                    "<urn:george> <" + RDF.TYPE + "> <urn:person> ."+
+                    "<urn:george> <urn:name> ?name . " +
+                    "<urn:george> <urn:eye> ?eye . " +
+                "}";
+
+            final TupleQueryResult rez = 
conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
+            final Set<BindingSet> results = new HashSet<>();
+            while(rez.hasNext()) {
+                final BindingSet bs = rez.next();
+                System.out.println(bs);
+                results.add(bs);
+            }
+            final ValueFactory vf = ValueFactoryImpl.getInstance();
+            final MapBindingSet expected = new MapBindingSet();
+            //expected.addBinding("name", 
vf.createURI("http://www.w3.org/2001/SMLSchema#string";, "George"));
+            expected.addBinding("name", vf.createLiteral("George"));
+            expected.addBinding("eye", vf.createLiteral("blue"));
+
+            assertEquals(1, results.size());
+            assertEquals(expected, results.iterator().next());
+        } finally {
+            conn.close();
         }
-        final ValueFactory vf = ValueFactoryImpl.getInstance();
-        final MapBindingSet expected = new MapBindingSet();
-        //expected.addBinding("name", 
vf.createURI("http://www.w3.org/2001/SMLSchema#string";, "George"));
-        expected.addBinding("name", vf.createLiteral("George"));
-        expected.addBinding("eye", vf.createLiteral("blue"));
-
-        assertEquals(1, results.size());
-        assertEquals(expected, results.iterator().next());
     }
 
-    private void setupTypes() throws Exception {
+    private void setupTypes(MongoEntityIndexer indexer) throws Exception {
         final TypeStorage typeStore = indexer.getTypeStorage(conf);
         // Add some Types to the storage.
         final Type cat = new Type(new RyaURI("urn:cat"),
@@ -184,7 +213,7 @@ public class MongoEntityIndexIT extends MongoTestBase {
         typeStore.create(person);
     }
 
-    private void addStatements() throws Exception {
+    private void addStatements(SailRepositoryConnection conn) throws Exception 
{
         //alice
         URI subject = VF.createURI("urn:alice");
         URI predicate = VF.createURI("urn:name");
@@ -304,4 +333,4 @@ public class MongoEntityIndexIT extends MongoTestBase {
         conn.add(VF.createStatement(subject, predicate, object));
         conn.add(VF.createStatement(subject, RDF.TYPE, 
VF.createURI("urn:icecream")));
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/767349da/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 f111fd1..71840ea 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
@@ -1,5 +1,4 @@
-package org.apache.rya.indexing.mongo;
-/*
+/**
  * 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
@@ -17,6 +16,10 @@ package org.apache.rya.indexing.mongo;
  * specific language governing permissions and limitations
  * under the License.
  */
+package org.apache.rya.indexing.mongo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -30,7 +33,6 @@ import org.apache.rya.indexing.StatementConstraints;
 import org.apache.rya.indexing.accumulo.ConfigUtils;
 import org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer;
 import org.apache.rya.mongodb.MongoTestBase;
-import org.junit.Assert;
 import org.junit.Test;
 import org.openrdf.model.Statement;
 import org.openrdf.model.URI;
@@ -44,13 +46,17 @@ import com.google.common.collect.Sets;
 
 import info.aduna.iteration.CloseableIteration;
 
+/**
+ * Integration tests the methods of {@link MongoFreeTextIndexer}.
+ */
 public class MongoFreeTextIndexerTest extends MongoTestBase {
     private static final StatementConstraints EMPTY_CONSTRAINTS = new 
StatementConstraints();
 
     @Test
     public void testSearch() throws Exception {
         try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
-            f.initIndexer(conf, super.getMongoClient());
+            f.setConf(conf);
+            f.init();
 
             final ValueFactory vf = new ValueFactoryImpl();
 
@@ -64,17 +70,18 @@ public class MongoFreeTextIndexerTest extends MongoTestBase 
{
             f.storeStatement(RdfToRyaConversions.convertStatement(statement));
             f.flush();
 
-            Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("asdf", 
EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(), getSet(f.queryText("asdf", 
EMPTY_CONSTRAINTS)));
 
-            Assert.assertEquals(Sets.newHashSet(statement), 
getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
-            Assert.assertEquals(Sets.newHashSet(statement), 
getSet(f.queryText("hat new", EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(statement), getSet(f.queryText("new", 
EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat 
new", EMPTY_CONSTRAINTS)));
         }
     }
 
     @Test
     public void testDelete() throws Exception {
         try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
-            f.initIndexer(conf, super.getMongoClient());
+            f.setConf(conf);
+            f.init();
 
             final ValueFactory vf = new ValueFactoryImpl();
 
@@ -100,15 +107,15 @@ public class MongoFreeTextIndexerTest extends 
MongoTestBase {
 
 
             
f.deleteStatement(RdfToRyaConversions.convertStatement(statement1));
-            Assert.assertEquals(Sets.newHashSet(statement2), 
getSet(f.queryText("Do you like my new hat?", EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(statement2), getSet(f.queryText("Do 
you like my new hat?", EMPTY_CONSTRAINTS)));
 
             // Check that "new" didn't get deleted from the term table after 
"this is a new hat"
             // was deleted since "new" is still in "Do you like my new hat?"
-            Assert.assertEquals(Sets.newHashSet(statement2), 
getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(statement2), 
getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
 
             
f.deleteStatement(RdfToRyaConversions.convertStatement(statement2));
-            Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("this is 
a new hat", EMPTY_CONSTRAINTS)));
-            Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("Do you 
like my new hat?", EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(), getSet(f.queryText("this is a new 
hat", EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(), getSet(f.queryText("Do you like my 
new hat?", EMPTY_CONSTRAINTS)));
         }
     }
 
@@ -117,7 +124,8 @@ public class MongoFreeTextIndexerTest extends MongoTestBase 
{
         conf.setStrings(ConfigUtils.FREETEXT_PREDICATES_LIST, "pred:1,pred:2");
 
         try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
-            f.initIndexer(conf, super.getMongoClient());
+            f.setConf(conf);
+            f.init();
 
             // These should not be stored because they are not in the 
predicate list
             f.storeStatement(new RyaStatement(new RyaURI("foo:subj1"), new 
RyaURI(RDFS.LABEL.toString()), new RyaType("invalid")));
@@ -137,20 +145,21 @@ public class MongoFreeTextIndexerTest extends 
MongoTestBase {
 
             f.flush();
 
-            Assert.assertEquals(Sets.newHashSet(), 
getSet(f.queryText("invalid", EMPTY_CONSTRAINTS)));
-            Assert.assertEquals(Sets.newHashSet(), 
getSet(f.queryText("in:validURI", EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(), getSet(f.queryText("invalid", 
EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(), getSet(f.queryText("in:validURI", 
EMPTY_CONSTRAINTS)));
 
             final Set<Statement> actual = getSet(f.queryText("valid", 
EMPTY_CONSTRAINTS));
-            Assert.assertEquals(2, actual.size());
-            
Assert.assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s3)));
-            
Assert.assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s4)));
+            assertEquals(2, actual.size());
+            
assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s3)));
+            
assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s4)));
         }
     }
 
     @Test
     public void testContextSearch() throws Exception {
         try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
-            f.initIndexer(conf, super.getMongoClient());
+            f.setConf(conf);
+            f.init();
 
             final ValueFactory vf = new ValueFactoryImpl();
             final URI subject = new URIImpl("foo:subj");
@@ -162,19 +171,18 @@ public class MongoFreeTextIndexerTest extends 
MongoTestBase {
             f.storeStatement(RdfToRyaConversions.convertStatement(statement));
             f.flush();
 
-            Assert.assertEquals(Sets.newHashSet(statement), 
getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
-            Assert.assertEquals(Sets.newHashSet(statement), 
getSet(f.queryText("hat", new StatementConstraints().setContext(context))));
-            Assert.assertEquals(Sets.newHashSet(),
+            assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", 
EMPTY_CONSTRAINTS)));
+            assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", 
new StatementConstraints().setContext(context))));
+            assertEquals(Sets.newHashSet(),
                     getSet(f.queryText("hat", new 
StatementConstraints().setContext(vf.createURI("foo:context2")))));
         }
     }
 
-
     private static <X> Set<X> getSet(final CloseableIteration<X, ?> iter) 
throws Exception {
-        final Set<X> set = new HashSet<X>();
+        final Set<X> set = new HashSet<>();
         while (iter.hasNext()) {
             set.add(iter.next());
         }
         return set;
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/767349da/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoIndexingConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoIndexingConfigurationTest.java
 
b/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoIndexingConfigurationTest.java
index cbd18b2..1f083f2 100644
--- 
a/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoIndexingConfigurationTest.java
+++ 
b/extras/indexing/src/test/java/org/apache/rya/indexing/mongo/MongoIndexingConfigurationTest.java
@@ -68,11 +68,11 @@ public class MongoIndexingConfigurationTest {
         assertEquals(conf.getCv(), visibility);
         assertEquals(conf.isInfer(), useInference);
         assertEquals(conf.isDisplayQueryPlan(), displayPlan);
-        assertEquals(conf.getMongoInstance(), "host");
+        assertEquals(conf.getMongoHostname(), "host");
         assertEquals(conf.getBoolean(".useMockInstance", false), useMock);
         assertEquals(conf.getMongoPort(), "1000");
         assertEquals(conf.getMongoDBName(), "dbname");
-        assertEquals(conf.getCollectionName(), "prefix_");
+        assertEquals(conf.getRyaInstance(), "prefix_");
         assertEquals(conf.get(MongoDBRdfConfiguration.MONGO_USER), user);
         assertEquals(conf.get(MongoDBRdfConfiguration.MONGO_USER_PASSWORD), 
password);
         assertTrue(
@@ -103,11 +103,11 @@ public class MongoIndexingConfigurationTest {
         assertEquals(conf.getCv(), visibility);
         assertEquals(conf.isInfer(), useInference);
         assertEquals(conf.isDisplayQueryPlan(), displayPlan);
-        assertEquals(conf.getMongoInstance(), "host");
+        assertEquals(conf.getMongoHostname(), "host");
         assertEquals(conf.getBoolean(".useMockInstance", false), useMock);
         assertEquals(conf.getMongoPort(), "1000");
         assertEquals(conf.getMongoDBName(), "dbname");
-        assertEquals(conf.getCollectionName(), "prefix_");
+        assertEquals(conf.getRyaInstance(), "prefix_");
         assertEquals(conf.get(MongoDBRdfConfiguration.MONGO_USER), user);
         assertEquals(conf.get(MongoDBRdfConfiguration.MONGO_USER_PASSWORD), 
password);
         assertTrue(

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/767349da/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 215e64c..ec7d1ec 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
@@ -80,13 +80,13 @@ import info.aduna.iteration.CloseableIteration;
  *
  */
 public final class MongoTemporalIndexerTest extends MongoTestBase {
-    private MongoTemporalIndexer tIndexer;
-    private DBCollection collection;
+//    private MongoTemporalIndexer tIndexer;
+//    private DBCollection collection;
 
     private static final String URI_PROPERTY_EVENT_TIME = 
"Property:event:time";
     private static final String URI_PROPERTY_CIRCA = "Property:circa";
     private static final String URI_PROPERTY_AT_TIME = "Property:atTime";
-    private static final String STAT_VALUEHASH = "valuehash";
+//    private static final String STAT_VALUEHASH = "valuehash";
     private static final StatementConstraints EMPTY_CONSTRAINTS = new 
StatementConstraints();
 
     // Assign this in setUpBeforeClass, store them in each test.
@@ -164,85 +164,110 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
 
     @Before
     public void before() throws Exception {
+//        // This is from http://linkedevents.org/ontology
+//        // and http://motools.sourceforge.net/event/event.html
+//        conf.setStrings(ConfigUtils.TEMPORAL_PREDICATES_LIST, ""
+//                + URI_PROPERTY_AT_TIME + ","
+//                + URI_PROPERTY_CIRCA + ","
+//                + URI_PROPERTY_EVENT_TIME);
+
+//        tIndexer
+//        tIndexer.setConf(conf);
+//        tIndexer.init();
+////        tIndexer.initIndexer(conf, super.getMongoClient());
+
+//        final String dbName = 
conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME);
+//        final DB db = super.getMongoClient().getDB(dbName);
+//        collection = 
db.getCollection(conf.get(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, 
"rya") + tIndexer.getCollectionName());
+   }
+
+    @Override
+    protected void updateConfiguration(final MongoDBRdfConfiguration conf) {
         // This is from http://linkedevents.org/ontology
         // and http://motools.sourceforge.net/event/event.html
         conf.setStrings(ConfigUtils.TEMPORAL_PREDICATES_LIST, ""
                 + URI_PROPERTY_AT_TIME + ","
                 + URI_PROPERTY_CIRCA + ","
                 + URI_PROPERTY_EVENT_TIME);
-
-        tIndexer = new MongoTemporalIndexer();
-        tIndexer.initIndexer(conf, super.getMongoClient());
-
-        final String dbName = conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME);
-        final DB db = super.getMongoClient().getDB(dbName);
-        collection = 
db.getCollection(conf.get(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, 
"rya") + tIndexer.getCollectionName());
-   }
+    }
 
     /**
      * Test method for {@link 
MongoTemporalIndexer#storeStatement(convertStatement(org.openrdf.model.Statement)}
      */
     @Test
     public void testStoreStatement() throws IOException {
-        final ValueFactory vf = new ValueFactoryImpl();
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
 
-        final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
-        final URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA);
-
-        // Should not be stored because they are not in the predicate list
-        final String validDateStringWithThirteens = "1313-12-13T13:13:13Z";
-        tIndexer.storeStatement(convertStatement(new 
StatementImpl(vf.createURI("foo:subj1"), RDFS.LABEL, 
vf.createLiteral(validDateStringWithThirteens))));
-
-        final String invalidDateString = "ThisIsAnInvalidDate";
-        tIndexer.storeStatement(convertStatement(new 
StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, 
vf.createLiteral(invalidDateString))));
-
-        // These are different datetimes instant but from different time zones.
-        // This is an arbitrary zone, BRST=Brazil, better if not local.
-        // same as "2015-01-01T01:59:59Z"
-        final String testDate2014InBRST = "2014-12-31T23:59:59-02:00";
-        // next year, same as "2017-01-01T01:59:59Z"
-        final String testDate2016InET = "2016-12-31T20:59:59-05:00";
-
-        // These should be stored because they are in the predicate list.
-        // BUT they will get converted to the same exact datetime in UTC.
-        final Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), 
pred1_atTime, vf.createLiteral(testDate2014InBRST));
-        final Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), 
pred2_circa, vf.createLiteral(testDate2016InET));
-        tIndexer.storeStatement(convertStatement(s3));
-        tIndexer.storeStatement(convertStatement(s4));
-
-        // This should not be stored because the object is not a literal
-        tIndexer.storeStatement(convertStatement(new 
StatementImpl(vf.createURI("foo:subj5"), pred1_atTime, 
vf.createURI("in:valid"))));
-
-        printTables("junit testing: Temporal entities stored in 
testStoreStatement");
-        assertEquals(2, tIndexer.getCollection().find().count());
+            final ValueFactory vf = new ValueFactoryImpl();
+
+            final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
+            final URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA);
+
+            // Should not be stored because they are not in the predicate list
+            final String validDateStringWithThirteens = "1313-12-13T13:13:13Z";
+            tIndexer.storeStatement(convertStatement(new 
StatementImpl(vf.createURI("foo:subj1"), RDFS.LABEL, 
vf.createLiteral(validDateStringWithThirteens))));
+
+            final String invalidDateString = "ThisIsAnInvalidDate";
+            tIndexer.storeStatement(convertStatement(new 
StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, 
vf.createLiteral(invalidDateString))));
+
+            // These are different datetimes instant but from different time 
zones.
+            // This is an arbitrary zone, BRST=Brazil, better if not local.
+            // same as "2015-01-01T01:59:59Z"
+            final String testDate2014InBRST = "2014-12-31T23:59:59-02:00";
+            // next year, same as "2017-01-01T01:59:59Z"
+            final String testDate2016InET = "2016-12-31T20:59:59-05:00";
+
+            // These should be stored because they are in the predicate list.
+            // BUT they will get converted to the same exact datetime in UTC.
+            final Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), 
pred1_atTime, vf.createLiteral(testDate2014InBRST));
+            final Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), 
pred2_circa, vf.createLiteral(testDate2016InET));
+            tIndexer.storeStatement(convertStatement(s3));
+            tIndexer.storeStatement(convertStatement(s4));
+
+            // This should not be stored because the object is not a literal
+            tIndexer.storeStatement(convertStatement(new 
StatementImpl(vf.createURI("foo:subj5"), pred1_atTime, 
vf.createURI("in:valid"))));
+
+            printTables(tIndexer, "junit testing: Temporal entities stored in 
testStoreStatement");
+            assertEquals(2, tIndexer.getCollection().find().count());
+        }
     }
 
     @Test
     public void testDelete() throws IOException, MongoException, 
TableNotFoundException, TableExistsException, NoSuchAlgorithmException {
-        final ValueFactory vf = new ValueFactoryImpl();
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
 
-        final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
-        final URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA);
+            final ValueFactory vf = new ValueFactoryImpl();
+
+            final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
+            final URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA);
 
-        final String testDate2014InBRST = "2014-12-31T23:59:59-02:00";
-        final String testDate2016InET = "2016-12-31T20:59:59-05:00";
+            final String testDate2014InBRST = "2014-12-31T23:59:59-02:00";
+            final String testDate2016InET = "2016-12-31T20:59:59-05:00";
 
-        // These should be stored because they are in the predicate list.
-        // BUT they will get converted to the same exact datetime in UTC.
-        final Statement s1 = new StatementImpl(vf.createURI("foo:subj3"), 
pred1_atTime, vf.createLiteral(testDate2014InBRST));
-        final Statement s2 = new StatementImpl(vf.createURI("foo:subj4"), 
pred2_circa, vf.createLiteral(testDate2016InET));
-        tIndexer.storeStatement(convertStatement(s1));
-        tIndexer.storeStatement(convertStatement(s2));
+            // These should be stored because they are in the predicate list.
+            // BUT they will get converted to the same exact datetime in UTC.
+            final Statement s1 = new StatementImpl(vf.createURI("foo:subj3"), 
pred1_atTime, vf.createLiteral(testDate2014InBRST));
+            final Statement s2 = new StatementImpl(vf.createURI("foo:subj4"), 
pred2_circa, vf.createLiteral(testDate2016InET));
+            tIndexer.storeStatement(convertStatement(s1));
+            tIndexer.storeStatement(convertStatement(s2));
 
+            final String dbName = conf.getMongoDBName();
+            final DB db = super.getMongoClient().getDB(dbName);
+            DBCollection collection = 
db.getCollection(conf.get(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, 
"rya") + tIndexer.getCollectionName());
 
-        printTables("junit testing: Temporal entities stored in testDelete 
before delete");
-        assertEquals("Number of rows stored.", 2, collection.count()); // 4 
index entries per statement
+            printTables(tIndexer, "junit testing: Temporal entities stored in 
testDelete before delete");
+            assertEquals("Number of rows stored.", 2, collection.count()); // 
4 index entries per statement
 
-        tIndexer.deleteStatement(convertStatement(s1));
-        tIndexer.deleteStatement(convertStatement(s2));
+            tIndexer.deleteStatement(convertStatement(s1));
+            tIndexer.deleteStatement(convertStatement(s2));
 
-        printTables("junit testing: Temporal entities stored in testDelete 
after delete");
-        assertEquals("Number of rows stored after delete.", 0, 
collection.count());
+            printTables(tIndexer, "junit testing: Temporal entities stored in 
testDelete after delete");
+            assertEquals("Number of rows stored after delete.", 0, 
collection.count());
+        }
     }
 
     /**
@@ -254,31 +279,36 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryInstantAfterInstant() throws IOException, 
QueryEvaluationException, TableNotFoundException, MongoException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        // these should not match as they are not instances.
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-
-        // seriesSpo[s] and seriesTs[s] are statements and instant for s 
seconds after the uniform time.
-        final int searchForSeconds = 4;
-        final int expectedResultCount = 9;
-        for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) { // 
<== logic here
-            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
-        }
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            // these should not match as they are not instances.
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+
+            // seriesSpo[s] and seriesTs[s] are statements and instant for s 
seconds after the uniform time.
+            final int searchForSeconds = 4;
+            final int expectedResultCount = 9;
+            for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) 
{ // <== logic here
+                tIndexer.storeStatement(convertStatement(seriesSpo[s]));
+            }
 
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryInstantAfterInstant(seriesTs[searchForSeconds], 
EMPTY_CONSTRAINTS);
-        int count = 0;
-        while (iter.hasNext()) {
-            final Statement s = iter.next();
-            final Statement nextExpectedStatement = seriesSpo[searchForSeconds 
+ count + 1]; // <== logic here
-            assertTrue("Should match: " + nextExpectedStatement + " == " + s, 
nextExpectedStatement.equals(s));
-            count++;
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = 
tIndexer.queryInstantAfterInstant(seriesTs[searchForSeconds], 
EMPTY_CONSTRAINTS);
+            int count = 0;
+            while (iter.hasNext()) {
+                final Statement s = iter.next();
+                final Statement nextExpectedStatement = 
seriesSpo[searchForSeconds + count + 1]; // <== logic here
+                assertTrue("Should match: " + nextExpectedStatement + " == " + 
s, nextExpectedStatement.equals(s));
+                count++;
+            }
+            assertEquals("Should find count of rows.", expectedResultCount, 
count);
         }
-        assertEquals("Should find count of rows.", expectedResultCount, count);
     }
     /**
      * Test instant before a given instant.
@@ -286,32 +316,37 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryInstantBeforeInstant() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        // these should not match as they are not instances.
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-
-        // seriesSpo[s] and seriesTs[s] are statements and instant for s 
seconds after the uniform time.
-        final int searchForSeconds = 4;
-        final int expectedResultCount = 4;
-        for (int s = 0; s <= searchForSeconds + 15; s++) { // <== logic here
-            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
-        }
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            // these should not match as they are not instances.
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+
+            // seriesSpo[s] and seriesTs[s] are statements and instant for s 
seconds after the uniform time.
+            final int searchForSeconds = 4;
+            final int expectedResultCount = 4;
+            for (int s = 0; s <= searchForSeconds + 15; s++) { // <== logic 
here
+                tIndexer.storeStatement(convertStatement(seriesSpo[s]));
+            }
 
-        CloseableIteration<Statement, QueryEvaluationException> iter;
+            CloseableIteration<Statement, QueryEvaluationException> iter;
 
-        iter = tIndexer.queryInstantBeforeInstant(seriesTs[searchForSeconds], 
EMPTY_CONSTRAINTS);
-        int count = 0;
-        while (iter.hasNext()) {
-            final Statement s = iter.next();
-            final Statement nextExpectedStatement = seriesSpo[count]; // <== 
logic here
-            assertTrue("Should match: " + nextExpectedStatement + " == " + s, 
nextExpectedStatement.equals(s));
-            count++;
+            iter = 
tIndexer.queryInstantBeforeInstant(seriesTs[searchForSeconds], 
EMPTY_CONSTRAINTS);
+            int count = 0;
+            while (iter.hasNext()) {
+                final Statement s = iter.next();
+                final Statement nextExpectedStatement = seriesSpo[count]; // 
<== logic here
+                assertTrue("Should match: " + nextExpectedStatement + " == " + 
s, nextExpectedStatement.equals(s));
+                count++;
+            }
+            assertEquals("Should find count of rows.", expectedResultCount, 
count);
         }
-        assertEquals("Should find count of rows.", expectedResultCount, count);
     }
 
     /**
@@ -320,31 +355,36 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryInstantBeforeInterval() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        // these should not match as they are not instances.
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-
-        // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
-        final TemporalInterval searchForSeconds = tvB02_E31;
-        final int expectedResultCount = 2; // 00 and 01 seconds.
-        for (int s = 0; s <= 40; s++) { // <== logic here
-            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
-        }
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            // these should not match as they are not instances.
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+
+            // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
+            final TemporalInterval searchForSeconds = tvB02_E31;
+            final int expectedResultCount = 2; // 00 and 01 seconds.
+            for (int s = 0; s <= 40; s++) { // <== logic here
+                tIndexer.storeStatement(convertStatement(seriesSpo[s]));
+            }
 
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryInstantBeforeInterval(searchForSeconds, 
EMPTY_CONSTRAINTS);
-        int count = 0;
-        while (iter.hasNext()) {
-            final Statement s = iter.next();
-            final Statement nextExpectedStatement = seriesSpo[count]; // <== 
logic here
-            assertTrue("Should match: " + nextExpectedStatement + " == " + s, 
nextExpectedStatement.equals(s));
-            count++;
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = tIndexer.queryInstantBeforeInterval(searchForSeconds, 
EMPTY_CONSTRAINTS);
+            int count = 0;
+            while (iter.hasNext()) {
+                final Statement s = iter.next();
+                final Statement nextExpectedStatement = seriesSpo[count]; // 
<== logic here
+                assertTrue("Should match: " + nextExpectedStatement + " == " + 
s, nextExpectedStatement.equals(s));
+                count++;
+            }
+            assertEquals("Should find count of rows.", expectedResultCount, 
count);
         }
-        assertEquals("Should find count of rows.", expectedResultCount, count);
     }
 
     /**
@@ -353,32 +393,37 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryInstantAfterInterval() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        // these should not match as they are not instances.
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-
-        // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
-        final TemporalInterval searchAfterInterval = tvB02_E31; // from 2 to 
31 seconds
-        final int endingSeconds = 31;
-        final int expectedResultCount = 9; // 32,33,...,40 seconds.
-        for (int s = 0; s <= endingSeconds + expectedResultCount; s++) { // 
<== logic here
-            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
-        }
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            // these should not match as they are not instances.
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+
+            // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
+            final TemporalInterval searchAfterInterval = tvB02_E31; // from 2 
to 31 seconds
+            final int endingSeconds = 31;
+            final int expectedResultCount = 9; // 32,33,...,40 seconds.
+            for (int s = 0; s <= endingSeconds + expectedResultCount; s++) { 
// <== logic here
+                tIndexer.storeStatement(convertStatement(seriesSpo[s]));
+            }
 
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryInstantAfterInterval(searchAfterInterval, 
EMPTY_CONSTRAINTS);
-        int count = 0;
-        while (iter.hasNext()) {
-            final Statement s = iter.next();
-            final Statement nextExpectedStatement = seriesSpo[count + 
endingSeconds + 1]; // <== logic here
-            assertTrue("Should match: " + nextExpectedStatement + " == " + s, 
nextExpectedStatement.equals(s));
-            count++;
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = tIndexer.queryInstantAfterInterval(searchAfterInterval, 
EMPTY_CONSTRAINTS);
+            int count = 0;
+            while (iter.hasNext()) {
+                final Statement s = iter.next();
+                final Statement nextExpectedStatement = seriesSpo[count + 
endingSeconds + 1]; // <== logic here
+                assertTrue("Should match: " + nextExpectedStatement + " == " + 
s, nextExpectedStatement.equals(s));
+                count++;
+            }
+            assertEquals("Should find count of rows.", expectedResultCount, 
count);
         }
-        assertEquals("Should find count of rows.", expectedResultCount, count);
     }
 
     /**
@@ -387,99 +432,116 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryInstantInsideInterval() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        // these should not match as they are not instances.
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-
-        // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
-        final TemporalInterval searchInsideInterval = tvB02_E31; // from 2 to 
31 seconds
-        final int beginningSeconds = 2; // <== logic here, and next few lines.
-        final int endingSeconds = 31;
-        final int expectedResultCount = endingSeconds - beginningSeconds - 1; 
// 3,4,...,30 seconds.
-        for (int s = 0; s <= 40; s++) {
-            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
-        }
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            // these should not match as they are not instances.
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+
+            // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
+            final TemporalInterval searchInsideInterval = tvB02_E31; // from 2 
to 31 seconds
+            final int beginningSeconds = 2; // <== logic here, and next few 
lines.
+            final int endingSeconds = 31;
+            final int expectedResultCount = endingSeconds - beginningSeconds - 
1; // 3,4,...,30 seconds.
+            for (int s = 0; s <= 40; s++) {
+                tIndexer.storeStatement(convertStatement(seriesSpo[s]));
+            }
 
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryInstantInsideInterval(searchInsideInterval, 
EMPTY_CONSTRAINTS);
-        int count = 0;
-        while (iter.hasNext()) {
-            final Statement s = iter.next();
-            final Statement nextExpectedStatement = seriesSpo[count + 
beginningSeconds + 1]; // <== logic here
-            assertTrue("Should match: " + nextExpectedStatement + " == " + s, 
nextExpectedStatement.equals(s));
-            count++;
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = tIndexer.queryInstantInsideInterval(searchInsideInterval, 
EMPTY_CONSTRAINTS);
+            int count = 0;
+            while (iter.hasNext()) {
+                final Statement s = iter.next();
+                final Statement nextExpectedStatement = seriesSpo[count + 
beginningSeconds + 1]; // <== logic here
+                assertTrue("Should match: " + nextExpectedStatement + " == " + 
s, nextExpectedStatement.equals(s));
+                count++;
+            }
+            assertEquals("Should find count of rows.", expectedResultCount, 
count);
         }
-        assertEquals("Should find count of rows.", expectedResultCount, count);
     }
+
     /**
      * Test instant is the Beginning of the given interval.
      * from the series: Instance {hasBeginning, hasEnd} Interval
      */
     @Test
     public void testQueryInstantHasBeginningInterval() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        // these should not match as they are not instances.
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-
-        // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
-        final TemporalInterval searchInsideInterval = tvB02_E31; // from 2 to 
31 seconds
-        final int searchSeconds = 2; // <== logic here, and next few lines.
-        final int expectedResultCount = 1; // 2 seconds.
-        for (int s = 0; s <= 10; s++) {
-            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
-        }
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            // these should not match as they are not instances.
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+
+            // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
+            final TemporalInterval searchInsideInterval = tvB02_E31; // from 2 
to 31 seconds
+            final int searchSeconds = 2; // <== logic here, and next few lines.
+            final int expectedResultCount = 1; // 2 seconds.
+            for (int s = 0; s <= 10; s++) {
+                tIndexer.storeStatement(convertStatement(seriesSpo[s]));
+            }
 
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryInstantHasBeginningInterval(searchInsideInterval, 
EMPTY_CONSTRAINTS);
-        int count = 0;
-        while (iter.hasNext()) {
-            final Statement s = iter.next();
-            final Statement nextExpectedStatement = seriesSpo[searchSeconds]; 
// <== logic here
-            assertTrue("Should match: " + nextExpectedStatement + " == " + s, 
nextExpectedStatement.equals(s));
-            count++;
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = 
tIndexer.queryInstantHasBeginningInterval(searchInsideInterval, 
EMPTY_CONSTRAINTS);
+            int count = 0;
+            while (iter.hasNext()) {
+                final Statement s = iter.next();
+                final Statement nextExpectedStatement = 
seriesSpo[searchSeconds]; // <== logic here
+                assertTrue("Should match: " + nextExpectedStatement + " == " + 
s, nextExpectedStatement.equals(s));
+                count++;
+            }
+            assertEquals("Should find count of rows.", expectedResultCount, 
count);
         }
-        assertEquals("Should find count of rows.", expectedResultCount, count);
     }
+
     /**
      * Test instant is the end of the given interval.
      * from the series: Instance {hasBeginning, hasEnd} Interval
      */
     @Test
     public void testQueryInstantHasEndInterval()  throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        // these should not match as they are not instances.
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-
-        // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
-        final TemporalInterval searchInsideInterval = tvB02_E31; // from 2 to 
31 seconds
-        final int searchSeconds = 31; // <== logic here, and next few lines.
-        final int expectedResultCount = 1; // 31 seconds.
-        for (int s = 0; s <= 40; s++) {
-            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
-        }
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            // these should not match as they are not instances.
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+
+            // seriesSpo[s] and seriesTs[s] are statements and instants for s 
seconds after the uniform time.
+            final TemporalInterval searchInsideInterval = tvB02_E31; // from 2 
to 31 seconds
+            final int searchSeconds = 31; // <== logic here, and next few 
lines.
+            final int expectedResultCount = 1; // 31 seconds.
+            for (int s = 0; s <= 40; s++) {
+                tIndexer.storeStatement(convertStatement(seriesSpo[s]));
+            }
 
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryInstantHasEndInterval(searchInsideInterval, 
EMPTY_CONSTRAINTS);
-        int count = 0;
-        while (iter.hasNext()) {
-            final Statement s = iter.next();
-            final Statement nextExpectedStatement = seriesSpo[searchSeconds]; 
// <== logic here
-            assertTrue("Should match: " + nextExpectedStatement + " == " + s, 
nextExpectedStatement.equals(s));
-            count++;
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = tIndexer.queryInstantHasEndInterval(searchInsideInterval, 
EMPTY_CONSTRAINTS);
+            int count = 0;
+            while (iter.hasNext()) {
+                final Statement s = iter.next();
+                final Statement nextExpectedStatement = 
seriesSpo[searchSeconds]; // <== logic here
+                assertTrue("Should match: " + nextExpectedStatement + " == " + 
s, nextExpectedStatement.equals(s));
+                count++;
+            }
+            assertEquals("Should find count of rows.", expectedResultCount, 
count);
         }
-        assertEquals("Should find count of rows.", expectedResultCount, count);
     }
 
     /**
@@ -492,21 +554,26 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryIntervalEquals() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-        tIndexer.storeStatement(convertStatement(seriesSpo[4])); // instance 
at 4 seconds
-
-
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryIntervalEquals(tvB02_E40, EMPTY_CONSTRAINTS);
-        // Should be found twice:
-        assertTrue("queryIntervalEquals: spo_B02_E40 should be found, but 
actually returned empty results. spo_B02_E40=" + spo_B02_E40, iter.hasNext());
-        assertTrue("queryIntervalEquals: spo_B02_E40 should be found, but does 
not match.", spo_B02_E40.equals(iter.next()));
-        assertFalse("queryIntervalEquals: Find no more than one, but actually 
has more.", iter.hasNext());
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+            tIndexer.storeStatement(convertStatement(seriesSpo[4])); // 
instance at 4 seconds
+
+
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = tIndexer.queryIntervalEquals(tvB02_E40, EMPTY_CONSTRAINTS);
+            // Should be found twice:
+            assertTrue("queryIntervalEquals: spo_B02_E40 should be found, but 
actually returned empty results. spo_B02_E40=" + spo_B02_E40, iter.hasNext());
+            assertTrue("queryIntervalEquals: spo_B02_E40 should be found, but 
does not match.", spo_B02_E40.equals(iter.next()));
+            assertFalse("queryIntervalEquals: Find no more than one, but 
actually has more.", iter.hasNext());
+        }
     }
 
     /**
@@ -518,25 +585,30 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryIntervalBefore() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        tIndexer.storeStatement(convertStatement(spo_B00_E01));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        // instants should be ignored.
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-        tIndexer.storeStatement(convertStatement(seriesSpo[1])); // instance 
at 1 seconds
-        tIndexer.storeStatement(convertStatement(seriesSpo[2]));
-        tIndexer.storeStatement(convertStatement(seriesSpo[31]));
-
-
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryIntervalBefore(tvB02_E31, EMPTY_CONSTRAINTS);
-        // Should be found twice:
-        assertTrue("spo_B00_E01 should be found, but actually returned empty 
results. spo_B00_E01=" + spo_B00_E01, iter.hasNext());
-        assertTrue("spo_B00_E01 should be found, but found another.", 
spo_B00_E01.equals(iter.next()));
-        assertFalse("Find no more than one, but actually has more.", 
iter.hasNext());
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            tIndexer.storeStatement(convertStatement(spo_B00_E01));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            // instants should be ignored.
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+            tIndexer.storeStatement(convertStatement(seriesSpo[1])); // 
instance at 1 seconds
+            tIndexer.storeStatement(convertStatement(seriesSpo[2]));
+            tIndexer.storeStatement(convertStatement(seriesSpo[31]));
+
+
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = tIndexer.queryIntervalBefore(tvB02_E31, EMPTY_CONSTRAINTS);
+            // Should be found twice:
+            assertTrue("spo_B00_E01 should be found, but actually returned 
empty results. spo_B00_E01=" + spo_B00_E01, iter.hasNext());
+            assertTrue("spo_B00_E01 should be found, but found another.", 
spo_B00_E01.equals(iter.next()));
+            assertFalse("Find no more than one, but actually has more.", 
iter.hasNext());
+        }
     }
 
     /**
@@ -548,29 +620,33 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryIntervalAfter() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        tIndexer.storeStatement(convertStatement(spo_B00_E01));
-        tIndexer.storeStatement(convertStatement(spo_B02_E29)); //<- after 
this one.
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B29_E30));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-        // instants should be ignored.
-        tIndexer.storeStatement(convertStatement(spo_B02));
-        tIndexer.storeStatement(convertStatement(seriesSpo[1])); // instance 
at 1 seconds
-        tIndexer.storeStatement(convertStatement(seriesSpo[2]));
-        tIndexer.storeStatement(convertStatement(seriesSpo[31]));
-
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        iter = tIndexer.queryIntervalAfter(tvB02_E29, EMPTY_CONSTRAINTS);
-        // Should be found twice:
-        assertTrue("spo_B30_E32 should be found, but actually returned empty 
results. spo_B30_E32=" + spo_B30_E32, iter.hasNext());
-        final Statement s = iter.next();
-        assertTrue("spo_B30_E32 should be found, but found another. 
spo_B30_E32="+spo_B30_E32+", but found="+s, spo_B30_E32.equals(s));
-        assertFalse("Find no more than one, but actually has more.", 
iter.hasNext());
-
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            tIndexer.storeStatement(convertStatement(spo_B00_E01));
+            tIndexer.storeStatement(convertStatement(spo_B02_E29)); //<- after 
this one.
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B29_E30));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+            // instants should be ignored.
+            tIndexer.storeStatement(convertStatement(spo_B02));
+            tIndexer.storeStatement(convertStatement(seriesSpo[1])); // 
instance at 1 seconds
+            tIndexer.storeStatement(convertStatement(seriesSpo[2]));
+            tIndexer.storeStatement(convertStatement(seriesSpo[31]));
+
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            iter = tIndexer.queryIntervalAfter(tvB02_E29, EMPTY_CONSTRAINTS);
+            // Should be found twice:
+            assertTrue("spo_B30_E32 should be found, but actually returned 
empty results. spo_B30_E32=" + spo_B30_E32, iter.hasNext());
+            final Statement s = iter.next();
+            assertTrue("spo_B30_E32 should be found, but found another. 
spo_B30_E32="+spo_B30_E32+", but found="+s, spo_B30_E32.equals(s));
+            assertFalse("Find no more than one, but actually has more.", 
iter.hasNext());
+        }
     }
 
     /**
@@ -578,65 +654,70 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      */
     @Test
     public void testQueryWithMultiplePredicates() throws IOException, 
QueryEvaluationException {
-        // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
-        // these should not match as they are not instances.
-        tIndexer.storeStatement(convertStatement(spo_B03_E20));
-        tIndexer.storeStatement(convertStatement(spo_B02_E30));
-        tIndexer.storeStatement(convertStatement(spo_B02_E40));
-        tIndexer.storeStatement(convertStatement(spo_B02_E31));
-        tIndexer.storeStatement(convertStatement(spo_B30_E32));
-
-        // seriesSpo[s] and seriesTs[s] are statements and instant for s 
seconds after the uniform time.
-        final int searchForSeconds = 4;
-        final int expectedResultCount = 9;
-        for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) { // 
<== logic here
-            tIndexer.storeStatement(convertStatement(seriesSpo[s]));
-        }
-        final ValueFactory vf = new ValueFactoryImpl();
-        final URI pred3_CIRCA_ = vf.createURI(URI_PROPERTY_CIRCA);  // this 
one to ignore.
-        final URI pred2_eventTime = vf.createURI(URI_PROPERTY_EVENT_TIME);
-        final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
-
-        // add the predicate = EventTime ; Store in an array for verification.
-        final Statement[] SeriesTs_EventTime = new 
Statement[expectedResultCount+1];
-        for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) { // 
<== logic here
-            final Statement statement = new 
StatementImpl(vf.createURI("foo:EventTimeSubj0" + s), pred2_eventTime, 
vf.createLiteral(seriesTs[s].getAsReadable()));
-            tIndexer.storeStatement(convertStatement(statement));
-            if (s>searchForSeconds) {
-                SeriesTs_EventTime[s - searchForSeconds -1 ] = statement;
+        try(MongoTemporalIndexer tIndexer = new MongoTemporalIndexer()) {
+            tIndexer.setConf(conf);
+            tIndexer.init();
+
+            // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
+            // these should not match as they are not instances.
+            tIndexer.storeStatement(convertStatement(spo_B03_E20));
+            tIndexer.storeStatement(convertStatement(spo_B02_E30));
+            tIndexer.storeStatement(convertStatement(spo_B02_E40));
+            tIndexer.storeStatement(convertStatement(spo_B02_E31));
+            tIndexer.storeStatement(convertStatement(spo_B30_E32));
+
+            // seriesSpo[s] and seriesTs[s] are statements and instant for s 
seconds after the uniform time.
+            final int searchForSeconds = 4;
+            final int expectedResultCount = 9;
+            for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) 
{ // <== logic here
+                tIndexer.storeStatement(convertStatement(seriesSpo[s]));
+            }
+            final ValueFactory vf = new ValueFactoryImpl();
+            final URI pred3_CIRCA_ = vf.createURI(URI_PROPERTY_CIRCA);  // 
this one to ignore.
+            final URI pred2_eventTime = vf.createURI(URI_PROPERTY_EVENT_TIME);
+            final URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
+
+            // add the predicate = EventTime ; Store in an array for 
verification.
+            final Statement[] SeriesTs_EventTime = new 
Statement[expectedResultCount+1];
+            for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) 
{ // <== logic here
+                final Statement statement = new 
StatementImpl(vf.createURI("foo:EventTimeSubj0" + s), pred2_eventTime, 
vf.createLiteral(seriesTs[s].getAsReadable()));
+                tIndexer.storeStatement(convertStatement(statement));
+                if (s>searchForSeconds) {
+                    SeriesTs_EventTime[s - searchForSeconds -1 ] = statement;
+                }
+            }
+            // add the predicate = CIRCA ; to be ignored because it is not in 
the constraints.
+            for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) 
{ // <== logic here
+                final Statement statement = new 
StatementImpl(vf.createURI("foo:CircaEventSubj0" + s), pred3_CIRCA_, 
vf.createLiteral(seriesTs[s].getAsReadable()));
+                tIndexer.storeStatement(convertStatement(statement));
             }
-        }
-        // add the predicate = CIRCA ; to be ignored because it is not in the 
constraints.
-        for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) { // 
<== logic here
-            final Statement statement = new 
StatementImpl(vf.createURI("foo:CircaEventSubj0" + s), pred3_CIRCA_, 
vf.createLiteral(seriesTs[s].getAsReadable()));
-            tIndexer.storeStatement(convertStatement(statement));
-        }
 
-        CloseableIteration<Statement, QueryEvaluationException> iter;
-        final StatementConstraints constraints = new StatementConstraints();
-        constraints.setPredicates(new HashSet<URI>(Arrays.asList( 
pred2_eventTime,  pred1_atTime )));
+            CloseableIteration<Statement, QueryEvaluationException> iter;
+            final StatementConstraints constraints = new 
StatementConstraints();
+            constraints.setPredicates(new HashSet<>(Arrays.asList( 
pred2_eventTime,  pred1_atTime )));
+
+            iter = 
tIndexer.queryInstantAfterInstant(seriesTs[searchForSeconds], constraints); // 
EMPTY_CONSTRAINTS);//
+            int count_AtTime = 0;
+            int count_EventTime = 0;
+            while (iter.hasNext()) {
+                final Statement s = iter.next();
+                final Statement nextExpectedStatement = 
seriesSpo[searchForSeconds + count_AtTime + 1]; // <== logic here
+                if (s.getPredicate().equals(pred1_atTime)) {
+                    assertTrue("Should match atTime: " + nextExpectedStatement 
+ " == " + s, nextExpectedStatement.equals(s));
+                    count_AtTime++;
+                }
+                else if (s.getPredicate().equals(pred2_eventTime)) {
+                    assertTrue("Should match eventTime: " + 
SeriesTs_EventTime[count_EventTime] + " == " + s, 
SeriesTs_EventTime[count_EventTime].equals(s));
+                    count_EventTime++;
+                } else {
+                    assertTrue("This predicate should not be returned: "+s, 
false);
+                }
 
-        iter = tIndexer.queryInstantAfterInstant(seriesTs[searchForSeconds], 
constraints); // EMPTY_CONSTRAINTS);//
-        int count_AtTime = 0;
-        int count_EventTime = 0;
-        while (iter.hasNext()) {
-            final Statement s = iter.next();
-            final Statement nextExpectedStatement = seriesSpo[searchForSeconds 
+ count_AtTime + 1]; // <== logic here
-            if (s.getPredicate().equals(pred1_atTime)) {
-                assertTrue("Should match atTime: " + nextExpectedStatement + " 
== " + s, nextExpectedStatement.equals(s));
-                count_AtTime++;
-            }
-            else if (s.getPredicate().equals(pred2_eventTime)) {
-                assertTrue("Should match eventTime: " + 
SeriesTs_EventTime[count_EventTime] + " == " + s, 
SeriesTs_EventTime[count_EventTime].equals(s));
-                count_EventTime++;
-            } else {
-                assertTrue("This predicate should not be returned: "+s, false);
             }
 
+            assertEquals("Should find count of atTime    rows.", 
expectedResultCount, count_AtTime);
+            assertEquals("Should find count of eventTime rows.", 
expectedResultCount, count_EventTime);
         }
-
-        assertEquals("Should find count of atTime    rows.", 
expectedResultCount, count_AtTime);
-        assertEquals("Should find count of eventTime rows.", 
expectedResultCount, count_EventTime);
     }
 
     /**
@@ -651,7 +732,7 @@ public final class MongoTemporalIndexerTest extends 
MongoTestBase {
      * @return Count of entries in the index table.
      * @throws IOException
      */
-    public void printTables(final String description) throws IOException {
+    public void printTables(MongoTemporalIndexer tIndexer, final String 
description) throws IOException {
         System.out.println("-- start printTables() -- " + description);
         System.out.println("Reading : " + 
tIndexer.getCollection().getFullName());
         final DBCursor cursor = tIndexer.getCollection().find();

Reply via email to