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 ResourceLimitingPoolMultithreadMaxStrictBlockTestCase extends TestCase 30 { 31 private static BufferedLogger m_logger; 32 private static ClassInstanceObjectFactory m_factory; 33 private static ResourceLimitingPool m_pool; 34 35 38 public ResourceLimitingPoolMultithreadMaxStrictBlockTestCase() 39 { 40 this( "ResourceLimitingPool Multithreaded Max Size Strict Blocking Test Case" ); 41 } 42 43 public ResourceLimitingPoolMultithreadMaxStrictBlockTestCase( final String name ) 44 { 45 super( name ); 46 } 47 48 51 public static Test suite() 52 { 53 TestSuite suite = new TestSuite(); 54 55 Timer timer = new ConstantTimer( 100 ); 56 int maxUsers = 10; 57 int iterations = 10; 58 long maxElapsedTime = 20000; 59 60 Test testCase = new ResourceLimitingPoolMultithreadMaxStrictBlockTestCase( "testGetPut" ); 61 Test loadTest = new LoadTest( testCase, maxUsers, iterations, timer ); 62 Test timedTest = new TimedTest( loadTest, maxElapsedTime ); 63 suite.addTest( timedTest ); 64 65 TestSetup wrapper= new TestSetup(suite) 66 { 67 public void setUp() 68 { 69 oneTimeSetUp(); 70 } 71 public void tearDown() throws Exception 72 { 73 oneTimeTearDown(); 74 } 75 }; 76 77 return wrapper; 78 } 79 80 public static void oneTimeSetUp() 81 { 82 m_logger = new BufferedLogger(); 83 m_factory = new ClassInstanceObjectFactory( PoolableTestObject.class, m_logger ); 84 m_pool = new ResourceLimitingPool( m_factory, 3, true, true, 0, 0 ); 85 86 m_pool.enableLogging( m_logger ); 87 } 88 89 public static void oneTimeTearDown() throws Exception 90 { 91 assertEquals( "1) Pool Ready Size", 3, m_pool.getReadySize() ); 93 assertEquals( "1) Pool Size", 3, m_pool.getSize() ); 94 95 Poolable p1 = m_pool.get(); 97 Poolable p2 = m_pool.get(); 98 Poolable p3 = m_pool.get(); 99 100 assertEquals( "2) Pool Ready Size", 0, m_pool.getReadySize() ); 101 assertEquals( "2) Pool Size", 3, m_pool.getSize() ); 102 103 assertTrue( "p1 != p2", p1 != p2 ); 104 assertTrue( "p1 != p3", p1 != p3 ); 105 assertTrue( "p2 != p3", p2 != p3 ); 106 107 m_pool.put( p1 ); 108 m_pool.put( p2 ); 109 m_pool.put( p3 ); 110 111 assertEquals( "3) Pool Ready Size", 3, m_pool.getReadySize() ); 112 assertEquals( "3) Pool Size", 3, m_pool.getSize() ); 113 114 m_pool.dispose(); 115 116 assertEquals( "4) Pool Ready Size", 0, m_pool.getReadySize() ); 117 assertEquals( "4) Pool Size", 0, m_pool.getSize() ); 118 } 119 120 123 public void testGetPut() throws Exception 124 { 125 Poolable p = m_pool.get(); 126 127 assertTrue( "Pool size <= 3", m_pool.getSize() <= 3 ); 129 130 try 131 { 132 Thread.sleep( 33 ); 133 } 134 catch (InterruptedException e) {} 135 m_pool.put( p ); 136 } 137 } 138 139 | Popular Tags |