1 22 package org.jboss.test.util.test; 23 24 import org.jboss.test.JBossTestCase; 25 import org.jboss.util.timeout.Timeout; 26 import org.jboss.util.timeout.TimeoutFactory; 27 import org.jboss.util.timeout.TimeoutTarget; 28 29 import EDU.oswego.cs.dl.util.concurrent.WaitableInt; 30 31 37 public class TimeoutFactoryStressTestCase extends JBossTestCase 38 { 39 WaitableInt count = new WaitableInt(0); 40 TimeoutFactory factory = TimeoutFactory.getSingleton(); 41 42 public void testStress() throws Exception 43 { 44 Thread [] threads = new Thread [getThreadCount()]; 45 for (int i = 0; i < threads.length; ++i) 46 threads[i] = new Thread (new MyRunnable(), "Test thread " + i); 47 for (int i = 0; i < threads.length; ++i) 48 threads[i].start(); 49 count.whenEqual(threads.length, null); 50 } 51 52 class MyRunnable implements Runnable 53 { 54 public void run() 55 { 56 factory.createTimeout(System.currentTimeMillis() + 10, instance); 57 } 58 } 59 60 MyTimeout instance = new MyTimeout(); 61 62 class MyTimeout implements TimeoutTarget, Runnable 63 { 64 public void timedOut(Timeout timeout) 65 { 66 assertTrue(timeout != null); 67 run(); 68 } 69 70 public void run() 71 { 72 count.increment(); 73 } 74 } 75 76 81 public TimeoutFactoryStressTestCase(String name) 82 { 83 super(name); 84 } 85 } 86 | Popular Tags |