validate jetty availabilty via socket connect to take out the guess work on loaded machines - avoid connection refused intermittent failures

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@904005 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2010-01-28 09:09:00 +00:00
parent 0d9c588ed7
commit 87cc36a359
2 changed files with 29 additions and 13 deletions

View File

@ -16,7 +16,11 @@
*/
package org.apache.activemq.transport.http;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import javax.net.SocketFactory;
import junit.framework.Test;
import junit.textui.TestRunner;
@ -24,9 +28,13 @@ import junit.textui.TestRunner;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.transport.TransportBrokerTestSupport;
import org.apache.activemq.util.Wait;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class HttpTransportBrokerTest extends TransportBrokerTestSupport {
private static final Log LOG = LogFactory.getLog(HttpTransportBrokerTest.class);
protected String getBindLocation() {
return "http://localhost:8081";
}
@ -34,11 +42,28 @@ public class HttpTransportBrokerTest extends TransportBrokerTestSupport {
protected void setUp() throws Exception {
maxWait = 2000;
super.setUp();
Thread.sleep(1000);
Thread.yield();
waitForJettySocketToAccept(getBindLocation());
}
protected BrokerService createBroker() throws Exception {
private void waitForJettySocketToAccept(String bindLocation) throws Exception {
final URL url = new URL(bindLocation);
assertTrue("Jetty endpoint is available", Wait.waitFor(new Wait.Condition() {
public boolean isSatisified() throws Exception {
boolean canConnect = false;
try {
Socket socket = SocketFactory.getDefault().createSocket(url.getHost(), url.getPort());
socket.close();
canConnect = true;
} catch (Exception e) {
LOG.warn("verify jettty available, failed to connect to " + url + e);
}
return canConnect;
}}, 60 * 1000));
}
protected BrokerService createBroker() throws Exception {
BrokerService broker = BrokerFactory.createBroker(new URI("broker:()/localhost?persistent=false&useJmx=false"));
connector = broker.addConnector(getBindLocation());
return broker;
@ -47,7 +72,7 @@ public class HttpTransportBrokerTest extends TransportBrokerTestSupport {
protected void tearDown() throws Exception {
super.tearDown();
// Give the jetty server enough time to shutdown before starting another one
Thread.sleep(500);
Thread.sleep(100);
}
public static Test suite() {

View File

@ -35,15 +35,6 @@ public class HttpsTransportBrokerTest extends HttpTransportBrokerTest {
System.setProperty("javax.net.ssl.keyStoreType", "jks");
//System.setProperty("javax.net.debug", "ssl,handshake,data,trustmanager");
super.setUp();
Thread.sleep(2000);
Thread.yield();
}
protected void tearDown() throws Exception {
super.tearDown();
// Give the jetty server more time to shutdown before starting another one
Thread.sleep(2000);
}
public static Test suite() {