public void completing(JobResult result) { completing(result, timeProvider.currentTime()); }
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 shouldReturnDateForLatestTransition() throws Exception { JobInstance instance = JobInstanceMother.scheduled("jobConfig1"); instance.setClock(timeProvider); when(timeProvider.currentTime()).thenReturn(new DateTime().plusDays(1).toDate()); instance.completing(JobResult.Passed); assertThat(instance.latestTransitionDate(),is(greaterThan(instance.getScheduledDate()))); }
@Test public void shouldReturnLatestTransitionDate() { Date date = JOB_SCHEDULE_DATE; firstJob.completing(JobResult.Failed, date); assertThat(stage.latestTransitionDate(), is(date)); }
@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 shouldSetCompletingTimeAndResult() throws Exception { JobInstance instance = JobInstanceMother.scheduled("jobConfig1"); final Date completionDate = new Date(); instance.completing(JobResult.Passed, completionDate); assertThat(instance.getResult(), is(JobResult.Passed)); assertThat(instance.getState(), is(JobState.Completing)); }
@Test public void shouldCreateATransitionOnStateChange() throws Exception { JobInstance instance = JobInstanceMother.scheduled("jobConfig1"); instance.completing(JobResult.Passed); final JobStateTransition scheduledState = new JobStateTransition(JobState.Scheduled, new Date()); final JobStateTransition completedState = new JobStateTransition(JobState.Completing, new Date()); assertThat(instance.getTransitions(), hasItem(scheduledState)); assertThat(instance.getTransitions(), hasItem(completedState)); assertThat(instance.getTransitions().first(), not(isTransitionWithState(JobState.Preparing))); }
@Test public void shouldCleanAgentIdAndResultAfterRescheduled() throws Exception { JobInstance instance = JobInstanceMother.assignedWithAgentId("testBuild", "uuid"); instance.completing(JobResult.Failed); instance.reschedule(); assertThat(instance.getState(), is(JobState.Scheduled)); assertThat(instance.getAgentUuid(), is(nullValue())); assertThat(instance.getResult(), is(JobResult.Unknown)); }
@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)); }
public void jobCompleting(JobIdentifier jobIdentifier, JobResult result, String agentUuid) { // have to synchronize at stage-level because cancellation happens at stage-level synchronized (mutexForStageInstance(jobIdentifier)) { synchronized (mutexForJob(jobIdentifier)) { JobInstance jobInstance = jobInstanceService.buildByIdWithTransitions(jobIdentifier.getBuildId()); if (jobInstance.isNull() || jobInstance.getResult() == JobResult.Cancelled || jobInstance.getState() == JobState.Rescheduled) { return; } //TODO: #2318 JobInstance should contain identifier after it's loaded from database jobInstance.setIdentifier(jobIdentifier); if (!StringUtils.equals(jobInstance.getAgentUuid(), agentUuid)) { LOGGER.error("Build Instance is using agent [{}] but status updating from agent [{}]", jobInstance.getAgentUuid(), agentUuid); throw new InvalidAgentException("AgentUUID has changed in the middle of a job. AgentUUID:" + agentUuid + ", Build: " + jobInstance.toString()); } jobInstance.completing(result); jobInstanceService.updateStateAndResult(jobInstance); } } }
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; }
firstJob.completing(JobResult.Passed, time2.toDate()); firstJob.completed(time2.toDate()); secondJob.completing(JobResult.Passed, time4.toDate()); secondJob.completed(time4.toDate());
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 Stage failingStage(String stageName) { StageConfig stageConfig = StageConfigMother.twoBuildPlansWithResourcesAndMaterials(stageName); Stage stage = scheduleInstance(stageConfig); stage.setId(fakeId()); stage.getJobInstances().get(0).fail(); stage.getJobInstances().get(1).completing(JobResult.Passed); return stage; }