diff --git itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java index 7b1c9da..44305d6 100644 --- itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java +++ itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -334,59 +334,6 @@ public void testParentReferences() throws Exception { rs.close(); } - /** - * 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(); diff --git itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java index 6c25736..e0bfbaa 100644 --- itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java +++ itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java @@ -29,8 +29,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hive.jdbc.miniHS2.MiniHS2; -import org.junit.After; -import org.junit.Before; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -38,7 +37,7 @@ private static MiniHS2 miniHS2 = null; private static Path dataFilePath; - private Connection hs2Conn = null; + private static Connection hs2Conn = null; @BeforeClass public static void beforeTest() throws Exception { @@ -48,17 +47,13 @@ public static void beforeTest() throws Exception { String dataFileDir = conf.get("test.data.files").replace('\\', '/') .replace("c:", ""); dataFilePath = new Path(dataFileDir, "kv1.txt"); - } - - @Before - public void setUp() throws Exception { miniHS2.start(); hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL(), System.getProperty("user.name"), "bar"); hs2Conn.createStatement().execute("set hive.support.concurrency = false"); } - @After - public void tearDown() throws Exception { + @AfterClass + public static void afterTest() throws Exception { hs2Conn.close(); miniHS2.stop(); } @@ -83,4 +78,48 @@ public void testConnection() throws Exception { res.close(); stmt.close(); } + + /** + * 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 { + + // 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 = miniHS2.getJdbcURL() + + "?" + 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(); + } + + 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); + } + } }