You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/08/11 01:00:14 UTC

svn commit: r1156397 - in /activemq/trunk/activemq-core/src/test/java/org/apache/activemq: broker/ReconnectWithJMXEnabledTest.java transport/stomp/StompSubscriptionRemoveTest.java transport/tcp/InactivityMonitorTest.java

Author: tabish
Date: Wed Aug 10 23:00:13 2011
New Revision: 1156397

URL: http://svn.apache.org/viewvc?rev=1156397&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-2411

remove some of the dependencies on port 61616 in current tests.

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ReconnectWithJMXEnabledTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompSubscriptionRemoveTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ReconnectWithJMXEnabledTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ReconnectWithJMXEnabledTest.java?rev=1156397&r1=1156396&r2=1156397&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ReconnectWithJMXEnabledTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ReconnectWithJMXEnabledTest.java Wed Aug 10 23:00:13 2011
@@ -17,17 +17,19 @@
 package org.apache.activemq.broker;
 
 import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 
+import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.EmbeddedBrokerTestSupport;
 
 /**
- * 
- * 
+ *
+ *
  */
 public class ReconnectWithJMXEnabledTest extends EmbeddedBrokerTestSupport {
 
@@ -44,15 +46,21 @@ public class ReconnectWithJMXEnabledTest
         broker = createBroker();
         startBroker();
 
+        connectionFactory = createConnectionFactory();
         connection = connectionFactory.createConnection();
         useConnection(connection);
     }
 
     protected void setUp() throws Exception {
-        bindAddress = "tcp://localhost:61616";
+        bindAddress = "tcp://localhost:0";
         super.setUp();
     }
 
+    @Override
+    protected ConnectionFactory createConnectionFactory() throws Exception {
+        return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
+    }
+
     protected void tearDown() throws Exception {
         if (connection != null) {
             connection.close();
@@ -79,5 +87,6 @@ public class ReconnectWithJMXEnabledTest
         Message message = session.createTextMessage("Hello World");
         producer.send(message);
         Thread.sleep(1000);
+        consumer.close();
     }
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompSubscriptionRemoveTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompSubscriptionRemoveTest.java?rev=1156397&r1=1156396&r2=1156397&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompSubscriptionRemoveTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompSubscriptionRemoveTest.java Wed Aug 10 23:00:13 2011
@@ -21,6 +21,7 @@ import java.io.DataInput;
 import java.io.DataInputStream;
 import java.io.IOException;
 import java.net.Socket;
+import java.net.URI;
 
 import javax.jms.Connection;
 import javax.jms.Message;
@@ -36,14 +37,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * 
- * 
+ *
+ *
  */
 public class StompSubscriptionRemoveTest extends TestCase {
     private static final Logger LOG = LoggerFactory.getLogger(StompSubscriptionRemoveTest.class);
     private static final String COMMAND_MESSAGE = "MESSAGE";
     private static final String HEADER_MESSAGE_ID = "message-id";
-    private static final int STOMP_PORT = 61613;
 
     private StompConnection stompConnection = new StompConnection();
 
@@ -51,11 +51,15 @@ public class StompSubscriptionRemoveTest
         BrokerService broker = new BrokerService();
         broker.setPersistent(false);
 
-        broker.addConnector("stomp://localhost:61613").setName("Stomp");
-        broker.addConnector("tcp://localhost:61616").setName("Default");
+        broker.addConnector("stomp://localhost:0").setName("Stomp");
+        broker.addConnector("tcp://localhost:0").setName("Default");
         broker.start();
 
-        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
+        final String stompUri = broker.getConnectorByName("Stomp").getPublishableConnectString();
+        final int stompPort = new URI(stompUri).getPort();
+        final String openwireUri = broker.getConnectorByName("Default").getPublishableConnectString();
+
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(openwireUri);
         Connection connection = factory.createConnection();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer producer = session.createProducer(new ActiveMQQueue(getDestinationName()));
@@ -68,7 +72,7 @@ public class StompSubscriptionRemoveTest
         session.close();
         connection.close();
 
-        stompConnection.open(new Socket("localhost", STOMP_PORT));
+        stompConnection.open(new Socket("localhost", stompPort));
 
         String connectFrame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n" + "\n";
         stompConnection.sendFrame(connectFrame);
@@ -95,7 +99,7 @@ public class StompSubscriptionRemoveTest
         Thread.sleep(1000);
         stompConnection.close();
 
-        stompConnection.open(new Socket("localhost", STOMP_PORT));
+        stompConnection.open(new Socket("localhost", stompPort));
 
         connectFrame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n" + "\n";
         stompConnection.sendFrame(connectFrame);

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java?rev=1156397&r1=1156396&r2=1156397&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java Wed Aug 10 23:00:13 2011
@@ -44,6 +44,7 @@ public class InactivityMonitorTest exten
     private TransportServer server;
     private Transport clientTransport;
     private Transport serverTransport;
+    private int serverPort;
 
     private final AtomicInteger clientReceiveCount = new AtomicInteger(0);
     private final AtomicInteger clientErrorCount = new AtomicInteger(0);
@@ -63,7 +64,7 @@ public class InactivityMonitorTest exten
      * @throws URISyntaxException
      */
     private void startClient() throws Exception, URISyntaxException {
-        clientTransport = TransportFactory.connect(new URI("tcp://localhost:61616?trace=true&wireFormat.maxInactivityDuration=1000"));
+        clientTransport = TransportFactory.connect(new URI("tcp://localhost:" + serverPort + "?trace=true&wireFormat.maxInactivityDuration=1000"));
         clientTransport.setTransportListener(new TransportListener() {
             public void onCommand(Object command) {
                 clientReceiveCount.incrementAndGet();
@@ -95,9 +96,11 @@ public class InactivityMonitorTest exten
      * @throws Exception
      */
     private void startTransportServer() throws IOException, URISyntaxException, Exception {
-        server = TransportFactory.bind(new URI("tcp://localhost:61616?trace=true&wireFormat.maxInactivityDuration=1000"));
+        server = TransportFactory.bind(new URI("tcp://localhost:0?trace=true&wireFormat.maxInactivityDuration=1000"));
         server.setAcceptListener(this);
         server.start();
+
+        serverPort = server.getSocketAddress().getPort();
     }
 
     protected void tearDown() throws Exception {
@@ -156,11 +159,11 @@ public class InactivityMonitorTest exten
 
     public void testClientHang() throws Exception {
 
-        // 
+        //
         // Manually create a client transport so that it does not send KeepAlive
         // packets.
         // this should simulate a client hang.
-        clientTransport = new TcpTransport(new OpenWireFormat(), SocketFactory.getDefault(), new URI("tcp://localhost:61616"), null);
+        clientTransport = new TcpTransport(new OpenWireFormat(), SocketFactory.getDefault(), new URI("tcp://localhost:" + serverPort), null);
         clientTransport.setTransportListener(new TransportListener() {
             public void onCommand(Object command) {
                 clientReceiveCount.incrementAndGet();
@@ -215,7 +218,7 @@ public class InactivityMonitorTest exten
     /**
      * Used to test when a operation blocks. This should not cause transport to
      * get disconnected.
-     * 
+     *
      * @throws Exception
      * @throws URISyntaxException
      */