mirror of https://github.com/apache/activemq.git
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:
parent
3495a05a24
commit
2920f2e0b4
|
@ -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,10 +42,28 @@ public class HttpTransportBrokerTest extends TransportBrokerTestSupport {
|
|||
protected void setUp() throws Exception {
|
||||
maxWait = 2000;
|
||||
super.setUp();
|
||||
Thread.sleep(500);
|
||||
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;
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue