SlotStatus slotStatus = createSlotStatus(id, self, externalUri, SlotStatus slotStatus = createSlotStatus(id, self, externalUri,
@BeforeMethod public void setUp() throws Exception { status = new AgentStatus("agent-id", ONLINE, "instance-id", URI.create("internal://10.0.0.1"), URI.create("external://localhost"), "/unknown/location", "instance.type", ImmutableList.<SlotStatus>of(createSlotStatus(UUID.fromString("12345678-1234-1234-1234-123456789012"), URI.create("fake://localhost"), URI.create("fake://localhost"), "instance", "/location", UNKNOWN, APPLE_ASSIGNMENT, "/install-path", ImmutableMap.<String, Integer>of())), ImmutableMap.<String, Integer>of( "memory", 2048, "cpu", 4)); }
@BeforeMethod public void setUp() throws Exception { status = new AgentStatus("agent-id", ONLINE, "instance-id", URI.create("internal://10.0.0.1"), URI.create("external://localhost"), "/unknown/location", "instance.type", ImmutableList.<SlotStatus>of(createSlotStatus(UUID.fromString("12345678-1234-1234-1234-123456789012"), URI.create("fake://localhost"), URI.create("fake://localhost"), "instance", "/location", UNKNOWN, APPLE_ASSIGNMENT, "/install-path", ImmutableMap.<String, Integer>of())), ImmutableMap.<String, Integer>of( "memory", 2048, "cpu", 4)); }
createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", TERMINATED, null, applePath, ImmutableMap.<String, Integer>of()), createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", TERMINATED, null, applePath, ImmutableMap.<String, Integer>of())) .addEquivalentGroup( createSlotStatus(bananaId, appleSelf, appleExternalUri, "instance", "/location", TERMINATED, null, applePath, ImmutableMap.<String, Integer>of()), createSlotStatus(bananaId, appleSelf, appleExternalUri, "instance", "/location", TERMINATED, null, applePath, ImmutableMap.<String, Integer>of())) .addEquivalentGroup( createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", RUNNING, APPLE_ASSIGNMENT, applePath, ImmutableMap.<String, Integer>of()), createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", RUNNING, APPLE_ASSIGNMENT, applePath, ImmutableMap.<String, Integer>of())) .addEquivalentGroup( createSlotStatus(bananaId, bananaSelf, bananaExternalUri, "instance", "/location", RUNNING, APPLE_ASSIGNMENT, bananaPath, ImmutableMap.<String, Integer>of()), createSlotStatus(bananaId, bananaSelf, bananaExternalUri, "instance", "/location", RUNNING, APPLE_ASSIGNMENT, bananaPath, ImmutableMap.<String, Integer>of())) .addEquivalentGroup( createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", RUNNING, BANANA_ASSIGNMENT, bananaPath, ImmutableMap.<String, Integer>of()), createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", RUNNING, BANANA_ASSIGNMENT, bananaPath, ImmutableMap.<String, Integer>of())) .addEquivalentGroup( createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", STOPPED, APPLE_ASSIGNMENT, applePath, ImmutableMap.<String, Integer>of()), createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", STOPPED, APPLE_ASSIGNMENT, applePath, ImmutableMap.<String, Integer>of())) .addEquivalentGroup( createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", UNKNOWN, APPLE_ASSIGNMENT, applePath, ImmutableMap.<String, Integer>of()), createSlotStatus(appleId, appleSelf, appleExternalUri, "instance", "/location", UNKNOWN, APPLE_ASSIGNMENT, applePath, ImmutableMap.<String, Integer>of())) .check();
lastSlotStatus = new AtomicReference<SlotStatus>(createSlotStatus(id, self, externalUri,
@Test public void testNullFields() { status = new AgentStatus("agent-id", ONLINE, null, null, null, null, null, ImmutableList.<SlotStatus>of(createSlotStatus(UUID.randomUUID(), null, null, null, "/location", UNKNOWN, null, null, ImmutableMap.<String, Integer>of())), ImmutableMap.<String, Integer>of()); assertTrue(new UuidPredicate("agent-id", asList("agent-id", null)).apply(status)); assertTrue(buildFilter("uuid", "agent-id", asList("agent-id", null), ImmutableList.<UUID>of()).apply(status)); assertFalse(new HostPredicate("localhost").apply(status)); assertFalse(buildFilter("host", "localhost").apply(status)); assertFalse(new MachinePredicate("instance-id").apply(status)); assertFalse(buildFilter("machine", "instance-id").apply(status)); } }
@Test public void testNullFields() { status = new AgentStatus("agent-id", ONLINE, null, null, null, null, null, ImmutableList.<SlotStatus>of(createSlotStatus(UUID.randomUUID(), null, null, null, "/location", UNKNOWN, null, null, ImmutableMap.<String, Integer>of())), ImmutableMap.<String, Integer>of()); assertTrue(new UuidPredicate("agent-id", asList("agent-id", null)).apply(status)); assertTrue(buildFilter("uuid", "agent-id", asList("agent-id", null), ImmutableList.<UUID>of()).apply(status)); assertFalse(new HostPredicate("localhost").apply(status)); assertFalse(buildFilter("host", "localhost").apply(status)); assertFalse(new MachinePredicate("instance-id").apply(status)); assertFalse(buildFilter("machine", "instance-id").apply(status)); } }
private void initializeOneAgent() SlotStatus appleSlotStatus1 = createSlotStatus(apple1SotId, URI.create("fake://appleServer1/v1/agent/slot/apple1"), URI.create("fake://appleServer1/v1/agent/slot/apple1"), ImmutableMap.<String, Integer>of()); apple2SlotId = UUID.randomUUID(); SlotStatus appleSlotStatus2 = createSlotStatus(apple2SlotId, URI.create("fake://appleServer2/v1/agent/slot/apple1"), URI.create("fake://appleServer2/v1/agent/slot/apple1"), ImmutableMap.<String, Integer>of()); bananaSlotId = UUID.randomUUID(); SlotStatus bananaSlotStatus = createSlotStatus(bananaSlotId, URI.create("fake://bananaServer/v1/agent/slot/banana"), URI.create("fake://bananaServer/v1/agent/slot/banana"),
private void initializeOneAgent() SlotStatus appleSlotStatus1 = createSlotStatus(apple1SotId, URI.create("fake://appleServer1/v1/agent/slot/apple1"), URI.create("fake://appleServer1/v1/agent/slot/apple1"), ImmutableMap.<String, Integer>of()); apple2SlotId = UUID.randomUUID(); SlotStatus appleSlotStatus2 = createSlotStatus(apple2SlotId, URI.create("fake://appleServer2/v1/agent/slot/apple1"), URI.create("fake://appleServer2/v1/agent/slot/apple1"), ImmutableMap.<String, Integer>of()); bananaSlotId = UUID.randomUUID(); SlotStatus bananaSlotStatus = createSlotStatus(bananaSlotId, URI.create("fake://bananaServer/v1/agent/slot/banana"), URI.create("fake://bananaServer/v1/agent/slot/banana"),
@Test public void testGetAllSlotsWithFilter() SlotStatus slot1 = createSlotStatus(UUID.randomUUID(), URI.create("fake://foo/v1/agent/slot/slot1"), URI.create("fake://foo/v1/agent/slot/slot1"), "/slot1", ImmutableMap.<String, Integer>of()); SlotStatus slot2 = createSlotStatus(UUID.randomUUID(), URI.create("fake://bar/v1/agent/slot/slot2"), URI.create("fake://bar/v1/agent/slot/slot2"),
@Test public void testGetAllSlots() SlotStatus slot1 = createSlotStatus(UUID.randomUUID(), URI.create("fake://localhost/v1/agent/slot/slot1"), URI.create("fake://localhost/v1/agent/slot/slot1"), "/slot1", ImmutableMap.<String, Integer>of()); SlotStatus slot2 = createSlotStatus(UUID.randomUUID(), URI.create("fake://localhost/v1/agent/slot/slot2"), URI.create("fake://localhost/v1/agent/slot/slot2"),
@Test public void testGetAllSlotsWithFilter() SlotStatus slot1 = createSlotStatus(UUID.randomUUID(), URI.create("fake://foo/v1/agent/slot/slot1"), URI.create("fake://foo/v1/agent/slot/slot1"), "/slot1", ImmutableMap.<String, Integer>of()); SlotStatus slot2 = createSlotStatus(UUID.randomUUID(), URI.create("fake://bar/v1/agent/slot/slot2"), URI.create("fake://bar/v1/agent/slot/slot2"),
@Test public void testGetAllSlots() SlotStatus slot1 = createSlotStatus(UUID.randomUUID(), URI.create("fake://localhost/v1/agent/slot/slot1"), URI.create("fake://localhost/v1/agent/slot/slot1"), "/slot1", ImmutableMap.<String, Integer>of()); SlotStatus slot2 = createSlotStatus(UUID.randomUUID(), URI.create("fake://localhost/v1/agent/slot/slot2"), URI.create("fake://localhost/v1/agent/slot/slot2"),
@Test public void testFullBinarySpecPredicate() SlotStatus status = createSlotStatus(UUID.randomUUID(), URI.create("fake://localhost"), URI.create("fake://localhost"),
@Test public void testFullBinarySpecPredicate() SlotStatus status = createSlotStatus(UUID.randomUUID(), URI.create("fake://localhost"), URI.create("fake://localhost"),
SlotStatus slotStatus = createSlotStatus(id, self, externalUri,
@Override public synchronized SlotStatus install(Installation installation) { checkNotNull(installation, "installation is null"); AgentStatus agentStatus = getAgentStatus(); Preconditions.checkState(agentStatus.getState() != OFFLINE, "agent is offline"); UUID slotId = UUID.randomUUID(); SlotStatus slotStatus = createSlotStatus(slotId, uriBuilderFrom(agentStatus.getInternalUri()).appendPath("slot").appendPath(slotId.toString()).build(), uriBuilderFrom(agentStatus.getExternalUri()).appendPath("slot").appendPath(slotId.toString()).build(), "instance", "/location", SlotLifecycleState.STOPPED, installation.getAssignment(), "/" + slotId, installation.getResources()); agentStatus.changeSlotStatus(slotStatus); return slotStatus; }
@Override public synchronized SlotStatus install(Installation installation) { checkNotNull(installation, "installation is null"); AgentStatus agentStatus = getAgentStatus(); Preconditions.checkState(agentStatus.getState() != OFFLINE, "agent is offline"); UUID slotId = UUID.randomUUID(); SlotStatus slotStatus = createSlotStatus(slotId, uriBuilderFrom(agentStatus.getInternalUri()).appendPath("slot").appendPath(slotId.toString()).build(), uriBuilderFrom(agentStatus.getExternalUri()).appendPath("slot").appendPath(slotId.toString()).build(), "instance", "/location", SlotLifecycleState.STOPPED, installation.getAssignment(), "/" + slotId, installation.getResources()); agentStatus.changeSlotStatus(slotStatus); return slotStatus; }
@Test public void testTerminate() throws Exception { // setup assertEquals(slot.assign(APPLE_INSTALLATION).getAssignment(), APPLE_ASSIGNMENT); // test remoteAgent.setStatus(agent.getAgentStatus()); RemoteSlot remoteSlot = new HttpRemoteSlot(slot.status(), client, remoteAgent); SlotStatus actual = remoteSlot.terminate(); // verify SlotStatus expected = createSlotStatus(slot.getId(), slot.getSelf(), slot.getExternalUri(), slot.status().getInstanceId(), slot.status().getLocation(), TERMINATED, null, null, ImmutableMap.<String, Integer>of()); assertEquals(actual, expected); }
assertFalse(buildFilter("assignable", APPLE_ASSIGNMENT.getBinary() + APPLE_ASSIGNMENT.getConfig(), false, repository).apply(status)); SlotStatus slot = createSlotStatus( UUID.fromString("99999999-1234-1234-1234-123456789012"), URI.create("fake://localhost"), assertFalse(buildFilter("assignable", BANANA_ASSIGNMENT.getBinary() + BANANA_ASSIGNMENT.getConfig(), true, repository).apply(status)); slot = createSlotStatus( slot.getId(), slot.getSelf(),