Search in sources :

Example 16 with AgentInstance

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);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) JobInstance(com.thoughtworks.go.domain.JobInstance) JobInstanceModel(com.thoughtworks.go.server.ui.JobInstanceModel) JobInstances(com.thoughtworks.go.domain.JobInstances) Test(org.junit.Test)

Example 17 with AgentInstance

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);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Test(org.junit.Test)

Example 18 with AgentInstance

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));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentConfig(com.thoughtworks.go.config.AgentConfig) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.Test)

Example 19 with AgentInstance

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));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) Date(java.util.Date) Test(org.junit.Test)

Example 20 with AgentInstance

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)));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) Test(org.junit.Test)

Aggregations

AgentInstance (com.thoughtworks.go.domain.AgentInstance)95 Test (org.junit.Test)68 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)27 ArrayList (java.util.ArrayList)21 AgentConfig (com.thoughtworks.go.config.AgentConfig)20 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)17 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)9 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)9 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)7 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)7 Username (com.thoughtworks.go.server.domain.Username)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)5 ResponseEntity (org.springframework.http.ResponseEntity)4 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)3 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)3 BuildWork (com.thoughtworks.go.remote.work.BuildWork)3 NoWork (com.thoughtworks.go.remote.work.NoWork)3 Work (com.thoughtworks.go.remote.work.Work)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3 AgentViewModel (com.thoughtworks.go.server.ui.AgentViewModel)3