de.flapdoodle.embed.mongo.config.Net Java Examples

The following examples show how to use de.flapdoodle.embed.mongo.config.Net. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedMongo.java    From spring-data-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Create a default {@code mongos} config.
 *
 * @param version
 * @param port
 * @param cmdOptions
 * @param configServerReplicaSet
 * @param configServerPort
 * @return
 */
private static IMongosConfig defaultMongosConfig(IFeatureAwareVersion version, int port, IMongoCmdOptions cmdOptions,
		String configServerReplicaSet, int configServerPort) {

	try {

		MongosConfigBuilder builder = new MongosConfigBuilder() //
				.version(version) //
				.withLaunchArgument("--quiet", null) //
				.net(new Net(LOCALHOST, port, Network.localhostIsIPv6())) //
				.cmdOptions(cmdOptions);

		if (StringUtils.hasText(configServerReplicaSet)) {
			builder = builder.replicaSet(configServerReplicaSet) //
					.configDB(LOCALHOST + ":" + configServerPort);
		}

		return builder.build();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example #2
Source File: MongoNotebookRepoTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
  String bindIp = "localhost";
  ServerSocket socket = new ServerSocket(0);
  int port = socket.getLocalPort();
  socket.close();

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

  mongodExecutable = MongodStarter.getDefaultInstance()
      .prepare(mongodConfig);
  mongodExecutable.start();

  System.setProperty(ZEPPELIN_NOTEBOOK_MONGO_URI.getVarName(), "mongodb://" + bindIp + ":" + port);
  zConf = new ZeppelinConfiguration();
  notebookRepo = new MongoNotebookRepo();
  notebookRepo.init(zConf);
}
 
Example #3
Source File: EmbeddedMongoHelper.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
public static void startMongoDB() throws IOException {
    if (!started.compareAndSet(false, true)) {
        throw new RuntimeException("Embedded mongo already running, call stopMongoDB before starting it again!");
    }
    final String bindIp = "localhost";
    try {
        final int port = Network.getFreeServerPort();
        final IMongodConfig mongodConfig = new MongodConfigBuilder()
                .version(Version.Main.PRODUCTION)
                .net(new Net(bindIp, port, Network.localhostIsIPv6()))
                .build();
        final MongodStarter runtime = MongodStarter.getInstance(new RuntimeConfigBuilder()
                .defaultsWithLogger(Command.MongoD, LOG)
                .build());
        mongodExecutable = runtime.prepare(mongodConfig, Distribution.detectFor(Version.Main.PRODUCTION));
        mongodProcess = mongodExecutable.start();
        mongoClient = new MongoClient(bindIp, port);
    } catch (final IOException e) {
        stopMongoDB();
        throw e;
    }
}
 
Example #4
Source File: MongoDbReadWriteIT.java    From beam with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  int port = NetworkTestHelper.getAvailableLocalPort();
  LOG.info("Starting MongoDB embedded instance on {}", port);
  IMongodConfig mongodConfig =
      new MongodConfigBuilder()
          .version(Version.Main.PRODUCTION)
          .configServer(false)
          .replication(new Storage(MONGODB_LOCATION.getRoot().getPath(), null, 0))
          .net(new Net(hostname, port, Network.localhostIsIPv6()))
          .cmdOptions(
              new MongoCmdOptionsBuilder()
                  .syncDelay(10)
                  .useNoPrealloc(true)
                  .useSmallFiles(true)
                  .useNoJournal(true)
                  .verbose(false)
                  .build())
          .build();
  mongodExecutable = mongodStarter.prepare(mongodConfig);
  mongodProcess = mongodExecutable.start();
  client = new MongoClient(hostname, port);

  mongoSqlUrl = String.format("mongodb://%s:%d/%s/%s", hostname, port, database, collection);
}
 
Example #5
Source File: MongoRyaDirectExample.java    From rya with Apache License 2.0 6 votes vote down vote up
private static Configuration getConf() throws IOException {

        MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder()
            .setUseMockMongo(USE_MOCK).setUseInference(USE_INFER).setAuths("U");

        if (USE_MOCK) {
            final EmbeddedMongoFactory factory = EmbeddedMongoFactory.newFactory();
            final IMongoConfig connectionConfig = factory.getMongoServerDetails();
            final Net net = connectionConfig.net();
            builder.setMongoHost(net.getBindIp() == null ? "127.0.0.1" : net.getBindIp())
                   .setMongoPort(net.getPort() + "");
        } else {
            // User name and password must be filled in:
            builder = builder.setMongoUser(MONGO_USER)
                             .setMongoPassword(MONGO_PASSWORD)
                             .setMongoHost(MONGO_INSTANCE_URL)
                             .setMongoPort(MONGO_INSTANCE_PORT);
        }

        return builder.setMongoDBName(MONGO_DB)
               .setMongoCollectionPrefix(MONGO_COLL_PREFIX)
               .setUseMongoFreetextIndex(true)
               .setMongoFreeTextPredicates(RDFS.LABEL.stringValue()).build();

    }
 
