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 2015/01/23 18:20:31 UTC
[2/2] qpid-jms git commit: Test URI option handling and error
processing.
Test URI option handling and error processing.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/b88ad669
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/b88ad669
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/b88ad669
Branch: refs/heads/master
Commit: b88ad6698817ba15065b1f8f9e7edc8af5ae2c75
Parents: f6d8463
Author: Timothy Bish <ta...@gmail.com>
Authored: Fri Jan 23 12:20:04 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Fri Jan 23 12:20:04 2015 -0500
----------------------------------------------------------------------
.../netty/NettySslTransportFactoryTest.java | 117 ++++++++++++++
.../netty/NettyTcpTransportFactoryTest.java | 159 +++++++++++++++++++
2 files changed, 276 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b88ad669/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportFactoryTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportFactoryTest.java
new file mode 100644
index 0000000..8b98c4c
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportFactoryTest.java
@@ -0,0 +1,117 @@
+/**
+ * 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.qpid.jms.transports.netty;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
+import org.apache.qpid.jms.transports.Transport;
+import org.apache.qpid.jms.transports.TransportOptions;
+import org.junit.Test;
+
+/**
+ * Test the NettyTcpTransportFactory class
+ */
+public class NettySslTransportFactoryTest {
+
+ public static final int CUSTOM_SEND_BUFFER_SIZE = 32 * 1024;
+ public static final int CUSTOM_RECEIVE_BUFFER_SIZE = CUSTOM_SEND_BUFFER_SIZE;
+ public static final int CUSTOM_TRAFFIC_CLASS = 1;
+ public static final boolean CUSTOM_TCP_NO_DELAY = false;
+ public static final boolean CUSTOM_TCP_KEEP_ALIVE = true;
+ public static final int CUSTOM_SO_LINGER = Short.MIN_VALUE;
+ public static final int CUSTOM_SO_TIMEOUT = 10;
+ public static final int CUSTOM_CONNECT_TIMEOUT = 90000;
+
+ @Test
+ public void testCreateWithDefaultOptions() throws Exception {
+ URI BASE_URI = new URI("tcp://localhost:5672");
+
+ NettyTcpTransportFactory factory = new NettyTcpTransportFactory();
+
+ Transport transport = factory.createTransport(BASE_URI);
+
+ assertNotNull(transport);
+ assertTrue(transport instanceof NettyTcpTransport);
+ assertFalse(transport.isConnected());
+
+ TransportOptions options = transport.getTransportOptions();
+ assertNotNull(options);
+
+ assertEquals(TransportOptions.DEFAULT_CONNECT_TIMEOUT, options.getConnectTimeout());
+ assertEquals(TransportOptions.DEFAULT_SEND_BUFFER_SIZE, options.getSendBufferSize());
+ assertEquals(TransportOptions.DEFAULT_RECEIVE_BUFFER_SIZE, options.getReceiveBufferSize());
+ assertEquals(TransportOptions.DEFAULT_TRAFFIC_CLASS, options.getTrafficClass());
+ assertEquals(TransportOptions.DEFAULT_TCP_NO_DELAY, options.isTcpNoDelay());
+ assertEquals(TransportOptions.DEFAULT_TCP_KEEP_ALIVE, options.isTcpKeepAlive());
+ assertEquals(TransportOptions.DEFAULT_SO_LINGER, options.getSoLinger());
+ assertEquals(TransportOptions.DEFAULT_SO_TIMEOUT, options.getSoTimeout());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCreateWithUnknownOption() throws Exception {
+ URI BASE_URI = new URI("tcp://localhost:5672?transport.someOption=true");
+ NettyTcpTransportFactory factory = new NettyTcpTransportFactory();
+ factory.createTransport(BASE_URI);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCreateWithBadOption() throws Exception {
+ URI BASE_URI = new URI("tcp://localhost:5672?transport.trafficClass=4096");
+ NettyTcpTransportFactory factory = new NettyTcpTransportFactory();
+ factory.createTransport(BASE_URI);
+ }
+
+ @Test
+ public void testCreateWithCustomOptions() throws Exception {
+ URI BASE_URI = new URI("tcp://localhost:5672");
+
+ URI configuredURI = new URI(BASE_URI.toString() + "?" +
+ "transport.connectTimeout=" + CUSTOM_CONNECT_TIMEOUT + "&" +
+ "transport.sendBufferSize=" + CUSTOM_SEND_BUFFER_SIZE + "&" +
+ "transport.receiveBufferSize=" + CUSTOM_RECEIVE_BUFFER_SIZE + "&" +
+ "transport.trafficClass=" + CUSTOM_TRAFFIC_CLASS + "&" +
+ "transport.tcpNoDelay=" + CUSTOM_TCP_NO_DELAY + "&" +
+ "transport.tcpKeepAlive=" + CUSTOM_TCP_KEEP_ALIVE + "&" +
+ "transport.soLinger=" + CUSTOM_SO_LINGER + "&" +
+ "transport.soTimeout=" + CUSTOM_SO_TIMEOUT);
+
+ NettyTcpTransportFactory factory = new NettyTcpTransportFactory();
+
+ Transport transport = factory.createTransport(configuredURI);
+
+ assertNotNull(transport);
+ assertTrue(transport instanceof NettyTcpTransport);
+ assertFalse(transport.isConnected());
+
+ TransportOptions options = transport.getTransportOptions();
+ assertNotNull(options);
+
+ assertEquals(CUSTOM_CONNECT_TIMEOUT, options.getConnectTimeout());
+ assertEquals(CUSTOM_SEND_BUFFER_SIZE, options.getSendBufferSize());
+ assertEquals(CUSTOM_RECEIVE_BUFFER_SIZE, options.getReceiveBufferSize());
+ assertEquals(CUSTOM_TRAFFIC_CLASS, options.getTrafficClass());
+ assertEquals(CUSTOM_TCP_NO_DELAY, options.isTcpNoDelay());
+ assertEquals(CUSTOM_TCP_KEEP_ALIVE, options.isTcpKeepAlive());
+ assertEquals(CUSTOM_SO_LINGER, options.getSoLinger());
+ assertEquals(CUSTOM_SO_TIMEOUT, options.getSoTimeout());
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b88ad669/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportFactoryTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportFactoryTest.java
new file mode 100644
index 0000000..ebe71ad
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportFactoryTest.java
@@ -0,0 +1,159 @@
+/**
+ * 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.qpid.jms.transports.netty;
+
+import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.qpid.jms.transports.Transport;
+import org.apache.qpid.jms.transports.TransportOptions;
+import org.apache.qpid.jms.transports.TransportSslOptions;
+import org.junit.Test;
+
+/**
+ * Test the NettyTcpTransportFactory class
+ */
+public class NettyTcpTransportFactoryTest {
+
+ public static final int CUSTOM_SEND_BUFFER_SIZE = 32 * 1024;
+ public static final int CUSTOM_RECEIVE_BUFFER_SIZE = CUSTOM_SEND_BUFFER_SIZE;
+ public static final int CUSTOM_TRAFFIC_CLASS = 1;
+ public static final boolean CUSTOM_TCP_NO_DELAY = false;
+ public static final boolean CUSTOM_TCP_KEEP_ALIVE = true;
+ public static final int CUSTOM_SO_LINGER = Short.MIN_VALUE;
+ public static final int CUSTOM_SO_TIMEOUT = 10;
+ public static final int CUSTOM_CONNECT_TIMEOUT = 90000;
+ public static final String[] CUSTOM_ENABLED_PROTOCOLS = {"TLSv1.1", "TLSv1.2"};
+ public static final String[] CUSTOM_ENABLED_CIPHER_SUITES = {"Suite-1", "Suite-2"};
+ public static final String CUSTOM_STORE_TYPE = "jceks";
+ public static final boolean CUSTOM_TRUST_ALL = true;
+ public static final boolean CUSTOM_VERIFY_HOST = true;
+
+ @Test
+ public void testCreateWithDefaultOptions() throws Exception {
+ URI BASE_URI = new URI("ssl://localhost:5672");
+
+ NettySslTransportFactory factory = new NettySslTransportFactory();
+
+ Transport transport = factory.createTransport(BASE_URI);
+
+ assertNotNull(transport);
+ assertTrue(transport instanceof NettySslTransport);
+ assertFalse(transport.isConnected());
+
+ TransportOptions options = transport.getTransportOptions();
+ assertNotNull(options);
+
+ assertEquals(TransportOptions.DEFAULT_CONNECT_TIMEOUT, options.getConnectTimeout());
+ assertEquals(TransportOptions.DEFAULT_SEND_BUFFER_SIZE, options.getSendBufferSize());
+ assertEquals(TransportOptions.DEFAULT_RECEIVE_BUFFER_SIZE, options.getReceiveBufferSize());
+ assertEquals(TransportOptions.DEFAULT_TRAFFIC_CLASS, options.getTrafficClass());
+ assertEquals(TransportOptions.DEFAULT_TCP_NO_DELAY, options.isTcpNoDelay());
+ assertEquals(TransportOptions.DEFAULT_TCP_KEEP_ALIVE, options.isTcpKeepAlive());
+ assertEquals(TransportOptions.DEFAULT_SO_LINGER, options.getSoLinger());
+ assertEquals(TransportOptions.DEFAULT_SO_TIMEOUT, options.getSoTimeout());
+
+ assertTrue(options instanceof TransportSslOptions);
+ TransportSslOptions sslOptions = (TransportSslOptions) options;
+
+ List<String> enabledProtocols = Arrays.asList(sslOptions.getEnabledProtocols());
+ List<String> defaultProtocols = Arrays.asList(TransportSslOptions.DEFAULT_ENABLED_PROTOCOLS);
+ assertThat(enabledProtocols, containsInAnyOrder(defaultProtocols.toArray()));
+
+ assertNull(sslOptions.getEnabledCipherSuites());
+
+ assertEquals(TransportSslOptions.DEFAULT_STORE_TYPE, sslOptions.getStoreType());
+ assertEquals(TransportSslOptions.DEFAULT_VERIFY_HOST, sslOptions.isVerifyHost());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCreateWithUnknownOption() throws Exception {
+ URI BASE_URI = new URI("ssl://localhost:5672?transport.someOption=true");
+ NettySslTransportFactory factory = new NettySslTransportFactory();
+ factory.createTransport(BASE_URI);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCreateWithBadOption() throws Exception {
+ URI BASE_URI = new URI("ssl://localhost:5672?transport.trafficClass=4096");
+ NettySslTransportFactory factory = new NettySslTransportFactory();
+ factory.createTransport(BASE_URI);
+ }
+
+ @Test
+ public void testCreateWithCustomOptions() throws Exception {
+ URI BASE_URI = new URI("tcp://localhost:5672");
+
+ URI configuredURI = new URI(BASE_URI.toString() + "?" +
+ "transport.connectTimeout=" + CUSTOM_CONNECT_TIMEOUT + "&" +
+ "transport.sendBufferSize=" + CUSTOM_SEND_BUFFER_SIZE + "&" +
+ "transport.receiveBufferSize=" + CUSTOM_RECEIVE_BUFFER_SIZE + "&" +
+ "transport.trafficClass=" + CUSTOM_TRAFFIC_CLASS + "&" +
+ "transport.tcpNoDelay=" + CUSTOM_TCP_NO_DELAY + "&" +
+ "transport.tcpKeepAlive=" + CUSTOM_TCP_KEEP_ALIVE + "&" +
+ "transport.soLinger=" + CUSTOM_SO_LINGER + "&" +
+ "transport.soTimeout=" + CUSTOM_SO_TIMEOUT + "&" +
+ "transport.verifyHost=" + CUSTOM_VERIFY_HOST + "&" +
+ "transport.storeType=" + CUSTOM_STORE_TYPE + "&" +
+ "transport.trustAll=" + CUSTOM_TRUST_ALL + "&" +
+ "transport.enabledProtocols=" + CUSTOM_ENABLED_PROTOCOLS + "&" +
+ "transport.enabledCipherSuites=" + CUSTOM_ENABLED_CIPHER_SUITES);
+
+ NettySslTransportFactory factory = new NettySslTransportFactory();
+
+ Transport transport = factory.createTransport(configuredURI);
+
+ assertNotNull(transport);
+ assertTrue(transport instanceof NettySslTransport);
+ assertFalse(transport.isConnected());
+
+ TransportOptions options = transport.getTransportOptions();
+ assertNotNull(options);
+
+ assertEquals(CUSTOM_CONNECT_TIMEOUT, options.getConnectTimeout());
+ assertEquals(CUSTOM_SEND_BUFFER_SIZE, options.getSendBufferSize());
+ assertEquals(CUSTOM_RECEIVE_BUFFER_SIZE, options.getReceiveBufferSize());
+ assertEquals(CUSTOM_TRAFFIC_CLASS, options.getTrafficClass());
+ assertEquals(CUSTOM_TCP_NO_DELAY, options.isTcpNoDelay());
+ assertEquals(CUSTOM_TCP_KEEP_ALIVE, options.isTcpKeepAlive());
+ assertEquals(CUSTOM_SO_LINGER, options.getSoLinger());
+ assertEquals(CUSTOM_SO_TIMEOUT, options.getSoTimeout());
+
+ assertTrue(options instanceof TransportSslOptions);
+ TransportSslOptions sslOptions = (TransportSslOptions) options;
+
+ List<String> enabledProtocols = Arrays.asList(sslOptions.getEnabledProtocols());
+ List<String> customProtocols = Arrays.asList(CUSTOM_ENABLED_PROTOCOLS);
+ assertThat(enabledProtocols, containsInAnyOrder(customProtocols.toArray()));
+
+ List<String> enabledCipherSuites = Arrays.asList(sslOptions.getEnabledCipherSuites());
+ List<String> customChiperSuites = Arrays.asList(CUSTOM_ENABLED_CIPHER_SUITES);
+ assertThat(enabledCipherSuites, containsInAnyOrder(customChiperSuites.toArray()));
+
+ assertEquals(CUSTOM_STORE_TYPE, sslOptions.getStoreType());
+ assertEquals(CUSTOM_VERIFY_HOST, sslOptions.isVerifyHost());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org