ulysses-you commented on a change in pull request #30481:
URL: https://github.com/apache/spark/pull/30481#discussion_r537536374



##########
File path: 
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerWithSparkContextSuite.scala
##########
@@ -79,6 +84,43 @@ trait ThriftServerWithSparkContextSuite extends 
SharedThriftServer {
         "java.lang.NumberFormatException: invalid input syntax for type 
numeric: 1.2"))
     }
   }
+
+  test("SPARK-33526: Add config to control if cancel invoke interrupt task on 
thriftserver") {
+    withJdbcStatement { statement =>
+      val forceCancel = new AtomicBoolean(false)
+      val listener = new SparkListener {
+        override def onTaskEnd(taskEnd: SparkListenerTaskEnd): Unit = {
+          assert(taskEnd.reason.isInstanceOf[TaskKilled])
+          if (forceCancel.get()) {
+            assert(System.currentTimeMillis() - taskEnd.taskInfo.launchTime < 
1000)
+          } else {
+            // avoid accuracy, we check 2s instead of 3s.
+            assert(System.currentTimeMillis() - taskEnd.taskInfo.launchTime >= 
2000)
+          }
+        }
+      }
+
+      spark.sparkContext.addSparkListener(listener)
+      try {
+        statement.execute(s"SET ${SQLConf.THRIFTSERVER_QUERY_TIMEOUT.key}=1")
+        statement.execute(s"SET 
${SQLConf.THRIFTSERVER_FORCE_CANCEL.key}=false")
+        forceCancel.set(false)
+        val e1 = intercept[SQLException] {
+          statement.execute("select java_method('java.lang.Thread', 'sleep', 
3000L)")
+        }.getMessage
+        assert(e1.contains("Query timed out"))
+
+        statement.execute(s"SET ${SQLConf.THRIFTSERVER_FORCE_CANCEL.key}=true")
+        forceCancel.set(true)
+        val e2 = intercept[SQLException] {
+          statement.execute("select java_method('java.lang.Thread', 'sleep', 
3000L)")
+        }.getMessage
+        assert(e2.contains("Query timed out"))

Review comment:
       Looks better !




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

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