use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class AgentInstanceTest method shouldInitializeTheLastHeardTimeWhenFirstPing.
@Test
public void shouldInitializeTheLastHeardTimeWhenFirstPing() throws Exception {
AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class));
Date time = agentInstance.getLastHeardTime();
assertThat(time, is(nullValue()));
agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false));
time = agentInstance.getLastHeardTime();
assertThat(time, is(not(nullValue())));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class AgentInstanceTest method shouldUpdateTheLastHeardTime.
@Test
public void shouldUpdateTheLastHeardTime() throws Exception {
AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class));
agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false));
Date time = agentInstance.getLastHeardTime();
Thread.sleep(1000);
agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false));
Date newtime = agentInstance.getLastHeardTime();
assertThat(newtime.after(time), is(true));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class AgentInstanceTest method shouldBeLostContactWhenLastHeardTimeExeedTimeOut.
@Test
public void shouldBeLostContactWhenLastHeardTimeExeedTimeOut() {
AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment() {
public int getAgentConnectionTimeout() {
return -1;
}
}, mock(AgentStatusChangeListener.class));
assertThat(instance.getStatus(), is(AgentStatus.Missing));
instance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false));
instance.refresh();
assertThat(instance.getStatus(), is(AgentStatus.LostContact));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class AgentInstanceMother method idle.
public static AgentInstance idle(final Date lastHeardAt, final String hostname, SystemEnvironment systemEnvironment) {
AgentConfig idleAgentConfig = new AgentConfig("uuid2", hostname, "10.18.5.1");
AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(idleAgentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
agentRuntimeInfo.setLocation("/var/lib/foo");
agentRuntimeInfo.idle();
agentRuntimeInfo.setUsableSpace(10 * 1024l);
AgentInstance agentInstance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, systemEnvironment, mock(AgentStatusChangeListener.class));
agentInstance.idle();
agentInstance.update(agentRuntimeInfo);
ReflectionUtil.setField(agentInstance, "lastHeardTime", lastHeardAt);
return agentInstance;
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class AgentInstanceMother method updateRuntimeStatus.
public static AgentInstance updateRuntimeStatus(AgentInstance agentInstance, AgentRuntimeStatus status) {
AgentConfig agentConfig = agentInstance.agentConfig();
AgentRuntimeInfo newRuntimeInfo = AgentRuntimeInfo.fromServer(agentConfig, true, agentInstance.getLocation(), agentInstance.getUsableSpace(), "linux", false);
newRuntimeInfo.setRuntimeStatus(status);
agentInstance.update(newRuntimeInfo);
return agentInstance;
}
Aggregations