use of de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder in project beam by apache.
the class MongoDBGridFSIOTest method setup.
@BeforeClass
public static void setup() throws Exception {
try (ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
LOG.info("Starting MongoDB embedded instance on {}", port);
try {
Files.forceDelete(new File(MONGODB_LOCATION));
} catch (Exception e) {
}
new File(MONGODB_LOCATION).mkdirs();
IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION).configServer(false).replication(new Storage(MONGODB_LOCATION, null, 0)).net(new Net("localhost", port, Network.localhostIsIPv6())).cmdOptions(new MongoCmdOptionsBuilder().syncDelay(10).useNoPrealloc(true).useSmallFiles(true).useNoJournal(true).build()).build();
mongodExecutable = mongodStarter.prepare(mongodConfig);
mongodProcess = mongodExecutable.start();
LOG.info("Insert test data");
Mongo client = new Mongo("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());
}
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);
for (int y = 0; y < 5000; y++) {
long time = now - random.nextInt(3600000);
String name = scientists[y % scientists.length];
writer.write(Long.toString(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(Long.toString(now) + "\t");
writer.write(name + "\t");
writer.write("101");
writer.write("\n");
}
writer.flush();
writer.close();
}
client.close();
}
use of de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder in project beam by apache.
the class MongoDbIOTest method setup.
@Before
public void setup() throws Exception {
LOG.info("Starting MongoDB embedded instance on {}", port);
try {
Files.forceDelete(new File(MONGODB_LOCATION));
} catch (Exception e) {
}
new File(MONGODB_LOCATION).mkdirs();
IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION).configServer(false).replication(new Storage(MONGODB_LOCATION, null, 0)).net(new Net("localhost", port, Network.localhostIsIPv6())).cmdOptions(new MongoCmdOptionsBuilder().syncDelay(10).useNoPrealloc(true).useSmallFiles(true).useNoJournal(true).build()).build();
mongodExecutable = mongodStarter.prepare(mongodConfig);
mongodProcess = mongodExecutable.start();
LOG.info("Insert test data");
MongoClient client = new MongoClient("localhost", port);
MongoDatabase database = client.getDatabase(DATABASE);
MongoCollection collection = database.getCollection(COLLECTION);
String[] scientists = { "Einstein", "Darwin", "Copernicus", "Pasteur", "Curie", "Faraday", "Newton", "Bohr", "Galilei", "Maxwell" };
for (int i = 1; i <= 1000; i++) {
int index = i % scientists.length;
Document document = new Document();
document.append("_id", i);
document.append("scientist", scientists[index]);
collection.insertOne(document);
}
}
use of de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder in project embedmongo-maven-plugin by joelittlejohn.
the class StartMojo method executeStart.
@Override
@SuppressWarnings("unchecked")
public void executeStart() throws MojoExecutionException, MojoFailureException {
MongodExecutable executable;
try {
final List<String> mongodArgs = this.createMongodArgsList();
final ICommandLinePostProcessor commandLinePostProcessor = new ICommandLinePostProcessor() {
@Override
public List<String> process(final Distribution distribution, final List<String> args) {
args.addAll(mongodArgs);
return args;
}
};
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.MongoD).processOutput(getOutputConfig()).artifactStore(getArtifactStore()).commandLinePostProcessor(commandLinePostProcessor).build();
int port = getPort();
if (isRandomPort()) {
port = NetworkUtils.allocateRandomPort();
}
savePortToProjectProperties(port);
IMongodConfig config = new MongodConfigBuilder().version(getVersion()).net(new Net(bindIp, port, NetworkUtils.localhostIsIPv6())).replication(new Storage(getDataDirectory(), null, 0)).cmdOptions(new MongoCmdOptionsBuilder().enableAuth(authEnabled).useNoJournal(!journal).useStorageEngine(storageEngine).build()).build();
executable = MongodStarter.getInstance(runtimeConfig).prepare(config);
} catch (DistributionException e) {
throw new MojoExecutionException("Failed to download MongoDB distribution: " + e.withDistribution(), e);
} catch (IOException e) {
throw new MojoExecutionException("Unable to Config MongoDB: ", e);
}
try {
MongodProcess mongod = executable.start();
if (isWait()) {
while (true) {
try {
TimeUnit.MINUTES.sleep(5);
} catch (InterruptedException e) {
break;
}
}
}
getPluginContext().put(MONGOD_CONTEXT_PROPERTY_NAME, mongod);
} catch (IOException e) {
throw new MojoExecutionException("Unable to start the mongod", e);
}
}
use of de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder 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);
}
use of de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder 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();
}
Aggregations