commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandy...@apache.org
Subject svn commit: r383688 - in /jakarta/commons/proper/pool/trunk/src: java/org/apache/commons/pool/ test/org/apache/commons/pool/
Date Mon, 06 Mar 2006 22:06:18 GMT
Author: sandymac
Date: Mon Mar  6 14:06:16 2006
New Revision: 383688

URL: http://svn.apache.org/viewcvs?rev=383688&view=rev
Log:
Updated BaseObjectPools and unit tests to conform to the Pool 2.0 contract changes.
* getNumIdle/getNumActive now return a negative value when unsupported.
* calling close() more than once no longer throws an exception.

Modified:
    jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseKeyedObjectPool.java
    jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java
    jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java

Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseKeyedObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseKeyedObjectPool.java?rev=383688&r1=383687&r2=383688&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseKeyedObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseKeyedObjectPool.java
Mon Mar  6 14:06:16 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,11 +17,12 @@
 package org.apache.commons.pool;
 
 /**
- * A simple base impementation of {@link ObjectPool}.
- * All optional operations are implemented as throwing
- * {@link UnsupportedOperationException}.
+ * A simple base implementation of {@link ObjectPool}.
+ * Optional operations are implemented to either do nothing, return a value
+ * indicating it is unsupported or throw {@link UnsupportedOperationException}.
  *
  * @author Rodney Waldhoff
+ * @author Sandy McArthur
  * @version $Revision$ $Date$
  */
 public abstract class BaseKeyedObjectPool implements KeyedObjectPool {
@@ -31,6 +32,8 @@
 
     /**
      * Not supported in this base implementation.
+     * Always throws an {@link UnsupportedOperationException},
+     * subclasses should override this behavior.
      */
     public void addObject(Object key) throws Exception, UnsupportedOperationException {
         throw new UnsupportedOperationException();
@@ -38,30 +41,34 @@
 
     /**
      * Not supported in this base implementation.
+     * @return a negative value.
      */
     public int getNumIdle(Object key) throws UnsupportedOperationException {
-        throw new UnsupportedOperationException();
+        return -1;
     }
 
     /**
      * Not supported in this base implementation.
+     * @return a negative value.
      */
     public int getNumActive(Object key) throws UnsupportedOperationException {
-        throw new UnsupportedOperationException();
+        return -1;
     }
 
     /**
      * Not supported in this base implementation.
+     * @return a negative value.
      */
     public int getNumIdle() throws UnsupportedOperationException {
-        throw new UnsupportedOperationException();
+        return -1;
     }
 
     /**
      * Not supported in this base implementation.
+     * @return a negative value.
      */
     public int getNumActive() throws UnsupportedOperationException {
-        throw new UnsupportedOperationException();
+        return -1;
     }
 
     /**
@@ -74,8 +81,7 @@
     /**
      * Not supported in this base implementation.
      */
-    public void clear(Object key)
-    throws Exception, UnsupportedOperationException {
+    public void clear(Object key) throws Exception, UnsupportedOperationException {
         throw new UnsupportedOperationException();
     }
 
@@ -88,9 +94,10 @@
 
     /**
      * Not supported in this base implementation.
+     * Always throws an {@link UnsupportedOperationException},
+     * subclasses should override this behavior.
      */
-    public void setFactory(KeyedPoolableObjectFactory factory)
-    throws IllegalStateException, UnsupportedOperationException {
+    public void setFactory(KeyedPoolableObjectFactory factory) throws IllegalStateException,
UnsupportedOperationException {
         throw new UnsupportedOperationException();
     }
 

Modified: jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseObjectPool.java?rev=383688&r1=383687&r2=383688&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/java/org/apache/commons/pool/BaseObjectPool.java
Mon Mar  6 14:06:16 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,11 +17,12 @@
 package org.apache.commons.pool;
 
 /**
- * A simple base impementation of {@link ObjectPool}.
- * All optional operations are implemented as throwing
- * {@link UnsupportedOperationException}.
+ * A simple base implementation of {@link ObjectPool}.
+ * Optional operations are implemented to either do nothing, return a value
+ * indicating it is unsupported or throw {@link UnsupportedOperationException}.
  *
  * @author Rodney Waldhoff
+ * @author Sandy McArthur
  * @version $Revision$ $Date$
  */
 public abstract class BaseObjectPool implements ObjectPool {
@@ -31,16 +32,18 @@
 
     /**
      * Not supported in this base implementation.
+     * @return a negative value.
      */
     public int getNumIdle() throws UnsupportedOperationException {
-        throw new UnsupportedOperationException();
+        return -1;
     }
 
     /**
      * Not supported in this base implementation.
+     * @return a negative value.
      */
     public int getNumActive() throws UnsupportedOperationException {
-        throw new UnsupportedOperationException();
+        return -1;
     }
 
     /**
@@ -52,27 +55,39 @@
 
     /**
      * Not supported in this base implementation.
+     * Always throws an {@link UnsupportedOperationException},
+     * subclasses should override this behavior.
      */
     public void addObject() throws Exception, UnsupportedOperationException {
         throw new UnsupportedOperationException();
     }
 
     public void close() throws Exception {
-        assertOpen();
         closed = true;
     }
 
     /**
      * Not supported in this base implementation.
+     * Always throws an {@link UnsupportedOperationException},
+     * subclasses should override this behavior.
      */
     public void setFactory(PoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException
{
         throw new UnsupportedOperationException();
     }
-    
+
+    /**
+     * Has this pool instance been closed.
+     * @return <code>true</code> when this pool has been closed.
+     */
     protected final boolean isClosed() {
         return closed;
     }
-    
+
+    /**
+     * Throws an <code>IllegalStateException</code> when this pool has been closed.
+     * @throws IllegalStateException when this pool has been closed.
+     * @see #isClosed()
+     */
     protected final void assertOpen() throws IllegalStateException {
         if(isClosed()) {
             throw new IllegalStateException("Pool not open");

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java?rev=383688&r1=383687&r2=383688&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java
Mon Mar  6 14:06:16 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 
 /**
  * @author Rodney Waldhoff
+ * @author Sandy McArthur
  * @version $Revision$ $Date$
  */
 public class TestBaseKeyedObjectPool extends TestCase {
@@ -51,36 +52,13 @@
             // expected
         }
 
-        try {
-            pool.getNumIdle();
-            fail("Expected UnsupportedOperationException");
-        } catch(UnsupportedOperationException e) {
-            // expected
-        }
-
-        try {
-            pool.getNumActive();
-            fail("Expected UnsupportedOperationException");
-        } catch(UnsupportedOperationException e) {
-            // expected
-        }
+        assertTrue("Negative expected.", pool.getNumIdle() < 0);
+        assertTrue("Negative expected.", pool.getNumIdle("key") < 0);
+        assertTrue("Negative expected.", pool.getNumActive() < 0);
+        assertTrue("Negative expected.", pool.getNumActive("key") < 0);
 
         try {
             pool.clear();
-            fail("Expected UnsupportedOperationException");
-        } catch(UnsupportedOperationException e) {
-            // expected
-        }
-
-        try {
-            pool.getNumIdle("key");
-            fail("Expected UnsupportedOperationException");
-        } catch(UnsupportedOperationException e) {
-            // expected
-        }
-
-        try {
-            pool.getNumActive("key");
             fail("Expected UnsupportedOperationException");
         } catch(UnsupportedOperationException e) {
             // expected

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java?rev=383688&r1=383687&r2=383688&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java
Mon Mar  6 14:06:16 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 
 /**
  * @author Rodney Waldhoff
+ * @author Sandy McArthur
  * @version $Revision$ $Date$ 
  */
 public class TestBaseObjectPool extends TestCase {
@@ -43,20 +44,9 @@
             public void invalidateObject(Object obj) throws Exception {                
             }            
         };   
-        
-        try {
-            pool.getNumIdle();
-            fail("Expected UnsupportedOperationException");
-        } catch(UnsupportedOperationException e) {
-            // expected
-        }
 
-        try {
-            pool.getNumActive();
-            fail("Expected UnsupportedOperationException");
-        } catch(UnsupportedOperationException e) {
-            // expected
-        }
+        assertTrue("Negative expected.", pool.getNumIdle() < 0);
+        assertTrue("Negative expected.", pool.getNumActive() < 0);
 
         try {
             pool.clear();
@@ -78,5 +68,20 @@
         } catch(UnsupportedOperationException e) {
             // expected
         }
+    }
+
+    public void testClose() throws Exception {
+        ObjectPool pool = new BaseObjectPool() {
+            public Object borrowObject() throws Exception {
+                return null;
+            }
+            public void returnObject(Object obj) throws Exception {
+            }
+            public void invalidateObject(Object obj) throws Exception {
+            }
+        };
+
+        pool.close();
+        pool.close(); // should not error as of Pool 2.0.
     }
 }

Modified: jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java?rev=383688&r1=383687&r2=383688&view=diff
==============================================================================
--- jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
(original)
+++ jakarta/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
Mon Mar  6 14:06:16 2006
@@ -216,23 +216,5 @@
         }
     }
 
-    public void testBaseCantCloseTwice() throws Exception {
-        try {
-            _pool = makeEmptyPool(3);
-        } catch(IllegalArgumentException e) {
-            return; // skip this test if unsupported
-        }
-        Object obj = _pool.borrowObject();
-        _pool.returnObject(obj);
-        
-        _pool.close();
-        try {
-            _pool.close();
-            fail("Expected IllegalStateException");
-        } catch(IllegalStateException e) {
-            // expected
-        }
-    }
-
     private ObjectPool _pool = null;
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message