Skip to content

Instantly share code, notes, and snippets.

@sw1nn
Created September 29, 2011 15:05
Show Gist options
  • Save sw1nn/1250920 to your computer and use it in GitHub Desktop.
Save sw1nn/1250920 to your computer and use it in GitHub Desktop.
Starting a mongod as part of a junit test
public class SimpleMongoConnectionTest {
...
private static Process mongod;
// TODO - this a clumsy way to start/stop a mongod. works for now.
@BeforeClass
public static void startMongoDB() throws IOException, InterruptedException
{
mongod = Runtime.getRuntime().exec(
MONGO_HOME + "\\bin\\mongod.exe --dbpath " +
MONGO_HOME + "\\data");
Thread.sleep(5000L);
// mongo is a 'one per app' connection pool
mongo = new Mongo("localhost");
}
@AfterClass
public static void stopMongoDB() throws IOException, InterruptedException {
mongod.destroy();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment