You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2013/12/05 14:36:19 UTC

svn commit: r1548133 - in /commons/proper/pool/trunk/src: changes/ test/java/org/apache/commons/pool2/ test/java/org/apache/commons/pool2/impl/

Author: markt
Date: Thu Dec  5 13:36:19 2013
New Revision: 1548133

URL: http://svn.apache.org/r1548133
Log:
Fix POOL-241
Patch from Bruno P. Kinoshita to expand coverage of unit tests.

Added:
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestEvictionConfig.java   (with props)
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java   (with props)
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestPooledSoftReference.java   (with props)
Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java

Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1548133&r1=1548132&r2=1548133&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Thu Dec  5 13:36:19 2013
@@ -43,10 +43,15 @@ The <action> type attribute can be add,u
     <title>Apache Commons Pool Changes</title>
   </properties>
   <body>
-  <release version="2.0.1" date="TBD" description=""This is a patch release, including bugfixes only.">
+  <release version="2.0.1" date="TBD" description=
+      "This is a patch release, including bugfixes and test case improvements.">
     <action issue="POOL-240" dev="psteitz" type="fix" due-to="Dan McNulty">
-      Ensured that blocked threads waiting on a depleted pool get served when objects are destroyed due to
-      validation or passivation failures in returnObject or when a checked out instance is invalidated.
+      Ensured that blocked threads waiting on a depleted pool get served when
+      objects are destroyed due to validation or passivation failures in
+      returnObject or when a checked out instance is invalidated.
+    </action>
+    <action issue="POOL-241" dev="markt" type="add" due-to="Bruno P. Kinoshita">
+      Expand the coverage of the unit tests.
     </action>
   </release>
   <release version="2.0" date="2013-11-11" description=

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java?rev=1548133&r1=1548132&r2=1548133&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java (original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java Thu Dec  5 13:36:19 2013
@@ -59,6 +59,31 @@ public class TestPoolUtils {
     private static final int CHECK_SLEEP_PERIOD = CHECK_PERIOD * (CHECK_COUNT - 1) + CHECK_PERIOD / 2;
 
     @Test
+    public void testCheckRethrow() {
+        try {
+            PoolUtils.checkRethrow(new Exception());
+        } catch (Throwable t) {
+            fail("PoolUtils.checkRethrow(Throwable) must rethrow only ThreadDeath and VirtualMachineError.");
+        }
+        try {
+            PoolUtils.checkRethrow(new ThreadDeath());
+            fail("PoolUtils.checkRethrow(Throwable) must rethrow ThreadDeath.");
+        } catch (ThreadDeath td) {
+            // expected
+        } catch (Throwable t) {
+            fail("PoolUtils.checkRethrow(Throwable) must rethrow only ThreadDeath and VirtualMachineError.");
+        }
+        try {
+            PoolUtils.checkRethrow(new InternalError()); // InternalError extends VirtualMachineError
+            fail("PoolUtils.checkRethrow(Throwable) must rethrow VirtualMachineError.");
+        } catch (VirtualMachineError td) {
+            // expected
+        } catch (Throwable t) {
+            fail("PoolUtils.checkRethrow(Throwable) must rethrow only ThreadDeath and VirtualMachineError.");
+        }
+    }
+
+    @Test
     public void testJavaBeanInstantiation() {
         Assert.assertNotNull(new PoolUtils());
     }
@@ -216,7 +241,7 @@ public class TestPoolUtils {
         try {
             @SuppressWarnings("unchecked")
             final KeyedObjectPool<Object,Object> pool = createProxy(KeyedObjectPool.class, (List<String>)null);
-            PoolUtils.checkMinIdle(pool, (Object)null, 1, 1);
+            PoolUtils.checkMinIdle(pool, (Collection<?>) null, 1, 1);
             fail("PoolUtils.checkMinIdle(KeyedObjectPool,Collection,int,long) must not accept null keys.");
         } catch (IllegalArgumentException iae) {
             // expected
@@ -683,6 +708,9 @@ public class TestPoolUtils {
         expectedMethods.add("getNumIdle");
         expectedMethods.add("invalidateObject");
         assertEquals(expectedMethods, calledMethods);
+        
+        String expectedToString = "ErodingPerKeyKeyedObjectPool{factor="+factor+", keyedPool=null}";
+        assertEquals(expectedToString, pool.toString());
     }
 
     private static List<String> invokeEveryMethod(ObjectPool<Object> op) throws Exception {

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java?rev=1548133&r1=1548132&r2=1548133&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java (original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java Thu Dec  5 13:36:19 2013
@@ -16,8 +16,10 @@
  */
 package org.apache.commons.pool2.impl;
 
+import java.text.SimpleDateFormat;
 import java.util.Set;
 
+import org.apache.commons.pool2.impl.DefaultPooledObject.AbandonedObjectCreatedException;
 import org.apache.commons.pool2.impl.TestGenericObjectPool.SimpleFactory;
 import org.junit.Assert;
 import org.junit.Test;
@@ -55,13 +57,21 @@ public class TestDefaultPooledObjectInfo
 
         DefaultPooledObjectInfo s1Info = strings.iterator().next();
 
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+
         Assert.assertTrue(s1Info.getCreateTime() > t1);
+        Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getCreateTime())),
+                s1Info.getCreateTimeFormatted());
         Assert.assertTrue(s1Info.getCreateTime() < t2);
 
         Assert.assertTrue(s1Info.getLastReturnTime() > t2);
+        Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getLastReturnTime())),
+                s1Info.getLastReturnTimeFormatted());
         Assert.assertTrue(s1Info.getLastReturnTime() < t3);
 
         Assert.assertTrue(s1Info.getLastBorrowTime() > t3);
