You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by se...@apache.org on 2016/10/01 01:09:17 UTC

[35/44] hive git commit: HiveServer2: Provide the user with different error messages depending on the Thrift client exception code (Peter Vary via Chaoyu Tang)

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/d16d4f1b
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/d16d4f1b
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/d16d4f1b

Branch: refs/heads/hive-14535
Commit: d16d4f1bcc43d6ebcab0eaf5bc635fb88b60be5f
Parents: 291f3d5
Author: ctang <ct...@cloudera.com>
Authored: Thu Sep 29 11:25:21 2016 -0400
Committer: ctang <ct...@cloudera.com>
Committed: Thu Sep 29 11:25:21 2016 -0400

----------------------------------------------------------------------
 .../java/org/apache/hive/beeline/BeeLine.java   | 20 +++++-
 beeline/src/main/resources/BeeLine.properties   | 11 ++-
 .../beeline/TestBeeLineExceptionHandling.java   | 72 ++++++++++++++++++++
 3 files changed, 101 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/d16d4f1b/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 5322ca6..79922d2 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -1778,7 +1778,25 @@ public class BeeLine implements Closeable {
     }
 
     if (e.getCause() instanceof TTransportException) {
-      error(loc("hs2-unavailable"));
+      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",

http://git-wip-us.apache.org/repos/asf/hive/blob/d16d4f1b/beeline/src/main/resources/BeeLine.properties
----------------------------------------------------------------------
diff --git a/beeline/src/main/resources/BeeLine.properties b/beeline/src/main/resources/BeeLine.properties
index 13321d2..ad79c01 100644
--- a/beeline/src/main/resources/BeeLine.properties
+++ b/beeline/src/main/resources/BeeLine.properties
@@ -142,7 +142,16 @@ active-connections: 0#No active connections|1#{0} active connection:|1<{0} activ
 
 time-ms: ({0,number,#.###} seconds)
 
-hs2-unavailable: HS2 may be unavailable, check server status
+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 \

http://git-wip-us.apache.org/repos/asf/hive/blob/d16d4f1b/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);
+  }
+}