1 8 package org.apache.avalon.excalibur.pool.test; 9 10 import junit.framework.TestCase; 11 12 import org.apache.avalon.excalibur.logger.BufferedLogger; 13 import org.apache.avalon.excalibur.pool.Poolable; 14 import org.apache.avalon.excalibur.pool.ResourceLimitingPool; 15 16 21 public final class ResourceLimitingPoolTestCase extends TestCase 22 { 23 26 public ResourceLimitingPoolTestCase() 27 { 28 this( "ResourceLimitingPool Test Case" ); 29 } 30 31 public ResourceLimitingPoolTestCase( final String name ) 32 { 33 super( name ); 34 } 35 36 39 public void testCreateDestroy() 40 { 41 BufferedLogger logger = new BufferedLogger(); 42 ClassInstanceObjectFactory factory = 43 new ClassInstanceObjectFactory( PoolableTestObject.class, logger ); 44 ResourceLimitingPool pool = new ResourceLimitingPool( factory, 0, false, false, 0, 0 ); 45 46 pool.enableLogging( logger ); 47 pool.dispose(); 48 49 assertEquals( 51 logger.toString(), 52 "" 53 ); 54 } 55 56 public void testSingleGetPut() throws Exception 57 { 58 BufferedLogger logger = new BufferedLogger(); 59 ClassInstanceObjectFactory factory = 60 new ClassInstanceObjectFactory( PoolableTestObject.class, logger ); 61 ResourceLimitingPool pool = new ResourceLimitingPool( factory, 0, false, false, 0, 0 ); 62 63 pool.enableLogging( logger ); 64 65 assertEquals( "1) Pool Ready Size", 0, pool.getReadySize() ); 66 assertEquals( "1) Pool Size", 0, pool.getSize() ); 67 68 Poolable p = pool.get(); 69 70 assertEquals( "2) Pool Ready Size", 0, pool.getReadySize() ); 71 assertEquals( "2) Pool Size", 1, pool.getSize() ); 72 73 pool.put(p); 74 75 assertEquals( "3) Pool Ready Size", 1, pool.getReadySize() ); 76 assertEquals( "3) Pool Size", 1, pool.getSize() ); 77 78 pool.dispose(); 79 80 assertEquals( "Logger output", 82 "DEBUG - ClassInstanceObjectFactory.newInstance() id:1\n" + 83 "DEBUG - Created a new org.apache.avalon.excalibur.pool.test.PoolableTestObject from the object factory.\n" + 84 "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" + 85 "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" + 86 "DEBUG - ClassInstanceObjectFactory.decommission(a org.apache.avalon.excalibur.pool.test.PoolableTestObject) id:1\n", 87 logger.toString() 88 ); 89 } 90 91 public void testSingleGetPutPoolCheck() throws Exception 92 { 93 BufferedLogger logger = new BufferedLogger(); 94 ClassInstanceObjectFactory factory = 95 new ClassInstanceObjectFactory( PoolableTestObject.class, logger ); 96 ResourceLimitingPool pool = new ResourceLimitingPool( factory, 0, false, false, 0, 0 ); 97 98 pool.enableLogging( logger ); 99 100 assertEquals( "1) Pool Ready Size", 0, pool.getReadySize() ); 101 assertEquals( "1) Pool Size", 0, pool.getSize() ); 102 103 Poolable p1 = pool.get(); 104 105 assertEquals( "2) Pool Ready Size", 0, pool.getReadySize() ); 106 assertEquals( "2) Pool Size", 1, pool.getSize() ); 107 108 pool.put( p1 ); 109 110 assertEquals( "3) Pool Ready Size", 1, pool.getReadySize() ); 111 assertEquals( "3) Pool Size", 1, pool.getSize() ); 112 113 Poolable p2 = pool.get(); 114 115 assertEquals( "4) Pool Ready Size", 0, pool.getReadySize() ); 116 assertEquals( "4) Pool Size", 1, pool.getSize() ); 117 118 assertEquals( "Pooled Object reuse check", p1, p2 ); 119 120 pool.put( p2 ); 121 122 assertEquals( "5) Pool Ready Size", 1, pool.getReadySize() ); 123 assertEquals( "5) Pool Size", 1, pool.getSize() ); 124 125 pool.dispose(); 126 127 assertEquals( "Logger output", 129 "DEBUG - ClassInstanceObjectFactory.newInstance() id:1\n" + 130 "DEBUG - Created a new org.apache.avalon.excalibur.pool.test.PoolableTestObject from the object factory.\n" + 131 "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" + 132 "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" + 133 "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" + 134 "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" + 135 "DEBUG - ClassInstanceObjectFactory.decommission(a org.apache.avalon.excalibur.pool.test.PoolableTestObject) id:1\n", 136 logger.toString() 137 ); 138 } 139 140 public void testMultipleGetPut() throws Exception 141 { 142 BufferedLogger logger = new BufferedLogger(); 143 ClassInstanceObjectFactory factory = 144 new ClassInstanceObjectFactory( PoolableTestObject.class, logger ); 145 ResourceLimitingPool pool = new ResourceLimitingPool( factory, 0, false, false, 0, 0 ); 146 147 pool.enableLogging( logger ); 148 149 assertEquals( "1) Pool Ready Size", 0, pool.getReadySize() ); 150 assertEquals( "1) Pool Size", 0, pool.getSize() ); 151 152 Poolable p1 = pool.get(); 153 154 assertEquals( "2) Pool Ready Size", 0, pool.getReadySize() ); 155 assertEquals( "2) Pool Size", 1, pool.getSize() ); 156 157 Poolable p2 = pool.get(); 158 159 assertEquals( "3) Pool Ready Size", 0, pool.getReadySize() ); 160 assertEquals( "3) Pool Size", 2, pool.getSize() ); 161 162 pool.put( p1 ); 163 164 assertEquals( "4) Pool Ready Size", 1, pool.getReadySize() ); 165 assertEquals( "4) Pool Size", 2, pool.getSize() ); 166 167 pool.put( p2 ); 168 169 assertEquals( "5) Pool Ready Size", 2, pool.getReadySize() ); 170 assertEquals( "5) Pool Size", 2, pool.getSize() ); 171 172 pool.dispose(); 173 174 assertEquals( "Logger output", 176 "DEBUG - ClassInstanceObjectFactory.newInstance() id:1\n" + 177 "DEBUG - Created a new org.apache.avalon.excalibur.pool.test.PoolableTestObject from the object factory.\n" + 178 "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" + 179 "DEBUG - ClassInstanceObjectFactory.newInstance() id:2\n" + 180 "DEBUG - Created a new org.apache.avalon.excalibur.pool.test.PoolableTestObject from the object factory.\n" + 181 "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" + 182 "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" + 183 "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" + 184 "DEBUG - ClassInstanceObjectFactory.decommission(a org.apache.avalon.excalibur.pool.test.PoolableTestObject) id:1\n" + 185 "DEBUG - ClassInstanceObjectFactory.decommission(a org.apache.avalon.excalibur.pool.test.PoolableTestObject) id:2\n", 186 logger.toString() 187 ); 188 } 189 } 190 191 | Popular Tags |