Repository: hive
Updated Branches:
  refs/heads/branch-2.1 a109ff520 -> af4dec312


HIVE-9423: HiveServer2: Provide the user with different error messages 
depending on the Thrift client exception code (Peter Vary via Chaoyu Tang)


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

Branch: refs/heads/branch-2.1
Commit: af4dec31238dd0c7dd174debf4d8bc5df9f9956b
Parents: a109ff5
Author: ctang <[email protected]>
Authored: Fri Sep 30 21:33:28 2016 -0400
Committer: ctang <[email protected]>
Committed: Fri Sep 30 21:33:28 2016 -0400

----------------------------------------------------------------------
 beeline/pom.xml                                 |  5 ++
 .../java/org/apache/hive/beeline/BeeLine.java   | 23 +++++++
 beeline/src/main/resources/BeeLine.properties   | 11 +++
 .../beeline/TestBeeLineExceptionHandling.java   | 72 ++++++++++++++++++++
 4 files changed, 111 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/af4dec31/beeline/pom.xml
----------------------------------------------------------------------
diff --git a/beeline/pom.xml b/beeline/pom.xml
index eaab306..c024590 100644
--- a/beeline/pom.xml
+++ b/beeline/pom.xml
@@ -119,6 +119,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>postgresql</groupId>
       <artifactId>postgresql</artifactId>
       <version>9.1-901.jdbc4</version>

http://git-wip-us.apache.org/repos/asf/hive/blob/af4dec31/beeline/src/java/org/apache/hive/beeline/BeeLine.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java 
b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
index 9138613..856daf3 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -95,6 +95,7 @@ import org.apache.hive.beeline.cli.CliOptionsProcessor;
 
 import org.apache.hive.jdbc.Utils;
 import org.apache.hive.jdbc.Utils.JdbcConnectionParams;
+import org.apache.thrift.transport.TTransportException;
 
 /**
  * A console SQL shell with command completion.
@@ -1755,6 +1756,28 @@ public class BeeLine implements Closeable {
       return;
     }
 
+    if (e.getCause() instanceof TTransportException) {
+      switch (((TTransportException)e.getCause()).getType()) {
+        case TTransportException.ALREADY_OPEN:
+          error(loc("hs2-connection-already-open"));
+          break;
+        case TTransportException.END_OF_FILE:
+          error(loc("hs2-unexpected-end-of-file"));
+          break;
+        case TTransportException.NOT_OPEN:
+          error(loc("hs2-could-not-open-connection"));
+          break;
+        case TTransportException.TIMED_OUT:
+          error(loc("hs2-connection-timed-out"));
+          break;
+        case TTransportException.UNKNOWN:
+          error(loc("hs2-unknown-connection-problem"));
+          break;
+        default:
+          error(loc("hs2-unexpected-error"));
+      }
+    }
+
     error(loc(e instanceof SQLWarning ? "Warning" : "Error",
         new Object[] {
             e.getMessage() == null ? "" : e.getMessage().trim(),

http://git-wip-us.apache.org/repos/asf/hive/blob/af4dec31/beeline/src/main/resources/BeeLine.properties
----------------------------------------------------------------------
diff --git a/beeline/src/main/resources/BeeLine.properties 
b/beeline/src/main/resources/BeeLine.properties
index 16f23a8..12e379c 100644
--- a/beeline/src/main/resources/BeeLine.properties
+++ b/beeline/src/main/resources/BeeLine.properties
@@ -142,6 +142,17 @@ active-connections: 0#No active connections|1#{0} active 
connection:|1<{0} activ
 
 time-ms: ({0,number,#.###} seconds)
 
+hs2-connection-already-open: Socket already connected.
+hs2-unexpected-end-of-file: Unexpected end of file when reading from HS2 
server. The root \
+cause might be too many concurrent connections. Please ask the administrator 
to check the number \
+of active connections, and adjust hive.server2.thrift.max.worker.threads if 
applicable.
+hs2-could-not-open-connection: Could not open connection to the HS2 server. 
Please check the \
+server URI and if the URI is correct, then ask the administrator to check the 
server status.\
+hs2-connection-timed-out: Connection timeout when communicating with HS2 
server.
+hs2-unknown-connection-problem: Unknown HS2 problem when communicating with 
Thrift server.
+hs2-unexpected-error: Unexpected HS2 error when communicating with the Thrift 
server.
+
+
 cmd-usage: Usage: java org.apache.hive.cli.beeline.BeeLine \n \
 \  -u <database url>               the JDBC URL to connect to\n \
 \  -r                              reconnect to last saved connect url (in 
conjunction with !save)\n \

http://git-wip-us.apache.org/repos/asf/hive/blob/af4dec31/beeline/src/test/org/apache/hive/beeline/TestBeeLineExceptionHandling.java
----------------------------------------------------------------------
diff --git 
a/beeline/src/test/org/apache/hive/beeline/TestBeeLineExceptionHandling.java 
b/beeline/src/test/org/apache/hive/beeline/TestBeeLineExceptionHandling.java
new file mode 100644
index 0000000..08579e8
--- /dev/null
+++ b/beeline/src/test/org/apache/hive/beeline/TestBeeLineExceptionHandling.java
@@ -0,0 +1,72 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.hive.beeline;
+
+import junit.framework.Assert;
+import org.apache.thrift.transport.TTransportException;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class TestBeeLineExceptionHandling {
+
+  public class TestBeeline extends BeeLine {
+    private String expectedLoc;
+    private int logCount;
+    public TestBeeline(String expectedLoc) {
+      this.expectedLoc = expectedLoc;
+      this.logCount = 0;
+    }
+
+    @Override
+    boolean error(String log) {
+      if (logCount == 0) {
+        Assert.assertEquals(loc(expectedLoc), log);
+      } else {
+        Assert.assertEquals("Error: 
org.apache.thrift.transport.TTransportException "
+            + "(state=,code=0)", log);
+      }
+      logCount++;
+      return false;
+    }
+  }
+
+  @Test
+  public void testHandleSQLExceptionLog() throws Exception {
+    checkException(TTransportException.ALREADY_OPEN, 
"hs2-connection-already-open");
+    checkException(TTransportException.END_OF_FILE, 
"hs2-unexpected-end-of-file");
+    checkException(TTransportException.NOT_OPEN, 
"hs2-could-not-open-connection");
+    checkException(TTransportException.TIMED_OUT, "hs2-connection-timed-out");
+    checkException(TTransportException.UNKNOWN, 
"hs2-unknown-connection-problem");
+    checkException(-1, "hs2-unexpected-error");
+  }
+
+  private void checkException(int type, String loc) {
+    BeeLine testBeeLine = new TestBeeline(loc);
+    TTransportException tTransportException = new TTransportException(type);
+    SQLException sqlException = new SQLException(tTransportException);
+    testBeeLine.handleSQLException(sqlException);
+  }
+}

Reply via email to