1 17 package org.apache.geronimo.pool; 18 19 import junit.framework.TestCase; 20 21 24 public class ThreadPoolTest extends TestCase { 25 private final Object lock = new Object (); 26 private boolean ready; 27 private ThreadPool threadPool; 28 29 public void testPoolLimit() throws Exception { 30 ready = false; 32 threadPool.execute(new Runnable () { 33 public void run() { 34 synchronized(lock) { 35 ready = true; 36 lock.notifyAll(); 37 try { 38 lock.wait(); 39 } catch (InterruptedException e) { 40 } 41 } 42 } 43 }); 44 45 synchronized(lock) { 47 if (!ready) { 48 lock.wait(5000); 49 } 50 } 51 assertTrue(ready); 52 53 try { 55 threadPool.execute(new Runnable (){ 56 public void run() { 57 } 58 }); 59 fail("Should not have been able to schedule second task"); 60 } catch (RuntimeException e) { 61 } 63 } 64 65 public void setUp() throws Exception { 66 threadPool = new ThreadPool(1, "foo", Long.MAX_VALUE, ThreadPoolTest.class.getClassLoader(), "foo:bar=baz"); 67 threadPool.doStart(); 68 } 69 70 public void tearDown() throws Exception { 71 threadPool.doStop(); 72 synchronized(lock) { 73 lock.notifyAll(); 74 } 75 } 76 } 77 | Popular Tags |