Search in sources :

Example 16 with Message

use of com.thoughtworks.go.websocket.Message in project gocd by gocd.

the class BuildAssignmentServiceIntegrationTest method shouldNotAssignWorkToCanceledAgentsRegisteredInAgentRemoteHandler.

@Test
public void shouldNotAssignWorkToCanceledAgentsRegisteredInAgentRemoteHandler() 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 agentInstance = agentService.findAgentAndRefreshStatus(info.getUUId());
    agentInstance.cancel();
    buildAssignmentService.onTimer();
    assertThat("Should not assign work when agent status is Canceled", agent.messages.size(), is(0));
}
Also used : Message(com.thoughtworks.go.websocket.Message)

Example 17 with Message

use of com.thoughtworks.go.websocket.Message in project gocd by gocd.

the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsRescheduled.

@Test
public void shouldSendCancelMessageIfJobIsRescheduled() 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));
    assertThat(MessageEncoding.decodeWork(agent.messages.get(0).getData()), instanceOf(BuildWork.class));
    BuildWork work = (BuildWork) MessageEncoding.decodeWork(agent.messages.get(0).getData());
    JobPlan jobPlan = work.getAssignment().getPlan();
    final JobInstance instance = jobInstanceService.buildByIdWithTransitions(jobPlan.getJobId());
    scheduleService.rescheduleJob(instance);
    assertThat(agent.messages.size(), is(2));
    assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Message(com.thoughtworks.go.websocket.Message) JobPlan(com.thoughtworks.go.domain.JobPlan) JobInstance(com.thoughtworks.go.domain.JobInstance) BuildWork(com.thoughtworks.go.remote.work.BuildWork)

Aggregations

Message (com.thoughtworks.go.websocket.Message)17 BuildWork (com.thoughtworks.go.remote.work.BuildWork)4 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 JobInstance (com.thoughtworks.go.domain.JobInstance)2 JobPlan (com.thoughtworks.go.domain.JobPlan)2 Username (com.thoughtworks.go.server.domain.Username)2 AgentStub (com.thoughtworks.go.server.websocket.AgentStub)2 Report (com.thoughtworks.go.websocket.Report)2 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 Work (com.thoughtworks.go.remote.work.Work)1 Agent (com.thoughtworks.go.server.websocket.Agent)1 ConsoleTransmission (com.thoughtworks.go.websocket.ConsoleTransmission)1 Map (java.util.Map)1 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1