View Javadoc
1 /************************************************************ 2 * Copyright * 3 * Portions of this software are Copyright (c) 1993 - 2002, * 4 * Chad Z. Hower (Kudzu) and the Indy Pit Crew * 5 * - http://www.nevrona.com/Indy/ * 6 ************************************************************/ 7 package org.indy; 8 9 import junit.framework.TestCase; 10 11 12 /*** 13 * DOCUMENT ME! 14 * 15 * @version $Revision$ 16 * @author $author$ 17 */ 18 public class TestThreadManagerDefault extends TestCase { 19 DefaultPeerThreadManager manager = new DefaultPeerThreadManager(); 20 21 /*** 22 * Creates a new TestThreadManagerDefault object. 23 * 24 * @param name DOCUMENT ME! 25 */ 26 public TestThreadManagerDefault(String name) { 27 super(name); 28 } 29 30 /*** 31 * DOCUMENT ME! 32 */ 33 public void setUp() { 34 } 35 36 /*** 37 * DOCUMENT ME! 38 */ 39 public void tearDown() { 40 } 41 42 /*** 43 * DOCUMENT ME! 44 */ 45 public void testGetThread() { 46 PeerThread thread = manager.getThread(); 47 48 assertNotNull("Thread not null", thread); 49 50 thread = null; 51 } 52 53 /*** 54 * DOCUMENT ME! 55 */ 56 public void testReleaseThread() { 57 PeerThread thread = manager.getThread(); 58 59 thread.start(); 60 61 try { 62 manager.releaseThread(thread); 63 } 64 catch (InterruptedException ex) { 65 return; 66 } 67 68 assertTrue("Thread is stopped", thread.isStopped()); 69 70 //it should also be terminated, and an attempt to start 71 //should trigger an exception 72 try { 73 thread.start(); 74 } 75 catch (IllegalStateException ise) { 76 return; 77 } 78 79 fail("Exception not thrown after releaseThread()-start()"); 80 } 81 82 /*** 83 * DOCUMENT ME! 84 */ 85 public void testTerminateAllThreads() { 86 PeerThread[] p = new PeerThread[10]; 87 88 for (int i = 0; i < 10; i++) { 89 p[i] = manager.getThread(); 90 p[i].start(); 91 } 92 93 try { 94 manager.terminateThreads(); 95 } 96 catch (InterruptedException ex) { 97 return; 98 } 99 100 for (int i = 0; i < p.length; i++) { 101 assertTrue("Thread is stopped", p[i].isStopped()); 102 } 103 104 for (int i = 0; i < p.length; i++) { 105 //it should also be terminated, and an attempt to start 106 //should trigger an exception 107 try { 108 p[i].start(); 109 } 110 catch (IllegalStateException ise) { 111 return; 112 } 113 114 fail("Exception not thrown after releaseThread()-start() in thread " + i); 115 } 116 } 117 }

This page was automatically generated by Maven