Created
September 29, 2011 15:05
-
-
Save sw1nn/1250920 to your computer and use it in GitHub Desktop.
Starting a mongod as part of a junit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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