From dc33bb84a4c5dc5d9a283596e2872a6c98a6bcaa Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 17 Oct 2014 11:04:23 +1100 Subject: [PATCH 1/2] 447472 test harness for slow large writes --- .../server/handler/ResourceHandlerTest.java | 60 +++++++++++++++++-- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java index 5dd6aa28765..615f5897577 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java @@ -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)); + + } + } } From 8bf6b2c62c814c5d8e160bc41a5a0089e4a4c9d9 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 17 Oct 2014 14:29:40 +1100 Subject: [PATCH 2/2] 444031 Ensure exceptions do not reduce threadpool below minimum improved the suppression of warnings --- .../eclipse/jetty/util/thread/QueuedThreadPool.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java index ff18e93eaea..375aa0d3ce3 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java @@ -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()