Github user tnachen commented on a diff in the pull request: https://github.com/apache/spark/pull/8771#discussion_r39583404 --- Diff: core/src/test/scala/org/apache/spark/scheduler/cluster/mesos/CoarseMesosSchedulerBackendSuite.scala --- @@ -184,4 +184,52 @@ class CoarseMesosSchedulerBackendSuite extends SparkFunSuite verify(driver, times(1)).reviveOffers() } + + test("testing various isOfferValidForScheduling cases") { + val sparkConf = (new SparkConf) + .setMaster("local[*]") + .setAppName("test-mesos-dynamic-alloc") + .setSparkHome("/path") + .set("spark.cores.max", "10") + + val sc = new SparkContext(sparkConf) + + val driver = mock[SchedulerDriver] + when(driver.start()).thenReturn(Protos.Status.DRIVER_RUNNING) + val taskScheduler = mock[TaskSchedulerImpl] + when(taskScheduler.sc).thenReturn(sc) + + + val schedulerBackend = createSchedulerBackend(taskScheduler, driver, sc) + + // Return true when there is a valid offer + assert(schedulerBackend.isOfferValidForScheduling(true, "Slave1", 10000, 5, sc)) + + schedulerBackend.slaveIdsWithExecutors += "Slave2" + schedulerBackend.failuresBySlaveId("Slave3") = 2 + schedulerBackend.totalCoresAcquired = 5 + + // Return false When offer do not meet constraints + assert(schedulerBackend.isOfferValidForScheduling(false, "Slave1", 10000, 5, sc) === false) + + // Return false When memory in offer is less than required memory + assert(schedulerBackend.isOfferValidForScheduling(true, "Slave1", 1, 5, sc) === false) + + // Return false When cpu in offer is less than required cpu + assert(schedulerBackend.isOfferValidForScheduling(true, "Slave1", 10000, 0, sc) === false) + + // Return false When offer is from slave already running an executor + assert(schedulerBackend.isOfferValidForScheduling(true, "Slave2", 10000, 5, sc) === false) + + // Return false When task is failed more than MAX_SLAVE_FAILURES times on the given slave + assert(schedulerBackend.isOfferValidForScheduling(true, "Slave3", 10000, 5, sc) === false) + + schedulerBackend.totalCoresAcquired = 10 + + // Return false When max core is already acquired + assert(schedulerBackend.isOfferValidForScheduling(true, "Slave1", 10000, 5, sc) === false) + --- End diff -- kill space
--- 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