You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ay...@apache.org on 2014/11/07 15:49:57 UTC
camel git commit: CAMEL-8012: camel-stream's scanStream mode should
read available lines before going into sleep (or delay)
Repository: camel
Updated Branches:
refs/heads/master f4886f8c8 -> a770bbb24
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/a770bbb2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a770bbb2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a770bbb2
Branch: refs/heads/master
Commit: a770bbb24ef2fb2fc371036af6b229bd17dc8074
Parents: f4886f8
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:49:48 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/a770bbb2/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/a770bbb2/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");
+ }
+ };
+ }
+}