use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.
the class AgentRemoteHandlerTest method sendCancelMessage.
@Test
public void sendCancelMessage() throws Exception {
AgentInstance instance = AgentInstanceMother.idle();
AgentRuntimeInfo info = new AgentRuntimeInfo(instance.getAgentIdentifier(), AgentRuntimeStatus.Idle, null, null, false);
when(agentService.findAgentAndRefreshStatus(instance.getUuid())).thenReturn(instance);
when(remote.ping(any(AgentRuntimeInfo.class))).thenReturn(new AgentInstruction(false));
when(remote.getCookie(instance.getAgentIdentifier(), info.getLocation())).thenReturn("new cookie");
handler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
agent.messages.clear();
handler.sendCancelMessage(instance.getAgentIdentifier().getUuid());
assertEquals(1, agent.messages.size());
}
use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.
the class AgentRemoteHandlerTest method registerConnectedAgentsByPing.
@Test
public void registerConnectedAgentsByPing() throws Exception {
AgentInstance instance = AgentInstanceMother.idle();
AgentRuntimeInfo info = new AgentRuntimeInfo(instance.getAgentIdentifier(), AgentRuntimeStatus.Idle, null, "cookie", false);
when(remote.ping(info)).thenReturn(new AgentInstruction(false));
handler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
verify(remote).ping(info);
assertEquals(1, handler.connectedAgents().size());
assertEquals(agent, handler.connectedAgents().get(instance.getUuid()));
assertTrue(agent.messages.isEmpty());
}
use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.
the class AgentRemoteHandlerTest method shouldSetCookieIfNoCookieFoundWhenAgentPingsServer.
@Test
public void shouldSetCookieIfNoCookieFoundWhenAgentPingsServer() throws Exception {
AgentIdentifier identifier = new AgentIdentifier("HostName", "ipAddress", "uuid");
AgentRuntimeInfo info = new AgentRuntimeInfo(identifier, AgentRuntimeStatus.Idle, null, null, false);
when(remote.getCookie(identifier, info.getLocation())).thenReturn("new cookie");
when(remote.ping(any(AgentRuntimeInfo.class))).thenReturn(new AgentInstruction(false));
handler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
verify(remote).ping(withCookie(info, "new cookie"));
assertEquals(1, agent.messages.size());
assertEquals(agent.messages.get(0).getAction(), Action.setCookie);
assertEquals(MessageEncoding.decodeData(agent.messages.get(0).getData(), String.class), "new cookie");
}
use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.
the class AgentRemoteHandlerTest method shouldSendBackAnAcknowledgementMessageIfMessageHasAcknowledgementId.
@Test
public void shouldSendBackAnAcknowledgementMessageIfMessageHasAcknowledgementId() throws Exception {
AgentInstance instance = AgentInstanceMother.idle();
AgentRuntimeInfo info = new AgentRuntimeInfo(instance.getAgentIdentifier(), AgentRuntimeStatus.Idle, null, null, false);
info.setCookie("cookie");
agent.setIgnoreAcknowledgements(false);
when(remote.ping(info)).thenReturn(new AgentInstruction(false));
when(agentService.findAgent(instance.getUuid())).thenReturn(instance);
Message msg = new Message(Action.ping, MessageEncoding.encodeData(info));
handler.process(agent, msg);
assertEquals(1, agent.messages.size());
assertEquals(Action.acknowledge, agent.messages.get(0).getAction());
assertEquals(msg.getAcknowledgementId(), MessageEncoding.decodeData(agent.messages.get(0).getData(), String.class));
}
Aggregations