You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/12/14 10:09:02 UTC

[2/3] git commit: CAMEL-7068: Fixed camel-flatpack in splitter streaming mode. Thanks to Xavier Fournet for the patch.

CAMEL-7068: Fixed camel-flatpack in splitter streaming mode. Thanks to Xavier Fournet for the patch.


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

Branch: refs/heads/camel-2.12.x
Commit: 954c068b94a66236358e1c762f8e414f8832924e
Parents: 25930b8
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Dec 14 10:05:11 2013 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Dec 14 10:10:35 2013 +0100

----------------------------------------------------------------------
 .../camel/component/flatpack/DataSetList.java   | 10 ++-
 .../camel-flatpack/src/test/data/delim2/foo.csv |  4 +-
 .../flatpack/DelimitedWithNoDescriptorTest.java |  6 +-
 .../component/flatpack/StreamedSplitTest.java   | 66 ++++++++++++++++++++
 .../flatpack/StreamedSplitTest-context.xml      | 42 +++++++++++++
 5 files changed, 121 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/954c068b/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
----------------------------------------------------------------------
diff --git a/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java b/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
index 0b15071..baf933c 100644
--- a/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
+++ b/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
@@ -23,7 +23,7 @@ import java.util.Map;
 import net.sf.flatpack.DataSet;
 
 /**
- * @version 
+ * @version
  */
 public class DataSetList extends AbstractList<Map<String, Object>> {
     private final DataSet dataSet;
@@ -45,14 +45,18 @@ public class DataSetList extends AbstractList<Map<String, Object>> {
     public Iterator<Map<String, Object>> iterator() {
         dataSet.goTop();
         return new Iterator<Map<String, Object>>() {
+            private boolean hasNext = dataSet.next();
+
             public boolean hasNext() {
-                return dataSet.next();
+                return hasNext;
             }
 
             public Map<String, Object> next() {
                 // because of a limitation in split() we need to create an object for the current position
                 // otherwise strangeness occurs when the same object is used to represent each row
-                return FlatpackConverter.toMap(dataSet);
+                Map<String, Object> result = FlatpackConverter.toMap(dataSet);
+                hasNext = dataSet.next();
+                return result;
             }
 
             public void remove() {

http://git-wip-us.apache.org/repos/asf/camel/blob/954c068b/components/camel-flatpack/src/test/data/delim2/foo.csv
----------------------------------------------------------------------
diff --git a/components/camel-flatpack/src/test/data/delim2/foo.csv b/components/camel-flatpack/src/test/data/delim2/foo.csv
index 9a1bd8f..ebfb8ca 100644
--- a/components/camel-flatpack/src/test/data/delim2/foo.csv
+++ b/components/camel-flatpack/src/test/data/delim2/foo.csv
@@ -1,3 +1,5 @@
 "NAME","LOCATION"
 "James", "London"
-"Claus", "Austria"
\ No newline at end of file
+"Claus", "Austria"
+"Antoine", "Lyon"
+"Xavier", "Lyon"

http://git-wip-us.apache.org/repos/asf/camel/blob/954c068b/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/DelimitedWithNoDescriptorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/DelimitedWithNoDescriptorTest.java b/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/DelimitedWithNoDescriptorTest.java
index 114e58d..fc843cb 100644
--- a/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/DelimitedWithNoDescriptorTest.java
+++ b/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/DelimitedWithNoDescriptorTest.java
@@ -34,7 +34,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 /**
- * @version 
+ * @version
  */
 @ContextConfiguration
 public class DelimitedWithNoDescriptorTest extends AbstractJUnit4SpringContextTests {
@@ -43,11 +43,11 @@ public class DelimitedWithNoDescriptorTest extends AbstractJUnit4SpringContextTe
     @EndpointInject(uri = "mock:results")
     protected MockEndpoint results;
 
-    protected String[] expectedItemDesc = {"James", "Claus"};
+    protected String[] expectedItemDesc = {"James", "Claus", "Antoine", "Xavier"};
 
     @Test
     public void testCamel() throws Exception {
-        results.expectedMessageCount(2);
+        results.expectedMessageCount(4);
         results.assertIsSatisfied();
 
         int counter = 0;

http://git-wip-us.apache.org/repos/asf/camel/blob/954c068b/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/StreamedSplitTest.java
----------------------------------------------------------------------
diff --git a/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/StreamedSplitTest.java b/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/StreamedSplitTest.java
new file mode 100644
index 0000000..c352a37
--- /dev/null
+++ b/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/StreamedSplitTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.flatpack;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * @version
+ */
+@ContextConfiguration
+public class StreamedSplitTest extends AbstractJUnit4SpringContextTests {
+    private static final Logger LOG = LoggerFactory.getLogger(FixedLengthTest.class);
+
+    @EndpointInject(uri = "mock:results")
+    protected MockEndpoint results;
+
+    protected String[] expectedItemDesc = {"James", "Claus", "Antoine", "Xavier"};
+
+    @Test
+    public void testCamel() throws Exception {
+        results.expectedMessageCount(4);
+        results.assertIsSatisfied();
+
+        int counter = 0;
+        List<Exchange> list = results.getReceivedExchanges();
+        for (Exchange exchange : list) {
+            Message in = exchange.getIn();
+            Map<?, ?> body = in.getBody(Map.class);
+            assertNotNull("Should have found body as a Map but was: " + ObjectHelper.className(in.getBody()), body);
+            assertEquals("NAME", expectedItemDesc[counter], body.get("NAME"));
+            LOG.info("Result: " + counter + " = " + body);
+            counter++;
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/954c068b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/StreamedSplitTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/StreamedSplitTest-context.xml b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/StreamedSplitTest-context.xml
new file mode 100644
index 0000000..2295fde
--- /dev/null
+++ b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/StreamedSplitTest-context.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="file://src/test/data/delim2?noop=true"/>
+
+      <unmarshal>
+        <flatpack/>
+      </unmarshal>
+
+      <split streaming="true">
+        <simple>${body}</simple>
+        <to uri="mock:results"/>
+      </split>
+    </route>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+
+</beans>