Search in sources :

Example 1 with JobState

use of com.thoughtworks.go.domain.JobState in project gocd by gocd.

the class BuildRepositoryServiceTest method shouldNotUpdateStatusFromWrongAgent.

@Test(expected = RuntimeException.class)
public void shouldNotUpdateStatusFromWrongAgent() throws Exception {
    final JobState state = JobState.Assigned;
    final JobInstance instance = context.mock(JobInstance.class);
    context.checking(new Expectations() {

        {
            one(instance).isNull();
            will(returnValue(false));
            one(instance).getResult();
            will(returnValue(JobResult.Unknown));
            one(jobInstanceService).buildByIdWithTransitions(jobIdendifier.getBuildId());
            will(returnValue(instance));
            one(instance).getState();
            one(instance).changeState(with(equal(state)));
            one(jobInstanceService).updateStateAndResult(instance);
            atLeast(1).of(instance).getAgentUuid();
            will(returnValue(agentUuid));
        }
    });
    buildRepositoryService.updateStatusFromAgent(jobIdendifier, state, "wrongId");
}
Also used : Expectations(org.jmock.Expectations) JobInstance(com.thoughtworks.go.domain.JobInstance) NullJobInstance(com.thoughtworks.go.domain.NullJobInstance) JobState(com.thoughtworks.go.domain.JobState) Test(org.junit.Test)

Example 2 with JobState

use of com.thoughtworks.go.domain.JobState in project gocd by gocd.

the class BuildStateTypeHandlerCallbackTest method shouldReturnScheduledWhenGivenStringScheduled.

@Test
public void shouldReturnScheduledWhenGivenStringScheduled() throws SQLException {
    context.checking(new Expectations() {

        {
            one(resultGetter).getString();
            will(returnValue(JobState.Scheduled.toString()));
        }
    });
    BuildStateTypeHandlerCallback callback = new BuildStateTypeHandlerCallback();
    JobState result = (JobState) callback.getResult(resultGetter);
    assertThat(result, is(equal(JobState.Scheduled)));
}
Also used : Expectations(org.jmock.Expectations) JobState(com.thoughtworks.go.domain.JobState) BuildStateTypeHandlerCallback(com.thoughtworks.go.server.dao.handlers.BuildStateTypeHandlerCallback) Test(org.junit.Test)

Example 3 with JobState

use of com.thoughtworks.go.domain.JobState in project gocd by gocd.

the class BuildRepositoryServiceTest method shouldUpdateStatusFromAssignedAgent.

@Test
public void shouldUpdateStatusFromAssignedAgent() throws Exception {
    JobState state = JobState.Completing;
    buildRepositoryService.updateStatusFromAgent(jobInstance.getIdentifier(), state, agentUuid);
    verify(scheduleService).updateJobStatus(jobInstance.getIdentifier(), state);
}
Also used : JobState(com.thoughtworks.go.domain.JobState) Test(org.junit.jupiter.api.Test)

Example 4 with JobState

use of com.thoughtworks.go.domain.JobState in project gocd by gocd.

the class BuildRepositoryRemoteImpl method reportCompleted.

public void reportCompleted(final AgentRuntimeInfo agentRuntimeInfo, final JobIdentifier jobIdentifier, final JobResult result) {
    final JobState state = JobState.Completed;
    handleFailuresDuringReporting(agentRuntimeInfo, jobIdentifier, "status and result", String.format("%s, %s", state, result), () -> {
        // TODO: may be i don't belong here, ping already updates agent runtime info
        agentService.updateRuntimeInfo(agentRuntimeInfo);
        buildRepositoryService.completing(jobIdentifier, result, agentRuntimeInfo.getUUId());
        buildRepositoryService.updateStatusFromAgent(jobIdentifier, state, agentRuntimeInfo.getUUId());
        jobStatusTopic.post(new JobStatusMessage(jobIdentifier, state, agentRuntimeInfo.getUUId()));
    });
}
Also used : JobStatusMessage(com.thoughtworks.go.server.messaging.JobStatusMessage) JobState(com.thoughtworks.go.domain.JobState)

Example 5 with JobState

use of com.thoughtworks.go.domain.JobState in project gocd by gocd.

the class BuildStateTypeHandlerCallbackTest method shouldReturnStateWithStringColumnName.

@Test
public void shouldReturnStateWithStringColumnName() throws SQLException {
    ResultSet rs = mock(ResultSet.class);
    when(rs.getString("foo")).thenReturn(JobState.Scheduled.toString());
    BuildStateTypeHandlerCallback callback = new BuildStateTypeHandlerCallback(JobState.class);
    JobState result = callback.getResult(rs, "foo");
    assertThat(result, is(JobState.Scheduled));
}
Also used : ResultSet(java.sql.ResultSet) JobState(com.thoughtworks.go.domain.JobState) BuildStateTypeHandlerCallback(com.thoughtworks.go.server.dao.handlers.BuildStateTypeHandlerCallback) Test(org.junit.jupiter.api.Test)

Aggregations

JobState (com.thoughtworks.go.domain.JobState)8 BuildStateTypeHandlerCallback (com.thoughtworks.go.server.dao.handlers.BuildStateTypeHandlerCallback)4 Test (org.junit.jupiter.api.Test)4 ResultSet (java.sql.ResultSet)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 JobInstance (com.thoughtworks.go.domain.JobInstance)1 NullJobInstance (com.thoughtworks.go.domain.NullJobInstance)1 JobStatusMessage (com.thoughtworks.go.server.messaging.JobStatusMessage)1 CallableStatement (java.sql.CallableStatement)1