@Test public void testGetAllSlotEmpty() { URI requestUri = URI.create("http://localhost/v1/slot?state=unknown"); Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
@Test public void testGetAllAgentsEmpty() { URI requestUri = URI.create("http://localhost/v1/admin/agent"); Response response = resource.getAllAgents(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
private void assertOkResponse(Response response, SlotLifecycleState state, SlotStatus... slots) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (SlotStatus slotStatus : slots) { builder.add(SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces } }
@Test public void testGetAllAgentsEmpty() { URI requestUri = URI.create("http://localhost/v1/admin/agent"); Response response = resource.getAllAgents(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
@Test public void testGetAllSlotEmpty() { URI requestUri = URI.create("http://localhost/v1/slot?state=unknown"); Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
private void assertOkResponse(Response response, SlotLifecycleState state, SlotStatus... slots) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (SlotStatus slotStatus : slots) { builder.add(SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces } }
private void assertOkResponse(Response response, SlotLifecycleState state, UUID... slotIds) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId); Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (UUID slotId : slotIds) { SlotStatus slotStatus = agentStatus.getSlotStatus(slotId); builder.add(SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); assertEquals(slotStatus.getAssignment(), APPLE_ASSIGNMENT); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
private void assertOkResponse(Response response, SlotLifecycleState state, UUID... slotIds) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId); Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (UUID slotId : slotIds) { SlotStatus slotStatus = agentStatus.getSlotStatus(slotId); builder.add(SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); assertEquals(slotStatus.getAssignment(), APPLE_ASSIGNMENT); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
@Test public void testGetAllSlotStatus() { SlotStatus slotStatus1 = agent.install(APPLE_INSTALLATION); SlotStatus slotStatus2 = agent.install(APPLE_INSTALLATION); Response response = resource.getAllSlotsStatus(uriInfo); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertInstanceOf(response.getEntity(), Collection.class); assertEqualsNoOrder((Collection<?>) response.getEntity(), ImmutableMultiset.of( SlotStatusRepresentation.from(slotStatus1), SlotStatusRepresentation.from(slotStatus2) )); assertEquals(response.getMetadata().get(AIRSHIP_AGENT_VERSION_HEADER).get(0), agent.getAgentStatus().getVersion()); }
@Test public void testGetAllSlotStatus() { SlotStatus slotStatus1 = agent.install(APPLE_INSTALLATION); SlotStatus slotStatus2 = agent.install(APPLE_INSTALLATION); Response response = resource.getAllSlotsStatus(uriInfo); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertInstanceOf(response.getEntity(), Collection.class); assertEqualsNoOrder((Collection<?>) response.getEntity(), ImmutableMultiset.of( SlotStatusRepresentation.from(slotStatus1), SlotStatusRepresentation.from(slotStatus2) )); assertEquals(response.getMetadata().get(AIRSHIP_AGENT_VERSION_HEADER).get(0), agent.getAgentStatus().getVersion()); }
@Test public void testGetAllSlotStatus() throws Exception { SlotStatus appleSlotStatus = agent.install(appleInstallation); SlotStatus bananaSlotStatus = agent.install(bananaInstallation); Request request = Request.Builder.prepareGet().setUri(urlFor("/v1/agent/slot")).build(); List<Map<String, Object>> response = client.execute(request, createJsonResponseHandler(listCodec, Status.OK.getStatusCode())); List<Map<String, Object>> expected = listCodec.fromJson(Resources.toString(Resources.getResource("slot-status-list.json"), UTF_8)); expected.get(0).put("id", appleSlotStatus.getId().toString()); expected.get(0).put("shortId", appleSlotStatus.getId().toString()); expected.get(0).put("version", appleSlotStatus.getVersion()); expected.get(0).put("self", urlFor(appleSlotStatus).toASCIIString()); expected.get(0).put("externalUri", urlFor(appleSlotStatus).toASCIIString()); expected.get(0).put("location", appleSlotStatus.getLocation()); expected.get(0).put("shortLocation", appleSlotStatus.getLocation()); expected.get(0).put("installPath", appleSlotStatus.getInstallPath()); expected.get(0).put("resources", ImmutableMap.<String, Integer>of("memory", 512)); expected.get(1).put("id", bananaSlotStatus.getId().toString()); expected.get(1).put("shortId", bananaSlotStatus.getId().toString()); expected.get(1).put("version", bananaSlotStatus.getVersion()); expected.get(1).put("self", urlFor(bananaSlotStatus).toASCIIString()); expected.get(1).put("externalUri", urlFor(bananaSlotStatus).toASCIIString()); expected.get(1).put("location", bananaSlotStatus.getLocation()); expected.get(1).put("shortLocation", bananaSlotStatus.getLocation()); expected.get(1).put("installPath", bananaSlotStatus.getInstallPath()); expected.get(1).put("resources", ImmutableMap.<String, Integer>of("cpu", 1)); assertEqualsNoOrder(response, expected); }
@Test public void testGetAllSlotStatus() throws Exception { SlotStatus appleSlotStatus = agent.install(appleInstallation); SlotStatus bananaSlotStatus = agent.install(bananaInstallation); Request request = Request.Builder.prepareGet().setUri(urlFor("/v1/agent/slot")).build(); List<Map<String, Object>> response = client.execute(request, createJsonResponseHandler(listCodec, Status.OK.getStatusCode())); List<Map<String, Object>> expected = listCodec.fromJson(Resources.toString(Resources.getResource("slot-status-list.json"), UTF_8)); expected.get(0).put("id", appleSlotStatus.getId().toString()); expected.get(0).put("shortId", appleSlotStatus.getId().toString()); expected.get(0).put("version", appleSlotStatus.getVersion()); expected.get(0).put("self", urlFor(appleSlotStatus).toASCIIString()); expected.get(0).put("externalUri", urlFor(appleSlotStatus).toASCIIString()); expected.get(0).put("location", appleSlotStatus.getLocation()); expected.get(0).put("shortLocation", appleSlotStatus.getLocation()); expected.get(0).put("installPath", appleSlotStatus.getInstallPath()); expected.get(0).put("resources", ImmutableMap.<String, Integer>of("memory", 512)); expected.get(1).put("id", bananaSlotStatus.getId().toString()); expected.get(1).put("shortId", bananaSlotStatus.getId().toString()); expected.get(1).put("version", bananaSlotStatus.getVersion()); expected.get(1).put("self", urlFor(bananaSlotStatus).toASCIIString()); expected.get(1).put("externalUri", urlFor(bananaSlotStatus).toASCIIString()); expected.get(1).put("location", bananaSlotStatus.getLocation()); expected.get(1).put("shortLocation", bananaSlotStatus.getLocation()); expected.get(1).put("installPath", bananaSlotStatus.getInstallPath()); expected.get(1).put("resources", ImmutableMap.<String, Integer>of("cpu", 1)); assertEqualsNoOrder(response, expected); }
Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of(SlotStatusRepresentation.from(slot1, prefixSize, repository))); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces
Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of(SlotStatusRepresentation.from(slot1, prefixSize, repository), SlotStatusRepresentation.from(slot2, prefixSize, repository))); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces
Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of(SlotStatusRepresentation.from(slot1, prefixSize, repository))); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces
Response response = resource.getAllSlots(MockUriInfo.from(requestUri)); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertEqualsNoOrder((Iterable<?>) response.getEntity(), ImmutableList.of(SlotStatusRepresentation.from(slot1, prefixSize, repository), SlotStatusRepresentation.from(slot2, prefixSize, repository))); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces
@Test public void testShow() throws Exception { initializeOneAgent(); coordinator.updateAllAgentsAndWait(); Request request = Request.Builder.prepareGet() .setUri(coordinatorUriBuilder().appendPath("/v1/slot").addParameter("!binary", "*:apple:*").build()) .build(); List<SlotStatusRepresentation> actual = httpClient.execute(request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode())); List<SlotStatusRepresentation> expected = ImmutableList.of( slotStatusRepresentationFactory.create(bananaSlot.status().changeInstanceId(agentInstanceId))); assertEqualsNoOrder(actual, expected); }
@Test public void testGetAllSlots() throws Exception { initializeOneAgent(); Request request = Request.Builder.prepareGet() .setUri(coordinatorUriBuilder().appendPath("/v1/slot").addParameter("name", "*").build()) .build(); List<SlotStatusRepresentation> actual = httpClient.execute(request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode())); AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId); int prefixSize = shortestUniquePrefix(asList( agentStatus.getSlotStatus(apple1SotId).getId().toString(), agentStatus.getSlotStatus(apple2SlotId).getId().toString(), agentStatus.getSlotStatus(bananaSlotId).getId().toString()), MIN_PREFIX_SIZE); assertEqualsNoOrder(actual, ImmutableList.of( SlotStatusRepresentation.from(agentStatus.getSlotStatus(apple1SotId), prefixSize, MOCK_REPO), SlotStatusRepresentation.from(agentStatus.getSlotStatus(apple2SlotId), prefixSize, MOCK_REPO), SlotStatusRepresentation.from(agentStatus.getSlotStatus(bananaSlotId), prefixSize, MOCK_REPO))); }
@Test public void testTerminate() throws Exception { initializeOneAgent(); Request request = Request.Builder.prepareDelete() .setUri(coordinatorUriBuilder().appendPath("/v1/slot").addParameter("binary", "*:apple:*").build()) .build(); List<SlotStatusRepresentation> actual = httpClient.execute(request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode())); List<SlotStatusRepresentation> expected = ImmutableList.of( slotStatusRepresentationFactory.create(appleSlot1.status().changeInstanceId(agentInstanceId)), slotStatusRepresentationFactory.create(appleSlot2.status().changeInstanceId(agentInstanceId))); assertEqualsNoOrder(actual, expected); assertEquals(appleSlot1.status().getState(), TERMINATED); assertEquals(appleSlot2.status().getState(), TERMINATED); assertEquals(bananaSlot.status().getState(), STOPPED); }
@Test public void testStart() throws Exception { initializeOneAgent(); Request request = Request.Builder.preparePut() .setUri(coordinatorUriBuilder().appendPath("/v1/slot/lifecycle").addParameter("binary", "apple:*").build()) .setBodyGenerator(createStaticBodyGenerator("running", 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(), RUNNING); assertEquals(apple2Status.getState(), RUNNING); assertEquals(bananaStatus.getState(), STOPPED); }