Repository: calcite Updated Branches: refs/heads/master f22ecfa54 -> d1c72b80c
[CALCITE-962] Propagate the cause, not just the cause's message, from JdbcMeta Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/d1c72b80 Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/d1c72b80 Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/d1c72b80 Branch: refs/heads/master Commit: d1c72b80c67814f670a3d87580f44f913c4eb0e5 Parents: f22ecfa Author: Josh Elser <[email protected]> Authored: Wed Nov 11 14:48:52 2015 -0500 Committer: Josh Elser <[email protected]> Committed: Wed Nov 11 18:25:07 2015 -0500 ---------------------------------------------------------------------- .../apache/calcite/avatica/jdbc/JdbcMeta.java | 4 +- .../calcite/avatica/RemoteDriverTest.java | 3 +- .../calcite/avatica/jdbc/JdbcMetaTest.java | 44 ++++++++++++++++++++ .../calcite/avatica/remote/RemoteMetaTest.java | 12 ++++-- .../calcite/avatica/remote/AbstractHandler.java | 1 + 5 files changed, 57 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/d1c72b80/avatica-server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java ---------------------------------------------------------------------- diff --git a/avatica-server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java b/avatica-server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java index 1bfd7f6..6f1339f 100644 --- a/avatica-server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java +++ b/avatica-server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcMeta.java @@ -642,13 +642,13 @@ public class JdbcMeta implements Meta { } } - private RuntimeException propagate(Throwable e) { + RuntimeException propagate(Throwable e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else if (e instanceof Error) { throw (Error) e; } else { - throw new RuntimeException(e.getMessage()); + throw new RuntimeException(e); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d1c72b80/avatica-server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java ---------------------------------------------------------------------- diff --git a/avatica-server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java b/avatica-server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java index a26f192..7e50dee 100644 --- a/avatica-server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java +++ b/avatica-server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java @@ -57,6 +57,7 @@ import java.util.TimeZone; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; @@ -856,7 +857,7 @@ public class RemoteDriverTest { fail("expected error, got " + resultSet); } catch (SQLException e) { assertThat(e.getMessage(), - equalTo("exception while executing query: unbound parameter")); + containsString("exception while executing query: unbound parameter")); } final ParameterMetaData parameterMetaData = ps.getParameterMetaData(); http://git-wip-us.apache.org/repos/asf/calcite/blob/d1c72b80/avatica-server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java ---------------------------------------------------------------------- diff --git a/avatica-server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java b/avatica-server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java new file mode 100644 index 0000000..5d1557d --- /dev/null +++ b/avatica-server/src/test/java/org/apache/calcite/avatica/jdbc/JdbcMetaTest.java @@ -0,0 +1,44 @@ +/* + * 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.calcite.avatica.jdbc; + +import org.junit.Test; + +import java.sql.SQLException; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +/** + * Unit tests for {@link JdbcMeta}. + */ +public class JdbcMetaTest { + + @Test public void testExceptionPropagation() throws SQLException { + JdbcMeta meta = new JdbcMeta("url"); + final Throwable e = new Exception(); + final RuntimeException rte; + try { + meta.propagate(e); + fail("Expected an exception to be thrown"); + } catch (RuntimeException caughtException) { + rte = caughtException; + assertThat(rte.getCause(), is(e)); + } + } +} http://git-wip-us.apache.org/repos/asf/calcite/blob/d1c72b80/avatica-server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java ---------------------------------------------------------------------- diff --git a/avatica-server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java b/avatica-server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java index d493c01..6cb4508 100644 --- a/avatica-server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java +++ b/avatica-server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java @@ -295,11 +295,12 @@ public class RemoteMetaTest { DriverManager.getConnection(url, "john", "doe"); fail("expected exception"); } catch (RuntimeException e) { - assertEquals("Remote driver error: " + assertEquals("Remote driver error: RuntimeException: " + "java.sql.SQLInvalidAuthorizationSpecException: invalid authorization specification" + " - not found: john" - + " -> invalid authorization specification - not found: john" - + " -> invalid authorization specification - not found: john", + + " -> SQLInvalidAuthorizationSpecException: invalid authorization specification - " + + "not found: john" + + " -> HsqlException: invalid authorization specification - not found: john", e.getMessage()); } } @@ -321,7 +322,10 @@ public class RemoteMetaTest { fail("expected exception"); } catch (Exception e) { assertEquals("Error -1 (00000) : Error while executing SQL \"select * from buffer\": " - + "Remote driver error: user lacks privilege or object not found: BUFFER", + + "Remote driver error: RuntimeException: java.sql.SQLSyntaxErrorException: " + + "user lacks privilege or object not found: BUFFER -> " + + "SQLSyntaxErrorException: user lacks privilege or object not found: BUFFER -> " + + "HsqlException: user lacks privilege or object not found: BUFFER", e.getMessage()); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/d1c72b80/avatica/src/main/java/org/apache/calcite/avatica/remote/AbstractHandler.java ---------------------------------------------------------------------- diff --git a/avatica/src/main/java/org/apache/calcite/avatica/remote/AbstractHandler.java b/avatica/src/main/java/org/apache/calcite/avatica/remote/AbstractHandler.java index 503790f..a8b76d8 100644 --- a/avatica/src/main/java/org/apache/calcite/avatica/remote/AbstractHandler.java +++ b/avatica/src/main/java/org/apache/calcite/avatica/remote/AbstractHandler.java @@ -133,6 +133,7 @@ public abstract class AbstractHandler<T> implements Handler<T> { sb.append(" -> "); } String message = curr.getMessage(); + sb.append(curr.getClass().getSimpleName()).append(": "); sb.append(null == message ? NULL_EXCEPTION_MESSAGE : message); curr = curr.getCause(); }
