knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject knox git commit: [KNOX-683] - Test failing due to port conflicts
Date Mon, 07 Mar 2016 18:04:04 GMT
Repository: knox
Updated Branches:
  refs/heads/master 26338adc5 -> 6f7bd2339


[KNOX-683] - Test failing due to port conflicts


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/6f7bd233
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/6f7bd233
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/6f7bd233

Branch: refs/heads/master
Commit: 6f7bd2339250027751f73ceb96a94150551f985b
Parents: 26338ad
Author: Kevin Minder <kminder@apache.org>
Authored: Mon Mar 7 13:03:59 2016 -0500
Committer: Kevin Minder <kminder@apache.org>
Committed: Mon Mar 7 13:03:59 2016 -0500

----------------------------------------------------------------------
 .../security/ldap/SimpleLdapServerTest.java     |  13 +-
 .../gateway/security/ShiroEmbeddedLdapTest.java | 156 -------------------
 .../hadoop/gateway/GatewayTestDriver.java       |   6 +-
 .../hadoop/gateway/SecureClusterTest.java       |  43 +++--
 .../hadoop/gateway/GatewayAdminFuncTest.java    |  12 +-
 .../gateway/GatewayAdminTopologyFuncTest.java   |  18 +--
 .../hadoop/gateway/GatewayAppFuncTest.java      |   8 +-
 .../hadoop/gateway/GatewayBasicFuncTest.java    |   9 +-
 .../hadoop/gateway/GatewayDeployFuncTest.java   |  12 +-
 .../hadoop/gateway/GatewayFuncTestDriver.java   |   4 +-
 .../GatewayLdapDynamicGroupFuncTest.java        |  14 +-
 .../gateway/GatewayLdapGroupFuncTest.java       |  14 +-
 .../gateway/GatewayLdapPosixGroupFuncTest.java  |  14 +-
 .../gateway/GatewayLocalServiceFuncTest.java    |  14 +-
 .../hadoop/gateway/GatewayMultiFuncTest.java    |   7 +-
 .../hadoop/gateway/GatewaySampleFuncTest.java   |  14 +-
 .../hadoop/gateway/GatewaySslFuncTest.java      |   7 +-
 .../apache/hadoop/gateway/Knox242FuncTest.java  |  12 +-
 .../gateway/KnoxCliLdapFuncTestNegative.java    |  16 +-
 .../gateway/KnoxCliLdapFuncTestPositive.java    |  16 +-
 .../hadoop/gateway/KnoxCliSysBindTest.java      |  17 +-
 .../hadoop/gateway/WebHdfsHaFuncTest.java       |   9 +-
 22 files changed, 85 insertions(+), 350 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-demo-ldap/src/test/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapServerTest.java
