You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2003/06/16 08:25:37 UTC
cvs commit: avalon-excalibur/pool/src/java/org/apache/avalon/excalibur/pool ResourceLimitingPool.java
leif 2003/06/15 23:25:37
Modified: pool/src/test/org/apache/avalon/excalibur/pool/test
ResourceLimitingPoolTestCase.java
pool/src/java/org/apache/avalon/excalibur/pool
ResourceLimitingPool.java
Added: pool/src/test/org/apache/avalon/excalibur/pool/test
FailingPoolableTestObject.java
Log:
Fix a problem where poolable objects which throw an error while they are being
instantiated was causing a leak in the pool. The pool counted the object as
having been instantiated. This was leading to the pool blocking even though it
was actually empty. Also added a new test case for this.
Revision Changes Path
1.6 +74 -1 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolTestCase.java
Index: ResourceLimitingPoolTestCase.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/ResourceLimitingPoolTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ResourceLimitingPoolTestCase.java 22 Mar 2003 12:46:54 -0000 1.5
+++ ResourceLimitingPoolTestCase.java 16 Jun 2003 06:25:36 -0000 1.6
@@ -228,5 +228,78 @@
logger.toString()
);
}
+
+ public void testFailingGets() throws Exception
+ {
+ BufferedLogger logger = new BufferedLogger();
+ ClassInstanceObjectFactory factory =
+ new ClassInstanceObjectFactory( FailingPoolableTestObject.class, logger );
+ ResourceLimitingPool pool = new ResourceLimitingPool( factory, 3, true, true, 5000, 0 );
+
+ pool.enableLogging( logger );
+ Poolable p1;
+
+ assertEquals( "1) Pool Ready Size", 0, pool.getReadySize() );
+ assertEquals( "1) Pool Size", 0, pool.getSize() );
+
+ try
+ {
+ p1 = pool.get();
+ fail( "1) call to get should have failed." );
+ }
+ catch ( IllegalStateException e )
+ {
+ // Expected
+ }
+
+ assertEquals( "2) Pool Ready Size", 0, pool.getReadySize() );
+ assertEquals( "2) Pool Size", 0, pool.getSize() );
+
+ try
+ {
+ p1 = pool.get();
+ fail( "2) call to get should have failed." );
+ }
+ catch ( IllegalStateException e )
+ {
+ // Expected
+ }
+
+ assertEquals( "3) Pool Ready Size", 0, pool.getReadySize() );
+ assertEquals( "3) Pool Size", 0, pool.getSize() );
+
+ try
+ {
+ p1 = pool.get();
+ fail( "3) call to get should have failed." );
+ }
+ catch ( IllegalStateException e )
+ {
+ // Expected
+ }
+
+ assertEquals( "4) Pool Ready Size", 0, pool.getReadySize() );
+ assertEquals( "4) Pool Size", 0, pool.getSize() );
+
+ try
+ {
+ p1 = pool.get();
+ fail( "4) call to get should have failed." );
+ }
+ catch ( IllegalStateException e )
+ {
+ // Expected
+ }
+
+ logger.debug( "OK" );
+
+ pool.dispose();
+
+ // Make sure the logger output check out.
+ assertEquals( "Logger output",
+ "DEBUG - OK\n",
+ logger.toString()
+ );
+ }
}
1.1 avalon-excalibur/pool/src/test/org/apache/avalon/excalibur/pool/test/FailingPoolableTestObject.java
Index: FailingPoolableTestObject.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.excalibur.pool.test;
import org.apache.avalon.excalibur.pool.Poolable;
/**
* @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
* @version CVS $Revision: 1.1 $ $Date: 2003/06/16 06:25:36 $
* @since 4.1
*/
public class FailingPoolableTestObject implements Poolable
{
public FailingPoolableTestObject()
{
throw new IllegalStateException( "For testing, this class can not be instantiated." );
}
}
1.8 +6 -4 avalon-excalibur/pool/src/java/org/apache/avalon/excalibur/pool/ResourceLimitingPool.java
Index: ResourceLimitingPool.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/pool/src/java/org/apache/avalon/excalibur/pool/ResourceLimitingPool.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ResourceLimitingPool.java 25 Feb 2003 16:28:49 -0000 1.7
+++ ResourceLimitingPool.java 16 Jun 2003 06:25:37 -0000 1.8
@@ -397,9 +397,10 @@
}
else
{
- // Create a new poolable
- m_size++;
+ // Create a new poolable. May throw an exception if the poolable can not be
+ // instantiated.
poolable = newPoolable();
+ m_size++;
if( getLogger().isDebugEnabled() )
{
@@ -675,7 +676,8 @@
m_createsInstrument.increment();
if( m_sizeInstrument.isActive() )
{
- m_sizeInstrument.setValue( getSize() );
+ // The size is incremented after this call in case an error is thrown.
+ m_sizeInstrument.setValue( getSize() + 1 );
}
return (Poolable)obj;
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org