diff --git a/sql/core/src/test/resources/log4j.properties b/sql/core/src/test/resources/log4j.properties index 12fb128149d32..e53cb1f4e681d 100644 --- a/sql/core/src/test/resources/log4j.properties +++ b/sql/core/src/test/resources/log4j.properties @@ -23,6 +23,7 @@ log4j.appender.CA=org.apache.log4j.ConsoleAppender log4j.appender.CA.layout=org.apache.log4j.PatternLayout log4j.appender.CA.layout.ConversionPattern=%d{HH:mm:ss.SSS} %p %c: %m%n log4j.appender.CA.Threshold = WARN +log4j.appender.CA.follow = true #File Appender diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/ui/SQLListenerSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/ui/SQLListenerSuite.scala index 085e4a49a57e6..4641a1ad78920 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/ui/SQLListenerSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/ui/SQLListenerSuite.scala @@ -25,6 +25,7 @@ import org.apache.spark.{SparkConf, SparkContext, SparkException, SparkFunSuite} import org.apache.spark.executor.TaskMetrics import org.apache.spark.scheduler._ import org.apache.spark.sql.{DataFrame, SQLContext} +import org.apache.spark.sql.catalyst.util.quietly import org.apache.spark.sql.execution.{SparkPlanInfo, SQLExecution} import org.apache.spark.sql.execution.metric.{LongSQLMetricValue, SQLMetrics} import org.apache.spark.sql.test.SharedSQLContext @@ -376,9 +377,7 @@ class SQLListenerSuite extends SparkFunSuite with SharedSQLContext { class SQLListenerMemoryLeakSuite extends SparkFunSuite { test("no memory leak") { - val oldLogLevel = org.apache.log4j.Logger.getRootLogger().getLevel() - try { - org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.FATAL) + quietly { val conf = new SparkConf() .setMaster("local") .setAppName("test") @@ -413,8 +412,6 @@ class SQLListenerMemoryLeakSuite extends SparkFunSuite { } finally { sc.stop() } - } finally { - org.apache.log4j.Logger.getRootLogger().setLevel(oldLogLevel) } } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/streaming/ContinuousQueryManagerSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/streaming/ContinuousQueryManagerSuite.scala index daf08efca4e3a..35bb9fdbfdd16 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/streaming/ContinuousQueryManagerSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/streaming/ContinuousQueryManagerSuite.scala @@ -49,7 +49,7 @@ class ContinuousQueryManagerSuite extends StreamTest with SharedSQLContext with sqlContext.streams.resetTerminated() } - test("listing") { + testQuietly("listing") { val (m1, ds1) = makeDataset val (m2, ds2) = makeDataset val (m3, ds3) = makeDataset @@ -83,7 +83,7 @@ class ContinuousQueryManagerSuite extends StreamTest with SharedSQLContext with require(!q2.isActive) require(q2.exception.isDefined) } - val ex2 = withClue("no error while getting non-active query") { + withClue("no error while getting non-active query") { intercept[IllegalArgumentException] { sqlContext.streams.get(q2.name).eq(q2) } @@ -93,7 +93,7 @@ class ContinuousQueryManagerSuite extends StreamTest with SharedSQLContext with } } - test("awaitAnyTermination without timeout and resetTerminated") { + testQuietly("awaitAnyTermination without timeout and resetTerminated") { val datasets = Seq.fill(5)(makeDataset._2) withQueriesOn(datasets: _*) { queries => require(queries.size === datasets.size) @@ -139,7 +139,7 @@ class ContinuousQueryManagerSuite extends StreamTest with SharedSQLContext with } } - test("awaitAnyTermination with timeout and resetTerminated") { + testQuietly("awaitAnyTermination with timeout and resetTerminated") { val datasets = Seq.fill(6)(makeDataset._2) withQueriesOn(datasets: _*) { queries => require(queries.size === datasets.size) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala b/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala index 7d6bff8295d2b..83ea311eb27b3 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala @@ -214,6 +214,20 @@ private[sql] trait SQLTestUtils protected implicit def logicalPlanToSparkQuery(plan: LogicalPlan): DataFrame = { DataFrame(sqlContext, plan) } + + /** + * Disable stdout and stderr when running the test. To not output the logs to the console, + * ConsoleAppender's `follow` should be set to `true` so that it will honors reassignments of + * System.out or System.err. Otherwise, ConsoleAppender will still output to the console even if + * we change System.out and System.err. + */ + protected def testQuietly(name: String)(f: => Unit): Unit = { + test(name) { + quietly { + f + } + } + } } private[sql] object SQLTestUtils {