1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import junit.framework.TestCase; 21 22 23 31 public class PoolDequeTest extends TestCase { 32 33 private static final int MAX_SIZE = 10; 34 35 public PoolDequeTest(String name) { 36 super(name); 37 } 39 40 public void testFill() throws Exception { 41 SinglePoolConnectionInterceptor.PoolDeque pool = new SinglePoolConnectionInterceptor.PoolDeque(MAX_SIZE); 42 for (int i = 0; i < MAX_SIZE; i++) { 43 pool.add(new ManagedConnectionInfo(null, null)); 44 } 45 } 46 47 48 public void testFillAndEmptyLast() throws Exception { 49 SinglePoolConnectionInterceptor.PoolDeque pool = new SinglePoolConnectionInterceptor.PoolDeque(MAX_SIZE); 50 ManagedConnectionInfo[] mcis = new ManagedConnectionInfo[MAX_SIZE]; 51 for (int i = 0; i < MAX_SIZE; i++) { 52 mcis[i] = new ManagedConnectionInfo(null, null); 53 pool.add(mcis[i]); 54 } 55 56 for (int i = MAX_SIZE - 1; i >= 0; i--) { 57 assertTrue("Expected to get corresponding MCI from pool", mcis[i] == pool.peek(i)); 58 assertTrue("Expected to get corresponding MCI from pool", mcis[i] == pool.removeLast()); 59 } 60 assertTrue("Expected pool to be empty!", pool.isEmpty()); 61 } 62 63 public void testRemove() throws Exception { 64 SinglePoolConnectionInterceptor.PoolDeque pool = new SinglePoolConnectionInterceptor.PoolDeque(MAX_SIZE); 65 ManagedConnectionInfo[] mcis = new ManagedConnectionInfo[MAX_SIZE]; 66 for (int i = 0; i < MAX_SIZE; i++) { 67 mcis[i] = new ManagedConnectionInfo(null, null); 68 pool.add(mcis[i]); 69 } 70 71 for (int i = 0; i < MAX_SIZE; i++) { 72 assertTrue("Expected to find MCI in pool", pool.remove(mcis[i])); 73 } 74 assertTrue("Expected pool to be empty!", pool.isEmpty()); 75 } 76 77 } | Popular Tags |