Search in sources :

Example 6 with CreateCollectionOptions

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);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CreateCollectionOptions(com.mongodb.client.model.CreateCollectionOptions) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 7 with CreateCollectionOptions

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");
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CreateCollectionOptions(com.mongodb.client.model.CreateCollectionOptions) Test(org.junit.Test)

Example 8 with CreateCollectionOptions

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");
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CreateCollectionOptions(com.mongodb.client.model.CreateCollectionOptions) Document(org.bson.Document) Test(org.junit.Test)

Example 9 with CreateCollectionOptions

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);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CreateCollectionOptions(com.mongodb.client.model.CreateCollectionOptions) Document(org.bson.Document) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 10 with CreateCollectionOptions

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");
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CreateCollectionOptions(com.mongodb.client.model.CreateCollectionOptions) Document(org.bson.Document) Test(org.junit.Test)

Aggregations

CreateCollectionOptions (com.mongodb.client.model.CreateCollectionOptions)22 Test (org.junit.Test)17 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 Document (org.bson.Document)12 BasicDBObject (com.mongodb.BasicDBObject)8 MongoDatabase (com.mongodb.client.MongoDatabase)4 ValidationOptions (com.mongodb.client.model.ValidationOptions)4 DBObject (com.mongodb.DBObject)3 Ignore (org.junit.Ignore)3 MongoCommandException (com.mongodb.MongoCommandException)2 Calendar (java.util.Calendar)2 CommandResult (com.mongodb.CommandResult)1 MongoClient (com.mongodb.MongoClient)1 MongoClientURI (com.mongodb.MongoClientURI)1 TextSearchOptions (com.mongodb.client.model.TextSearchOptions)1 Date (java.util.Date)1 Bson (org.bson.conversions.Bson)1 Book (org.mongodb.morphia.aggregation.AggregationTest.Book)1 CountResult (org.mongodb.morphia.aggregation.AggregationTest.CountResult)1