use of com.mongodb.client.model.CreateCollectionOptions in project camel by apache.
the class MongoDbTailableCursorConsumerTest method testThousandRecordsWithRouteId.
private void testThousandRecordsWithRouteId(String routeId) throws Exception {
assertEquals(0, cappedTestCollection.count());
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedMessageCount(1000);
// create a capped collection with max = 1000
//BasicDBObjectBuilder.start().add("capped", true).add("size", 1000000000).add("max", 1000).get()
db.createCollection(cappedTestCollectionName, new CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(1000));
cappedTestCollection = db.getCollection(cappedTestCollectionName, BasicDBObject.class);
for (int i = 0; i < 1000; i++) {
cappedTestCollection.insertOne(new BasicDBObject("increasing", i).append("string", "value" + i));
}
assertEquals(1000, cappedTestCollection.count());
addTestRoutes();
context.startRoute(routeId);
Thread.sleep(1000);
mock.assertIsSatisfied();
context.stopRoute(routeId);
}
use of com.mongodb.client.model.CreateCollectionOptions in project camel by apache.
the class MongoDbTailableCursorConsumerTest method testMultipleBursts.
@Test
public void testMultipleBursts() throws Exception {
assertEquals(0, cappedTestCollection.count());
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedMessageCount(5000);
//BasicDBObjectBuilder.start().add("capped", true).add("size", 1000000000).add("max", 1000).get()
// create a capped collection with max = 1000
CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(1000);
db.createCollection(cappedTestCollectionName, createCollectionOptions);
cappedTestCollection = db.getCollection(cappedTestCollectionName, BasicDBObject.class);
addTestRoutes();
context.startRoute("tailableCursorConsumer1");
// pump 5 bursts of 1000 records each with 500ms pause between burst and burst
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5000; i++) {
if (i % 1000 == 0) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
return;
}
}
cappedTestCollection.insertOne(new BasicDBObject("increasing", i).append("string", "value" + i));
}
}
});
// start the data pumping
t.start();
// before we assert, wait for the data pumping to end
t.join();
mock.assertIsSatisfied();
context.stopRoute("tailableCursorConsumer1");
}
use of com.mongodb.client.model.CreateCollectionOptions in project camel by apache.
the class MongoDbTailableCursorConsumerTest method testNoRecords.
@Test
public void testNoRecords() throws Exception {
assertEquals(0, cappedTestCollection.count());
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedMessageCount(0);
// DocumentBuilder.start().add("capped", true).add("size",
// 1000000000).add("max", 1000).get()
// create a capped collection with max = 1000
CreateCollectionOptions collectionOptions = new CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(1000);
db.createCollection(cappedTestCollectionName, collectionOptions);
cappedTestCollection = db.getCollection(cappedTestCollectionName, Document.class);
assertEquals(0, cappedTestCollection.count());
addTestRoutes();
context.startRoute("tailableCursorConsumer1");
Thread.sleep(1000);
mock.assertIsSatisfied();
context.stopRoute("tailableCursorConsumer1");
}
use of com.mongodb.client.model.CreateCollectionOptions in project camel by apache.
the class MongoDbTailableCursorConsumerTest method testThousandRecordsWithRouteId.
private void testThousandRecordsWithRouteId(String routeId) throws Exception {
assertEquals(0, cappedTestCollection.count());
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedMessageCount(1000);
// create a capped collection with max = 1000
// DocumentBuilder.start().add("capped", true).add("size",
// 1000000000).add("max", 1000).get()
db.createCollection(cappedTestCollectionName, new CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(1000));
cappedTestCollection = db.getCollection(cappedTestCollectionName, Document.class);
for (int i = 0; i < 1000; i++) {
cappedTestCollection.insertOne(new Document("increasing", i).append("string", "value" + i));
}
assertEquals(1000, cappedTestCollection.count());
addTestRoutes();
context.startRoute(routeId);
Thread.sleep(1000);
mock.assertIsSatisfied();
context.stopRoute(routeId);
}
use of com.mongodb.client.model.CreateCollectionOptions in project camel by apache.
the class MongoDbTailableCursorConsumerTest method testMultipleBursts.
@Test
public void testMultipleBursts() throws Exception {
assertEquals(0, cappedTestCollection.count());
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedMessageCount(5000);
// DocumentBuilder.start().add("capped", true).add("size",
// 1000000000).add("max", 1000).get()
// create a capped collection with max = 1000
CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(1000);
db.createCollection(cappedTestCollectionName, createCollectionOptions);
cappedTestCollection = db.getCollection(cappedTestCollectionName, Document.class);
addTestRoutes();
context.startRoute("tailableCursorConsumer1");
// pump 5 bursts of 1000 records each with 500ms pause between burst and
// burst
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5000; i++) {
if (i % 1000 == 0) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
return;
}
}
cappedTestCollection.insertOne(new Document("increasing", i).append("string", "value" + i));
}
}
});
// start the data pumping
t.start();
// before we assert, wait for the data pumping to end
t.join();
mock.assertIsSatisfied();
context.stopRoute("tailableCursorConsumer1");
}
Aggregations