You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2017/02/23 09:03:37 UTC
[01/10] camel git commit: CAMEL-10883: read payloads with a single
delay
Repository: camel
Updated Branches:
refs/heads/master af0668a03 -> 4ab39fc3b
CAMEL-10883: read payloads with a single delay
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c2ffb108
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c2ffb108
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c2ffb108
Branch: refs/heads/master
Commit: c2ffb1085508fbd8a29932841ee7abdfffc05d4c
Parents: 52803ab
Author: rohan <ro...@fronde.com>
Authored: Tue Feb 21 11:35:21 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:23 2017 +0100
----------------------------------------------------------------------
.../apache/camel/component/undertow/DefaultUndertowHttpBinding.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c2ffb108/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 8c379d2..adbe2dd 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
@@ -408,7 +408,6 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding {
}
});
source.resumeReads();
- return out.toByteArray();
} else {
buffer.flip();
out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.arrayOffset() + buffer.limit());
[07/10] camel git commit: CAMEL-10883: make stub source behave more
like the real HttpServerExchange class
Posted by ac...@apache.org.
CAMEL-10883: make stub source behave more like the real HttpServerExchange class
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/de3afdd0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/de3afdd0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/de3afdd0
Branch: refs/heads/master
Commit: de3afdd0f957da7f78cd7d9d7fe2cd97942a1637
Parents: 72bcb07
Author: rohan <ro...@fronde.com>
Authored: Tue Feb 21 15:24:24 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:25 2017 +0100
----------------------------------------------------------------------
.../undertow/DefaultUndertowHttpBindingTest.java | 10 ++++++++++
1 file changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/de3afdd0/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
index e8e1726..532ee9d 100644
--- 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
@@ -87,6 +87,16 @@ public class DefaultUndertowHttpBindingTest {
}
return 0;
}
+
+ @Override
+ public void resumeReads() {
+ /**
+ * {@link io.undertow.server.HttpServerExchange.ReadDispatchChannel} delays resumes in the main thread
+ */
+ if (sourceThread != Thread.currentThread()) {
+ super.resumeReads();
+ }
+ }
};
}
[08/10] camel git commit: CAMEL-10883: replace complex code with
standard blocking channel
Posted by ac...@apache.org.
CAMEL-10883: replace complex code with standard blocking channel
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/603467ef
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/603467ef
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/603467ef
Branch: refs/heads/master
Commit: 603467efbf45a3968631598d47b8f0ab5d7d57b0
Parents: 4196654
Author: rohan <ro...@fronde.com>
Authored: Tue Feb 21 15:47:24 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:26 2017 +0100
----------------------------------------------------------------------
.../undertow/DefaultUndertowHttpBinding.java | 45 +++-----------------
1 file changed, 6 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/603467ef/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 5aa774a..153279b 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
@@ -22,13 +22,12 @@ import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
import javax.activation.FileDataSource;
@@ -56,7 +55,7 @@ import org.apache.camel.util.MessageHelper;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.xnio.ChannelListener;
+import org.xnio.channels.BlockingReadableByteChannel;
import org.xnio.channels.StreamSourceChannel;
/**
@@ -384,46 +383,14 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteBuffer buffer = ByteBuffer.wrap(new byte[1024]);
+ ReadableByteChannel blockingSource = new BlockingReadableByteChannel(source);
+
for (;;) {
- int res = source.read(buffer);
+ int res = blockingSource.read(buffer);
if (res == -1) {
return out.toByteArray();
} else if (res == 0) {
- BlockingQueue<Integer> ping = new ArrayBlockingQueue<Integer>(1);
- source.getReadSetter().set(new ChannelListener<StreamSourceChannel>() {
- @Override
- public void handleEvent(StreamSourceChannel channel) {
- for (;;) {
- try {
- int res = channel.read(buffer);
- switch (res) {
- case -1:
- ping.put(res);
- return;
- case 0:
- // await next chunk
- source.getReadSetter().set(this);
- source.resumeReads();
- return;
- default:
- buffer.flip();
- out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.arrayOffset() + buffer.limit());
- buffer.clear();
- }
- } catch (IOException | InterruptedException e) {
- LOG.error("Exception reading from channel {}", e);
- }
- }
- }
- });
- source.resumeReads();
- try {
- // wait for the listener to complete
- ping.take();
- } catch (InterruptedException e) {
- LOG.error("Exception reading from channel {}", e);
- }
- return out.toByteArray();
+ LOG.error("Channel did not block");
} else {
buffer.flip();
out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.arrayOffset() + buffer.limit());
[05/10] camel git commit: CAMEL-10883: show that payloads with
multiple delays are not read also ensure that the main thread is not spinning
on read=0
Posted by ac...@apache.org.
CAMEL-10883: show that payloads with multiple delays are not read
also ensure that the main thread is not spinning on read=0
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dc42a59b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dc42a59b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dc42a59b
Branch: refs/heads/master
Commit: dc42a59b3eeefc304e7262ece0eb564c71a2f2a4
Parents: c2ffb10
Author: rohan <ro...@fronde.com>
Authored: Tue Feb 21 12:45:31 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:24 2017 +0100
----------------------------------------------------------------------
.../DefaultUndertowHttpBindingTest.java | 92 +++++++++++++-------
1 file changed, 62 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/dc42a59b/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
index 9bd7cc7..797196f 100644
--- 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
@@ -10,56 +10,88 @@ import java.nio.ByteBuffer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class DefaultUndertowHttpBindingTest {
- @Test
+ @Test(timeout = 1000)
public void readEntireDelayedPayload() throws Exception {
- byte[] delayedPayload = "first ".getBytes();
+ String[] delayedPayloads = new String[] {
+ "chunk",
+ };
- ExecutorService executor = Executors.newFixedThreadPool(1);
- StreamSourceChannel source = new EmptyStreamSourceChannel(
- new XnioIoThread(null, 0) {
- @Override
- public void execute(Runnable runnable) {
- executor.execute(runnable);
- }
+ StreamSourceChannel source = source(delayedPayloads);
- @Override
- public Key executeAfter(Runnable runnable, long l, TimeUnit timeUnit) {
- execute(runnable);
- return null;
- }
+ DefaultUndertowHttpBinding binding = new DefaultUndertowHttpBinding();
+ String result = new String(binding.readFromChannel(source));
- @Override
- public Key executeAtInterval(Runnable runnable, long l, TimeUnit timeUnit) {
- execute(runnable);
- return null;
- }
- }) {
+ assertThat(result, is(delayedPayloads[0]));
+ }
+
+ @Test(timeout = 1000)
+ public void readEntireMultiDelayedPayload() throws Exception {
+ String[] delayedPayloads = new String[] {
+ "first ",
+ "second",
+ };
+
+ StreamSourceChannel source = source(delayedPayloads);
+
+ DefaultUndertowHttpBinding binding = new DefaultUndertowHttpBinding();
+ String result = new String(binding.readFromChannel(source));
+
+ assertThat(result, is(
+ Stream.of(delayedPayloads)
+ .collect(Collectors.joining())));
+ }
+
+ private StreamSourceChannel source(final String[] delayedPayloads) {
+ XnioIoThread thread = thread();
+ Thread sourceThread = Thread.currentThread();
+
+ return new EmptyStreamSourceChannel(thread) {
int chunk = 0;
@Override
public int read(ByteBuffer dst) throws IOException {
- switch (chunk) {
- case 0:
- chunk++;
- return 0;
- case 1:
+ // can only read payloads in the reader thread
+ if (sourceThread != Thread.currentThread()) {
+ if (chunk < delayedPayloads.length) {
+ byte[] delayedPayload = delayedPayloads[chunk].getBytes();
dst.put(delayedPayload);
chunk++;
- return 6;
+ return delayedPayload.length;
+ }
+ return -1;
}
- return -1;
+ return 0;
}
};
+ }
- DefaultUndertowHttpBinding binding = new DefaultUndertowHttpBinding();
- byte[] result = binding.readFromChannel(source);
+ private XnioIoThread thread() {
+ ExecutorService executor = Executors.newFixedThreadPool(1);
+ return 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;
+ }
- assertThat(result, is(delayedPayload));
+ @Override
+ public Key executeAtInterval(Runnable runnable, long l, TimeUnit timeUnit) {
+ execute(runnable);
+ return null;
+ }
+ };
}
}
\ No newline at end of file
[10/10] camel git commit: CAMEL-10883: apply Camel checkstyle
Posted by ac...@apache.org.
CAMEL-10883: apply Camel checkstyle
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4ab39fc3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4ab39fc3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4ab39fc3
Branch: refs/heads/master
Commit: 4ab39fc3b54612e22fc14b3631b28d6e80d2d804
Parents: e997947
Author: rohan <ro...@fronde.com>
Authored: Wed Feb 22 09:24:14 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:26 2017 +0100
----------------------------------------------------------------------
.../DefaultUndertowHttpBindingTest.java | 48 +++++++++++++-------
1 file changed, 32 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4ab39fc3/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
index 4a4884b..ce3c65f 100644
--- 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
@@ -1,10 +1,21 @@
+/**
+ * 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.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;
@@ -13,6 +24,11 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.junit.Test;
+import org.xnio.XnioIoThread;
+import org.xnio.channels.EmptyStreamSourceChannel;
+import org.xnio.channels.StreamSourceChannel;
+
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
@@ -22,8 +38,8 @@ public class DefaultUndertowHttpBindingTest {
@Test(timeout = 1000)
public void readEntireDelayedPayload() throws Exception {
String[] delayedPayloads = new String[] {
- "",
- "chunk",
+ "",
+ "chunk",
};
StreamSourceChannel source = source(delayedPayloads);
@@ -37,9 +53,9 @@ public class DefaultUndertowHttpBindingTest {
@Test(timeout = 1000)
public void readEntireMultiDelayedPayload() throws Exception {
String[] delayedPayloads = new String[] {
- "",
- "first ",
- "second",
+ "",
+ "first ",
+ "second",
};
StreamSourceChannel source = source(delayedPayloads);
@@ -59,10 +75,10 @@ public class DefaultUndertowHttpBindingTest {
@Test(timeout = 1000)
public void readEntireMultiDelayedWithPausePayload() throws Exception {
String[] delayedPayloads = new String[] {
- "",
- "first ",
- "",
- "second",
+ "",
+ "first ",
+ "",
+ "second",
};
StreamSourceChannel source = source(delayedPayloads);
@@ -77,8 +93,8 @@ public class DefaultUndertowHttpBindingTest {
Thread sourceThread = Thread.currentThread();
return new EmptyStreamSourceChannel(thread()) {
- int chunk = 0;
- boolean mustWait = false; // make sure that the caller is not spinning on read==0
+ int chunk;
+ boolean mustWait; // make sure that the caller is not spinning on read==0
@Override
public int read(ByteBuffer dst) throws IOException {
[04/10] camel git commit: CAMEL-10883: read delayed payloads
Posted by ac...@apache.org.
CAMEL-10883: read delayed payloads
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/72bcb075
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/72bcb075
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/72bcb075
Branch: refs/heads/master
Commit: 72bcb07522bac6404cb7ee90d1332f3760a2eb62
Parents: 4c043a8
Author: rohan <ro...@fronde.com>
Authored: Tue Feb 21 15:11:22 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:24 2017 +0100
----------------------------------------------------------------------
.../undertow/DefaultUndertowHttpBinding.java | 32 +++++++++++++++-----
1 file changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/72bcb075/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 adbe2dd..5aa774a 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
@@ -27,6 +27,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
import javax.activation.FileDataSource;
@@ -387,27 +389,41 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding {
if (res == -1) {
return out.toByteArray();
} else if (res == 0) {
+ BlockingQueue<Integer> ping = new ArrayBlockingQueue<Integer>(1);
source.getReadSetter().set(new ChannelListener<StreamSourceChannel>() {
@Override
public void handleEvent(StreamSourceChannel channel) {
for (;;) {
try {
int res = channel.read(buffer);
- if (res == -1 || res == 0) {
- out.toByteArray();
- return;
- } else {
- buffer.flip();
- out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.arrayOffset() + buffer.limit());
- buffer.clear();
+ switch (res) {
+ case -1:
+ ping.put(res);
+ return;
+ case 0:
+ // await next chunk
+ source.getReadSetter().set(this);
+ source.resumeReads();
+ return;
+ default:
+ buffer.flip();
+ out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.arrayOffset() + buffer.limit());
+ buffer.clear();
}
- } catch (IOException e) {
+ } catch (IOException | InterruptedException e) {
LOG.error("Exception reading from channel {}", e);
}
}
}
});
source.resumeReads();
+ try {
+ // wait for the listener to complete
+ ping.take();
+ } catch (InterruptedException e) {
+ LOG.error("Exception reading from channel {}", e);
+ }
+ return out.toByteArray();
} else {
buffer.flip();
out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.arrayOffset() + buffer.limit());
[03/10] camel git commit: CAMEL-10883: show that payloads with
multiple pauses are not read correctly
Posted by ac...@apache.org.
CAMEL-10883: show that payloads with multiple pauses 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/4c043a8b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4c043a8b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4c043a8b
Branch: refs/heads/master
Commit: 4c043a8b6a174a90dd0767ba8e97bff86c7140b5
Parents: dc42a59
Author: rohan <ro...@fronde.com>
Authored: Tue Feb 21 14:24:42 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:24 2017 +0100
----------------------------------------------------------------------
.../DefaultUndertowHttpBindingTest.java | 21 ++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4c043a8b/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
index 797196f..e8e1726 100644
--- 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
@@ -49,11 +49,28 @@ public class DefaultUndertowHttpBindingTest {
.collect(Collectors.joining())));
}
+ @Test(timeout = 1000)
+ public void readEntireMultiDelayedWithPausePayload() throws Exception {
+ String[] delayedPayloads = new String[] {
+ "first ",
+ "",
+ "second",
+ };
+
+ StreamSourceChannel source = source(delayedPayloads);
+
+ DefaultUndertowHttpBinding binding = new DefaultUndertowHttpBinding();
+ String result = new String(binding.readFromChannel(source));
+
+ assertThat(result, is(
+ Stream.of(delayedPayloads)
+ .collect(Collectors.joining())));
+ }
+
private StreamSourceChannel source(final String[] delayedPayloads) {
- XnioIoThread thread = thread();
Thread sourceThread = Thread.currentThread();
- return new EmptyStreamSourceChannel(thread) {
+ return new EmptyStreamSourceChannel(thread()) {
int chunk = 0;
@Override
[06/10] camel git commit: CAMEL-10883: correct tests and ensure that
reader's wait for data
Posted by ac...@apache.org.
CAMEL-10883: correct tests and ensure that reader's wait for data
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4196654f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4196654f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4196654f
Branch: refs/heads/master
Commit: 4196654f91f540bc32465f24cc04c190a233f8b8
Parents: de3afdd
Author: rohan <ro...@fronde.com>
Authored: Tue Feb 21 15:44:46 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:25 2017 +0100
----------------------------------------------------------------------
.../DefaultUndertowHttpBindingTest.java | 41 +++++++++++++-------
1 file changed, 28 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4196654f/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
index 532ee9d..4a4884b 100644
--- 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
@@ -15,12 +15,14 @@ import java.util.stream.Stream;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
public class DefaultUndertowHttpBindingTest {
@Test(timeout = 1000)
public void readEntireDelayedPayload() throws Exception {
String[] delayedPayloads = new String[] {
+ "",
"chunk",
};
@@ -29,12 +31,13 @@ public class DefaultUndertowHttpBindingTest {
DefaultUndertowHttpBinding binding = new DefaultUndertowHttpBinding();
String result = new String(binding.readFromChannel(source));
- assertThat(result, is(delayedPayloads[0]));
+ checkResult(result, delayedPayloads);
}
@Test(timeout = 1000)
public void readEntireMultiDelayedPayload() throws Exception {
String[] delayedPayloads = new String[] {
+ "",
"first ",
"second",
};
@@ -44,6 +47,10 @@ public class DefaultUndertowHttpBindingTest {
DefaultUndertowHttpBinding binding = new DefaultUndertowHttpBinding();
String result = new String(binding.readFromChannel(source));
+ checkResult(result, delayedPayloads);
+ }
+
+ private void checkResult(String result, String[] delayedPayloads) {
assertThat(result, is(
Stream.of(delayedPayloads)
.collect(Collectors.joining())));
@@ -52,6 +59,7 @@ public class DefaultUndertowHttpBindingTest {
@Test(timeout = 1000)
public void readEntireMultiDelayedWithPausePayload() throws Exception {
String[] delayedPayloads = new String[] {
+ "",
"first ",
"",
"second",
@@ -62,9 +70,7 @@ public class DefaultUndertowHttpBindingTest {
DefaultUndertowHttpBinding binding = new DefaultUndertowHttpBinding();
String result = new String(binding.readFromChannel(source));
- assertThat(result, is(
- Stream.of(delayedPayloads)
- .collect(Collectors.joining())));
+ checkResult(result, delayedPayloads);
}
private StreamSourceChannel source(final String[] delayedPayloads) {
@@ -72,20 +78,23 @@ public class DefaultUndertowHttpBindingTest {
return new EmptyStreamSourceChannel(thread()) {
int chunk = 0;
+ boolean mustWait = false; // make sure that the caller is not spinning on read==0
@Override
public int read(ByteBuffer dst) throws IOException {
- // can only read payloads in the reader thread
- if (sourceThread != Thread.currentThread()) {
- if (chunk < delayedPayloads.length) {
- byte[] delayedPayload = delayedPayloads[chunk].getBytes();
- dst.put(delayedPayload);
- chunk++;
- return delayedPayload.length;
+ if (mustWait) {
+ fail("must wait before reading");
+ }
+ if (chunk < delayedPayloads.length) {
+ byte[] delayedPayload = delayedPayloads[chunk].getBytes();
+ dst.put(delayedPayload);
+ chunk++;
+ if (delayedPayload.length == 0) {
+ mustWait = true;
}
- return -1;
+ return delayedPayload.length;
}
- return 0;
+ return -1;
}
@Override
@@ -97,6 +106,12 @@ public class DefaultUndertowHttpBindingTest {
super.resumeReads();
}
}
+
+ @Override
+ public void awaitReadable() throws IOException {
+ mustWait = false;
+ super.awaitReadable();
+ }
};
}
[02/10] camel git commit: CAMEL-10883: show that delayed payloads are
not read correctly
Posted by ac...@apache.org.
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 <ro...@fronde.com>
Authored: Tue Feb 21 11:30:20 2017 +1300
Committer: Andrea Cosentino <an...@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
[09/10] camel git commit: CAMEL-10883: allow for 100-continue
processing
Posted by ac...@apache.org.
CAMEL-10883: allow for 100-continue processing
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e9979473
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e9979473
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e9979473
Branch: refs/heads/master
Commit: e997947396ee4e74aa4e715e7a28dab62627e7bf
Parents: 603467e
Author: rohan <ro...@fronde.com>
Authored: Tue Feb 21 16:16:31 2017 +1300
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Feb 23 10:00:26 2017 +0100
----------------------------------------------------------------------
.../org/apache/camel/component/undertow/UndertowConsumer.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e9979473/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
index 846fe63..817eb6e 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.undertow;
import java.io.IOException;
import java.nio.ByteBuffer;
+import io.undertow.Handlers;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.form.EagerFormParsingHandler;
@@ -77,8 +78,10 @@ public class UndertowConsumer extends DefaultConsumer implements HttpHandler {
}
public HttpHandler getHttpHandler() {
- // wrap with EagerFormParsingHandler to enable undertow form parsers
- return new EagerFormParsingHandler().setNext(this);
+ // allow for HTTP 1.1 continue
+ return Handlers.httpContinueRead(
+ // wrap with EagerFormParsingHandler to enable undertow form parsers
+ new EagerFormParsingHandler().setNext(this));
}
@Override