public void fail() { Date completionDate = timeProvider.currentTime(); completing(JobResult.Failed, completionDate); completed(completionDate); }
public static JobInstance completed(JobInstance instance, JobResult result, Date completedDate) { instance.completing(result, completedDate); instance.completed(completedDate); return instance; }
private void complete(JobInstance job, DateTime fiveMinsForNow) { job.completing(JobResult.Passed, fiveMinsForNow.toDate()); job.completed(fiveMinsForNow.plusSeconds(10).toDate()); assignIdsToAllTransitions(job); }
private static void completeBuildInstancesOfStage(Stage stage, JobResult result, Date completionDate) { for (JobInstance job : stage.getJobInstances()) { job.assign("uuid", new DateTime(completionDate.getTime()).minusHours(1).toDate()); job.completing(result, completionDate); job.completed(completionDate); } stage.setLastTransitionedTime(new Timestamp(completionDate.getTime())); }
@Test public void shouldReturnMostRecentCompletedTransitionAsCompletedDateIfLatestTransitionIdIsNot() { 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()); secondJob.getTransitions().byState(JobState.Completed).setId(1); stage.calculateResult(); assertThat(stage.completedDate(), is(time4.toDate())); }
@Test public void shouldSetCompletedTimeOnComplete() throws Exception { JobInstance instance = JobInstanceMother.scheduled("jobConfig1"); final Date completionDate = new Date(); instance.completing(JobResult.Passed, completionDate); instance.completed(completionDate); assertThat(instance.getResult(), is(JobResult.Passed)); assertThat(instance.getStartedDateFor(JobState.Completed), is(completionDate)); assertThat(instance.getState(), is(JobState.Completed)); }
@Test public void shouldDetermineMostRecentPassed() { JobInstance oldestPassed = JobInstanceMother.building("oldestPassed"); oldestPassed.completing(JobResult.Passed, DateUtils.addHours(new Date(), -1)); oldestPassed.completed(DateUtils.addHours(new Date(), -1)); JobInstance newestPassed = JobInstanceMother.building("newestPassed"); newestPassed.completing(JobResult.Passed, new Date()); newestPassed.completed(new Date()); assertEquals(newestPassed, newestPassed.mostRecentPassed(oldestPassed)); assertEquals(newestPassed, oldestPassed.mostRecentPassed(newestPassed)); JobInstance newestFailed = JobInstanceMother.building("newestFailed"); newestFailed.completing(JobResult.Failed, DateUtils.addHours(new Date(), +1)); newestFailed.completed(DateUtils.addHours(new Date(), +1)); assertEquals(newestPassed, newestPassed.mostRecentPassed(newestFailed)); }
@Test public void shouldDetermineMostRecentPassedBeforeWithNullBuildInstances() { JobInstance mostRecent = JobInstanceMother.building("mostRecent"); mostRecent.completing(JobResult.Passed, new Date()); mostRecent.completed(new Date()); assertEquals(mostRecent, mostRecent.mostRecentPassed(JobInstance.NULL)); assertEquals(mostRecent, JobInstance.NULL.mostRecentPassed(mostRecent)); }
private JobInstances mixedBuilds() { JobInstances instances = new JobInstances(); JobInstance assigned = JobInstanceMother.assigned("test"); instances.add(assigned); JobInstance oldest = passed("oldest"); oldest.completed(new Date()); instances.add(oldest); JobInstance newest = failed("newest"); newest.completed(new Date()); instances.add(newest); instances.add(JobInstance.NULL); JobInstance scheduled = scheduled("redHerring"); instances.add(scheduled); return instances; }
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; }
public static JobInstance completed(String jobConfigName, JobResult result, Date completedDate, Date startbuilding) { JobInstance instance = new JobInstance(jobConfigName); instance.completing(result, completedDate); instance.completed(completedDate); instance.getTransitions().add(new JobStateTransition(JobState.Building, startbuilding)); return instance; }
public static JobInstance cancelled(String jobConfigName, Date scheduledDate, int interval) { JobInstance instance = new JobInstance(jobConfigName); instance.setIdentifier(defaultJobIdentifier(jobConfigName)); instance.schedule(); instance.getTransition(JobState.Scheduled).setStateChangeTime(scheduledDate); instance.setResult(JobResult.Cancelled); instance.completed(addMillis(scheduledDate, interval)); return instance; }