Github user kchilton2 commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/256#discussion_r159510572 --- Diff: dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/EmbeddedMongoSingleton.java --- @@ -19,20 +19,43 @@ package org.apache.rya.mongodb; import java.io.IOException; +import java.net.UnknownHostException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.mongodb.MongoClient; +import com.mongodb.MongoException; + +import de.flapdoodle.embed.mongo.config.IMongodConfig; /** * To be used for tests. Creates a singleton {@link MongoClient} to be used * throughout all of the MongoDB related tests. Without the singleton, the * embedded mongo factory ends up orphaning processes, consuming resources. */ public class EmbeddedMongoSingleton { - public static MongoClient getInstance() { - return InstanceHolder.SINGLETON.instance; + + public static MongoClient getNewMongoClient() throws UnknownHostException, MongoException { + final MongoClient client = InstanceHolder.SINGLETON.factory.newMongoClient(); + + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + try { + client.close(); + } catch (final Throwable t) { + // logging frameworks will likely be shut down + t.printStackTrace(System.err); + } + } + }); + + return client; + } + + public static IMongodConfig getMongodConfig() { --- End diff -- Done.
---