Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-33173][CORE][TESTS][FOLLOWUP] Use local[2] and AtomicInteger #30823

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.spark.internal.plugin
import java.io.File
import java.nio.charset.StandardCharsets
import java.util.{Map => JMap}
import java.util.concurrent.atomic.AtomicInteger

import scala.collection.JavaConverters._
import scala.concurrent.duration._
Expand Down Expand Up @@ -138,15 +139,15 @@ class PluginContainerSuite extends SparkFunSuite with BeforeAndAfterEach with Lo
sc = new SparkContext(conf)
sc.parallelize(1 to 10, 2).count()

assert(TestSparkPlugin.executorPlugin.numOnTaskStart == 2)
assert(TestSparkPlugin.executorPlugin.numOnTaskSucceeded == 2)
assert(TestSparkPlugin.executorPlugin.numOnTaskFailed == 0)
assert(TestSparkPlugin.executorPlugin.numOnTaskStart.get() == 2)
assert(TestSparkPlugin.executorPlugin.numOnTaskSucceeded.get() == 2)
assert(TestSparkPlugin.executorPlugin.numOnTaskFailed.get() == 0)
}

test("SPARK-33088: executor failed tasks trigger plugin calls") {
val conf = new SparkConf()
.setAppName(getClass().getName())
.set(SparkLauncher.SPARK_MASTER, "local[1]")
.set(SparkLauncher.SPARK_MASTER, "local[2]")
.set(PLUGINS, Seq(classOf[TestSparkPlugin].getName()))

sc = new SparkContext(conf)
Expand All @@ -157,9 +158,9 @@ class PluginContainerSuite extends SparkFunSuite with BeforeAndAfterEach with Lo
}

eventually(timeout(10.seconds), interval(100.millis)) {
assert(TestSparkPlugin.executorPlugin.numOnTaskStart == 2)
assert(TestSparkPlugin.executorPlugin.numOnTaskSucceeded == 0)
assert(TestSparkPlugin.executorPlugin.numOnTaskFailed == 2)
assert(TestSparkPlugin.executorPlugin.numOnTaskStart.get() == 2)
assert(TestSparkPlugin.executorPlugin.numOnTaskSucceeded.get() == 0)
assert(TestSparkPlugin.executorPlugin.numOnTaskFailed.get() == 2)
}
}

Expand Down Expand Up @@ -343,9 +344,9 @@ private class TestDriverPlugin extends DriverPlugin {

private class TestExecutorPlugin extends ExecutorPlugin {

var numOnTaskStart: Int = 0
var numOnTaskSucceeded: Int = 0
var numOnTaskFailed: Int = 0
val numOnTaskStart = new AtomicInteger(0)
val numOnTaskSucceeded = new AtomicInteger(0)
val numOnTaskFailed = new AtomicInteger(0)

override def init(ctx: PluginContext, extraConf: JMap[String, String]): Unit = {
ctx.metricRegistry().register("executorMetric", new Gauge[Int] {
Expand All @@ -355,15 +356,15 @@ private class TestExecutorPlugin extends ExecutorPlugin {
}

override def onTaskStart(): Unit = {
numOnTaskStart += 1
numOnTaskStart.incrementAndGet()
}

override def onTaskSucceeded(): Unit = {
numOnTaskSucceeded += 1
numOnTaskSucceeded.incrementAndGet()
}

override def onTaskFailed(failureReason: TaskFailedReason): Unit = {
numOnTaskFailed += 1
numOnTaskFailed.incrementAndGet()
}
}

Expand Down