camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [02/10] camel git commit: CAMEL-10883: show that delayed payloads are not read correctly
Date Thu, 23 Feb 2017 09:03:38 GMT
CAMEL-10883: show that delayed payloads are not read correctly


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

Branch: refs/heads/master
Commit: 52803ab507292252373b3f49111a5c20866fcb4c
Parents: af0668a
Author: rohan <rohan.hart@fronde.com>
Authored: Tue Feb 21 11:30:20 2017 +1300
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Feb 23 10:00:23 2017 +0100

----------------------------------------------------------------------
 .../undertow/DefaultUndertowHttpBinding.java    |  2 +-
 .../DefaultUndertowHttpBindingTest.java         | 65 ++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/52803ab5/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
index 4e5fc3b..8c379d2 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
@@ -378,7 +378,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding
{
         return body;
     }
 
-    private byte[] readFromChannel(StreamSourceChannel source) throws IOException {
+    byte[] readFromChannel(StreamSourceChannel source) throws IOException {
         final ByteArrayOutputStream out = new ByteArrayOutputStream();
         final ByteBuffer buffer = ByteBuffer.wrap(new byte[1024]);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/52803ab5/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/DefaultUndertowHttpBindingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/DefaultUndertowHttpBindingTest.java
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/DefaultUndertowHttpBindingTest.java
new file mode 100644
index 0000000..9bd7cc7
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/DefaultUndertowHttpBindingTest.java
@@ -0,0 +1,65 @@
+package org.apache.camel.component.undertow;
+
+import org.junit.Test;
+import org.xnio.XnioIoThread;
+import org.xnio.channels.EmptyStreamSourceChannel;
+import org.xnio.channels.StreamSourceChannel;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class DefaultUndertowHttpBindingTest {
+
+    @Test
+    public void readEntireDelayedPayload() throws Exception {
+        byte[] delayedPayload = "first ".getBytes();
+
+        ExecutorService executor = Executors.newFixedThreadPool(1);
+        StreamSourceChannel source = new EmptyStreamSourceChannel(
+                new XnioIoThread(null, 0) {
+                    @Override
+                    public void execute(Runnable runnable) {
+                        executor.execute(runnable);
+                    }
+
+                    @Override
+                    public Key executeAfter(Runnable runnable, long l, TimeUnit timeUnit)
{
+                        execute(runnable);
+                        return null;
+                    }
+
+                    @Override
+                    public Key executeAtInterval(Runnable runnable, long l, TimeUnit timeUnit)
{
+                        execute(runnable);
+                        return null;
+                    }
+                }) {
+            int chunk = 0;
+
+            @Override
+            public int read(ByteBuffer dst) throws IOException {
+                switch (chunk) {
+                    case 0:
+                        chunk++;
+                        return 0;
+                    case 1:
+                        dst.put(delayedPayload);
+                        chunk++;
+                        return 6;
+                }
+                return -1;
+            }
+        };
+
+        DefaultUndertowHttpBinding binding = new DefaultUndertowHttpBinding();
+        byte[] result = binding.readFromChannel(source);
+
+        assertThat(result, is(delayedPayload));
+    }
+}
\ No newline at end of file


Mime
View raw message