use of com.thoughtworks.go.server.websocket.AgentStub in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldAssignAgentsWhenThereAreAgentsAreDisabledOrNeedReregister.
@Test
public void shouldAssignAgentsWhenThereAreAgentsAreDisabledOrNeedReregister() throws Exception {
fixture.createPipelineWithFirstStageScheduled();
AgentConfig canceledAgentConfig = AgentMother.remoteAgent();
configHelper.addAgent(canceledAgentConfig);
AgentRuntimeInfo canceledAgentInfo = AgentRuntimeInfo.fromServer(canceledAgentConfig, true, "location", 1000000l, "OS", false);
canceledAgentInfo.setCookie("cookie1");
AgentStub canceledAgent = new AgentStub();
agentRemoteHandler.process(canceledAgent, new Message(Action.ping, MessageEncoding.encodeData(canceledAgentInfo)));
AgentInstance agentInstance = agentService.findAgentAndRefreshStatus(canceledAgentInfo.getUUId());
agentInstance.cancel();
AgentConfig needRegisterAgentConfig = AgentMother.remoteAgent();
AgentRuntimeInfo needRegisterAgentInfo = AgentRuntimeInfo.fromServer(needRegisterAgentConfig, true, "location", 1000000l, "OS", false);
agentService.requestRegistration(new Username("bob"), needRegisterAgentInfo);
needRegisterAgentInfo.setCookie("cookie2");
AgentStub needRegisterAgent = new AgentStub();
agentRemoteHandler.process(needRegisterAgent, new Message(Action.ping, MessageEncoding.encodeData(needRegisterAgentInfo)));
AgentConfig assignedAgent = AgentMother.remoteAgent();
configHelper.addAgent(assignedAgent);
AgentRuntimeInfo assignedAgentInfo = AgentRuntimeInfo.fromServer(assignedAgent, true, "location", 1000000l, "OS", false);
assignedAgentInfo.setCookie("cookie3");
agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(assignedAgentInfo)));
buildAssignmentService.onTimer();
assertThat(canceledAgent.messages.size(), is(0));
assertThat(needRegisterAgent.messages.size(), is(1));
assertThat(needRegisterAgent.messages.get(0).getAction(), is(Action.reregister));
assertThat(agent.messages.size(), is(1));
assertThat(MessageEncoding.decodeWork(agent.messages.get(0).getData()), instanceOf(BuildWork.class));
}
use of com.thoughtworks.go.server.websocket.AgentStub in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
configCache = new ConfigCache();
registry = ConfigElementImplementationRegistryMother.withNoPlugins();
configHelper = new GoConfigFileHelper().usingCruiseConfigDao(goConfigDao);
configHelper.onSetUp();
dbHelper.onSetUp();
fixture = new PipelineWithTwoStages(materialRepository, transactionTemplate, temporaryFolder);
fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp();
repository = new SvnCommand(null, testRepo.projectRepositoryUrl());
evolveConfig = configHelper.addPipeline("evolve", STAGE_NAME, repository, "unit");
configHelper.addPipeline("anotherPipeline", STAGE_NAME, repository, "anotherTest");
configHelper.addPipeline("thirdPipeline", STAGE_NAME, repository, "yetAnotherTest");
goConfigService.forceNotifyListeners();
goCache.clear();
u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper);
agent = new AgentStub();
notifier.disableUpdates();
}
use of com.thoughtworks.go.server.websocket.AgentStub in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldOnlyAssignWorkToIdleAgentsRegisteredInAgentRemoteHandler.
@Test
public void shouldOnlyAssignWorkToIdleAgentsRegisteredInAgentRemoteHandler() throws Exception {
AgentConfig agentConfig = AgentMother.remoteAgent();
configHelper.addAgent(agentConfig);
fixture.createPipelineWithFirstStageScheduled();
AgentStatus[] statuses = new AgentStatus[] { AgentStatus.Building, AgentStatus.Pending, AgentStatus.Disabled, AgentStatus.LostContact, AgentStatus.Missing };
for (AgentStatus status : statuses) {
AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
info.setCookie("cookie");
info.setStatus(status);
agent = new AgentStub();
agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
buildAssignmentService.onTimer();
assertThat("Should not assign work when agent status is " + status, agent.messages.size(), is(0));
}
}
Aggregations