You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2013/08/14 23:43:59 UTC

git commit: Added a test based on a user-forum issue.

Updated Branches:
  refs/heads/master 7173865d8 -> 2601e5602


Added a test based on a user-forum issue.

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

Branch: refs/heads/master
Commit: 2601e560289162fdd8a4f23cb83fd1731d7fcb0a
Parents: 7173865
Author: Babak Vahdat <bv...@apache.org>
Authored: Wed Aug 14 23:43:55 2013 +0200
Committer: Babak Vahdat <bv...@apache.org>
Committed: Wed Aug 14 23:43:55 2013 +0200

----------------------------------------------------------------------
 .../NettyMultipleSimultaneousClientsTest.java   | 96 ++++++++++++++++++++
 1 file changed, 96 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2601e560/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyMultipleSimultaneousClientsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyMultipleSimultaneousClientsTest.java b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyMultipleSimultaneousClientsTest.java
new file mode 100644
index 0000000..c55b0a2
--- /dev/null
+++ b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyMultipleSimultaneousClientsTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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.netty;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class NettyMultipleSimultaneousClientsTest extends BaseNettyTest {
+
+    private String uri = "netty:tcp://localhost:{{port}}?sync=true&reuseAddress=true&synchronous=false";
+    private int clientCount = 20;
+    private CountDownLatch startLatch = new CountDownLatch(1);
+    private CountDownLatch finishLatch = new CountDownLatch(clientCount);
+
+    @Test
+    public void testSimultaneousClients() throws Exception {
+        ExecutorService executorService = Executors.newFixedThreadPool(clientCount);
+        Future<?>[] replies = new Future[clientCount];
+
+        for (int i = 0; i < clientCount; i++) {
+            replies[i] = executorService.submit(new Callable<Object>() {
+                @Override
+                public Object call() throws Exception {
+                    // wait until we're permitted to start
+                    startLatch.await();
+
+                    Object reply = template.requestBody(uri, "World");
+
+                    // signal that we're now done
+                    finishLatch.countDown();
+
+                    return reply;
+                }
+            });
+        }
+
+        Object[] expectedReplies = new Object[clientCount];
+        for (int i = 0; i < clientCount; i++) {
+            expectedReplies[i] = "Bye World";
+        }
+        getMockEndpoint("mock:result").expectedMessageCount(clientCount);
+        getMockEndpoint("mock:result").expectedBodiesReceived(expectedReplies);
+
+        // fire the simultaneous client calls
+        startLatch.countDown();
+
+        // and wait long enough until they're all done
+        assertTrue("Waiting on the latch ended up with a timeout!", finishLatch.await(5, TimeUnit.SECONDS));
+
+        // shutdown the thread pool as the finishLatch above has already guaranteed the completion of all the tasks
+        executorService.shutdown();
+
+        // assert on what we expect to receive
+        for (int i = 0; i < clientCount; i++) {
+            assertEquals("Bye World", replies[i].get());
+        }
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(uri)
+                    .log("${body}")
+                    .transform(body().prepend("Bye "))
+                    .to("mock:result");
+            }
+        };
+    }
+}