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

Matthew Swift
28.31.2014 ed08a89377a333c10202ead88d355e16bcb3a0fd
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