fixed some more tests after EWYK refactor

This commit is contained in:
Greg Wilkins 2014-12-23 22:20:49 +01:00
parent 3f59bc4c14
commit fecc03a2f5
9 changed files with 95 additions and 33 deletions

View File

@ -271,8 +271,8 @@ public class MetaData implements Iterable<HttpField>
@Override
public String toString()
{
return String.format("%s %s %s%s%s",
getMethod(), getURI(), getVersion(), System.lineSeparator(), super.toString());
return String.format("%s{u=%s,%s,h=%d}",
getMethod(), getURI(), getVersion(), getFields().size());
}
}
@ -364,7 +364,7 @@ public class MetaData implements Iterable<HttpField>
@Override
public String toString()
{
return String.format("%s %d%s%s", getVersion(), getStatus(), System.lineSeparator(), super.toString());
return String.format("%s{s=%d,h=%d}", getVersion(), getStatus(), getFields().size());
}
}
}

View File

@ -656,6 +656,13 @@ public class SslConnection extends AbstractConnection
}
}
}
catch (IllegalStateException e)
{
// Some internal error in SSLEngine
LOG.debug(e);
getEndPoint().close();
throw new EofException(e);
}
catch (Exception e)
{
getEndPoint().close();

View File

@ -514,12 +514,12 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
private class Acceptor implements Runnable
{
private final int _acceptor;
private final int _id;
private String _name;
private Acceptor(int id)
{
_acceptor = id;
_id = id;
}
@Override
@ -527,7 +527,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
{
final Thread thread = Thread.currentThread();
String name=thread.getName();
_name=String.format("%s-acceptor-%d@%x-%s",name,_acceptor,hashCode(),AbstractConnector.this.toString());
_name=String.format("%s-acceptor-%d@%x-%s",name,_id,hashCode(),AbstractConnector.this.toString());
thread.setName(_name);
int priority=thread.getPriority();
@ -536,7 +536,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
synchronized (AbstractConnector.this)
{
_acceptors[_acceptor] = thread;
_acceptors[_id] = thread;
}
try
@ -545,7 +545,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
{
try
{
accept(_acceptor);
accept(_id);
}
catch (Throwable e)
{
@ -564,7 +564,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
synchronized (AbstractConnector.this)
{
_acceptors[_acceptor] = null;
_acceptors[_id] = null;
}
CountDownLatch stopping=_stopping;
if (stopping!=null)
@ -577,7 +577,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
{
String name=_name;
if (name==null)
return String.format("acceptor-%d@%x", _acceptor, hashCode());
return String.format("acceptor-%d@%x", _id, hashCode());
return name;
}

View File

@ -563,6 +563,14 @@ public class HttpChannelState
event.cancelTimeoutTask();
}
public boolean isIdle()
{
synchronized (this)
{
return _state==State.IDLE;
}
}
public boolean isExpired()
{
synchronized (this)
@ -613,6 +621,7 @@ public class HttpChannelState
}
}
public boolean isAsync()
{
synchronized (this)

View File

@ -32,6 +32,7 @@ import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.server.HttpChannelState.State;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IteratingCallback;
@ -198,6 +199,12 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
final HttpConnection last=setCurrentConnection(this);
// If the channel state is not idle, then a request is in progress and
// has previously been dispatched. Thus if this call to onFillable produces
// a parsed event, it will be handled by the channel mechanism and this call
// does not need to call fillInterested
final boolean handling = !_channel.getState().isIdle();
try
{
while (true)
@ -220,8 +227,8 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
{
boolean suspended = !_channel.handle();
// We should break iteration if we have suspended or changed connection
if (suspended || getEndPoint().getConnection() != this )
// We should break iteration if we have suspended or changed connection or this is not the handling thread.
if (suspended || getEndPoint().getConnection() != this || handling )
break;
}

View File

@ -356,6 +356,10 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
InputStream is=client.getInputStream();
Assert.assertFalse(client.isClosed());
OutputStream os=client.getOutputStream();
os.write("GET ".getBytes("utf-8"));
os.flush();
Thread.sleep(sleepTime);
long start = System.currentTimeMillis();
try
@ -365,7 +369,35 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
}
catch(SSLException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime);
}
@Test(timeout=60000)
public void testMaxIdleNothingSent() throws Exception
{
configureServer(new EchoHandler());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
InputStream is=client.getInputStream();
Assert.assertFalse(client.isClosed());
Thread.sleep(sleepTime);
long start = System.currentTimeMillis();
try
{
IO.toString(is);
Assert.assertEquals(-1, is.read());
}
catch(SSLException e)
{
// e.printStackTrace();
}
catch(Exception e)
{

View File

@ -1,3 +1,3 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG

View File

@ -93,6 +93,7 @@ import org.eclipse.jetty.util.annotation.ManagedObject;
public class StdErrLog extends AbstractLogger
{
private static final String EOL = System.getProperty("line.separator");
private static int __tagpad = Integer.getInteger("org.eclipse.jetty.util.log.StdErrLog.TAG_PAD",50);
private static DateCache _dateCache;
private static final Properties __props = new Properties();
@ -101,6 +102,8 @@ public class StdErrLog extends AbstractLogger
private final static boolean __long = Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.stderr.LONG","false"));
private final static boolean __escape = Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.stderr.ESCAPE","true"));
static
{
__props.putAll(Log.__props);
@ -127,6 +130,11 @@ public class StdErrLog extends AbstractLogger
}
}
public static void setTagPad(int pad)
{
__tagpad=pad;
}
public static final int LEVEL_ALL = 0;
public static final int LEVEL_DEBUG = 1;
public static final int LEVEL_INFO = 2;
@ -590,29 +598,23 @@ public class StdErrLog extends AbstractLogger
}
buffer.append(ms).append(tag);
int p=buffer.length();
if (_printLongNames)
{
buffer.append(_name);
}
else
{
buffer.append(_abbrevname);
}
p=buffer.length()-p-25;
if (p>0)
buffer.setLength(buffer.length()-p);
else
buffer.append(" ",0,-p);
buffer.append(':');
String name=_printLongNames?_name:_abbrevname;
String tname=Thread.currentThread().getName();
p=buffer.length();
buffer.append(Thread.currentThread().getName());
p=buffer.length()-p-20;
if (p>0)
buffer.setLength(buffer.length()-p);
else
buffer.append(" ",0,-p);
int p=__tagpad>0?(name.length()+tname.length()-__tagpad):0;
if (p<0)
{
buffer
.append(name)
.append(':')
.append(" ",0,-p)
.append(tname);
}
else if (p==0)
{
buffer.append(name).append(':').append(tname);
}
buffer.append(':');
if (_source)

View File

@ -38,6 +38,11 @@ import org.junit.Test;
*/
public class StdErrLogTest
{
static
{
StdErrLog.setTagPad(0);
}
@Before
public void before()
{