| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.sdk; |
| | |
| | | |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.ServerSocket; |
| | | |
| | | |
| | | |
| | |
| | | public static final String PROPERTY_LDAP_PORT = "org.opends.server.LdapPort"; |
| | | |
| | | /** |
| | | * Port number that's used by the server. Need to be used by the testcases to |
| | | * Port number that's used by the server. Need to be used by the test cases to |
| | | * create connections. |
| | | */ |
| | | public static int port = 11389; |
| | | public static int port; |
| | | |
| | | static |
| | | { |
| | |
| | | { |
| | | port = Integer.valueOf(ldapPort); |
| | | } |
| | | else |
| | | { |
| | | port = findFreePort(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * Creates a temporary text file with the specified contents. It will be |
| | | * marked for automatic deletion when the JVM exits. |
| | | * |
| | | * @param lines |
| | | * The file contents. |
| | | * @return The absolute path to the file that was created. |
| | | * @throws Exception |
| | | * If an unexpected problem occurs. |
| | |
| | | |
| | | |
| | | /** |
| | | * Finds a free server socket port on the local host. |
| | | * |
| | | * @return The free port. |
| | | */ |
| | | public static int findFreePort() |
| | | { |
| | | int port; |
| | | try |
| | | { |
| | | ServerSocket serverLdapSocket = new ServerSocket(); |
| | | serverLdapSocket.setReuseAddress(true); |
| | | serverLdapSocket.bind(new InetSocketAddress("127.0.0.1", 0)); |
| | | port = serverLdapSocket.getLocalPort(); |
| | | serverLdapSocket.close(); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return port; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns an internal client connection to the running ldap server. |
| | | * |
| | | * @return The internal client connection. |
| | |
| | | * Starts the test ldap server. |
| | | * |
| | | * @throws Exception |
| | | * If an error occurs when starting the server. |
| | | */ |
| | | public static void startServer() throws Exception |
| | | { |
| | | // TODO:Try a couple of random ports before throwing exception. |
| | | LDAPServer.getInstance().start(port); |
| | | } |
| | | |