View Javadoc

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.commons.pool.impl;
19  
20  import org.apache.commons.pool.KeyedObjectPoolFactory;
21  import org.apache.commons.pool.KeyedPoolableObjectFactory;
22  import org.apache.commons.pool.TestKeyedObjectPoolFactory;
23  
24  /**
25   * Tests for {@link StackKeyedObjectPoolFactory}.
26   *
27   * @author Sandy McArthur
28   * @version $Revision: 901944 $ $Date: 2010-01-21 17:27:04 -0700 (Thu, 21 Jan 2010) $
29   */
30  public class TestStackKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
31      public TestStackKeyedObjectPoolFactory(final String name) {
32          super(name);
33      }
34  
35      protected KeyedObjectPoolFactory makeFactory(final KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException {
36          return new StackKeyedObjectPoolFactory(objectFactory);
37      }
38  
39      public void testConstructors() throws Exception {
40          StackKeyedObjectPoolFactory factory = new StackKeyedObjectPoolFactory();
41          factory.createPool().close();
42  
43          factory = new StackKeyedObjectPoolFactory(1);
44          StackKeyedObjectPool pool = (StackKeyedObjectPool)factory.createPool();
45          assertEquals(1,pool._maxSleeping);
46          pool.close();
47  
48          factory = new StackKeyedObjectPoolFactory(1, 2);
49          pool = (StackKeyedObjectPool)factory.createPool();
50          assertEquals(1,pool._maxSleeping);
51          assertEquals(2,pool._initSleepingCapacity);
52          pool.close();
53  
54          factory = new StackKeyedObjectPoolFactory(createObjectFactory());
55          pool = (StackKeyedObjectPool)factory.createPool();
56          pool.close();
57  
58          factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1);
59          pool = (StackKeyedObjectPool)factory.createPool();
60          assertEquals(1,pool._maxSleeping);
61          pool.close();
62  
63          factory = new StackKeyedObjectPoolFactory(createObjectFactory(),  1, 2);
64          pool = (StackKeyedObjectPool)factory.createPool();
65          assertEquals(1,pool._maxSleeping);
66          assertEquals(2,pool._initSleepingCapacity);
67          pool.close();
68  
69      }
70  }