350397 SelectChannelConnector does not shutdown gracefully
This commit is contained in:
parent
94cfedf912
commit
a7eabf0757
|
@ -1,9 +1,10 @@
|
|||
jetty-7.4.4-SNAPSHOT
|
||||
+ JETTY-1380 Jetty Rewrite example does not work in Hightide
|
||||
+ 308851 Converted all jetty-client module tests to JUnit 4
|
||||
+ 345268 JDBCSessionManager does not work with maxInactiveInterval = -1
|
||||
+ 350397 SelectChannelConnector does not shutdown gracefully
|
||||
+ 351039 Forward dispatch should retain locale
|
||||
+ 351199 HttpServletResponse.encodeURL() wrongly encodes an url without path when cookies are disabled
|
||||
+ JETTY-1380 Jetty Rewrite example does not work in Hightide
|
||||
|
||||
jetty-7.4.3.v20110701 01 July 2011
|
||||
+ 295832 ProxyServlet more extensible and configurable
|
||||
|
|
|
@ -102,17 +102,6 @@ public class SelectChannelConnector extends AbstractNIOConnector
|
|||
{
|
||||
synchronized(this)
|
||||
{
|
||||
if(_manager.isRunning())
|
||||
{
|
||||
try
|
||||
{
|
||||
_manager.stop();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
if (_acceptChannel != null)
|
||||
_acceptChannel.close();
|
||||
_acceptChannel = null;
|
||||
|
@ -297,6 +286,20 @@ public class SelectChannelConnector extends AbstractNIOConnector
|
|||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
if(_manager.isRunning())
|
||||
{
|
||||
try
|
||||
{
|
||||
_manager.stop();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.doStop();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import org.eclipse.jetty.server.nio.BlockingChannelConnector;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* HttpServer Tester.
|
||||
*/
|
||||
public class BlockingChannelCloseTest extends HttpServerTestBase
|
||||
{
|
||||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
startServer(new BlockingChannelConnector());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,232 @@
|
|||
//========================================================================
|
||||
//Copyright (c) Webtide LLC
|
||||
//------------------------------------------------------------------------
|
||||
//All rights reserved. This program and the accompanying materials
|
||||
//are made available under the terms of the Eclipse Public License v1.0
|
||||
//and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
//The Eclipse Public License is available at
|
||||
//http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
//The Apache License v2.0 is available at
|
||||
//http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
//You may elect to redistribute this code under either of these licenses.
|
||||
//========================================================================
|
||||
|
||||
package org.eclipse.jetty.server;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* HttpServer Tester.
|
||||
*/
|
||||
public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
|
||||
{
|
||||
private static String __content =
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis felis nunc. "+
|
||||
"Quisque suscipit mauris et ante auctor ornare rhoncus lacus aliquet. Pellentesque "+
|
||||
"habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. "+
|
||||
"Vestibulum sit amet felis augue, vel convallis dolor. Cras accumsan vehicula diam "+
|
||||
"at faucibus. Etiam in urna turpis, sed congue mi. Morbi et lorem eros. Donec vulputate "+
|
||||
"velit in risus suscipit lobortis. Aliquam id urna orci, nec sollicitudin ipsum. "+
|
||||
"Cras a orci turpis. Donec suscipit vulputate cursus. Mauris nunc tellus, fermentum "+
|
||||
"eu auctor ut, mollis at diam. Quisque porttitor ultrices metus, vitae tincidunt massa "+
|
||||
"sollicitudin a. Vivamus porttitor libero eget purus hendrerit cursus. Integer aliquam "+
|
||||
"consequat mauris quis luctus. Cras enim nibh, dignissim eu faucibus ac, mollis nec neque. "+
|
||||
"Aliquam purus mauris, consectetur nec convallis lacinia, porta sed ante. Suspendisse "+
|
||||
"et cursus magna. Donec orci enim, molestie a lobortis eu, imperdiet vitae neque.";
|
||||
private static int __length = __content.length();
|
||||
|
||||
private StringBuffer _response;
|
||||
private boolean _continue;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Test
|
||||
public void testCloseBetweenRequests() throws Exception
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
_continue = true;
|
||||
_response = new StringBuffer();
|
||||
|
||||
configureServer(new HelloWorldHandler());
|
||||
|
||||
Socket client = newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os = client.getOutputStream();
|
||||
|
||||
ResponseReader reader = new ResponseReader(client);
|
||||
Thread runner = new Thread(reader);
|
||||
runner.start();
|
||||
|
||||
for (int pipeline = 1; pipeline < 32; pipeline++)
|
||||
{
|
||||
if (pipeline == 16)
|
||||
_connector.close();
|
||||
|
||||
total += pipeline;
|
||||
|
||||
String request = "";
|
||||
for (int i = 0; i < pipeline; i++)
|
||||
{
|
||||
request +=
|
||||
"GET /data?writes=1&block=16&id="+i+" HTTP/1.1\r\n"+
|
||||
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
|
||||
"user-agent: testharness/1.0 (blah foo/bar)\r\n"+
|
||||
"accept-encoding: nothing\r\n"+
|
||||
"cookie: aaa=1234567890\r\n"+
|
||||
"\r\n";
|
||||
}
|
||||
os.write(request.getBytes());
|
||||
os.flush();
|
||||
|
||||
Thread.sleep(50);
|
||||
}
|
||||
|
||||
_continue = false;
|
||||
runner.join();
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.close();
|
||||
|
||||
int count = 0;
|
||||
StringTokenizer lines = new StringTokenizer(_response.toString(),"\r\n");
|
||||
while(lines.hasMoreTokens())
|
||||
{
|
||||
String line = lines.nextToken();
|
||||
if (line.equals("HTTP/1.1 200 OK"))
|
||||
{
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(total, count);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Test
|
||||
public void testCloseBetweenChunks() throws Exception
|
||||
{
|
||||
_continue = true;
|
||||
_response = new StringBuffer();
|
||||
|
||||
configureServer(new EchoHandler());
|
||||
|
||||
Socket client = newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os = client.getOutputStream();
|
||||
|
||||
ResponseReader reader = new ResponseReader(client);
|
||||
Thread runner = new Thread(reader);
|
||||
runner.start();
|
||||
|
||||
String content = "abcdefghij";
|
||||
byte[] bytes = __content.getBytes("utf-8");
|
||||
|
||||
os.write((
|
||||
"POST /echo?charset=utf-8 HTTP/1.1\r\n"+
|
||||
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
|
||||
"content-type: text/plain; charset=utf-8\r\n"+
|
||||
"content-length: "+bytes.length+"\r\n"+
|
||||
"\r\n"
|
||||
).getBytes("iso-8859-1"));
|
||||
|
||||
int len = bytes.length;
|
||||
int offset = 0;
|
||||
int stop = len / 2;
|
||||
while (offset < stop)
|
||||
{
|
||||
os.write(bytes, offset, 64);
|
||||
offset += 64;
|
||||
}
|
||||
|
||||
_connector.close();
|
||||
|
||||
while (offset < len)
|
||||
{
|
||||
os.write(bytes, offset, len-offset <=64 ? len-offset : 64);
|
||||
offset += 64;
|
||||
}
|
||||
os.flush();
|
||||
|
||||
Thread.sleep(50);
|
||||
|
||||
_continue = false;
|
||||
runner.join();
|
||||
|
||||
String in = _response.toString();
|
||||
assertTrue(in.indexOf(__content.substring(__length-64))>0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public class ResponseReader implements Runnable
|
||||
{
|
||||
private BufferedReader _reader;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ResponseReader(Socket client) throws IOException
|
||||
{
|
||||
_reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
int count = 0;
|
||||
char[] buffer = new char[256];
|
||||
|
||||
try
|
||||
{
|
||||
while (_continue)
|
||||
{
|
||||
if (_reader.ready())
|
||||
{
|
||||
count = _reader.read(buffer);
|
||||
_response.append(buffer, 0, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
Thread.sleep(10);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (IOException ex) { }
|
||||
catch (InterruptedException ex) { }
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
_reader.close();
|
||||
}
|
||||
catch (IOException e) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.junit.Before;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public class SelectChannelConnectorCloseTest extends ConnectorCloseTestBase
|
||||
{
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
System.setProperty("org.eclipse.jetty.util.log.DEBUG","true");
|
||||
startServer(new SelectChannelConnector());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import org.eclipse.jetty.server.bio.SocketConnector;
|
||||
import org.junit.Before;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public class SocketConnectorCloseTest extends ConnectorCloseTestBase
|
||||
{
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
System.setProperty("org.eclipse.jetty.util.log.DEBUG","true");
|
||||
startServer(new SocketConnector());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue