Repository: hive Updated Branches: refs/heads/branch-2.0 422d58c25 -> a59d4ff2b
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/a59d4ff2 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/a59d4ff2 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/a59d4ff2 Branch: refs/heads/branch-2.0 Commit: a59d4ff2bfb477de02253bed410b280c011c3021 Parents: 422d58c 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:44 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/a59d4ff2/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/a59d4ff2/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 c312ece..e3a5028 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -1025,8 +1025,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; } /*
