From 3d6222d188e57f49f2e02a589b53a5ba9f10e501 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 19 Dec 2012 16:54:04 +0000 Subject: [PATCH] Remove dependency on fixed port for these tests. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1423946 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/util/HttpTestSupport.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/activemq-fileserver/src/test/java/org/apache/activemq/util/HttpTestSupport.java b/activemq-fileserver/src/test/java/org/apache/activemq/util/HttpTestSupport.java index 2d9c65efba..4f48843e0b 100644 --- a/activemq-fileserver/src/test/java/org/apache/activemq/util/HttpTestSupport.java +++ b/activemq-fileserver/src/test/java/org/apache/activemq/util/HttpTestSupport.java @@ -30,16 +30,16 @@ import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.webapp.WebAppContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public abstract class HttpTestSupport extends TestCase { private static final Logger LOG = LoggerFactory.getLogger(HttpTestSupport.class); - + BrokerService broker; Server server; ActiveMQConnectionFactory factory; @@ -47,16 +47,17 @@ public abstract class HttpTestSupport extends TestCase { Session session; MessageProducer producer; Destination destination; - + protected boolean createBroker = true; - + final File homeDir = new File("src/main/webapp/uploads/"); - + + @Override protected void setUp() throws Exception { - + server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); - connector.setPort(8080); + connector.setPort(0); connector.setServer(server); WebAppContext context = new WebAppContext(); @@ -68,8 +69,11 @@ public abstract class HttpTestSupport extends TestCase { connector }); server.start(); - waitForJettySocketToAccept("http://localhost:8080"); - + + int port = connector.getLocalPort(); + + waitForJettySocketToAccept("http://localhost:" + port); + if (createBroker) { broker = new BrokerService(); broker.setPersistent(false); @@ -77,19 +81,21 @@ public abstract class HttpTestSupport extends TestCase { broker.addConnector("vm://localhost"); broker.start(); broker.waitUntilStarted(); - + factory = new ActiveMQConnectionFactory("vm://localhost"); + factory.getBlobTransferPolicy().setDefaultUploadUrl("http://localhost:" + port + "/uploads/"); connection = factory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = session.createQueue("test"); producer = session.createProducer(destination); - + IOHelper.deleteFile(homeDir); homeDir.mkdir(); } } + @Override protected void tearDown() throws Exception { server.stop(); if (createBroker) { @@ -105,6 +111,7 @@ public abstract class HttpTestSupport extends TestCase { final URL url = new URL(bindLocation); assertTrue("Jetty endpoint is available", Wait.waitFor(new Wait.Condition() { + @Override public boolean isSatisified() throws Exception { boolean canConnect = false; try { @@ -117,6 +124,6 @@ public abstract class HttpTestSupport extends TestCase { return canConnect; }}, 60 * 1000)); } - + }