You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2014/09/28 04:38:14 UTC

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

Author: psteitz
Date: Sun Sep 28 02:38:14 2014
New Revision: 1628042

URL: http://svn.apache.org/r1628042
Log:
Added some tests for BaseGenericObjectPool stats.

Added:
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java

Added: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java?rev=1628042&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java (added)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java Sun Sep 28 02:38:14 2014
@@ -0,0 +1,65 @@
+/*
+ * 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 org.apache.commons.pool2.impl.TestGenericObjectPool.SimpleFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version $Revision:$
+ */
+public class TestBaseGenericObjectPool {
+
+    BaseGenericObjectPool<String> pool = null;
+    SimpleFactory factory = null;
+
+    @Before
+    public void setUp() throws Exception {
+        factory = new SimpleFactory();
+        pool = new GenericObjectPool<String>(factory);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        pool.close();
+        pool = null;
+        factory = null; 
+    }
+    
+    @Test
+    public void testBorrowWaitStatistics() {
+    	DefaultPooledObject<String> p = (DefaultPooledObject<String>) factory.makeObject();
+    	pool.updateStatsBorrow(p, 10);
+    	pool.updateStatsBorrow(p, 20);
+    	pool.updateStatsBorrow(p, 20);
+    	pool.updateStatsBorrow(p, 30);
+    	Assert.assertEquals(20, pool.getMeanBorrowWaitTimeMillis(), Double.MIN_VALUE);
+    	Assert.assertEquals(30, pool.getMaxBorrowWaitTimeMillis(), 0);
+    }
+    
+    @Test
+    public void testActiveTimeStatistics() {
+    	for (int i = 0; i < 99; i++) {  // must be < MEAN_TIMING_STATS_CACHE_SIZE
+    		pool.updateStatsReturn(i);
+    	}
+    	Assert.assertEquals(49, pool.getMeanActiveTimeMillis(), Double.MIN_VALUE);
+    }
+}