use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class ConsoleOutputWebsocketTransmitter method consumeLine.
@Override
public void consumeLine(String line) {
ConsoleTransmission transmission = new ConsoleTransmission(line, buildId);
this.webSocketSessionHandler.sendAndWaitForAcknowledgement(new Message(Action.consoleOut, MessageEncoding.encodeData(transmission)));
}
use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsCancelled.
@Test
public void shouldSendCancelMessageIfJobIsCancelled() throws Exception {
AgentConfig agentConfig = AgentMother.remoteAgent();
configHelper.addAgent(agentConfig);
fixture.createPipelineWithFirstStageScheduled();
AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
info.setCookie("cookie");
agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
buildAssignmentService.onTimer();
assertThat(agent.messages.size(), is(1));
Work work = MessageEncoding.decodeWork(agent.messages.get(0).getData());
assertThat(work, instanceOf(BuildWork.class));
BuildAssignment assignment = ((BuildWork) work).getAssignment();
final JobInstance instance = jobInstanceService.buildByIdWithTransitions(assignment.getJobIdentifier().getBuildId());
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jobInstanceService.cancelJob(instance);
}
});
assertThat(agent.messages.size(), is(2));
assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class DefaultBuildStateReporter method reportCompleting.
@Override
public void reportCompleting(String buildId, JobResult buildResult) {
Report report = new Report(agentRuntimeInfo, buildId, null, buildResult);
webSocketSessionHandler.sendAndWaitForAcknowledgement(new Message(Action.reportCompleting, MessageEncoding.encodeData(report)));
}
use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class WebSocketSessionHandlerTest method shouldWaitForAcknowledgementWhileSendingMessages.
@Test
public void shouldWaitForAcknowledgementWhileSendingMessages() throws Exception {
final Message message = new Message(Action.reportCurrentStatus);
when(session.getRemote()).thenReturn(new FakeWebSocketEndpoint(new Runnable() {
@Override
public void run() {
handler.acknowledge(new Message(Action.acknowledge, message.getAcknowledgementId()));
}
}));
Thread sendThread = new Thread(new Runnable() {
@Override
public void run() {
handler.sendAndWaitForAcknowledgement(message);
}
});
sendThread.start();
assertThat(sendThread.isAlive(), is(true));
sendThread.join();
assertThat(sendThread.isAlive(), is(false));
}
use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldAssignMatchedJobToAgentsRegisteredInAgentRemoteHandler.
@Test
public void shouldAssignMatchedJobToAgentsRegisteredInAgentRemoteHandler() throws Exception {
AgentConfig agentConfig = AgentMother.remoteAgent();
configHelper.addAgent(agentConfig);
fixture.createPipelineWithFirstStageScheduled();
AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
info.setCookie("cookie");
agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
AgentInstance agent = agentService.findAgent(agentConfig.getUuid());
assertFalse(agent.isBuilding());
buildAssignmentService.onTimer();
assertThat(this.agent.messages.size(), is(1));
assertThat(MessageEncoding.decodeWork(this.agent.messages.get(0).getData()), instanceOf(BuildWork.class));
assertTrue(agent.isBuilding());
}
Aggregations