Allow starting and stopping of test server to throw an exception (#9895)
This commit is contained in:
parent
6313391d71
commit
f491250efa
|
@ -31,33 +31,26 @@ class TapestryTest extends AbstractHttpServerUsingTest<Server> {
|
||||||
HttpServerInstrumentationExtension.forAgent();
|
HttpServerInstrumentationExtension.forAgent();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Server setupServer() {
|
protected Server setupServer() throws Exception {
|
||||||
WebAppContext webAppContext = new WebAppContext();
|
WebAppContext webAppContext = new WebAppContext();
|
||||||
webAppContext.setContextPath(getContextPath());
|
webAppContext.setContextPath(getContextPath());
|
||||||
Server jettyServer = new Server(port);
|
Server jettyServer = new Server(port);
|
||||||
|
|
||||||
// set up test application
|
// set up test application
|
||||||
try {
|
webAppContext.setBaseResource(Resource.newResource("src/test/webapp"));
|
||||||
webAppContext.setBaseResource(Resource.newResource("src/test/webapp"));
|
for (Connector connector : jettyServer.getConnectors()) {
|
||||||
for (Connector connector : jettyServer.getConnectors()) {
|
connector.setHost("localhost");
|
||||||
connector.setHost("localhost");
|
|
||||||
}
|
|
||||||
|
|
||||||
jettyServer.setHandler(webAppContext);
|
|
||||||
jettyServer.start();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jettyServer.setHandler(webAppContext);
|
||||||
|
jettyServer.start();
|
||||||
|
|
||||||
return jettyServer;
|
return jettyServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void stopServer(Server server) {
|
protected void stopServer(Server server) throws Exception {
|
||||||
try {
|
server.stop();
|
||||||
server.stop();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,9 +27,9 @@ public abstract class AbstractHttpServerUsingTest<SERVER> {
|
||||||
public int port;
|
public int port;
|
||||||
public URI address;
|
public URI address;
|
||||||
|
|
||||||
protected abstract SERVER setupServer();
|
protected abstract SERVER setupServer() throws Exception;
|
||||||
|
|
||||||
protected abstract void stopServer(SERVER server);
|
protected abstract void stopServer(SERVER server) throws Exception;
|
||||||
|
|
||||||
protected final InstrumentationTestRunner testing() {
|
protected final InstrumentationTestRunner testing() {
|
||||||
return testing;
|
return testing;
|
||||||
|
@ -40,7 +40,11 @@ public abstract class AbstractHttpServerUsingTest<SERVER> {
|
||||||
address = buildAddress();
|
address = buildAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
server = setupServer();
|
try {
|
||||||
|
server = setupServer();
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new IllegalStateException("Failed to start server", exception);
|
||||||
|
}
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
logger.info(
|
logger.info(
|
||||||
getClass().getName()
|
getClass().getName()
|
||||||
|
@ -57,7 +61,11 @@ public abstract class AbstractHttpServerUsingTest<SERVER> {
|
||||||
logger.info(getClass().getName() + " can't stop null server");
|
logger.info(getClass().getName() + " can't stop null server");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stopServer(server);
|
try {
|
||||||
|
stopServer(server);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new IllegalStateException("Failed to stop server", exception);
|
||||||
|
}
|
||||||
server = null;
|
server = null;
|
||||||
logger.info(getClass().getName() + " http server stopped at: http://localhost:" + port + "/");
|
logger.info(getClass().getName() + " http server stopped at: http://localhost:" + port + "/");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue