Search in sources :

Example 1 with BuildAssignmentService

use of com.thoughtworks.go.server.service.BuildAssignmentService in project gocd by gocd.

the class WorkFinderTest method shouldReturnNoWorkInCaseOfAnErrorIsThrown.

@Test
public void shouldReturnNoWorkInCaseOfAnErrorIsThrown() {
    BuildAssignmentService assigner = mock(BuildAssignmentService.class);
    IdleAgentTopic idleTopic = mock(IdleAgentTopic.class);
    WorkAssignedTopic assignedTopic = mock(WorkAssignedTopic.class);
    WorkFinder finder = new WorkFinder(assigner, idleTopic, assignedTopic, workAssignmentPerformanceLogger);
    AgentRuntimeInfo runtimeInfo = AgentRuntimeInfo.initialState(AgentMother.approvedAgent());
    when(assigner.assignWorkToAgent(runtimeInfo.getIdentifier())).thenThrow(new OutOfMemoryError("test error for martians"));
    try {
        finder.onMessage(new IdleAgentMessage(runtimeInfo));
        fail("should have propagated error");
    } catch (OutOfMemoryError e) {
        String message = e.getMessage();
        if (message != null && message.equals("test error for martians")) {
        //expected
        } else {
            throw e;
        }
    }
    verify(assignedTopic).post(new WorkAssignedMessage(runtimeInfo.getIdentifier(), new NoWork()));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) NoWork(com.thoughtworks.go.remote.work.NoWork) BuildAssignmentService(com.thoughtworks.go.server.service.BuildAssignmentService) Test(org.junit.Test)

Aggregations

NoWork (com.thoughtworks.go.remote.work.NoWork)1 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)1 BuildAssignmentService (com.thoughtworks.go.server.service.BuildAssignmentService)1 Test (org.junit.Test)1