use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class JobInstanceServiceIntegrationTest method shouldFindAllCopiesOfJobsRunMultipleInstance.
@Test
public void shouldFindAllCopiesOfJobsRunMultipleInstance() throws Exception {
StageConfig stageConfig = StageConfigMother.custom("dev", "build");
JobConfig jobConfig = stageConfig.jobConfigByInstanceName("build", true);
jobConfig.setRunInstanceCount(2);
DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("anyone", new Agents());
Stage stage = instanceFactory.createStageInstance(stageConfig, schedulingContext, "md5-test", new TimeProvider());
for (JobInstance instance : stage.getJobInstances()) {
instance.setIdentifier(new JobIdentifier("cruise", "1", "dev", "1", instance.getName()));
}
jobStatusCache.jobStatusChanged(stage.getJobInstances().first());
jobStatusCache.jobStatusChanged(stage.getJobInstances().last());
JobInstances jobs = jobInstanceService.currentJobsOfStage("cruise", stageConfig);
assertThat(jobs.size(), is(2));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is(RunMultipleInstance.CounterBasedJobNameGenerator.appendMarker("build", 1)))));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is(RunMultipleInstance.CounterBasedJobNameGenerator.appendMarker("build", 2)))));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class PipelineHistoryServiceIntegrationTest method findMatchingPipelineInstances_shouldMatchUpStreamPipelineLabel.
@Test
public void findMatchingPipelineInstances_shouldMatchUpStreamPipelineLabel() {
final int limit = 3;
PipelineConfig upstreamConfig = PipelineConfigMother.createPipelineConfig("upstream", "stage", "job");
upstreamConfig.setLabelTemplate("${COUNT}-hello-world-${COUNT}");
PipelineConfig downstreamConfig = PipelineConfigMother.createPipelineConfig("downstream", "stage", "job");
downstreamConfig.materialConfigs().clear();
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream"), new CaseInsensitiveString("stage"));
downstreamConfig.addMaterialConfig(dependencyMaterial.config());
goConfigService.addPipeline(upstreamConfig, "pipeline-group");
goConfigService.addPipeline(downstreamConfig, "pipeline-group");
Pipeline upstreamPipeline = dbHelper.schedulePipeline(upstreamConfig, new TimeProvider());
dbHelper.passStage(upstreamPipeline.getStages().get(0));
Modification modification = new Modification(new Date(), DependencyMaterialRevision.create("upstream", 1, "1", "stage", 1).getRevision(), "1", upstreamPipeline.getId());
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(dependencyMaterial, modification));
Pipeline downstreamPipeline = dbHelper.schedulePipeline(downstreamConfig, BuildCause.createWithModifications(materialRevisions, "cruise"), new TimeProvider());
dbHelper.passStage(downstreamPipeline.getStages().get(0));
PipelineInstanceModels actual = pipelineHistoryService.findMatchingPipelineInstances("downstream", "hello-world", limit, new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
assertThat(actual.size(), is(1));
assertThat(actual.get(0).getCounter(), is(downstreamPipeline.getCounter()));
}
use of com.thoughtworks.go.util.TimeProvider 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.util.TimeProvider in project gocd by gocd.
the class StageTest method shouldReturnCreatedDateWhenNoTranstions.
@Test
public void shouldReturnCreatedDateWhenNoTranstions() throws Exception {
stage = new Stage("dev", new JobInstances(), "anonymous", "manual", new TimeProvider());
assertEquals(new Date(stage.getCreatedTime().getTime()), stage.latestTransitionDate());
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class StageTest method shouldSetTheCurrentTimeAsCreationTimeForRerunOfJobs.
@Test
public void shouldSetTheCurrentTimeAsCreationTimeForRerunOfJobs() {
Stage stage = new Stage("foo-stage", new JobInstances(), "admin", "manual", false, false, "git-sha", new TimeProvider());
Timestamp createdTimeOfRun1 = stage.getCreatedTime();
long minuteAfter = DateTimeUtils.currentTimeMillis() + 60000;
freezeTime(minuteAfter);
stage.prepareForRerunOf(new DefaultSchedulingContext("admin"), "git-sha");
resetTime();
Timestamp createdTimeOfRun2 = stage.getCreatedTime();
assertNotEquals(createdTimeOfRun1, createdTimeOfRun2);
assertEquals(createdTimeOfRun2, new Timestamp(minuteAfter));
}
Aggregations