Skip to content

Commit 4d2efe9

Browse files
author
Imran Rashid
committed
change tests to show utility of localValue
1 parent 206a383 commit 4d2efe9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

core/src/main/scala/spark/Accumulators.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Accumulable[T,R] (
3636
}
3737

3838
/**
39-
* get the current value of this accumulator from within a task.
39+
* Get the current value of this accumulator from within a task.
4040
*
4141
* This is NOT the global value of the accumulator. To get the global value after a
4242
* completed operation on the dataset, call `value`.

core/src/test/scala/spark/AccumulatorSuite.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ class AccumulatorSuite extends FunSuite with ShouldMatchers {
8585
for (nThreads <- List(1, 10)) { //test single & multi-threaded
8686
val sc = new SparkContext("local[" + nThreads + "]", "test")
8787
val acc: Accumulable[mutable.Set[Any], Any] = sc.accumulable(new mutable.HashSet[Any]())
88-
val d = sc.parallelize(1 to maxI)
88+
val groupedInts = (1 to (maxI/20)).map {x => (20 * (x - 1) to 20 * x).toSet}
89+
val d = sc.parallelize(groupedInts)
8990
d.foreach {
90-
x => acc.localValue += x
91+
x => acc.localValue ++= x
9192
}
92-
acc.value should be ( (1 to maxI).toSet)
93+
acc.value should be ( (0 to maxI).toSet)
9394
}
9495
}
9596

0 commit comments

Comments
 (0)