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.ObjectPool;
21  import org.apache.commons.pool.PoolableObjectFactory;
22  import org.apache.commons.pool.TestBaseObjectPool;
23  
24  /**
25   * @author Rodney Waldhoff
26   * @author Sandy McArthur
27   * @version $Revision: 901944 $ $Date: 2010-01-21 17:27:04 -0700 (Thu, 21 Jan 2010) $
28   */
29  public class TestSoftReferenceObjectPool extends TestBaseObjectPool {
30      public TestSoftReferenceObjectPool(String testName) {
31          super(testName);
32      }
33  
34      protected ObjectPool makeEmptyPool(int cap) {
35          return new SoftReferenceObjectPool(
36              new PoolableObjectFactory()  {
37                  int counter = 0;
38                  public Object makeObject() { return String.valueOf(counter++); }
39                  public void destroyObject(Object obj) { }
40                  public boolean validateObject(Object obj) { return true; }
41                  public void activateObject(Object obj) { }
42                  public void passivateObject(Object obj) { }
43              }
44              );
45      }
46  
47      protected ObjectPool makeEmptyPool(final PoolableObjectFactory factory) {
48          return new SoftReferenceObjectPool(factory);
49      }
50  
51      protected Object getNthObject(int n) {
52          return String.valueOf(n);
53      }
54  
55      protected boolean isLifo() {
56          return false;
57      }
58  
59      protected boolean isFifo() {
60          return false;
61      }
62  
63  }