From bc4b8e0910ec07507bd3231a9115cba6d9187e8f Mon Sep 17 00:00:00 2001 From: Yin Huai Date: Mon, 17 Aug 2015 11:44:37 -0700 Subject: [PATCH] Update tests and add comments. --- .../scala/org/apache/spark/sql/SQLConfSuite.scala | 9 +++++---- .../scala/org/apache/spark/sql/SQLQuerySuite.scala | 14 ++++++++++++-- .../org/apache/spark/sql/test/TestSQLContext.scala | 4 ++++ .../org/apache/spark/sql/hive/test/TestHive.scala | 4 ++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLConfSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLConfSuite.scala index 48cddac461090..f20ea581a0c97 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLConfSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLConfSuite.scala @@ -32,11 +32,12 @@ class SQLConfSuite extends QueryTest with SharedSQLContext { } test("programmatic ways of basic setting and getting") { + // Set a conf first. + ctx.setConf(testKey, testVal) + // Clear the conf. ctx.conf.clear() - // The number of confs set after we call clear equals to the number of - // confs in TestSQLContext.overrideConfs (we always override these confs - // when we use TestSQLContext). - assert(ctx.getAllConfs.size === TestSQLContext.overrideConfs.size) + // After clear, only overrideConfs used by unit test should be in the SQLConf. + assert(ctx.getAllConfs === TestSQLContext.overrideConfs) ctx.setConf(testKey, testVal) assert(ctx.getConf(testKey) === testVal) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala index c329fdb2a6bb1..d9b662e78319c 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala @@ -25,7 +25,7 @@ import org.apache.spark.sql.catalyst.DefaultParserDialect import org.apache.spark.sql.catalyst.errors.DialectException import org.apache.spark.sql.execution.aggregate import org.apache.spark.sql.functions._ -import org.apache.spark.sql.test.SharedSQLContext +import org.apache.spark.sql.test.{TestSQLContext, SharedSQLContext} import org.apache.spark.sql.test.SQLTestData._ import org.apache.spark.sql.types._ @@ -990,7 +990,17 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { val nonexistentKey = "nonexistent" // "set" itself returns all config variables currently specified in SQLConf. - assert(sql("SET").collect().size == 0) + assert(sql("SET").collect().size == TestSQLContext.overrideConfs.size) + sql("SET").collect().foreach { row => + val key = row.getString(0) + val value = row.getString(1) + assert( + TestSQLContext.overrideConfs.contains(key), + s"$key should not exist in SQLConf.") + assert( + TestSQLContext.overrideConfs(key) === value, + s"The value of $key should be ${TestSQLContext.overrideConfs(key)} instead of $value.") + } // "set key=val" sql(s"SET $testKey=$testVal") diff --git a/sql/core/src/test/scala/org/apache/spark/sql/test/TestSQLContext.scala b/sql/core/src/test/scala/org/apache/spark/sql/test/TestSQLContext.scala index c82096d59c7ea..8e622ec8c8d3a 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/test/TestSQLContext.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/test/TestSQLContext.scala @@ -63,6 +63,10 @@ private[sql] class TestSQLContext(sc: SparkContext) extends SQLContext(sc) { sel } private[sql] object TestSQLContext { + + /** + * A map used to store all confs that need to be overridden in sql/core unit tests. + */ val overrideConfs: Map[String, String] = Map( // Fewer shuffle partitions to speed up testing. diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala index 4f721d89a0357..11f5999acff81 100644 --- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala +++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala @@ -471,6 +471,10 @@ class TestHiveContext(sc: SparkContext) extends HiveContext(sc) { } private[hive] object TestHiveContext { + + /** + * A map used to store all confs that need to be overridden in sql/hive unit tests. + */ val overrideConfs: Map[String, String] = Map( // Fewer shuffle partitions to speed up testing.