+        Assert.assertEquals(sdf.format(Long.valueOf(s1Info.getLastBorrowTime())),
+                s1Info.getLastBorrowTimeFormatted());
         Assert.assertTrue(s1Info.getLastBorrowTime() < t4);
     }
 
@@ -97,4 +107,30 @@ public class TestDefaultPooledObjectInfo
 
         Assert.assertEquals(s1, s1Info.getPooledObjectToString());
     }
+
+    @Test
+    public void testGetLastBorrowTrace() throws Exception {
+        AbandonedConfig abandonedConfig = new AbandonedConfig();
+
+        abandonedConfig.setRemoveAbandonedOnBorrow(true);
+        abandonedConfig.setRemoveAbandonedTimeout(1);
+        abandonedConfig.setLogAbandoned(true);
+        GenericObjectPool<String> pool = new GenericObjectPool<String>(
+                new SimpleFactory(),
+                new GenericObjectPoolConfig(),
+                abandonedConfig);
+
+        try {
+            pool.borrowObject();
+            //pool.returnObject(s1); // Object not returned, causes abandoned object created exception
+        } catch (AbandonedObjectCreatedException e) {
+            // do nothing. We will print the stack trace later
+        }
+
+        Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
+        DefaultPooledObjectInfo s1Info = strings.iterator().next();
+        String lastBorrowTrace = s1Info.getLastBorrowTrace();
+
+        Assert.assertTrue(lastBorrowTrace.startsWith(AbandonedObjectCreatedException.class.getName()));
+    }
 }

Added: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestEvictionConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestEvictionConfig.java?rev=1548133&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestEvictionConfig.java (added)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestEvictionConfig.java Thu Dec  5 13:36:19 2013
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.pool2.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Tests for {@link EvictionConfig}.
+ */
+public class TestEvictionConfig {
+
+    @Test
+    public void testConstructor() {
+        EvictionConfig config = new EvictionConfig(0, 0, 0);
+
+        assertEquals(Long.MAX_VALUE, config.getIdleEvictTime());
+        assertEquals(Long.MAX_VALUE, config.getIdleSoftEvictTime());
+        assertEquals(0, config.getMinIdle());
+
+        config = new EvictionConfig(1, 1, 1);
+
+        assertEquals(1, config.getIdleEvictTime());
+        assertEquals(1, config.getIdleSoftEvictTime());
+        assertEquals(1, config.getMinIdle());
+    }
+
+}

