[MINOR] Add missing sc.stop() to end of examples

## What changes were proposed in this pull request?

Add `finally` clause for `sc.stop()` in the `test("register and deregister Spark listener from SparkContext")`.

## How was this patch tested?
Pass the build and unit tests.

Author: Weiqing Yang <yangweiqing001@gmail.com>

Closes #16426 from weiqingy/testIssue.
This commit is contained in:
Weiqing Yang 2017-01-03 09:56:42 +00:00 committed by Sean Owen
parent ae83c21125
commit e5c307c50a
No known key found for this signature in database
GPG key ID: BEB3956D6717BDDC
26 changed files with 55 additions and 11 deletions

View file

@ -455,16 +455,14 @@ class SparkContextSuite extends SparkFunSuite with LocalSparkContext {
test("register and deregister Spark listener from SparkContext") { test("register and deregister Spark listener from SparkContext") {
sc = new SparkContext(new SparkConf().setAppName("test").setMaster("local")) sc = new SparkContext(new SparkConf().setAppName("test").setMaster("local"))
try { val sparkListener1 = new SparkListener { }
val sparkListener1 = new SparkListener { } val sparkListener2 = new SparkListener { }
val sparkListener2 = new SparkListener { } sc.addSparkListener(sparkListener1)
sc.addSparkListener(sparkListener1) sc.addSparkListener(sparkListener2)
sc.addSparkListener(sparkListener2) assert(sc.listenerBus.listeners.contains(sparkListener1))
assert(sc.listenerBus.listeners.contains(sparkListener1)) assert(sc.listenerBus.listeners.contains(sparkListener2))
assert(sc.listenerBus.listeners.contains(sparkListener2)) sc.removeSparkListener(sparkListener1)
sc.removeSparkListener(sparkListener1) assert(!sc.listenerBus.listeners.contains(sparkListener1))
assert(!sc.listenerBus.listeners.contains(sparkListener1)) assert(sc.listenerBus.listeners.contains(sparkListener2))
assert(sc.listenerBus.listeners.contains(sparkListener2))
}
} }
} }

View file

@ -111,5 +111,7 @@ public class JavaBinaryClassificationMetricsExample {
model.save(sc, "target/tmp/LogisticRegressionModel"); model.save(sc, "target/tmp/LogisticRegressionModel");
LogisticRegressionModel.load(sc, "target/tmp/LogisticRegressionModel"); LogisticRegressionModel.load(sc, "target/tmp/LogisticRegressionModel");
// $example off$ // $example off$
sc.stop();
} }
} }

View file

@ -103,6 +103,8 @@ public class JavaLBFGSExample {
System.out.println(l); System.out.println(l);
System.out.println("Area under ROC = " + auROC); System.out.println("Area under ROC = " + auROC);
// $example off$ // $example off$
sc.stop();
} }
} }

View file

@ -91,5 +91,7 @@ public class JavaMulticlassClassificationMetricsExample {
LogisticRegressionModel sameModel = LogisticRegressionModel.load(sc, LogisticRegressionModel sameModel = LogisticRegressionModel.load(sc,
"target/tmp/LogisticRegressionModel"); "target/tmp/LogisticRegressionModel");
// $example off$ // $example off$
sc.stop();
} }
} }

View file

@ -61,5 +61,6 @@ public class JavaPCAExample {
for (Vector vector : collectPartitions) { for (Vector vector : collectPartitions) {
System.out.println("\t" + vector); System.out.println("\t" + vector);
} }
sc.stop();
} }
} }

View file

@ -47,6 +47,8 @@ object AssociationRulesExample {
+ rule.consequent.mkString(",") + "]," + rule.confidence) + rule.consequent.mkString(",") + "]," + rule.confidence)
} }
// $example off$ // $example off$
sc.stop()
} }
} }

View file

