1 package org.jgroups.blocks; 2 3 import junit.framework.TestCase; 4 5 import org.jgroups.tests.MessageDispatcherTest; 6 7 import java.util.Arrays ; 8 import java.util.HashSet ; 9 import java.util.Set ; 10 11 14 15 19 public class MessageDispatcherThreadingTest 20 extends TestCase { 21 22 24 public void testAllThreadsAreStopped() throws Exception { 25 ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); 27 Thread [] originalThreads = new Thread [threadGroup.activeCount()]; 28 29 threadGroup.enumerate(originalThreads); 31 Set originalThreadSet = new HashSet (Arrays.asList(originalThreads)); 32 33 new MessageDispatcherTest().start(); 34 35 Thread.sleep(10000); 37 38 Thread [] currentThreads = new Thread [threadGroup.activeCount()]; 39 40 boolean residualThreadsFound = false; 42 threadGroup.enumerate(currentThreads); 43 44 for (int i = 0; i < currentThreads.length; i++) { 46 Thread thread = currentThreads[i]; 47 if (! originalThreadSet.contains(thread) && thread.isAlive()) { 48 residualThreadsFound = true; 49 System.out.println("The following thread was left over: " + thread); 50 } 51 } 52 assertFalse("Residual threads were found", residualThreadsFound); 53 } 54 } 55 56 | Popular Tags |