Issue #3440 Stop on Unavailable

+ cleanup after review

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-03-11 16:41:20 +11:00
parent 9a75a40284
commit 054d7f240e
2 changed files with 61 additions and 21 deletions

View File

@ -387,15 +387,18 @@ public class Server extends HandlerWrapper implements Attributes
}
// start connectors last
for (Connector connector : _connectors)
if (mex.size()==0)
{
try
for (Connector connector : _connectors)
{
connector.start();
}
catch(Throwable e)
{
mex.add(e);
try
{
connector.start();
}
catch (Throwable e)
{
mex.add(e);
}
}
}
@ -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()));
}

View File

@ -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
{
/**
@ -657,6 +659,40 @@ public class GracefulStopTest
assertThat(response,Matchers.not(Matchers.containsString("Connection: close")));
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
{