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

The following examples show how to use de.flapdoodle.embed.mongo.config.Storage. 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: EmbedMongoConfiguration.java    From syndesis with Apache License 2.0 5 votes vote down vote up
static IMongodConfig createEmbeddedMongoConfiguration() {
    try {
        final Path storagePath = Files.createTempDirectory("embeddeddmongo");
        storagePath.toFile().deleteOnExit();
        return new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION)
            .net(new Net(PORT, Network.localhostIsIPv6()))
            .replication(new Storage(storagePath.toString(),
                REPLICA_SET, 5000))
            .stopTimeoutInMillis(10000)
            .build();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #3
Source File: MongodManager.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
private IMongodConfig buildMongodConfiguration(final HostAndPort hostAndPort, final boolean configureReplicaSet) throws IOException {
    final InetAddress address = InetAddress.getByName(hostAndPort.getHost());

    // @formatter:off
    final MongodConfigBuilder builder = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION)
            .net(new Net(hostAndPort.getHost(), hostAndPort.getPort(), address instanceof Inet6Address));
    // @formatter:on

    if (configureReplicaSet) {
        builder.replication(new Storage(null, "test001", 0));
    }
    return builder.build();
}
 
Example #4
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 #5
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 #6
Source File: MongodbSourceUriTaskTest.java    From kafka-connect-mongodb with Apache License 2.0 4 votes vote down vote up
@Override
    public void setUp() {
        offsets = new HashMap<>();
        totalWrittenDocuments = 0;
        try {
            super.setUp();
            mongodStarter = MongodStarter.getDefaultInstance();
            mongodConfig = new MongodConfigBuilder()
                    .version(Version.Main.V3_2)
                    .replication(new Storage(REPLICATION_PATH, "rs0", 1024))
                    .net(new Net(12345, Network.localhostIsIPv6()))
                    .build();
            mongodExecutable = mongodStarter.prepare(mongodConfig);
            mongod = mongodExecutable.start();
            mongoClient = new MongoClient(new ServerAddress("localhost", 12345));
            MongoDatabase adminDatabase = mongoClient.getDatabase("admin");

            BasicDBObject replicaSetSetting = new BasicDBObject();
            replicaSetSetting.put("_id", "rs0");
            BasicDBList members = new BasicDBList();
            DBObject host = new BasicDBObject();
            host.put("_id", 0);
            host.put("host", "127.0.0.1:12345");
            members.add(host);
            replicaSetSetting.put("members", members);
            adminDatabase.runCommand(new BasicDBObject("isMaster", 1));
            adminDatabase.runCommand(new BasicDBObject("replSetInitiate", replicaSetSetting));
            MongoDatabase db = mongoClient.getDatabase("mydb");
            db.createCollection("test1");
            db.createCollection("test2");
            db.createCollection("test3");
        } catch (Exception e) {
//                Assert.assertTrue(false);
        }

        task = new MongodbSourceTask();

        offsetStorageReader = PowerMock.createMock(OffsetStorageReader.class);
        context = PowerMock.createMock(SourceTaskContext.class);
        task.initialize(context);

        sourceProperties = new HashMap<>();
        sourceProperties.put("uri", "mongodb://localhost:12345");
        sourceProperties.put("batch.size", Integer.toString(100));
        sourceProperties.put("schema.name", "schema");
        sourceProperties.put("topic.prefix", "prefix");
        sourceProperties.put("databases", "mydb.test1,mydb.test2,mydb.test3");

    }
 
Example #7
Source File: MongodbSourceTaskTest.java    From kafka-connect-mongodb with Apache License 2.0 4 votes vote down vote up
@Override
    public void setUp() {
        offsets = new HashMap<>();
        totalWrittenDocuments = 0;
        try {
            super.setUp();
            mongodStarter = MongodStarter.getDefaultInstance();
            mongodConfig = new MongodConfigBuilder()
                    .version(Version.Main.V3_2)
                    .replication(new Storage(REPLICATION_PATH, "rs0", 1024))
                    .net(new Net(12345, Network.localhostIsIPv6()))
                    .build();
            mongodExecutable = mongodStarter.prepare(mongodConfig);
            mongod = mongodExecutable.start();
            mongoClient = new MongoClient(new ServerAddress("localhost", 12345));
            MongoDatabase adminDatabase = mongoClient.getDatabase("admin");

            BasicDBObject replicaSetSetting = new BasicDBObject();
            replicaSetSetting.put("_id", "rs0");
            BasicDBList members = new BasicDBList();
            DBObject host = new BasicDBObject();
            host.put("_id", 0);
            host.put("host", "127.0.0.1:12345");
            members.add(host);
            replicaSetSetting.put("members", members);
            adminDatabase.runCommand(new BasicDBObject("isMaster", 1));
            adminDatabase.runCommand(new BasicDBObject("replSetInitiate", replicaSetSetting));
            MongoDatabase db = mongoClient.getDatabase("mydb");
            db.createCollection("test1");
            db.createCollection("test2");
            db.createCollection("test3");
        } catch (Exception e) {
//                Assert.assertTrue(false);
        }

        task = new MongodbSourceTask();

        offsetStorageReader = PowerMock.createMock(OffsetStorageReader.class);
        context = PowerMock.createMock(SourceTaskContext.class);
        task.initialize(context);

        sourceProperties = new HashMap<>();
        sourceProperties.put("host", "localhost");
        sourceProperties.put("port", Integer.toString(12345));
        sourceProperties.put("batch.size", Integer.toString(100));
        sourceProperties.put("schema.name", "schema");
        sourceProperties.put("topic.prefix", "prefix");
        sourceProperties.put("databases", "mydb.test1,mydb.test2,mydb.test3");

    }
 
Example #8
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();

}