From 3e1db08dce649f6d426aae67d506c8c23b15f6e8 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 18 Sep 2013 16:05:59 +0000
Subject: [PATCH] Fix OPENDJ-1058 – HeartbeatConnectionFactory does not actively shutdown dead connections

---
 opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionPoolTestCase.java |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionPoolTestCase.java b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionPoolTestCase.java
index 83348e3..0dd7596 100644
--- a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionPoolTestCase.java
+++ b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/ConnectionPoolTestCase.java
@@ -44,7 +44,6 @@
 
 import java.util.LinkedList;
 import java.util.List;
-import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 
 import org.forgerock.opendj.ldap.requests.BindRequest;
@@ -448,10 +447,7 @@
         assertThat(scheduler.isScheduled()).isTrue();
 
         // First populate the pool with idle connections at time 0.
-        @SuppressWarnings("unchecked")
-        final Callable<Long> timeSource = mock(Callable.class);
-        when(timeSource.call()).thenReturn(0L);
-        pool.testTimeSource = timeSource;
+        pool.timeSource = mockTimeSource(0);
 
         assertThat(pool.currentPoolSize()).isEqualTo(0);
         Connection c1 = pool.getConnection();
@@ -466,13 +462,13 @@
         assertThat(pool.currentPoolSize()).isEqualTo(4);
 
         // First purge at time 50 is no-op because no connections have expired.
-        when(timeSource.call()).thenReturn(50L);
-        scheduler.getCommand().run();
+        when(pool.timeSource.currentTimeMillis()).thenReturn(50L);
+        scheduler.runFirstTask();
         assertThat(pool.currentPoolSize()).isEqualTo(4);
 
         // Second purge at time 150 should remove 2 non-core connections.
-        when(timeSource.call()).thenReturn(150L);
-        scheduler.getCommand().run();
+        when(pool.timeSource.currentTimeMillis()).thenReturn(150L);
+        scheduler.runFirstTask();
         assertThat(pool.currentPoolSize()).isEqualTo(2);
 
         verify(pooledConnection1, times(1)).close();
@@ -481,7 +477,7 @@
         verify(pooledConnection4, times(0)).close();
 
         // Regrow the pool at time 200.
-        when(timeSource.call()).thenReturn(200L);
+        when(pool.timeSource.currentTimeMillis()).thenReturn(200L);
         Connection c5 = pool.getConnection(); // pooledConnection3
         Connection c6 = pool.getConnection(); // pooledConnection4
         Connection c7 = pool.getConnection(); // pooledConnection5
@@ -494,13 +490,13 @@
         assertThat(pool.currentPoolSize()).isEqualTo(4);
 
         // Third purge at time 250 should not remove any connections.
-        when(timeSource.call()).thenReturn(250L);
-        scheduler.getCommand().run();
+        when(pool.timeSource.currentTimeMillis()).thenReturn(250L);
+        scheduler.runFirstTask();
         assertThat(pool.currentPoolSize()).isEqualTo(4);
 
         // Fourth purge at time 350 should remove 2 non-core connections.
-        when(timeSource.call()).thenReturn(350L);
-        scheduler.getCommand().run();
+        when(pool.timeSource.currentTimeMillis()).thenReturn(350L);
+        scheduler.runFirstTask();
         assertThat(pool.currentPoolSize()).isEqualTo(2);
 
         verify(pooledConnection3, times(1)).close();

--
Gitblit v1.10.0