camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject camel git commit: CAMEL-8012: camel-stream's scanStream mode should read available lines before going into sleep (or delay)
Date Fri, 07 Nov 2014 14:51:23 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x 34a5ee903 -> dbc9d4e14


CAMEL-8012: camel-stream's scanStream mode should read available lines before going into sleep
(or delay)


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

Branch: refs/heads/camel-2.14.x
Commit: dbc9d4e14bce6cb19ff2166d8297ade41efcfb9a
Parents: 34a5ee9
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Fri Nov 7 15:49:04 2014 +0100
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Fri Nov 7 15:51:00 2014 +0100

----------------------------------------------------------------------
 .../camel/component/stream/StreamConsumer.java  | 13 ++--
 .../component/stream/ScanStreamDelayTest.java   | 73 ++++++++++++++++++++
 2 files changed, 81 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dbc9d4e1/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
b/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
index 60b0603..5c32a64 100644
--- a/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
+++ b/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
@@ -136,11 +136,14 @@ public class StreamConsumer extends DefaultConsumer implements Runnable
{
                     //try and re-open stream
                     br = initializeStream();
                 }
-                try {
-                    Thread.sleep(endpoint.getScanStreamDelay());
-                } catch (InterruptedException e) {
-                    Thread.currentThread().interrupt();
-                    break;
+                // sleep only if there is no input
+                if (eos) {
+                    try {
+                        Thread.sleep(endpoint.getScanStreamDelay());
+                    } catch (InterruptedException e) {
+                        Thread.currentThread().interrupt();
+                        break;
+                    }
                 }
             }
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/dbc9d4e1/components/camel-stream/src/test/java/org/apache/camel/component/stream/ScanStreamDelayTest.java
----------------------------------------------------------------------
diff --git a/components/camel-stream/src/test/java/org/apache/camel/component/stream/ScanStreamDelayTest.java
b/components/camel-stream/src/test/java/org/apache/camel/component/stream/ScanStreamDelayTest.java
new file mode 100644
index 0000000..af562ee
--- /dev/null
+++ b/components/camel-stream/src/test/java/org/apache/camel/component/stream/ScanStreamDelayTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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.stream;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class ScanStreamDelayTest extends CamelTestSupport {
+
+
+    private File file;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        deleteDirectory("target/stream");
+        createDirectory("target/stream");
+
+        file = new File("target/stream/scanstreamdelayfile.txt");
+        file.createNewFile();
+        FileOutputStream fos = new FileOutputStream(file);
+        fos.write("Hello\n".getBytes());
+        fos.write("World\n".getBytes());
+        fos.write("Hello\n".getBytes());
+        fos.write("World\n".getBytes());
+        fos.write("Hello\n".getBytes());
+        fos.write("World\n".getBytes());
+        fos.close();
+
+        super.setUp();
+    }
+
+    @Test
+    public void testScanFile() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(6);
+        assertMockEndpointsSatisfied(1, TimeUnit.SECONDS);
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("stream:file?fileName=target/stream/scanstreamdelayfile.txt&scanStream=true&scanStreamDelay=1000")
+                    .to("mock:result");
+            }
+        };
+    }
+}


Mime
View raw message