Example #6
Source File: AbstractMongoDBResource.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void importData(String dbname, String collection, String file, ImportFormat format, ImportOption... options) throws IOException {
  int p = port.orElseThrow(() -> new IllegalStateException("Trying to access client before server has been started"));

  MongoImportConfigBuilder builder = new MongoImportConfigBuilder()
      .version(version)
      .net(new Net(p, Network.localhostIsIPv6()))
      .db(dbname)
      .collection(collection)
      .importFile(file)
      .type(format.name().toLowerCase(Locale.ROOT));

  for(ImportOption option: options) {
    if (option instanceof ImportOptions) {
      setOption(builder, (ImportOptions) option);
      continue;
    }

    throw new IllegalArgumentException("Unknown option " + option);
  }

  MongoImportExecutable executable = Environment.prepareMongoImport(builder.build());
  executable.start();
}
 
Example #7
Source File: EmbeddedMongoDb.java    From render with GNU General Public License v2.0 6 votes vote down vote up
public EmbeddedMongoDb(final String dbName)
        throws IOException {

    this.version = Version.Main.V4_0;
    this.port = 12345;

    // see MongodForTestsFactory for example verbose startup options
    this.mongodExecutable = STARTER.prepare(
            new MongodConfigBuilder()
                    .version(version)
                    .net(new Net(port, Network.localhostIsIPv6()))

                    // use ephemeralForTest storage engine to fix super slow run times on Mac
                    // see https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/issues/166
                    .cmdOptions(new MongoCmdOptionsBuilder().useStorageEngine("ephemeralForTest").build())

                    .build());

    this.mongodProcess = mongodExecutable.start();

    this.mongoClient = new MongoClient("localhost", port);

    this.db = mongoClient.getDatabase(dbName);
}
 
Example #8
Source File: EmbeddedMongoDb.java    From render with GNU General Public License v2.0 6 votes vote down vote up
public void importCollection(final String collectionName,
                             final File jsonFile,
                             final Boolean jsonArray,
                             final Boolean upsert,
                             final Boolean drop) throws IOException {

    final IMongoImportConfig mongoImportConfig = new MongoImportConfigBuilder()
            .version(version)
            .net(new Net(port, Network.localhostIsIPv6()))
            .db(db.getName())
            .collection(collectionName)
            .upsert(upsert)
            .dropCollection(drop)
            .jsonArray(jsonArray)
            .importFile(jsonFile.getAbsolutePath())
            .build();

    final MongoImportExecutable mongoImportExecutable =
            MongoImportStarter.getInstance(MONGO_IMPORT_RUNTIME_CONFIG).prepare(mongoImportConfig);

    mongoImportExecutable.start();
}
 
Example #9
Source File: DevelopmentConfig.java    From entref-spring-boot with MIT License 6 votes vote down vote up
@Override
public DatabaseInformation getDatabaseInformation() throws Exception {
    String connStr = env.getProperty(Constants.ENV_DB_CONNSTR);
    String name;
    if (connStr == null) {
        if (this.embeddedMongoInstance == null) {
            // we need to try to startup embedded mongo
            this.embeddedBindInformation = new Net();
            this.embeddedMongoInstance = this.setupMongoEmbed(this.embeddedBindInformation);
        }

        connStr = "mongodb://localhost:" + this.embeddedBindInformation.getPort();
        name = "test";
    } else {
        name = env.getRequiredProperty(Constants.ENV_DB_NAME);
    }

    return new DatabaseInformation(connStr, name);
}
 
