Merge branch 'jetty-9.4.x' into jetty-9.4.x-ewyk

This commit is contained in:
Greg Wilkins 2017-03-23 16:01:00 +11:00
commit f89b08d08a
8 changed files with 276 additions and 145 deletions

View File

@ -381,6 +381,12 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
throw _state.getAsyncContextEvent().getThrowable(); throw _state.getAsyncContextEvent().getThrowable();
} }
case READ_PRODUCE:
{
_request.getHttpInput().produceContent();
break;
}
case READ_CALLBACK: case READ_CALLBACK:
{ {
ContextHandler handler=_state.getContextHandler(); ContextHandler handler=_state.getContextHandler();

View File

@ -78,6 +78,7 @@ public class HttpChannelState
ERROR_DISPATCH, // handle a normal error ERROR_DISPATCH, // handle a normal error
ASYNC_ERROR, // handle an async error ASYNC_ERROR, // handle an async error
WRITE_CALLBACK, // handle an IO write callback WRITE_CALLBACK, // handle an IO write callback
READ_PRODUCE, // Check is a read is possible by parsing/filling
READ_CALLBACK, // handle an IO read callback READ_CALLBACK, // handle an IO read callback
COMPLETE, // Complete the response COMPLETE, // Complete the response
TERMINATED, // No further actions TERMINATED, // No further actions
@ -99,19 +100,15 @@ public class HttpChannelState
ERRORED // The error has been processed ERRORED // The error has been processed
} }
private enum Interest private enum AsyncRead
{ {
NONE(false), NONE, // No isReady; No data
NEEDED(true), AVAILABLE, // No isReady; onDataAvailable
REGISTERED(true); NEEDED, // isReady()==false handling; No data
REGISTERED, // isReady()==false !handling; No data
private final boolean _interested; POSSIBLE, // isReady()==false async callback called (http/1 only)
PRODUCING, // isReady()==false handling content production (http/1 only)
Interest(boolean interest) READY // isReady() was false, data now available
{
_interested = interest;
}
private boolean isInterested() { return _interested;}
} }
private final Locker _locker=new Locker(); private final Locker _locker=new Locker();
@ -120,8 +117,7 @@ public class HttpChannelState
private State _state; private State _state;
private Async _async; private Async _async;
private boolean _initial; private boolean _initial;
private boolean _asyncReadPossible; private AsyncRead _asyncRead=AsyncRead.NONE;
private Interest _asyncRead=Interest.NONE;
private boolean _asyncWritePossible; private boolean _asyncWritePossible;
private long _timeoutMs=DEFAULT_TIMEOUT; private long _timeoutMs=DEFAULT_TIMEOUT;
private AsyncContextEvent _event; private AsyncContextEvent _event;
@ -187,15 +183,14 @@ public class HttpChannelState
public String toStringLocked() public String toStringLocked()
{ {
return String.format("%s@%x{s=%s a=%s i=%b r=%s/%s w=%b}", return String.format("%s@%x{s=%s a=%s i=%b r=%s w=%b}",
getClass().getSimpleName(), getClass().getSimpleName(),
hashCode(), hashCode(),
_state, _state,
_async, _async,
_initial, _initial,
_asyncRead, _asyncRead,
_asyncReadPossible, _asyncWritePossible);
_asyncWritePossible);
} }
@ -234,11 +229,18 @@ public class HttpChannelState
return Action.TERMINATED; return Action.TERMINATED;
case ASYNC_WOKEN: case ASYNC_WOKEN:
if (_asyncReadPossible && _asyncRead.isInterested()) switch (_asyncRead)
{ {
_state=State.ASYNC_IO; case POSSIBLE:
_asyncRead=Interest.NONE; _state=State.ASYNC_IO;
return Action.READ_CALLBACK; _asyncRead=AsyncRead.PRODUCING;
return Action.READ_PRODUCE;
case READY:
_state=State.ASYNC_IO;
_asyncRead=AsyncRead.NONE;
return Action.READ_CALLBACK;
default:
break;
} }
if (_asyncWritePossible) if (_asyncWritePossible)
@ -385,7 +387,7 @@ public class HttpChannelState
protected Action unhandle() protected Action unhandle()
{ {
Action action; Action action;
boolean read_interested=false; boolean read_interested = false;
try(Locker.Lock lock= _locker.lock()) try(Locker.Lock lock= _locker.lock())
{ {
@ -412,7 +414,7 @@ public class HttpChannelState
} }
_initial=false; _initial=false;
switch(_async) async: switch(_async)
{ {
case COMPLETE: case COMPLETE:
_state=State.COMPLETING; _state=State.COMPLETING;
@ -427,13 +429,31 @@ public class HttpChannelState
break; break;
case STARTED: case STARTED:
if (_asyncReadPossible && _asyncRead.isInterested()) switch(_asyncRead)
{ {
_state=State.ASYNC_IO; case READY:
_asyncRead=Interest.NONE; _state=State.ASYNC_IO;
action=Action.READ_CALLBACK; _asyncRead=AsyncRead.NONE;
action=Action.READ_CALLBACK;
break async;
case POSSIBLE:
_state=State.ASYNC_IO;
action=Action.READ_PRODUCE;
break async;
case NEEDED:
case PRODUCING:
_asyncRead=AsyncRead.REGISTERED;
read_interested=true;
case NONE:
case AVAILABLE:
case REGISTERED:
break;
} }
else if (_asyncWritePossible)
if (_asyncWritePossible)
{ {
_state=State.ASYNC_IO; _state=State.ASYNC_IO;
_asyncWritePossible=false; _asyncWritePossible=false;
@ -443,11 +463,6 @@ public class HttpChannelState
{ {
_state=State.ASYNC_WAIT; _state=State.ASYNC_WAIT;
action=Action.WAIT; action=Action.WAIT;
if (_asyncRead==Interest.NEEDED)
{
_asyncRead=Interest.REGISTERED;
read_interested=true;
}
Scheduler scheduler=_channel.getScheduler(); Scheduler scheduler=_channel.getScheduler();
if (scheduler!=null && _timeoutMs>0) if (scheduler!=null && _timeoutMs>0)
_event.setTimeoutTask(scheduler.schedule(_event,_timeoutMs,TimeUnit.MILLISECONDS)); _event.setTimeoutTask(scheduler.schedule(_event,_timeoutMs,TimeUnit.MILLISECONDS));
@ -915,8 +930,7 @@ public class HttpChannelState
_state=State.IDLE; _state=State.IDLE;
_async=Async.NOT_ASYNC; _async=Async.NOT_ASYNC;
_initial=true; _initial=true;
_asyncReadPossible=false; _asyncRead=AsyncRead.NONE;
_asyncRead=Interest.NONE;
_asyncWritePossible=false; _asyncWritePossible=false;
_timeoutMs=DEFAULT_TIMEOUT; _timeoutMs=DEFAULT_TIMEOUT;
_event=null; _event=null;
@ -943,8 +957,7 @@ public class HttpChannelState
_state=State.UPGRADED; _state=State.UPGRADED;
_async=Async.NOT_ASYNC; _async=Async.NOT_ASYNC;
_initial=true; _initial=true;
_asyncReadPossible=false; _asyncRead=AsyncRead.NONE;
_asyncRead=Interest.NONE;
_asyncWritePossible=false; _asyncWritePossible=false;
_timeoutMs=DEFAULT_TIMEOUT; _timeoutMs=DEFAULT_TIMEOUT;
_event=null; _event=null;
@ -1133,19 +1146,30 @@ public class HttpChannelState
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("onReadUnready {}",toStringLocked()); LOG.debug("onReadUnready {}",toStringLocked());
// We were already unready, this is not a state change, so do nothing switch(_asyncRead)
if (_asyncRead!=Interest.REGISTERED)
{ {
_asyncReadPossible=false; // Assumes this has been checked in isReady() with lock held case NONE:
if (_state==State.ASYNC_WAIT) case AVAILABLE:
{ case READY:
interested=true; case NEEDED:
_asyncRead=Interest.REGISTERED; if (_state==State.ASYNC_WAIT)
} {
else interested=true;
{ _asyncRead=AsyncRead.REGISTERED;
_asyncRead=Interest.NEEDED; }
} else
{
_asyncRead=AsyncRead.NEEDED;
}
break;
case REGISTERED:
case POSSIBLE:
case PRODUCING:
break;
default:
throw new IllegalStateException(toStringLocked());
} }
} }
@ -1160,7 +1184,7 @@ public class HttpChannelState
* is returned. * is returned.
* @return True IFF the channel was unready and in ASYNC_WAIT state * @return True IFF the channel was unready and in ASYNC_WAIT state
*/ */
public boolean onReadPossible() public boolean onDataAvailable()
{ {
boolean woken=false; boolean woken=false;
try(Locker.Lock lock= _locker.lock()) try(Locker.Lock lock= _locker.lock())
@ -1168,11 +1192,33 @@ public class HttpChannelState
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("onReadPossible {}",toStringLocked()); LOG.debug("onReadPossible {}",toStringLocked());
_asyncReadPossible=true; switch(_asyncRead)
if (_state==State.ASYNC_WAIT && _asyncRead.isInterested())
{ {
woken=true; case NONE:
_state=State.ASYNC_WOKEN; _asyncRead=AsyncRead.AVAILABLE;
break;
case AVAILABLE:
break;
case PRODUCING:
_asyncRead=AsyncRead.READY;
break;
case NEEDED:
case REGISTERED:
case POSSIBLE:
case READY:
_asyncRead=AsyncRead.READY;
if (_state==State.ASYNC_WAIT)
{
woken=true;
_state=State.ASYNC_WOKEN;
}
break;
default:
throw new IllegalStateException(toStringLocked());
} }
} }
return woken; return woken;
@ -1181,7 +1227,7 @@ public class HttpChannelState
/** /**
* Called to signal that the channel is ready for a callback. * Called to signal that the channel is ready for a callback.
* This is similar to calling {@link #onReadUnready()} followed by * This is similar to calling {@link #onReadUnready()} followed by
* {@link #onReadPossible()}, except that as content is already * {@link #onDataAvailable()}, except that as content is already
* available, read interest is never set. * available, read interest is never set.
* @return true if woken * @return true if woken
*/ */
@ -1192,13 +1238,52 @@ public class HttpChannelState
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("onReadReady {}",toStringLocked()); LOG.debug("onReadReady {}",toStringLocked());
_asyncRead=Interest.REGISTERED; switch(_asyncRead)
_asyncReadPossible=true;
if (_state==State.ASYNC_WAIT)
{ {
woken=true; case NONE:
_state=State.ASYNC_WOKEN; case AVAILABLE:
_asyncRead=AsyncRead.READY;
if (_state==State.ASYNC_WAIT)
{
woken=true;
_state=State.ASYNC_WOKEN;
}
break;
default:
throw new IllegalStateException(toStringLocked());
}
}
return woken;
}
/**
* Called to indicate that more content may be available,
* but that a handling thread may need to produce (fill/parse)
* it. Typically called by the async read success callback.
*/
public boolean onReadPossible()
{
boolean woken=false;
try(Locker.Lock lock= _locker.lock())
{
if (LOG.isDebugEnabled())
LOG.debug("onReadReady {}",toStringLocked());
switch(_asyncRead)
{
case REGISTERED:
_asyncRead=AsyncRead.POSSIBLE;
if (_state==State.ASYNC_WAIT)
{
woken=true;
_state=State.ASYNC_WOKEN;
}
break;
default:
throw new IllegalStateException(toStringLocked());
} }
} }
return woken; return woken;
@ -1217,9 +1302,8 @@ public class HttpChannelState
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("onEof {}",toStringLocked()); LOG.debug("onEof {}",toStringLocked());
// Force read interest so onAllDataRead can be called // Force read ready so onAllDataRead can be called
_asyncRead=Interest.REGISTERED; _asyncRead=AsyncRead.READY;
_asyncReadPossible=true;
if (_state==State.ASYNC_WAIT) if (_state==State.ASYNC_WAIT)
{ {
woken=true; woken=true;
@ -1229,14 +1313,6 @@ public class HttpChannelState
return woken; return woken;
} }
public boolean isReadPossible()
{
try(Locker.Lock lock= _locker.lock())
{
return _asyncReadPossible;
}
}
public boolean onWritePossible() public boolean onWritePossible()
{ {
boolean wake=false; boolean wake=false;

View File

@ -625,10 +625,8 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
@Override @Override
public void succeeded() public void succeeded()
{ {
if (fillAndParseForContent()) if (_channel.getState().onReadPossible())
_channel.handle(); _channel.handle();
else if (!_input.isFinished() && !_input.hasContent())
asyncReadFillInterested();
} }
@Override @Override

View File

@ -577,7 +577,7 @@ public class HttpInput extends ServletInputStream implements Runnable
if (_listener == null) if (_listener == null)
_inputQ.notify(); _inputQ.notify();
else else
woken = _channelState.onReadPossible(); woken = _channelState.onDataAvailable();
} }
return woken; return woken;
} }
@ -612,7 +612,7 @@ public class HttpInput extends ServletInputStream implements Runnable
if (_listener == null) if (_listener == null)
_inputQ.notify(); _inputQ.notify();
else else
woken = _channelState.onReadPossible(); woken = _channelState.onDataAvailable();
} }
} }
return woken; return woken;
@ -800,7 +800,7 @@ public class HttpInput extends ServletInputStream implements Runnable
if (_listener == null) if (_listener == null)
_inputQ.notify(); _inputQ.notify();
else else
woken = _channelState.onReadPossible(); woken = _channelState.onDataAvailable();
} }
return woken; return woken;

