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-6508: Recipient list now stores exchange property with the endooint uri where the message was sent.
Date Sun, 28 Jul 2013 16:17:29 GMT
CAMEL-6508: Recipient list now stores exchange property with the endooint uri where the message
was sent.


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

Branch: refs/heads/master
Commit: 84abf528037841c1aa98eb446fecfe5a7806da2e
Parents: 28e045d
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Jul 28 17:43:35 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jul 28 17:43:35 2013 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/camel/Exchange.java    |  1 +
 .../camel/processor/RecipientListProcessor.java |  3 +-
 ...ExchangePropertyAggregationStrategyTest.java | 88 ++++++++++++++++++++
 .../RecipientListExchangePropertyTest.java      | 60 +++++++++++++
 4 files changed, 151 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/84abf528/camel-core/src/main/java/org/apache/camel/Exchange.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java b/camel-core/src/main/java/org/apache/camel/Exchange.java
index 9161430..0aa0762 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -164,6 +164,7 @@ public interface Exchange {
 
     String PARENT_UNIT_OF_WORK = "CamelParentUnitOfWork";
 
+    String RECIPIENT_LIST_ENDPOINT = "CamelRecipientListEndpoint";
     String RECEIVED_TIMESTAMP      = "CamelReceivedTimestamp";
     String REDELIVERED             = "CamelRedelivered";
     String REDELIVERY_COUNTER      = "CamelRedeliveryCounter";

http://git-wip-us.apache.org/repos/asf/camel/blob/84abf528/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
b/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
index 636a88a..92b3422 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
@@ -97,8 +97,9 @@ public class RecipientListProcessor extends MulticastProcessor {
         }
 
         public void begin() {
-            // we have already acquired and prepare the producer so we
+            // we have already acquired and prepare the producer
             LOG.trace("RecipientProcessorExchangePair #{} begin: {}", index, exchange);
+            exchange.setProperty(Exchange.RECIPIENT_LIST_ENDPOINT, endpoint.getEndpointUri());
         }
 
         public void done() {

http://git-wip-us.apache.org/repos/asf/camel/blob/84abf528/camel-core/src/test/java/org/apache/camel/processor/RecipientListExchangePropertyAggregationStrategyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/RecipientListExchangePropertyAggregationStrategyTest.java
b/camel-core/src/test/java/org/apache/camel/processor/RecipientListExchangePropertyAggregationStrategyTest.java
new file mode 100644
index 0000000..762f340
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/RecipientListExchangePropertyAggregationStrategyTest.java
@@ -0,0 +1,88 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+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.AggregationStrategy;
+
+/**
+ * @version 
+ */
+public class RecipientListExchangePropertyAggregationStrategyTest extends ContextTestSupport
{
+
+    private final MyAggregationStrategy strategy = new MyAggregationStrategy();
+
+    public void testRecipientExchangeProperty() throws Exception {
+        getMockEndpoint("mock:a").expectedPropertyReceived(Exchange.RECIPIENT_LIST_ENDPOINT,
"direct://a");
+        getMockEndpoint("mock:a").expectedPropertyReceived(Exchange.TO_ENDPOINT, "mock://a");
+        getMockEndpoint("mock:b").expectedPropertyReceived(Exchange.RECIPIENT_LIST_ENDPOINT,
"direct://b");
+        getMockEndpoint("mock:b").expectedPropertyReceived(Exchange.TO_ENDPOINT, "mock://b");
+        getMockEndpoint("mock:c").expectedPropertyReceived(Exchange.RECIPIENT_LIST_ENDPOINT,
"direct://c");
+        getMockEndpoint("mock:c").expectedPropertyReceived(Exchange.TO_ENDPOINT, "mock://c");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello c");
+        // would be the last one
+        mock.expectedPropertyReceived(Exchange.RECIPIENT_LIST_ENDPOINT, "direct://c");
+
+        String out = template.requestBodyAndHeader("direct:start", "Hello World", "slip",
"direct:a,direct:b,direct:c", String.class);
+        assertEquals("Hello c", out);
+
+        assertMockEndpointsSatisfied();
+
+        assertEquals(3, strategy.getUris().size());
+        assertEquals("direct://a", strategy.getUris().get(0));
+        assertEquals("direct://b", strategy.getUris().get(1));
+        assertEquals("direct://c", strategy.getUris().get(2));
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start")
+                    .recipientList(header("slip")).aggregationStrategy(strategy)
+                        .to("mock:result");
+
+                from("direct:a").to("mock:a").transform(constant("Hello a"));
+                from("direct:b").to("mock:b").transform(constant("Hello b"));
+                from("direct:c").to("mock:c").transform(constant("Hello c"));
+            }
+        };
+    }
+
+    private static class MyAggregationStrategy implements AggregationStrategy {
+
+        private List<String> uris = new ArrayList<String>();
+
+        @Override
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            uris.add(newExchange.getProperty(Exchange.RECIPIENT_LIST_ENDPOINT, String.class));
+            return newExchange;
+        }
+
+        public List<String> getUris() {
+            return uris;
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/84abf528/camel-core/src/test/java/org/apache/camel/processor/RecipientListExchangePropertyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/RecipientListExchangePropertyTest.java
b/camel-core/src/test/java/org/apache/camel/processor/RecipientListExchangePropertyTest.java
new file mode 100644
index 0000000..d450c84
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/RecipientListExchangePropertyTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version 
+ */
+public class RecipientListExchangePropertyTest extends ContextTestSupport {
+
+    public void testRecipientExchangeProperty() throws Exception {
+        getMockEndpoint("mock:a").expectedPropertyReceived(Exchange.RECIPIENT_LIST_ENDPOINT,
"direct://a");
+        getMockEndpoint("mock:a").expectedPropertyReceived(Exchange.TO_ENDPOINT, "mock://a");
+        getMockEndpoint("mock:b").expectedPropertyReceived(Exchange.RECIPIENT_LIST_ENDPOINT,
"direct://b");
+        getMockEndpoint("mock:b").expectedPropertyReceived(Exchange.TO_ENDPOINT, "mock://b");
+        getMockEndpoint("mock:c").expectedPropertyReceived(Exchange.RECIPIENT_LIST_ENDPOINT,
"direct://c");
+        getMockEndpoint("mock:c").expectedPropertyReceived(Exchange.TO_ENDPOINT, "mock://c");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello c");
+        // would be the last one
+        mock.expectedPropertyReceived(Exchange.RECIPIENT_LIST_ENDPOINT, "direct://c");
+
+        String out = template.requestBodyAndHeader("direct:start", "Hello World", "slip",
"direct:a,direct:b,direct:c", String.class);
+        assertEquals("Hello c", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").recipientList(header("slip")).to("mock:result");
+
+                from("direct:a").to("mock:a").transform(constant("Hello a"));
+                from("direct:b").to("mock:b").transform(constant("Hello b"));
+                from("direct:c").to("mock:c").transform(constant("Hello c"));
+            }
+        };
+    }
+
+}
\ No newline at end of file


Mime
View raw message