1 package org.jfox.pool; 2 3 import junit.framework.TestCase; 4 5 8 9 public class SimpleObjectPoolTest extends TestCase { 10 SimpleObjectPool pool; 11 12 public void setUp() throws Exception { 13 super.setUp(); 14 } 15 16 public void tearDown() throws Exception { 17 18 } 19 20 public void testSimpleObjectPool() throws Exception { 21 pool = new SimpleObjectPool(SimpleObjectFactory.class, TestPoolableObject.class); 22 23 pool.init(); 24 25 System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest()); 26 27 TestPoolableObject tpobj = (TestPoolableObject) pool.retrieveObject(); 28 29 System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest()); 30 31 System.out.println("word from pool: " + tpobj.say()); 32 33 pool.restoreObject(tpobj); 34 35 System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest()); 36 37 } 38 39 public void testTimeout() throws Exception { 40 pool = new SimpleObjectPool(SimpleObjectFactory.class, TestPoolableObject.class, 5, 10, 10 * 1000); 41 42 pool.init(); 43 44 TestPoolableObject tpobj = (TestPoolableObject) pool.retrieveObject(); 45 46 System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest()); 47 System.out.println("sleeptime: " + tpobj.getSleepTime()); 48 pool.restoreObject(tpobj); 49 50 System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest()); 51 52 } 53 54 } | Popular Tags |