Merge remote-tracking branch 'origin/master' into jetty-8
This commit is contained in:
commit
b8b5df27d6
|
@ -72,7 +72,7 @@ import org.eclipse.jetty.util.thread.Timeout;
|
|||
*/
|
||||
public class HttpExchange
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(HttpExchange.class);
|
||||
static final Logger LOG = Log.getLogger(HttpExchange.class);
|
||||
|
||||
public static final int STATUS_START = 0;
|
||||
public static final int STATUS_WAITING_FOR_CONNECTION = 1;
|
||||
|
|
|
@ -54,7 +54,7 @@ import org.junit.Test;
|
|||
*/
|
||||
public class HttpExchangeTest
|
||||
{
|
||||
final static boolean verbose=true;
|
||||
final static boolean verbose=HttpExchange.LOG.isDebugEnabled();
|
||||
protected static int _maxConnectionsPerAddress = 2;
|
||||
protected static String _scheme = "http";
|
||||
protected static Server _server;
|
||||
|
|
|
@ -44,6 +44,7 @@ public class ChannelEndPoint implements EndPoint
|
|||
protected final InetSocketAddress _local;
|
||||
protected final InetSocketAddress _remote;
|
||||
protected int _maxIdleTime;
|
||||
private boolean _ishut;
|
||||
|
||||
public ChannelEndPoint(ByteChannel channel) throws IOException
|
||||
{
|
||||
|
@ -111,29 +112,31 @@ public class ChannelEndPoint implements EndPoint
|
|||
LOG.debug("ishut {}",this);
|
||||
if (_channel.isOpen())
|
||||
{
|
||||
if (_channel instanceof SocketChannel)
|
||||
if (_socket!=null)
|
||||
{
|
||||
Socket socket= ((SocketChannel)_channel).socket();
|
||||
try
|
||||
{
|
||||
if (!socket.isInputShutdown())
|
||||
socket.shutdownInput();
|
||||
if (!_socket.isInputShutdown())
|
||||
{
|
||||
// System.err.println("ISHUT "+_socket);
|
||||
_socket.shutdownInput();
|
||||
}
|
||||
}
|
||||
catch(SocketException e)
|
||||
{
|
||||
// System.err.println(e);
|
||||
LOG.debug(e.toString());
|
||||
LOG.ignore(e);
|
||||
if (!socket.isClosed())
|
||||
close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(socket.isOutputShutdown() && !socket.isClosed())
|
||||
_ishut=true;
|
||||
if(_socket.isOutputShutdown() && !_socket.isClosed())
|
||||
close();
|
||||
}
|
||||
}
|
||||
else
|
||||
close();
|
||||
_ishut=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,24 +153,26 @@ public class ChannelEndPoint implements EndPoint
|
|||
LOG.debug("oshut {}",this);
|
||||
if (_channel.isOpen())
|
||||
{
|
||||
if (_channel instanceof SocketChannel)
|
||||
if (_socket!=null)
|
||||
{
|
||||
Socket socket= ((SocketChannel)_channel).socket();
|
||||
try
|
||||
{
|
||||
if (!socket.isOutputShutdown())
|
||||
socket.shutdownOutput();
|
||||
if (!_socket.isOutputShutdown())
|
||||
{
|
||||
// System.err.println("OSHUT "+_socket);
|
||||
_socket.shutdownOutput();
|
||||
}
|
||||
}
|
||||
catch(SocketException e)
|
||||
{
|
||||
LOG.warn(e.toString());
|
||||
LOG.debug(e);
|
||||
if (!socket.isClosed())
|
||||
LOG.debug(e.toString());
|
||||
LOG.ignore(e);
|
||||
if (!_socket.isClosed())
|
||||
close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (socket.isInputShutdown() && !socket.isClosed())
|
||||
if ((_ishut||_socket.isInputShutdown()) && !_socket.isClosed())
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +196,7 @@ public class ChannelEndPoint implements EndPoint
|
|||
|
||||
public boolean isInputShutdown()
|
||||
{
|
||||
return !_channel.isOpen() || _socket!=null && _socket.isInputShutdown();
|
||||
return !_channel.isOpen() || _ishut || _socket!=null && _socket.isInputShutdown();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -200,6 +205,8 @@ public class ChannelEndPoint implements EndPoint
|
|||
public void close() throws IOException
|
||||
{
|
||||
LOG.debug("close {}",this);
|
||||
|
||||
// System.err.println("CLOSE "+_socket);
|
||||
_channel.close();
|
||||
}
|
||||
|
||||
|
@ -208,6 +215,8 @@ public class ChannelEndPoint implements EndPoint
|
|||
*/
|
||||
public int fill(Buffer buffer) throws IOException
|
||||
{
|
||||
if (_ishut)
|
||||
return -1;
|
||||
Buffer buf = buffer.buffer();
|
||||
int len=0;
|
||||
if (buf instanceof NIOBuffer)
|
||||
|
|
|
@ -657,14 +657,8 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
|||
|
||||
while (now<end)
|
||||
{
|
||||
process(null,null);
|
||||
synchronized (SslConnection.this)
|
||||
{
|
||||
if (_unwrapBuf!=null && _unwrapBuf.hasContent())
|
||||
if (process(null,null))
|
||||
break;
|
||||
if (_inbound!=null && _inbound.hasContent())
|
||||
break;
|
||||
}
|
||||
_endp.blockReadable(end-now);
|
||||
now = System.currentTimeMillis();
|
||||
}
|
||||
|
|
|
@ -24,11 +24,15 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
EndPointPair<T> c = newConnection();
|
||||
Buffer buffer = new IndirectNIOBuffer(4096);
|
||||
|
||||
// Client sends a request
|
||||
c.client.flush(new ByteArrayBuffer("request"));
|
||||
|
||||
// Server receives the request
|
||||
int len = c.server.fill(buffer);
|
||||
assertEquals(7,len);
|
||||
assertEquals("request",buffer.toString());
|
||||
|
||||
// Client and server are open
|
||||
assertTrue(c.client.isOpen());
|
||||
assertFalse(c.client.isInputShutdown());
|
||||
assertFalse(c.client.isOutputShutdown());
|
||||
|
@ -36,9 +40,11 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertFalse(c.server.isInputShutdown());
|
||||
assertFalse(c.server.isOutputShutdown());
|
||||
|
||||
// Server sends response and closes output
|
||||
c.server.flush(new ByteArrayBuffer("response"));
|
||||
c.server.shutdownOutput();
|
||||
|
||||
// client server are open, server is oshut
|
||||
assertTrue(c.client.isOpen());
|
||||
assertFalse(c.client.isInputShutdown());
|
||||
assertFalse(c.client.isOutputShutdown());
|
||||
|
@ -46,11 +52,13 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertFalse(c.server.isInputShutdown());
|
||||
assertTrue(c.server.isOutputShutdown());
|
||||
|
||||
// Client reads response
|
||||
buffer.clear();
|
||||
len = c.client.fill(buffer);
|
||||
assertEquals(8,len);
|
||||
assertEquals("response",buffer.toString());
|
||||
|
||||
// Client and server are open, server is oshut
|
||||
assertTrue(c.client.isOpen());
|
||||
assertFalse(c.client.isInputShutdown());
|
||||
assertFalse(c.client.isOutputShutdown());
|
||||
|
@ -58,10 +66,12 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertFalse(c.server.isInputShutdown());
|
||||
assertTrue(c.server.isOutputShutdown());
|
||||
|
||||
// Client reads -1
|
||||
buffer.clear();
|
||||
len = c.client.fill(buffer);
|
||||
assertEquals(-1,len);
|
||||
|
||||
// Client and server are open, server is oshut, client is ishut
|
||||
assertTrue(c.client.isOpen());
|
||||
assertTrue(c.client.isInputShutdown());
|
||||
assertFalse(c.client.isOutputShutdown());
|
||||
|
@ -69,8 +79,10 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertFalse(c.server.isInputShutdown());
|
||||
assertTrue(c.server.isOutputShutdown());
|
||||
|
||||
// Client shutsdown output, which is a close because already ishut
|
||||
c.client.shutdownOutput();
|
||||
|
||||
// Client is closed. Server is open and oshut
|
||||
assertFalse(c.client.isOpen());
|
||||
assertTrue(c.client.isInputShutdown());
|
||||
assertTrue(c.client.isOutputShutdown());
|
||||
|
@ -78,10 +90,12 @@ public abstract class EndPointTest<T extends EndPoint>
|
|||
assertFalse(c.server.isInputShutdown());
|
||||
assertTrue(c.server.isOutputShutdown());
|
||||
|
||||
// Server reads close
|
||||
buffer.clear();
|
||||
len = c.server.fill(buffer);
|
||||
assertEquals(-1,len);
|
||||
|
||||
// Client and Server are closed
|
||||
assertFalse(c.client.isOpen());
|
||||
assertTrue(c.client.isInputShutdown());
|
||||
assertTrue(c.client.isOutputShutdown());
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.Assert;
|
||||
|
@ -51,14 +53,12 @@ public class IOTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testHalfCloses() throws Exception
|
||||
public void testHalfClose() throws Exception
|
||||
{
|
||||
ServerSocket connector = new ServerSocket(0);
|
||||
|
||||
Socket client = new Socket("localhost",connector.getLocalPort());
|
||||
System.err.println(client);
|
||||
Socket server = connector.accept();
|
||||
System.err.println(server);
|
||||
|
||||
// we can write both ways
|
||||
client.getOutputStream().write(1);
|
||||
|
@ -130,8 +130,72 @@ public class IOTest
|
|||
server.close();
|
||||
assertTrue(server.isClosed());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHalfCloseClientServer() throws Exception
|
||||
{
|
||||
ServerSocketChannel connector = ServerSocketChannel.open();
|
||||
connector.socket().bind(null);
|
||||
|
||||
Socket client = SocketChannel.open(connector.socket().getLocalSocketAddress()).socket();
|
||||
client.setSoTimeout(1000);
|
||||
client.setSoLinger(false,-1);
|
||||
Socket server = connector.accept().socket();
|
||||
server.setSoTimeout(1000);
|
||||
server.setSoLinger(false,-1);
|
||||
|
||||
// Write from client to server
|
||||
client.getOutputStream().write(1);
|
||||
|
||||
// Server reads
|
||||
assertEquals(1,server.getInputStream().read());
|
||||
|
||||
// Write from server to client with oshut
|
||||
server.getOutputStream().write(1);
|
||||
System.err.println("OSHUT "+server);
|
||||
server.shutdownOutput();
|
||||
|
||||
// Client reads response
|
||||
assertEquals(1,client.getInputStream().read());
|
||||
|
||||
try
|
||||
{
|
||||
// Client reads -1 and does ishut
|
||||
assertEquals(-1,client.getInputStream().read());
|
||||
assertFalse(client.isInputShutdown());
|
||||
System.err.println("ISHUT "+client);
|
||||
client.shutdownInput();
|
||||
|
||||
// Client ???
|
||||
System.err.println("OSHUT "+client);
|
||||
client.shutdownOutput();
|
||||
System.err.println("CLOSE "+client);
|
||||
client.close();
|
||||
|
||||
// Server reads -1, does ishut and then close
|
||||
assertEquals(-1,server.getInputStream().read());
|
||||
assertFalse(server.isInputShutdown());
|
||||
System.err.println("ISHUT "+server);
|
||||
|
||||
try
|
||||
{
|
||||
server.shutdownInput();
|
||||
}
|
||||
catch(SocketException e)
|
||||
{
|
||||
System.err.println(e);
|
||||
}
|
||||
System.err.println("CLOSE "+server);
|
||||
server.close();
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// Dang OSX!
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -36,11 +36,9 @@ public class ChannelEndPointTest extends EndPointTest<ChannelEndPoint>
|
|||
return c;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stress() throws Exception
|
||||
@Override
|
||||
public void testClientServerExchange() throws Exception
|
||||
{
|
||||
|
||||
testClientServerExchange();
|
||||
super.testClientServerExchange();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -154,12 +154,12 @@ public class SelectChannelEndPointTest
|
|||
|
||||
public void onClose()
|
||||
{
|
||||
System.err.println("onClose");
|
||||
// System.err.println("onClose");
|
||||
}
|
||||
|
||||
public void onInputShutdown() throws IOException
|
||||
{
|
||||
System.err.println("onInputShutdown");
|
||||
// System.err.println("onInputShutdown");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -209,9 +209,15 @@ public class SelectChannelEndPointTest
|
|||
assertTrue(b>0);
|
||||
assertEquals(c,(char)b);
|
||||
}
|
||||
|
||||
client.close();
|
||||
|
||||
int i=0;
|
||||
while (server.isOpen())
|
||||
{
|
||||
assert(i++<10);
|
||||
Thread.sleep(10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -283,7 +289,7 @@ public class SelectChannelEndPointTest
|
|||
OutputStream clientOutputStream = client.getOutputStream();
|
||||
InputStream clientInputStream = client.getInputStream();
|
||||
|
||||
int specifiedTimeout = 200;
|
||||
int specifiedTimeout = 400;
|
||||
client.setSoTimeout(specifiedTimeout);
|
||||
|
||||
// Write 8 and cause block for 10
|
||||
|
@ -303,8 +309,8 @@ public class SelectChannelEndPointTest
|
|||
catch(SocketTimeoutException e)
|
||||
{
|
||||
int elapsed = Long.valueOf(System.currentTimeMillis() - start).intValue();
|
||||
System.err.println("blocked " + elapsed);
|
||||
Assert.assertThat("Expected timeout", elapsed, greaterThanOrEqualTo(specifiedTimeout));
|
||||
System.err.println("blocked for " + elapsed+ "ms");
|
||||
Assert.assertThat("Expected timeout", elapsed, greaterThanOrEqualTo(3*specifiedTimeout/4));
|
||||
}
|
||||
|
||||
// write remaining characters
|
||||
|
@ -324,13 +330,13 @@ public class SelectChannelEndPointTest
|
|||
public void testStress() throws Exception
|
||||
{
|
||||
Socket client = newClient();
|
||||
client.setSoTimeout(10000);
|
||||
client.setSoTimeout(30000);
|
||||
|
||||
SocketChannel server = _connector.accept();
|
||||
server.configureBlocking(false);
|
||||
|
||||
_manager.register(server);
|
||||
int writes = 1000000;
|
||||
int writes = 100000;
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(writes);
|
||||
final InputStream in = new BufferedInputStream(client.getInputStream());
|
||||
|
|
|
@ -464,9 +464,22 @@ public class ResourceTest
|
|||
// This test is intended to run only on Windows platform
|
||||
assumeTrue(OS.IS_WINDOWS);
|
||||
|
||||
String path = __userURL.toURI().getPath().replace('/','\\')+"ResourceTest.java";
|
||||
System.err.println(path);
|
||||
|
||||
Resource resource = Resource.newResource(path, false);
|
||||
System.err.println(resource);
|
||||
assertTrue(resource.exists());
|
||||
|
||||
/*
|
||||
|
||||
String uncPath = "\\\\127.0.0.1"+__userURL.toURI().getPath().replace('/','\\').replace(':','$')+"ResourceTest.java";
|
||||
System.err.println(uncPath);
|
||||
|
||||
Resource uncResource = Resource.newResource(uncPath, false);
|
||||
System.err.println(uncResource);
|
||||
assertTrue(uncResource.exists());
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue