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.WaitableLong; 30 31 37 public class TimeoutFactoryMixedStressTestCase extends JBossTestCase 38 { 39 WaitableLong count = new WaitableLong(0); 40 int iterationCount = getIterationCount(); 41 int threadCount = getThreadCount(); 42 long target = iterationCount * threadCount; 43 TimeoutFactory factory = TimeoutFactory.getSingleton(); 44 45 public void testStress() throws Exception 46 { 47 Thread [] threads = new Thread [threadCount]; 48 for (int i = 0; i < threads.length; ++i) 49 threads[i] = new Thread (new MyRunnable(), "Test thread " + i); 50 for (int i = 0; i < threads.length; ++i) 51 threads[i].start(); 52 count.whenEqual(target, null); 53 } 54 55 class MyRunnable implements Runnable 56 { 57 public void run() 58 { 59 for (int i = 0; i < iterationCount; ++i) 60 { 61 Timeout timeout = factory.createTimeout(System.currentTimeMillis() + 1, instance); 62 if (timeout.cancel()) 63 count.increment(); 64 } 65 } 66 } 67 68 MyTimeout instance = new MyTimeout(); 69 70 class MyTimeout implements TimeoutTarget 71 { 72 public void timedOut(Timeout timeout) 73 { 74 count.increment(); 75 } 76 } 77 78 83 public TimeoutFactoryMixedStressTestCase(String name) 84 { 85 super(name); 86 } 87 } 88 | Popular Tags |