diff --git a/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java b/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java index e667aa6..0013b31 100644 --- a/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java +++ b/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -54,6 +54,7 @@ import org.apache.hive.service.cli.operation.ClassicTableTypeMapping.ClassicTableTypes; import org.apache.hive.service.cli.operation.HiveTableTypeMapping; import org.apache.hive.service.cli.operation.TableTypeMappingFactory.TableTypeMappings; +import org.apache.hive.service.server.HiveServer2; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -250,7 +251,6 @@ public void testBadURL() throws Exception { checkBadUrl("jdbc:hive2://localhost:10000test"); } - private void checkBadUrl(String url) throws SQLException { try{ DriverManager.getConnection(url, "", ""); @@ -261,6 +261,59 @@ private void checkBadUrl(String url) throws SQLException { } } + /** + * This method tests whether while creating a new connection, + * the config variables specified in the JDBC URI are properly set for the connection. + * This is a test for HiveConnection#configureConnection. + * @throws Exception + */ + @Test + public void testNewConnectionConfiguration() throws Exception { + // Start HiveServer2 with default conf + HiveServer2 hiveServer2 = new HiveServer2(); + hiveServer2.init(new HiveConf()); + hiveServer2.start(); + Thread.sleep(3000); + + // Set some conf parameters + String hiveConf = "hive.cli.print.header=true;hive.server2.async.exec.shutdown.timeout=20;" + + "hive.server2.async.exec.threads=30;hive.server2.thrift.http.max.worker.threads=15"; + // Set some conf vars + String hiveVar = "stab=salesTable;icol=customerID"; + String jdbcUri = "jdbc:hive2://localhost:10000/default" + + "?" + hiveConf + + "#" + hiveVar; + + // Open a new connection with these conf & vars + Connection con1 = DriverManager.getConnection(jdbcUri); + + // Execute "set" command and retrieve values for the conf & vars specified above + // Assert values retrieved + Statement stmt = con1.createStatement(); + + // Verify that the property has been properly set while creating the connection above + verifyConfProperty(stmt, "hive.cli.print.header", "true"); + verifyConfProperty(stmt, "hive.server2.async.exec.shutdown.timeout", "20"); + verifyConfProperty(stmt, "hive.server2.async.exec.threads", "30"); + verifyConfProperty(stmt, "hive.server2.thrift.http.max.worker.threads", "15"); + verifyConfProperty(stmt, "stab", "salesTable"); + verifyConfProperty(stmt, "icol", "customerID"); + con1.close(); + + if(hiveServer2 != null) { + hiveServer2.stop(); + } + } + + private void verifyConfProperty(Statement stmt, String property, String expectedValue) + throws Exception { + ResultSet res = stmt.executeQuery("set " + property); + while(res.next()) { + String resultValues[] = res.getString(1).split("="); + assertEquals(resultValues[1], expectedValue); + } + } + @Test public void testDataTypes2() throws Exception { Statement stmt = con.createStatement();