Repository: hive
Updated Branches:
  refs/heads/master 71536a2f8 -> 2d2ab0942


HIVE-12605 : Implement JDBC Connection.isValid (Gabor Liptak via Thejas Nair)


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

Branch: refs/heads/master
Commit: 2d2ab0942482a6ce1523dd9dd0f4094865e93b28
Parents: 71536a2
Author: Gabor Liptak <[email protected]>
Authored: Sun Dec 20 11:04:56 2015 -0800
Committer: Thejas Nair <[email protected]>
Committed: Sun Dec 20 11:05:24 2015 -0800

----------------------------------------------------------------------
 .../hive/minikdc/TestJdbcWithMiniKdc.java       | 30 +++++++++++++++++---
 .../org/apache/hive/jdbc/HiveConnection.java    | 14 +++++++--
 2 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/2d2ab094/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithMiniKdc.java
----------------------------------------------------------------------
diff --git 
a/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithMiniKdc.java
 
b/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithMiniKdc.java
index 954a452..3ef2ce3 100644
--- 
a/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithMiniKdc.java
+++ 
b/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithMiniKdc.java
@@ -18,10 +18,6 @@
 
 package org.apache.hive.minikdc;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
@@ -46,6 +42,8 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+
 public class TestJdbcWithMiniKdc {
   // Need to hive.server2.session.hook to SessionHookTest in hive-site
   public static final String SESSION_USER_NAME = "proxy.test.session.user";
@@ -126,6 +124,30 @@ public class TestJdbcWithMiniKdc {
   }
 
   /***
+   * Test isValid() method
+   * @throws Exception
+   */
+  @Test
+  public void testIsValid() throws Exception {
+    miniHiveKdc.loginUser(MiniHiveKdc.HIVE_TEST_SUPER_USER);
+    hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL());
+    assertTrue(hs2Conn.isValid(1000));
+    hs2Conn.close();
+  }
+
+  /***
+   * Negative test isValid() method
+   * @throws Exception
+   */
+  @Test
+  public void testIsValidNeg() throws Exception {
+    miniHiveKdc.loginUser(MiniHiveKdc.HIVE_TEST_SUPER_USER);
+    hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL());
+    hs2Conn.close();
+    assertFalse(hs2Conn.isValid(1000));
+  }
+
+  /***
    * Test token based authentication over kerberos
    * Login as super user and retrieve the token for normal user
    * use the token to connect connect as normal user

http://git-wip-us.apache.org/repos/asf/hive/blob/2d2ab094/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
----------------------------------------------------------------------
diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java 
b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
index 3c5dc0c..31ad1f1 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
@@ -1030,8 +1030,18 @@ public class HiveConnection implements 
java.sql.Connection {
 
   @Override
   public boolean isValid(int timeout) throws SQLException {
-    // TODO Auto-generated method stub
-    throw new SQLException("Method not supported");
+    if (timeout < 0) {
+      throw new SQLException("timeout value was negative");
+    }
+    boolean rc = false;
+    try {
+      String productName = new HiveDatabaseMetaData(this, client, sessHandle)
+              .getDatabaseProductName();
+      rc = true;
+    } catch (SQLException e) {
+      // IGNORE
+    }
+    return rc;
   }
 
   /*

Reply via email to