View File

@ -29,6 +29,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -230,7 +231,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
try (FileInputStream in = new FileInputStream(file)) try (FileInputStream in = new FileInputStream(file))
{ {
SessionData data = load(in); SessionData data = load(in, id);
data.setLastSaved(file.lastModified()); data.setLastSaved(file.lastModified());
reference.set(data); reference.set(data);
} }
@ -498,6 +499,11 @@ public class FileSessionDataStore extends AbstractSessionDataStore
} }
/**
* Remove all existing session files for the session in the context
* @param storeDir where the session files are stored
* @param idInContext the session id within a particular context
*/
private void deleteAllFiles(final File storeDir, final String idInContext) private void deleteAllFiles(final File storeDir, final String idInContext)
{ {
File[] files = storeDir.listFiles (new FilenameFilter() { File[] files = storeDir.listFiles (new FilenameFilter() {
@ -522,7 +528,14 @@ public class FileSessionDataStore extends AbstractSessionDataStore
//delete all files //delete all files
for (File f:files) for (File f:files)
{ {
f.delete(); try
{
Files.deleteIfExists(f.toPath());
}
catch (Exception e)
{
LOG.warn("Unable to delete session file", e);
}
} }
} }
@ -547,56 +560,86 @@ public class FileSessionDataStore extends AbstractSessionDataStore
{ {
if (dir != storeDir) if (dir != storeDir)
return false; return false;
if (!match(name)) if (!match(name))
return false; return false;
return (name.contains(idWithContext)); return (name.contains(idWithContext));
} }
}); });
//no file for that session //no file for that session
if (files == null || files.length == 0) if (files == null || files.length == 0)
return null; return null;
//delete all but the most recent file //delete all but the most recent file
File file = null; File newest = null;
for (File f:files) for (File f:files)
{ {
if (file == null) try
file = f;
else
{ {
//accept the newest file if (newest == null)
if (f.lastModified() > file.lastModified())
{ {
file.delete(); //haven't looked at any files yet
file = f; newest = f;
} }
else else
{ {
f.delete(); if (f.lastModified() > newest.lastModified())
{
//this file is more recent
Files.deleteIfExists(newest.toPath());
newest = f;
}
else if (f.lastModified() < newest.lastModified())
{
//this file is older
Files.deleteIfExists(f.toPath());
}
else
{
//files have same last modified times, decide based on latest expiry time
long exp1 = getExpiryFromFile(newest);
long exp2 = getExpiryFromFile(f);
if (exp2 >= exp1)
{
//this file has a later expiry date
Files.deleteIfExists(newest.toPath());
newest = f;
}
else
{
//this file has an earlier expiry date
Files.deleteIfExists(f.toPath());
}
}
} }
} }
catch (Exception e)
{
LOG.warn("Unable to delete old session file", e);
}
} }
return file; return newest;
} }
/** /**
* @param is inputstream containing session data * @param is inputstream containing session data
* @param expectedId the id we've been told to load
* @return the session data * @return the session data
* @throws Exception * @throws Exception
*/ */
private SessionData load (InputStream is) private SessionData load (InputStream is, String expectedId)
throws Exception throws Exception
{ {
String id = null; String id = null; //the actual id from inside the file
try try
{ {
@ -629,7 +672,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
} }
catch (Exception e) catch (Exception e)
{ {
throw new UnreadableSessionDataException(id, _context, e); throw new UnreadableSessionDataException(expectedId, _context, e);
} }
} }

