Search in sources :

Example 76 with TimeProvider

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

Example 77 with TimeProvider

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()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) Test(org.junit.Test)

Example 78 with TimeProvider

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));
}
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 79 with TimeProvider

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

Example 80 with TimeProvider

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

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)177 Test (org.junit.Test)122 Date (java.util.Date)29 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)28 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)25 DateTime (org.joda.time.DateTime)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)16 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)13 Username (com.thoughtworks.go.server.domain.Username)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 Before (org.junit.Before)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)11 Materials (com.thoughtworks.go.config.materials.Materials)10 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 TransactionStatus (org.springframework.transaction.TransactionStatus)9 Material (com.thoughtworks.go.domain.materials.Material)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)6