KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > outbound > PoolDequeTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.connector.outbound;
19
20 import junit.framework.TestCase;
21
22
23 /**
24  * PoolDequeTest.java
25  *
26  *
27  * Created: Fri Oct 10 12:00:47 2003
28  *
29  * @version 1.0
30  */

31 public class PoolDequeTest extends TestCase {
32
33     private static final int MAX_SIZE = 10;
34
35     public PoolDequeTest(String JavaDoc name) {
36         super(name);
37     } // PoolDequeTest constructor
38

39
40     public void testFill() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 } // PoolDequeTest
78
Popular Tags