Skip to content

Commit 1d66085

Browse files
yaooqinncloud-fan
authored andcommitted
[SPARK-31289][TEST][TEST-HIVE1.2] Eliminate org.apache.spark.sql.hive.thriftserver.CliSuite flakiness
### What changes were proposed in this pull request? CliSuite seems to be flaky while using metastoreDir per test. https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/120470/testReport/org.apache.spark.sql.hive.thriftserver/CliSuite/ https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/120470/testReport/junit/org.apache.spark.sql.hive.thriftserver/CliSuite/history/ According to the error stack trace in the failed test, the test failed to instantiate a hive metastore client because of derby requirements. ```scala Caused by: ERROR XBM0A: The database directory '/home/jenkins/workspace/SparkPullRequestBuilder/target/tmp/spark-9249ce52-0a06-42b6-a3df-e6295e880df0' exists. However, it does not contain the expected 'service.properties' file. Perhaps Derby was brought down in the middle of creating this database. You may want to delete this directory and try creating the database again. ``` The derby requires the metastore dir does not exist, but it does exist probably due to the test case before it failed to clear the metastore dir In this PR, the metastore is shared across the tests of CliSuite except those explicitly asked a separated metastore env itself ### Why are the changes needed? CliSuite seems to be flaky while using metastoreDir per test. To eliminate test flakiness ### Does this PR introduce any user-facing change? no ### How was this patch tested? modified test Closes #28055 from yaooqinn/clisuite. Authored-by: Kent Yao <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent 86bd37f commit 1d66085

File tree

1 file changed

+59
-37
lines changed
  • sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver

1 file changed

+59
-37
lines changed

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/CliSuite.scala

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import org.apache.spark.util.{ThreadUtils, Utils}
3939
/**
4040
* A test suite for the `spark-sql` CLI tool.
4141
*/
42-
class CliSuite extends SparkFunSuite with BeforeAndAfterAll with BeforeAndAfterEach with Logging {
42+
class CliSuite extends SparkFunSuite with BeforeAndAfterAll with Logging {
4343
val warehousePath = Utils.createTempDir()
4444
val metastorePath = Utils.createTempDir()
4545
val scratchDirPath = Utils.createTempDir()
@@ -62,12 +62,6 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with BeforeAndAfterE
6262
}
6363
}
6464

