1 19 package org.apache.avalon.excalibur.pool.test; 20 21 import org.apache.avalon.excalibur.pool.ObjectFactory; 22 import org.apache.avalon.excalibur.pool.Pool; 23 import org.apache.avalon.excalibur.pool.Poolable; 24 import org.apache.avalon.excalibur.pool.ResourceLimitingPool; 25 import org.apache.avalon.excalibur.pool.SingleThreadedPool; 26 import org.apache.avalon.framework.activity.Disposable; 27 28 35 public class SingleThreadedPoolComparisonProfile 36 extends PoolComparisonProfileAbstract 37 { 38 41 public SingleThreadedPoolComparisonProfile( String name ) 42 { 43 super( name ); 44 } 45 46 49 56 public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables() 57 throws Exception 58 { 59 String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables"; 60 61 Class poolableClass = SmallPoolable.class; 62 ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger ); 63 int min = 0; 64 int max = 10; 65 boolean maxStrict = false; 66 boolean blocking = false; 67 long blockTimeout = 0; 68 long trimInterval = 0; 69 70 SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max ); 71 poolA.enableLogging( m_poolLogger ); 72 poolA.initialize(); 73 74 ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval ); 75 poolB.enableLogging( m_poolLogger ); 76 77 generalTest( name, poolA, poolB, 10, factory ); 78 } 79 80 87 public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables() 88 throws Exception 89 { 90 String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables"; 91 92 Class poolableClass = SmallPoolable.class; 93 ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger ); 94 int min = 0; 95 int max = 10; 96 boolean maxStrict = false; 97 boolean blocking = false; 98 long blockTimeout = 0; 99 long trimInterval = 0; 100 101 SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max ); 102 poolA.enableLogging( m_poolLogger ); 103 poolA.initialize(); 104 105 ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval ); 106 poolB.enableLogging( m_poolLogger ); 107 108 generalTest( name, poolA, poolB, 20, factory ); 109 } 110 111 118 public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables() 119 throws Exception 120 { 121 String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables"; 122 123 Class poolableClass = MediumPoolable.class; 124 ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger ); 125 int min = 0; 126 int max = 10; 127 boolean maxStrict = false; 128 boolean blocking = false; 129 long blockTimeout = 0; 130 long trimInterval = 0; 131 132 SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max ); 133 poolA.enableLogging( m_poolLogger ); 134 poolA.initialize(); 135 136 ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval ); 137 poolB.enableLogging( m_poolLogger ); 138 139 generalTest( name, poolA, poolB, 10, factory ); 140 } 141 142 149 public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables() 150 throws Exception 151 { 152 String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables"; 153 154 Class poolableClass = MediumPoolable.class; 155 ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger ); 156 int min = 0; 157 int max = 10; 158 boolean maxStrict = false; 159 boolean blocking = false; 160 long blockTimeout = 0; 161 long trimInterval = 0; 162 163 SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max ); 164 poolA.enableLogging( m_poolLogger ); 165 poolA.initialize(); 166 167 ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval ); 168 poolB.enableLogging( m_poolLogger ); 169 170 generalTest( name, poolA, poolB, 20, factory ); 171 } 172 173 180 public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables() 181 throws Exception 182 { 183 String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables"; 184 185 Class poolableClass = LargePoolable.class; 186 ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger ); 187 int min = 0; 188 int max = 10; 189 boolean maxStrict = false; 190 boolean blocking = false; 191 long blockTimeout = 0; 192 long trimInterval = 0; 193 194 SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max ); 195 poolA.enableLogging( m_poolLogger ); 196 poolA.initialize(); 197 198 ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval ); 199 poolB.enableLogging( m_poolLogger ); 200 201 generalTest( name, poolA, poolB, 10, factory ); 202 } 203 204 211 public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables() 212 throws Exception 213 { 214 String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables"; 215 216 Class poolableClass = LargePoolable.class; 217 ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger ); 218 int min = 0; 219 int max = 10; 220 boolean maxStrict = false; 221 boolean blocking = false; 222 long blockTimeout = 0; 223 long trimInterval = 0; 224 225 SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max ); 226 poolA.enableLogging( m_poolLogger ); 227 poolA.initialize(); 228 229 ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval ); 230 poolB.enableLogging( m_poolLogger ); 231 232 generalTest( name, poolA, poolB, 20, factory ); 233 } 234 235 238 protected long getPoolRunTime( Pool pool, int gets ) 239 throws Exception 240 { 241 resetMemory(); 243 244 final long startTime = System.currentTimeMillis(); 245 final Poolable[] poolTmp = new Poolable[ gets ]; 246 final int loops = TEST_SIZE / gets; 247 for( int i = 0; i < loops; i++ ) 248 { 249 for( int j = 0; j < gets; j++ ) 251 { 252 poolTmp[ j ] = pool.get(); 253 } 254 255 for( int j = 0; j < gets; j++ ) 257 { 258 pool.put( poolTmp[ j ] ); 259 poolTmp[ j ] = null; 260 } 261 } 262 final long duration = System.currentTimeMillis() - startTime; 263 264 if( pool instanceof Disposable ) 266 { 267 ( (Disposable)pool ).dispose(); 268 } 269 270 return duration; 271 } 272 } 273 | Popular Tags |