pan3793 commented on code in PR #3379:
URL: https://github.com/apache/hive/pull/3379#discussion_r905980870


##########
itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcTimeout.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.jdbc;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hive.jdbc.miniHS2.MiniHS2;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.HashMap;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestJdbcTimeout {
+
+  private static MiniHS2 miniHS2 = null;
+
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    Class.forName(MiniHS2.getJdbcDriverName());
+    HiveConf conf = new HiveConf();
+    conf.setVar(HiveConf.ConfVars.HIVE_LOCK_MANAGER, 
"org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager");
+    miniHS2 = new MiniHS2.Builder().withConf(conf).build();
+    miniHS2.start(new HashMap<>());
+  }
+
+  @AfterClass
+  public static void afterTest() throws Exception {
+    if (miniHS2 != null && miniHS2.isStarted()) {
+      miniHS2.stop();
+    }
+  }
+
+  @Test
+  public void testDriverManagerLoginTimeout() throws Exception {
+    DriverManager.setLoginTimeout(10);
+    String url = miniHS2.getJdbcURL("default");
+    try (HiveConnection conn = (HiveConnection) 
DriverManager.getConnection(url)) {
+      assertEquals(10000, conn.getLoginTimeout());
+      assertEquals(0, conn.getSocketTimeout());
+    }
+  }
+
+  @Test
+  public void testParameterLoginTimeout() throws Exception {
+    DriverManager.setLoginTimeout(10);
+    String url = miniHS2.getJdbcURL("default", "loginTimeout=20000");
+    try (HiveConnection conn = (HiveConnection) 
DriverManager.getConnection(url)) {
+      assertEquals(20000, conn.getLoginTimeout());
+      assertEquals(0, conn.getSocketTimeout());
+    }
+  }
+
+  @Test
+  public void testParameterSocketTimeout() throws Exception {
+    DriverManager.setLoginTimeout(0);
+    String url = miniHS2.getJdbcURL("default", "socketTimeout=10000");
+    try (HiveConnection conn = (HiveConnection) 
DriverManager.getConnection(url)) {
+      assertEquals(0, conn.getLoginTimeout());
+      assertEquals(10000, conn.getSocketTimeout());
+    }
+  }
+
+  @Test
+  public void testLoginTimeoutDoesNotAffectSocketTime() throws Exception {

Review Comment:
   > Was this `loginTimeout` used anywhere else?
   
   I think no, the IDEA index indicates it is not used by others.
   
   > Do we need to keep backward compatibility?
   
   I think not necessary, the old implementation does not right. HIVE-12371 has 
already broken it one time.
   
   To clarify I think we have 3 approaches for improving the "*timeout" stuff
   
   1. Introduce new JDBC parameter `connectTimeout` w/ exsiting `socketTime`, 
ignore `DriverManager.loginTimeout`
   2. Same as 1, but use `DriverManager.loginTimeout` as `connectTimeout` if 
`connectTimeout` absent.
   3. Introduce new JDBC parameter `loginTimeout` and `connectTimeout` w/s 
exsiting `socketTime`, use `loginTimeout` as `socketTimeout` for openSession 
request, and reset `socketTimeout` if openSession successful.
   
   Which one do you prefer?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to