Propchange: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestEvictionConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java?rev=1548133&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java (added)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java Thu Dec  5 13:36:19 2013
@@ -0,0 +1,485 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.pool2.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for {@link LinkedBlockingDeque}.
+ */
+public class TestLinkedBlockingDeque {
+
+    private static final Integer ONE = Integer.valueOf(1);
+    private static final Integer TWO = Integer.valueOf(2);
+    private static final Integer THREE = Integer.valueOf(3);
+
+    LinkedBlockingDeque<Integer> deque;
+
+    @Before
+    public void setUp() {
+        deque = new LinkedBlockingDeque<Integer>(2);
+    }
+
+    @Test
+    public void testConstructors() {
+        LinkedBlockingDeque<Integer> deque = new LinkedBlockingDeque<Integer>();
+        assertEquals(Integer.MAX_VALUE, deque.remainingCapacity());
+
+        deque = new LinkedBlockingDeque<Integer>(2);
+        assertEquals(2, deque.remainingCapacity());
+
+        deque = new LinkedBlockingDeque<Integer>(Arrays.asList(ONE, TWO));
+        assertEquals(2, deque.size());
+
+        try {
+            deque = new LinkedBlockingDeque<Integer>(Arrays.asList(ONE, null));
+            fail("Not supposed to get here");
+        } catch (NullPointerException npe) {
+            // OK
+        }
+    }
+
+    @Test
+    public void testAddFirst() {
+        deque.addFirst(ONE);
+        deque.addFirst(TWO);
+        assertEquals(2, deque.size());
+        try {
+            deque.addFirst(THREE);
+            fail("Not supposed to get here");
+        } catch (IllegalStateException e) {}
+        assertEquals(Integer.valueOf(2), deque.pop());
+    }
+
+    @Test
+    public void testAddLast() {
+        deque.addLast(ONE);
+        deque.addLast(TWO);
+        assertEquals(2, deque.size());
+        try {
+            deque.addLast(THREE);
+            fail("Not supposed to get here");
+        } catch (IllegalStateException e) {}
+        assertEquals(Integer.valueOf(1), deque.pop());
+    }
+
+    @Test
+    public void testOfferFirst() {
+        deque.offerFirst(ONE);
+        deque.offerFirst(TWO);
+        assertEquals(2, deque.size());
+        try {
+            deque.offerFirst(null);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+        assertEquals(Integer.valueOf(2), deque.pop());
+    }
+
+    @Test
+    public void testOfferLast() {
+        deque.offerLast(ONE);
+        deque.offerLast(TWO);
+        assertEquals(2, deque.size());
+        try {
+            deque.offerLast(null);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+        assertEquals(Integer.valueOf(1), deque.pop());
+    }
+
+    @Test
+    public void testPutFirst() throws InterruptedException {
+        try {
+            deque.putFirst(null);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+        deque.putFirst(ONE);
+        deque.putFirst(TWO);
+        assertEquals(2, deque.size());
+        assertEquals(Integer.valueOf(2), deque.pop());
+    }
+
+    @Test
+    public void testPutLast() throws InterruptedException {
+        try {
+            deque.putLast(null);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+        deque.putLast(ONE);
+        deque.putLast(TWO);
+        assertEquals(2, deque.size());
+        assertEquals(Integer.valueOf(1), deque.pop());
+    }
+
+    @Test
+    public void testOfferFirstWithTimeout() throws InterruptedException {
+        try {
+            deque.offerFirst(null);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+        assertTrue(deque.offerFirst(ONE, 50, TimeUnit.MILLISECONDS));
+        assertTrue(deque.offerFirst(TWO, 50, TimeUnit.MILLISECONDS));
+        assertFalse(deque.offerFirst(THREE, 50, TimeUnit.MILLISECONDS));
+    }
+
+    @Test
+    public void testOfferLastWithTimeout() throws InterruptedException {
+        try {
+            deque.offerLast(null);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+        assertTrue(deque.offerLast(ONE, 50, TimeUnit.MILLISECONDS));
+        assertTrue(deque.offerLast(TWO, 50, TimeUnit.MILLISECONDS));
+        assertFalse(deque.offerLast(THREE, 50, TimeUnit.MILLISECONDS));
+    }
+
+    @Test
+    public void testRemoveFirst() {
+        try {
+            deque.removeFirst();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(1), deque.removeFirst());
+        try {
+            deque.removeFirst();
+            deque.removeFirst();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+    }
+
+    @Test
+    public void testRemoveLast() {
+        try {
+            deque.removeLast();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(2), deque.removeLast());
+        try {
+            deque.removeLast();
+            deque.removeLast();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+    }
+
+    @Test
+    public void testPollFirst() {
+        assertNull(deque.pollFirst());
+        assertTrue(deque.offerFirst(ONE));
+        assertTrue(deque.offerFirst(TWO));
+        assertEquals(Integer.valueOf(2), deque.pollFirst());
+    }
+
+    @Test
+    public void testPollLast() {
+        assertNull(deque.pollLast());
+        assertTrue(deque.offerFirst(ONE));
+        assertTrue(deque.offerFirst(TWO));
+        assertEquals(Integer.valueOf(1), deque.pollLast());
+    }
+
+    @Test
+    public void testTakeFirst() throws InterruptedException {
+        assertTrue(deque.offerFirst(ONE));
+        assertTrue(deque.offerFirst(TWO));
+        assertEquals(Integer.valueOf(2), deque.takeFirst());
+    }
+
+    @Test
+    public void testTakeLast() throws InterruptedException {
+        assertTrue(deque.offerFirst(ONE));
+        assertTrue(deque.offerFirst(TWO));
+        assertEquals(Integer.valueOf(1), deque.takeLast());
+    }
+
+    @Test
+    public void testPollFirstWithTimeout() throws InterruptedException {
+        assertNull(deque.pollFirst());
+        assertNull(deque.pollFirst(50, TimeUnit.MILLISECONDS));
+    }
+
+    @Test
+    public void testPollLastWithTimeout() throws InterruptedException {
+        assertNull(deque.pollLast());
+        assertNull(deque.pollLast(50, TimeUnit.MILLISECONDS));
+    }
+
+    @Test
+    public void testGetFirst() {
+        try {
+            deque.getFirst();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e){}
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(1), deque.getFirst());
+    }
+
+    @Test
+    public void testGetLast() {
+        try {
+            deque.getLast();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e){}
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(2), deque.getLast());
+    }
+
+    @Test
+    public void testPeekFirst() {
+        assertNull(deque.peekFirst());
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(1), deque.peekFirst());
+    }
+
+    @Test
+    public void testPeekLast() {
+        assertNull(deque.peekLast());
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(2), deque.peekLast());
+    }
+
+    @Test
+    public void testRemoveLastOccurence() {
+        assertFalse(deque.removeLastOccurrence(null));
+        assertFalse(deque.removeLastOccurrence(ONE));
+        deque.add(ONE);
+        deque.add(ONE);
+        assertTrue(deque.removeLastOccurrence(ONE));
+        assertTrue(deque.size() == 1);
+    }
+
+    @Test
+    public void testAdd() {
+        assertTrue(deque.add(ONE));
+        assertTrue(deque.add(TWO));
+        try {
+            assertTrue(deque.add(THREE));
+            fail("Not supposed to get here");
+        } catch (IllegalStateException e) {}
+        try {
+            assertTrue(deque.add(null));
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+    }
+
+    @Test
+    public void testOffer() {
+        assertTrue(deque.offer(ONE));
+        assertTrue(deque.offer(TWO));
+        assertFalse(deque.offer(THREE));
+        try {
+            deque.offer(null);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+    }
+
+    @Test
+    public void testPut() throws InterruptedException {
+        try {
+            deque.put(null);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+        deque.put(ONE);
+        deque.put(TWO);
+    }
+
+    @Test
+    public void testOfferWithTimeout() throws InterruptedException {
+        assertTrue(deque.offer(ONE, 50, TimeUnit.MILLISECONDS));
+        assertTrue(deque.offer(TWO, 50, TimeUnit.MILLISECONDS));
+        assertFalse(deque.offer(THREE, 50, TimeUnit.MILLISECONDS));
+        try {
+            deque.offer(null, 50, TimeUnit.MILLISECONDS);
+            fail("Not supposed to get here");
+        } catch (NullPointerException e) {}
+    }
+
+    @Test
+    public void testRemove() {
+        try {
+            deque.remove();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(1), deque.remove());
+    }
+
+    @Test
+    public void testTake() throws InterruptedException {
+        assertTrue(deque.offerFirst(ONE));
+        assertTrue(deque.offerFirst(TWO));
+        assertEquals(Integer.valueOf(2), deque.take());
+    }
+
+    @Test
+    public void testPollWithTimeout() throws InterruptedException {
+        assertNull(deque.poll(50, TimeUnit.MILLISECONDS));
+        assertNull(deque.poll(50, TimeUnit.MILLISECONDS));
+    }
+
+    @Test
+    public void testElement() {
+        try {
+            deque.element();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e){}
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(1), deque.element());
+    }
+
+    @Test
+    public void testPeek() {
+        assertNull(deque.peek());
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(1), deque.peek());
+    }
+
+    @Test
+    public void testDrainTo() {
+        Collection<Integer> c = new ArrayList<Integer>();
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(2, deque.drainTo(c));
+        assertEquals(2, c.size());
+
+        c = new ArrayList<Integer>();
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(1, deque.drainTo(c, 1));
+        assertEquals(1, deque.size());
+        assertEquals(1, c.size());
+        assertEquals(Integer.valueOf(1), c.iterator().next());
+    }
+
+    @Test
+    public void testPush() {
+        deque.push(ONE);
+        deque.push(TWO);
+        assertEquals(2, deque.size());
+        try {
+            deque.push(THREE);
+            fail("Not supposed to get here");
+        } catch (IllegalStateException e) {}
+        assertEquals(Integer.valueOf(2), deque.pop());
+    }
+
+    @Test
+    public void testPop() {
+        try {
+            deque.pop();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+        deque.add(ONE);
+        deque.add(TWO);
+        assertEquals(Integer.valueOf(1), deque.pop());
+        try {
+            deque.pop();
+            deque.pop();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+    }
+
+    @Test
+    public void testContains() {
+        deque.add(ONE);
+        assertTrue(deque.contains(ONE));
+        assertFalse(deque.contains(TWO));
+        assertFalse(deque.contains(null));
+        deque.add(TWO);
+        assertTrue(deque.contains(TWO));
+        assertFalse(deque.contains(THREE));
+    }
+
+    @Test
+    public void testToArray() {
+        deque.add(ONE);
+        deque.add(TWO);
+        Object[] arr = deque.toArray();
+        assertEquals(Integer.valueOf(1), arr[0]);
+        assertEquals(Integer.valueOf(2), arr[1]);
+
+        arr = deque.toArray(new Integer[0]);
+        assertEquals(Integer.valueOf(1), arr[0]);
+        assertEquals(Integer.valueOf(2), arr[1]);
+
+        arr = deque.toArray(new Integer[deque.size()]);
+        assertEquals(Integer.valueOf(1), arr[0]);
+        assertEquals(Integer.valueOf(2), arr[1]);
+    }
+
+    @Test
+    public void testClear() {
+        deque.add(ONE);
+        deque.add(TWO);
+        deque.clear();
+        deque.add(ONE);
+        assertEquals(1, deque.size());
+    }
+
+    @Test
+    public void testIterator() {
+        try {
+            deque.iterator().next();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+        deque.add(ONE);
+        deque.add(TWO);
+        Iterator<Integer> iter = deque.iterator();
+        assertEquals(Integer.valueOf(1), iter.next());
+        iter.remove();
+        assertEquals(Integer.valueOf(2), iter.next());
+    }
+
+    @Test
+    public void testDescendingIterator() {
+        try {
+            deque.descendingIterator().next();
+            fail("Not supposed to get here");
+        } catch (NoSuchElementException e) {}
+        deque.add(ONE);
+        deque.add(TWO);
+        Iterator<Integer> iter = deque.descendingIterator();
+        assertEquals(Integer.valueOf(2), iter.next());
+        iter.remove();
+        assertEquals(Integer.valueOf(1), iter.next());
+    }
+
+}

Propchange: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestLinkedBlockingDeque.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestPooledSoftReference.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestPooledSoftReference.java?rev=1548133&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestPooledSoftReference.java (added)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestPooledSoftReference.java Thu Dec  5 13:36:19 2013
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.pool2.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.ref.SoftReference;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for {@PooledSoftReference}.
+ */
+public class TestPooledSoftReference {
+
+    PooledSoftReference<String> ref;
+    private static final String REFERENT = "test";
+    private static final String REFERENT2 = "test2";
+
+    @Before
+    public void setUp() {
+        SoftReference<String> softRef = new SoftReference<String>(REFERENT);
+        ref = new PooledSoftReference<String>(softRef);
+    }
+
+    @Test
+    public void testPooledSoftReference() {
+        assertEquals(REFERENT, ref.getObject());
+
+        SoftReference<String> softRef = ref.getReference();
+        assertEquals(REFERENT, softRef.get());
+        softRef.clear();
+
+        softRef = new SoftReference<String>(REFERENT2);
+        ref.setReference(softRef);
+
+        assertEquals(REFERENT2, ref.getObject());
+
+        softRef = ref.getReference();
+        assertEquals(REFERENT2, softRef.get());
+        softRef.clear();
+    }
+
+}

Propchange: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestPooledSoftReference.java
------------------------------------------------------------------------------
    svn:eol-style = native