| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | */ |
| | | @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. |
| | |
| | | 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 |