Search in sources :

Example 1 with Timeout

use of de.flapdoodle.embed.mongo.config.Timeout in project logging-log4j2 by apache.

the class MongoDb3TestRule method apply.

@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);
            try {
                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
            } catch (final IllegalArgumentException e) {
                if (e.getMessage().contains("this version does not support 32Bit")) {
                    throw new AssumptionViolatedException("Unsupported platform: " + e.getMessage());
                }
            }
            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;
                }
            }
        }
    };
}
Also used : MongoClient(com.mongodb.MongoClient) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) Timeout(de.flapdoodle.embed.mongo.config.Timeout) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder)

Example 2 with Timeout

use of de.flapdoodle.embed.mongo.config.Timeout in project logging-log4j2 by apache.

the class MongoDb4TestRule method apply.

@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);
            try {
                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
            } catch (final IllegalArgumentException e) {
                if (e.getMessage().contains("this version does not support 32Bit")) {
                    throw new AssumptionViolatedException("Unsupported platform: " + e.getMessage());
                }
            }
            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;
                }
            }
        }
    };
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) Timeout(de.flapdoodle.embed.mongo.config.Timeout) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder)

Example 3 with Timeout

use of de.flapdoodle.embed.mongo.config.Timeout in project embedmongo-maven-plugin by joelittlejohn.

the class MongoImportMojo method sendImportScript.

private void sendImportScript() throws IOException, InterruptedException, MojoExecutionException {
    List<MongoImportProcess> pendingMongoProcess = new ArrayList<MongoImportProcess>();
    if (imports == null || imports.length == 0) {
        getLog().error("No imports found, check your configuration");
        return;
    }
    getLog().info("Default import database: " + defaultImportDatabase);
    for (ImportDataConfig importData : imports) {
        getLog().info("Import " + importData);
        verify(importData);
        String database = importData.getDatabase();
        if (StringUtils.isBlank(database)) {
            database = defaultImportDatabase;
        }
        IMongoImportConfig mongoImportConfig = new MongoImportConfigBuilder().version(getVersion()).net(new Net(getPort(), NetworkUtils.localhostIsIPv6())).db(database).collection(importData.getCollection()).upsert(importData.getUpsertOnImport()).dropCollection(importData.getDropOnImport()).importFile(importData.getFile()).jsonArray(true).timeout(new Timeout(importData.getTimeout())).build();
        MongoImportExecutable mongoImport = MongoImportStarter.getDefaultInstance().prepare(mongoImportConfig);
        MongoImportProcess importProcess = mongoImport.start();
        if (parallel) {
            pendingMongoProcess.add(importProcess);
        } else {
            waitFor(importProcess);
        }
    }
    for (MongoImportProcess importProcess : pendingMongoProcess) {
        waitFor(importProcess);
    }
}
Also used : MongoImportProcess(de.flapdoodle.embed.mongo.MongoImportProcess) IMongoImportConfig(de.flapdoodle.embed.mongo.config.IMongoImportConfig) Timeout(de.flapdoodle.embed.mongo.config.Timeout) ArrayList(java.util.ArrayList) Net(de.flapdoodle.embed.mongo.config.Net) MongoImportConfigBuilder(de.flapdoodle.embed.mongo.config.MongoImportConfigBuilder) MongoImportExecutable(de.flapdoodle.embed.mongo.MongoImportExecutable)

Aggregations

Net (de.flapdoodle.embed.mongo.config.Net)3 Timeout (de.flapdoodle.embed.mongo.config.Timeout)3 MongodConfigBuilder (de.flapdoodle.embed.mongo.config.MongodConfigBuilder)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 Statement (org.junit.runners.model.Statement)2 MongoClient (com.mongodb.MongoClient)1 MongoImportExecutable (de.flapdoodle.embed.mongo.MongoImportExecutable)1 MongoImportProcess (de.flapdoodle.embed.mongo.MongoImportProcess)1 IMongoImportConfig (de.flapdoodle.embed.mongo.config.IMongoImportConfig)1 MongoImportConfigBuilder (de.flapdoodle.embed.mongo.config.MongoImportConfigBuilder)1 ArrayList (java.util.ArrayList)1