----------------------------------------------------------------------
diff --git a/gateway-demo-ldap/src/test/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapServerTest.java b/gateway-demo-ldap/src/test/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapServerTest.java
index 75f439e..33a367e 100644
--- a/gateway-demo-ldap/src/test/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapServerTest.java
+++ b/gateway-demo-ldap/src/test/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapServerTest.java
@@ -38,14 +38,16 @@ public class SimpleLdapServerTest {
 
   private static int port;
   private static File ldifFile;
+  private static TcpTransport ldapTransport;
   private static SimpleLdapDirectoryServer ldap;
 
   @BeforeClass
   public static void setup() throws Exception {
-    port = findFreePort();
     ldifFile = new File( ClassLoader.getSystemResource( "users.ldif" ).toURI() );
-    ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", ldifFile, new Transport[]{ new TcpTransport( port ) } );
+    ldapTransport = new TcpTransport( 0 );
+    ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", ldifFile, ldapTransport );
     ldap.start();
+    port = ldapTransport.getAcceptor().getLocalAddress().getPort();
   }
 
   @AfterClass
@@ -55,13 +57,6 @@ public class SimpleLdapServerTest {
     }
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   @Test
   public void testBind() throws LdapException, IOException {
     LdapConnection connection;

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-server/src/test/java/org/apache/hadoop/gateway/security/ShiroEmbeddedLdapTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/security/ShiroEmbeddedLdapTest.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/security/ShiroEmbeddedLdapTest.java
deleted file mode 100644
index aede0ad..0000000
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/security/ShiroEmbeddedLdapTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.gateway.security;
-
-import com.jayway.restassured.RestAssured;
-import org.apache.directory.server.protocol.shared.transport.TcpTransport;
-import org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer;
-import org.apache.hadoop.test.category.ManualTests;
-import org.apache.hadoop.test.category.MediumTests;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.web.env.EnvironmentLoaderListener;
-import org.apache.shiro.web.servlet.ShiroFilter;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.servlet.FilterHolder;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.junit.*;
-import org.junit.experimental.categories.Category;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.*;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.util.EnumSet;
-
-import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.config.ConnectionConfig.connectionConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
-import static org.hamcrest.core.IsEqual.equalTo;
-
-// Derrived from this thread
-// http://shiro-user.582556.n2.nabble.com/Integration-of-Shiro-with-Embedded-Jetty-td7519712.html
-@Category( { ManualTests.class, MediumTests.class } )
-public class ShiroEmbeddedLdapTest {
-
-  private static Logger log = LoggerFactory.getLogger( ShiroEmbeddedLdapTest.class );
-
-  private static SimpleLdapDirectoryServer ldap;
-
-  private Server jetty;
-
-  @BeforeClass
-  public static void setupSuite() throws Exception{
-    RestAssured.config = newConfig().connectionConfig(connectionConfig().closeIdleConnectionsAfterEachResponse());
-    int port = findFreePort();
-    TcpTransport transport = new TcpTransport( port );
-    ldap = new SimpleLdapDirectoryServer(
-        "dc=hadoop,dc=apache,dc=org",
-        new File( ClassLoader.getSystemResource( "users.ldif" ).toURI() ),
-        transport );
-    ldap.start();
-  }
-
-  @AfterClass
-  public static void cleanupSuite() throws Exception {
-    ldap.stop( true );
-  }
-
-  @Before
-  public void setupTest() throws Exception {
-    ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS );
-    context.setContextPath( "/" );
-    context.addEventListener( new EnvironmentLoaderListener() );
-
-    // Add root ShiroFilter, all remaining filters and filter chains are defined in shiro.ini's [urls] section.
-    FilterHolder filterHolder = new FilterHolder( new ShiroFilter() );
-    ServletHolder servletHolder = new ServletHolder( new MockServlet() );
-
-    EnumSet<DispatcherType> types = EnumSet.allOf( DispatcherType.class );
-    context.addFilter( filterHolder, "/*", types );
-    context.addFilter( new FilterHolder( new TestFilter() ), "/*", types );
-    context.addServlet( servletHolder, "/*" );
-
-    jetty = new Server( findFreePort() );
-    jetty.setHandler( context );
-    jetty.start();
-  }
-
-  @After
-  public void cleanupTest() throws Exception {
-    jetty.stop();
-    jetty.join();
-  }
-
-  @Test
-  public void testShiro() throws Exception {
-    String url = "http://localhost:" + jetty.getURI().getPort() + "/";
-
-    given()
-        .expect().statusCode( 401 )
-        .when().get( url );
-
-    given()
-        .auth().basic( "allowedUser", "password" )
-        .expect().body( equalTo( "<html>Hello!</html>" ) )
-        .when().get( url );
-
-    given()
-        .auth().basic( "deniedUser","invalid-password")
-        .expect().statusCode( 401 )
-        .when().get( url );
-
-    given()
-        .auth().basic( "invalidUser", "password" )
-        .expect().statusCode( 401 )
-        .when().get( url );
-
-  }
-
-  private static class TestFilter implements Filter {
-    public void init( FilterConfig filterConfig ) throws ServletException {}
-    public void destroy() {}
-    
-    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException {
-      org.apache.shiro.subject.Subject ss = SecurityUtils.getSubject();
-      log.info( "PRINCIPAL: " + ss.getPrincipal() );
-      chain.doFilter( request, response );
-    }
-  }
-
-  private static class MockServlet extends HttpServlet {
-    @Override
-    protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
-      resp.setContentType( "text/html" );
-      resp.getWriter().write( "<html>Hello!</html>" );
-    }
-  }
-
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java
----------------------------------------------------------------------
diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java
index 95a4964..b8254fc 100644
--- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java
+++ b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestDriver.java
@@ -69,10 +69,10 @@ public class GatewayTestDriver {
    */
   public int setupLdap( int port ) throws Exception {
     URL usersUrl = getResourceUrl("users.ldif");
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    log.info( "LDAP port = " + port );
+    log.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
     return port;
   }
 
@@ -156,7 +156,7 @@ public class GatewayTestDriver {
   }
 
   public String getLdapUrl() {
-    return "ldap://localhost:" + ldapTransport.getPort();
+    return "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort();
   }
 
   public String getClusterUrl() {

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java
----------------------------------------------------------------------
diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java
index 2638b1c..ea39c25 100644
--- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java
+++ b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java
@@ -17,6 +17,12 @@
  */
 package org.apache.hadoop.gateway;
 
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.security.Principal;
+import java.util.Properties;
+
 import com.mycila.xmltool.XMLDoc;
 import com.mycila.xmltool.XMLTag;
 import org.apache.hadoop.fs.Path;
@@ -27,6 +33,7 @@ import org.apache.hadoop.minikdc.MiniKdc;
 import org.apache.hadoop.security.SecurityUtil;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
+import org.apache.hadoop.test.TestUtils;
 import org.apache.hadoop.test.category.ReleaseTest;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
@@ -46,14 +53,23 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.security.Principal;
-import java.util.Properties;
-
-import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_HTTPS_ADDRESS_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_KERBEROS_PRINCIPAL_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_KEYTAB_FILE_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATA_ENCRYPTION_ALGORITHM_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HTTP_POLICY_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNALNODE_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNALNODE_KERBEROS_PRINCIPAL_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNALNODE_KEYTAB_FILE_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_KERBEROS_PRINCIPAL_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_RESOURCE_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -72,7 +88,7 @@ public class SecureClusterTest {
 
   @BeforeClass
   public static void setupSuite() throws Exception {
-    nameNodeHttpPort = findFreePort();
+    nameNodeHttpPort = TestUtils.findFreePort();
     configuration = new HdfsConfiguration();
     baseDir = new File(KeyStoreTestUtil.getClasspathDir(SecureClusterTest.class));
     System.setProperty(MiniDFSCluster.PROP_TEST_BUILD_DATA, baseDir.getAbsolutePath());
@@ -151,7 +167,7 @@ public class SecureClusterTest {
     config.setKerberosConfig(kdc.getKrb5conf().getAbsolutePath());
     config.setKerberosLoginConfig(jaasConf.getAbsolutePath());
     driver.setResourceBase(SecureClusterTest.class);
-    driver.setupLdap(findFreePort());
+    driver.setupLdap(0);
     driver.setupGateway(config, "cluster", createTopology(), true);
   }
 
@@ -281,11 +297,4 @@ public class SecureClusterTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
index 91f2162..6835d3d 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
@@ -88,8 +88,7 @@ public class GatewayAdminFuncTest {
 
   public static void setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
     LOG.info( "LDAP port = " + ldapTransport.getPort() );
@@ -150,7 +149,7 @@ public class GatewayAdminFuncTest {
         .addTag( "value" ).addText( "uid={0},ou=people,dc=hadoop,dc=apache,dc=org" ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.url" )
-        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getPort() ).gotoParent()
+        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort() ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.authenticationMechanism" )
         .addTag( "value" ).addText( "simple" ).gotoParent()
@@ -170,13 +169,6 @@ public class GatewayAdminFuncTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
index e099141..53b1c94 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
@@ -101,11 +101,10 @@ public class GatewayAdminTopologyFuncTest {
 
   public static void setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
   }
 
   public static void setupGateway(GatewayTestConfig testConfig) throws Exception {
@@ -175,7 +174,7 @@ public class GatewayAdminTopologyFuncTest {
         .addTag( "value" ).addText( "uid={0},ou=people,dc=hadoop,dc=apache,dc=org" ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.url" )
-        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getPort() ).gotoParent()
+        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort() ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.authenticationMechanism" )
         .addTag( "value" ).addText( "simple" ).gotoParent()
@@ -218,7 +217,7 @@ public class GatewayAdminTopologyFuncTest {
         .addTag( "value" ).addText( "uid={0},ou=people,dc=hadoop,dc=apache,dc=org" ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.url" )
-        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getPort() ).gotoParent()
+        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort() ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.authenticationMechanism" )
         .addTag( "value" ).addText( "simple" ).gotoParent()
@@ -244,13 +243,6 @@ public class GatewayAdminTopologyFuncTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }
@@ -474,7 +466,7 @@ public class GatewayAdminTopologyFuncTest {
 
     Param ldapURL = new Param();
     ldapURL.setName("main.ldapRealm.contextFactory.url");
-    ldapURL.setValue("ldap://localhost:" + ldapTransport.getPort());
+    ldapURL.setValue("ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort());
 
     Param ldapUserTemplate = new Param();
     ldapUserTemplate.setName("main.ldapRealm.userDnTemplate");

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
index 52f5eed..d599014 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
@@ -112,11 +112,11 @@ public class GatewayAppFuncTest {
 
   public static void setupLdap() throws Exception {
     URL usersUrl = TestUtils.getResourceUrl( DAT, "users.ldif" );
-    ldapPort = TestUtils.findFreePort();
-    ldapTransport = new TcpTransport( ldapPort );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    ldapPort = ldapTransport.getAcceptor().getLocalAddress().getPort();
+    LOG.info( "LDAP port = " + ldapPort );
   }
 
   public static void setupGateway() throws Exception {
@@ -175,7 +175,7 @@ public class GatewayAppFuncTest {
     LOG.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() );
 
     params = new Properties();
-    params.put( "LDAP_URL", "ldap://localhost:" + ldapTransport.getPort() );
+    params.put( "LDAP_URL", "ldap://localhost:" + ldapPort );
     params.put( "WEBHDFS_URL", "http://localhost:" + mockWebHdfs.getPort() );
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index 27e4b72..892c383 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -126,13 +126,6 @@ public class GatewayBasicFuncTest {
 //  private static final boolean USE_MOCK_SERVICES = false;
 //  private static final boolean CLEANUP_TEST = false;
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   /**
    * Creates a deployment of a gateway instance that all test methods will share.  This method also creates a
    * registry of sorts for all of the services that will be used by the test methods.
@@ -148,7 +141,7 @@ public class GatewayBasicFuncTest {
     GatewayTestConfig config = new GatewayTestConfig();
     config.setGatewayPath( "gateway" );
     driver.setResourceBase(GatewayBasicFuncTest.class);
-    driver.setupLdap(findFreePort());
+    driver.setupLdap(0);
     driver.setupService("WEBHDFS", "http://" + TEST_HOST + ":50070/webhdfs", "/cluster/webhdfs", USE_MOCK_SERVICES);
     driver.setupService( "DATANODE", "http://" + TEST_HOST + ":50075/webhdfs", "/cluster/webhdfs/data", USE_MOCK_SERVICES );
     driver.setupService( "WEBHCAT", "http://" + TEST_HOST + ":50111/templeton", "/cluster/templeton", USE_MOCK_SERVICES );

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
index 534f3b0..7d6ecce 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayDeployFuncTest.java
@@ -99,8 +99,7 @@ public class GatewayDeployFuncTest {
 
   public static void setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
     LOG.info( "LDAP port = " + ldapTransport.getPort() );
@@ -165,7 +164,7 @@ public class GatewayDeployFuncTest {
         .addTag( "value" ).addText( "uid={0},ou=people,dc=hadoop,dc=apache,dc=org" ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.url" )
-        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getPort() ).gotoParent()
+        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort() ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.authenticationMechanism" )
         .addTag( "value" ).addText( "simple" ).gotoParent()
@@ -184,13 +183,6 @@ public class GatewayDeployFuncTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
index 81c45e1..c06e602 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
@@ -109,7 +109,7 @@ public class GatewayFuncTestDriver {
     ldapTransport = new TcpTransport( port );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    log.info( "LDAP port = " + port );
+    log.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
     return port;
   }
 
@@ -256,7 +256,7 @@ public class GatewayFuncTestDriver {
   }
 
   public String getLdapUrl() {
-    return "ldap://localhost:" + ldapTransport.getPort();
+    return "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort();
   }
 
   private static class Service {

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
index b94cb34..5c5a27f 100755
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
@@ -107,12 +107,11 @@ public class GatewayLdapDynamicGroupFuncTest {
 
   public static int setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
-    return port;
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
+    return ldapTransport.getAcceptor().getLocalAddress().getPort();
   }
 
   public static void setupGateway(int ldapPort) throws IOException, Exception {
@@ -266,13 +265,6 @@ public class GatewayLdapDynamicGroupFuncTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
index c9cecab..9780198 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
@@ -107,12 +107,11 @@ public class GatewayLdapGroupFuncTest {
 
   public static int setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
-    return port;
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
+    return ldapTransport.getAcceptor().getLocalAddress().getPort();
   }
 
   public static void setupGateway(int ldapPort) throws Exception {
@@ -265,13 +264,6 @@ public class GatewayLdapGroupFuncTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapPosixGroupFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapPosixGroupFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapPosixGroupFuncTest.java
index 6698888..6278c53 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapPosixGroupFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapPosixGroupFuncTest.java
@@ -107,12 +107,11 @@ public class GatewayLdapPosixGroupFuncTest {
 
   public static int setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
-    return port;
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
+    return ldapTransport.getAcceptor().getLocalAddress().getPort();
   }
 
   public static void setupGateway(int ldapPort) throws Exception {
@@ -243,13 +242,6 @@ public class GatewayLdapPosixGroupFuncTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java
index aa93422..f9ca534 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java
@@ -92,11 +92,10 @@ public class GatewayLocalServiceFuncTest {
 
   public static void setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
   }
 
   public static void setupGateway() throws Exception {
@@ -154,7 +153,7 @@ public class GatewayLocalServiceFuncTest {
         .addTag( "value" ).addText( "uid={0},ou=people,dc=hadoop,dc=apache,dc=org" ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.url" )
-        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getPort() ).gotoParent()
+        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort() ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.authenticationMechanism" )
         .addTag( "value" ).addText( "simple" ).gotoParent()
@@ -197,13 +196,6 @@ public class GatewayLocalServiceFuncTest {
     LOG_EXIT();
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
index 47fe9bd..54390f4 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayMultiFuncTest.java
@@ -106,11 +106,10 @@ public class GatewayMultiFuncTest {
 
   public static void setupLdap() throws Exception {
     URL usersUrl = TestUtils.getResourceUrl( DAT, "users.ldif" );
-    ldapPort = TestUtils.findFreePort();
-    ldapTransport = new TcpTransport( ldapPort );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
   }
 
   public static void setupGateway() throws Exception {
@@ -168,7 +167,7 @@ public class GatewayMultiFuncTest {
     LOG.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() );
 
     params = new Properties();
-    params.put( "LDAP_URL", "ldap://localhost:" + ldapTransport.getPort() );
+    params.put( "LDAP_URL", "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort() );
     params.put( "WEBHDFS_URL", "http://localhost:" + mockWebHdfs.getPort() );
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
index 2d63b5d..4cad0cb 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
@@ -95,11 +95,10 @@ public class GatewaySampleFuncTest {
 
   public static void setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
   }
 
   public static void setupGateway() throws Exception {
@@ -158,7 +157,7 @@ public class GatewaySampleFuncTest {
         .addTag( "value" ).addText( "uid={0},ou=people,dc=hadoop,dc=apache,dc=org" ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.url" )
-        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getPort() ).gotoParent()
+        .addTag( "value" ).addText( "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort() ).gotoParent()
         .addTag( "param" )
         .addTag( "name" ).addText( "main.ldapRealm.contextFactory.authenticationMechanism" )
         .addTag( "value" ).addText( "simple" ).gotoParent()
@@ -178,13 +177,6 @@ public class GatewaySampleFuncTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
index b419231..3b8eba7 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySslFuncTest.java
@@ -136,11 +136,10 @@ public class GatewaySslFuncTest {
 
   public static void setupLdap() throws Exception {
     URL usersUrl = TestUtils.getResourceUrl( DAT, "users.ldif" );
-    ldapPort = TestUtils.findFreePort();
-    ldapTransport = new TcpTransport( ldapPort );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
   }
 
   public static void setupGateway() throws Exception {
@@ -203,7 +202,7 @@ public class GatewaySslFuncTest {
     LOG.info( "Gateway port = " + gateway.getAddresses()[ 0 ].getPort() );
 
     params = new Properties();
-    params.put( "LDAP_URL", "ldap://localhost:" + ldapTransport.getPort() );
+    params.put( "LDAP_URL", "ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort() );
     params.put( "WEBHDFS_URL", "http://localhost:" + mockWebHdfs.getPort() );
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/Knox242FuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/Knox242FuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/Knox242FuncTest.java
index feeb08f..88f02b9 100755
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/Knox242FuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/Knox242FuncTest.java
@@ -108,12 +108,11 @@ public class Knox242FuncTest {
 
   public static int setupLdap() throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
     LOG.info( "LDAP port = " + ldapTransport.getPort() );
-    return port;
+    return ldapTransport.getAcceptor().getLocalAddress().getPort();
   }
 
   public static void setupGateway(int ldapPort) throws IOException, Exception {
@@ -259,13 +258,6 @@ public class Knox242FuncTest {
     return xml;
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestNegative.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestNegative.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestNegative.java
index 0872428..ade2b5a 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestNegative.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestNegative.java
@@ -96,11 +96,10 @@ public class KnoxCliLdapFuncTestNegative {
 
   public static void setupLdap( ) throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
   }
 
   public static void setupGateway() throws Exception {
@@ -151,13 +150,6 @@ public class KnoxCliLdapFuncTestNegative {
 
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }
@@ -192,7 +184,7 @@ public class KnoxCliLdapFuncTestNegative {
         .addTag("value").addText("uid={0},ou=people,dc=hadoop,dc=apache,dc=org").gotoParent()
         .addTag("param")
         .addTag( "name" ).addText("main.ldapRealm.contextFactory.url")
-        .addTag("value").addText("ldap://localhost:" + ldapTransport.getPort()).gotoParent()
+        .addTag("value").addText("ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()).gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.systemUsername")
         .addTag("value").addText("uid=guest,ou=people,dc=hadoop,dc=apache,dc=org").gotoParent()
@@ -259,7 +251,7 @@ public class KnoxCliLdapFuncTestNegative {
         .addTag("value").addText("uid={0},ou=people,dc=hadoop,dc=apache,dc=org").gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.url")
-        .addTag("value").addText("ldap://localhost:" + ldapTransport.getPort()).gotoParent()
+        .addTag("value").addText("ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()).gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.authenticationMechanism")
         .addTag("value").addText("simple").gotoParent()

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestPositive.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestPositive.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestPositive.java
index 5aad293..e49c5a3 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestPositive.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliLdapFuncTestPositive.java
@@ -94,11 +94,10 @@ public class KnoxCliLdapFuncTestPositive {
 
   public static void setupLdap( ) throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
   }
 
   public static void setupGateway() throws Exception {
@@ -149,13 +148,6 @@ public class KnoxCliLdapFuncTestPositive {
 
   }
 
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }
@@ -190,7 +182,7 @@ public class KnoxCliLdapFuncTestPositive {
         .addTag("value").addText("uid={0},ou=people,dc=hadoop,dc=apache,dc=org").gotoParent()
         .addTag( "param" )
         .addTag("name").addText("main.ldapRealm.contextFactory.url")
-        .addTag("value").addText("ldap://localhost:" + ldapTransport.getPort()).gotoParent()
+        .addTag("value").addText("ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()).gotoParent()
         .addTag( "param" )
         .addTag("name").addText("main.ldapRealm.contextFactory.authenticationMechanism")
         .addTag("value").addText("simple").gotoParent()
@@ -253,7 +245,7 @@ public class KnoxCliLdapFuncTestPositive {
         .addTag("value").addText("uid={0},ou=people,dc=hadoop,dc=apache,dc=org").gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.url")
-        .addTag("value").addText("ldap://localhost:" + ldapTransport.getPort()).gotoParent()
+        .addTag("value").addText("ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()).gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.authenticationMechanism")
         .addTag("value").addText("simple").gotoParent()

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliSysBindTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliSysBindTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliSysBindTest.java
index 3bb2ef3..afa309d 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliSysBindTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/KnoxCliSysBindTest.java
@@ -93,11 +93,10 @@ public class KnoxCliSysBindTest {
 
   public static void setupLdap( ) throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
-    int port = findFreePort();
-    ldapTransport = new TcpTransport( port );
+    ldapTransport = new TcpTransport( 0 );
     ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", new File( usersUrl.toURI() ), ldapTransport );
     ldap.start();
-    LOG.info( "LDAP port = " + ldapTransport.getPort() );
+    LOG.info( "LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort() );
   }
 
   public static void setupGateway() throws Exception {
@@ -153,14 +152,6 @@ public class KnoxCliSysBindTest {
 
   }
 
-
-  private static int findFreePort() throws IOException {
-    ServerSocket socket = new ServerSocket(0);
-    int port = socket.getLocalPort();
-    socket.close();
-    return port;
-  }
-
   public static InputStream getResourceStream( String resource ) throws IOException {
     return getResourceUrl( resource ).openStream();
   }
@@ -195,7 +186,7 @@ public class KnoxCliSysBindTest {
         .addTag("value").addText("uid={0},ou=people,dc=hadoop,dc=apache,dc=org").gotoParent()
         .addTag( "param" )
         .addTag("name").addText("main.ldapRealm.contextFactory.url")
-        .addTag("value").addText("ldap://localhost:" + ldapTransport.getPort()).gotoParent()
+        .addTag("value").addText("ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()).gotoParent()
         .addTag( "param" )
         .addTag("name").addText("main.ldapRealm.contextFactory.authenticationMechanism")
         .addTag("value").addText("simple").gotoParent()
@@ -258,7 +249,7 @@ public class KnoxCliSysBindTest {
         .addTag("value").addText("uid={0},ou=people,dc=hadoop,dc=apache,dc=org").gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.url")
-        .addTag("value").addText("ldap://localhost:" + ldapTransport.getPort()).gotoParent()
+        .addTag("value").addText("ldap://localhost:" + ldapTransport.getAcceptor().getLocalAddress().getPort()).gotoParent()
         .addTag("param")
         .addTag("name").addText("main.ldapRealm.contextFactory.authenticationMechanism")
         .addTag("value").addText("simple").gotoParent()

http://git-wip-us.apache.org/repos/asf/knox/blob/6f7bd233/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java
index 33290e7..da6bbc4 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java
@@ -56,13 +56,6 @@ public class WebHdfsHaFuncTest {
 
    private static MockServer standbyServer;
 
-   private static int findFreePort() throws IOException {
-      ServerSocket socket = new ServerSocket(0);
-      int port = socket.getLocalPort();
-      socket.close();
-      return port;
-   }
-
    /**
     * Creates a deployment of a gateway instance that all test methods will share.  This method also creates a
     * registry of sorts for all of the services that will be used by the test methods.
@@ -83,7 +76,7 @@ public class WebHdfsHaFuncTest {
       GatewayTestConfig config = new GatewayTestConfig();
       config.setGatewayPath("gateway");
       driver.setResourceBase(WebHdfsHaFuncTest.class);
-      driver.setupLdap(findFreePort());
+      driver.setupLdap(0);
       driver.setupService("WEBHDFS", "http://vm.local:50070/webhdfs", "/cluster/webhdfs", USE_MOCK_SERVICES);
       driver.setupGateway(config, "cluster", createTopology(), USE_GATEWAY);
       LOG_EXIT();


Mime
View raw message