當前位置: 首頁>>代碼示例>>Java>>正文


Java MongodStarter.getInstance方法代碼示例

本文整理匯總了Java中de.flapdoodle.embed.mongo.MongodStarter.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java MongodStarter.getInstance方法的具體用法?Java MongodStarter.getInstance怎麽用?Java MongodStarter.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在de.flapdoodle.embed.mongo.MongodStarter的用法示例。


在下文中一共展示了MongodStarter.getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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);
	
}
 
開發者ID:spgroup,項目名稱:groundhog,代碼行數:25,代碼來源:GroundhogDBTest.java

示例2: 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());
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:22,代碼來源:MongoDbTestRule.java

示例3: MongoClientTestConfiguration

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
public MongoClientTestConfiguration() throws IOException {

    Command command = Command.MongoD;
    IDownloadConfig downloadConfig = new DownloadConfigBuilder().defaultsForCommand(command)
                                                                .progressListener(new Slf4jProgressListener(LOGGER))
                                                                .build();
    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(command)
                                                             .artifactStore(new ExtractedArtifactStoreBuilder()
                                                                                .defaults(command)
                                                                                .download(downloadConfig))
                                                             .build();
    final MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
    mongodExecutable = runtime.prepare(newMongodConfig(Version.Main.PRODUCTION));
    startMongodExecutable();
  }
 
開發者ID:krraghavan,項目名稱:mongodb-aggregate-query-support,代碼行數:16,代碼來源:MongoClientTestConfiguration.java

示例4: MongoInstance

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
public MongoInstance() throws IOException, InterruptedException {

        // Download Mongo artifacts into the project directory to ease cleanup
        IDownloadConfig downloadConfig = new DownloadConfigBuilder()
                .defaultsForCommand(Command.MongoD)
                .artifactStorePath(ARTIFACT_STORE_PATH)
                .build();

        // Extract Mongo artifacts into the project directory to ease cleanup
        IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
                .defaults(Command.MongoD)
                .artifactStore(new ExtractedArtifactStoreBuilder()
                        .defaults(Command.MongoD)
                        .download(downloadConfig)
                        .extractDir(EXTRACTED_STORE_PATH)
                )
                .build();

        // Store Mongo data into the project directory to ease cleanup
        Storage replication = new Storage("./data/mongodb/data", null, 0);

        MongodStarter starter = MongodStarter.getInstance(runtimeConfig);

        IMongodConfig mongodConfig = new MongodConfigBuilder()
                .version(Version.Main.PRODUCTION)
                .cmdOptions(new MongoCmdOptionsBuilder()
                        .useNoJournal(false)
                        .useSmallFiles(true)
                        .build())
                .net(new Net(MongoProperties.DEFAULT_PORT, Network.localhostIsIPv6()))
                .replication(replication)
                .build();

        mongo = starter.prepare(mongodConfig);
        process = mongo.start();
    }
 
開發者ID:mike-plummer,項目名稱:graylog-springboot,代碼行數:37,代碼來源:MongoInstance.java

示例5: startMongo

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
private void startMongo(final List<IMongodConfig> mongodConfigList) throws IOException {
    // @formatter:off
    final ProcessOutput processOutput = new ProcessOutput(
            logTo(LOGGER, Slf4jLevel.INFO),
            logTo(LOGGER, Slf4jLevel.ERROR),
            named("[console>]", logTo(LOGGER, Slf4jLevel.DEBUG)));

    final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaultsWithLogger(Command.MongoD,LOGGER)
            .processOutput(processOutput)
            .artifactStore(new ExtractedArtifactStoreBuilder()
                .defaults(Command.MongoD)
                .download(new DownloadConfigBuilder()
                    .defaultsForCommand(Command.MongoD)
                    .progressListener(new Slf4jProgressListener(LOGGER))
                    .build()))
            .build();
    // @formatter:on
    final MongodStarter starter = MongodStarter.getInstance(runtimeConfig);

    for (final IMongodConfig mongodConfig : mongodConfigList) {
        final MongodExecutable mongodExecutable = starter.prepare(mongodConfig);
        final MongodProcess mongod = mongodExecutable.start();

        mongoProcesses.put(mongod, mongodExecutable);
    }
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:28,代碼來源:MongodManager.java

示例6: before

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
@Override
public void before() throws Throwable {

    int port = Network.getFreeServerPort();
    String portProp = System.getProperty(MONGO_PORT_PROP);
    if (portProp != null && !portProp.isEmpty()) {
        port = Integer.valueOf(portProp);
    }

    IMongodConfig conf =
            new MongodConfigBuilder().version(Version.Main.PRODUCTION)
                .net(new Net(port, Network.localhostIsIPv6())).build();

    Command command = Command.MongoD;
    IRuntimeConfig runtimeConfig =
            new RuntimeConfigBuilder()
                .defaultsWithLogger(command, LOGGER)
                .artifactStore(
                        new ArtifactStoreBuilder().defaults(command).download(
                                new DownloadConfigBuilder().defaultsForCommand(command).proxyFactory(new SystemProxy())))
                .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
    mongoExec = runtime.prepare(conf);

    mongoProc = mongoExec.start();

    client = new MongoClient(new ServerAddress(conf.net().getServerAddress(), conf.net().getPort()));

    // set the property for our config...
    System.setProperty("dbhost", conf.net().getServerAddress().getHostAddress());
    System.setProperty("dbport", Integer.toString(conf.net().getPort()));
}
 
開發者ID:jimzucker,項目名稱:hygieia-temp,代碼行數:34,代碼來源:EmbeddedMongoDBRule.java

示例7: run

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
public IResponse run(IContext context) throws CommandException
{
	// Creates the response
	IResponse response = new Response();
	
	// If the embedded server is not already stated or starting
	if(context.getState() != State.STARTING && context.getState() != State.STARTED) {
	
		// Sets the starting state
		context.setState(State.STARTING);

		// Creates and starts a MongodExecutable
		MongodStarter starter = MongodStarter.getInstance(context.getMongoContext().getRuntimeConfig());
		MongodExecutable mongodExecutable = starter.prepare(context.getMongoContext().getMongodConfig());
		
		try {
			MongodProcess mongodProcess = mongodExecutable.start();
			context.getMongoContext().setMongodProcess(mongodProcess);
		} catch (IOException ioException) {
			throw new CommandException(ioException);
		}

		context.getMongoContext().setMongodExecutable(mongodExecutable);

		// Sets the started state
		context.setState(State.STARTED);

	}

	// Otherwise this is an error because the server is already started
	else {
		
		// TODO: Trouver un moyen de modéliser une erreur générique
		
	}

	return response;
}
 
開發者ID:gomoob,項目名稱:embedded-mongo,代碼行數:42,代碼來源:StartCommand.java

示例8: setup

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
@PostConstruct
public void setup()
{
    try
    {
        MongodStarter runtime = MongodStarter.getInstance( runtimeConfig() );
        exe = runtime.prepare( mongodConfig() );
        exe.start();
    }
    catch ( Exception e )
    {
        throw Throwables.propagate( e );
    }
}
 
開發者ID:cherimojava,項目名稱:orchidae,代碼行數:15,代碼來源:cfgMongo.java

示例9: setUpClass

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
/**
 * Initiate the MongoDB server on the default port
 */
@Override
public void setUpClass() throws IOException {
  IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
          .defaultsWithLogger(Command.MongoD, log)
          .processOutput(ProcessOutput.getDefaultInstanceSilent())
          .build();

  MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

  int port = Network.getFreeServerPort();
  IMongodConfig mongodConfig = new MongodConfigBuilder()
          .version(version)
          .net(new Net(port, Network.localhostIsIPv6())).build();

  // Store Mongo server "host:port" in Hadoop configuration
  // so that MongoStore will be able to get it latter
  conf.set(MongoStoreParameters.PROP_MONGO_SERVERS, "127.0.0.1:" + port);

  log.info("Starting embedded Mongodb server on {} port.", port);
  try {

    _mongodExe = runtime.prepare(mongodConfig);
    _mongod = _mongodExe.start();

    _mongo = new MongoClient("localhost", port);
  } catch (Exception e) {
    log.error("Error starting embedded Mongodb server... tearing down test driver.");
    tearDownClass();
  }
}
 
開發者ID:apache,項目名稱:gora,代碼行數:34,代碼來源:GoraMongodbTestDriver.java

示例10: getMongodStarter

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
private MongodStarter getMongodStarter(IRuntimeConfig runtimeConfig) {
	if (runtimeConfig == null) {
		return MongodStarter.getDefaultInstance();
	}
	return MongodStarter.getInstance(runtimeConfig);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:7,代碼來源:EmbeddedMongoAutoConfiguration.java

示例11: setup_mongo

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
@BeforeClass
public static void setup_mongo() throws UnknownHostException, IOException{
	
	String proxyHost = System.getenv("http.proxyHost");
	String proxyPort = System.getenv("http.proxyPort");
	
	String proxy = System.getenv("http_proxy");
	System.out.println("Proxy URL : " + proxy);
	if(proxy != null){
		if(proxyHost == null && proxyPort == null){
			URL proxyurl = new URL(proxy);
		   proxyHost = proxyurl.getHost();
		   proxyPort = String.valueOf(proxyurl.getPort());
		}  
	}
	
	MongodStarter starter ;
	
	System.out.println("Proxy Host : " + proxyHost);
	System.out.println("Proxy Port : " + proxyPort);
	if (proxyHost != null && proxyPort != null) {
		IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.MongoD)
				.artifactStore(
						new ArtifactStoreBuilder().defaults(Command.MongoD)
								.download(
										new DownloadConfigBuilder()
												.defaultsForCommand(Command.MongoD)
												.proxyFactory(
														new HttpProxyFactory(
																proxyHost,
																Integer.parseInt(proxyPort)))
												.build()).build()).build();
		 starter = MongodStarter.getInstance(runtimeConfig);
	} else {
		 starter = MongodStarter.getDefaultInstance();
	}
		                                        		
	
	IMongodConfig mongodConfig = new MongodConfigBuilder()
			.version(Version.Main.PRODUCTION)
			.net(new Net(mongoport, Network.localhostIsIPv6())).build();

	MongodExecutable mongodExecutable = null;

	mongodExecutable = starter.prepare(mongodConfig);
	mongod = mongodExecutable.start();
	
}
 
開發者ID:pulsarIO,項目名稱:jetstream,代碼行數:49,代碼來源:DynamicConfigTest.java

示例12: init

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
@BeforeSuite
public static void init() throws IOException {
    Command command = Command.MongoD;

    try {
        Files.forceDelete(new File(DB_FOLDER_NAME));
    } catch (Exception e) {

    }

    new File(DB_FOLDER_NAME).mkdirs();

    IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION)
            .configServer(false)
            .replication(new Storage(DB_FOLDER_NAME, null, 0))
            .net(new Net(PORT, Network.localhostIsIPv6()))
            .cmdOptions(new MongoCmdOptionsBuilder()
                    .syncDelay(10)
                    .useNoPrealloc(true)
                    .useSmallFiles(true)
                    .useNoJournal(true)
                    .build())
            .build();

    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaults(command)
            .artifactStore(new ArtifactStoreBuilder()
                    .defaults(command)
                    .download(new DownloadConfigBuilder()
                            .defaultsForCommand(command)
                            .downloadPath("https://s3-eu-west-1.amazonaws.com/stratio-mongodb-distribution/")))
            .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

    mongodExecutable = null;

    mongodExecutable = runtime.prepare(mongodConfig);

    mongod = mongodExecutable.start();

}
 
