mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
18.28.2013 7d1bbf9b372e41121198be2b9f0f322d58b8d014
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();