Github user squito commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8760#discussion_r42049028
  
    --- Diff: 
core/src/test/scala/org/apache/spark/scheduler/BlacklistTrackerSuite.scala ---
    @@ -0,0 +1,162 @@
    +package org.apache.spark.scheduler
    +
    +import org.apache.spark.SparkFunSuite
    +import org.scalatest.BeforeAndAfter
    +import org.apache.spark.SparkConf
    +import org.apache.spark.TaskEndReason
    +import org.apache.spark.Success
    +import org.apache.spark.ExceptionFailure
    +import org.apache.spark.LocalSparkContext
    +import org.apache.spark.SparkContext
    +
    +import org.mockito.Mockito.{when,spy}
    +
    +class BlacklistTrackerSuite extends SparkFunSuite with BeforeAndAfter with 
LocalSparkContext {
    +
    +  val FAILURE: TaskEndReason = new ExceptionFailure(
    +      "Fake",
    +      "fake failure",
    +      Array.empty[StackTraceElement],
    +      "fake stack trace",
    +      None,
    +      None)
    +
    +  // Variable name can indicate basic information of taskInfo
    +  // The format is "taskInfo_executorId_taskId_hostName"
    +  val taskInfo_1_1_hostA = new TaskInfo(1L,1,1,0L,"1","hostA", 
TaskLocality.ANY, false)
    +  val taskInfo_1_2_hostA = new TaskInfo(2L,1,1,0L,"1","hostA", 
TaskLocality.ANY, false)
    +  val taskInfo_2_1_hostA = new TaskInfo(1L,1,1,0L,"2","hostA", 
TaskLocality.ANY, false)
    +  val taskInfo_2_2_hostA = new TaskInfo(2L,1,1,0L,"2","hostA", 
TaskLocality.ANY, false)
    +  val taskInfo_3_3_hostB = new TaskInfo(3L,1,1,0L,"3","hostB", 
TaskLocality.ANY, false)
    +
    +  test ("expireExecutorsInBlacklist works ") {
    +    val conf = new SparkConf().setAppName("test").setMaster("local")
    +      .set("spark.ui.enabled","false")
    +      .set("spark.scheduler.blacklist.recoverPeriod", "2")
    +    sc = new SparkContext(conf)
    +    val scheduler = new TaskSchedulerImpl(sc, 1)
    +
    +    val tracker = new BlacklistTracker(conf)
    +    tracker.start()
    +    Thread.sleep(100)
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("1"))
    +
    +    // sleep 2 second to wait for expireExecutorsInBlackList be triggered
    +    Thread.sleep(2000)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set())
    +
    +    tracker.stop()
    +  }
    +
    +  test("default strategy works as exceptation") {
    +    val conf = new SparkConf().setAppName("test").setMaster("local")
    +      .set("spark.ui.enabled","false")
    +    sc = new SparkContext(conf)
    +    val scheduler = new TaskSchedulerImpl(sc, 1)
    +
    +    val tracker = new BlacklistTracker(conf)
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, FAILURE)
    +    tracker.updateFailureExecutors(taskInfo_2_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("1","2"))
    +    assert(tracker.executorBlacklist(scheduler, 2L) === Set())
    +
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, Success)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("2"))
    +    assert(tracker.nodeBlacklist() === Set())
    +
    +    tracker.updateFailureExecutors(taskInfo_3_3_hostB, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 3L) === Set("3"))
    +    assert(tracker.nodeBlacklist() === Set())
    +
    +    tracker.updateFailureExecutors(taskInfo_2_1_hostA, Success)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set())
    +  }
    +  
    +  test ("strict strategy works as exception") {
    +    val conf = new SparkConf().setAppName("test").setMaster("local")
    +      .set("spark.ui.enabled","false")
    +      .set("spark.scheduler.blacklist.strategy", "strict")
    +    sc = new SparkContext(conf)
    +    val scheduler = new TaskSchedulerImpl(sc, 1)
    +
    +    val tracker = new BlacklistTracker(conf)
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("1"))
    +    tracker.updateFailureExecutors(taskInfo_1_2_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 2L) === Set("1"))
    +    assert(tracker.nodeBlacklist() === Set("hostA"))
    +
    +    tracker.updateFailureExecutors(taskInfo_2_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 2L) === Set("1", "2"))
    +    assert(tracker.nodeBlacklist() === Set("hostA"))
    +
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, Success)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("1","2"))
    +
    +    tracker.updateFailureExecutors(taskInfo_3_3_hostB, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 3L) === Set("1","2","3"))
    +    assert(tracker.nodeBlacklist() === Set("hostA","hostB"))
    +  }
    +
    +  test ("threshold strategy works as exception") {
    +    val conf = new SparkConf().setAppName("test").setMaster("local")
    +      .set("spark.ui.enabled","false")
    +      .set("spark.scheduler.blacklist.strategy", "threshold")
    +      .set("spark.scheduler.blacklist.threshold.maxFailureTaskNumber", "1")
    +      .set("spark.scheduler.blacklist.threshold.maxBlackExecutorNumber", 
"0")
    +    sc = new SparkContext(conf)
    +    val scheduler = new TaskSchedulerImpl(sc, 1)
    +
    +    val tracker = new BlacklistTracker(conf)
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set())
    +    tracker.updateFailureExecutors(taskInfo_1_2_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 2L) === Set("1"))
    +    assert(tracker.nodeBlacklist() === Set("hostA"))
    +
    +    tracker.updateFailureExecutors(taskInfo_2_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 2L) === Set("1"))
    +    assert(tracker.nodeBlacklist() === Set("hostA"))
    +
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, Success)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set())
    +  }
    +
    +  test ("test speculate executor feature under threshold strategy") {
    +    val conf = new SparkConf().setAppName("test").setMaster("local")
    +      .set("spark.ui.enabled","false")
    +      .set("spark.scheduler.blacklist.strategy", "threshold")
    +      .set("spark.scheduler.blacklist.threshold.maxFailureTaskNumber", "1")
    +      .set("spark.scheduler.blacklist.threshold.maxBlackExecutorNumber", 
"0")
    +      .set("spark.scheduler.blacklist.speculate","true")
    +    sc = new SparkContext(conf)
    +    val scheduler = spy(new TaskSchedulerImpl(sc, 1))
    +    
when(scheduler.getExecutorsAliveOnHost("hostA")).thenReturn(Some(Set("1","2")))
    +
    +    val tracker = new BlacklistTracker(conf)
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set())
    +    tracker.updateFailureExecutors(taskInfo_1_2_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 2L) === Set("1", "2"))
    +    assert(tracker.nodeBlacklist() === Set("hostA"))
    +
    +    tracker.updateFailureExecutors(taskInfo_2_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 2L) === Set("1", "2"))
    +    assert(tracker.nodeBlacklist() === Set("hostA"))
    +
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, Success)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set())
    +  }
    +
    +  test ("unsupported strategy wors as exception") {
    +    val ex = intercept[Exception]{
    +      val conf = new SparkConf().setAppName("test").setMaster("local")
    +        .set("spark.ui.enabled","false")
    +        .set("spark.scheduler.blacklist.strategy", "FAKE")
    +      sc = new SparkContext(conf)
    +      val scheduler = new TaskSchedulerImpl(sc, 1)
    +    }
    +    assert(ex.getMessage === "No match blacklist strategy for: FAKE")
    --- End diff --
    
    nit: "No matching blacklist ..."


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to