asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Blow (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Suppress stacktraces on expected exceptions
Date Fri, 09 Jun 2017 18:24:23 GMT
Michael Blow has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1823

Change subject: Suppress stacktraces on expected exceptions
......................................................................

Suppress stacktraces on expected exceptions

Change-Id: Ifce33d34d7ef3551613a67fdbfe45b143c46be86
---
M asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
1 file changed, 37 insertions(+), 11 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/23/1823/1

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..7570672 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.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;
@@ -91,8 +92,8 @@
 public class TestExecutor {
 
     /*
-     * Static variables
-     */
+         * Static variables
+         */
     protected static final Logger LOGGER = Logger.getLogger(TestExecutor.class.getName());
     // see
     // https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers/417184
@@ -453,25 +454,50 @@
             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)
@@ -1260,7 +1286,7 @@
                         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()) {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1823
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifce33d34d7ef3551613a67fdbfe45b143c46be86
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mblow@apache.org>

Mime
View raw message