use of com.thoughtworks.go.utils.Timeout in project gocd by gocd.
the class StageMother method createStageWithFakeDuration.
private static Stage createStageWithFakeDuration(String pipelineName, int pipelineCounter, String stageName, int stageCounter, String jobName, final DateTime scheduleTime, DateTime completedTime, JobResult jobResult) {
TimeProvider timeProvider = new TimeProvider() {
@Override
public Date currentTime() {
return scheduleTime.toDate();
}
public DateTime currentDateTime() {
throw new UnsupportedOperationException("Not implemented");
}
public DateTime timeoutTime(Timeout timeout) {
throw new UnsupportedOperationException("Not implemented");
}
};
JobInstance firstJob = new JobInstance(jobName, timeProvider);
JobInstances jobInstances = new JobInstances(firstJob);
Stage stage = StageMother.custom(pipelineName, stageName, jobInstances);
firstJob.assign("AGENT-1", completedTime.toDate());
firstJob.completing(jobResult, completedTime.toDate());
firstJob.completed(completedTime.toDate());
stage.calculateResult();
stage.setCreatedTime(new Timestamp(timeProvider.currentTime().getTime()));
stage.setLastTransitionedTime(new Timestamp(completedTime.toDate().getTime()));
stage.setIdentifier(new StageIdentifier(pipelineName, pipelineCounter, "LABEL-" + pipelineCounter, stageName, String.valueOf(stageCounter)));
return stage;
}
use of com.thoughtworks.go.utils.Timeout in project gocd by gocd.
the class StageTest method shouldCalculateTotalTimeFromFirstScheduledJobToLastCompletedJob.
@Test
public void shouldCalculateTotalTimeFromFirstScheduledJobToLastCompletedJob() {
final DateTime time0 = new DateTime(2008, 2, 22, 10, 21, 23, 0);
timeProvider = new TimeProvider() {
@Override
public Date currentTime() {
return time0.toDate();
}
public DateTime currentDateTime() {
throw new UnsupportedOperationException("Not implemented");
}
public DateTime timeoutTime(Timeout timeout) {
throw new UnsupportedOperationException("Not implemented");
}
};
firstJob = new JobInstance("first-job", timeProvider);
secondJob = new JobInstance("second-job", timeProvider);
jobInstances = new JobInstances(firstJob, secondJob);
stage = StageMother.custom("test", jobInstances);
firstJob.assign("AGENT-1", time1.toDate());
firstJob.completing(JobResult.Passed, time2.toDate());
firstJob.completed(time2.toDate());
secondJob.assign("AGENT-2", time3.toDate());
secondJob.completing(JobResult.Passed, time4.toDate());
secondJob.completed(time4.toDate());
stage.calculateResult();
stage.setCreatedTime(new Timestamp(time0.toDate().getTime()));
stage.setLastTransitionedTime(new Timestamp(time4.toDate().getTime()));
RunDuration.ActualDuration expectedDuration = new RunDuration.ActualDuration(new Duration(time0, time4));
RunDuration.ActualDuration duration = (RunDuration.ActualDuration) stage.getDuration();
assertThat(duration, is(expectedDuration));
assertThat(duration.getTotalSeconds(), is(7263L));
}
use of com.thoughtworks.go.utils.Timeout in project gocd by gocd.
the class InstanceFactoryTest method shouldCloneStageForGivenJobsWithLatestMd5.
@Test
public void shouldCloneStageForGivenJobsWithLatestMd5() {
TimeProvider timeProvider = new TimeProvider() {
@Override
public Date currentTime() {
return new Date();
}
public DateTime currentDateTime() {
throw new UnsupportedOperationException("Not implemented");
}
public DateTime timeoutTime(Timeout timeout) {
throw new UnsupportedOperationException("Not implemented");
}
};
JobInstance firstJob = new JobInstance("first-job", timeProvider);
JobInstance secondJob = new JobInstance("second-job", timeProvider);
JobInstances jobInstances = new JobInstances(firstJob, secondJob);
Stage stage = StageMother.custom("test", jobInstances);
Stage clonedStage = instanceFactory.createStageForRerunOfJobs(stage, Arrays.asList("first-job"), new DefaultSchedulingContext("loser", new Agents()), StageConfigMother.custom("test", "first-job", "second-job"), new TimeProvider(), "latest");
assertThat(clonedStage.getConfigVersion(), CoreMatchers.is("latest"));
}
use of com.thoughtworks.go.utils.Timeout in project gocd by gocd.
the class StageTest method setUp.
@Before
public void setUp() {
timeProvider = new TimeProvider() {
@Override
public Date currentTime() {
return JOB_SCHEDULE_DATE;
}
public DateTime currentDateTime() {
throw new UnsupportedOperationException("Not implemented");
}
public DateTime timeoutTime(Timeout timeout) {
throw new UnsupportedOperationException("Not implemented");
}
};
firstJob = new JobInstance("first-job", timeProvider);
secondJob = new JobInstance("second-job", timeProvider);
jobInstances = new JobInstances(firstJob, secondJob);
stage = StageMother.custom("test", jobInstances);
}