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

    https://github.com/apache/spark/pull/8760#discussion_r42330786
  
    --- Diff: 
core/src/test/scala/org/apache/spark/scheduler/BlacklistTrackerSuite.scala ---
    @@ -0,0 +1,155 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +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}
    +import org.apache.spark.util.ManualClock
    +
    +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)
    +
    +  val clock = new ManualClock(0)
    +  
    +  test ("expireExecutorsInBlacklist works") {
    +    // expire time is set to 6s
    +    val conf = new SparkConf().setAppName("test").setMaster("local")
    +      .set("spark.ui.enabled","false")
    +      .set("spark.scheduler.executorTaskBlacklistTime", "6000")
    +
    +    sc = new SparkContext(conf)
    +    val scheduler = new TaskSchedulerImpl(sc, 1)
    +
    +    val tracker = new BlacklistTracker(conf, clock)
    +    // Executor 1 into blacklist at Time 00:00:00
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("1"))
    +
    +    clock.setTime(2000)
    +    tracker.expireExecutorsInBlackList()
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("1"))
    +    // Executor 1 failed again at Time 00::00:02
    +    tracker.updateFailureExecutors(taskInfo_1_1_hostA, FAILURE)
    +
    +    clock.setTime(3000)
    +    // Executor 2 failed at Time 00:00:03
    +    tracker.updateFailureExecutors(taskInfo_2_1_hostA, FAILURE)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("1", "2"))
    +
    +    clock.setTime(6000)
    +    tracker.expireExecutorsInBlackList()
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("1", "2"))
    +
    +    clock.setTime(8000)
    +    tracker.expireExecutorsInBlackList()
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("2"))
    +
    +    clock.setTime(10000)
    +    tracker.expireExecutorsInBlackList()
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set())
    +  }
    +
    +  test("default strategy works") {
    +    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, clock)
    +    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, Success)
    +    assert(tracker.executorBlacklist(scheduler, 1L) === Set("2"))
    +    
    +    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 ("threshold strategy works") {
    +    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 = spy(new TaskSchedulerImpl(sc, 1))
    +    
when(scheduler.getExecutorsAliveOnHost("hostA")).thenReturn(Some(Set("1","2")))
    +
    +    val tracker = new BlacklistTracker(conf, clock)
    +    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"))
    --- End diff --
    
    It's a meaningful test, I will add it


---
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