コード例 #1
0
  @Test
  public void testTerminate() throws Exception {
    initializeOneAgent();

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId);
    SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId);

    Request request =
        Request.Builder.prepareDelete()
            .setUri(
                coordinatorUriBuilder()
                    .appendPath("/v1/slot")
                    .addParameter("host", "apple*")
                    .build())
            .build();
    List<SlotStatusRepresentation> actual =
        httpClient.execute(
            request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode()));

    apple1Status = apple1Status.changeState(TERMINATED);
    apple2Status = apple2Status.changeState(TERMINATED);
    SlotStatus bananaStatus = coordinator.getAgentByAgentId(agentId).getSlotStatus(bananaSlotId);

    List<SlotStatusRepresentation> expected =
        ImmutableList.of(
            slotStatusRepresentationFactory.create(apple1Status),
            slotStatusRepresentationFactory.create(apple2Status.changeState(TERMINATED)));

    assertEqualsNoOrder(actual, expected);

    assertEquals(apple1Status.getState(), TERMINATED);
    assertEquals(apple2Status.getState(), TERMINATED);
    assertEquals(bananaStatus.getState(), STOPPED);
  }
コード例 #2
0
  @Test
  public void testKill() throws Exception {
    initializeOneAgent();

    coordinator.setState(RUNNING, Predicates.<SlotStatus>alwaysTrue(), null);

    Request request =
        Request.Builder.preparePut()
            .setUri(
                coordinatorUriBuilder()
                    .appendPath("/v1/slot/lifecycle")
                    .addParameter("binary", "apple:*")
                    .build())
            .setBodyGenerator(createStaticBodyGenerator("killing", UTF_8))
            .build();
    List<SlotStatusRepresentation> actual =
        httpClient.execute(
            request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode()));

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId);
    SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId);
    SlotStatus bananaStatus = agentStatus.getSlotStatus(bananaSlotId);

    List<SlotStatusRepresentation> expected =
        ImmutableList.of(
            slotStatusRepresentationFactory.create(apple1Status),
            slotStatusRepresentationFactory.create(apple2Status));

    assertEqualsNoOrder(actual, expected);
    assertEquals(apple1Status.getState(), STOPPED);
    assertEquals(apple2Status.getState(), STOPPED);
    assertEquals(bananaStatus.getState(), RUNNING);
  }
コード例 #3
0
  @Test
  public void testUpgrade() throws Exception {
    initializeOneAgent();

    UpgradeVersions upgradeVersions = new UpgradeVersions("2.0", "2.0");
    Request request =
        Request.Builder.preparePost()
            .setUri(
                coordinatorUriBuilder()
                    .appendPath("/v1/slot/assignment")
                    .addParameter("host", "apple*")
                    .build())
            .setHeader(CONTENT_TYPE, APPLICATION_JSON)
            .setBodyGenerator(jsonBodyGenerator(upgradeVersionsCodec, upgradeVersions))
            .build();
    List<SlotStatusRepresentation> actual =
        httpClient.execute(
            request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode()));

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId);
    SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId);
    SlotStatus bananaStatus = agentStatus.getSlotStatus(bananaSlotId);

    List<SlotStatusRepresentation> expected =
        ImmutableList.of(
            slotStatusRepresentationFactory.create(apple1Status),
            slotStatusRepresentationFactory.create(apple2Status));

    assertEqualsNoOrder(actual, expected);

    assertEquals(apple1Status.getState(), STOPPED);
    assertEquals(apple2Status.getState(), STOPPED);
    assertEquals(bananaStatus.getState(), STOPPED);

    assertEquals(
        apple1Status.getAssignment(),
        upgradeVersions.upgradeAssignment(MOCK_REPO, APPLE_ASSIGNMENT));
    assertEquals(
        apple2Status.getAssignment(),
        upgradeVersions.upgradeAssignment(MOCK_REPO, APPLE_ASSIGNMENT));
    assertEquals(bananaStatus.getAssignment(), BANANA_ASSIGNMENT);
  }