@ -98,6 +98,7 @@ object BinaryClassificationMetricsExample {
val auROC = metrics.areaUnderROC val auROC = metrics.areaUnderROC
println("Area under ROC = " + auROC) println("Area under ROC = " + auROC)
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -62,6 +62,8 @@ object DecisionTreeClassificationExample {
model.save(sc, "target/tmp/myDecisionTreeClassificationModel") model.save(sc, "target/tmp/myDecisionTreeClassificationModel")
val sameModel = DecisionTreeModel.load(sc, "target/tmp/myDecisionTreeClassificationModel") val sameModel = DecisionTreeModel.load(sc, "target/tmp/myDecisionTreeClassificationModel")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -61,6 +61,8 @@ object DecisionTreeRegressionExample {
model.save(sc, "target/tmp/myDecisionTreeRegressionModel") model.save(sc, "target/tmp/myDecisionTreeRegressionModel")
val sameModel = DecisionTreeModel.load(sc, "target/tmp/myDecisionTreeRegressionModel") val sameModel = DecisionTreeModel.load(sc, "target/tmp/myDecisionTreeRegressionModel")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -62,6 +62,8 @@ object GradientBoostingClassificationExample {
val sameModel = GradientBoostedTreesModel.load(sc, val sameModel = GradientBoostedTreesModel.load(sc,
"target/tmp/myGradientBoostingClassificationModel") "target/tmp/myGradientBoostingClassificationModel")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -61,6 +61,8 @@ object GradientBoostingRegressionExample {
val sameModel = GradientBoostedTreesModel.load(sc, val sameModel = GradientBoostedTreesModel.load(sc,
"target/tmp/myGradientBoostingRegressionModel") "target/tmp/myGradientBoostingRegressionModel")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -62,6 +62,8 @@ object IsotonicRegressionExample {
model.save(sc, "target/tmp/myIsotonicRegressionModel") model.save(sc, "target/tmp/myIsotonicRegressionModel")
val sameModel = IsotonicRegressionModel.load(sc, "target/tmp/myIsotonicRegressionModel") val sameModel = IsotonicRegressionModel.load(sc, "target/tmp/myIsotonicRegressionModel")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -84,6 +84,8 @@ object LBFGSExample {
loss.foreach(println) loss.foreach(println)
println("Area under ROC = " + auROC) println("Area under ROC = " + auROC)
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -64,6 +64,8 @@ object MultiLabelMetricsExample {
// Subset accuracy // Subset accuracy
println(s"Subset accuracy = ${metrics.subsetAccuracy}") println(s"Subset accuracy = ${metrics.subsetAccuracy}")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -90,6 +90,8 @@ object MulticlassMetricsExample {
println(s"Weighted F1 score: ${metrics.weightedFMeasure}") println(s"Weighted F1 score: ${metrics.weightedFMeasure}")
println(s"Weighted false positive rate: ${metrics.weightedFalsePositiveRate}") println(s"Weighted false positive rate: ${metrics.weightedFalsePositiveRate}")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -45,6 +45,8 @@ object NaiveBayesExample {
model.save(sc, "target/tmp/myNaiveBayesModel") model.save(sc, "target/tmp/myNaiveBayesModel")
val sameModel = NaiveBayesModel.load(sc, "target/tmp/myNaiveBayesModel") val sameModel = NaiveBayesModel.load(sc, "target/tmp/myNaiveBayesModel")
// $example off$ // $example off$
sc.stop()
} }
} }

View file

@ -53,6 +53,8 @@ object PCAOnRowMatrixExample {
val collect = projected.rows.collect() val collect = projected.rows.collect()
println("Projected Row Matrix of principal component:") println("Projected Row Matrix of principal component:")
collect.foreach { vector => println(vector) } collect.foreach { vector => println(vector) }
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -52,6 +52,8 @@ object PCAOnSourceVectorExample {
val collect = projected.collect() val collect = projected.collect()
println("Projected vector of principal component:") println("Projected vector of principal component:")
collect.foreach { vector => println(vector) } collect.foreach { vector => println(vector) }
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -46,6 +46,8 @@ object PrefixSpanExample {
", " + freqSequence.freq) ", " + freqSequence.freq)
} }
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:off println // scalastyle:off println

View file

@ -62,6 +62,8 @@ object RandomForestClassificationExample {
model.save(sc, "target/tmp/myRandomForestClassificationModel") model.save(sc, "target/tmp/myRandomForestClassificationModel")
val sameModel = RandomForestModel.load(sc, "target/tmp/myRandomForestClassificationModel") val sameModel = RandomForestModel.load(sc, "target/tmp/myRandomForestClassificationModel")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -62,6 +62,8 @@ object RandomForestRegressionExample {
model.save(sc, "target/tmp/myRandomForestRegressionModel") model.save(sc, "target/tmp/myRandomForestRegressionModel")
val sameModel = RandomForestModel.load(sc, "target/tmp/myRandomForestRegressionModel") val sameModel = RandomForestModel.load(sc, "target/tmp/myRandomForestRegressionModel")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -62,6 +62,8 @@ object RecommendationExample {
model.save(sc, "target/tmp/myCollaborativeFilter") model.save(sc, "target/tmp/myCollaborativeFilter")
val sameModel = MatrixFactorizationModel.load(sc, "target/tmp/myCollaborativeFilter") val sameModel = MatrixFactorizationModel.load(sc, "target/tmp/myCollaborativeFilter")
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -56,6 +56,8 @@ object SVDExample {
collect.foreach { vector => println(vector) } collect.foreach { vector => println(vector) }
println(s"Singular values are: $s") println(s"Singular values are: $s")
println(s"V factor is:\n$V") println(s"V factor is:\n$V")
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -53,6 +53,8 @@ object SimpleFPGrowth {
+ ", " + rule.confidence) + ", " + rule.confidence)
} }
// $example off$ // $example off$
sc.stop()
} }
} }
// scalastyle:on println // scalastyle:on println

View file

@ -86,6 +86,7 @@ object KMeansDataGenerator {
val data = generateKMeansRDD(sc, numPoints, k, d, r, parts) val data = generateKMeansRDD(sc, numPoints, k, d, r, parts)
data.map(_.mkString(" ")).saveAsTextFile(outputPath) data.map(_.mkString(" ")).saveAsTextFile(outputPath)
sc.stop()
System.exit(0) System.exit(0)
} }
} }

View file

@ -52,6 +52,7 @@ class YarnSchedulerBackendSuite extends SparkFunSuite with MockitoSugar with Loc
// Serialize to make sure serialization doesn't throw an error // Serialize to make sure serialization doesn't throw an error
ser.serialize(req) ser.serialize(req)
} }
sc.stop()
} }
} }