Search in sources :

Example 6 with AgentInstruction

use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.

the class JobRunnerTest method shouldCancelOncePerJob.

@Test
public void shouldCancelOncePerJob() {
    runner.setWork(work);
    runner.handleInstruction(new AgentInstruction(true), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false));
    assertThat(work.getCallCount(), is(1));
    runner.handleInstruction(new AgentInstruction(true), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false));
    assertThat(work.getCallCount(), is(1));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) Test(org.junit.Test)

Example 7 with AgentInstruction

use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.

the class JobRunnerTest method shouldReturnTrueOnGetJobIsCancelledWhenJobIsCancelled.

@Test
public void shouldReturnTrueOnGetJobIsCancelledWhenJobIsCancelled() {
    assertThat(runner.isJobCancelled(), is(false));
    runner.handleInstruction(new AgentInstruction(true), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false));
    assertThat(runner.isJobCancelled(), is(true));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) Test(org.junit.Test)

Example 8 with AgentInstruction

use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.

the class AgentRemoteHandlerTest method shouldSetCookieAndCancelJobWhenPingServerWithoutCookieAndServerSideRuntimeStatusIsCanceled.

@Test
public void shouldSetCookieAndCancelJobWhenPingServerWithoutCookieAndServerSideRuntimeStatusIsCanceled() 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(true));
    handler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    verify(remote).ping(withCookie(info, "new cookie"));
    assertEquals(2, agent.messages.size());
    assertEquals(agent.messages.get(0).getAction(), Action.setCookie);
    assertEquals(MessageEncoding.decodeData(agent.messages.get(0).getData(), String.class), "new cookie");
    assertEquals(agent.messages.get(1).getAction(), Action.cancelBuild);
}
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 9 with AgentInstruction

use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.

the class AgentRemoteHandlerTest method shouldCancelJobIfAgentRuntimeStatusIsCanceledOnSeverSideWhenClientPingsServer.

@Test
public void shouldCancelJobIfAgentRuntimeStatusIsCanceledOnSeverSideWhenClientPingsServer() throws Exception {
    AgentRuntimeInfo info = new AgentRuntimeInfo(new AgentIdentifier("HostName", "ipAddress", "uuid"), AgentRuntimeStatus.Idle, null, null, false);
    info.setCookie("cookie");
    when(remote.ping(info)).thenReturn(new AgentInstruction(true));
    handler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    verify(remote).ping(info);
    assertEquals(1, handler.connectedAgents().size());
    assertEquals(agent, handler.connectedAgents().get("uuid"));
    assertEquals(1, agent.messages.size());
    assertEquals(agent.messages.get(0).getAction(), Action.cancelBuild);
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.Test)

Example 10 with AgentInstruction

use of com.thoughtworks.go.remote.AgentInstruction in project gocd by gocd.

the class AgentRemoteHandlerTest method shouldCancelBuildIfAgentRuntimeStatusIsCanceledOnSeverSideWhenClientWithBuildCommandSupportPingsServer.

@Test
public void shouldCancelBuildIfAgentRuntimeStatusIsCanceledOnSeverSideWhenClientWithBuildCommandSupportPingsServer() throws Exception {
    AgentRuntimeInfo info = new AgentRuntimeInfo(new AgentIdentifier("HostName", "ipAddress", "uuid"), AgentRuntimeStatus.Idle, null, null, true);
    info.setCookie("cookie");
    when(remote.ping(info)).thenReturn(new AgentInstruction(true));
    handler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    verify(remote).ping(info);
    assertEquals(1, handler.connectedAgents().size());
    assertEquals(agent, handler.connectedAgents().get("uuid"));
    assertEquals(1, agent.messages.size());
    assertEquals(agent.messages.get(0).getAction(), Action.cancelBuild);
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) 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