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/11/03 19:24:00 UTC

svn commit: r1538412 - /commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java

Author: markt
Date: Sun Nov  3 18:24:00 2013
New Revision: 1538412

URL: http://svn.apache.org/r1538412
Log:
Add some tests for DefaultPooledObjectInfo that currently has zero coverage.

Added:
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java   (with props)

Added: 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=1538412&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java (added)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObjectInfo.java Sun Nov  3 18:24:00 2013
@@ -0,0 +1,100 @@
+/*
+ * 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 java.util.Set;
+
+import org.apache.commons.pool2.impl.TestGenericObjectPool.SimpleFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestDefaultPooledObjectInfo {
+
+    @Test
+    public void testTiming() throws Exception {
+        GenericObjectPool<String> pool =
+                new GenericObjectPool<String>(new SimpleFactory());
+
+        long t1 = System.currentTimeMillis();
+
+        Thread.sleep(50);
+        String s1 = pool.borrowObject();
+        Thread.sleep(50);
+
+        long t2 = System.currentTimeMillis();
+
+        Thread.sleep(50);
+        pool.returnObject(s1);
+        Thread.sleep(50);
+
+        long t3 = System.currentTimeMillis();
+
+        Thread.sleep(50);
+        s1 = pool.borrowObject();
+        Thread.sleep(50);
+
+        long t4 = System.currentTimeMillis();
+
+        Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
+
+        Assert.assertEquals(1, strings.size());
+
+        DefaultPooledObjectInfo s1Info = strings.iterator().next();
+
+        Assert.assertTrue(s1Info.getCreateTime() > t1);
+        Assert.assertTrue(s1Info.getCreateTime() < t2);
+
+        Assert.assertTrue(s1Info.getLastReturnTime() > t2);
+        Assert.assertTrue(s1Info.getLastReturnTime() < t3);
+
+        Assert.assertTrue(s1Info.getLastBorrowTime() > t3);
+        Assert.assertTrue(s1Info.getLastBorrowTime() < t4);
+    }
+
+    @Test
+    public void testGetPooledObjectType() throws Exception {
+        GenericObjectPool<String> pool =
+                new GenericObjectPool<String>(new SimpleFactory());
+
+        pool.borrowObject();
+
+        Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
+
+        Assert.assertEquals(1, strings.size());
+
+        DefaultPooledObjectInfo s1Info = strings.iterator().next();
+
+        Assert.assertEquals(String.class.getName(),
+                s1Info.getPooledObjectType());
+    }
+
+    @Test
+    public void testGetPooledObjectToString() throws Exception {
+        GenericObjectPool<String> pool =
+                new GenericObjectPool<String>(new SimpleFactory());
+
+        String s1 = pool.borrowObject();
+
+        Set<DefaultPooledObjectInfo> strings = pool.listAllObjects();
+
+        Assert.assertEquals(1, strings.size());
+
+        DefaultPooledObjectInfo s1Info = strings.iterator().next();
+
+        Assert.assertEquals(s1, s1Info.getPooledObjectToString());
+    }
+}

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