Search in sources :

Example 1 with AgentStub

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));
}
Also used : Message(com.thoughtworks.go.websocket.Message) Username(com.thoughtworks.go.server.domain.Username) BuildWork(com.thoughtworks.go.remote.work.BuildWork) AgentStub(com.thoughtworks.go.server.websocket.AgentStub)

Example 2 with AgentStub

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();
}
Also used : PipelineWithTwoStages(com.thoughtworks.go.fixture.PipelineWithTwoStages) SvnCommand(com.thoughtworks.go.domain.materials.svn.SvnCommand) AgentStub(com.thoughtworks.go.server.websocket.AgentStub)

Example 3 with AgentStub

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));
    }
}
Also used : Message(com.thoughtworks.go.websocket.Message) AgentStub(com.thoughtworks.go.server.websocket.AgentStub)

Aggregations

AgentStub (com.thoughtworks.go.server.websocket.AgentStub)3 Message (com.thoughtworks.go.websocket.Message)2 SvnCommand (com.thoughtworks.go.domain.materials.svn.SvnCommand)1 PipelineWithTwoStages (com.thoughtworks.go.fixture.PipelineWithTwoStages)1 BuildWork (com.thoughtworks.go.remote.work.BuildWork)1 Username (com.thoughtworks.go.server.domain.Username)1