You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/06/03 08:01:46 UTC

[5/8] camel git commit: CAMEL-8668: Partly cleaned up

CAMEL-8668: Partly cleaned up


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dfbab447
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dfbab447
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dfbab447

Branch: refs/heads/master
Commit: dfbab4478acfda03d002080e44824323c5b48c0f
Parents: de1fa97
Author: Arno Noordover <an...@users.noreply.github.com>
Authored: Wed Jun 1 21:07:59 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jun 3 09:57:00 2016 +0200

----------------------------------------------------------------------
 .../camel-mongodb/src/main/docs/mongodb.adoc    |   4 +-
 .../component/mongodb/MongoDbEndpoint.java      |  11 +-
 .../component/mongodb/MongoDbProducer.java      | 162 ++++++++-----------
 .../mongodb/MongoDbOperationsTest.java          |   1 +
 .../MongoDbTailableCursorConsumerTest.java      |  21 ++-
 5 files changed, 84 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dfbab447/components/camel-mongodb/src/main/docs/mongodb.adoc
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/docs/mongodb.adoc b/components/camel-mongodb/src/main/docs/mongodb.adoc
index bd31941..c5dcea2 100644
--- a/components/camel-mongodb/src/main/docs/mongodb.adoc
+++ b/components/camel-mongodb/src/main/docs/mongodb.adoc
@@ -64,6 +64,7 @@ The MongoDB component has no options.
 
 
 
+
 // endpoint options: START
 The MongoDB component supports 22 endpoint options which are listed below:
 
@@ -78,7 +79,7 @@ The MongoDB component supports 22 endpoint options which are listed below:
 | database | common |  | String | Sets the name of the MongoDB database to target
 | operation | common |  | MongoDbOperation | Sets the operation this endpoint will execute against MongoDB. For possible values see MongoDbOperation.
 | outputType | common |  | MongoDbOutputType | Convert the output of the producer to the selected type : DBObjectList DBObject or DBCursor. DBObjectList or DBObject applies to findAll. DBCursor applies to all other operations.
-| writeConcern | common |  | WriteConcern | Set the WriteConcern for write operations on MongoDB using the standard ones. Resolved from the fields of the WriteConcern class by calling the link WriteConcernvalueOf(String) method.
+| writeConcern | common | ACKNOWLEDGED | WriteConcern | Set the WriteConcern for write operations on MongoDB using the standard ones. Resolved from the fields of the WriteConcern class by calling the link WriteConcernvalueOf(String) method.
 | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
 | exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
 | cursorRegenerationDelay | advanced | 1000 | long | MongoDB tailable cursors will block until new data arrives. If no new data is inserted after some time the cursor will be automatically freed and closed by the MongoDB server. The client is expected to regenerate the cursor if needed. This value specifies the time to wait before attempting to fetch a new cursor and if the attempt fails how long before the next attempt is made. Default value is 1000ms.
@@ -101,6 +102,7 @@ The MongoDB component supports 22 endpoint options which are listed below:
 
 
 
+
 [[MongoDB-ConfigurationofdatabaseinSpringXML]]
 Configuration of database in Spring XML
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

http://git-wip-us.apache.org/repos/asf/camel/blob/dfbab447/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
index 74a89c9..6219c1c 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbEndpoint.java
@@ -24,8 +24,6 @@ import java.util.stream.StreamSupport;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.mongodb.BasicDBObject;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
 import com.mongodb.DBObject;
 import com.mongodb.MongoClient;
 import com.mongodb.ReadPreference;
