本文整理匯總了Java中de.flapdoodle.embed.mongo.MongodStarter類的典型用法代碼示例。如果您正苦於以下問題:Java MongodStarter類的具體用法?Java MongodStarter怎麽用?Java MongodStarter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MongodStarter類屬於de.flapdoodle.embed.mongo包,在下文中一共展示了MongodStarter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setup
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
private static void setup() throws UnknownHostException, IOException {
IMongoCmdOptions cmdOptions = new MongoCmdOptionsBuilder().verbose(false)
.enableAuth(authEnabled).build();
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(LOCALHOST, MONGOS_PORT, Network.localhostIsIPv6()))
.cmdOptions(cmdOptions).build();
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(
Command.MongoD).build();
mongodExecutable = MongodStarter.getInstance(runtimeConfig).prepare(
mongodConfig);
mongod = mongodExecutable.start();
mongoClient = new MongoClient(new ServerAddress(LOCALHOST, MONGOS_PORT));
createDbAndCollections(EMPLOYEE_DB, EMPINFO_COLLECTION, "employee_id");
createDbAndCollections(EMPLOYEE_DB, SCHEMA_CHANGE_COLLECTION, "field_2");
}
示例2: beforeClass
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
@BeforeClass
public static void beforeClass() throws Exception {
MongodStarter runtime = MongodStarter.getDefaultInstance();
mongodExe = runtime.prepare(
new MongodConfigBuilder().version(Version.V3_3_1)
.net(new Net(12345, Network.localhostIsIPv6()))
.build());
MongodProcess process = mongodExe.start();
await().until(() -> process != null);
}
示例3: startMangoDb
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
private void startMangoDb() throws InterruptedException {
startInNewThread(() -> {
try {
MongodStarter starter = MongodStarter.getDefaultInstance();
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(12345, Network.localhostIsIPv6()))
.pidFile(new File("target/process.pid").getAbsolutePath())
.replication(new Storage(new File("target/tmp/mongodb/").getAbsolutePath(), null, 0))
.build();
logger.debug("Would download MongoDB if not yet downloaded.");
MongodExecutable mongodExecutable = starter.prepare(mongodConfig);
logger.debug("Done with downloading MongoDB exec.");
mongodExecutable.start();
MongoClientURI uri = new MongoClientURI("mongodb://localhost:12345/eventStreamAnalytics");
MongoClient client = new MongoClient(uri);
MongoDatabase mongoDatabase = client.getDatabase(uri.getDatabase());
mongoDatabase.createCollection("events");
} catch (Exception ex) {
logger.error("Failed to start MongoDB", ex);
throw new RuntimeException(ex);
}
}, "MangoDB").join();
logger.debug("Successfully Started MongoDB.");
}
示例4: setup
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
private static void setup() throws UnknownHostException, IOException {
IMongoCmdOptions cmdOptions = new MongoCmdOptionsBuilder().verbose(false)
.enableAuth(authEnabled).build();
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(LOCALHOST, MONGOS_PORT, Network.localhostIsIPv6()))
.cmdOptions(cmdOptions).build();
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(
Command.MongoD).build();
mongodExecutable = MongodStarter.getInstance(runtimeConfig).prepare(
mongodConfig);
mongod = mongodExecutable.start();
mongoClient = new MongoClient(new ServerAddress(LOCALHOST, MONGOS_PORT));
createDbAndCollections(EMPLOYEE_DB, EMPINFO_COLLECTION, "employee_id");
createDbAndCollections(EMPLOYEE_DB, SCHEMA_CHANGE_COLLECTION, "field_2");
createDbAndCollections(EMPLOYEE_DB, EMPTY_COLLECTION, "field_2");
createDbAndCollections(DATATYPE_DB, DATATYPE_COLLECTION, "_id");
}
示例5: SimpleMongoAsyncTest
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
public SimpleMongoAsyncTest() throws IOException {
// Start embeded mongo
config = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(27018, Network.localhostIsIPv6()))
.build();
exe = MongodStarter.getDefaultInstance().prepare(config);
mongoProcess = exe.start();
AtomicBoolean started = new AtomicBoolean(false);
// Start mongo client
client = MongoClients.create("mongodb://localhost:27018");
database = client.getDatabase("test");
collection = database.getCollection(COLLECTION_NAME);
morphia = new Morphia().mapPackage("com.querydsl.mongodb.domain");
}
示例6: start
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
@Override
public void start(Future<Void> future) {
MongodStarter starter = MongodStarter.getDefaultInstance();
try {
int port = MainVerticle.MONGO_PORT;
MongodConfigBuilder builder = new MongodConfigBuilder();
builder.version(Version.Main.PRODUCTION);
builder.net(new Net(port, Network.localhostIsIPv6()));
mongod = starter.prepare(builder.build());
mongod.start();
} catch (IOException ioe) {
future.fail(ioe);
return;
}
future.complete();
}
示例7: before
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
@Override
public void before() throws Exception {
if(defaultPort < 0) {
currentPort = Helper.findRandomOpenPortOnAllLocalInterfaces();
} else {
currentPort = defaultPort;
}
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(version)
.net(new Net("localhost", currentPort, Network.localhostIsIPv6()))
.build();
MongodStarter runtime = MongodStarter.getDefaultInstance();
mongodExe = runtime.prepare(mongodConfig);
mongod = mongodExe.start();
}
示例8: setupClass
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
@BeforeClass
public static void setupClass() throws Exception {
MongodStarter runtime = MongodStarter.getDefaultInstance();
mongodExe = runtime.prepare(new MongodConfig(de.flapdoodle.embed.mongo.distribution.Version.V2_4_3, MONGO_PORT, false));
try {
mongod = mongodExe.start();
} catch (IOException e) {
// someone probably killed the process in a breakpoint in an ide.. try again
mongod = mongodExe.start();
}
mongo = new Mongo(IN_MEM_CONNECTION_URL);
Configuration config = new Configuration();
config.setName(DB_NAME);
config.setHost(MONGO_HOST);
config.setPort(String.valueOf(MONGO_PORT));
crud = new MongoCRUD(config);
}
示例9: before
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
@Override
protected void before() throws IOException {
MongodStarter runtime = MongodStarter.getDefaultInstance();
IMongodConfig config = new MongodConfigBuilder().
version(getMongoVersion()).
net(new Net(getPort(), Network.localhostIsIPv6())).
build();
mongodExe = runtime.prepare(config);
try {
mongod = mongodExe.start();
} catch (IOException e) {
//Mongo failed to start for the previously stated reason. A single retry will be attempted.
mongod = mongodExe.start();
}
}
示例10: before
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
@Before
public void before() throws Exception {
MongodStarter starter = MongodStarter.getDefaultInstance();
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(27017, Network.localhostIsIPv6()))
.build();
MongodExecutable mongodExecutable = null;
mongodExecutable = starter.prepare(mongodConfig);
mongod = mongodExecutable.start();
ApplicationContext context = new ClassPathXmlApplicationContext("spring/mongodb-data-store-adapter-test-context.xml");
BeanFactory factory = context;
adapter = (DataStoreAdapter) factory.getBean("adapter");
}
示例11: setup
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
@Before
public void setup() throws Exception {
IStreamProcessor stream = new NullProcessor();
MongodStarter runtime = MongodStarter.getInstance(new RuntimeConfigBuilder()
.defaults(Command.MongoD)
.processOutput(new ProcessOutput(stream, stream, stream))
.artifactStore(new ArtifactStoreBuilder()
.defaults(Command.MongoD)
.build())
.build());
this.mongodExecutable = runtime.prepare(new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(PROCESS_PORT, Network.localhostIsIPv6()))
.build());
this.mongodProcess = mongodExecutable.start();
this.mongoClient = new MongoClient(PROCESS_ADDRESS, PROCESS_PORT);
Injector injector = Guice.createInjector(new SearchModule(), new HttpModule());
this.groundHogDB = new GroundhogDB(this.mongoClient, "myGitHubResearch");
this.searchGitHub = injector.getInstance(SearchGitHub.class);
}
示例12: MongoDatabaseForTestsFactory
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
/**
* Constructor
*
* @throws Exception
*/
public MongoDatabaseForTestsFactory() throws Exception
{
MongodStarter starter = MongodStarter.getDefaultInstance();
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(version)
.processListener(new MongoDatabaseProcessListener())
.build();
this.mongodExecutable = starter.prepare(mongodConfig);
this.mongodProcess = mongodExecutable.start();
// We use a randomly-assigned port, so get it
InetAddress address = mongodProcess.getConfig().net()
.getServerAddress();
int port = mongodProcess.getConfig().net().getPort();
this.mongoClient = new MongoClient(new ServerAddress(address, port));
this.database = this.mongoClient.getDatabase(UUID.randomUUID()
.toString());
}
示例13: MongoDBForTestsFactory
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
/**
* Constructor
*
* @throws Exception
*/
@SuppressWarnings("deprecation")
public MongoDBForTestsFactory() throws Exception
{
MongodStarter starter = MongodStarter.getDefaultInstance();
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(version)
.processListener(new MongoDBProcessListener())
.build();
mongodExecutable = starter.prepare(mongodConfig);
mongodProcess = mongodExecutable.start();
// We use a randomly-assigned port, so get it
InetAddress address = mongodProcess.getConfig().net().getServerAddress();
int port = mongodProcess.getConfig().net().getPort();
mongo = new MongoClient(new ServerAddress(address, port));
db = mongo.getDB(UUID.randomUUID().toString());
}
示例14: getMongodStarter
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
private static MongodStarter getMongodStarter(final LoggingTarget loggingTarget) {
if (loggingTarget == null) {
return MongodStarter.getDefaultInstance();
}
switch (loggingTarget) {
case NULL:
final Logger logger = LoggerFactory.getLogger(MongoDbTestRule.class.getName());
final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
// @formatter:off
.defaultsWithLogger(Command.MongoD, logger)
.processOutput(ProcessOutput.getDefaultInstanceSilent())
.build();
// @formatter:on
return MongodStarter.getInstance(runtimeConfig);
case CONSOLE:
return MongodStarter.getDefaultInstance();
default:
throw new NotImplementedException(loggingTarget.toString());
}
}
示例15: before
import de.flapdoodle.embed.mongo.MongodStarter; //導入依賴的package包/類
@Override
protected void before() throws Throwable {
MongodStarter starter = MongodStarter.getDefaultInstance();
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(URL, PORT, Network.localhostIsIPv6()))
.build();
mongodExecutable = starter.prepare(mongodConfig);
mongodExecutable.start();
mongo = new MongoClient(URL, PORT);
}