use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class BuildWorkTest method shouldReportBuildIsFailedWhenAntBuildPassed.
@Test
public void shouldReportBuildIsFailedWhenAntBuildPassed() throws Exception {
buildWork = (BuildWork) getWork(WILL_PASS, PIPELINE_NAME);
buildWork.doWork(agentIdentifier, buildRepository, artifactManipulator, environmentVariableContext, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension);
assertThat(buildRepository.results, containsResult(Passed));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class WorkFinderTest method shouldDoNothingIfNoWorkIsAvailable.
@Test
public void shouldDoNothingIfNoWorkIsAvailable() {
context.checking(new Expectations() {
{
one(workAssigner).assignWorkToAgent(AGENT_1);
will(returnValue(NO_WORK));
one(assignedWorkTopic).post(new WorkAssignedMessage(AGENT_1, NO_WORK));
}
});
finder.onMessage(new IdleAgentMessage(new AgentRuntimeInfo(AGENT_1, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class WorkFinderTest method shouldAssignWorkIfItIsAvailable.
@Test
public void shouldAssignWorkIfItIsAvailable() {
context.checking(new Expectations() {
{
one(workAssigner).assignWorkToAgent(AGENT_1);
will(returnValue(SOME_WORK));
one(assignedWorkTopic).post(new WorkAssignedMessage(AGENT_1, SOME_WORK));
}
});
finder.onMessage(new IdleAgentMessage(new AgentRuntimeInfo(AGENT_1, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class AgentWebSocketClientControllerTest method processBuildCommandWithConsoleLogsThroughWebSockets.
@Test
public void processBuildCommandWithConsoleLogsThroughWebSockets() throws Exception {
ArgumentCaptor<Message> currentStatusMessageCaptor = ArgumentCaptor.forClass(Message.class);
when(systemEnvironment.isConsoleLogsThroughWebsocketEnabled()).thenReturn(true);
when(agentRegistry.uuid()).thenReturn(agentUuid);
agentController = createAgentController();
agentController.init();
BuildSettings build = new BuildSettings();
build.setBuildId("b001");
build.setConsoleUrl("http://foo.bar/console");
build.setArtifactUploadBaseUrl("http://foo.bar/artifacts");
build.setPropertyBaseUrl("http://foo.bar/properties");
build.setBuildLocator("build1");
build.setBuildLocatorForDisplay("build1ForDisplay");
build.setBuildCommand(BuildCommand.compose(BuildCommand.echo("building"), BuildCommand.reportCurrentStatus(JobState.Building)));
agentController.process(new Message(Action.build, MessageEncoding.encodeData(build)));
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
AgentRuntimeInfo agentRuntimeInfo = cloneAgentRuntimeInfo(agentController.getAgentRuntimeInfo());
agentRuntimeInfo.busy(new AgentBuildingInfo("build1ForDisplay", "build1"));
verify(webSocketSessionHandler, times(3)).sendAndWaitForAcknowledgement(currentStatusMessageCaptor.capture());
Message consoleOutMsg = currentStatusMessageCaptor.getAllValues().get(0);
assertThat(consoleOutMsg.getAcknowledgementId(), notNullValue());
assertThat(consoleOutMsg.getAction(), is(Action.consoleOut));
ConsoleTransmission ct = MessageEncoding.decodeData(consoleOutMsg.getData(), ConsoleTransmission.class);
assertThat(ct.getLine(), RegexMatcher.matches("building"));
assertEquals(ct.getBuildId(), "b001");
Message message = currentStatusMessageCaptor.getAllValues().get(1);
assertThat(message.getAcknowledgementId(), notNullValue());
assertThat(message.getAction(), is(Action.reportCurrentStatus));
assertThat(message.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", JobState.Building, null))));
Message jobCompletedMessage = currentStatusMessageCaptor.getAllValues().get(2);
assertThat(jobCompletedMessage.getAcknowledgementId(), notNullValue());
assertThat(jobCompletedMessage.getAction(), is(Action.reportCompleted));
assertThat(jobCompletedMessage.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", null, JobResult.Passed))));
}
use of com.thoughtworks.go.server.service.AgentRuntimeInfo in project gocd by gocd.
the class AgentWebSocketClientControllerTest method processBuildCommand.
@Test
public void processBuildCommand() throws Exception {
ArgumentCaptor<Message> currentStatusMessageCaptor = ArgumentCaptor.forClass(Message.class);
when(agentRegistry.uuid()).thenReturn(agentUuid);
CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(httpService.execute(any())).thenReturn(httpResponse);
agentController = createAgentController();
agentController.init();
BuildSettings build = new BuildSettings();
build.setBuildId("b001");
build.setConsoleUrl("http://foo.bar/console");
build.setArtifactUploadBaseUrl("http://foo.bar/artifacts");
build.setPropertyBaseUrl("http://foo.bar/properties");
build.setBuildLocator("build1");
build.setBuildLocatorForDisplay("build1ForDisplay");
build.setBuildCommand(BuildCommand.compose(BuildCommand.echo("building"), BuildCommand.reportCurrentStatus(JobState.Building)));
agentController.process(new Message(Action.build, MessageEncoding.encodeData(build)));
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
AgentRuntimeInfo agentRuntimeInfo = cloneAgentRuntimeInfo(agentController.getAgentRuntimeInfo());
agentRuntimeInfo.busy(new AgentBuildingInfo("build1ForDisplay", "build1"));
verify(webSocketSessionHandler, times(2)).sendAndWaitForAcknowledgement(currentStatusMessageCaptor.capture());
Message message = currentStatusMessageCaptor.getAllValues().get(0);
assertThat(message.getAcknowledgementId(), notNullValue());
assertThat(message.getAction(), is(Action.reportCurrentStatus));
assertThat(message.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", JobState.Building, null))));
Message jobCompletedMessage = currentStatusMessageCaptor.getAllValues().get(1);
assertThat(jobCompletedMessage.getAcknowledgementId(), notNullValue());
assertThat(jobCompletedMessage.getAction(), is(Action.reportCompleted));
assertThat(jobCompletedMessage.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", null, JobResult.Passed))));
}
Aggregations