Issue #3440 Stop on Unavailable
+ cleanup after review Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
9a75a40284
commit
054d7f240e
|
@ -387,17 +387,20 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
}
|
||||
|
||||
// start connectors last
|
||||
if (mex.size()==0)
|
||||
{
|
||||
for (Connector connector : _connectors)
|
||||
{
|
||||
try
|
||||
{
|
||||
connector.start();
|
||||
}
|
||||
catch(Throwable e)
|
||||
catch (Throwable e)
|
||||
{
|
||||
mex.add(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isDumpAfterStart())
|
||||
dumpStdErr();
|
||||
|
@ -412,9 +415,10 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
{
|
||||
mex.add(e);
|
||||
}
|
||||
mex.ifExceptionThrow();
|
||||
}
|
||||
|
||||
mex.ifExceptionThrow();
|
||||
|
||||
LOG.info(String.format("Started @%dms",Uptime.getUptime()));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,18 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.condition.OS.WINDOWS;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -54,18 +42,32 @@ import org.eclipse.jetty.io.EndPoint;
|
|||
import org.eclipse.jetty.server.LocalConnector.LocalEndPoint;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.condition.OS.WINDOWS;
|
||||
|
||||
public class GracefulStopTest
|
||||
{
|
||||
/**
|
||||
|
@ -658,6 +660,40 @@ public class GracefulStopTest
|
|||
assertTrue(latch.await(10,TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailedStart()
|
||||
{
|
||||
Server server= new Server();
|
||||
|
||||
LocalConnector connector = new LocalConnector(server);
|
||||
server.addConnector(connector);
|
||||
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection();
|
||||
server.setHandler(contexts);
|
||||
ContextHandler context0 = new ContextHandler(server,"/zero");
|
||||
ContextHandler context1 = new ContextHandler(server,"/one")
|
||||
{
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
throw new Exception("Test start failure");
|
||||
}
|
||||
};
|
||||
contexts.setHandlers(new Handler[]{context0,context1});
|
||||
|
||||
try
|
||||
{
|
||||
server.start();
|
||||
fail();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
assertThat(e.getMessage(),is("Test start failure"));
|
||||
}
|
||||
|
||||
server.getContainedBeans(LifeCycle.class).stream().forEach(lc -> assertTrue(!lc.isRunning()));
|
||||
}
|
||||
|
||||
static class NoopHandler extends AbstractHandler
|
||||
{
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
|
Loading…
Reference in New Issue