KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > util > test > TimeoutFactoryCancelStressTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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 /**
32  * TimeoutFactoryCancelStressTestCase.
33  *
34  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
35  * @version $Revision: 43750 $
36  */

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 JavaDoc
44    {
45       Thread JavaDoc[] threads = new Thread JavaDoc[getThreadCount()];
46       for (int i = 0; i < threads.length; ++i)
47          threads[i] = new Thread JavaDoc(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 JavaDoc
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 JavaDoc 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    /**
85     * Create a new TimeoutFactoryStressTestCase.
86     *
87     * @param name the test name
88     */

89    public TimeoutFactoryCancelStressTestCase(String JavaDoc name)
90    {
91       super(name);
92    }
93 }
94
Popular Tags