Search in sources :

Example 76 with AgentIdentifier

use of com.thoughtworks.go.remote.AgentIdentifier 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 77 with AgentIdentifier

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

the class AgentRemoteHandlerTest method reportCurrentStatus.

@Test
public void reportCurrentStatus() throws Exception {
    AgentRuntimeInfo info = new AgentRuntimeInfo(new AgentIdentifier("HostName", "ipAddress", "uuid"), AgentRuntimeStatus.Idle, null, null, false);
    JobIdentifier jobIdentifier = new JobIdentifier();
    handler.process(agent, new Message(Action.reportCurrentStatus, MessageEncoding.encodeData(new Report(info, jobIdentifier, JobState.Preparing))));
    verify(remote).reportCurrentStatus(info, jobIdentifier, JobState.Preparing);
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.Test)

Example 78 with AgentIdentifier

use of com.thoughtworks.go.remote.AgentIdentifier 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 79 with AgentIdentifier

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

the class AgentRemoteHandlerTest method reportCompleting.

@Test
public void reportCompleting() throws Exception {
    AgentRuntimeInfo info = new AgentRuntimeInfo(new AgentIdentifier("HostName", "ipAddress", "uuid"), AgentRuntimeStatus.Idle, null, null, false);
    JobIdentifier jobIdentifier = new JobIdentifier();
    handler.process(agent, new Message(Action.reportCompleting, MessageEncoding.encodeData(new Report(info, jobIdentifier, JobResult.Passed))));
    verify(remote).reportCompleting(info, jobIdentifier, JobResult.Passed);
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.Test)

Example 80 with AgentIdentifier

use of com.thoughtworks.go.remote.AgentIdentifier 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

AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)81 Test (org.junit.Test)57 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)34 FakeBuildRepositoryRemote (com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote)12 Before (org.junit.Before)11 UploadEntry (com.thoughtworks.go.matchers.UploadEntry)10 ArrayList (java.util.ArrayList)10 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)9 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)9 File (java.io.File)9 AgentConfig (com.thoughtworks.go.config.AgentConfig)5 AgentInstance (com.thoughtworks.go.domain.AgentInstance)5 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)5 AgentInstruction (com.thoughtworks.go.remote.AgentInstruction)4 NoWork (com.thoughtworks.go.remote.work.NoWork)4 Work (com.thoughtworks.go.remote.work.Work)4 Agent (com.thoughtworks.go.server.domain.Agent)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)2