コード例 #1
0
  @Test
  public void willLaunchTaskFromValidOffer() throws Exception {
    Protos.Offer offer = TestHelper.createDummyOffer();
    Protos.TaskInfo task =
        TestHelper.createDummyTask(
            "task", builder -> builder.setTaskId(Protos.TaskID.newBuilder().setValue(taskId)));

    when(uuidSupplier.get()).thenReturn(uuid);
    OfferEvaluation offerEvaluation =
        OfferEvaluation.accept(
            "test",
            taskId,
            offer,
            Collections.emptyMap(),
            Collections.emptyList(),
            Collections.emptyList());
    when(offerStrategyFilter.evaluate(taskId, offer)).thenReturn(offerEvaluation);
    when(taskMaterializer.createProposal(offerEvaluation))
        .thenReturn(new TaskProposal(offer, task));
    when(taskInfoFactory.create(
            taskId,
            offer,
            Collections.emptyList(),
            new ExecutionParameters(
                Collections.emptyMap(), Collections.emptyList(), Collections.emptyList())))
        .thenReturn(task);

    scheduler.resourceOffers(schedulerDriver, Collections.singletonList(offer));

    verify(schedulerDriver, never()).declineOffer(any(Protos.OfferID.class));
    verify(schedulerDriver)
        .launchTasks(Collections.singleton(offer.getId()), Collections.singleton(task));

    ArgumentCaptor<Protos.TaskInfo> taskInfoArgumentCaptor =
        ArgumentCaptor.forClass(Protos.TaskInfo.class);
    verify(stateRepository).store(taskInfoArgumentCaptor.capture());
    Protos.TaskInfo taskInfo = taskInfoArgumentCaptor.getValue();
    assertEquals(taskId, taskInfo.getTaskId().getValue());
  }
コード例 #2
0
  @Test
  public void willDeclineInvalidOffers() throws Exception {
    Protos.Offer offer = TestHelper.createDummyOffer();

    when(uuidSupplier.get()).thenReturn(uuid);
    when(offerStrategyFilter.evaluate(taskId, offer))
        .thenReturn(OfferEvaluation.decline("test", taskId, offer, null));

    scheduler.resourceOffers(schedulerDriver, Collections.singletonList(offer));

    verify(schedulerDriver).declineOffer(offer.getId());
    verifyNoMoreInteractions(schedulerDriver);
  }