Search in sources :

Example 11 with AgentInstruction

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());
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) Test(org.junit.Test)

Example 12 with AgentInstruction

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());
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) Test(org.junit.Test)

Example 13 with AgentInstruction

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");
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 14 with AgentInstruction

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));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

AgentInstruction (com.thoughtworks.go.remote.AgentInstruction)14 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)13 Test (org.junit.Test)12 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 File (java.io.File)1