Skip to content

Commit

Permalink
Add barrier for local properties unit test and fix some styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryshao committed Sep 22, 2013
1 parent ffa5f8e commit aa0c29f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/src/main/scala/org/apache/spark/SparkContext.scala
Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions core/src/test/scala/org/apache/spark/ThreadingSuite.scala
Expand Up @@ -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)
}
Expand Down

0 comments on commit aa0c29f

Please sign in to comment.