Search in sources :

Example 11 with AgentRuntimeInfo

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

Example 12 with AgentRuntimeInfo

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

Example 13 with AgentRuntimeInfo

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

Example 14 with AgentRuntimeInfo

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

Example 15 with AgentRuntimeInfo

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))));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)150 Test (org.junit.jupiter.api.Test)70 Test (org.junit.Test)52 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)35 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)29 File (java.io.File)17 RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)16 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14 Agent (com.thoughtworks.go.config.Agent)13 AgentInstruction (com.thoughtworks.go.remote.AgentInstruction)13 FakeBuildRepositoryRemote (com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote)12 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)11 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)11 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)11 UploadEntry (com.thoughtworks.go.matchers.UploadEntry)10 ArrayList (java.util.ArrayList)10 StringContains.containsString (org.hamcrest.core.StringContains.containsString)9 AgentInstance (com.thoughtworks.go.domain.AgentInstance)8 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)8 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)7