From 7d1bbf9b372e41121198be2b9f0f322d58b8d014 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 18 Sep 2013 16:28:59 +0000
Subject: [PATCH] Backport fix for OPENDJ-1058 – HeartbeatConnectionFactory does not actively shutdown dead connections
---
opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java b/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
index 33b34f5..2a8c3bd 100644
--- a/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
+++ b/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
@@ -22,7 +22,7 @@
*
*
* Copyright 2009-2010 Sun Microsystems, Inc.
- * Portions copyright 2012 ForgeRock AS.
+ * Portions copyright 2012-2013 ForgeRock AS.
*/
package org.forgerock.opendj.ldap;
@@ -42,8 +42,10 @@
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import org.mockito.stubbing.OngoingStubbing;
import com.forgerock.opendj.util.CompletedFutureResult;
+import com.forgerock.opendj.util.TimeSource;
/**
* This class defines some utility functions which can be used by test cases.
@@ -202,4 +204,22 @@
return mockConnection;
}
+
+ /**
+ * Returns a mock {@link TimeSource} which can be used for injecting fake
+ * time stamps into components.
+ *
+ * @param times
+ * The times in milli-seconds which should be returned by the
+ * time source.
+ * @return The mock time source.
+ */
+ public static TimeSource mockTimeSource(final long... times) {
+ final TimeSource mock = mock(TimeSource.class);
+ OngoingStubbing<Long> stubbing = when(mock.currentTimeMillis());
+ for (long t : times) {
+ stubbing = stubbing.thenReturn(t);
+ }
+ return mock;
+ }
}
--
Gitblit v1.10.0