use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class JobPresentationServiceTest method shouldReturnJobModel.
@Test
public void shouldReturnJobModel() throws Exception {
JobInstance dev = assignedWithAgentId("dev", "agent1");
JobInstance DEv = assignedWithAgentId("DEv", "agent1");
JobInstance bev = assignedWithAgentId("bev", "agent2");
JobInstance tev = scheduled("tev");
JobInstance lev = assignAgent(passed("lev"), "agent3");
JobInstance kev = assignAgent(failed("kev"), "agent3");
AgentInstance agentInstance = building();
when(agentService.findAgentAndRefreshStatus(any(String.class))).thenReturn(agentInstance);
List<JobInstanceModel> models = new JobPresentationService(jobDurationStrategy, agentService).jobInstanceModelFor(new JobInstances(dev, bev, tev, lev, kev, DEv));
assertThat(models.size(), is(6));
// failed
assertThat(models.get(0), is(new JobInstanceModel(kev, jobDurationStrategy, agentInstance)));
// in progress. sort by name (case insensitive)
assertThat(models.get(1), is(new JobInstanceModel(bev, jobDurationStrategy, agentInstance)));
assertThat(models.get(2), is(new JobInstanceModel(dev, jobDurationStrategy, agentInstance)));
assertThat(models.get(3), is(new JobInstanceModel(DEv, jobDurationStrategy, agentInstance)));
assertThat(models.get(4), is(new JobInstanceModel(tev, jobDurationStrategy)));
// passed
assertThat(models.get(5), is(new JobInstanceModel(lev, jobDurationStrategy, agentInstance)));
// assert agent info
verify(agentService, times(2)).findAgentAndRefreshStatus("agent1");
verify(agentService).findAgentAndRefreshStatus("agent2");
verify(agentService, times(2)).findAgentAndRefreshStatus("agent3");
verifyNoMoreInteractions(agentService);
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentStatusChangeNotifierTest method shouldNotifyInAbsenceOfPluginsInterestedInAgentStatusNotifications.
@Test
public void shouldNotifyInAbsenceOfPluginsInterestedInAgentStatusNotifications() throws Exception {
AgentInstance agentInstance = AgentInstanceMother.building();
when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(false);
agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
verifyZeroInteractions(pluginNotificationQueue);
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentInstancesTest method shouldUnderstandFilteringAgentListBasedOnUuid.
@Test
public void shouldUnderstandFilteringAgentListBasedOnUuid() {
AgentInstances instances = new AgentInstances(mock(AgentStatusChangeListener.class));
AgentRuntimeInfo agent1 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-1", "host-1", "192.168.1.2"), true, "/foo/bar", 100l, "linux", false);
AgentRuntimeInfo agent2 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-2", "host-2", "192.168.1.3"), true, "/bar/baz", 200l, "linux", false);
AgentRuntimeInfo agent3 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-3", "host-3", "192.168.1.4"), true, "/baz/quux", 300l, "linux", false);
AgentInstance instance1 = AgentInstance.createFromLiveAgent(agent1, systemEnvironment, mock(AgentStatusChangeListener.class));
instances.add(instance1);
instances.add(AgentInstance.createFromLiveAgent(agent2, systemEnvironment, mock(AgentStatusChangeListener.class)));
AgentInstance instance3 = AgentInstance.createFromLiveAgent(agent3, systemEnvironment, mock(AgentStatusChangeListener.class));
instances.add(instance3);
List<AgentInstance> agents = instances.filter(Arrays.asList("uuid-1", "uuid-3"));
assertThat(agents, hasItems(instance1, instance3));
assertThat(agents.size(), is(2));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentInstancesTest method shouldFindAgentsByItHostName.
@Test
public void shouldFindAgentsByItHostName() throws Exception {
AgentInstance idle = AgentInstanceMother.idle(new Date(), "ghost-name");
AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, idle, AgentInstanceMother.building());
AgentInstance byHostname = agentInstances.findFirstByHostname("ghost-name");
assertThat(byHostname, is(idle));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentInstancesTest method shouldReturnNullAgentsWhenHostNameIsNotFound.
@Test
public void shouldReturnNullAgentsWhenHostNameIsNotFound() throws Exception {
AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, AgentInstanceMother.building());
agentInstances.add(idle);
agentInstances.add(building);
AgentInstance byHostname = agentInstances.findFirstByHostname("not-exist");
assertThat(byHostname, is(instanceOf(NullAgentInstance.class)));
}
Aggregations