From b9973dac04c76a51e7bc163087483a4f43a88ec7 Mon Sep 17 00:00:00 2001 From: Josh Rosen Date: Sun, 25 Jan 2015 20:25:25 -0800 Subject: [PATCH] Add test to ensure that conf and env var settings are merged, not overriden. --- .../spark/scheduler/SparkListenerSuite.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/src/test/scala/org/apache/spark/scheduler/SparkListenerSuite.scala b/core/src/test/scala/org/apache/spark/scheduler/SparkListenerSuite.scala index ec9edbc3b5986..bca4808b3c0b8 100644 --- a/core/src/test/scala/org/apache/spark/scheduler/SparkListenerSuite.scala +++ b/core/src/test/scala/org/apache/spark/scheduler/SparkListenerSuite.scala @@ -383,6 +383,21 @@ class SparkListenerSuite extends FunSuite with LocalSparkContext with Matchers }.size should be (1) } + test("spark.extraListeners and SPARK_EXTRA_LISTENERS configurations are merged") { + // This test ensures that we don't accidentally change the behavior such that one setting + // overrides the other: + val SPARK_EXTRA_LISTENERS = classOf[ListenerThatAcceptsSparkConf].getName + val conf = spy(new SparkConf().setMaster("local").setAppName("test") + .set("spark.extraListeners", classOf[BasicJobCounter].getName)) + when(conf.getenv("SPARK_EXTRA_LISTENERS")).thenReturn(SPARK_EXTRA_LISTENERS) + when(conf.clone).thenReturn(conf) // so that our mock is still used + sc = new SparkContext(conf) + sc.listenerBus.sparkListeners.collect { case x: BasicJobCounter => x}.size should be (1) + sc.listenerBus.sparkListeners.collect { + case x: ListenerThatAcceptsSparkConf => x + }.size should be (1) + } + /** * Assert that the given list of numbers has an average that is greater than zero. */