Author: ningjiang
Date: Tue Oct 16 14:09:09 2012
New Revision: 1398810
URL: http://svn.apache.org/viewvc?rev=1398810&view=rev
Log:
CAMEL-5704 Fixed the Split inside Split - Parallel processing issue
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileSplitInSplitTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java?rev=1398810&r1=1398809&r2=1398810&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
Tue Oct 16 14:09:09 2012
@@ -1002,6 +1002,10 @@ public class MulticastProcessor extends
Map<Object, AggregationStrategy> map = CastUtils.cast(property);
if (map == null) {
map = new HashMap<Object, AggregationStrategy>();
+ } else {
+ // it is not safe to use the map directly as the exchange doesn't
have the deep copy of it's properties
+ // we just create a new copy if we need to change the map
+ map = new HashMap<Object, AggregationStrategy>(map);
}
// store the strategy using this processor as the key
// (so we can store multiple strategies on the same exchange)
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileSplitInSplitTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileSplitInSplitTest.java?rev=1398810&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileSplitInSplitTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileSplitInSplitTest.java
Tue Oct 16 14:09:09 2012
@@ -0,0 +1,107 @@
+/**
+ * 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.component.file;
+
+import java.io.File;
+
+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.model.language.SimpleExpression;
+import org.apache.camel.processor.interceptor.Tracer;
+
+public class FileSplitInSplitTest extends ContextTestSupport {
+
+ private final int size = 3;
+ private final String comma = ",";
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/split");
+ super.setUp();
+ }
+
+ public void testConcurrentAppend() throws Exception {
+ // create file with many lines
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < size; i++) {
+ sb.append("Block1 Line " + i + LS);
+ }
+ sb.append(comma);
+ for (int i = 10; i < size + 10; i++) {
+ sb.append("Block2 Line " + i + LS);
+ }
+
+ template.sendBodyAndHeader("file:target/split", sb.toString(),
Exchange.FILE_NAME, "input.txt");
+
+ // start route
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+
+ context.startRoute("foo");
+
+ assertMockEndpointsSatisfied();
+
+ // check one file has expected number of lines +1 saying split is
+ // complete.
+ String txt = context.getTypeConverter().convertTo(String.class,
+ new
File("target/split/outbox/result0.txt"));
+ assertNotNull(txt);
+
+ String[] lines = txt.split(LS);
+ assertEquals("Should be " + (size + 1) + " lines", size + 1,
lines.length);
+
+
+ txt = context.getTypeConverter().convertTo(String.class,
+ new
File("target/split/outbox/result1.txt"));
+ assertNotNull(txt);
+
+ lines = txt.split(LS);
+ assertEquals("Should be " + (size + 1) + " lines", size + 1,
lines.length);
+
+
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ Tracer tracer = new Tracer();
+ getContext().addInterceptStrategy(tracer);
+
+ from("file:target/split").routeId("foo").noAutoStartup()
+ .split(body().tokenize(comma))
+ .parallelProcessing()
+ .streaming()
+ .setProperty("split", new
SimpleExpression("${property.CamelSplitIndex}"))
+ .split(body().tokenize(LS))
+ .parallelProcessing()
+ .streaming()
+ .setBody(body().append(":Status=OK").append(LS))
+
.to("file:target/split/outbox?fileExist=Append&fileName=result${property.split}.txt")
+ .end()
+ .setBody(new SimpleExpression("${property.split}
complete"))
+
.to("file:target/split/outbox?fileExist=Append&fileName=result${property.split}.txt")
+ .end().to("mock:result");
+
+ }
+ };
+ }
+
+}