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

Matthew Swift
13.33.2012 7282c7f762540fe097290a2a82b72d23284968e3
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
@@ -31,6 +31,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.SocketAddress;
/**
 * This class defines some utility functions which can be used by test cases.
@@ -101,6 +102,24 @@
    }
    /**
     * Finds a free server socket port on the local host.
     *
     * @return The free port.
     */
    public static SocketAddress findFreeSocketAddress() {
        try {
            ServerSocket serverLdapSocket = new ServerSocket();
            serverLdapSocket.setReuseAddress(true);
            serverLdapSocket.bind(new InetSocketAddress("127.0.0.1", 0));
            final SocketAddress address = serverLdapSocket.getLocalSocketAddress();
            serverLdapSocket.close();
            return address;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * Returns an internal client connection to the running ldap server.
     *
     * @return The internal client connection.