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 TimeoutFactoryCancelStressTestCase extends JBossTestCase 38 { 39 WaitableInt count = new WaitableInt(0); 40 int iterationCount = getIterationCount(); 41 TimeoutFactory factory = TimeoutFactory.getSingleton(); 42 43 public void testStress() throws Exception 44 { 45 Thread [] threads = new Thread [getThreadCount()]; 46 for (int i = 0; i < threads.length; ++i) 47 threads[i] = new Thread (new MyRunnable(), "Test thread " + i); 48 for (int i = 0; i < threads.length; ++i) 49 threads[i].start(); 50 count.whenEqual(threads.length, null); 51 } 52 53 class MyRunnable implements Runnable 54 { 55 public void run() 56 { 57 try 58 { 59 for (int i = 0; i < iterationCount; ++i) 60 { 61 Timeout timeout = factory.createTimeout(System.currentTimeMillis() + 3000000, instance); 62 timeout.cancel(); 63 } 64 count.increment(); 65 } 66 catch (Throwable t) 67 { 68 log.error("Error", t); 69 fail("Error" + t.toString()); 70 } 71 } 72 } 73 74 MyTimeout instance = new MyTimeout(); 75 76 class MyTimeout implements TimeoutTarget 77 { 78 public void timedOut(Timeout timeout) 79 { 80 fail("Should not timeout"); 81 } 82 } 83 84 89 public TimeoutFactoryCancelStressTestCase(String name) 90 { 91 super(name); 92 } 93 } 94 | Popular Tags |