voonhous commented on code in PR #19921:
URL: https://github.com/apache/hudi/pull/19921#discussion_r3995326960


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala:
##########
@@ -118,23 +153,68 @@ class HoodieSparkSqlTestBase extends FunSuite with 
BeforeAndAfterAll {
         // it, so a throwing or non-withRecordType INMEMORY test would 
otherwise leak state here.
         // Runs before the catalog cleanup so it holds even if a drop throws.
         HoodieInMemoryHashIndex.clear()
-        val catalog = spark.sessionState.catalog
-        catalog.listDatabases().foreach { db =>
-          catalog.listTables(db).foreach { table =>
-            catalog.dropTable(table, true, true)
-          }
-        }
+        dropSuiteTables()
       }
     )
   }
 
+  /**
+   * Shared mode: scalatest runs each suite on its own thread and Hudi reads 
SparkSession.active in a few
+   * places (HoodieCatalog captures it when the session's catalog is first 
built, BaseProcedure per CALL),
+   * so pin this suite's child session to the test thread and fail fast if the 
session's HoodieCatalog was
+   * built against another session.
+   */
+  private def bindSuiteSession(): Unit = {
+    SparkSession.setActiveSession(spark)
+    
spark.sessionState.catalogManager.catalog(CatalogManager.SESSION_CATALOG_NAME) 
match {
+      case hoodieCatalog: HoodieCatalog =>
+        assert(hoodieCatalog.spark eq spark,
+          s"HoodieCatalog of ${getClass.getSimpleName} is bound to another 
SparkSession")
+      case _ =>
+    }
+  }
+
+  private lazy val tableNamePrefix: String = 
s"h${getClass.getSimpleName.toLowerCase}_"
+
+  /**
+   * Drops the tables a test left behind. Per-suite mode owns the whole 
catalog. Shared mode shares the
+   * external catalog with every other suite in the JVM, so it drops only this 
suite's generateTableName
+   * tables plus any table whose name is not of that form (fixed names and 
temp views); under serial
+   * execution those can only come from the test that just ran. Fixed names 
are renamed in a later step.
+   */
+  private def dropSuiteTables(): Unit = {
+    val catalog = spark.sessionState.catalog
+    catalog.listDatabases().foreach { db =>

Review Comment:
   Restructured in 55bed9e8c7de: dropSuiteTables now picks either every table 
or the owned ones depending on the mode, and ownsTable is just the two name 
tests.
   



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

Reply via email to