use of com.thoughtworks.go.work.SleepWork in project gocd by gocd.
the class AgentWebSocketClientControllerTest method processAssignWorkActionWithConsoleLogsThroughWebSockets.
@Test
public void processAssignWorkActionWithConsoleLogsThroughWebSockets() throws IOException, InterruptedException {
SystemEnvironment env = new SystemEnvironment();
env.set(SystemEnvironment.WEBSOCKET_ENABLED, true);
env.set(SystemEnvironment.CONSOLE_LOGS_THROUGH_WEBSOCKET_ENABLED, true);
ArgumentCaptor<Message> argumentCaptor = ArgumentCaptor.forClass(Message.class);
agentController = createAgentController();
agentController.init();
agentController.process(new Message(Action.assignWork, MessageEncoding.encodeWork(new SleepWork("work1", 0))));
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
verify(webSocketSessionHandler, times(2)).sendAndWaitForAcknowledgement(argumentCaptor.capture());
verify(artifactsManipulator).setProperty(null, new Property("work1_result", "done"));
Message message = argumentCaptor.getAllValues().get(1);
assertThat(message.getAcknowledgementId(), notNullValue());
assertThat(message.getAction(), is(Action.ping));
assertThat(message.getData(), is(MessageEncoding.encodeData(agentController.getAgentRuntimeInfo())));
Message message2 = argumentCaptor.getAllValues().get(0);
assertThat(message2.getAcknowledgementId(), notNullValue());
assertThat(message2.getAction(), is(Action.consoleOut));
ConsoleTransmission ct = MessageEncoding.decodeData(message2.getData(), ConsoleTransmission.class);
assertThat(ct.getLine(), RegexMatcher.matches("Sleeping for 0 milliseconds"));
env.set(SystemEnvironment.WEBSOCKET_ENABLED, false);
env.set(SystemEnvironment.CONSOLE_LOGS_THROUGH_WEBSOCKET_ENABLED, false);
}
use of com.thoughtworks.go.work.SleepWork in project gocd by gocd.
the class AgentWebSocketClientControllerTest method shouldCancelPreviousRunningJobIfANewAssignWorkMessageIsReceived.
@Test
public void shouldCancelPreviousRunningJobIfANewAssignWorkMessageIsReceived() throws IOException, InterruptedException {
agentController = createAgentController();
agentController.init();
final SleepWork work1 = new SleepWork("work1", MAX_WAIT_IN_TEST);
Thread work1Thread = new Thread(new Runnable() {
@Override
public void run() {
try {
agentController.process(new Message(Action.assignWork, MessageEncoding.encodeWork(work1)));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
work1Thread.start();
waitForAgentRuntimeState(agentController.getAgentRuntimeInfo(), AgentRuntimeStatus.Building);
SleepWork work2 = new SleepWork("work2", 1);
agentController.process(new Message(Action.assignWork, MessageEncoding.encodeWork(work2)));
work1Thread.join(MAX_WAIT_IN_TEST);
verify(artifactsManipulator).setProperty(null, new Property("work1_result", "done_canceled"));
verify(artifactsManipulator).setProperty(null, new Property("work2_result", "done"));
}
use of com.thoughtworks.go.work.SleepWork in project gocd by gocd.
the class AgentWebSocketClientControllerTest method processAssignWorkAction.
@Test
public void processAssignWorkAction() throws IOException, InterruptedException {
ArgumentCaptor<Message> argumentCaptor = ArgumentCaptor.forClass(Message.class);
agentController = createAgentController();
agentController.init();
agentController.process(new Message(Action.assignWork, MessageEncoding.encodeWork(new SleepWork("work1", 0))));
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
verify(webSocketSessionHandler, times(1)).sendAndWaitForAcknowledgement(argumentCaptor.capture());
verify(artifactsManipulator).setProperty(null, new Property("work1_result", "done"));
Message message = argumentCaptor.getAllValues().get(0);
assertThat(message.getAcknowledgementId(), notNullValue());
assertThat(message.getAction(), is(Action.ping));
assertThat(message.getData(), is(MessageEncoding.encodeData(agentController.getAgentRuntimeInfo())));
}
use of com.thoughtworks.go.work.SleepWork in project gocd by gocd.
the class AgentWebSocketClientControllerTest method processCancelJobAction.
@Test
public void processCancelJobAction() throws IOException, InterruptedException {
agentController = createAgentController();
agentController.init();
final SleepWork sleep1secWork = new SleepWork("work1", MAX_WAIT_IN_TEST);
Thread buildingThread = new Thread(new Runnable() {
@Override
public void run() {
try {
agentController.process(new Message(Action.assignWork, MessageEncoding.encodeWork(sleep1secWork)));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
buildingThread.start();
waitForAgentRuntimeState(agentController.getAgentRuntimeInfo(), AgentRuntimeStatus.Building);
agentController.process(new Message(Action.cancelBuild));
buildingThread.join(MAX_WAIT_IN_TEST);
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
verify(artifactsManipulator).setProperty(null, new Property("work1_result", "done_canceled"));
}
Aggregations