Merge remote-tracking branch 'origin/jetty-9.2.x'
This commit is contained in:
commit
ba7f7589cb
|
@ -26,6 +26,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
|
@ -36,6 +37,8 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.SimpleRequest;
|
||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.AfterClass;
|
||||
|
@ -62,9 +65,9 @@ public class ResourceHandlerTest
|
|||
public static void setUp() throws Exception
|
||||
{
|
||||
File dir = MavenTestingUtils.getTargetFile("test-classes/simple");
|
||||
File huge = new File(dir,"huge.txt");
|
||||
File bigger = new File(dir,"bigger.txt");
|
||||
File big = new File(dir,"big.txt");
|
||||
try (OutputStream out = new FileOutputStream(huge))
|
||||
try (OutputStream out = new FileOutputStream(bigger))
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
|
@ -74,7 +77,8 @@ public class ResourceHandlerTest
|
|||
}
|
||||
}
|
||||
}
|
||||
huge.deleteOnExit();
|
||||
|
||||
bigger.deleteOnExit();
|
||||
|
||||
// determine how the SCM of choice checked out the big.txt EOL
|
||||
// we can't just use whatever is the OS default.
|
||||
|
@ -178,11 +182,11 @@ public class ResourceHandlerTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testHuge() throws Exception
|
||||
public void testBigger() throws Exception
|
||||
{
|
||||
try (Socket socket = new Socket("localhost",_connector.getLocalPort());)
|
||||
{
|
||||
socket.getOutputStream().write("GET /resource/huge.txt HTTP/1.0\n\n".getBytes());
|
||||
socket.getOutputStream().write("GET /resource/bigger.txt HTTP/1.0\n\n".getBytes());
|
||||
Thread.sleep(1000);
|
||||
String response = IO.toString(socket.getInputStream());
|
||||
Assert.assertThat(response,Matchers.startsWith("HTTP/1.1 200 OK"));
|
||||
|
@ -190,4 +194,50 @@ public class ResourceHandlerTest
|
|||
Assert.assertThat(response,Matchers.endsWith(" 400\tThis is a big file" + LN));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Slow
|
||||
public void testSlowBiggest() throws Exception
|
||||
{
|
||||
_connector.setIdleTimeout(10000);
|
||||
|
||||
File dir = MavenTestingUtils.getTargetFile("test-classes/simple");
|
||||
File biggest = new File(dir,"biggest.txt");
|
||||
try (OutputStream out = new FileOutputStream(biggest))
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
try (InputStream in = new FileInputStream(new File(dir,"bigger.txt")))
|
||||
{
|
||||
IO.copy(in,out);
|
||||
}
|
||||
}
|
||||
out.write("\nTHE END\n".getBytes(StandardCharsets.ISO_8859_1));
|
||||
}
|
||||
biggest.deleteOnExit();
|
||||
|
||||
try (Socket socket = new Socket("localhost",_connector.getLocalPort());OutputStream out=socket.getOutputStream();InputStream in=socket.getInputStream())
|
||||
{
|
||||
|
||||
socket.getOutputStream().write("GET /resource/biggest.txt HTTP/1.0\n\n".getBytes());
|
||||
|
||||
byte[] array = new byte[102400];
|
||||
ByteBuffer buffer=null;
|
||||
int i=0;
|
||||
while(true)
|
||||
{
|
||||
Thread.sleep(100);
|
||||
int len=in.read(array);
|
||||
if (len<0)
|
||||
break;
|
||||
buffer=BufferUtil.toBuffer(array,0,len);
|
||||
// System.err.println(++i+": "+BufferUtil.toDetailString(buffer));
|
||||
}
|
||||
|
||||
Assert.assertEquals('E',buffer.get(buffer.limit()-4));
|
||||
Assert.assertEquals('N',buffer.get(buffer.limit()-3));
|
||||
Assert.assertEquals('D',buffer.get(buffer.limit()-2));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -522,6 +522,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
|
|||
public void run()
|
||||
{
|
||||
boolean shrink = false;
|
||||
boolean ignore = false;
|
||||
try
|
||||
{
|
||||
Runnable job = _jobs.poll();
|
||||
|
@ -538,7 +539,10 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
|
|||
{
|
||||
runJob(job);
|
||||
if (Thread.interrupted())
|
||||
{
|
||||
ignore=true;
|
||||
break loop;
|
||||
}
|
||||
job = _jobs.poll();
|
||||
}
|
||||
|
||||
|
@ -575,12 +579,15 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
|
|||
finally
|
||||
{
|
||||
if (_threadsIdle.decrementAndGet() == 0)
|
||||
{
|
||||
startThreads(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
ignore=true;
|
||||
LOG.ignore(e);
|
||||
}
|
||||
catch (Throwable e)
|
||||
|
@ -591,7 +598,8 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
|
|||
{
|
||||
if (!shrink && isRunning())
|
||||
{
|
||||
LOG.warn("Unexpected thread death: {} in {}",this,QueuedThreadPool.this);
|
||||
if (!ignore)
|
||||
LOG.warn("Unexpected thread death: {} in {}",this,QueuedThreadPool.this);
|
||||
// This is an unexpected thread death!
|
||||
if (_threadsStarted.decrementAndGet()<getMaxThreads())
|
||||
startThreads(1);
|
||||
|
|
Loading…
Reference in New Issue