開發者ID:Stratio,項目名稱:deep-spark,代碼行數:44,代碼來源:MongoJavaRDDFT.java

示例13: initialize

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
private void initialize() {
    if (db != null) {
        return;
    }

    System.setProperty("mongodb.database", dbName);
    System.setProperty("mongodb.host", mongoHostname);
    System.setProperty("mongodb.port", String.valueOf(mongoPort));

    try {
        IStreamProcessor mongodOutput = Processors.named("[mongod>]",
                new FileStreamProcessor(File.createTempFile("mongod", "log")));
        IStreamProcessor mongodError = new FileStreamProcessor(File.createTempFile("mongod-error", "log"));
        IStreamProcessor commandsOutput = Processors.namedConsole("[console>]");

        IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
                .defaults(Command.MongoD)
                .processOutput(new ProcessOutput(mongodOutput, mongodError, commandsOutput))
                .build();

        MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
        mongodExe = runtime.prepare(
                new MongodConfigBuilder()
                .version(de.flapdoodle.embed.mongo.distribution.Version.V2_6_8)
                .net(new Net(mongoPort, Network.localhostIsIPv6()))
                .build()
        );
        try {
            mongod = mongodExe.start();
        } catch (Throwable t) {
            // try again, could be killed breakpoint in IDE
            mongod = mongodExe.start();
        }

        if (MONGO_CREDENTIALS.isEmpty()) {
            client = new MongoClient(mongoHostname + ":" + mongoPort);
        } else {
            client = new MongoClient(new ServerAddress(mongoHostname + ":" + mongoPort), MONGO_CREDENTIALS);
            client.getDB("admin").command("{ user: \"siteUserAdmin\", pwd: \"password\", roles: [ { role: \"userAdminAnyDatabase\", db: \"admin\" } , { role: \"userAdminAnyDatabase\", db: \"" + dbName + "\" } ] }");
        }

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                super.start();
                if (mongodExe != null) {
                    mongodExe.stop();
                }
                db = null;
                client = null;
                mongod = null;
                mongodExe = null;
            }

        });

        db = client.getDB(dbName);
    } catch (IOException e) {
        throw new Error(e);
    }
}
 
開發者ID:lightblue-platform,項目名稱:lightblue-mongo,代碼行數:62,代碼來源:EmbeddedMongo.java

示例14: mongodExecutable

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
private static MongodExecutable mongodExecutable()
    throws IOException
{
    MongodStarter runtime = MongodStarter.getInstance( runtimeConfig() );
    return runtime.prepare( mongodConfig() );
}
 
開發者ID:cherimojava,項目名稱:cherimodata,代碼行數:7,代碼來源:Suite.java

示例15: EmbeddedMongoFactory

import de.flapdoodle.embed.mongo.MongodStarter; //導入方法依賴的package包/類
/**
 * Create the testing utility using the specified version of MongoDB.
 *
 * @param version
 *            version of MongoDB.
 */
private EmbeddedMongoFactory(final IFeatureAwareVersion version) throws IOException {
    final MongodStarter runtime = MongodStarter.getInstance(new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).build());
    mongodExecutable = runtime.prepare(newMongodConfig(version));
    mongodProcess = mongodExecutable.start();
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:12,代碼來源:EmbeddedMongoFactory.java


注:本文中的de.flapdoodle.embed.mongo.MongodStarter.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。