commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1770094 - in /commons/proper/pool/trunk: .travis.yml src/test/java/org/apache/commons/pool2/PoolTest.java
Date Thu, 17 Nov 2016 00:02:16 GMT
Author: ggregory
Date: Thu Nov 17 00:02:16 2016
New Revision: 1770094

URL: http://svn.apache.org/viewvc?rev=1770094&view=rev
Log:
Add starter TravisCI configuration. Will pick up Travis profile from new parent module when
released.

Added:
    commons/proper/pool/trunk/.travis.yml
    commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/PoolTest.java

Added: commons/proper/pool/trunk/.travis.yml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/.travis.yml?rev=1770094&view=auto
==============================================================================
--- commons/proper/pool/trunk/.travis.yml (added)
+++ commons/proper/pool/trunk/.travis.yml Thu Nov 17 00:02:16 2016
@@ -0,0 +1,24 @@
+# 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.
+
+language: java
+sudo: false
+
+jdk:
+  - openjdk7
+  - oraclejdk8
+
+after_success:
+  - mvn clean cobertura:cobertura coveralls:report

Added: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/PoolTest.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/PoolTest.java?rev=1770094&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/PoolTest.java (added)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/PoolTest.java Thu Nov
17 00:02:16 2016
@@ -0,0 +1,80 @@
+package org.apache.commons.pool2;
+
+import static org.junit.Assert.assertFalse;
+
+import org.apache.commons.pool2.impl.DefaultPooledObject;
+import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore
+public class PoolTest {
+    private static final CharSequence COMMONS_POOL_EVICTIONS_TIMER_THREAD_NAME = "commons-pool-EvictionTimer";
+    private static final long EVICTION_PERIOD_IN_MILLIS = 100;
+
+    private static class Foo {
+    }
+
+    private static class PooledFooFactory implements PooledObjectFactory<Foo> {
+        private static final long VALIDATION_WAIT_IN_MILLIS = 1000;
+
+        @Override
+        public PooledObject<Foo> makeObject() throws Exception {
+            return new DefaultPooledObject<Foo>(new Foo());
+        }
+
+        @Override
+        public void destroyObject(PooledObject<Foo> pooledObject) throws Exception
{
+        }
+
+        @Override
+        public boolean validateObject(PooledObject<Foo> pooledObject) {
+            try {
+                Thread.sleep(VALIDATION_WAIT_IN_MILLIS);
+            } catch (final InterruptedException e) {
+                Thread.interrupted();
+            }
+            return false;
+        }
+
+        @Override
+        public void activateObject(PooledObject<Foo> pooledObject) throws Exception
{
+        }
+
+        @Override
+        public void passivateObject(PooledObject<Foo> pooledObject) throws Exception
{
+        }
+    }
+
+    @Test
+    public void testPool() throws Exception {
+        final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
+        poolConfig.setTestWhileIdle(true /* testWhileIdle */);
+        final PooledFooFactory pooledFooFactory = new PooledFooFactory();
+        GenericObjectPool<Foo> pool = null;
+        try {
+            pool = new GenericObjectPool<Foo>(pooledFooFactory, poolConfig);
+            pool.setTimeBetweenEvictionRunsMillis(EVICTION_PERIOD_IN_MILLIS);
+            pool.addObject();
+            try {
+                Thread.sleep(EVICTION_PERIOD_IN_MILLIS);
+            } catch (final InterruptedException e) {
+                Thread.interrupted();
+            }
+        } finally {
+            if (pool != null) {
+                pool.close();
+            }
+        }
+        final Thread[] threads = new Thread[Thread.activeCount()];
+        Thread.enumerate(threads);
+        for (final Thread thread : threads) {
+            if (thread == null) {
+                continue;
+            }
+            final String name = thread.getName();
+            assertFalse(name, name.contains(COMMONS_POOL_EVICTIONS_TIMER_THREAD_NAME));
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message