Skip to content

Commit

Permalink
Add test for the Unavailable offer
Browse files Browse the repository at this point in the history
  • Loading branch information
zmalik authored and Zain Malik committed Jun 16, 2017
1 parent 2facb7a commit afb0124
Showing 1 changed file with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.apache.mesos.chronos.scheduler.mesos

import mesosphere.mesos.protos._
import mesosphere.mesos.util.FrameworkIdUtil
import org.apache.mesos.Protos.Offer
import org.apache.mesos.Protos.{DurationInfo, Offer, TimeInfo, Unavailability}
import org.apache.mesos.chronos.ChronosTestHelper._
import org.apache.mesos.chronos.scheduler.jobs.{BaseJob, JobScheduler, MockJobUtils, TaskManager}
import org.apache.mesos.{Protos, SchedulerDriver}
Expand Down Expand Up @@ -76,6 +76,33 @@ class MesosJobFrameworkSpec extends SpecificationWithJUnit with Mockito {
there was one(mockSchedulerDriver).declineOffer(OfferID("1"), Protos.Filters.getDefaultInstance)
}

"Reject unavailable offer" in {
import mesosphere.mesos.protos.Implicits._

import scala.collection.JavaConverters._

val mockDriverFactory = MockJobUtils.mockDriverFactory
val mockSchedulerDriver = mockDriverFactory.get

val mesosJobFramework = spy(
new MesosJobFramework(
mockDriverFactory,
mock[JobScheduler],
mock[TaskManager],
makeConfig(),
mock[FrameworkIdUtil],
mock[MesosTaskBuilder],
mock[MesosOfferReviver]))

val tasks = mutable.Buffer[(String, BaseJob, Offer)]()
doReturn(tasks).when(mesosJobFramework).generateLaunchableTasks(any)

val offer: Offer = makeUnavailableOffer
mesosJobFramework.resourceOffers(mockSchedulerDriver, Seq[Protos.Offer](offer).asJava)

there was one(mockSchedulerDriver).declineOffer(OfferID("1"), Protos.Filters.getDefaultInstance)
}

"Reject unused offers with default RefuseSeconds if --decline_offer_duration is not set" in {
import mesosphere.mesos.protos.Implicits._

Expand Down Expand Up @@ -176,6 +203,22 @@ class MesosJobFrameworkSpec extends SpecificationWithJUnit with Mockito {
}

private[this] def makeBasicOffer: Offer = {

makeBasicOfferBuilder
.build()
}

private[this] def makeUnavailableOffer: Offer = {

makeBasicOfferBuilder.setUnavailability(
Unavailability.newBuilder()
.setStart(TimeInfo.newBuilder().setNanoseconds(System.nanoTime()))
.setDuration(DurationInfo.newBuilder().setNanoseconds(-1l))
.build())
.build()
}

private[this] def makeBasicOfferBuilder: Offer.Builder = {
import mesosphere.mesos.protos.Implicits._

Protos.Offer.newBuilder()
Expand All @@ -186,7 +229,6 @@ class MesosJobFrameworkSpec extends SpecificationWithJUnit with Mockito {
.addResources(ScalarResource(Resource.CPUS, 1, "*"))
.addResources(ScalarResource(Resource.MEM, 100, "*"))
.addResources(ScalarResource(Resource.DISK, 100, "*"))
.build()
}


Expand Down

0 comments on commit afb0124

Please sign in to comment.