[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:
parent
ae83c21125
commit
e5c307c50a
|
@ -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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ object AssociationRulesExample {
|
||||||
+ rule.consequent.mkString(",") + "]," + rule.confidence)
|
+ rule.consequent.mkString(",") + "]," + rule.confidence)
|
||||||
}
|
}
|
||||||
// $example off$
|
// $example off$
|
||||||
|
|
||||||
|
sc.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -46,6 +46,8 @@ object PrefixSpanExample {
|
||||||
", " + freqSequence.freq)
|
", " + freqSequence.freq)
|
||||||
}
|
}
|
||||||
// $example off$
|
// $example off$
|
||||||
|
|
||||||
|
sc.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// scalastyle:off println
|
// scalastyle:off println
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -53,6 +53,8 @@ object SimpleFPGrowth {
|
||||||
+ ", " + rule.confidence)
|
+ ", " + rule.confidence)
|
||||||
}
|
}
|
||||||
// $example off$
|
// $example off$
|
||||||
|
|
||||||
|
sc.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// scalastyle:on println
|
// scalastyle:on println
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue