You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2017/04/03 20:27:22 UTC

qpid-jms git commit: QPIDJMS-279 Test for NettyTcpTransport honoring useEpoll option

Repository: qpid-jms
Updated Branches:
  refs/heads/master a2fd5f165 -> 6c2a7c144


QPIDJMS-279 Test for NettyTcpTransport honoring useEpoll option

Add a test that will run on platforms that support Epoll to check that
the transport honors the useEpoll TransportOption.

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/6c2a7c14
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/6c2a7c14
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/6c2a7c14

Branch: refs/heads/master
Commit: 6c2a7c144df265185ce1579ee723d2f789c48386
Parents: a2fd5f1
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Apr 3 16:27:13 2017 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Apr 3 16:27:13 2017 -0400

----------------------------------------------------------------------
 .../transports/netty/NettyTcpTransportTest.java | 59 ++++++++++++++++++++
 1 file changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6c2a7c14/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
index 2f42dd8..7183ecf 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
@@ -22,8 +22,10 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
 
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
@@ -40,6 +42,8 @@ import org.slf4j.LoggerFactory;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
+import io.netty.channel.epoll.Epoll;
+import io.netty.channel.epoll.EpollEventLoopGroup;
 
 /**
  * Test basic functionality of the Netty based TCP transport.
@@ -462,6 +466,61 @@ public class NettyTcpTransportTest extends QpidJmsTestCase {
         }
     }
 
+    @Test(timeout = 60 * 1000)
+    public void testConnectToServerWithEpollEnabled() throws Exception {
+        doTestEpollSupport(true);
+    }
+
+    @Test(timeout = 60 * 1000)
+    public void testConnectToServerWithEpollDisabled() throws Exception {
+        doTestEpollSupport(false);
+    }
+
+    private void doTestEpollSupport(boolean useEpoll) throws Exception {
+        assumeTrue(Epoll.isAvailable());
+
+        try (NettyEchoServer server = createEchoServer(createServerOptions())) {
+            server.start();
+
+            int port = server.getServerPort();
+            URI serverLocation = new URI("tcp://localhost:" + port);
+
+            TransportOptions options = createClientOptions();
+            options.setUseEpoll(useEpoll);
+
+            Transport transport = createTransport(serverLocation, testListener, options);
+            try {
+                transport.connect(null);
+                LOG.info("Connected to server:{} as expected.", serverLocation);
+            } catch (Exception e) {
+                fail("Should have connected to the server at " + serverLocation + " but got exception: " + e);
+            }
+
+            assertTrue(transport.isConnected());
+            assertEquals(serverLocation, transport.getRemoteLocation());
+            assertEpoll("Transport should be using Epoll", useEpoll, transport);
+
+            transport.close();
+
+            // Additional close should not fail or cause other problems.
+            transport.close();
+        }
+
+        assertTrue(!transportClosed);  // Normal shutdown does not trigger the event.
+        assertTrue(exceptions.isEmpty());
+        assertTrue(data.isEmpty());
+    }
+
+    private void assertEpoll(String message, boolean expected, Transport transport) throws Exception {
+        Field group = transport.getClass().getDeclaredField("group");
+        group.setAccessible(true);
+        if (expected) {
+            assertTrue(message, group.get(transport) instanceof EpollEventLoopGroup);
+        } else {
+            assertFalse(message, group.get(transport) instanceof EpollEventLoopGroup);
+        }
+    }
+
     protected Transport createTransport(URI serverLocation, TransportListener listener, TransportOptions options) {
         if (listener == null) {
             return new NettyTcpTransport(serverLocation, options);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org