| package org.example.similarproduct |
| |
| import org.apache.spark.{SparkConf, SparkContext} |
| import org.scalatest.{BeforeAndAfterAll, Suite} |
| |
| trait EngineTestSparkContext extends BeforeAndAfterAll { |
| self: Suite => |
| @transient private var _sc: SparkContext = _ |
| |
| def sc: SparkContext = _sc |
| |
| var conf = new SparkConf(false) |
| |
| override def beforeAll() { |
| _sc = new SparkContext("local", "test", conf) |
| super.beforeAll() |
| } |
| |
| override def afterAll() { |
| LocalSparkContext.stop(_sc) |
| |
| _sc = null |
| super.afterAll() |
| } |
| } |
| |
| object LocalSparkContext { |
| def stop(sc: SparkContext) { |
| if (sc != null) { |
| sc.stop() |
| } |
| // To avoid Akka rebinding to the same port, since it doesn't unbind |
| // immediately on shutdown |
| System.clearProperty("spark.driver.port") |
| } |
| } |