Author: davsclaus
Date: Tue Aug 16 07:49:07 2011
New Revision: 1158140
URL: http://svn.apache.org/viewvc?rev=1158140&view=rev
Log:
CAMEL-4310: Splitter in streaming mode set split size header on the completed
exchange. Thanks to Sebastien Petrucci for the patch.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java?rev=1158140&r1=1158139&r2=1158140&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
Tue Aug 16 07:49:07 2011
@@ -188,12 +188,15 @@ public class Splitter extends MulticastP
exchange.setProperty(Exchange.SPLIT_INDEX, index);
if (allPairs instanceof Collection) {
+ // non streaming mode, so we know the total size already
exchange.setProperty(Exchange.SPLIT_SIZE, ((Collection<?>)
allPairs).size());
}
if (it.hasNext()) {
exchange.setProperty(Exchange.SPLIT_COMPLETE, Boolean.FALSE);
} else {
exchange.setProperty(Exchange.SPLIT_COMPLETE, Boolean.TRUE);
+ // streaming mode, so set total size when we are complete based on
the index
+ exchange.setProperty(Exchange.SPLIT_SIZE, index + 1);
}
}
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java?rev=1158140&r1=1158139&r2=1158140&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
Tue Aug 16 07:49:07 2011
@@ -176,10 +176,21 @@ public class SplitterTest extends Contex
});
assertMockEndpointsSatisfied();
- for (Exchange exchange : resultEndpoint.getReceivedExchanges()) {
- assertNotNull(exchange.getProperty(Exchange.SPLIT_INDEX));
- //this header cannot be set when streaming is used
- assertNull(exchange.getProperty(Exchange.SPLIT_SIZE));
+
+ // check properties with split details is correct
+ int size = resultEndpoint.getReceivedExchanges().size();
+ for (int i = 0; i < size; i++) {
+ Exchange exchange = resultEndpoint.getReceivedExchanges().get(i);
+ assertEquals(i, exchange.getProperty(Exchange.SPLIT_INDEX));
+ if (i < (size - 1)) {
+ assertEquals(Boolean.FALSE,
exchange.getProperty(Exchange.SPLIT_COMPLETE));
+ //this header cannot be set when streaming is used, except for
the last exchange
+ assertNull(exchange.getProperty(Exchange.SPLIT_SIZE));
+ } else {
+ assertEquals(Boolean.TRUE,
exchange.getProperty(Exchange.SPLIT_COMPLETE));
+ // when we are complete the size is set
+ assertEquals(size, exchange.getProperty(Exchange.SPLIT_SIZE));
+ }
}
}