01: package org.jgroups.blocks;
02:
03: import junit.framework.TestCase;
04:
05: import org.jgroups.tests.MessageDispatcherTest;
06:
07: import java.util.Arrays;
08: import java.util.HashSet;
09: import java.util.Set;
10:
11: /*
12: * Created on May 16, 2005
13: */
14:
15: /**
16: * @author BConlon
17: * @version $Revision: 1.1 $
18: */
19: public class MessageDispatcherThreadingTest extends TestCase {
20:
21: //~ Methods ----------------------------------------------------------------------------------------------
22:
23: public void testAllThreadsAreStopped() throws Exception {
24: // get the threads for this thread group
25: ThreadGroup threadGroup = Thread.currentThread()
26: .getThreadGroup();
27: Thread[] originalThreads = new Thread[threadGroup.activeCount()];
28:
29: // populate the array with the threads in this group.
30: threadGroup.enumerate(originalThreads);
31: Set originalThreadSet = new HashSet(Arrays
32: .asList(originalThreads));
33:
34: new MessageDispatcherTest().start();
35:
36: // wait for anything necessary to finish up.
37: Thread.sleep(10000);
38:
39: Thread[] currentThreads = new Thread[threadGroup.activeCount()];
40:
41: // populate the array with the threads in this group.
42: boolean residualThreadsFound = false;
43: threadGroup.enumerate(currentThreads);
44:
45: // Look for threads not alive when we started.
46: for (int i = 0; i < currentThreads.length; i++) {
47: Thread thread = currentThreads[i];
48: if (!originalThreadSet.contains(thread) && thread.isAlive()) {
49: residualThreadsFound = true;
50: System.out
51: .println("The following thread was left over: "
52: + thread);
53: }
54: }
55: assertFalse("Residual threads were found", residualThreadsFound);
56: }
57: }
|