de.flapdoodle.embed.mongo.MongodExecutable Java Examples

The following examples show how to use de.flapdoodle.embed.mongo.MongodExecutable. 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: 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 #2
Source File: EmbeddedClient.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    final IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION).build();

    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaultsWithLogger(Command.MongoD, logger)
            .processOutput(ProcessOutput.getDefaultInstanceSilent())
            .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

    MongodExecutable mongodExecutable = runtime.prepare(mongodConfig);
    mongod = mongodExecutable.start();

    // cluster configuration
    ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(mongodConfig.net().getServerAddress().getHostName(), mongodConfig.net().getPort()))).build();
    // codec configuration
    CodecRegistry pojoCodecRegistry = fromRegistries(MongoClients.getDefaultCodecRegistry(),
            fromProviders(PojoCodecProvider.builder().automatic(true).build()));

    MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).codecRegistry(pojoCodecRegistry).writeConcern(WriteConcern.ACKNOWLEDGED).build();
    mongoClient = MongoClients.create(settings);
    mongoDatabase = mongoClient.getDatabase(databaseName);
}
 
Example #3
Source File: EmbeddedClient.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {

    final IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION).build();

    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
            .defaultsWithLogger(Command.MongoD, logger)
            .processOutput(ProcessOutput.getDefaultInstanceSilent())
            .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

    MongodExecutable mongodExecutable = runtime.prepare(mongodConfig);
    mongod = mongodExecutable.start();

    // cluster configuration
    ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(mongodConfig.net().getServerAddress().getHostName(), mongodConfig.net().getPort()))).build();
    // codec configuration
    CodecRegistry pojoCodecRegistry = fromRegistries(MongoClients.getDefaultCodecRegistry(),
            fromProviders(PojoCodecProvider.builder().automatic(true).build()));

    MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).codecRegistry(pojoCodecRegistry).writeConcern(WriteConcern.ACKNOWLEDGED).build();
    mongoClient = MongoClients.create(settings);
    mongoDatabase = mongoClient.getDatabase(databaseName);
}
 
Example #4
Source File: MongoTestBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static MongodExecutable getMongodExecutable(IMongodConfig config) {
    try {
        return doGetExecutable(config);
    } catch (Exception e) {
        // sometimes the download process can timeout so just sleep and try again
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignored) {

        }
        return doGetExecutable(config);
    }
}
 
Example #5
Source File: MongodManager.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #6
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 #7
Source File: MongoDbResource.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private static MongodProcess tryToStartMongoDb(final MongodExecutable mongodExecutable) {
    try {
        return mongodExecutable.start();
    } catch (final IOException e) {
        throw new IllegalStateException("Failed to start MongoDB!", e);
    }
}
 
Example #8
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 #9
Source File: MongoDbResource.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private static MongodExecutable tryToConfigureMongoDb(final String bindIp,
        final int mongoDbPort,
        final IProxyFactory proxyFactory,
        final Logger logger) {

    try {
        return configureMongoDb(bindIp, mongoDbPort, proxyFactory, logger);
    } catch (final Throwable e) {
        return null;
    }
}
 
Example #10
Source File: TracingMongoClientPostProcessorTest.java    From java-spring-cloud with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws IOException {
  processor = new TracingMongoClientPostProcessor(tracer);

  MongodStarter starter = MongodStarter.getDefaultInstance();
  MongodExecutable executable = starter.prepare(new MongodConfigBuilder()
      .version(Version.Main.PRODUCTION)
      .net(new Net(27017, Network.localhostIsIPv6()))
      .build());
  process = executable.start();
}
 
Example #11
Source File: EmbedMongoConfiguration.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static void startEmbeddedMongo() {
    final IStreamProcessor logDestination = new Slf4jStreamProcessor(LoggerFactory.getLogger("embeddeddmongo"), Slf4jLevel.INFO);
    final IStreamProcessor daemon = Processors.named("mongod", logDestination);
    final IStreamProcessor error = Processors.named("mongod-error", logDestination);
    final IStreamProcessor command = Processors.named("mongod-command", logDestination);
    final ProcessOutput processOutput = new ProcessOutput(daemon, error, command);
    final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
        .defaults(Command.MongoD)
        .artifactStore(new ExtractedArtifactStoreBuilder()
            .defaults(Command.MongoD)
            .extractDir(new FixedPath(".extracted"))
            .download(new DownloadConfigBuilder()
                .defaultsForCommand(Command.MongoD)
                .artifactStorePath(new FixedPath(".cache"))
                .build())
            .build())
        .processOutput(processOutput)
        .build();

    try {
        final IMongodConfig mongodConfig = createEmbeddedMongoConfiguration();

        final MongodExecutable mongodExecutable = MongodStarter.getInstance(runtimeConfig)
            .prepare(mongodConfig);


        mongodExecutable.start();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #12
Source File: ExampleMongoConfiguration.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
@Bean
public MongoClient mongoClient(final MongoProperties mongoProperties) throws IOException {
    String bindIp = mongoProperties.getHost()[0];
    int port = Network.getFreeServerPort();
    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 mongodExecutable = runtime.prepare(mongodConfig, Distribution.detectFor(Version.Main.PRODUCTION));
    mongodExecutable.start();
    return new MongoClient(bindIp, port);
}
 
Example #13
Source File: MongoWithReplicasTestBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static MongodExecutable getMongodExecutable(IMongodConfig config) {
    try {
        return doGetExecutable(config);
    } catch (Exception e) {
        // sometimes the download process can timeout so just sleep and try again
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignored) {

        }
        return doGetExecutable(config);
    }
}
 
Example #14
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 #15
Source File: MongosSystemForTestFactory.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
private void initializeConfigServer(IMongodConfig config) throws Exception {
	if (!config.isConfigServer()) {
		throw new Exception(
				"Mongo configuration is not a defined for a config server.");
	}
	MongodStarter starter = MongodStarter.getDefaultInstance();
	MongodExecutable mongodExe = starter.prepare(config);
	MongodProcess process = mongodExe.start();
	mongodProcessList.add(process);
}
 
Example #16
Source File: MongoWithReplicasTestBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static MongodExecutable getMongodExecutable(IMongodConfig config) {
    try {
        return doGetExecutable(config);
    } catch (Exception e) {
        // sometimes the download process can timeout so just sleep and try again
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignored) {

        }
        return doGetExecutable(config);
    }
}
 