@@ -70,8 +68,8 @@ public class MongoDbEndpoint extends DefaultEndpoint {
     private MongoDbOperation operation;
     @UriParam(defaultValue = "true")
     private boolean createCollection = true;
-    @UriParam(enums = "ACKNOWLEDGED,W1,W2,W3,UNACKNOWLEDGED,JOURNALED,MAJORITY,SAFE")
-    private WriteConcern writeConcern;
+    @UriParam(defaultValue = "ACKNOWLEDGED", enums = "ACKNOWLEDGED,W1,W2,W3,UNACKNOWLEDGED,JOURNALED,MAJORITY,SAFE")
+    private WriteConcern writeConcern = WriteConcern.ACKNOWLEDGED;
     private WriteConcern writeConcernRef;
     @UriParam(label = "advanced")
     private ReadPreference readPreference;
@@ -175,9 +173,8 @@ public class MongoDbEndpoint extends DefaultEndpoint {
                 throw new IllegalArgumentException("consumerType, tailTracking, cursorRegenerationDelay options cannot appear on a producer endpoint");
             }
         } else if (role == 'C') {
-            if (!ObjectHelper.isEmpty(operation) || !ObjectHelper.isEmpty(writeConcern) || writeConcernRef != null
-                   || dynamicity || outputType != null) {
-                throw new IllegalArgumentException("operation, writeConcern, writeConcernRef, dynamicity, outputType "
+            if (!ObjectHelper.isEmpty(operation) || dynamicity || outputType != null) {
+                throw new IllegalArgumentException("operation, dynamicity, outputType "
                         + "options cannot appear on a consumer endpoint");
             }
             if (consumerType == MongoDbConsumerType.tailable) {

http://git-wip-us.apache.org/repos/asf/camel/blob/dfbab447/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
index 406e6f1..6ef3415 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbProducer.java
@@ -23,7 +23,6 @@ import java.util.List;
 import com.mongodb.BasicDBList;
 import com.mongodb.BasicDBObject;
 import com.mongodb.DBObject;
-import com.mongodb.WriteConcern;
 import com.mongodb.client.AggregateIterable;
 import com.mongodb.client.FindIterable;
 import com.mongodb.client.MongoCollection;
@@ -33,7 +32,6 @@ import com.mongodb.client.result.DeleteResult;
 import com.mongodb.client.result.UpdateResult;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.MessageHelper;
@@ -142,21 +140,21 @@ public class MongoDbProducer extends DefaultProducer {
 
     // ----------- MongoDB operations ----------------
 
+    //returns result in body
     protected void doCommand(Exchange exchange) throws Exception {
         Document result;
         MongoDatabase db = calculateDb(exchange);
         BasicDBObject cmdObj = exchange.getIn().getMandatoryBody(BasicDBObject.class);
 
-        //TODO Manage the read preference
         result = db.runCommand(cmdObj);
 
-
-        Message responseMessage = prepareResponseMessage(exchange, MongoDbOperation.command);
-        responseMessage.setBody(result);
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.command);
+        processAndTransferResult(result, exchange, MongoDbOperation.command);
     }
 
     protected void doGetStats(Exchange exchange, MongoDbOperation operation) throws Exception {
-        Document result = null;
+        Document result;
 
         if (operation == MongoDbOperation.getColStats) {
             result = calculateDb(exchange).runCommand(createCollStatsCommand(calculateCollectionName(exchange)));
@@ -167,8 +165,9 @@ public class MongoDbProducer extends DefaultProducer {
             throw new CamelMongoDbException("Internal error: wrong operation for getStats variant" + operation);
         }
 
-        Message responseMessage = prepareResponseMessage(exchange, operation);
-        responseMessage.setBody(result);
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, operation);
+        processAndTransferResult(result, exchange, operation);
     }
 
     private BasicDBObject createDbStatsCommand() {
@@ -185,11 +184,9 @@ public class MongoDbProducer extends DefaultProducer {
 
         DeleteResult result = dbCol.deleteMany(removeObj);
 
-        Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.remove);
-        // we always return the WriteResult, because whether the getLastError was called or not,
-        // the user will have the means to call it or obtain the cached CommandResult
-        processAndTransferDeleteResult(result, exchange);
-        resultMessage.setHeader(MongoDbConstants.RECORDS_AFFECTED, result.getDeletedCount());
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.remove);
+        processAndTransferResult(result, exchange, MongoDbOperation.remove);
     }
 
     @SuppressWarnings("unchecked")
@@ -207,7 +204,6 @@ public class MongoDbProducer extends DefaultProducer {
         Boolean upsert = exchange.getIn().getHeader(MongoDbConstants.UPSERT, Boolean.class);
 
         UpdateResult result;
-        WriteConcern wc = extractWriteConcern(exchange);
         // In API 2.7, the default upsert and multi values of update(DBObject, DBObject) are false, false, so we unconditionally invoke the
         // full-signature method update(DBObject, DBObject, boolean, boolean). However, the default behaviour may change in the future, 
         // so it's safer to be explicit at this level for full determinism
@@ -227,11 +223,9 @@ public class MongoDbProducer extends DefaultProducer {
             result = dbCol.updateOne(updateCriteria, objNew, options);
         }
 
-        Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.update);
-        // we always return the WriteResult, because whether the getLastError was called or not, the user will have the means to call it or 
-        // obtain the cached CommandResult
-        processAndTransferUpdateResult(result, exchange);
-        resultMessage.setHeader(MongoDbConstants.RECORDS_AFFECTED, result.getModifiedCount());
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.update);
+        processAndTransferResult(result, exchange, MongoDbOperation.update);
     }
 
     /**
@@ -249,21 +243,9 @@ public class MongoDbProducer extends DefaultProducer {
         UpdateResult result = dbCol.replaceOne(queryObject, saveObj, options);
         exchange.getIn().setHeader(MongoDbConstants.OID, saveObj.get("_id"));
 
-        prepareResponseMessage(exchange, MongoDbOperation.save);
-        //TODO: insertOne doesn't return a WriteResult
-        // we always return the WriteResult, because whether the getLastError was called or not, the user will have the means to call it or 
-        // obtain the cached CommandResult
-        processAndTransferUpdateResult(result, exchange);
-    }
-
-    private void processAndTransferResult(Object result, Exchange exchange) {
-        // determine where to set the WriteResult: as the OUT body or as an IN message header
-        if (endpoint.isWriteResultAsHeader()) {
-            exchange.getOut().setHeader(MongoDbConstants.WRITERESULT, result);
-        } else {
-            exchange.getOut().setBody(result);
-        }
-
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.save);
+        processAndTransferResult(result, exchange, MongoDbOperation.save);
     }
 
     protected void doFindById(Exchange exchange) throws Exception {
@@ -279,9 +261,11 @@ public class MongoDbProducer extends DefaultProducer {
             ret = dbCol.find(o).filter(fieldFilter).first();
         }
 
-        Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.save);
-        resultMessage.setBody(ret);
-        resultMessage.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret == null ? 0 : 1);
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.save);
+        processAndTransferResult(ret, exchange, MongoDbOperation.save);
+        //exchange.getOut().setBody(ret);
+        exchange.getOut().setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret == null ? 0 : 1);
     }
 
     @SuppressWarnings({"rawtypes", "unchecked"})
@@ -318,9 +302,9 @@ public class MongoDbProducer extends DefaultProducer {
             exchange.getIn().setHeader(MongoDbConstants.OID, oids);
         }
 
-        prepareResponseMessage(exchange, MongoDbOperation.insert);
-
-        processAndTransferResult(insert, exchange);
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.insert);
+        processAndTransferResult(insert, exchange, MongoDbOperation.insert);
     }
 
     protected void doFindAll(Exchange exchange) throws Exception {
@@ -364,16 +348,17 @@ public class MongoDbProducer extends DefaultProducer {
                 ret.limit(limit.intValue());
             }
 
-            Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.findAll);
+            copyHeaders(exchange);
+            moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.findAll);
             if (MongoDbOutputType.DBCursor.equals(endpoint.getOutputType())) {
-                resultMessage.setBody(ret.iterator());
+                processAndTransferResult(ret.iterator(), exchange, MongoDbOperation.findAll);
             } else {
                 List<BasicDBObject> result = new ArrayList<>();
                 ret.iterator().forEachRemaining(result::add);
-                resultMessage.setBody(result);
+                processAndTransferResult(result, exchange, MongoDbOperation.findAll);
                 //TODO: decide what to do with total number of elements (count query needed).
                 //resultMessage.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret.....);
-                resultMessage.setHeader(MongoDbConstants.RESULT_PAGE_SIZE, result.size());
+                exchange.getOut().setHeader(MongoDbConstants.RESULT_PAGE_SIZE, result.size());
             }
         } finally {
             // make sure the cursor is closed
@@ -396,9 +381,10 @@ public class MongoDbProducer extends DefaultProducer {
             ret = dbCol.find(o).filter(fieldFilter).first();
         }
 
-        Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.findOneByQuery);
-        resultMessage.setBody(ret);
-        resultMessage.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret == null ? 0 : 1);
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.findOneByQuery);
+        processAndTransferResult(ret, exchange, MongoDbOperation.findOneByQuery);
+        exchange.getOut().setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret == null ? 0 : 1);
     }
 
     protected void doCount(Exchange exchange) throws Exception {
@@ -410,8 +396,10 @@ public class MongoDbProducer extends DefaultProducer {
         } else {
             answer = dbCol.count(query);
         }
-        Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.count);
-        resultMessage.setBody(answer);
+
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.count);
+        processAndTransferResult(answer, exchange, MongoDbOperation.count);
     }
 
     /**
@@ -421,6 +409,7 @@ public class MongoDbProducer extends DefaultProducer {
      * @param exchange
      * @throws Exception
      */
+    //always returns result as body
     protected void doAggregate(Exchange exchange) throws Exception {
         MongoCollection<BasicDBObject> dbCol = calculateCollection(exchange);
         DBObject query = exchange.getIn().getMandatoryBody(DBObject.class);
@@ -446,8 +435,9 @@ public class MongoDbProducer extends DefaultProducer {
         }
 
         aggregationResult.iterator().forEachRemaining(dbIterator::add);
-        Message resultMessage = prepareResponseMessage(exchange, MongoDbOperation.aggregate);
-        resultMessage.setBody(dbIterator);
+        copyHeaders(exchange);
+        moveBodyToOutIfResultIsReturnedAsHeader(exchange, MongoDbOperation.aggregate);
+        processAndTransferResult(dbIterator, exchange, MongoDbOperation.aggregate);
     }
 
     // --------- Convenience methods -----------------------
@@ -488,7 +478,8 @@ public class MongoDbProducer extends DefaultProducer {
         // dynamic calculation is an option. In most cases it won't be used and we should not penalise all users with running this
         // resolution logic on every Exchange if they won't be using this functionality at all
         if (!endpoint.isDynamicity()) {
-            return endpoint.getMongoCollection();
+            return endpoint.getMongoCollection()
+                    .withWriteConcern(endpoint.getWriteConcern());
         }
 
         String dynamicDB = exchange.getIn().getHeader(MongoDbConstants.DATABASE, String.class);
@@ -500,7 +491,8 @@ public class MongoDbProducer extends DefaultProducer {
         MongoCollection<BasicDBObject> dbCol;
 
         if (dynamicDB == null && dynamicCollection == null) {
-            dbCol = endpoint.getMongoCollection();
+            dbCol = endpoint.getMongoCollection()
+                    .withWriteConcern(endpoint.getWriteConcern());
         } else {
             MongoDatabase db = calculateDb(exchange);
 
@@ -524,44 +516,6 @@ public class MongoDbProducer extends DefaultProducer {
         return dbCol;
     }
 
-    private void processAndTransferDeleteResult(DeleteResult result, Exchange exchange) {
-        // determine where to set the WriteResult: as the OUT body or as an IN message header
-        if (endpoint.isWriteResultAsHeader()) {
-            exchange.getOut().setHeader(MongoDbConstants.WRITERESULT, result);
-        } else {
-            exchange.getOut().setBody(result);
-        }
-    }
-
-    private void processAndTransferUpdateResult(UpdateResult result, Exchange exchange) {
-        // determine where to set the WriteResult: as the OUT body or as an IN message header
-        if (endpoint.isWriteResultAsHeader()) {
-            exchange.getOut().setHeader(MongoDbConstants.WRITERESULT, result);
-        } else {
-            exchange.getOut().setBody(result);
-        }
-    }
-
-    private WriteConcern extractWriteConcern(Exchange exchange) throws CamelMongoDbException {
-        Object o = exchange.getIn().getHeader(MongoDbConstants.WRITECONCERN);
-
-        if (o == null) {
-            return null;
-        } else if (o instanceof WriteConcern) {
-            return ObjectHelper.cast(WriteConcern.class, o);
-        } else if (o instanceof String) {
-            WriteConcern answer = WriteConcern.valueOf(ObjectHelper.cast(String.class, o));
-            if (answer == null) {
-                throw new CamelMongoDbException("WriteConcern specified in the " + MongoDbConstants.WRITECONCERN + " header, with value " + o
-                        + " could not be resolved to a WriteConcern type");
-            }
-        }
-
-        // should never get here
-        LOG.warn("A problem occurred while resolving the Exchange's Write Concern");
-        return null;
-    }
-
     @SuppressWarnings("rawtypes")
     private List<DBObject> attemptConvertToList(List insertList, Exchange exchange) throws CamelMongoDbException {
         List<DBObject> dbObjectList = new ArrayList<DBObject>(insertList.size());
@@ -577,17 +531,27 @@ public class MongoDbProducer extends DefaultProducer {
         return dbObjectList;
     }
 
-    private Message prepareResponseMessage(Exchange exchange, MongoDbOperation operation) {
-        Message answer = exchange.getOut();
-        MessageHelper.copyHeaders(exchange.getIn(), answer, false);
+    private boolean isWriteOperation(MongoDbOperation operation) {
+        return MongoDbComponent.WRITE_OPERATIONS.contains(operation);
+    }
+
+    private void copyHeaders(Exchange exchange) {
+        MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), false);
+    }
+
+    private void moveBodyToOutIfResultIsReturnedAsHeader(Exchange exchange, MongoDbOperation operation) {
         if (isWriteOperation(operation) && endpoint.isWriteResultAsHeader()) {
-            answer.setBody(exchange.getIn().getBody());
+            exchange.getOut().setBody(exchange.getIn().getBody());
         }
-        return answer;
     }
 
-    private boolean isWriteOperation(MongoDbOperation operation) {
-        return MongoDbComponent.WRITE_OPERATIONS.contains(operation);
+    private void processAndTransferResult(Object result, Exchange exchange, MongoDbOperation operation) {
+        // determine where to set the WriteResult: as the OUT body or as an IN message header
+        if (isWriteOperation(operation) && endpoint.isWriteResultAsHeader()) {
+            exchange.getOut().setHeader(MongoDbConstants.WRITERESULT, result);
+        } else {
+            exchange.getOut().setBody(result);
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/dfbab447/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
index 3fa9b25..842af35 100644
--- a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbOperationsTest.java
@@ -24,6 +24,7 @@ import static java.util.Arrays.asList;
 import com.mongodb.BasicDBObject;
 import com.mongodb.DBObject;
 import com.mongodb.WriteResult;
+import com.mongodb.client.DistinctIterable;
 import com.mongodb.client.result.DeleteResult;
 import com.mongodb.client.result.UpdateResult;
 import com.mongodb.util.JSON;

http://git-wip-us.apache.org/repos/asf/camel/blob/dfbab447/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbTailableCursorConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbTailableCursorConsumerTest.java b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbTailableCursorConsumerTest.java
index e45e18c..e6c7eb0 100644
--- a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbTailableCursorConsumerTest.java
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbTailableCursorConsumerTest.java
@@ -19,17 +19,13 @@ package org.apache.camel.component.mongodb;
 import java.util.Calendar;
 
 import com.mongodb.BasicDBObject;
-import com.mongodb.BasicDBObjectBuilder;
-import com.mongodb.DBCollection;
 import com.mongodb.DBObject;
-import com.mongodb.WriteConcern;
 import com.mongodb.client.MongoCollection;
 import com.mongodb.client.model.CreateCollectionOptions;
 
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-
 import org.junit.Test;
 
 public class MongoDbTailableCursorConsumerTest extends AbstractMongoDbTest {
@@ -128,7 +124,7 @@ public class MongoDbTailableCursorConsumerTest extends AbstractMongoDbTest {
                 new CreateCollectionOptions()
                         .capped(true)
                         .sizeInBytes(1000000000)
-                        .maxDocuments(100));
+                        .maxDocuments(1000));
         cappedTestCollection = db.getCollection(cappedTestCollectionName, BasicDBObject.class);
         addTestRoutes();
         context.startRoute("tailableCursorConsumer1");
@@ -171,7 +167,10 @@ public class MongoDbTailableCursorConsumerTest extends AbstractMongoDbTest {
         // 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));
+                new CreateCollectionOptions()
+                        .capped(true)
+                        .sizeInBytes(1000000000)
+                        .maxDocuments(1000));
         cappedTestCollection = db.getCollection(cappedTestCollectionName, BasicDBObject.class);
         cappedTestCollection.createIndex(new BasicDBObject("increasing", 1));
 
@@ -244,7 +243,10 @@ public class MongoDbTailableCursorConsumerTest extends AbstractMongoDbTest {
         // 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));
+                new CreateCollectionOptions()
+                        .capped(true)
+                        .sizeInBytes(1000000000)
+                        .maxDocuments(1000));
         cappedTestCollection = db.getCollection(cappedTestCollectionName, BasicDBObject.class);
         addTestRoutes();
         context.startRoute("tailableCursorConsumer2");
@@ -318,7 +320,10 @@ public class MongoDbTailableCursorConsumerTest extends AbstractMongoDbTest {
         // 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));
+                new CreateCollectionOptions()
+                        .capped(true)
+                        .sizeInBytes(1000000000)
+                        .maxDocuments(1000));
         cappedTestCollection = db.getCollection(cappedTestCollectionName, BasicDBObject.class);
         addTestRoutes();
         context.startRoute("tailableCursorConsumer3");