Skip to content

Commit b9973da

Browse files
committed
Add test to ensure that conf and env var settings are merged, not overriden.
1 parent d6f3113 commit b9973da

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

core/src/test/scala/org/apache/spark/scheduler/SparkListenerSuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,21 @@ class SparkListenerSuite extends FunSuite with LocalSparkContext with Matchers
383383
}.size should be (1)
384384
}
385385

386+
test("spark.extraListeners and SPARK_EXTRA_LISTENERS configurations are merged") {
387+
// This test ensures that we don't accidentally change the behavior such that one setting
388+
// overrides the other:
389+
val SPARK_EXTRA_LISTENERS = classOf[ListenerThatAcceptsSparkConf].getName
390+
val conf = spy(new SparkConf().setMaster("local").setAppName("test")
391+
.set("spark.extraListeners", classOf[BasicJobCounter].getName))
392+
when(conf.getenv("SPARK_EXTRA_LISTENERS")).thenReturn(SPARK_EXTRA_LISTENERS)
393+
when(conf.clone).thenReturn(conf) // so that our mock is still used
394+
sc = new SparkContext(conf)
395+
sc.listenerBus.sparkListeners.collect { case x: BasicJobCounter => x}.size should be (1)
396+
sc.listenerBus.sparkListeners.collect {
397+
case x: ListenerThatAcceptsSparkConf => x
398+
}.size should be (1)
399+
}
400+
386401
/**
387402
* Assert that the given list of numbers has an average that is greater than zero.
388403
*/

0 commit comments

Comments
 (0)