activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1203176 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/ main/java/org/apache/activemq/security/ test/java/org/apache/activemq/transport/stomp/
Date Thu, 17 Nov 2011 12:49:32 GMT
Author: gtully
Date: Thu Nov 17 12:49:32 2011
New Revision: 1203176

URL: http://svn.apache.org/viewvc?rev=1203176&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3599 - JaasDualAuthenticationPlugin, java.net.BindException:
Address already in use on shutdown with pending connectons. resolve with test

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/JaasDualAuthenticationBroker.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/ConnectTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java?rev=1203176&r1=1203175&r2=1203176&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
Thu Nov 17 12:49:32 2011
@@ -280,7 +280,6 @@ public class TransportConnector implemen
         }
         if (server != null) {
             ss.stop(server);
-            server = null;
         }
         if (this.statusDector != null) {
             this.statusDector.stop();
@@ -290,6 +289,7 @@ public class TransportConnector implemen
             TransportConnection c = iter.next();
             ss.stop(c);
         }
+        server = null;
         ss.throwFirstException();
         LOG.info("Connector " + getName() + " Stopped");
     }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/JaasDualAuthenticationBroker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/JaasDualAuthenticationBroker.java?rev=1203176&r1=1203175&r2=1203176&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/JaasDualAuthenticationBroker.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/JaasDualAuthenticationBroker.java
Thu Nov 17 12:49:32 2011
@@ -106,9 +106,9 @@ public class JaasDualAuthenticationBroke
     public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable
error) throws Exception {
         boolean isSSL;
         Connector connector = context.getConnector();
-        if (connector instanceof ManagedTransportConnector) {
-            ManagedTransportConnector managedTransportConnector = (ManagedTransportConnector)
connector;
-            isSSL = (managedTransportConnector.getServer() instanceof SslTransportServer);
+        if (connector instanceof TransportConnector) {
+            TransportConnector transportConnector = (TransportConnector) connector;
+            isSSL = (transportConnector.getServer() instanceof SslTransportServer);
         } else {
             isSSL = false;
         }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/ConnectTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/ConnectTest.java?rev=1203176&r1=1203175&r2=1203176&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/ConnectTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/ConnectTest.java
Thu Nov 17 12:49:32 2011
@@ -16,8 +16,14 @@
  */
 package org.apache.activemq.transport.stomp;
 
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
 import java.util.Vector;
+import javax.net.ServerSocketFactory;
+import org.apache.activemq.broker.BrokerPlugin;
 import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.security.JaasDualAuthenticationPlugin;
 import org.apache.activemq.util.Wait;
 import org.junit.After;
 import org.junit.Before;
@@ -40,8 +46,6 @@ public class ConnectTest {
         brokerService = new BrokerService();
         brokerService.setPersistent(false);
         brokerService.setAdvisorySupport(false);
-        brokerService.addConnector("stomp://0.0.0.0:61612?transport.soLinger=0");
-        brokerService.start();
     }
 
     @After
@@ -54,12 +58,15 @@ public class ConnectTest {
     @Test
     public void testStompConnectLeak() throws Exception {
 
+        brokerService.addConnector("stomp://0.0.0.0:0?transport.soLinger=0");
+        brokerService.start();
+
         Thread t1 = new Thread() {
             StompConnection connection = new StompConnection();
 
             public void run() {
                 try {
-                    connection.open("localhost", 61612);
+                    connection.open("localhost", brokerService.getTransportConnectors().get(0).getConnectUri().getPort());
                     connection.connect("system", "manager");
                     connection.disconnect();
                 } catch (Exception ex) {
@@ -70,7 +77,7 @@ public class ConnectTest {
         };
 
         int i = 0;
-        long done = System.currentTimeMillis() + (60 * 1000 * 2);
+        long done = System.currentTimeMillis() + (15 * 1000);
         while (System.currentTimeMillis() < done) {
             t1.run();
             if (++i % 5000 == 0) {
@@ -86,4 +93,47 @@ public class ConnectTest {
         }));
         assertTrue("no exceptions", exceptions.isEmpty());
     }
+
+    @Test
+    public void testJaasDualStopWithOpenConnection() throws Exception {
+
+        brokerService.setPlugins(new BrokerPlugin[]{new JaasDualAuthenticationPlugin()});
+        brokerService.addConnector("stomp://0.0.0.0:0?transport.closeAsync=false");
+        brokerService.start();
+
+        final int listenPort = brokerService.getTransportConnectors().get(0).getConnectUri().getPort();
+        Thread t1 = new Thread() {
+            StompConnection connection = new StompConnection();
+
+            public void run() {
+                try {
+                    connection.open("localhost", listenPort);
+                    connection.connect("system", "manager");
+                } catch (Exception ex) {
+                    LOG.error("unexpected exception on connect/disconnect", ex);
+                    exceptions.add(ex);
+                }
+            }
+        };
+
+        t1.run();
+
+        assertTrue("one connection", Wait.waitFor(new Wait.Condition() {
+            @Override
+            public boolean isSatisified() throws Exception {
+                return 1 == brokerService.getTransportConnectors().get(0).connectionCount();
+            }
+        }));
+
+        brokerService.stop();
+
+        // server socket should be available after stop
+        ServerSocket socket = ServerSocketFactory.getDefault().createServerSocket();
+        socket.setReuseAddress(true);
+        InetAddress address = InetAddress.getLocalHost();
+        socket.bind(new InetSocketAddress(address, listenPort));
+        LOG.info("bound address: " + socket);
+        socket.close();
+        assertTrue("no exceptions", exceptions.isEmpty());
+    }
 }
\ No newline at end of file



Mime
View raw message