1   /*
2    * Created on May 19, 2004
3    *
4    */
5   package org.neo.swarm.util.threads;
6   
7   import org.neo.swarm.util.threads.OswegoThreadPool;
8   import org.neo.swarm.util.threads.ThreadPool;
9   
10  import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
11  import junit.framework.TestCase;
12  
13  /***
14   * A functional test.
15   * @author navery
16   */
17  public class ThreadPoolTest extends TestCase {
18  	
19  	public void testBlockingThreadPool() throws Exception {
20  		ThreadPool tp = new OswegoThreadPool(new PooledExecutor(), 5, 10);
21  
22  		int numThreads = 5000;
23  		for (int i = 0; i < 5 * 1000; i++) {
24  			TestThreadRunner tr = new TestThreadRunner(i);
25  			tp.execute(tr);
26  			if (i % 100 == 0) {
27  //				System.out.println("size:" + tp.getPoolSize());
28  			}
29  		}
30  		tp.shutdown(1000);
31  		System.out.println("size:" + tp.getPoolSize());
32  		assertEquals(TestThreadRunner.count, numThreads);
33  	}
34  	
35  	public void testAccessors() throws Exception {
36  		ThreadPool tp = new OswegoThreadPool(new PooledExecutor(), 0, 10);
37  		tp.getMaximumPoolSize();
38  		tp.getMinimumPoolSize();
39  		tp.setMaximumPoolSize(50);
40  		tp.setMinimumPoolSize(5);
41  		tp.getPoolSize();
42  	}
43  }