Search in sources :

Example 16 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project vertx-auth by vert-x3.

the class MongoBaseTest method startMongo.

@BeforeClass
public static void startMongo() throws Exception {
    if (getConnectionString() == null) {
        IMongodConfig config = new MongodConfigBuilder().version(Version.Main.PRODUCTION).net(new Net(27018, Network.localhostIsIPv6())).build();
        exe = MongodStarter.getDefaultInstance().prepare(config);
        exe.start();
    }
}
Also used : IMongodConfig(de.flapdoodle.embed.mongo.config.IMongodConfig) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder) BeforeClass(org.junit.BeforeClass)

Example 17 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project beam by apache.

the class MongoDbReadWriteIT method setUp.

@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);
}
Also used : MongoClient(com.mongodb.MongoClient) Storage(de.flapdoodle.embed.mongo.config.Storage) IMongodConfig(de.flapdoodle.embed.mongo.config.IMongodConfig) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder) MongoCmdOptionsBuilder(de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder) BeforeClass(org.junit.BeforeClass)

Example 18 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project beam by apache.

the class MongoDBGridFSIOTest method start.

@BeforeClass
public static void start() 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();
    LOG.info("Insert test data");
    MongoClient client = new MongoClient("localhost", port);
    DB database = client.getDB(DATABASE);
    GridFS gridfs = new GridFS(database);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    for (int x = 0; x < 100; x++) {
        out.write(("Einstein\nDarwin\nCopernicus\nPasteur\n" + "Curie\nFaraday\nNewton\nBohr\nGalilei\nMaxwell\n").getBytes(StandardCharsets.UTF_8));
    }
    for (int x = 0; x < 5; x++) {
        gridfs.createFile(new ByteArrayInputStream(out.toByteArray()), "file" + x).save();
    }
    gridfs = new GridFS(database, "mapBucket");
    long now = System.currentTimeMillis();
    Random random = new Random();
    String[] scientists = { "Einstein", "Darwin", "Copernicus", "Pasteur", "Curie", "Faraday", "Newton", "Bohr", "Galilei", "Maxwell" };
    for (int x = 0; x < 10; x++) {
        GridFSInputFile file = gridfs.createFile("file_" + x);
        OutputStream outf = file.getOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(outf, StandardCharsets.UTF_8);
        for (int y = 0; y < 5000; y++) {
            long time = now - random.nextInt(3600000);
            String name = scientists[y % scientists.length];
            writer.write(time + "\t");
            writer.write(name + "\t");
            writer.write(Integer.toString(random.nextInt(100)));
            writer.write("\n");
        }
        for (int y = 0; y < scientists.length; y++) {
            String name = scientists[y % scientists.length];
            writer.write(now + "\t");
            writer.write(name + "\t");
            writer.write("101");
            writer.write("\n");
        }
        writer.flush();
        writer.close();
    }
    client.close();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GridFS(com.mongodb.gridfs.GridFS) MongoClient(com.mongodb.MongoClient) GridFSInputFile(com.mongodb.gridfs.GridFSInputFile) Storage(de.flapdoodle.embed.mongo.config.Storage) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) IMongodConfig(de.flapdoodle.embed.mongo.config.IMongodConfig) OutputStreamWriter(java.io.OutputStreamWriter) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder) MongoCmdOptionsBuilder(de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder) DB(com.mongodb.DB) BeforeClass(org.junit.BeforeClass)

Example 19 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project beam by apache.

the class MongoDbIOTest method beforeClass.

@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, false);
    MongoCollection<Document> collection = getCollection(COLLECTION);
    collection.insertMany(documents);
}
Also used : MongoClient(com.mongodb.MongoClient) Storage(de.flapdoodle.embed.mongo.config.Storage) IMongodConfig(de.flapdoodle.embed.mongo.config.IMongodConfig) Net(de.flapdoodle.embed.mongo.config.Net) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder) MongoCmdOptionsBuilder(de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder) BeforeClass(org.junit.BeforeClass)

Aggregations

MongodConfigBuilder (de.flapdoodle.embed.mongo.config.MongodConfigBuilder)19 Net (de.flapdoodle.embed.mongo.config.Net)19 IMongodConfig (de.flapdoodle.embed.mongo.config.IMongodConfig)14 MongoClient (com.mongodb.MongoClient)8 Storage (de.flapdoodle.embed.mongo.config.Storage)7 MongoCmdOptionsBuilder (de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder)6 MongodStarter (de.flapdoodle.embed.mongo.MongodStarter)5 IOException (java.io.IOException)5 BeforeClass (org.junit.BeforeClass)5 Document (org.bson.Document)3 Before (org.junit.Before)3 DB (com.mongodb.DB)2 MongoDatabase (com.mongodb.client.MongoDatabase)2 GridFS (com.mongodb.gridfs.GridFS)2 GridFSInputFile (com.mongodb.gridfs.GridFSInputFile)2 MongodExecutable (de.flapdoodle.embed.mongo.MongodExecutable)2 RuntimeConfigBuilder (de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)2 Timeout (de.flapdoodle.embed.mongo.config.Timeout)2 IRuntimeConfig (de.flapdoodle.embed.process.config.IRuntimeConfig)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2