camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 01/02: CAMEL-12316 : Add allowDiskUse option to aggregate operation
Date Mon, 05 Mar 2018 07:05:23 GMT
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0d209e7019a204b490fe5b68fb9d0108a8c7c48f
Author: Far├Ęs Hassak <fares.hassak@gmail.com>
AuthorDate: Sat Mar 3 19:49:10 2018 +0100

    CAMEL-12316 : Add allowDiskUse option to aggregate operation
---
 .../apache/camel/component/mongodb/MongoDbConstants.java    |  1 +
 .../org/apache/camel/component/mongodb/MongoDbProducer.java |  5 ++++-
 .../component/mongodb/MongoDbAggregateOperationTest.java    | 13 ++++++++++---
 .../apache/camel/component/mongodb3/MongoDbConstants.java   |  1 +
 .../apache/camel/component/mongodb3/MongoDbProducer.java    |  8 ++++++--
 .../component/mongodb3/MongoDbAggregateOperationTest.java   | 12 +++++++++---
 6 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbConstants.java
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbConstants.java
index 88cf672..ba3e71b 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbConstants.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbConstants.java
@@ -39,6 +39,7 @@ public final class MongoDbConstants {
     public static final String WRITERESULT = "CamelMongoWriteResult";
     public static final String OID = "CamelMongoOid";
     public static final String DISTINCT_QUERY_FIELD = "CamelMongoDbDistinctQueryField";
+    public static final String ALLOW_DISK_USE = "CamelMongoDbAllowDiskUse";
 
     private MongoDbConstants() {
     }
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 f0192d9..63568e7 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
@@ -510,7 +510,10 @@ public class MongoDbProducer extends DefaultProducer {
                 if (batchSize != null) {
                     aggregationResult.batchSize(batchSize);
                 }
-                
+
+                Boolean allowDiskUse  = exchange.getIn().getHeader(MongoDbConstants.ALLOW_DISK_USE,
Boolean.FALSE, Boolean.class);
+                aggregationResult.allowDiskUse(allowDiskUse);
+
                 Iterable<BasicDBObject> result;
                 if (!MongoDbOutputType.DBCursor.equals(endpoint.getOutputType())) {
                     try {
diff --git a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbAggregateOperationTest.java
b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbAggregateOperationTest.java
index b547d23..4f37a67 100644
--- a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbAggregateOperationTest.java
+++ b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbAggregateOperationTest.java
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.component.mongodb;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import com.mongodb.BasicDBObject;
 import com.mongodb.DBObject;
@@ -77,14 +79,19 @@ public class MongoDbAggregateOperationTest extends AbstractMongoDbTest
{
     }
 
     @Test
-    public void testAggregateDBCursorBatchSize() {
+    public void testAggregateWithOptions() {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
 
+        Map<String, Object> options = new HashMap<>();
+        options.put(MongoDbConstants.BATCH_SIZE, 10);
+        options.put(MongoDbConstants.ALLOW_DISK_USE, true);
+
         Object result = template
-                .requestBodyAndHeader("direct:aggregateDBCursor",
-                        "[{ $match : {$or : [{\"scientist\" : \"Darwin\"},{\"scientist\"
: \"Einstein\"}]}}]", MongoDbConstants.BATCH_SIZE, 10);
+                .requestBodyAndHeaders("direct:aggregateDBCursor",
+                        "[{ $match : {$or : [{\"scientist\" : \"Darwin\"},{\"scientist\"
: \"Einstein\"}]}}]", options);
+        
         
         assertTrue("Result is not of type DBCursor", result instanceof MongoIterable);
 
diff --git a/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/MongoDbConstants.java
b/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/MongoDbConstants.java
index 7196a98..70fe95c 100644
--- a/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/MongoDbConstants.java
+++ b/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/MongoDbConstants.java
@@ -40,6 +40,7 @@ public final class MongoDbConstants {
     public static final String WRITERESULT = "CamelMongoWriteResult";
     public static final String OID = "CamelMongoOid";
     public static final String DISTINCT_QUERY_FIELD = "CamelMongoDbDistinctQueryField";
+    public static final String ALLOW_DISK_USE = "CamelMongoDbAllowDiskUse";
 
     public static final String MONGO_ID = "_id"; // default id field
 
diff --git a/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/MongoDbProducer.java
b/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/MongoDbProducer.java
index 17cd024..ad558a8 100644
--- a/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/MongoDbProducer.java
+++ b/components/camel-mongodb3/src/main/java/org/apache/camel/component/mongodb3/MongoDbProducer.java
@@ -47,6 +47,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.mongodb.client.model.Filters.eq;
+import static org.apache.camel.component.mongodb3.MongoDbConstants.ALLOW_DISK_USE;
 import static org.apache.camel.component.mongodb3.MongoDbConstants.BATCH_SIZE;
 import static org.apache.camel.component.mongodb3.MongoDbConstants.COLLECTION;
 import static org.apache.camel.component.mongodb3.MongoDbConstants.COLLECTION_INDEX;
@@ -530,8 +531,11 @@ public class MongoDbProducer extends DefaultProducer {
                 if (batchSize != null) {
                     aggregationResult.batchSize(batchSize);
                 }
-                
-                Iterable<Document> result;                
+
+                Boolean allowDiskUse  = exchange.getIn().getHeader(MongoDbConstants.ALLOW_DISK_USE,
Boolean.FALSE, Boolean.class);
+                aggregationResult.allowDiskUse(allowDiskUse);
+
+                Iterable<Document> result;
                 if (!MongoDbOutputType.MongoIterable.equals(endpoint.getOutputType())) {
                     try {
                         result = new ArrayList<>();
diff --git a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbAggregateOperationTest.java
b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbAggregateOperationTest.java
index 9241567..be849bc 100644
--- a/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbAggregateOperationTest.java
+++ b/components/camel-mongodb3/src/test/java/org/apache/camel/component/mongodb3/MongoDbAggregateOperationTest.java
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.component.mongodb3;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import com.mongodb.client.MongoIterable;
 
@@ -76,14 +78,18 @@ public class MongoDbAggregateOperationTest extends AbstractMongoDbTest
{
     }
 
     @Test
-    public void testAggregateDBCursorBatchSize() {
+    public void testAggregateWithOptions() {
         // Test that the collection has 0 documents in it
         assertEquals(0, testCollection.count());
         pumpDataIntoTestCollection();
 
+        Map<String, Object> options = new HashMap<>();
+        options.put(MongoDbConstants.BATCH_SIZE, 10);
+        options.put(MongoDbConstants.ALLOW_DISK_USE, true);
+
         Object result = template
-                .requestBodyAndHeader("direct:aggregateDBCursor",
-                        "[{ $match : {$or : [{\"scientist\" : \"Darwin\"},{\"scientist\"
: \"Einstein\"}]}}]", MongoDbConstants.BATCH_SIZE, 10);
+                .requestBodyAndHeaders("direct:aggregateDBCursor",
+                        "[{ $match : {$or : [{\"scientist\" : \"Darwin\"},{\"scientist\"
: \"Einstein\"}]}}]", options);
 
         assertTrue("Result is not of type DBCursor", result instanceof MongoIterable);
 

-- 
To stop receiving notification emails like this one, please contact
acosentino@apache.org.

Mime
View raw message