From 636d60aa711984cef838e2e765d2d76b09a27314 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Thu, 19 Aug 2021 10:46:24 +0800 Subject: [PATCH] [KYUUBI #958] [TEST] Ensure two connections in user mode share the same engine ### _Why are the changes needed?_ Ensure changes like #935 do not break the rule for the semantics of engine sharing If and only if we want engines to be pooling, this test can be changed ### _How was this patch tested?_ - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #958 from yaooqinn/same. Closes #958 e172cebf [Kent Yao] Ensure two connections in user mode share the same engine Authored-by: Kent Yao Signed-off-by: Kent Yao --- .../KyuubiOperationPerUserSuite.scala | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerUserSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerUserSuite.scala index d2b270778..32aa966be 100644 --- a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerUserSuite.scala +++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerUserSuite.scala @@ -17,6 +17,8 @@ package org.apache.kyuubi.operation +import org.scalatest.time.SpanSugar._ + import org.apache.kyuubi.WithKyuubiServer import org.apache.kyuubi.config.KyuubiConf @@ -27,4 +29,30 @@ class KyuubiOperationPerUserSuite extends WithKyuubiServer with JDBCTests { override protected val conf: KyuubiConf = { KyuubiConf().set(KyuubiConf.ENGINE_SHARE_LEVEL, "user") } + + test("ensure two connections in user mode share the same engine") { + var r1: String = null + var r2: String = null + new Thread { + override def run(): Unit = withJdbcStatement() { statement => + val res = statement.executeQuery("set spark.app.name") + assert(res.next()) + r1 = res.getString("value") + } + }.start() + + new Thread { + override def run(): Unit = withJdbcStatement() { statement => + val res = statement.executeQuery("set spark.app.name") + assert(res.next()) + r2 = res.getString("value") + } + }.start() + + eventually(timeout(120.seconds), interval(100.milliseconds)) { + assert(r1 != null && r2 != null) + } + + assert(r1 === r2) + } }