asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mb...@apache.org
Subject asterixdb git commit: Suppress stacktraces on expected exceptions
Date Sat, 10 Jun 2017 02:18:54 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master b88c4ba75 -> cb0c265fc


Suppress stacktraces on expected exceptions

Change-Id: Ifce33d34d7ef3551613a67fdbfe45b143c46be86
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1823
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>


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

Branch: refs/heads/master
Commit: cb0c265fcc3e8c0a2741e35be36dee5998677a1c
Parents: b88c4ba
Author: Michael Blow <mblow@apache.org>
Authored: Fri Jun 9 14:24:03 2017 -0400
Committer: Michael Blow <mblow@apache.org>
Committed: Fri Jun 9 19:18:31 2017 -0700

----------------------------------------------------------------------
 .../asterix/test/common/TestExecutor.java       | 44 ++++++++++++++++----
 1 file changed, 35 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/cb0c265f/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
index 55c98d1..c8c8aec 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.lang.reflect.InvocationTargetException;
@@ -453,27 +454,52 @@ public class TestExecutor {
             throws Exception {
         if (!responseCodeValidator.test(httpResponse.getStatusLine().getStatusCode())) {
             String errorBody = EntityUtils.toString(httpResponse.getEntity());
-            String exceptionMsg;
+            String[] errors;
             try {
                 // First try to parse the response for a JSON error response.
                 ObjectMapper om = new ObjectMapper();
                 JsonNode result = om.readTree(errorBody);
-                String[] errors = { result.get("error-code").asText(), result.get("summary").asText(),
+                errors = new String[] { result.get("error-code").get(1).asText(), result.get("summary").asText(),
                         result.get("stacktrace").asText() };
-                GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, errors[2]);
-                exceptionMsg = "HTTP operation failed: " + errors[0] + "\nSTATUS LINE: "
+ httpResponse.getStatusLine()
-                        + "\nSUMMARY: " + errors[1] + "\nSTACKTRACE: " + errors[2];
             } catch (Exception e) {
                 // whoops, not JSON (e.g. 404) - just include the body
                 GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, errorBody);
-                exceptionMsg = "HTTP operation failed:" + "\nSTATUS LINE: " + httpResponse.getStatusLine()
-                        + "\nERROR_BODY: " + errorBody;
+                throw new Exception("HTTP operation failed:" + "\nSTATUS LINE: " + httpResponse.getStatusLine()
+                        + "\nERROR_BODY: " + errorBody, e);
             }
-            throw new Exception(exceptionMsg);
+            throw new ParsedException("HTTP operation failed: " + errors[0] + "\nSTATUS LINE:
"
+                    + httpResponse.getStatusLine() + "\nSUMMARY: " + errors[2].split("\n")[0],
errors[2]);
         }
         return httpResponse;
     }
 
+    static class ParsedException extends Exception {
+
+        private final String savedStack;
+
+        ParsedException(String message, String stackTrace) {
+            super(message);
+            savedStack = stackTrace;
+        }
+
+        @Override
+        public String toString() {
+            return getMessage();
+        }
+
+        @Override
+        public void printStackTrace(PrintStream s) {
+            super.printStackTrace(s);
+            s.println("Caused by: " + savedStack);
+        }
+
+        @Override
+        public void printStackTrace(PrintWriter s) {
+            super.printStackTrace(s);
+            s.println("Caused by: " + savedStack);
+        }
+    }
+
     public InputStream executeQuery(String str, OutputFormat fmt, URI uri, List<CompilationUnit.Parameter>
params)
             throws Exception {
         HttpUriRequest method = constructHttpMethod(str, uri, "query", false, params);
@@ -1260,7 +1286,7 @@ public class TestExecutor {
                         if (failedGroup != null) {
                             failedGroup.getTestCase().add(testCaseCtx.getTestCase());
                         }
-                        throw new Exception("Test \"" + testFile + "\" FAILED!", e);
+                        throw new Exception("Test \"" + testFile + "\" FAILED!");
                     }
                 } finally {
                     if (numOfFiles == testFileCtxs.size()) {


Mime
View raw message