Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
d7f08932
Commit
d7f08932
authored
12 years ago
by
Matei Zaharia
Browse files
Options
Downloads
Patches
Plain Diff
Fixed AccumulatorSuite to clean up SparkContext with BeforeAndAfter
parent
f7149c5e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/test/scala/spark/AccumulatorSuite.scala
+20
-10
20 additions, 10 deletions
core/src/test/scala/spark/AccumulatorSuite.scala
with
20 additions
and
10 deletions
core/src/test/scala/spark/AccumulatorSuite.scala
+
20
−
10
View file @
d7f08932
package
spark
import
org.scalatest.BeforeAndAfter
import
org.scalatest.FunSuite
import
org.scalatest.matchers.ShouldMatchers
import
collection.mutable
...
...
@@ -8,32 +9,39 @@ import scala.math.exp
import
scala.math.signum
import
spark.SparkContext._
class
AccumulatorSuite
extends
FunSuite
with
ShouldMatchers
{
class
AccumulatorSuite
extends
FunSuite
with
ShouldMatchers
with
BeforeAndAfter
{
var
sc
:
SparkContext
=
null
after
{
if
(
sc
!=
null
)
{
sc
.
stop
()
sc
=
null
}
}
test
(
"basic accumulation"
){
val
sc
=
new
SparkContext
(
"local"
,
"test"
)
sc
=
new
SparkContext
(
"local"
,
"test"
)
val
acc
:
Accumulator
[
Int
]
=
sc
.
accumulator
(
0
)
val
d
=
sc
.
parallelize
(
1
to
20
)
d
.
foreach
{
x
=>
acc
+=
x
}
acc
.
value
should
be
(
210
)
sc
.
stop
()
}
test
(
"value not assignable from tasks"
)
{
val
sc
=
new
SparkContext
(
"local"
,
"test"
)
sc
=
new
SparkContext
(
"local"
,
"test"
)
val
acc
:
Accumulator
[
Int
]
=
sc
.
accumulator
(
0
)
val
d
=
sc
.
parallelize
(
1
to
20
)
evaluating
{
d
.
foreach
{
x
=>
acc
.
value
=
x
}}
should
produce
[
Exception
]
sc
.
stop
()
}
test
(
"add value to collection accumulators"
)
{
import
SetAccum._
val
maxI
=
1000
for
(
nThreads
<-
List
(
1
,
10
))
{
//test single & multi-threaded
val
sc
=
new
SparkContext
(
"local["
+
nThreads
+
"]"
,
"test"
)
sc
=
new
SparkContext
(
"local["
+
nThreads
+
"]"
,
"test"
)
val
acc
:
Accumulable
[
mutable.Set
[
Any
]
,
Any
]
=
sc
.
accumulable
(
new
mutable
.
HashSet
[
Any
]())
val
d
=
sc
.
parallelize
(
1
to
maxI
)
d
.
foreach
{
...
...
@@ -44,6 +52,7 @@ class AccumulatorSuite extends FunSuite with ShouldMatchers {
v
should
contain
(
i
)
}
sc
.
stop
()
sc
=
null
}
}
...
...
@@ -67,16 +76,17 @@ class AccumulatorSuite extends FunSuite with ShouldMatchers {
import
SetAccum._
val
maxI
=
1000
for
(
nThreads
<-
List
(
1
,
10
))
{
//test single & multi-threaded
val
sc
=
new
SparkContext
(
"local["
+
nThreads
+
"]"
,
"test"
)
sc
=
new
SparkContext
(
"local["
+
nThreads
+
"]"
,
"test"
)
val
acc
:
Accumulable
[
mutable.Set
[
Any
]
,
Any
]
=
sc
.
accumulable
(
new
mutable
.
HashSet
[
Any
]())
val
d
=
sc
.
parallelize
(
1
to
maxI
)
val
thrown
=
evaluating
{
evaluating
{
d
.
foreach
{
x
=>
acc
.
value
+=
x
}
}
should
produce
[
SparkException
]
println
(
thrown
)
sc
.
stop
()
sc
=
null
}
}
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment