From f3e9ec0b81adfdbb5c44ef4d92b036ba5f60c6b5 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Tue, 18 Oct 2011 19:05:15 +0000 Subject: [PATCH] Removes the dependence on the fixed ports, should prevent needless test failures. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1185804 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/activemq/web/AjaxTest.java | 5 --- .../org/apache/activemq/web/JettyServer.java | 8 ++-- .../apache/activemq/web/JettyTestSupport.java | 4 +- .../org/apache/activemq/web/RestTest.java | 40 ++++++++----------- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java b/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java index 4174e3611a..a5c30277f2 100644 --- a/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java +++ b/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java @@ -18,9 +18,7 @@ package org.apache.activemq.web; import org.apache.activemq.transport.stomp.StompConnection; import org.apache.activemq.transport.stomp.StompFrame; -import org.apache.activemq.transport.stomp.Stomp; -import java.lang.Thread; import java.net.SocketTimeoutException; import org.slf4j.Logger; @@ -31,12 +29,10 @@ import java.util.*; import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.io.ByteArrayBuffer; import javax.jms.MessageProducer; import javax.jms.Message; -import javax.jms.TextMessage; public class AjaxTest extends JettyTestSupport { private static final Logger LOG = LoggerFactory.getLogger(AjaxTest.class); @@ -533,5 +529,4 @@ public class AjaxTest extends JettyTestSupport { assertContains( "B2\n", fullResponse ); assertResponseCount( 4, fullResponse ); } - } diff --git a/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyServer.java b/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyServer.java index f8889fddf6..692df0591f 100644 --- a/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyServer.java +++ b/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyServer.java @@ -27,8 +27,8 @@ import org.eclipse.jetty.webapp.WebAppContext; /** * A simple bootstrap class for starting Jetty in your IDE using the local web * application. - * - * + * + * */ public final class JettyServer { @@ -46,8 +46,8 @@ public final class JettyServer { BrokerService broker = new BrokerService(); broker.setPersistent(false); broker.setUseJmx(true); - broker.addConnector("tcp://localhost:61616"); - broker.addConnector("stomp://localhost:61613"); + broker.addConnector("tcp://localhost:0"); + broker.addConnector("stomp://localhost:0"); broker.start(); // lets publish some messages so that there is some stuff to browse diff --git a/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java b/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java index 1f0209e746..0285ed94c5 100644 --- a/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java +++ b/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java @@ -54,8 +54,8 @@ public class JettyTestSupport extends TestCase { broker = new BrokerService(); broker.setPersistent(false); broker.setUseJmx(true); - tcpUri = broker.addConnector("tcp://localhost:61616").getConnectUri(); - stompUri = broker.addConnector("stomp://localhost:61613").getConnectUri(); + tcpUri = new URI(broker.addConnector("tcp://localhost:0").getPublishableConnectString()); + stompUri = new URI(broker.addConnector("stomp://localhost:0").getPublishableConnectString()); broker.start(); broker.waitUntilStarted(); diff --git a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java index c96cac2090..cf2b60414f 100644 --- a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java +++ b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java @@ -19,8 +19,6 @@ package org.apache.activemq.web; import javax.jms.TextMessage; import javax.management.ObjectName; -import org.apache.activemq.broker.jmx.DestinationViewMBean; -import org.apache.activemq.broker.jmx.SubscriptionViewMBean; import org.apache.commons.lang.RandomStringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,11 +29,11 @@ import java.util.Set; public class RestTest extends JettyTestSupport { private static final Logger LOG = LoggerFactory.getLogger(RestTest.class); - + public void testConsume() throws Exception { producer.send(session.createTextMessage("test")); LOG.info("message sent"); - + HttpClient httpClient = new HttpClient(); httpClient.start(); ContentExchange contentExchange = new ContentExchange(); @@ -43,9 +41,9 @@ public class RestTest extends JettyTestSupport { contentExchange.setURL("http://localhost:8080/message/test?readTimeout=1000&type=queue"); httpClient.send(contentExchange); contentExchange.waitForDone(); - assertEquals("test", contentExchange.getResponseContent()); + assertEquals("test", contentExchange.getResponseContent()); } - + public void testSubscribeFirst() throws Exception { HttpClient httpClient = new HttpClient(); httpClient.start(); @@ -53,27 +51,27 @@ public class RestTest extends JettyTestSupport { httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); contentExchange.setURL("http://localhost:8080/message/test?readTimeout=5000&type=queue"); httpClient.send(contentExchange); - + Thread.sleep(1000); - + producer.send(session.createTextMessage("test")); LOG.info("message sent"); - + contentExchange.waitForDone(); - assertEquals("test", contentExchange.getResponseContent()); + assertEquals("test", contentExchange.getResponseContent()); } - + public void testSelector() throws Exception { TextMessage msg1 = session.createTextMessage("test1"); msg1.setIntProperty("test", 1); producer.send(msg1); LOG.info("message 1 sent"); - + TextMessage msg2 = session.createTextMessage("test2"); msg2.setIntProperty("test", 2); producer.send(msg2); LOG.info("message 2 sent"); - + HttpClient httpClient = new HttpClient(); httpClient.start(); ContentExchange contentExchange = new ContentExchange(); @@ -84,20 +82,20 @@ public class RestTest extends JettyTestSupport { contentExchange.waitForDone(); assertEquals("test2", contentExchange.getResponseContent()); } - + // test for https://issues.apache.org/activemq/browse/AMQ-2827 public void testCorrelation() throws Exception { for (int i = 0; i < 200; i++) { String correlId = "RESTY" + RandomStringUtils.randomNumeric(10); - + TextMessage message = session.createTextMessage(correlId); message.setStringProperty("correlationId", correlId); message.setJMSCorrelationID(correlId); - + LOG.info("Sending: " + correlId); - + producer.send(message); - + HttpClient httpClient = new HttpClient(); httpClient.start(); ContentExchange contentExchange = new ContentExchange(); @@ -131,12 +129,8 @@ public class RestTest extends JettyTestSupport { httpClient.stop(); - - - ObjectName name = new ObjectName("org.apache.activemq" + ":BrokerName=localhost,Type=Queue,Destination=test"); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Subscription,destinationType=Queue,destinationName=test,*"); - Set subs = broker.getManagementContext().queryNames(query, null); + Set subs = broker.getManagementContext().queryNames(query, null); assertEquals("Consumers not closed", 0 , subs.size()); } - }