activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject [2/2] activemq git commit: https://issues.apache.org/jira/browse/AMQ-6414
Date Tue, 06 Sep 2016 14:19:36 GMT
https://issues.apache.org/jira/browse/AMQ-6414

Changing the nio+ssl transports to trigger a serviceRead after start up
to prevent blocking. The prevents the channels from not reading in
certain cases, most notably with the auto+nio+ssl transport when used
for a network bridge.  Also added a couple tests and changed a network
bridge test to test out auto+nio+ssl.

(cherry picked from commit ed0e786b6002633411037923fb28a075489e442b)


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/679f0cfd
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/679f0cfd
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/679f0cfd

Branch: refs/heads/activemq-5.14.x
Commit: 679f0cfd311c362aa7821763067d9c9fa9bdc801
Parents: fb24b48
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Wed Aug 31 09:46:50 2016 -0400
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Tue Sep 6 10:19:20 2016 -0400

----------------------------------------------------------------------
 .../transport/amqp/AmqpNioSslTransport.java     |  5 +-
 .../transport/nio/AutoInitNioSSLTransport.java  |  2 +-
 .../activemq/transport/nio/NIOSSLTransport.java | 29 +++++-
 .../transport/mqtt/MQTTNIOSSLTransport.java     |  1 +
 .../transport/stomp/StompNIOSSLTransport.java   |  2 +-
 .../network/DurableSyncNetworkBridgeTest.java   | 20 ++++-
 .../openwire/OpenWireConnectionTimeoutTest.java | 31 ++++++-
 .../usecases/NetworkAsyncStartTest.java         | 92 +++++++++++++++++++-
 8 files changed, 165 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/679f0cfd/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
