diff options
author | shuifeng lu <lushuifeng@gmail.com> | 2018-10-31 19:54:52 +0800 |
---|---|---|
committer | Timothy Farkas <timothyfarkas@apache.org> | 2018-11-09 19:55:39 -0800 |
commit | 9eba276845a8f9c6edba628bd6a59207cd41c64e (patch) | |
tree | 90ac6c07321b55a006353d1dfaab392b19337f45 /exec/java-exec/src/test/java/org/apache/drill/exec/util | |
parent | f2fd822afd8acc5aaa99dd37fb2f798bbec54a00 (diff) |
DRILL-6760: Retain original exception in Verbose Error Message
closes #1519
Diffstat (limited to 'exec/java-exec/src/test/java/org/apache/drill/exec/util')
-rw-r--r-- | exec/java-exec/src/test/java/org/apache/drill/exec/util/DrillExceptionUtilTest.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/util/DrillExceptionUtilTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/util/DrillExceptionUtilTest.java new file mode 100644 index 000000000..a2cb29aea --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/util/DrillExceptionUtilTest.java @@ -0,0 +1,53 @@ +/* + * 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.drill.exec.util; + +import org.apache.drill.common.exceptions.DrillIOException; +import org.apache.drill.common.exceptions.DrillRuntimeException; +import org.apache.drill.common.exceptions.ErrorHelper; +import org.apache.drill.common.util.DrillExceptionUtil; +import org.apache.drill.exec.proto.UserBitShared; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class DrillExceptionUtilTest { + private static final String ERROR_MESSAGE = "Exception Test"; + private static final String NESTED_ERROR_MESSAGE = "Nested Exception"; + + @Test + public void testUnwrapException() { + Throwable rootThrowable = new DrillRuntimeException(ERROR_MESSAGE); + UserBitShared.ExceptionWrapper exceptionWrapper = ErrorHelper.getWrapper(rootThrowable); + Throwable t = DrillExceptionUtil.getThrowable(exceptionWrapper); + assertEquals("Exception class should match", rootThrowable.getClass(), t.getClass()); + assertEquals("Exception message should match", rootThrowable.getMessage(), t.getMessage()); + } + + @Test + public void testUnwrapNestedException() { + Throwable nested = new DrillIOException(NESTED_ERROR_MESSAGE); + Throwable rootThrowable = new Error(ERROR_MESSAGE, nested); + UserBitShared.ExceptionWrapper exceptionWrapper = ErrorHelper.getWrapper(rootThrowable); + Throwable t = DrillExceptionUtil.getThrowable(exceptionWrapper); + assertEquals("Exception class should match", rootThrowable.getClass(), t.getClass()); + assertEquals("Exception message should match", rootThrowable.getMessage(), t.getMessage()); + assertEquals("Exception cause class should match", rootThrowable.getCause().getClass(), t.getCause().getClass()); + assertEquals("Exception cause message should match", rootThrowable.getCause().getMessage(), t.getCause().getMessage()); + } +} |