001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.pool.impl;
019
020 import junit.framework.Test;
021 import junit.framework.TestSuite;
022
023 import org.apache.commons.pool.ObjectPool;
024 import org.apache.commons.pool.PoolableObjectFactory;
025 import org.apache.commons.pool.TestBaseObjectPool;
026
027 /**
028 * @author Rodney Waldhoff
029 * @author Sandy McArthur
030 * @version $Revision: 774099 $ $Date: 2009-05-12 17:29:02 -0400 (Tue, 12 May 2009) $
031 */
032 public class TestSoftReferenceObjectPool extends TestBaseObjectPool {
033 public TestSoftReferenceObjectPool(String testName) {
034 super(testName);
035 }
036
037 public static Test suite() {
038 return new TestSuite(TestSoftReferenceObjectPool.class);
039 }
040
041 protected ObjectPool makeEmptyPool(int cap) {
042 return new SoftReferenceObjectPool(
043 new PoolableObjectFactory() {
044 int counter = 0;
045 public Object makeObject() { return String.valueOf(counter++); }
046 public void destroyObject(Object obj) { }
047 public boolean validateObject(Object obj) { return true; }
048 public void activateObject(Object obj) { }
049 public void passivateObject(Object obj) { }
050 }
051 );
052 }
053
054 protected ObjectPool makeEmptyPool(final PoolableObjectFactory factory) {
055 return new SoftReferenceObjectPool(factory);
056 }
057
058 protected Object getNthObject(int n) {
059 return String.valueOf(n);
060 }
061
062 protected boolean isLifo() {
063 return false;
064 }
065
066 protected boolean isFifo() {
067 return false;
068 }
069
070 }