From 470e63b77bc7749d7a58ae9e6f8cbbe80215e316 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 9 Nov 2011 16:07:36 +1100 Subject: [PATCH] added SCEP stress test --- .../eclipse/jetty/io/nio/SelectorManager.java | 2 +- .../io/nio/SelectChannelEndPointSslTest.java | 5 ++ .../io/nio/SelectChannelEndPointTest.java | 62 ++++++++++++++++++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java index 0a02d74d40c..6ce552281f8 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java @@ -55,7 +55,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa public static final Logger LOG=Log.getLogger("org.eclipse.jetty.io.nio"); private static final int __MONITOR_PERIOD=Integer.getInteger("org.eclipse.jetty.io.nio.MONITOR_PERIOD",1000).intValue(); - private static final int __MAX_SELECTS=Integer.getInteger("org.eclipse.jetty.io.nio.MAX_SELECTS",25000).intValue(); + private static final int __MAX_SELECTS=Integer.getInteger("org.eclipse.jetty.io.nio.MAX_SELECTS",100000).intValue(); private static final int __BUSY_PAUSE=Integer.getInteger("org.eclipse.jetty.io.nio.BUSY_PAUSE",50).intValue(); private static final int __IDLE_TICK=Integer.getInteger("org.eclipse.jetty.io.nio.IDLE_TICK",400).intValue(); diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/nio/SelectChannelEndPointSslTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/nio/SelectChannelEndPointSslTest.java index 05fb9221e23..bb08e4de2b7 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/nio/SelectChannelEndPointSslTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/nio/SelectChannelEndPointSslTest.java @@ -179,4 +179,9 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest Assert.assertEquals(-1,filled); } + @Test + public void testStress() throws Exception + { + super.testStress(); + } } diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/nio/SelectChannelEndPointTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/nio/SelectChannelEndPointTest.java index 04f735a3469..d1437aba839 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/nio/SelectChannelEndPointTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/nio/SelectChannelEndPointTest.java @@ -3,12 +3,16 @@ package org.eclipse.jetty.io.nio; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import java.io.BufferedInputStream; import java.io.IOException; +import java.io.InputStream; import java.net.Socket; import java.net.SocketTimeoutException; import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.AsyncEndPoint; @@ -111,8 +115,11 @@ public class SelectChannelEndPointTest progress=false; _in.compact(); if (_in.space()>0 && _endp.fill(_in)>0) + { progress=true; - + ((AsyncEndPoint)_endp).cancelIdle(); + } + if (_blockAt>0 && _in.length()>0 && _in.length()<_blockAt) { _endp.blockReadable(10000); @@ -146,10 +153,12 @@ public class SelectChannelEndPointTest public void onClose() { + System.err.println("onClose"); } public void onInputShutdown() throws IOException { + System.err.println("onInputShutdown"); } } @@ -304,5 +313,54 @@ public class SelectChannelEndPointTest assertEquals(c,(char)b); } } - + + @Test + public void testStress() throws Exception + { + Socket client = newClient(); + client.setSoTimeout(10000); + + SocketChannel server = _connector.accept(); + server.configureBlocking(false); + + _manager.register(server); + int writes = 1000000; + + final CountDownLatch latch = new CountDownLatch(writes); + final InputStream in = new BufferedInputStream(client.getInputStream()); + + new Thread() + { + public void run() + { + try + { + while (latch.getCount()>0) + { + // Verify echo server to client + for (char c : "HelloWorld".toCharArray()) + { + int b = in.read(); + assertTrue(b>0); + assertEquals(c,(char)b); + } + latch.countDown(); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } + }.start(); + + byte[] bytes="HelloWorld".getBytes("UTF-8"); + + // Write client to server + for (int i=0;i