You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by zb...@apache.org on 2015/08/26 16:48:40 UTC
knox git commit: KNOX-584 Fix for UT instability in
GatewayBasicFuncTest.testCLIServiceTest
Repository: knox
Updated Branches:
refs/heads/master 55f9405c4 -> 2fc2220f5
KNOX-584 Fix for UT instability in GatewayBasicFuncTest.testCLIServiceTest
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/2fc2220f
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/2fc2220f
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/2fc2220f
Branch: refs/heads/master
Commit: 2fc2220f558df0b67a11e0a86558b7cd894f1084
Parents: 55f9405
Author: zblanco <zb...@apache.org>
Authored: Wed Aug 26 10:48:33 2015 -0400
Committer: zblanco <zb...@apache.org>
Committed: Wed Aug 26 10:48:33 2015 -0400
----------------------------------------------------------------------
.../org/apache/hadoop/gateway/util/KnoxCLI.java | 75 ++++++++++----------
.../hadoop/gateway/GatewayBasicFuncTest.java | 6 +-
2 files changed, 43 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/2fc2220f/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
index 246c123..82618be 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
@@ -1480,8 +1480,8 @@ public class KnoxCLI extends Configured implements Tool {
attempts++;
SSLContext ctx = null;
CloseableHttpClient client;
- String http = "https://";
- String https = "http://";
+ String http = "http://";
+ String https = "https://";
GatewayConfig conf = getGatewayConfig();
String gatewayPort;
String host;
@@ -1499,7 +1499,7 @@ public class KnoxCLI extends Configured implements Tool {
try {
host = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
- out.println(e.getMessage());
+ out.println(e.toString());
out.println("Defaulting address to localhost. Use --hostname option to specify a different hostname");
host = "localhost";
}
@@ -1532,7 +1532,7 @@ public class KnoxCLI extends Configured implements Tool {
try {
ctx = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
} catch (Exception e) {
- out.println(e.getMessage());
+ out.println(e.toString());
}
// Initialize the HTTP client
@@ -1542,21 +1542,20 @@ public class KnoxCLI extends Configured implements Tool {
client = HttpClients.custom().setSslcontext(ctx).build();
}
- HttpGet request = new HttpGet(httpsServiceTestURL);
+ HttpGet request;
+ if(ssl) {
+ request = new HttpGet(httpsServiceTestURL);
+ } else {
+ request = new HttpGet(httpServiceTestURL);
+ }
+
+
request.setHeader("Authorization", authString);
request.setHeader("Accept", MediaType.APPLICATION_JSON.getMediaType());
try {
+ out.println(request.toString());
CloseableHttpResponse response = client.execute(request);
-// Fallback to http in case Http in case https doesn't work.
- if(response.getStatusLine().getStatusCode() != 200) {
- request = new HttpGet(httpServiceTestURL);
- response = client.execute(request);
- }
-
- response.close();
- request.releaseConnection();
-
switch (response.getStatusLine().getStatusCode()) {
case 200:
@@ -1575,33 +1574,22 @@ public class KnoxCLI extends Configured implements Tool {
out.println(response.getStatusLine().toString());
response.getEntity().writeTo(out);
break;
-
-
}
+ response.close();
+ request.releaseConnection();
} catch (ClientProtocolException e) {
- out.println(e.getMessage());
+ out.println(e.toString());
if (debug) {
e.printStackTrace(out);
}
} catch (SSLException e) {
- out.println(e.getMessage());
-
- if(attempts < 2) {
- if(ssl) {
- ssl = false;
- out.println("Attempting request without SSL.");
- } else {
- ssl = true;
- out.println("Attempting request with SSL ");
- }
- execute();
- } else {
- out.println("Unable to successfully make request. Try using the API with cURL.");
- }
+ out.println(e.toString());
+ retryRequest();
} catch (IOException e) {
- out.println(e.getMessage());
+ out.println(e.toString());
+ retryRequest();
if(debug) {
e.printStackTrace(out);
}
@@ -1609,12 +1597,27 @@ public class KnoxCLI extends Configured implements Tool {
try {
client.close();
} catch (IOException e) {
- out.println(e.getMessage());
+ out.println(e.toString());
}
}
}
+ public void retryRequest(){
+ if(attempts < 2) {
+ if(ssl) {
+ ssl = false;
+ out.println("Attempting request without SSL.");
+ } else {
+ ssl = true;
+ out.println("Attempting request with SSL ");
+ }
+ execute();
+ } else {
+ out.println("Unable to successfully make request. Try using the API with cURL.");
+ }
+ }
+
}
private static Properties loadBuildProperties() {
@@ -1632,9 +1635,9 @@ public class KnoxCLI extends Configured implements Tool {
}
/**
- * @param args
- * @throws Exception
- */
+ * @param args
+ * @throws Exception
+ */
public static void main(String[] args) throws Exception {
PropertyConfigurator.configure( System.getProperty( "log4j.configuration" ) );
int res = ToolRunner.run(new GatewayConfigImpl(), new KnoxCLI(), args);
http://git-wip-us.apache.org/repos/asf/knox/blob/2fc2220f/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 51add41..74d7885 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
@@ -3553,11 +3553,13 @@ public class GatewayBasicFuncTest {
String args3[] = {"service-test", "--master", "knox", "--cluster", driver.clusterName, "--hostname", "bad-host",
- "--port", "0" };
+ "--port", "0", "--u", "guest", "--p", "guest-password" };
cli = new KnoxCLI();
cli.run(args3);
- assertThat(outContent.toString(), containsString("nodename nor servname provided"));
+ assertThat(outContent.toString().toLowerCase(),
+ either(containsString("nodename nor servname provided")).or(containsString("name or service not known"))
+ .or(containsString("//bad-host:0/")));
outContent.reset();
String args4[] = {"service-test", "--master", "knox", "--cluster", driver.clusterName, "--hostname", gatewayAddress.getHostName(),