----------------------------------------------------------------------
diff --git a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
index 88d9284..fb19866 100644
--- a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
+++ b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
@@ -69,12 +69,11 @@ public class AmqpNioSslTransport extends NIOSSLTransport {
      */
 
     @Override
-    protected void doInit() {
+    protected void doInit() throws Exception {
         if (initBuffer != null) {
             nextFrameSize = -1;
-            serviceRead();
-
         }
+        super.doInit();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/activemq/blob/679f0cfd/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java
b/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java
index 9b7a579..0bf4145 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java
@@ -118,7 +118,7 @@ public class AutoInitNioSSLTransport extends NIOSSLTransport {
             sslEngine.beginHandshake();
             handshakeStatus = sslEngine.getHandshakeStatus();
             doHandshake();
-           // detectReadyState();
+
         } catch (Exception e) {
             try {
                 if(outputStream != null) {

http://git-wip-us.apache.org/repos/asf/activemq/blob/679f0cfd/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java
b/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java
index 97148ac..3bceb0e 100644
--- a/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java
+++ b/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java
@@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.security.cert.X509Certificate;
+import java.util.concurrent.CountDownLatch;
 
 import javax.net.SocketFactory;
 import javax.net.ssl.SSLContext;
@@ -159,6 +160,11 @@ public class NIOSSLTransport extends NIOTransport {
             selection = SelectorManager.getInstance().register(channel, new SelectorManager.Listener()
{
                 @Override
                 public void onSelect(SelectorSelection selection) {
+                    try {
+                        initialized.await();
+                    } catch (InterruptedException error) {
+                        onException(IOExceptionSupport.create(error));
+                    }
                     serviceRead();
                 }
 
@@ -184,13 +190,28 @@ public class NIOSSLTransport extends NIOTransport {
         }
     }
 
-    protected void doInit() throws Exception {
+    final protected CountDownLatch initialized = new CountDownLatch(1);
 
+    protected void doInit() throws Exception {
+        taskRunnerFactory.execute(new Runnable() {
+
+            @Override
+            public void run() {
+                //Need to start in new thread to let startup finish first
+                //We can trigger a read because we know the channel is ready since the SSL
handshake
+                //already happened
+                serviceRead();
+                initialized.countDown();
+            }
+        });
     }
 
+    //Only used for the auto transport to abort the openwire init method early if already
initialized
+    boolean openWireInititialized = false;
+
     protected void doOpenWireInit() throws Exception {
         //Do this later to let wire format negotiation happen
-        if (initBuffer != null && this.wireFormat instanceof OpenWireFormat) {
+        if (initBuffer != null && !openWireInititialized && this.wireFormat
instanceof OpenWireFormat) {
             initBuffer.buffer.flip();
             if (initBuffer.buffer.hasRemaining()) {
                 nextFrameSize = -1;
@@ -198,6 +219,7 @@ public class NIOSSLTransport extends NIOTransport {
                 processCommand(initBuffer.buffer);
                 processCommand(initBuffer.buffer);
                 initBuffer.buffer.clear();
+                openWireInititialized = true;
             }
         }
     }
@@ -460,6 +482,8 @@ public class NIOSSLTransport extends NIOTransport {
 
     @Override
     protected void doStop(ServiceStopper stopper) throws Exception {
+        initialized.countDown();
+
         if (taskRunnerFactory != null) {
             taskRunnerFactory.shutdownNow();
             taskRunnerFactory = null;
@@ -489,6 +513,7 @@ public class NIOSSLTransport extends NIOTransport {
     /**
      * @return peer certificate chain associated with the ssl socket
      */
+    @Override
     public X509Certificate[] getPeerCertificates() {
 
         X509Certificate[] clientCertChain = null;

http://git-wip-us.apache.org/repos/asf/activemq/blob/679f0cfd/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTNIOSSLTransport.java
----------------------------------------------------------------------
diff --git a/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTNIOSSLTransport.java
b/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTNIOSSLTransport.java
index 0d3a838..986c114 100644
--- a/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTNIOSSLTransport.java
+++ b/activemq-mqtt/src/main/java/org/apache/activemq/transport/mqtt/MQTTNIOSSLTransport.java
@@ -74,6 +74,7 @@ public class MQTTNIOSSLTransport extends NIOSSLTransport {
             initBuffer.buffer.flip();
             processCommand(initBuffer.buffer);
         }
+        super.doInit();
     }
 
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/679f0cfd/activemq-stomp/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransport.java
----------------------------------------------------------------------
diff --git a/activemq-stomp/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransport.java
b/activemq-stomp/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransport.java
index f583533..09757a4 100644
--- a/activemq-stomp/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransport.java
+++ b/activemq-stomp/src/main/java/org/apache/activemq/transport/stomp/StompNIOSSLTransport.java
@@ -87,10 +87,10 @@ public class StompNIOSSLTransport extends NIOSSLTransport {
     protected void doInit() throws Exception {
         if (initBuffer != null) {
             nextFrameSize = -1;
-           // System.out.println("length1: " + initBuffer.array().length);
             receiveCounter += initBuffer.readSize;
             initBuffer.buffer.flip();
             processCommand(initBuffer.buffer);
         }
+        super.doInit();
     }
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/679f0cfd/activemq-unit-tests/src/test/java/org/apache/activemq/network/DurableSyncNetworkBridgeTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/DurableSyncNetworkBridgeTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/network/DurableSyncNetworkBridgeTest.java
index f3314cc..67e9e24 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/DurableSyncNetworkBridgeTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/DurableSyncNetworkBridgeTest.java
@@ -77,6 +77,20 @@ public class DurableSyncNetworkBridgeTest extends DynamicNetworkTestSupport
{
         });
     }
 
+    public static final String KEYSTORE_TYPE = "jks";
+    public static final String PASSWORD = "password";
+    public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore";
+    public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
+
+    static {
+        System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
+        System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
+        System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
+        System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
+        System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
+        System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);
+    }
+
 
     public DurableSyncNetworkBridgeTest(final FLOW flow) {
         this.flow = flow;
@@ -492,7 +506,8 @@ public class DurableSyncNetworkBridgeTest extends DynamicNetworkTestSupport
{
             brokerService.addNetworkConnector(configureLocalNetworkConnector());
         }
 
-        brokerService.addConnector("tcp://localhost:0");
+        //Use auto+nio+ssl to test out the transport works with bridging
+        brokerService.addConnector("auto+nio+ssl://localhost:0");
 
         return brokerService;
     }
@@ -531,7 +546,8 @@ public class DurableSyncNetworkBridgeTest extends DynamicNetworkTestSupport
{
         remoteAdvisoryBroker = (AdvisoryBroker) brokerService.getBroker().getAdaptor(AdvisoryBroker.class);
 
         //Need a larger cache size in order to handle all of the durables
-        brokerService.addConnector("tcp://localhost:" + port + "?wireFormat.cacheSize=2048&wireFormat.version="
+ remoteBrokerWireFormatVersion);
+        //Use auto+nio+ssl to test out the transport works with bridging
+        brokerService.addConnector("auto+nio+ssl://localhost:" + port + "?wireFormat.cacheSize=2048&wireFormat.version="
+ remoteBrokerWireFormatVersion);
 
         return brokerService;
     }

http://git-wip-us.apache.org/repos/asf/activemq/blob/679f0cfd/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/OpenWireConnectionTimeoutTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/OpenWireConnectionTimeoutTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/OpenWireConnectionTimeoutTest.java
index 28e0989..dc1c43b 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/OpenWireConnectionTimeoutTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/OpenWireConnectionTimeoutTest.java
@@ -38,6 +38,7 @@ import javax.net.ssl.X509TrustManager;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.TransportConnector;
 import org.apache.activemq.spring.SpringSslContext;
+import org.apache.activemq.transport.tcp.TcpTransportServer;
 import org.apache.activemq.util.Wait;
 import org.junit.After;
 import org.junit.Before;
@@ -73,7 +74,11 @@ public class OpenWireConnectionTimeoutTest {
                 {"tcp"},
                 {"ssl"},
                 {"nio"},
-                {"nio+ssl"}
+                {"nio+ssl"},
+                {"auto"},
+                {"auto+ssl"},
+                {"auto+nio"},
+                {"auto+nio+ssl"}
             });
     }
 
@@ -111,7 +116,7 @@ public class OpenWireConnectionTimeoutTest {
     }
 
     public String getAdditionalConfig() {
-        return "?transport.connectAttemptTimeout=1200";
+        return "?transport.connectAttemptTimeout=1200&protocolDetectionTimeOut=1200";
     }
 
     @Test(timeout = 90000)
@@ -137,7 +142,8 @@ public class OpenWireConnectionTimeoutTest {
         assertTrue("one connection", Wait.waitFor(new Wait.Condition() {
              @Override
              public boolean isSatisified() throws Exception {
-                 return 1 == brokerService.getTransportConnectorByScheme(getConnectorScheme()).connectionCount();
+                 TcpTransportServer server = (TcpTransportServer) brokerService.getTransportConnectorByScheme(getConnectorScheme()).getServer();
+                 return 1 == server.getCurrentTransportCount().get();
              }
         }, TimeUnit.SECONDS.toMillis(15), TimeUnit.MILLISECONDS.toMillis(250)));
 
@@ -145,7 +151,8 @@ public class OpenWireConnectionTimeoutTest {
         assertTrue("no dangling connections", Wait.waitFor(new Wait.Condition() {
             @Override
             public boolean isSatisified() throws Exception {
-                return 0 == brokerService.getTransportConnectorByScheme(getConnectorScheme()).connectionCount();
+                TcpTransportServer server = (TcpTransportServer) brokerService.getTransportConnectorByScheme(getConnectorScheme()).getServer();
+                return 0 == server.getCurrentTransportCount().get();
             }
         }, TimeUnit.SECONDS.toMillis(15), TimeUnit.MILLISECONDS.toMillis(500)));
 
@@ -157,10 +164,14 @@ public class OpenWireConnectionTimeoutTest {
 
         switch (connectorScheme) {
             case "tcp":
+            case "auto":
             case "nio":
+            case "auto+nio":
                 break;
             case "ssl":
+            case "auto+ssl":
             case "nio+ssl":
+            case "auto+nio+ssl":
                 useSsl = true;;
                 break;
             default:
@@ -219,6 +230,18 @@ public class OpenWireConnectionTimeoutTest {
             case "nio+ssl":
                 connector = brokerService.addConnector("nio+ssl://0.0.0.0:0" + getAdditionalConfig());
                 break;
+            case "auto":
+                connector = brokerService.addConnector("auto://0.0.0.0:0" + getAdditionalConfig());
+                break;
+            case "auto+nio":
+                connector = brokerService.addConnector("auto+nio://0.0.0.0:0" + getAdditionalConfig());
+                break;
+            case "auto+ssl":
+                connector = brokerService.addConnector("auto+ssl://0.0.0.0:0" + getAdditionalConfig());
+                break;
+            case "auto+nio+ssl":
+                connector = brokerService.addConnector("auto+nio+ssl://0.0.0.0:0" + getAdditionalConfig());
+                break;
             default:
                 throw new IOException("Invalid OpenWire connector scheme passed to test.");
         }

http://git-wip-us.apache.org/repos/asf/activemq/blob/679f0cfd/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/NetworkAsyncStartTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/NetworkAsyncStartTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/NetworkAsyncStartTest.java
index 8f74117..4c4353b 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/NetworkAsyncStartTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/NetworkAsyncStartTest.java
@@ -19,6 +19,7 @@ package org.apache.activemq.usecases;
 import java.net.URI;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
+
 import org.apache.activemq.JmsMultipleBrokersTestSupport;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.network.DiscoveryNetworkConnector;
@@ -30,11 +31,91 @@ import org.slf4j.LoggerFactory;
 public class NetworkAsyncStartTest extends JmsMultipleBrokersTestSupport {
     private static final Logger LOG = LoggerFactory.getLogger(NetworkAsyncStartTest.class);
 
-    private String brokerBUri = "tcp://localhost:61617";
-    private String brokerCUri = "tcp://localhost:61618";
+    private String brokerBDomain = "localhost:61617";
+    private String brokerCDomain = "localhost:61618";
     int bridgeCount=0;
 
-    public void testAsyncNetworkStartup() throws Exception {
+    public static final String KEYSTORE_TYPE = "jks";
+    public static final String PASSWORD = "password";
+    public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore";
+    public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
+
+    static {
+        System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
+        System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
+        System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
+        System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
+        System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
+        System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);
+    }
+
+    public void testAsyncNetworkStartupTcp() throws Exception {
+        testAsyncNetworkStartup("tcp");
+    }
+
+    public void testAsyncNetworkStartupWithSlowConnectionCreationTcp() throws Exception {
+        testAsyncNetworkStartupWithSlowConnectionCreation("tcp");
+    }
+
+    public void testAsyncNetworkStartupNio() throws Exception {
+        testAsyncNetworkStartup("nio");
+    }
+
+    public void testAsyncNetworkStartupWithSlowConnectionCreationNio() throws Exception {
+        testAsyncNetworkStartupWithSlowConnectionCreation("nio");
+    }
+
+    public void testAsyncNetworkStartupAuto() throws Exception {
+        testAsyncNetworkStartup("auto");
+    }
+
+    public void testAsyncNetworkStartupWithSlowConnectionCreationAuto() throws Exception
{
+        testAsyncNetworkStartupWithSlowConnectionCreation("auto");
+    }
+
+    public void testAsyncNetworkStartupAutoNio() throws Exception {
+        testAsyncNetworkStartup("auto+nio");
+    }
+
+    public void testAsyncNetworkStartupWithSlowConnectionCreationAutoNio() throws Exception
{
+        testAsyncNetworkStartupWithSlowConnectionCreation("auto+nio");
+    }
+
+    public void testAsyncNetworkStartupSsl() throws Exception {
+        testAsyncNetworkStartup("ssl");
+    }
+
+    public void testAsyncNetworkStartupWithSlowConnectionCreationSsl() throws Exception {
+        testAsyncNetworkStartupWithSlowConnectionCreation("ssl");
+    }
+
+    public void testAsyncNetworkStartupAutoSsl() throws Exception {
+        testAsyncNetworkStartup("auto+ssl");
+    }
+
+    public void testAsyncNetworkStartupWithSlowConnectionCreationAutoSsl() throws Exception
{
+        testAsyncNetworkStartupWithSlowConnectionCreation("auto+ssl");
+    }
+
+    public void testAsyncNetworkStartupNioSsl() throws Exception {
+        testAsyncNetworkStartup("nio+ssl");
+    }
+
+    public void testAsyncNetworkStartupWithSlowConnectionCreationNioSsl() throws Exception
{
+        testAsyncNetworkStartupWithSlowConnectionCreation("nio+ssl");
+    }
+
+    public void testAsyncNetworkStartupAutoNioSsl() throws Exception {
+        testAsyncNetworkStartup("auto+nio+ssl");
+    }
+
+    public void testAsyncNetworkStartupWithSlowConnectionCreationAutoNioSsl() throws Exception
{
+        testAsyncNetworkStartupWithSlowConnectionCreation("auto+nio+ssl");
+    }
+
+    protected void testAsyncNetworkStartup(String transport) throws Exception {
+        String brokerBUri = transport + "://" + brokerBDomain;
+        String brokerCUri = transport + "://" + brokerCDomain;
 
         BrokerService brokerA = brokers.get("BrokerA").broker;
         bridgeBroker(brokerA, brokerBUri);
@@ -60,7 +141,9 @@ public class NetworkAsyncStartTest extends JmsMultipleBrokersTestSupport
{
         assertTrue("got bridge to B&C", waitForBridgeFormation(brokerA, 1, 1));
     }
 
-    public void testAsyncNetworkStartupWithSlowConnectionCreation() throws Exception {
+    protected void testAsyncNetworkStartupWithSlowConnectionCreation(String transport) throws
Exception {
+        String brokerBUri = transport + "://" + brokerBDomain;
+        String brokerCUri = transport + "://" + brokerCDomain;
 
         final BrokerService brokerA = brokers.get("BrokerA").broker;
 
@@ -81,6 +164,7 @@ public class NetworkAsyncStartTest extends JmsMultipleBrokersTestSupport
{
 
         Executor e = Executors.newCachedThreadPool();
         e.execute(new Runnable() {
+            @Override
             public void run() {
                 LOG.info("starting A");
                 try {


Mime
View raw message