tarak271 commented on code in PR #6141:
URL: https://github.com/apache/hive/pull/6141#discussion_r2468212345


##########
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/processor/TestShowProcessList.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.hadoop.hive.ql.processor;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.utils.TestTxnDbUtil;
+import org.apache.hive.jdbc.miniHS2.MiniHS2;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.net.URI;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class TestShowProcessList {
+  protected static final Logger LOG = 
LoggerFactory.getLogger(TestShowProcessList.class);
+
+  private static MiniHS2 miniHS2 = null;
+  private static HiveConf conf;
+  private static String user;
+  private static ThreadPoolExecutor executor;
+
+  static HiveConf defaultConf() throws Exception {
+    String confDir = "../../data/conf/llap/";
+    HiveConf.setHiveSiteLocation(new URI("file://" + new 
File(confDir).toURI().getPath() + "/hive-site.xml").toURL());
+    System.out.println("Setting hive-site: " + HiveConf.getHiveSiteLocation());
+    HiveConf defaultConf = new HiveConf();
+    defaultConf.addResource(new URI("file://" + new 
File(confDir).toURI().getPath() + "/tez-site.xml").toURL());
+    return defaultConf;
+  }
+
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    conf = defaultConf();
+    user = System.getProperty("user.name");
+    conf.setVar(HiveConf.ConfVars.USERS_IN_ADMIN_ROLE, user);
+    conf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER,
+        
"org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
+    String suffix = TestShowProcessList.class.getCanonicalName() + "-" + 
System.currentTimeMillis();
+    String dir = new File(System.getProperty("java.io.tmpdir") + 
File.separator + suffix).getPath()
+        .replaceAll("\\\\", "/") + "/warehouse";
+    conf.set(MetastoreConf.ConfVars.WAREHOUSE.name(), dir);
+    TestTxnDbUtil.setConfValues(conf);
+    TestTxnDbUtil.prepDb(conf);
+    MiniHS2.cleanupLocalDir();
+    Class.forName(MiniHS2.getJdbcDriverName());
+    miniHS2 = new MiniHS2(conf, MiniHS2.MiniClusterType.LLAP);
+    Map<String, String> confOverlay = new HashMap<>();
+    miniHS2.start(confOverlay);
+
+    executor = new ThreadPoolExecutor(5, 10, 50, TimeUnit.MILLISECONDS, new 
LinkedBlockingQueue<>());
+  }
+
+  @AfterClass
+  public static void afterTest() throws Exception {
+    if (miniHS2 != null && miniHS2.isStarted()) {
+      miniHS2.stop();
+    }
+    TestTxnDbUtil.cleanDb(conf);
+  }
+
+  @Test
+  public void testQueries() throws Exception {
+    //Initiate several parallel connections, each with a query that may begin 
a transaction.
+    for (int i = 0; i < 20; i++) {
+      executor.submit(() -> {
+        try (Connection con = 
DriverManager.getConnection(miniHS2.getJdbcURL(), user, "bar");
+            Statement stmt = con.createStatement()) {
+          stmt.execute("drop database if exists DB_" + 
Thread.currentThread().threadId() + " cascade");

Review Comment:
   @Aggarwal-Raghav Please find below responses
   
   1. The idea is to simulate 10/20 connections/queries which can open 
transactions. A new txnId will be opened for every query irrespective of the 
connection or thread
   2. We can take any number of threads, for now I am keeping it to 10, i.e 10 
queries will be run and the txnIds for those queries can be captured using show 
processlist and cross verify it txnid got opened or not
   3. Moved assert out of that loop. This loop will keep on executing until all 
the queries got executed & all the transactions got captured using show 
processlist. At the end checking if 10 transactions were opened or not for 
those 10 queries



-- 
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