Add barrier for local properties unit test and fix some styles

This commit is contained in:
jerryshao 2013-09-22 09:40:40 +08:00
parent ffa5f8e11d
commit aa0c29f747
2 changed files with 11 additions and 3 deletions

View file

@ -275,7 +275,8 @@ class SparkContext(
}
}
def getLocalProperty(key: String): String = Option(localProperties.get).map(_.getProperty(key)).getOrElse(null)
def getLocalProperty(key: String): String =
Option(localProperties.get).map(_.getProperty(key)).getOrElse(null)
/** Set a human readable description of the current job. */
def setJobDescription(value: String) {

View file

@ -152,36 +152,43 @@ class ThreadingSuite extends FunSuite with LocalSparkContext {
test("set local properties in different thread") {
sc = new SparkContext("local", "test")
val sem = new Semaphore(0)
val threads = (1 to 5).map{ i =>
val threads = (1 to 5).map { i =>
new Thread() {
override def run() {
sc.setLocalProperty("test", i.toString)
assert(sc.getLocalProperty("test") === i.toString)
sem.release()
}
}
}
threads.foreach(_.start())
sem.acquire(5)
assert(sc.getLocalProperty("test") === null)
}
test("set and get local properties in parent-children thread") {
sc = new SparkContext("local", "test")
sc.setLocalProperty("test", "parent")
val sem = new Semaphore(0)
val threads = (1 to 5).map{ i =>
val threads = (1 to 5).map { i =>
new Thread() {
override def run() {
assert(sc.getLocalProperty("test") === "parent")
sc.setLocalProperty("test", i.toString)
assert(sc.getLocalProperty("test") === i.toString)
sem.release()
}
}
}
threads.foreach(_.start())
sem.acquire(5)
assert(sc.getLocalProperty("test") === "parent")
assert(sc.getLocalProperty("Foo") === null)
}