jetty-9 updated more test harness
This commit is contained in:
parent
571eb63bcd
commit
145938cecc
|
@ -17,10 +17,10 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
|
|||
{
|
||||
private static final int TICK=Integer.getInteger("org.eclipse.jetty.io.AsyncByteArrayEndPoint.TICK",100);
|
||||
public static final Logger LOG=Log.getLogger(AsyncByteArrayEndPoint.class);
|
||||
private static final Timer _timer = new Timer(true);
|
||||
private final Timer _timer;
|
||||
private AsyncConnection _connection;
|
||||
|
||||
private final TimerTask _task=new TimeoutTask(this);
|
||||
private final TimerTask _checkTimeout=new TimeoutTask(this);
|
||||
|
||||
private final ReadInterest _readInterest = new ReadInterest()
|
||||
{
|
||||
|
@ -41,23 +41,25 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
|
|||
}
|
||||
};
|
||||
|
||||
{
|
||||
_timer.schedule(_task,TICK,TICK);
|
||||
}
|
||||
|
||||
public AsyncByteArrayEndPoint()
|
||||
public AsyncByteArrayEndPoint(Timer timer)
|
||||
{
|
||||
super();
|
||||
_timer=timer;
|
||||
_timer.schedule(_checkTimeout,TICK,TICK);
|
||||
}
|
||||
|
||||
public AsyncByteArrayEndPoint(byte[] input, int outputSize)
|
||||
public AsyncByteArrayEndPoint(Timer timer, byte[] input, int outputSize)
|
||||
{
|
||||
super(input,outputSize);
|
||||
_timer=timer;
|
||||
_timer.schedule(_checkTimeout,TICK,TICK);
|
||||
}
|
||||
|
||||
public AsyncByteArrayEndPoint(String input, int outputSize)
|
||||
public AsyncByteArrayEndPoint(Timer timer, String input, int outputSize)
|
||||
{
|
||||
super(input,outputSize);
|
||||
_timer=timer;
|
||||
_timer.schedule(_checkTimeout,TICK,TICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,6 +84,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
|
|||
super.setOutput(out);
|
||||
_writeFlusher.completeWrite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
|
@ -145,7 +148,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
|
|||
@Override
|
||||
public void onClose()
|
||||
{
|
||||
_task.cancel();
|
||||
_checkTimeout.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import static org.junit.Assert.fail;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Timer;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
|
@ -20,10 +21,12 @@ import org.junit.Test;
|
|||
|
||||
public class AsyncByteArrayEndPointTest
|
||||
{
|
||||
private final Timer _timer = new Timer(true);
|
||||
|
||||
@Test
|
||||
public void testReadable() throws Exception
|
||||
{
|
||||
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint();
|
||||
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint(_timer);
|
||||
endp.setInput("test input");
|
||||
|
||||
ByteBuffer buffer = BufferUtil.allocate(1024);
|
||||
|
@ -82,7 +85,7 @@ public class AsyncByteArrayEndPointTest
|
|||
@Test
|
||||
public void testWrite() throws Exception
|
||||
{
|
||||
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint((byte[])null,15);
|
||||
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint(_timer,(byte[])null,15);
|
||||
endp.setGrowOutput(false);
|
||||
endp.setOutput(BufferUtil.allocate(10));
|
||||
|
||||
|
@ -110,7 +113,7 @@ public class AsyncByteArrayEndPointTest
|
|||
@Test
|
||||
public void testIdle() throws Exception
|
||||
{
|
||||
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint();
|
||||
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint(_timer);
|
||||
endp.setMaxIdleTime(500);
|
||||
endp.setInput("test");
|
||||
endp.setGrowOutput(false);
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.jetty.http.HttpURI;
|
|||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http.MimeTypes;
|
||||
import org.eclipse.jetty.io.AsyncConnection;
|
||||
import org.eclipse.jetty.io.AsyncEndPoint;
|
||||
import org.eclipse.jetty.io.EofException;
|
||||
import org.eclipse.jetty.io.UncheckedPrintWriter;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
|
@ -129,6 +130,12 @@ public abstract class HttpChannel
|
|||
return _handler;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public AsyncEndPoint getEndPoint()
|
||||
{
|
||||
return getConnection().getEndPoint();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isIdle()
|
||||
{
|
||||
|
@ -810,4 +817,5 @@ public abstract class HttpChannel
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -716,8 +716,8 @@ public class HttpChannelState implements AsyncContext, Continuation
|
|||
protected void scheduleTimeout()
|
||||
{
|
||||
Timer timer = _channel.getTimer();
|
||||
timer.schedule(_event._timeout,_timeoutMs);
|
||||
|
||||
if (timer!=null)
|
||||
timer.schedule(_event._timeout,_timeoutMs);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.Timer;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
import org.eclipse.jetty.http.HttpGenerator;
|
||||
import org.eclipse.jetty.http.HttpGenerator.Action;
|
||||
|
@ -285,7 +286,7 @@ public class HttpConnection extends AbstractAsyncConnection
|
|||
if (_parser.isClosed())
|
||||
LOG.debug(e);
|
||||
else
|
||||
LOG.warn(e);
|
||||
LOG.warn(this.toString(),e);
|
||||
getEndPoint().close();
|
||||
}
|
||||
finally
|
||||
|
@ -418,14 +419,29 @@ public class HttpConnection extends AbstractAsyncConnection
|
|||
// it wants to eat more
|
||||
if (_requestBuffer==null)
|
||||
scheduleOnReadable();
|
||||
else
|
||||
else if (getConnector().isStarted())
|
||||
{
|
||||
LOG.debug("{} pipelined",this);
|
||||
execute(new Runnable()
|
||||
|
||||
// TODO avoid temporary runnable
|
||||
try
|
||||
{
|
||||
@Override public void run() {onReadable();}
|
||||
});
|
||||
execute(new Runnable()
|
||||
{
|
||||
@Override public void run() {onReadable();}
|
||||
});
|
||||
}
|
||||
catch(RejectedExecutionException e)
|
||||
{
|
||||
if (getConnector().isStarted())
|
||||
LOG.warn(e);
|
||||
else
|
||||
LOG.ignore(e);
|
||||
getEndPoint().close();
|
||||
}
|
||||
}
|
||||
else
|
||||
getEndPoint().close();
|
||||
}
|
||||
|
||||
if (_parser.isClosed()&&!getEndPoint().isOutputShutdown())
|
||||
|
|
|
@ -54,12 +54,12 @@ public abstract class HttpConnector extends AbstractConnector
|
|||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
_timer.cancel();
|
||||
if (_timer!=null)
|
||||
_timer.cancel();
|
||||
_timer=null;
|
||||
super.doStop();
|
||||
}
|
||||
|
||||
|
||||
public Timer getTimer()
|
||||
{
|
||||
return _timer;
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.server;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Timer;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
|
@ -35,11 +36,13 @@ public class LocalHttpConnector extends HttpConnector
|
|||
private final BlockingQueue<LocalEndPoint> _connects = new LinkedBlockingQueue<LocalEndPoint>();
|
||||
private LocalExecutor _executor;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public LocalHttpConnector()
|
||||
{
|
||||
setMaxIdleTime(30000);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public Object getTransport()
|
||||
{
|
||||
|
@ -94,6 +97,7 @@ public class LocalHttpConnector extends HttpConnector
|
|||
return endp;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void accept(int acceptorID) throws IOException, InterruptedException
|
||||
{
|
||||
|
@ -101,11 +105,11 @@ public class LocalHttpConnector extends HttpConnector
|
|||
LocalEndPoint endp = _connects.take();
|
||||
HttpConnection connection=new HttpConnection(this,endp,getServer());
|
||||
endp.setAsyncConnection(connection);
|
||||
connection.onOpen();
|
||||
connectionOpened(connection);
|
||||
_executor._phaser.arriveAndDeregister(); // arrive for the register done in getResponses
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
|
@ -113,6 +117,7 @@ public class LocalHttpConnector extends HttpConnector
|
|||
_executor=new LocalExecutor(findExecutor());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
|
@ -120,12 +125,14 @@ public class LocalHttpConnector extends HttpConnector
|
|||
_executor=null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public Executor findExecutor()
|
||||
{
|
||||
return _executor==null?super.findExecutor():_executor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
class LocalExecutor implements Executor
|
||||
{
|
||||
Phaser _phaser=new Phaser()
|
||||
|
@ -167,21 +174,25 @@ public class LocalHttpConnector extends HttpConnector
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public class LocalEndPoint extends AsyncByteArrayEndPoint
|
||||
{
|
||||
private CountDownLatch _closed = new CountDownLatch(1);
|
||||
|
||||
LocalEndPoint()
|
||||
{
|
||||
super(getTimer());
|
||||
setGrowOutput(true);
|
||||
setMaxIdleTime(LocalHttpConnector.this.getMaxIdleTime());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
LocalEndPoint(CountDownLatch onCloseLatch)
|
||||
{
|
||||
this();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void addInput(String s)
|
||||
{
|
||||
// TODO this is a busy wait
|
||||
|
@ -190,13 +201,16 @@ public class LocalHttpConnector extends HttpConnector
|
|||
setInput(BufferUtil.toBuffer(s,StringUtil.__UTF8_CHARSET));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void onClose()
|
||||
{
|
||||
super.onClose();
|
||||
connectionClosed(getAsyncConnection());
|
||||
_closed.countDown();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void shutdownOutput()
|
||||
{
|
||||
|
@ -204,6 +218,7 @@ public class LocalHttpConnector extends HttpConnector
|
|||
close();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void waitUntilClosed()
|
||||
{
|
||||
while (isOpen())
|
||||
|
@ -225,5 +240,4 @@ public class LocalHttpConnector extends HttpConnector
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ import org.junit.Test;
|
|||
*/
|
||||
public class ResponseTest
|
||||
{
|
||||
private Timer _timer;
|
||||
private Server _server;
|
||||
private LocalHttpConnector _connector;
|
||||
private HttpChannel _channel;
|
||||
|
@ -68,12 +69,13 @@ public class ResponseTest
|
|||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
_timer=new Timer(true);
|
||||
_server = new Server();
|
||||
_connector = new LocalHttpConnector();
|
||||
_server.addConnector(_connector);
|
||||
_server.setHandler(new DumpHandler());
|
||||
_server.start();
|
||||
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint();
|
||||
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint(_timer);
|
||||
HttpInput input = new HttpInput();
|
||||
AsyncConnection connection = new AbstractAsyncConnection(endp,null)
|
||||
{
|
||||
|
@ -168,6 +170,7 @@ public class ResponseTest
|
|||
@After
|
||||
public void destroy() throws Exception
|
||||
{
|
||||
_timer.cancel();
|
||||
_server.stop();
|
||||
_server.join();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.SelectChannelConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -48,7 +49,7 @@ import org.junit.runners.Parameterized.Parameters;
|
|||
public class IPAccessHandlerTest
|
||||
{
|
||||
private static Server _server;
|
||||
private static Connector _connector;
|
||||
private static Connector.NetConnector _connector;
|
||||
private static IPAccessHandler _handler;
|
||||
|
||||
private String _white;
|
||||
|
@ -62,7 +63,7 @@ public class IPAccessHandlerTest
|
|||
throws Exception
|
||||
{
|
||||
_server = new Server();
|
||||
_connector = new SocketConnector();
|
||||
_connector = new SelectChannelConnector();
|
||||
_server.setConnectors(new Connector[] { _connector });
|
||||
|
||||
_handler = new IPAccessHandler();
|
||||
|
|
|
@ -52,7 +52,7 @@ public class StatisticsHandlerTest
|
|||
|
||||
_connector = new LocalHttpConnector();
|
||||
_server.addConnector(_connector);
|
||||
_connector.setStatsOn(true);
|
||||
_connector.getStatistics().start();
|
||||
|
||||
_latchHandler = new LatchHandler();
|
||||
_statsHandler = new StatisticsHandler();
|
||||
|
@ -100,7 +100,7 @@ public class StatisticsHandlerTest
|
|||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _connector.getConnectionsOpen());
|
||||
assertEquals(1, _connector.getStatistics().getConnectionsOpen());
|
||||
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
|
@ -136,7 +136,7 @@ public class StatisticsHandlerTest
|
|||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(2, _connector.getConnectionsOpen());
|
||||
assertEquals(2, _connector.getStatistics().getConnectionsOpen());
|
||||
|
||||
assertEquals(2, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
|
@ -173,7 +173,7 @@ public class StatisticsHandlerTest
|
|||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(4, _connector.getConnectionsOpen());
|
||||
assertEquals(4, _connector.getStatistics().getConnectionsOpen());
|
||||
|
||||
assertEquals(4, _statsHandler.getRequests());
|
||||
assertEquals(2, _statsHandler.getRequestsActive());
|
||||
|
@ -258,7 +258,7 @@ public class StatisticsHandlerTest
|
|||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _connector.getConnectionsOpen());
|
||||
assertEquals(1, _connector.getStatistics().getConnectionsOpen());
|
||||
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
|
@ -297,7 +297,7 @@ public class StatisticsHandlerTest
|
|||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _connector.getConnectionsOpen());
|
||||
assertEquals(1, _connector.getStatistics().getConnectionsOpen());
|
||||
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
|
@ -385,7 +385,7 @@ public class StatisticsHandlerTest
|
|||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _connector.getConnectionsOpen());
|
||||
assertEquals(1, _connector.getStatistics().getConnectionsOpen());
|
||||
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
|
@ -505,7 +505,7 @@ public class StatisticsHandlerTest
|
|||
|
||||
barrier[0].await();
|
||||
|
||||
assertEquals(1, _connector.getConnectionsOpen());
|
||||
assertEquals(1, _connector.getStatistics().getConnectionsOpen());
|
||||
|
||||
assertEquals(1, _statsHandler.getRequests());
|
||||
assertEquals(1, _statsHandler.getRequestsActive());
|
||||
|
|
|
@ -136,7 +136,7 @@ public class SSLCloseTest extends TestCase
|
|||
baseRequest.setHandled(true);
|
||||
response.setStatus(200);
|
||||
response.setHeader("test","value");
|
||||
__endp=(AsyncEndPoint)baseRequest.getHttpChannel().getEndPoint();
|
||||
__endp=baseRequest.getHttpChannel().getEndPoint();
|
||||
|
||||
OutputStream out=response.getOutputStream();
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ public class SelectChannelServerSslTest extends HttpServerTestBase
|
|||
cf.setKeyManagerPassword("keypwd");
|
||||
cf.setTrustStore(keystorePath);
|
||||
cf.setTrustStorePassword("storepwd");
|
||||
connector.setUseDirectBuffers(true);
|
||||
startServer(connector);
|
||||
|
||||
|
||||
|
|
|
@ -506,7 +506,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s{%b,%d<=%d<=%d/%d,%d}",_name,isRunning(),getMinThreads(),getIdleThreads(),getThreads(),getMaxThreads(),(_jobs==null?-1:_jobs.size()));
|
||||
return String.format("%s{%s,%d<=%d<=%d/%d,%d}",_name,getState(),getMinThreads(),getIdleThreads(),getThreads(),getMaxThreads(),(_jobs==null?-1:_jobs.size()));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
Loading…
Reference in New Issue