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

The following examples show how to use de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder. 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: 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 #2
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 #3
Source File: MongoWithReplicasTestBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static IMongodConfig buildMongodConfiguration(String url, int port, final boolean configureReplicaSet)
        throws IOException {
    final MongodConfigBuilder builder = new MongodConfigBuilder()
            .version(Version.Main.V4_0)
            .net(new Net(url, port, Network.localhostIsIPv6()));
    if (configureReplicaSet) {
        builder.withLaunchArgument("--replSet", "test001");
        builder.cmdOptions(new MongoCmdOptionsBuilder()
                .syncDelay(10)
                .useSmallFiles(true)
                .useNoJournal(false)
                .build());
    }
    return builder.build();
}
 
Example #4
Source File: MongoWithReplicasTestBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static IMongodConfig buildMongodConfiguration(String url, int port, final boolean configureReplicaSet)
        throws IOException {
    final MongodConfigBuilder builder = new MongodConfigBuilder()
            .version(Version.Main.V4_0)
            .net(new Net(url, port, Network.localhostIsIPv6()));
    if (configureReplicaSet) {
        builder.withLaunchArgument("--replSet", "test001");
        builder.cmdOptions(new MongoCmdOptionsBuilder()
                .syncDelay(10)
                .useSmallFiles(true)
                .useNoJournal(false)
                .build());
    }
    return builder.build();
}
 
Example #5
Source File: MongoDbResource.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private static MongodExecutable configureMongoDb(final String bindIp,
        final int mongoDbPort,
        final IProxyFactory proxyFactory,
        final Logger logger) throws IOException {

    final Command command = Command.MongoD;

    final ProcessOutput processOutput;
    if (logger != null) {
        processOutput = ProcessOutput.getInstance("mongod", logger);
    } else {
        processOutput = ProcessOutput.getDefaultInstanceSilent();
    }

    final MongodStarter mongodStarter = MongodStarter.getInstance(new RuntimeConfigBuilder()
            .defaults(command)
            .processOutput(processOutput)
            .artifactStore(new ExtractedArtifactStoreBuilder()
                    .defaults(command)
                    .download(new DownloadConfigBuilder()
                            .defaultsForCommand(command)
                            .proxyFactory(proxyFactory)
                            .progressListener(new StandardConsoleProgressListener())
                            .build()))
            .build());

    return mongodStarter.prepare(new MongodConfigBuilder()
            .net(new Net(bindIp, mongoDbPort, false))
            .version(Version.Main.V3_6)
            .cmdOptions(new MongoCmdOptionsBuilder()
                    .useStorageEngine("wiredTiger")
                    .useNoJournal(false)
                    .build())
            .build());
}
 
Example #6
Source File: MongoDbIOTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  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("localhost", 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("localhost", port);

  LOG.info("Insert test data");
  List<Document> documents = createDocuments(1000);
  MongoCollection<Document> collection = getCollection(COLLECTION);
  collection.insertMany(documents);
}
 
Example #7
Source File: EmbeddedMongo.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
/**
 * @return Default {@link IMongoCmdOptions command options}.
 */
private static IMongoCmdOptions defaultCommandOptions() {

	return new MongoCmdOptionsBuilder() //
			.useNoPrealloc(false) //
			.useSmallFiles(false) //
			.useNoJournal(false) //
			.useStorageEngine(STORAGE_ENGINE) //
			.verbose(false) //
			.build();
}
 
Example #8
Source File: QueryConverterIT.java    From sql-to-mongo-db-query-converter with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() throws IOException {
    IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION)
            .cmdOptions(new MongoCmdOptionsBuilder()
        		.useNoPrealloc(false)
        		.useSmallFiles(false)
        		.build())
            .net(new Net("localhost",port, false))
            .build();

    mongodExecutable = starter.prepare(mongodConfig);
    mongodProcess = mongodExecutable.start();
    mongoClient = new MongoClient("localhost",port);


    mongoDatabase = mongoClient.getDatabase(DATABASE);
    
    
    mongoCollection = mongoDatabase.getCollection(COLLECTION_CUSTOMERS);

    mongoCollection.deleteMany(new Document());
    loadRecords(TOTAL_TEST_RECORDS_PRIMER,DATASET_CUSTOMERS,mongoCollection);
    assertEquals(TOTAL_TEST_RECORDS_CUSTOMERS,mongoCollection.countDocuments());
    
    mongoCollection = mongoDatabase.getCollection(COLLECTION_FILMS);

    mongoCollection.deleteMany(new Document());
    loadRecords(TOTAL_TEST_RECORDS_PRIMER,DATASET_FILMS,mongoCollection);
    assertEquals(TOTAL_TEST_RECORDS_FILMS,mongoCollection.countDocuments());
    
    mongoCollection = mongoDatabase.getCollection(COLLECTION_STORES);

    mongoCollection.deleteMany(new Document());
    loadRecords(TOTAL_TEST_RECORDS_PRIMER,DATASET_STORES,mongoCollection);
    assertEquals(TOTAL_TEST_RECORDS_STORES,mongoCollection.countDocuments());

    mongoCollection = mongoDatabase.getCollection(COLLECTION);

    mongoCollection.deleteMany(new Document());
    loadRecords(TOTAL_TEST_RECORDS_PRIMER,DATASET_PRIMER,mongoCollection);
    assertEquals(TOTAL_TEST_RECORDS_PRIMER,mongoCollection.countDocuments());
    
}
 
Example #9
Source File: MongoJavaRDDFT.java    From deep-spark with Apache License 2.0 4 votes vote down vote up
@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();

}