Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project

This commit is contained in:
Greg Wilkins 2011-11-18 16:09:07 +11:00
commit d84d4c155d
2 changed files with 54 additions and 12 deletions

View File

@ -68,6 +68,8 @@ public class ShutdownHandler extends AbstractHandler
private final Server _server;
private boolean _exitJvm = false;
/**
* Creates a listener that lets the server be shut down remotely (but only from localhost).
@ -110,18 +112,24 @@ public class ShutdownHandler extends AbstractHandler
LOG.info("Shutting down by request from " + getRemoteAddr(request));
try
new Thread()
{
shutdownServer();
}
catch (InterruptedException e)
{
LOG.ignore(e);
}
catch (Exception e)
{
throw new RuntimeException("Shutting down server",e);
}
public void run ()
{
try
{
shutdownServer();
}
catch (InterruptedException e)
{
LOG.ignore(e);
}
catch (Exception e)
{
throw new RuntimeException("Shutting down server",e);
}
}
}.start();
}
private boolean requestFromLocalhost(HttpServletRequest request)

View File

@ -14,12 +14,18 @@ package org.eclipse.jetty.server.handler;
//========================================================================
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@ -48,8 +54,36 @@ public class ShutdownHandlerTest
public void shutdownServerWithCorrectTokenAndIPTest() throws Exception
{
setDefaultExpectations();
final CountDownLatch countDown = new CountDownLatch(1);
server.addLifeCycleListener(new AbstractLifeCycle.Listener ()
{
public void lifeCycleStarting(LifeCycle event)
{
}
public void lifeCycleStarted(LifeCycle event)
{
}
public void lifeCycleFailure(LifeCycle event, Throwable cause)
{
}
public void lifeCycleStopping(LifeCycle event)
{
}
public void lifeCycleStopped(LifeCycle event)
{
countDown.countDown();
}
});
shutdownHandler.handle("/shutdown",null,request,response);
assertEquals("Server should be stopped","STOPPED",server.getState());
boolean stopped = countDown.await(1000, TimeUnit.MILLISECONDS); //wait up to 1 sec to stop
assertTrue("Server lifecycle stop listener called", stopped);
assertEquals("Server should be stopped","STOPPED",server.getState());
}
@Test