From 3302d54babb8765ceeeef396ac245f614a45c1a9 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 21 Jul 2011 22:36:19 +1000 Subject: [PATCH] 352684 ensure test harness completes --- .../jetty/monitor/ThreadMonitorTest.java | 20 ++++++++++++------- .../src/main/java/com/acme/Dump.java | 7 +++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/ThreadMonitorTest.java b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/ThreadMonitorTest.java index 02606f7ac09..30f8e540643 100644 --- a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/ThreadMonitorTest.java +++ b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/ThreadMonitorTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertTrue; import java.lang.management.ThreadInfo; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -27,20 +28,19 @@ import org.junit.Test; */ public class ThreadMonitorTest { - public final static int DURATION=5000; - private int count; + public final static int DURATION=9000; + private AtomicInteger count=new AtomicInteger(0); @Test public void monitorTest() throws Exception { - count = 0; - ThreadMonitor monitor = new ThreadMonitor(1,95,2) + ThreadMonitor monitor = new ThreadMonitor(1,50,2) { @Override protected void dump(List threads) { - ++count; + count.incrementAndGet(); super.dump(threads); } }; @@ -55,13 +55,13 @@ public class ThreadMonitorTest spinner.setDone(); monitor.stop(); - assertTrue(count >= 2); + assertTrue(count.get() >= 2); } private class Spinner implements Runnable { - private boolean done = false; + private volatile boolean done = false; /* ------------------------------------------------------------ */ /** @@ -73,6 +73,12 @@ public class ThreadMonitorTest /* ------------------------------------------------------------ */ public void run() + { + spin(); + } + + /* ------------------------------------------------------------ */ + public void spin() { long result=-1; long end=System.currentTimeMillis()+DURATION+1000; diff --git a/test-jetty-webapp/src/main/java/com/acme/Dump.java b/test-jetty-webapp/src/main/java/com/acme/Dump.java index 78cd0ab8694..24189e27b1c 100644 --- a/test-jetty-webapp/src/main/java/com/acme/Dump.java +++ b/test-jetty-webapp/src/main/java/com/acme/Dump.java @@ -122,6 +122,13 @@ public class Dump extends HttpServlet request.setCharacterEncoding("UTF-8"); + if (request.getParameter("busy")!=null) + { + long end = System.currentTimeMillis()+Long.parseLong(request.getParameter("busy")); + while(System.currentTimeMillis()