Search in sources :

Example 1 with Timeout

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;
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Timeout(com.thoughtworks.go.utils.Timeout) Timestamp(java.sql.Timestamp)

Example 2 with Timeout

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));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Timeout(com.thoughtworks.go.utils.Timeout) Duration(org.joda.time.Duration) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.junit.Test)

Example 3 with Timeout

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"));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Timeout(com.thoughtworks.go.utils.Timeout) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Timeout

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);
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Timeout(com.thoughtworks.go.utils.Timeout) Date(java.util.Date) DateTime(org.joda.time.DateTime) Before(org.junit.Before)

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)4 Timeout (com.thoughtworks.go.utils.Timeout)4 Date (java.util.Date)3 Timestamp (java.sql.Timestamp)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.Test)2 Duration (org.joda.time.Duration)1 Before (org.junit.Before)1