camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] git commit: CAMEL-6557: Fixed AbstractListAggregationStrategy to work with completion from batch consumer.
Date Fri, 23 Aug 2013 09:29:58 GMT
CAMEL-6557: Fixed AbstractListAggregationStrategy to work with completion from batch consumer.


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

Branch: refs/heads/master
Commit: 2c5a42db466a287b4cd95f411ed387ef1106bf82
Parents: 7d854c9
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Aug 23 11:29:05 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Aug 23 11:29:48 2013 +0200

----------------------------------------------------------------------
 .../AbstractListAggregationStrategy.java        |  6 +-
 ...StrategyCompletionFromBatchConsumerTest.java | 78 ++++++++++++++++++++
 2 files changed, 80 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2c5a42db/camel-core/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
b/camel-core/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
index d37bba3..a19bdbc 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
@@ -80,11 +80,9 @@ public abstract class AbstractListAggregationStrategy<V> implements
CompletionAw
      */
     public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
         List<V> list;
-        Exchange answer = oldExchange;
 
         if (oldExchange == null) {
-            answer = new DefaultExchange(newExchange);
-            list = getList(answer);
+            list = getList(newExchange);
         } else {
             list = getList(oldExchange);
         }
@@ -96,7 +94,7 @@ public abstract class AbstractListAggregationStrategy<V> implements
CompletionAw
             }
         }
 
-        return answer;
+        return oldExchange != null ? oldExchange : newExchange;
     }
 
     @SuppressWarnings("unchecked")

http://git-wip-us.apache.org/repos/asf/camel/blob/2c5a42db/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomListAggregationStrategyCompletionFromBatchConsumerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomListAggregationStrategyCompletionFromBatchConsumerTest.java
b/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomListAggregationStrategyCompletionFromBatchConsumerTest.java
new file mode 100644
index 0000000..987e3b9
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/aggregator/CustomListAggregationStrategyCompletionFromBatchConsumerTest.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.aggregator;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.aggregate.AbstractListAggregationStrategy;
+
+/**
+ *
+ */
+public class CustomListAggregationStrategyCompletionFromBatchConsumerTest extends ContextTestSupport
{
+
+    @SuppressWarnings("unchecked")
+    public void testCustomAggregationStrategy() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedMessageCount(1);
+
+        template.sendBodyAndHeader("file:target/batch", "100", Exchange.FILE_NAME, "1.txt");
+        template.sendBodyAndHeader("file:target/batch", "150", Exchange.FILE_NAME, "2.txt");
+        template.sendBodyAndHeader("file:target/batch", "130", Exchange.FILE_NAME, "3.txt");
+
+        context.startRoute("foo");
+
+        assertMockEndpointsSatisfied();
+
+        // the list will be stored as the message body by default
+        List<Integer> numbers = result.getExchanges().get(0).getIn().getBody(List.class);
+        assertNotNull(numbers);
+        assertEquals(Integer.valueOf("100"), numbers.get(0));
+        assertEquals(Integer.valueOf("150"), numbers.get(1));
+        assertEquals(Integer.valueOf("130"), numbers.get(2));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/batch?sortBy=file:name").routeId("foo").noAutoStartup()
+                    .aggregate(new MyListOfNumbersStrategy()).constant(true)
+                    .completionFromBatchConsumer()
+                    .to("mock:result");
+            }
+        };
+    }
+
+    /**
+     * Our strategy just group a list of integers.
+     */
+    public final class MyListOfNumbersStrategy extends AbstractListAggregationStrategy<Integer>
{
+
+        @Override
+        public Integer getValue(Exchange exchange) {
+            String s = exchange.getIn().getBody(String.class);
+            return Integer.valueOf(s);
+        }
+    }
+
+}


Mime
View raw message