Example #10
Source File: PropertyMockingApplicationContextInitializer.java    From entref-spring-boot with MIT License 6 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    // configure a net binding instance
    Net mongoNet = this.getMongoNet();

    // register some autowire-able dependencies, to make leveraging the configured instances in a test possible
    applicationContext.getBeanFactory().registerResolvableDependency(RestTemplateBuilder.class, this.getRestTemplateBuilder());
    applicationContext.getBeanFactory().registerResolvableDependency(Net.class, mongoNet);
    applicationContext.getBeanFactory().registerResolvableDependency(MongodExecutable.class, this.getMongo(mongoNet));

    // configure the property sources that will be used by the application
    MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
    MockPropertySource mockEnvVars = new MockPropertySource()
            .withProperty(Constants.ENV_DB_NAME, this.getDbName())
            .withProperty(Constants.ENV_DB_CONNSTR, "mongodb://localhost:" + mongoNet.getPort())
            .withProperty(Constants.ENV_ALLOWED_ORIGIN, this.getAllowedOrigin())
            .withProperty(Constants.ENV_EXCLUDE_FILTER, String.join(",", this.getExcludeList()));

    // inject the property sources into the application as environment variables
    propertySources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, mockEnvVars);
}
 
Example #11
Source File: MongoBaseTest.java    From vertx-auth with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startMongo() throws Exception {
  String uri = getConnectionString();
  if (uri == null ) {
    Version.Main version = Version.Main.V3_4;
    int port = 27018;
    System.out.println("Starting Mongo " + version + " on port " + port);
    IMongodConfig config = new MongodConfigBuilder().
      version(version).
      net(new Net(port, Network.localhostIsIPv6())).
      build();
    exe = MongodStarter.getDefaultInstance().prepare(config);
    exe.start();
  } else {
    System.out.println("Using existing Mongo " + uri);
  }
}
 
Example #12
Source File: RyaMongoGeoDirectExample.java    From rya with Apache License 2.0 5 votes vote down vote up
private static Configuration getConf() throws IOException {

        MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder()
            .setUseMockMongo(USE_MOCK).setUseInference(USE_INFER).setAuths("U");

        if (USE_MOCK) {
            mock = EmbeddedMongoFactory.newFactory();
            final MongoClient c = mock.newMongoClient();
            final Net address = mock.getMongoServerDetails().net();
            final String url = address.getServerAddress().getHostAddress();
            final String port = Integer.toString(address.getPort());
            c.close();
            builder.setMongoHost(url).setMongoPort(port);
        } else {
            // User name and password must be filled in:
            builder = builder.setMongoUser("fill this in")
                             .setMongoPassword("fill this in")
                             .setMongoHost(MONGO_INSTANCE_URL)
                             .setMongoPort(MONGO_INSTANCE_PORT);
        }

        return builder.setMongoDBName(MONGO_DB)
               .setMongoCollectionPrefix(MONGO_COLL_PREFIX)
               .setUseMongoFreetextIndex(true)
               .setMongoFreeTextPredicates(RDFS.LABEL.stringValue()).build();

    }
 
Example #13
Source File: MongoDb4TestRule.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            final String value = Objects.requireNonNull(System.getProperty(portSystemPropertyName),
                    "System property '" + portSystemPropertyName + "' is null");
            final int port = Integer.parseInt(value);
            mongodExecutable = starter.prepare(
            // @formatter:off
                    new MongodConfigBuilder().version(Version.Main.PRODUCTION)
                            .timeout(new Timeout(BUILDER_TIMEOUT_MILLIS))
                            .net(new Net("localhost", port, Network.localhostIsIPv6())).build());
            // @formatter:on
            mongodProcess = mongodExecutable.start();
            mongoClient = MongoClients.create("mongodb://localhost:" + port);
            try {
                base.evaluate();
            } finally {
                if (mongodProcess != null) {
                    mongodProcess.stop();
                    mongodProcess = null;
                }
                if (mongodExecutable != null) {
                    mongodExecutable.stop();
                    mongodExecutable = null;
                }
            }
        }
    };
}
 
Example #14
Source File: MongoImplTest.java    From eagle with Apache License 2.0 5 votes vote down vote up
public static void before() {
    try {
        MongodStarter starter = MongodStarter.getDefaultInstance();
        mongodExe = starter.prepare(new MongodConfigBuilder().version(Version.V3_2_1)
            .net(new Net(27017, Network.localhostIsIPv6())).build());
        mongod = mongodExe.start();
    } catch (Exception e) {
        LOG.error("start embed mongod failed, assume some external mongo running. continue run test!", e);
    }
}
 
Example #15
Source File: SimpleEmbedMongo.java    From eagle with Apache License 2.0 5 votes vote down vote up
public void start() throws Exception {
    MongodStarter starter = MongodStarter.getDefaultInstance();
    mongodExe = starter.prepare(new MongodConfigBuilder().version(Version.V3_2_1)
            .net(new Net(27017, Network.localhostIsIPv6())).build());
    mongod = mongodExe.start();

    client = new MongoClient("localhost");
}
 
