Search in sources :

Example 1 with AgentInstruction

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

the class JobRunnerTest method shouldDoNothingWhenJobIsNotCancelled.

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

Example 2 with AgentInstruction

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

the class AgentRemoteHandlerTest method removeRegisteredAgent.

@Test
public void removeRegisteredAgent() throws Exception {
    AgentInstance instance = AgentInstanceMother.idle();
    AgentRuntimeInfo info = new AgentRuntimeInfo(instance.getAgentIdentifier(), AgentRuntimeStatus.Idle, null, null, false);
    when(remote.ping(any(AgentRuntimeInfo.class))).thenReturn(new AgentInstruction(false));
    when(remote.getCookie(instance.getAgentIdentifier(), info.getLocation())).thenReturn("new cookie");
    when(agentService.findAgent(instance.getUuid())).thenReturn(instance);
    handler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    handler.remove(agent);
    assertEquals(0, handler.connectedAgents().size());
    assertEquals(AgentStatus.LostContact, instance.getStatus());
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) Test(org.junit.Test)

Example 3 with AgentInstruction

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

the class AgentRemoteHandlerTest method shouldNotSetDupCookieForSameAgent.

@Test
public void shouldNotSetDupCookieForSameAgent() throws Exception {
    AgentInstance instance = AgentInstanceMother.idle();
    AgentRuntimeInfo info = new AgentRuntimeInfo(instance.getAgentIdentifier(), AgentRuntimeStatus.Idle, null, null, false);
    when(remote.ping(any(AgentRuntimeInfo.class))).thenReturn(new AgentInstruction(false));
    when(remote.getCookie(instance.getAgentIdentifier(), info.getLocation())).thenReturn("cookie");
    when(agentService.findAgent(instance.getUuid())).thenReturn(instance);
    handler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    info.setCookie(null);
    reset(remote);
    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)));
    verify(remote).ping(withCookie(info, "cookie"));
    info.setCookie(null);
    handler.remove(agent);
    reset(remote);
    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)));
    verify(remote).ping(withCookie(info, "new cookie"));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) Test(org.junit.Test)

Example 4 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 5 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)

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