65-
override def afterEach(): Unit = {
66-
// Only running `runCliWithin` in a single test case will share the same temporary
67-
// Hive metastore
68-
Utils.deleteRecursively(metastorePath)
69-
}
70-
7165
/**
7266
* Run a CLI operation and expect all the queries and expected answers to be returned.
7367
*
@@ -77,14 +71,21 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with BeforeAndAfterE
7771
* is taken as an immediate error condition. That is: if a line containing
7872
* with one of these strings is found, fail the test immediately.
7973
* The default value is `Seq("Error:")`
74+
* @param maybeWarehouse an option for warehouse path, which will be set via
75+
* `hive.metastore.warehouse.dir`.
76+
* @param useExternalHiveFile whether to load the hive-site.xml from `src/test/noclasspath` or
77+
* not, disabled by default
78+
* @param metastore which path the embedded derby database for metastore locates. Use the the
79+
* global `metastorePath` by default
8080
* @param queriesAndExpectedAnswers one or more tuples of query + answer
8181
*/
8282
def runCliWithin(
8383
timeout: FiniteDuration,
8484
extraArgs: Seq[String] = Seq.empty,
8585
errorResponses: Seq[String] = Seq("Error:"),
8686
maybeWarehouse: Option[File] = Some(warehousePath),
87-
useExternalHiveFile: Boolean = false)(
87+
useExternalHiveFile: Boolean = false,
88+
metastore: File = metastorePath)(
8889
queriesAndExpectedAnswers: (String, String)*): Unit = {
8990

9091
// Explicitly adds ENTER for each statement to make sure they are actually entered into the CLI.
@@ -116,7 +117,7 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with BeforeAndAfterE
116117
maybeWarehouse.map(dir => s"--hiveconf ${ConfVars.METASTOREWAREHOUSE}=$dir").getOrElse("")
117118
val command = {
118119
val cliScript = "../../bin/spark-sql".split("/").mkString(File.separator)
119-
val jdbcUrl = s"jdbc:derby:;databaseName=$metastorePath;create=true"
120+
val jdbcUrl = s"jdbc:derby:;databaseName=$metastore;create=true"
120121
s"""$cliScript
121122
| --master local
122123
| --driver-java-options -Dderby.system.durability=test
@@ -202,9 +203,18 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with BeforeAndAfterE
202203
}
203204

204205
test("load warehouse dir from hive-site.xml") {
205-
runCliWithin(1.minute, maybeWarehouse = None, useExternalHiveFile = true)(
206-
"desc database default;" -> "hive_one",
207-
"set spark.sql.warehouse.dir;" -> "hive_one")
206+
val metastore = Utils.createTempDir()
207+
metastore.delete()
208+
try {
209+
runCliWithin(1.minute,
210+
maybeWarehouse = None,
211+
useExternalHiveFile = true,
212+
metastore = metastore)(
213+
"desc database default;" -> "hive_one",
214+
"set spark.sql.warehouse.dir;" -> "hive_one")
215+
} finally {
216+
Utils.deleteRecursively(metastore)
217+
}
208218
}
209219

210220
test("load warehouse dir from --hiveconf") {
@@ -218,35 +228,47 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with BeforeAndAfterE
218228

219229
test("load warehouse dir from --conf spark(.hadoop).hive.*") {
220230
// override conf from hive-site.xml
221-
runCliWithin(
222-
2.minute,
223-
extraArgs = Seq("--conf", s"spark.hadoop.${ConfVars.METASTOREWAREHOUSE}=$sparkWareHouseDir"),
224-
maybeWarehouse = None,
225-
useExternalHiveFile = true)(
226-
"desc database default;" -> sparkWareHouseDir.getAbsolutePath,
227-
"create database cliTestDb;" -> "",
228-
"desc database cliTestDb;" -> sparkWareHouseDir.getAbsolutePath,
229-
"set spark.sql.warehouse.dir;" -> sparkWareHouseDir.getAbsolutePath)
230-
231-
// override conf from --hiveconf too
232-
runCliWithin(
233-
2.minute,
234-
extraArgs = Seq("--conf", s"spark.${ConfVars.METASTOREWAREHOUSE}=$sparkWareHouseDir"))(
235-
"desc database default;" -> sparkWareHouseDir.getAbsolutePath,
236-
"create database cliTestDb;" -> "",
237-
"desc database cliTestDb;" -> sparkWareHouseDir.getAbsolutePath,
238-
"set spark.sql.warehouse.dir;" -> sparkWareHouseDir.getAbsolutePath)
231+
val metastore = Utils.createTempDir()
232+
metastore.delete()
233+
try {
234+
runCliWithin(2.minute,
235+
extraArgs =
236+
Seq("--conf", s"spark.hadoop.${ConfVars.METASTOREWAREHOUSE}=$sparkWareHouseDir"),
237+
maybeWarehouse = None,
238+
useExternalHiveFile = true,
239+
metastore = metastore)(
240+
"desc database default;" -> sparkWareHouseDir.getAbsolutePath,
241+
"create database cliTestDb;" -> "",
242+
"desc database cliTestDb;" -> sparkWareHouseDir.getAbsolutePath,
243+
"set spark.sql.warehouse.dir;" -> sparkWareHouseDir.getAbsolutePath)
244+
245+
// override conf from --hiveconf too
246+
runCliWithin(2.minute,
247+
extraArgs = Seq("--conf", s"spark.${ConfVars.METASTOREWAREHOUSE}=$sparkWareHouseDir"),
248+
metastore = metastore)(
249+
"desc database default;" -> sparkWareHouseDir.getAbsolutePath,
250+
"create database cliTestDb;" -> "",
251+
"desc database cliTestDb;" -> sparkWareHouseDir.getAbsolutePath,
252+
"set spark.sql.warehouse.dir;" -> sparkWareHouseDir.getAbsolutePath)
253+
} finally {
254+
Utils.deleteRecursively(metastore)
255+
}
239256
}
240257

241258
test("load warehouse dir from spark.sql.warehouse.dir") {
242259
// spark.sql.warehouse.dir overrides all hive ones
243-
runCliWithin(
244-
2.minute,
245-
extraArgs =
246-
Seq("--conf",
247-
s"${StaticSQLConf.WAREHOUSE_PATH.key}=${sparkWareHouseDir}1",
248-
"--conf", s"spark.hadoop.${ConfVars.METASTOREWAREHOUSE}=${sparkWareHouseDir}2"))(
249-
"desc database default;" -> sparkWareHouseDir.getAbsolutePath.concat("1"))
260+
val metastore = Utils.createTempDir()
261+
metastore.delete()
262+
try {
263+
runCliWithin(2.minute,
264+
extraArgs = Seq(
265+
"--conf", s"${StaticSQLConf.WAREHOUSE_PATH.key}=${sparkWareHouseDir}1",
266+
"--conf", s"spark.hadoop.${ConfVars.METASTOREWAREHOUSE}=${sparkWareHouseDir}2"),
267+
metastore = metastore)(
268+
"desc database default;" -> sparkWareHouseDir.getAbsolutePath.concat("1"))
269+
} finally {
270+
Utils.deleteRecursively(metastore)
271+
}
250272
}
251273

252274
test("Simple commands") {

0 commit comments

Comments
 (0)