Example #16
Source File: MongodbLocalServer.java    From hadoop-mini-clusters with Apache License 2.0 5 votes vote down vote up
@Override
public void configure() throws Exception {
    conf = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION)
            .net(new Net(ip, port, false))
            .build();
}
 
Example #17
Source File: ManualEmbeddedMongoDbIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeEach
void setup() throws Exception {
    String ip = "localhost";
    int randomPort = SocketUtils.findAvailableTcpPort();

    IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION)
        .net(new Net(ip, randomPort, Network.localhostIsIPv6()))
        .build();

    MongodStarter starter = MongodStarter.getDefaultInstance();
    mongodExecutable = starter.prepare(mongodConfig);
    mongodExecutable.start();
    mongoTemplate = new MongoTemplate(new MongoClient(ip, randomPort), "test");
}
 
Example #18
Source File: MyFirstVerticleTest.java    From my-vertx-first-app with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initialize() throws IOException {
  MongodStarter starter = MongodStarter.getDefaultInstance();

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

  MongodExecutable mongodExecutable = starter.prepare(mongodConfig);
  MONGO = mongodExecutable.start();
}
 
Example #19
Source File: InferenceExamples.java    From rya with Apache License 2.0 5 votes vote down vote up
private static Configuration getConf() throws IOException {

       // MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder()
       //     .setUseMockMongo(USE_MOCK).setUseInference(USE_INFER).setAuths("U");
        MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder()
	            .setUseMockMongo(USE_EMBEDDED_MONGO).setUseInference(true).setAuths("U");

        if (USE_EMBEDDED_MONGO) {
            final MongoClient c = EmbeddedMongoFactory.newFactory().newMongoClient();
            final Net address = EmbeddedMongoFactory.newFactory().getMongoServerDetails().net();
            final String url = address.getServerAddress().getHostAddress();
            final String port = Integer.toString(address.getPort());
            c.close();
            builder.setMongoHost(url).setMongoPort(port);
        } else {
            // User name and password must be filled in:
            builder = builder.setMongoUser(MongoUserName)
                             .setMongoPassword(MongoUserPswd)
                             .setMongoHost(MONGO_INSTANCE_URL)
                             .setMongoPort(MONGO_INSTANCE_PORT);
        }

        return builder.setMongoDBName(MONGO_DB)
               .setMongoCollectionPrefix(MONGO_COLL_PREFIX)
               .setUseMongoFreetextIndex(true)
               .setMongoFreeTextPredicates(RDFS.LABEL.stringValue()).build();

    }
 
Example #20
Source File: MongoSpinIT.java    From rya with Apache License 2.0 5 votes vote down vote up
private static MongoDBRdfConfiguration getConf() throws Exception {
    final MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder().setUseMockMongo(true);
    final MongoClient c = EmbeddedMongoFactory.newFactory().newMongoClient();
    final Net address = EmbeddedMongoFactory.newFactory().getMongoServerDetails().net();
    builder.setMongoHost(address.getServerAddress().getHostAddress());
    builder.setMongoPort(Integer.toString(address.getPort()));
    builder.setUseInference(false);
    c.close();
    return builder.build();
}
 
Example #21
Source File: EmbeddedMongo.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Create a default {@code mongod} config.
 *
 * @param version
 * @param port
 * @param cmdOptions
 * @param configServer
 * @param shardServer
 * @param replicaSet
 * @return
 */
private static IMongodConfig defaultMongodConfig(IFeatureAwareVersion version, int port, IMongoCmdOptions cmdOptions,
		boolean configServer, boolean shardServer, String replicaSet) {

	try {

		MongodConfigBuilder builder = new MongodConfigBuilder() //
				.version(version) //
				.withLaunchArgument("--quiet") //
				.net(new Net(LOCALHOST, port, Network.localhostIsIPv6())) //
				.configServer(configServer).cmdOptions(cmdOptions); //

		if (StringUtils.hasText(replicaSet)) {

			builder = builder //
					.replication(new Storage(null, replicaSet, 0));

			if (!configServer) {
				builder = builder.shardServer(shardServer);
			} else {
				builder = builder.shardServer(false);
			}
		}

		return builder.build();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example #22
Source File: MongoDbInit.java    From tutorials with MIT License 5 votes vote down vote up
public static void startMongoDb() throws IOException {
    _mongodExe = starter.prepare(new MongodConfigBuilder()
            .version(Version.Main.DEVELOPMENT)
            .net(new Net("localhost", 27017, Network.localhostIsIPv6()))
            .build());
    _mongod = _mongodExe.start();
}
 
Example #23
Source File: MongoDb3TestRule.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            final String value = Objects.requireNonNull(System.getProperty(portSystemPropertyName),
                    "System property '" + portSystemPropertyName + "' is null");
            final int port = Integer.parseInt(value);
            mongodExecutable = starter.prepare(
            // @formatter:off
                    new MongodConfigBuilder()
                        .version(Version.Main.PRODUCTION)
                        .timeout(new Timeout(BUILDER_TIMEOUT_MILLIS))
                        .net(
                                new Net("localhost", port, Network.localhostIsIPv6()))
                        .build());
            // @formatter:on
            mongodProcess = mongodExecutable.start();
            mongoClient = new MongoClient("localhost", port);
            try {
                base.evaluate();
            } finally {
                if (mongodProcess != null) {
                    mongodProcess.stop();
                    mongodProcess = null;
                }
                if (mongodExecutable != null) {
                    mongodExecutable.stop();
                    mongodExecutable = null;
                }
            }
        }
    };
}
 
