From 6a43174e1beb66446601e5c87063d07de92d2418 Mon Sep 17 00:00:00 2001
From: Chris Ridd <chris.ridd@forgerock.com>
Date: Thu, 22 May 2014 09:46:17 +0000
Subject: [PATCH] Fix OPENDJ-1466: Improve initialization of InetSocketAddress in SDK to prevent cached DNS data.
---
opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/LDAPConnectionFactoryImpl.java | 15 ++
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactoryTestCase.java | 18 ++
opendj-core/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java | 67 ----------
opendj-core/clirr-ignored-api-changes.xml | 25 ++++
opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicLDAPConnectionFactory.java | 28 +++-
opendj-grizzly/src/main/java/com/forgerock/opendj/grizzly/GrizzlyTransportProvider.java | 6
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java | 61 ++++++---
opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicTransportProvider.java | 4
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java | 41 ++++--
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionTestCase.java | 4
opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/TransportProvider.java | 13 +
opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java | 46 +++++--
12 files changed, 196 insertions(+), 132 deletions(-)
diff --git a/opendj-core/clirr-ignored-api-changes.xml b/opendj-core/clirr-ignored-api-changes.xml
index ddb722e..e32115d 100644
--- a/opendj-core/clirr-ignored-api-changes.xml
+++ b/opendj-core/clirr-ignored-api-changes.xml
@@ -43,6 +43,31 @@
Note: waiting on https://jira.codehaus.org/browse/MCLIRR-62 to be resolved to avoid the need to use \s* in the '<to>' tags.
-->
<difference>
+ <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className>
+ <differenceType>7002</differenceType>
+ <method>LDAPConnectionFactory(java.net.SocketAddress)</method>
+ <justification>Moving from inetSocketAddress to host+port constructors</justification>
+ </difference>
+ <difference>
+ <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className>
+ <differenceType>7002</differenceType>
+ <method>LDAPConnectionFactory(java.net.SocketAddress, org.forgerock.opendj.ldap.LDAPOptions)</method>
+ <justification>Moving from inetSocketAddress to host+port constructors</justification>
+ </difference>
+ <difference>
+ <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className>
+ <differenceType>7002</differenceType>
+ <method>java.net.InetAddress getAddress()</method>
+ <justification>Moving from inetSocketAddress to host+port constructors</justification>
+ </difference>
+ <difference>
+ <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className>
+ <differenceType>7002</differenceType>
+ <method>java.net.SocketAddress getSocketAddress()</method>
+ <justification>Moving from inetSocketAddress to host+port constructors</justification>
+ </difference>
+
+ <difference>
<className>org/forgerock/opendj/ldap/CoreMessages</className>
<differenceType>8001</differenceType>
<justification>Incorrectly reported because it is automatically generated</justification>
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java
index f3e4312..1881392 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java
@@ -29,9 +29,6 @@
import static com.forgerock.opendj.util.StaticUtils.getProvider;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-
import org.forgerock.opendj.ldap.spi.LDAPConnectionFactoryImpl;
import org.forgerock.opendj.ldap.spi.TransportProvider;
import org.forgerock.util.Reject;
@@ -54,43 +51,8 @@
/**
* Creates a new LDAP connection factory which can be used to create LDAP
- * connections to the Directory Server at the provided address.
- *
- * @param address
- * The address of the Directory Server.
- * @throws NullPointerException
- * If {@code address} was {@code null}.
- * @throws ProviderNotFoundException if no provider is available or if the
- * provider requested using options is not found.
- */
- public LDAPConnectionFactory(final InetSocketAddress address) {
- this(address, new LDAPOptions());
- }
-
- /**
- * Creates a new LDAP connection factory which can be used to create LDAP
- * connections to the Directory Server at the provided address.
- *
- * @param address
- * The address of the Directory Server.
- * @param options
- * The LDAP options to use when creating connections.
- * @throws NullPointerException
- * If {@code address} or {@code options} was {@code null}.
- * @throws ProviderNotFoundException if no provider is available or if the
- * provider requested using options is not found.
- */
- public LDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options) {
- Reject.ifNull(address, options);
- this.provider = getProvider(TransportProvider.class, options.getTransportProvider(),
- options.getProviderClassLoader());
- this.impl = provider.getLDAPConnectionFactory(address, options);
- }
-
- /**
- * Creates a new LDAP connection factory which can be used to create LDAP
* connections to the Directory Server at the provided host and port
- * address.
+ * number.
*
* @param host
* The host name.
@@ -108,7 +70,7 @@
/**
* Creates a new LDAP connection factory which can be used to create LDAP
* connections to the Directory Server at the provided host and port
- * address.
+ * number.
*
* @param host
* The host name.
@@ -123,19 +85,9 @@
*/
public LDAPConnectionFactory(final String host, final int port, final LDAPOptions options) {
Reject.ifNull(host, options);
- final InetSocketAddress address = new InetSocketAddress(host, port);
this.provider = getProvider(TransportProvider.class, options.getTransportProvider(),
options.getProviderClassLoader());
- this.impl = provider.getLDAPConnectionFactory(address, options);
- }
-
- /**
- * Returns the {@code InetAddress} of the Directory Server.
- *
- * @return The {@code InetAddress} of the Directory Server.
- */
- public InetAddress getAddress() {
- return getSocketAddress().getAddress();
+ this.impl = provider.getLDAPConnectionFactory(host, port, options);
}
@Override
@@ -163,7 +115,7 @@
* @return The host name of the Directory Server.
*/
public String getHostName() {
- return Connections.getHostString(getSocketAddress());
+ return impl.getHostName();
}
/**
@@ -172,16 +124,7 @@
* @return The port of the Directory Server.
*/
public int getPort() {
- return getSocketAddress().getPort();
- }
-
- /**
- * Returns the address of the Directory Server.
- *
- * @return The address of the Directory Server.
- */
- public InetSocketAddress getSocketAddress() {
- return impl.getSocketAddress();
+ return impl.getPort();
}
/**
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/LDAPConnectionFactoryImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/LDAPConnectionFactoryImpl.java
index bbd1c36..159f58c 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/LDAPConnectionFactoryImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/LDAPConnectionFactoryImpl.java
@@ -49,4 +49,19 @@
*/
public InetSocketAddress getSocketAddress();
+ /**
+ * Returns the hostname used by the connections created by this factory.
+ *
+ * @return The hostname used by the connections.
+ */
+ public String getHostName();
+
+ /**
+ * Returns the remote port number used by the connections created by this
+ * factory.
+ *
+ * @return The remote port number used by the connections.
+ */
+ public int getPort();
+
}
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/TransportProvider.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/TransportProvider.java
index d3f0841..d4cb0bc 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/TransportProvider.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/TransportProvider.java
@@ -46,18 +46,21 @@
public interface TransportProvider extends Provider {
/**
- * Returns an implementation of {@code LDAPConnectionFactory}.
+ * Returns an implementation of {@code LDAPConnectionFactory}. The address
+ * will be resolved each time a new connection is returned.
*
- * @param address
- * The address of the Directory Server to connect to.
+ * @param host
+ * The hostname of the Directory Server to connect to.
+ * @param port
+ * The port number of the Directory Server to connect to.
* @param options
* The LDAP options to use when creating connections.
* @return an implementation of {@code LDAPConnectionFactory}
*/
- LDAPConnectionFactoryImpl getLDAPConnectionFactory(InetSocketAddress address,
+ LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port,
LDAPOptions options);
- /**
+ /**
* Returns an implementation of {@code LDAPListener}.
*
* @param address
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicLDAPConnectionFactory.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicLDAPConnectionFactory.java
index 95c54ed..6299d3d 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicLDAPConnectionFactory.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicLDAPConnectionFactory.java
@@ -46,18 +46,22 @@
public final class BasicLDAPConnectionFactory implements LDAPConnectionFactoryImpl {
private final LDAPOptions options;
- private final InetSocketAddress socketAddress;
+ private final String host;
+ private final int port;
/**
* Creates a new LDAP connection factory which does nothing.
*
- * @param address
+ * @param host
* The address of the Directory Server to connect to.
+ * @param port
+ * The port of the Directory Server to connect to.
* @param options
* The LDAP connection options to use when creating connections.
*/
- public BasicLDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options) {
- this.socketAddress = address;
+ public BasicLDAPConnectionFactory(final String host, final int port, final LDAPOptions options) {
+ this.host = host;
+ this.port = port;
this.options = new LDAPOptions(options);
}
@@ -90,14 +94,26 @@
* @return The address of the Directory Server.
*/
public InetSocketAddress getSocketAddress() {
- return socketAddress;
+ return new InetSocketAddress(host, port);
+ }
+
+ @Override
+ public String getHostName() {
+ return host;
+ }
+
+ @Override
+ public int getPort() {
+ return port;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("LDAPConnectionFactory(");
- builder.append(getSocketAddress().toString());
+ builder.append(host);
+ builder.append(':');
+ builder.append(port);
builder.append(')');
return builder.toString();
}
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicTransportProvider.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicTransportProvider.java
index b8b3f5b..475f05e 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicTransportProvider.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/spi/BasicTransportProvider.java
@@ -50,8 +50,8 @@
/** {@inheritDoc} */
@Override
- public LDAPConnectionFactoryImpl getLDAPConnectionFactory(InetSocketAddress address, LDAPOptions options) {
- return new BasicLDAPConnectionFactory(address, options);
+ public LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, LDAPOptions options) {
+ return new BasicLDAPConnectionFactory(host, port, options);
}
/** {@inheritDoc} */
diff --git a/opendj-grizzly/src/main/java/com/forgerock/opendj/grizzly/GrizzlyTransportProvider.java b/opendj-grizzly/src/main/java/com/forgerock/opendj/grizzly/GrizzlyTransportProvider.java
index 6357a83..43a6718 100644
--- a/opendj-grizzly/src/main/java/com/forgerock/opendj/grizzly/GrizzlyTransportProvider.java
+++ b/opendj-grizzly/src/main/java/com/forgerock/opendj/grizzly/GrizzlyTransportProvider.java
@@ -44,9 +44,9 @@
public class GrizzlyTransportProvider implements TransportProvider {
@Override
- public LDAPConnectionFactoryImpl getLDAPConnectionFactory(InetSocketAddress address,
- LDAPOptions options) {
- return new GrizzlyLDAPConnectionFactory(address, options);
+ public LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port,
+ LDAPOptions options) {
+ return new GrizzlyLDAPConnectionFactory(host, port, options);
}
@Override
diff --git a/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java b/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java
index abe101c..f67bd22 100644
--- a/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java
+++ b/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactory.java
@@ -217,7 +217,7 @@
return timeoutEndTime - currentTime;
} else {
future.handleErrorResult(newErrorResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR,
- LDAP_CONNECTION_CONNECT_TIMEOUT.get(socketAddress, getTimeout()).toString()));
+ LDAP_CONNECTION_CONNECT_TIMEOUT.get(getSocketAddress(), getTimeout()).toString()));
return 0;
}
}
@@ -231,7 +231,8 @@
private final LDAPClientFilter clientFilter;
private final FilterChain defaultFilterChain;
private final LDAPOptions options;
- private final InetSocketAddress socketAddress;
+ private final String host;
+ private final int port;
/**
* Prevents the transport and timeoutChecker being released when there are
@@ -254,13 +255,15 @@
* to create connections to the Directory Server at the provided host and
* port address using provided connection options.
*
- * @param address
- * The address of the Directory Server to connect to.
+ * @param host
+ * The hostname of the Directory Server to connect to.
+ * @param port
+ * The port number of the Directory Server to connect to.
* @param options
* The LDAP connection options to use when creating connections.
*/
- public GrizzlyLDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options) {
- this(address, options, null);
+ public GrizzlyLDAPConnectionFactory(final String host, final int port, final LDAPOptions options) {
+ this(host, port, options, null);
}
/**
@@ -269,18 +272,21 @@
* port address using provided connection options and provided TCP
* transport.
*
- * @param address
- * The address of the Directory Server to connect to.
+ * @param host
+ * The hostname of the Directory Server to connect to.
+ * @param port
+ * The port number of the Directory Server to connect to.
* @param options
* The LDAP connection options to use when creating connections.
* @param transport
* Grizzly TCP Transport NIO implementation to use for
* connections. If {@code null}, default transport will be used.
*/
- public GrizzlyLDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options,
- TCPNIOTransport transport) {
+ public GrizzlyLDAPConnectionFactory(final String host, final int port, final LDAPOptions options,
+ TCPNIOTransport transport) {
this.transport = DEFAULT_TRANSPORT.acquireIfNull(transport);
- this.socketAddress = address;
+ this.host = host;
+ this.port = port;
this.options = new LDAPOptions(options);
this.clientFilter = new LDAPClientFilter(this.options.getDecodeOptions(), 0);
this.defaultFilterChain =
@@ -312,20 +318,32 @@
.build();
final AsynchronousFutureResult<Connection, ResultHandler<? super Connection>> future =
new AsynchronousFutureResult<Connection, ResultHandler<? super Connection>>(handler);
- connectorHandler.connect(socketAddress, new CompletionHandlerAdapter(future));
+ connectorHandler.connect(getSocketAddress(), new CompletionHandlerAdapter(future));
return future;
}
@Override
public InetSocketAddress getSocketAddress() {
- return socketAddress;
+ return new InetSocketAddress(host, port);
+ }
+
+ @Override
+ public String getHostName() {
+ return host;
+ }
+
+ @Override
+ public int getPort() {
+ return port;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("LDAPConnectionFactory(");
- builder.append(getSocketAddress().toString());
+ builder.append(host);
+ builder.append(':');
+ builder.append(port);
builder.append(')');
return builder.toString();
}
diff --git a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java
index 37d00f0..5763cca 100644
--- a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java
+++ b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java
@@ -36,6 +36,7 @@
import static org.mockito.Mockito.*;
import static org.testng.Assert.*;
+import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
@@ -166,9 +167,10 @@
Requests.newSearchRequest("uid=user.0,ou=people,o=test", SearchScope.BASE_OBJECT,
"objectclass=*", "cn");
+ InetSocketAddress serverAddress = getServerSocketAddress();
factories[0][0] =
Connections.newHeartBeatConnectionFactory(new LDAPConnectionFactory(
- getServerSocketAddress()),
+ serverAddress.getHostName(), serverAddress.getPort()),
1000, 500, TimeUnit.MILLISECONDS, request);
// InternalConnectionFactory
@@ -176,16 +178,18 @@
// AuthenticatedConnectionFactory
factories[2][0] =
- Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress()),
+ Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory(
+ serverAddress.getHostName(), serverAddress.getPort()),
Requests.newSimpleBindRequest("", new char[0]));
// AuthenticatedConnectionFactory with multi-stage SASL
factories[3][0] =
- Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress()),
+ Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory(
+ serverAddress.getHostName(), serverAddress.getPort()),
Requests.newCRAMMD5SASLBindRequest("id:user", "password".toCharArray()));
// LDAPConnectionFactory with default options
- factories[4][0] = new LDAPConnectionFactory(getServerSocketAddress());
+ factories[4][0] = new LDAPConnectionFactory(serverAddress.getHostName(), serverAddress.getPort());
// LDAPConnectionFactory with startTLS
SSLContext sslContext =
@@ -198,7 +202,7 @@
"SSL_DH_anon_WITH_DES_CBC_SHA", "SSL_DH_anon_WITH_RC4_128_MD5",
"TLS_DH_anon_WITH_AES_128_CBC_SHA",
"TLS_DH_anon_WITH_AES_256_CBC_SHA" });
- factories[5][0] = new LDAPConnectionFactory(getServerSocketAddress(), options);
+ factories[5][0] = new LDAPConnectionFactory(serverAddress.getHostName(), serverAddress.getPort(), options);
// startTLS + SASL confidentiality
// Use IP address here so that DIGEST-MD5 host verification works if
@@ -207,20 +211,26 @@
// FIXME: enable QOP once OPENDJ-514 is fixed.
factories[6][0] =
Connections.newAuthenticatedConnectionFactory(new LDAPConnectionFactory(
- getServerSocketAddress(), options), Requests.newDigestMD5SASLBindRequest(
+ serverAddress.getHostName(), serverAddress.getPort(), options),
+ Requests.newDigestMD5SASLBindRequest(
"id:user", "password".toCharArray()).setCipher(
DigestMD5SASLBindRequest.CIPHER_LOW));
// Connection pool and load balancing tests.
+ InetSocketAddress offlineSocketAddress1 = findFreeSocketAddress();
ConnectionFactory offlineServer1 =
Connections.newNamedConnectionFactory(
- new LDAPConnectionFactory(findFreeSocketAddress()), "offline1");
+ new LDAPConnectionFactory(offlineSocketAddress1.getHostName(),
+ offlineSocketAddress1.getPort()), "offline1");
+ InetSocketAddress offlineSocketAddress2 = findFreeSocketAddress();
ConnectionFactory offlineServer2 =
Connections.newNamedConnectionFactory(
- new LDAPConnectionFactory(findFreeSocketAddress()), "offline2");
+ new LDAPConnectionFactory(offlineSocketAddress2.getHostName(),
+ offlineSocketAddress2.getPort()), "offline2");
ConnectionFactory onlineServer =
Connections.newNamedConnectionFactory(
- new LDAPConnectionFactory(getServerSocketAddress()), "online");
+ new LDAPConnectionFactory(serverAddress.getHostName(),
+ serverAddress.getPort()), "online");
// Connection pools.
factories[7][0] = Connections.newFixedConnectionPool(onlineServer, 10);
@@ -330,7 +340,9 @@
public void testSchemaUsage() throws Exception {
// Create a connection factory: this should always use the default
// schema, even if it is updated.
- final ConnectionFactory factory = new LDAPConnectionFactory(getServerSocketAddress());
+ InetSocketAddress socketAddress = getServerSocketAddress();
+ final ConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(),
+ socketAddress.getPort());
final Schema defaultSchema = Schema.getDefaultSchema();
final Connection connection = factory.getConnection();
@@ -572,7 +584,7 @@
LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mockServer);
try {
LDAPConnectionFactory clientFactory =
- new LDAPConnectionFactory(listener.getSocketAddress());
+ new LDAPConnectionFactory(listener.getHostName(), listener.getPort());
final Connection client = clientFactory.getConnection();
connectLatch.await(TEST_TIMEOUT, TimeUnit.SECONDS);
MockConnectionEventListener mockListener = null;
@@ -655,7 +667,8 @@
LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mockServer);
try {
LDAPConnectionFactory clientFactory =
- new LDAPConnectionFactory(listener.getSocketAddress());
+ new LDAPConnectionFactory(listener.getHostName(),
+ listener.getPort());
final Connection client = clientFactory.getConnection();
connectLatch.await(TEST_TIMEOUT, TimeUnit.SECONDS);
try {
@@ -689,9 +702,11 @@
@Test(description = "Test for OPENDJ-1121: Closing a connection after "
+ "closing the connection factory causes NPE")
public void testFactoryCloseBeforeConnectionClose() throws Exception {
+ InetSocketAddress socketAddress = getServerSocketAddress();
final ConnectionFactory factory =
newLoadBalancer(new FailoverLoadBalancingAlgorithm(Arrays.asList(newFixedConnectionPool(
- newHeartBeatConnectionFactory(new LDAPConnectionFactory(getServerSocketAddress())), 2))));
+ newHeartBeatConnectionFactory(new LDAPConnectionFactory(
+ socketAddress.getHostName(), socketAddress.getPort())), 2))));
Connection conn = null;
try {
conn = factory.getConnection();
diff --git a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactoryTestCase.java b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactoryTestCase.java
index a6f4f18..980e64b 100644
--- a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactoryTestCase.java
+++ b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactoryTestCase.java
@@ -35,6 +35,7 @@
import static org.mockito.Mockito.*;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -104,8 +105,9 @@
private final AtomicReference<LDAPClientContext> context =
new AtomicReference<LDAPClientContext>();
private final LDAPListener server = createServer();
- private final ConnectionFactory factory = new LDAPConnectionFactory(server.getSocketAddress(),
- new LDAPOptions().setTimeout(1, TimeUnit.MILLISECONDS));
+ private final InetSocketAddress socketAddress = server.getSocketAddress();
+ private final ConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(),
+ socketAddress.getPort(), new LDAPOptions().setTimeout(1, TimeUnit.MILLISECONDS));
private final ConnectionFactory pool = Connections.newFixedConnectionPool(factory, 10);
private volatile ServerConnection<Integer> serverConnection;
@@ -293,7 +295,9 @@
@Test
public void testCreateLDAPConnectionFactory() throws Exception {
// test no exception is thrown, which means transport provider is correctly loaded
- LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress());
+ InetSocketAddress socketAddress = findFreeSocketAddress();
+ LDAPConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(),
+ socketAddress.getPort());
factory.close();
}
@@ -301,7 +305,9 @@
expectedExceptionsMessageRegExp = "^The requested provider 'unknown' .*")
public void testCreateLDAPConnectionFactoryFailureProviderNotFound() throws Exception {
LDAPOptions options = new LDAPOptions().setTransportProvider("unknown");
- LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress(), options);
+ InetSocketAddress socketAddress = findFreeSocketAddress();
+ LDAPConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(),
+ socketAddress.getPort(), options);
factory.close();
}
@@ -311,7 +317,9 @@
LDAPOptions options =
new LDAPOptions().setProviderClassLoader(Thread.currentThread()
.getContextClassLoader());
- LDAPConnectionFactory factory = new LDAPConnectionFactory(findFreeSocketAddress(), options);
+ InetSocketAddress socketAddress = findFreeSocketAddress();
+ LDAPConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(),
+ socketAddress.getPort(), options);
factory.close();
}
diff --git a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionTestCase.java b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionTestCase.java
index 6ca0d90..2ffb2ba 100644
--- a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionTestCase.java
+++ b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionTestCase.java
@@ -91,8 +91,8 @@
* Use a very long time out in order to prevent the timeout thread from
* triggering the timeout.
*/
- LDAPConnectionFactory factory = new LDAPConnectionFactory(address,
- new LDAPOptions().setTimeout(100, TimeUnit.SECONDS));
+ LDAPConnectionFactory factory = new LDAPConnectionFactory(address.getHostName(),
+ address.getPort(), new LDAPOptions().setTimeout(100, TimeUnit.SECONDS));
GrizzlyLDAPConnection connection = (GrizzlyLDAPConnection) factory.getConnection();
try {
SearchRequest request =
diff --git a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java
index 776a00c..984af22 100644
--- a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java
+++ b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java
@@ -307,7 +307,8 @@
try {
// Connect and close.
final Connection connection =
- new LDAPConnectionFactory(listener.getSocketAddress()).getConnection();
+ new LDAPConnectionFactory(listener.getHostName(),
+ listener.getPort()).getConnection();
assertThat(serverConnection.context.get(10, TimeUnit.SECONDS)).isNotNull();
assertThat(serverConnection.isClosed.getCount()).isEqualTo(1);
connection.close();
@@ -336,16 +337,20 @@
try {
// Connection pool and load balancing tests.
+ InetSocketAddress offlineAddress1 = findFreeSocketAddress();
final ConnectionFactory offlineServer1 =
Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
- findFreeSocketAddress()), "offline1");
+ offlineAddress1.getHostName(),
+ offlineAddress1.getPort()), "offline1");
+ InetSocketAddress offlineAddress2 = findFreeSocketAddress();
final ConnectionFactory offlineServer2 =
Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
- findFreeSocketAddress()), "offline2");
+ offlineAddress2.getHostName(),
+ offlineAddress2.getPort()), "offline2");
final ConnectionFactory onlineServer =
Connections.newNamedConnectionFactory(new LDAPConnectionFactory(
- onlineServerListener.getSocketAddress()),
- "online");
+ onlineServerListener.getHostName(),
+ onlineServerListener.getPort()), "online");
// Round robin.
final ConnectionFactory loadBalancer =
@@ -376,7 +381,8 @@
try {
// Connect and close.
final Connection connection =
- new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection();
+ new LDAPConnectionFactory(proxyListener.getHostName(),
+ proxyListener.getPort()).getConnection();
assertThat(proxyServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull();
assertThat(onlineServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull();
@@ -411,15 +417,20 @@
try {
// Connection pool and load balancing tests.
+ InetSocketAddress offlineAddress1 = findFreeSocketAddress();
final ConnectionFactory offlineServer1 =
Connections.newNamedConnectionFactory(
- new LDAPConnectionFactory(findFreeSocketAddress()), "offline1");
+ new LDAPConnectionFactory(offlineAddress1.getHostName(),
+ offlineAddress1.getPort()), "offline1");
+ InetSocketAddress offlineAddress2 = findFreeSocketAddress();
final ConnectionFactory offlineServer2 =
Connections.newNamedConnectionFactory(
- new LDAPConnectionFactory(findFreeSocketAddress()), "offline2");
+ new LDAPConnectionFactory(offlineAddress2.getHostName(),
+ offlineAddress2.getPort()), "offline2");
final ConnectionFactory onlineServer =
Connections.newNamedConnectionFactory(
- new LDAPConnectionFactory(onlineServerListener.getSocketAddress()), "online");
+ new LDAPConnectionFactory(onlineServerListener.getHostName(),
+ onlineServerListener.getPort()), "online");
// Round robin.
final ConnectionFactory loadBalancer =
@@ -462,7 +473,8 @@
try {
// Connect, bind, and close.
final Connection connection =
- new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection();
+ new LDAPConnectionFactory(proxyListener.getHostName(),
+ proxyListener.getPort()).getConnection();
try {
connection.bind("cn=test", "password".toCharArray());
@@ -508,8 +520,10 @@
public ServerConnection<Integer> handleAccept(
final LDAPClientContext clientContext) throws ErrorResultException {
// First attempt offline server.
+ InetSocketAddress offlineAddress = findFreeSocketAddress();
LDAPConnectionFactory lcf =
- new LDAPConnectionFactory(findFreeSocketAddress());
+ new LDAPConnectionFactory(offlineAddress.getHostName(),
+ offlineAddress.getPort());
try {
// This is expected to fail.
lcf.getConnection().close();
@@ -519,8 +533,9 @@
// This is expected - so go to online server.
try {
lcf =
- new LDAPConnectionFactory(onlineServerListener
- .getSocketAddress());
+ new LDAPConnectionFactory(
+ onlineServerListener.getHostName(),
+ onlineServerListener.getPort());
lcf.getConnection().close();
} catch (final Exception e) {
// Unexpected.
@@ -548,7 +563,8 @@
try {
// Connect and close.
final Connection connection =
- new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection();
+ new LDAPConnectionFactory(proxyListener.getHostName(),
+ proxyListener.getPort()).getConnection();
assertThat(proxyServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull();
assertThat(onlineServerConnection.context.get(10, TimeUnit.SECONDS)).isNotNull();
@@ -593,7 +609,9 @@
final ResultHandler<BindResult> resultHandler)
throws UnsupportedOperationException {
// First attempt offline server.
- LDAPConnectionFactory lcf = new LDAPConnectionFactory(findFreeSocketAddress());
+ InetSocketAddress offlineAddress = findFreeSocketAddress();
+ LDAPConnectionFactory lcf = new LDAPConnectionFactory(offlineAddress.getHostName(),
+ offlineAddress.getPort());
try {
// This is expected to fail.
lcf.getConnection().close();
@@ -603,7 +621,8 @@
} catch (final ConnectionException ce) {
// This is expected - so go to online server.
try {
- lcf = new LDAPConnectionFactory(onlineServerListener.getSocketAddress());
+ lcf = new LDAPConnectionFactory(onlineServerListener.getHostName(),
+ onlineServerListener.getPort());
lcf.getConnection().close();
resultHandler.handleResult(Responses.newBindResult(ResultCode.SUCCESS));
} catch (final Exception e) {
@@ -628,7 +647,8 @@
try {
// Connect, bind, and close.
final Connection connection =
- new LDAPConnectionFactory(proxyListener.getSocketAddress()).getConnection();
+ new LDAPConnectionFactory(proxyListener.getHostName(),
+ proxyListener.getPort()).getConnection();
try {
connection.bind("cn=test", "password".toCharArray());
@@ -666,7 +686,7 @@
Connection connection = null;
try {
- connection = new LDAPConnectionFactory(listener.getSocketAddress()).
+ connection = new LDAPConnectionFactory(listener.getHostName(), listener.getPort()).
getConnection();
// Small request
@@ -724,7 +744,7 @@
final Connection connection;
try {
// Connect and bind.
- connection = new LDAPConnectionFactory(listener.getSocketAddress()).getConnection();
+ connection = new LDAPConnectionFactory(listener.getHostName(), listener.getPort()).getConnection();
try {
connection.bind("cn=test", "password".toCharArray());
} catch (final ErrorResultException e) {
@@ -739,7 +759,8 @@
try {
// Connect and bind.
final Connection failedConnection =
- new LDAPConnectionFactory(listener.getSocketAddress()).getConnection();
+ new LDAPConnectionFactory(listener.getHostName(),
+ listener.getPort()).getConnection();
failedConnection.close();
connection.close();
fail("Connection attempt to closed listener succeeded unexpectedly");
--
Gitblit v1.10.0