You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by km...@apache.org on 2014/11/04 00:14:29 UTC

git commit: KNOX-467: Unit tests failing on windows

Repository: knox
Updated Branches:
  refs/heads/master 0edaec6e3 -> 4c7ddb58f


KNOX-467: Unit tests failing on windows


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

Branch: refs/heads/master
Commit: 4c7ddb58ff4d9f655e3e7f919a6ac8d91bdcbb06
Parents: 0edaec6
Author: Kevin Minder <ke...@hortonworks.com>
Authored: Mon Nov 3 18:14:17 2014 -0500
Committer: Kevin Minder <ke...@hortonworks.com>
Committed: Mon Nov 3 18:14:17 2014 -0500

----------------------------------------------------------------------
 .../hadoop/gateway/GatewayBasicFuncTest.java    | 29 ++++++++++++++++----
 .../hadoop/gateway/GatewayFuncTestDriver.java   | 17 ++++++++++--
 2 files changed, 38 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/4c7ddb58/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 c639a43..830bcad 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
@@ -54,6 +54,7 @@ import java.io.FileFilter;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.URI;
@@ -63,9 +64,9 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import static com.jayway.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.anyOf;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -287,6 +288,8 @@ public class GatewayBasicFuncTest {
     String username = "hdfs";
     String password = "hdfs-password";
     InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
+    String forwardHostName = gatewayAddress.getHostName();
+    String reverseHostName = InetAddress.getByName( forwardHostName ).getHostName();
 
     driver.getMock( "WEBHDFS" )
         .expect()
@@ -311,7 +314,9 @@ public class GatewayBasicFuncTest {
     //System.out.println( location );
     log.debug( "Redirect location: " + response.getHeader( "Location" ) );
     if( driver.isUseGateway() ) {
-      MatcherAssert.assertThat( location, startsWith( "http://" + gatewayAddress.getHostName() + ":" + gatewayAddress.getPort() + "/" ) );
+      MatcherAssert.assertThat( location, anyOf(
+          startsWith( "http://" + forwardHostName + ":" + gatewayAddress.getPort() + "/" ),
+          startsWith( "http://" + reverseHostName + ":" + gatewayAddress.getPort() + "/" ) ) );
       MatcherAssert.assertThat( location, containsString( "?_=" ) );
     }
     MatcherAssert.assertThat( location, not( containsString( "host=" ) ) );
@@ -381,6 +386,9 @@ public class GatewayBasicFuncTest {
     String password = "hdfs-password";
     InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
 
+    String forwardHostName = gatewayAddress.getHostName();
+    String reverseHostName = InetAddress.getByName( forwardHostName ).getHostName();
+
     // Attempt to delete the test directory in case a previous run failed.
     // Ignore any result.
     // Cleanup anything that might have been leftover because the test failed previously.
@@ -547,8 +555,9 @@ public class GatewayBasicFuncTest {
     String location = response.getHeader( "Location" );
     log.debug( "Redirect location: " + response.getHeader( "Location" ) );
     if( driver.isUseGateway() ) {
-      MatcherAssert.assertThat( location, startsWith( "http://" + gatewayAddress.getHostName() + ":" + gatewayAddress.getPort() + "/" ) );
-      MatcherAssert.assertThat( location, startsWith( "http://" + gatewayAddress.getHostName() + ":" + gatewayAddress.getPort() + "/" ) );
+      MatcherAssert.assertThat( location, anyOf(
+          startsWith( "http://" + forwardHostName + ":" + gatewayAddress.getPort() + "/" ),
+          startsWith( "http://" + reverseHostName + ":" + gatewayAddress.getPort() + "/" ) ) );
       MatcherAssert.assertThat( location, containsString( "?_=" ) );
     }
     MatcherAssert.assertThat( location, not( containsString( "host=" ) ) );
@@ -566,7 +575,9 @@ public class GatewayBasicFuncTest {
     location = response.getHeader( "Location" );
     log.debug( "Created location: " + location );
     if( driver.isUseGateway() ) {
-      MatcherAssert.assertThat( location, startsWith( "http://" + gatewayAddress.getHostName() + ":" + gatewayAddress.getPort() + "/" ) );
+      MatcherAssert.assertThat( location, anyOf(
+          startsWith( "http://" + forwardHostName + ":" + gatewayAddress.getPort() + "/" ),
+          startsWith( "http://" + reverseHostName + ":" + gatewayAddress.getPort() + "/" ) ) );
     }
     driver.assertComplete();
 
@@ -2251,7 +2262,13 @@ public class GatewayBasicFuncTest {
         .statusCode( HttpStatus.SC_OK )
         .contentType( contentType );
     if ( running ) {
-      response.content( "app.trackingUrl", startsWith( "http://" + gatewayAddress.getHostName() + ":" + gatewayAddress.getPort() + "/" ) );
+      String forwardHostName = gatewayAddress.getHostName();
+      String reverseHostName = InetAddress.getByName( forwardHostName ).getHostName();
+      response.content(
+          "app.trackingUrl",
+          anyOf(
+              startsWith( "http://" + forwardHostName + ":" + gatewayAddress.getPort() + "/" ),
+              startsWith( "http://" + reverseHostName + ":" + gatewayAddress.getPort() + "/" ) ) );
     } else {
       response.content( "app.trackingUrl", isEmptyString() );
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/4c7ddb58/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 6453c49..1874b5a 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
@@ -53,9 +53,11 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.InetAddress;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.net.UnknownHostException;
 import java.nio.charset.Charset;
 import java.util.HashMap;
 import java.util.Map;
@@ -194,13 +196,24 @@ public class GatewayFuncTestDriver {
     return getUrl( serviceRole, false );
   }
 
+  private String getLocalHostName() {
+    String hostName = "localhost";
+    try {
+      hostName = InetAddress.getByName( "127.0.0.1" ).getHostName();
+    } catch( UnknownHostException e ) {
+      // Ignore and use the default.
+    }
+    return hostName;
+  }
+
   public String getUrl( String serviceRole, boolean real ) {
     String url;
+    String localHostName = getLocalHostName();
     Service service = services.get( serviceRole );
     if( useGateway && !real ) {
-      url = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath() + service.gatewayPath;
+      url = "http://" + localHostName + ":" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath() + service.gatewayPath;
     } else if( service.mock ) {
-      url = "http://localhost:" + service.server.getPort();
+      url = "http://" + localHostName + ":" + service.server.getPort();
     } else {
       url = service.realUrl.toASCIIString();
     }