Example #24
Source File: EmbeddedMongoDBSetup.java    From tutorials with MIT License 5 votes vote down vote up
private void initdb() throws IOException {
    _mongodExe = starter.prepare(new MongodConfigBuilder()
            .version(Version.Main.DEVELOPMENT)
            .net(new Net(MONGODB_HOST, MONGODB_PORT, Network.localhostIsIPv6()))
            .build());
    _mongod = _mongodExe.start();
}
 
Example #25
Source File: ErrorLogsCounterManualTest.java    From tutorials with MIT License 5 votes vote down vote up
private MongoTemplate initMongoTemplate() throws IOException {
    mongodExecutable = starter.prepare(new MongodConfigBuilder()
      .version(Version.Main.PRODUCTION)
      .net(new Net(SERVER, PORT, Network.localhostIsIPv6()))
      .build());
    mongoDaemon = mongodExecutable.start();

    MongoClient mongoClient = new MongoClient(SERVER, PORT);
    db = mongoClient.getDatabase(DB_NAME);

    return new MongoTemplate(mongoClient, DB_NAME);
}
 
Example #26
Source File: MongoTestBase.java    From vertx-mongo-client with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startMongo() throws Exception {
  String uri = getConnectionString();
  if (uri == null ) {
    Version.Main version = Version.Main.V3_4;
    int port = 27018;
    System.out.println("Starting Mongo " + version + " on port " + port);
    IMongodConfig config = new MongodConfigBuilder().
      version(version).
      net(new Net(port, Network.localhostIsIPv6())).
      build();
    exe = MongodStarter.getDefaultInstance().prepare(config);
    exe.start();
  } else {
    System.out.println("Using existing Mongo " + uri);
  }
}
 
Example #27
Source File: MongoDBITBase.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void startDB() throws Exception {
    MongodStarter starter = MongodStarter.getDefaultInstance();

    String bindIp = "localhost";
    int port = 27018;

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

    MongodExecutable mongodExecutable = null;

    mongodExecutable = starter.prepare(mongodConfig);

    //give time for previous DB close to finish and port to be released"
    Thread.sleep(200L);
    mongod = mongodExecutable.start();
    setClient();
}
 
Example #28
Source File: MongoDBSessionDataStorageTest.java    From pippo with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpClass() throws IOException {
    Integer port = Network.getFreeServerPort();
    MongodStarter starter = MongodStarter.getDefaultInstance();
    mongodExe = starter.prepare(
            new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION)
            .net(new Net(port, Network.localhostIsIPv6()))
            .build());
    mongod = mongodExe.start();
    mongoClient = new MongoClient(HOST, port);
}
 
Example #29
Source File: MyFirstVerticleTest.java    From df_data_service with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initialize() throws IOException {
  MongodStarter starter = MongodStarter.getDefaultInstance();

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

  MongodExecutable mongodExecutable = starter.prepare(mongodConfig);
  MONGO = mongodExecutable.start();
}
 
Example #30
Source File: DevelopmentConfig.java    From entref-spring-boot with MIT License 5 votes vote down vote up
/**
 * Attempts to start a mongo instance, using embedMongo
 * @param bind the net info to bind to
 * @return the instance
 * @throws IOException indicates a failure
 */
private MongodExecutable setupMongoEmbed(Net bind) throws IOException {
    MongodStarter starter;
    starter = MongodStarter.getDefaultInstance();

    IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.DEVELOPMENT)
            .net(bind)
            .build();

    MongodExecutable mongodExecutable = starter.prepare(mongodConfig);
    MongodProcess mongod = mongodExecutable.start();
    return mongodExecutable;
}