merge -c 904005 https://svn.apache.org/repos/asf/activemq/trunk - 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/branches/activemq-5.3@905593 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2010-02-02 11:55:13 +00:00
parent 3495a05a24
commit 2920f2e0b4
2 changed files with 29 additions and 12 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,7 +42,25 @@ public class HttpTransportBrokerTest extends TransportBrokerTestSupport {
protected void setUp() throws Exception {
maxWait = 2000;
super.setUp();
Thread.sleep(500);
waitForJettySocketToAccept(getBindLocation());
}
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 {
@ -46,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(1000);
}
public static Test suite() {