1 8 package org.apache.avalon.excalibur.pool.test; 9 10 import com.clarkware.junitperf.ConstantTimer; 11 import com.clarkware.junitperf.LoadTest; 12 import com.clarkware.junitperf.TimedTest; 13 import com.clarkware.junitperf.Timer; 14 15 import junit.extensions.TestSetup; 16 import junit.framework.Test; 17 import junit.framework.TestCase; 18 import junit.framework.TestSuite; 19 20 import org.apache.avalon.excalibur.logger.BufferedLogger; 21 import org.apache.avalon.excalibur.pool.Poolable; 22 import org.apache.avalon.excalibur.pool.ResourceLimitingPool; 23 24 29 public final class ResourceLimitingPoolMultithreadMaxTestCase 30 extends TestCase 31 { 32 private static BufferedLogger m_logger; 33 private static ClassInstanceObjectFactory m_factory; 34 private static ResourceLimitingPool m_pool; 35 36 39 public ResourceLimitingPoolMultithreadMaxTestCase() 40 { 41 this( "ResourceLimitingPool Multithreaded Max Size Test Case" ); 42 } 43 44 public ResourceLimitingPoolMultithreadMaxTestCase( final String name ) 45 { 46 super( name ); 47 } 48 49 52 public static Test suite() 53 { 54 TestSuite suite = new TestSuite(); 55 56 Timer timer = new ConstantTimer( 100 ); 57 int maxUsers = 50; 58 int iterations = 10; 59 long maxElapsedTime = 20000; 60 61 Test testCase = new ResourceLimitingPoolMultithreadMaxTestCase( "testGetPut" ); 62 Test loadTest = new LoadTest( testCase, maxUsers, iterations, timer ); 63 Test timedTest = new TimedTest( loadTest, maxElapsedTime ); 64 suite.addTest( timedTest ); 65 66 TestSetup wrapper= new TestSetup( suite ) 67 { 68 public void setUp() 69 { 70 oneTimeSetUp(); 71 } 72 public void tearDown() throws Exception 73 { 74 oneTimeTearDown(); 75 } 76 }; 77 78 return wrapper; 79 } 80 81 public static void oneTimeSetUp() 82 { 83 m_logger = new BufferedLogger(); 84 m_factory = new ClassInstanceObjectFactory( PoolableTestObject.class, m_logger ); 85 m_pool = new ResourceLimitingPool( m_factory, 3, false, false, 0, 0 ); 86 87 m_pool.enableLogging( m_logger ); 88 } 89 90 public static void oneTimeTearDown() throws Exception 91 { 92 assertEquals( "1) Pool Ready Size", 3, m_pool.getReadySize() ); 94 assertEquals( "1) Pool Size", 3, m_pool.getSize() ); 95 96 Poolable p1 = m_pool.get(); 98 Poolable p2 = m_pool.get(); 99 Poolable p3 = m_pool.get(); 100 101 assertEquals( "2) Pool Ready Size", 0, m_pool.getReadySize() ); 102 assertEquals( "2) Pool Size", 3, m_pool.getSize() ); 103 104 assertTrue( "p1 != p2", p1 != p2 ); 105 assertTrue( "p1 != p3", p1 != p3 ); 106 assertTrue( "p2 != p3", p2 != p3 ); 107 108 m_pool.put( p1 ); 109 m_pool.put( p2 ); 110 m_pool.put( p3 ); 111 112 assertEquals( "3) Pool Ready Size", 3, m_pool.getReadySize() ); 113 assertEquals( "3) Pool Size", 3, m_pool.getSize() ); 114 115 m_pool.dispose(); 116 117 assertEquals( "4) Pool Ready Size", 0, m_pool.getReadySize() ); 118 assertEquals( "4) Pool Size", 0, m_pool.getSize() ); 119 } 120 121 124 public void testGetPut() throws Exception 125 { 126 Poolable p = m_pool.get(); 127 128 try 129 { 130 Thread.sleep(33); 131 } catch ( InterruptedException e ) {} 132 m_pool.put( p ); 133 } 134 } 135 136 | Popular Tags |