Example #17
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 #18
Source File: MongoTestBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static MongodExecutable getMongodExecutable(IMongodConfig config) {
    try {
        return doGetExecutable(config);
    } catch (Exception e) {
        // sometimes the download process can timeout so just sleep and try again
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignored) {

        }
        return doGetExecutable(config);
    }
}
 
Example #19
Source File: MongoTestResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private MongodExecutable getMongodExecutable(IMongodConfig config) {
    try {
        return doGetExecutable(config);
    } catch (Exception e) {
        // sometimes the download process can timeout so just sleep and try again
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignored) {

        }
        return doGetExecutable(config);
    }
}
 
Example #20
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;
}
 
Example #21
Source File: MongoTestResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private MongodExecutable getMongodExecutable(IMongodConfig config) {
    try {
        return doGetExecutable(config);
    } catch (Exception e) {
        // sometimes the download process can timeout so just sleep and try again
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignored) {

        }
        return doGetExecutable(config);
    }
}
 
Example #22
Source File: WithEmbeddedMongo.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@BeforeClass
static void setUpMongo() throws IOException {
    MongodStarter starter = MongodStarter.getDefaultInstance();

    String bindIp = "localhost";
    int port = 27017;
    IMongodConfig mongodConfig = new MongodConfigBuilder()
            .version(Version.Main.DEVELOPMENT)
            .net(new Net(bindIp, port, Network.localhostIsIPv6()))
            .build();

    MongodExecutable mongodExecutable = starter.prepare(mongodConfig);
    MONGO_HOLDER.set(mongodExecutable);
    mongodExecutable.start();
}
 
Example #23
Source File: Helpers.java    From entref-spring-boot with MIT License 5 votes vote down vote up
/**
 * Setup a mongo instance
 * @param net the net instance to bind to
 * @return the mongo instance
 * @throws IOException thrown when unable to bind
 */
static MongodExecutable SetupMongo(Net net) throws IOException {
    MongodStarter starter = MongodStarter.getDefaultInstance();

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

    MongodExecutable mongoProc = starter.prepare(mongodConfig);
    mongoProc.start();

    return mongoProc;
}
 
Example #24
Source File: PropertyMockingApplicationContextInitializer.java    From entref-spring-boot with MIT License 5 votes vote down vote up
/**
 * Get the embedded mongo server instance
 * @param bind the net binding information to bind to
 * @return the embedded mongo server instance
 */
protected MongodExecutable getMongo(Net bind) {
    try {
        return Helpers.SetupMongo(bind);
    } catch (IOException e) {
        return null;
    }
}
 
Example #25
Source File: MongoDb3TestRule.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public MongodExecutable getMongodExecutable() {
    return mongodExecutable;
}
 
Example #26
Source File: MongoDb4TestRule.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public MongodExecutable getMongodExecutable() {
    return mongodExecutable;
}
 
Example #27
Source File: Environment.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
static MongodExecutable prepareMongod(IMongodConfig config) {
  return INSTANCE.mongodStarter.prepare(config);
}
 
Example #28
Source File: MongoWithReplicasTestBase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static MongodExecutable doGetExecutable(IMongodConfig config) {
    return MongodStarter.getDefaultInstance().prepare(config);
}
 
Example #29
Source File: MongoTestBase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static MongodExecutable doGetExecutable(IMongodConfig config) {
    return MongodStarter.getDefaultInstance().prepare(config);
}
 
Example #30
Source File: MongoWithReplicasTestBase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static MongodExecutable doGetExecutable(IMongodConfig config) {
    return MongodStarter.getDefaultInstance().prepare(config);
}