From ed08a89377a333c10202ead88d355e16bcb3a0fd Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 27 Feb 2014 23:31:10 +0000
Subject: [PATCH] Backport fix for OPENDJ-1197: API is lacking functionality to specify TCP connect timeout
---
opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java | 33 +++++++++++++++++++++++++++++++--
1 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java b/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java
index 7778e46..1fbf160 100644
--- a/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java
+++ b/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/LDAPConnectionFactoryTestCase.java
@@ -21,7 +21,7 @@
* CDDL HEADER END
*
*
- * Copyright 2013 ForgeRock AS.
+ * Copyright 2013-2014 ForgeRock AS.
*/
package org.forgerock.opendj.ldap;
@@ -61,7 +61,11 @@
*/
@SuppressWarnings({ "javadoc", "unchecked" })
public class LDAPConnectionFactoryTestCase extends SdkTestCase {
- // Manual testing has gone up to 10000 iterations.
+ /*
+ * The number of test iterations for unit tests which attempt to expose
+ * potential race conditions. Manual testing has gone up to 10000
+ * iterations.
+ */
private static final int ITERATIONS = 100;
// Test timeout for tests which need to wait for network events.
@@ -95,6 +99,31 @@
server.close();
}
+ @Test(description = "OPENDJ-1197")
+ public void testClientSideConnectTimeout() throws Exception {
+ // Use an non-local unreachable network address.
+ final ConnectionFactory factory =
+ new LDAPConnectionFactory("10.20.30.40", 1389, new LDAPOptions().setConnectTimeout(
+ 1, TimeUnit.MILLISECONDS));
+ try {
+ for (int i = 0; i < ITERATIONS; i++) {
+ final ResultHandler<Connection> handler = mock(ResultHandler.class);
+ final FutureResult<Connection> future = factory.getConnectionAsync(handler);
+ // Wait for the connect to timeout.
+ try {
+ future.get(TEST_TIMEOUT, TimeUnit.SECONDS);
+ fail("The connect request succeeded unexpectedly");
+ } catch (ConnectionException e) {
+ assertThat(e.getResult().getResultCode()).isEqualTo(
+ ResultCode.CLIENT_SIDE_CONNECT_ERROR);
+ verify(handler).handleErrorResult(same(e));
+ }
+ }
+ } finally {
+ factory.close();
+ }
+ }
+
/**
* Unit test for OPENDJ-1247: a locally timed out bind request will leave a
* connection in an invalid state since a bind (or startTLS) is in progress
--
Gitblit v1.10.0