View File

@ -120,9 +120,9 @@ public class HttpInputAsyncStateTest
} }
@Override @Override
public boolean onReadPossible() public boolean onDataAvailable()
{ {
boolean wake = super.onReadPossible(); boolean wake = super.onDataAvailable();
__history.add("onReadPossible "+wake); __history.add("onReadPossible "+wake);
return wake; return wake;
} }

View File

@ -42,19 +42,19 @@ public class HttpInputTest
@Override @Override
public void onError(Throwable t) public void onError(Throwable t)
{ {
_history.add("onError:" + t); _history.add("l.onError:" + t);
} }
@Override @Override
public void onDataAvailable() throws IOException public void onDataAvailable() throws IOException
{ {
_history.add("onDataAvailable"); _history.add("l.onDataAvailable");
} }
@Override @Override
public void onAllDataRead() throws IOException public void onAllDataRead() throws IOException
{ {
_history.add("onAllDataRead"); _history.add("l.onAllDataRead");
} }
}; };
private HttpInput _in; private HttpInput _in;
@ -99,21 +99,28 @@ public class HttpInputTest
@Override @Override
public void onReadUnready() public void onReadUnready()
{ {
_history.add("unready"); _history.add("s.onReadUnready");
super.onReadUnready(); super.onReadUnready();
} }
@Override @Override
public boolean onReadPossible() public boolean onReadPossible()
{ {
_history.add("onReadPossible"); _history.add("s.onReadPossible");
return super.onReadPossible(); return super.onReadPossible();
} }
@Override
public boolean onDataAvailable()
{
_history.add("s.onDataAvailable");
return super.onDataAvailable();
}
@Override @Override
public boolean onReadReady() public boolean onReadReady()
{ {
_history.add("ready"); _history.add("s.onReadReady");
return super.onReadReady(); return super.onReadReady();
} }
}) })
@ -387,17 +394,17 @@ public class HttpInputTest
{ {
_in.setReadListener(_listener); _in.setReadListener(_listener);
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isReady(), Matchers.equalTo(false)); Assert.assertThat(_in.isReady(), Matchers.equalTo(false));
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isReady(), Matchers.equalTo(false)); Assert.assertThat(_in.isReady(), Matchers.equalTo(false));
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
} }
@ -406,21 +413,21 @@ public class HttpInputTest
{ {
_in.setReadListener(_listener); _in.setReadListener(_listener);
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isReady(), Matchers.equalTo(false)); Assert.assertThat(_in.isReady(), Matchers.equalTo(false));
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
_in.addContent(new TContent("AB")); _in.addContent(new TContent("AB"));
_fillAndParseSimulate.add("CD"); _fillAndParseSimulate.add("CD");
Assert.assertThat(_history.poll(), Matchers.equalTo("onReadPossible")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onDataAvailable"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
_in.run(); _in.run();
Assert.assertThat(_history.poll(), Matchers.equalTo("onDataAvailable")); Assert.assertThat(_history.poll(), Matchers.equalTo("l.onDataAvailable"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isReady(), Matchers.equalTo(true)); Assert.assertThat(_in.isReady(), Matchers.equalTo(true));
@ -434,7 +441,7 @@ public class HttpInputTest
Assert.assertThat(_in.isReady(), Matchers.equalTo(true)); Assert.assertThat(_in.isReady(), Matchers.equalTo(true));
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 1")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 1"));
Assert.assertThat(_history.poll(), Matchers.equalTo("onReadPossible")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onDataAvailable"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.read(), Matchers.equalTo((int)'C')); Assert.assertThat(_in.read(), Matchers.equalTo((int)'C'));
@ -446,7 +453,7 @@ public class HttpInputTest
Assert.assertThat(_in.isReady(), Matchers.equalTo(false)); Assert.assertThat(_in.isReady(), Matchers.equalTo(false));
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
} }
@ -455,13 +462,13 @@ public class HttpInputTest
{ {
_in.setReadListener(_listener); _in.setReadListener(_listener);
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
_in.eof(); _in.eof();
Assert.assertThat(_in.isReady(), Matchers.equalTo(true)); Assert.assertThat(_in.isReady(), Matchers.equalTo(true));
Assert.assertThat(_in.isFinished(), Matchers.equalTo(false)); Assert.assertThat(_in.isFinished(), Matchers.equalTo(false));
Assert.assertThat(_history.poll(), Matchers.equalTo("onReadPossible")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onDataAvailable"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.read(), Matchers.equalTo(-1)); Assert.assertThat(_in.read(), Matchers.equalTo(-1));
@ -474,22 +481,22 @@ public class HttpInputTest
{ {
_in.setReadListener(_listener); _in.setReadListener(_listener);
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isReady(), Matchers.equalTo(false)); Assert.assertThat(_in.isReady(), Matchers.equalTo(false));
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
_in.addContent(new TContent("AB")); _in.addContent(new TContent("AB"));
_fillAndParseSimulate.add("_EOF_"); _fillAndParseSimulate.add("_EOF_");
Assert.assertThat(_history.poll(), Matchers.equalTo("onReadPossible")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onDataAvailable"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
_in.run(); _in.run();
Assert.assertThat(_history.poll(), Matchers.equalTo("onDataAvailable")); Assert.assertThat(_history.poll(), Matchers.equalTo("l.onDataAvailable"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isReady(), Matchers.equalTo(true)); Assert.assertThat(_in.isReady(), Matchers.equalTo(true));
@ -504,7 +511,7 @@ public class HttpInputTest
Assert.assertThat(_in.isFinished(), Matchers.equalTo(false)); Assert.assertThat(_in.isFinished(), Matchers.equalTo(false));
Assert.assertThat(_in.isReady(), Matchers.equalTo(true)); Assert.assertThat(_in.isReady(), Matchers.equalTo(true));
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 1")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 1"));
Assert.assertThat(_history.poll(), Matchers.equalTo("onReadPossible")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onDataAvailable"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isFinished(), Matchers.equalTo(false)); Assert.assertThat(_in.isFinished(), Matchers.equalTo(false));
@ -521,21 +528,21 @@ public class HttpInputTest
{ {
_in.setReadListener(_listener); _in.setReadListener(_listener);
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isReady(), Matchers.equalTo(false)); Assert.assertThat(_in.isReady(), Matchers.equalTo(false));
Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0")); Assert.assertThat(_history.poll(), Matchers.equalTo("produceContent 0"));
Assert.assertThat(_history.poll(), Matchers.equalTo("unready")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onReadUnready"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
_in.failed(new TimeoutException()); _in.failed(new TimeoutException());
Assert.assertThat(_history.poll(), Matchers.equalTo("onReadPossible")); Assert.assertThat(_history.poll(), Matchers.equalTo("s.onDataAvailable"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
_in.run(); _in.run();
Assert.assertThat(_in.isFinished(), Matchers.equalTo(true)); Assert.assertThat(_in.isFinished(), Matchers.equalTo(true));
Assert.assertThat(_history.poll(), Matchers.equalTo("onError:java.util.concurrent.TimeoutException")); Assert.assertThat(_history.poll(), Matchers.equalTo("l.onError:java.util.concurrent.TimeoutException"));
Assert.assertThat(_history.poll(), Matchers.nullValue()); Assert.assertThat(_history.poll(), Matchers.nullValue());
Assert.assertThat(_in.isReady(), Matchers.equalTo(true)); Assert.assertThat(_in.isReady(), Matchers.equalTo(true));

View File

@ -85,7 +85,7 @@ public class FileSessionManagerTest
handler.setSessionCache(ss); handler.setSessionCache(ss);
ss.setSessionDataStore(ds); ss.setSessionDataStore(ds);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes"); File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
testDir.mkdirs(); FS.ensureEmpty(testDir);
ds.setStoreDir(testDir); ds.setStoreDir(testDir);
handler.setSessionIdManager(idmgr); handler.setSessionIdManager(idmgr);
handler.start(); handler.start();
@ -125,8 +125,9 @@ public class FileSessionManagerTest
DefaultSessionCache ss = new DefaultSessionCache(handler); DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionCache(ss); handler.setSessionCache(ss);
ss.setSessionDataStore(ds); ss.setSessionDataStore(ds);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes"); File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
testDir.mkdirs(); FS.ensureEmpty(testDir);
ds.setStoreDir(testDir); ds.setStoreDir(testDir);
handler.setSessionIdManager(idmgr); handler.setSessionIdManager(idmgr);
handler.start(); handler.start();
@ -135,26 +136,27 @@ public class FileSessionManagerTest
String name1 = "100__0.0.0.0_abc"; String name1 = "100__0.0.0.0_abc";
File f1 = new File(testDir, name1); File f1 = new File(testDir, name1);
if (f1.exists()) if (f1.exists())
f1.delete(); Assert.assertTrue(f1.delete());
f1.createNewFile(); f1.createNewFile();
Thread.currentThread().sleep(20); Thread.sleep(1100);
String name2 = "101__0.0.0.0_abc"; String name2 = "101__0.0.0.0_abc";
File f2 = new File(testDir, name2); File f2 = new File(testDir, name2);
if (f2.exists()) if (f2.exists())
f2.delete(); Assert.assertTrue(f2.delete());
f2.createNewFile(); f2.createNewFile();
Thread.currentThread().sleep(20); Thread.sleep(1100);
String name3 = "102__0.0.0.0_abc"; String name3 = "102__0.0.0.0_abc";
File f3 = new File(testDir, name3); File f3 = new File(testDir, name3);
if (f3.exists()) if (f3.exists())
f3.delete(); Assert.assertTrue(f3.delete());
f3.createNewFile(); f3.createNewFile();
Thread.currentThread().sleep(20); Thread.sleep(1100);
Session session = handler.getSession("abc"); Session session = handler.getSession("abc");
Assert.assertTrue(!f1.exists()); Assert.assertTrue(!f1.exists());
@ -202,8 +204,7 @@ public class FileSessionManagerTest
public void testHashSession() throws Exception public void testHashSession() throws Exception
{ {
File testDir = MavenTestingUtils.getTargetTestingDir("saved"); File testDir = MavenTestingUtils.getTargetTestingDir("saved");
IO.delete(testDir); FS.ensureEmpty(testDir);
testDir.mkdirs();
Server server = new Server(); Server server = new Server();
SessionHandler handler = new SessionHandler(); SessionHandler handler = new SessionHandler();
@ -286,7 +287,7 @@ public class FileSessionManagerTest
handler.setSessionCache(ss); handler.setSessionCache(ss);
ss.setSessionDataStore(ds); ss.setSessionDataStore(ds);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes"); File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
testDir.mkdirs(); FS.ensureEmpty(testDir);
ds.setStoreDir(testDir); ds.setStoreDir(testDir);
handler.setSessionIdManager(idmgr); handler.setSessionIdManager(idmgr);
handler.start(); handler.start();