Search in sources :

Example 61 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class PipelineScheduleQueueIntegrationTest method shouldCreatePipelineIfBuildCauseIsNotTrumped.

@Test
public void shouldCreatePipelineIfBuildCauseIsNotTrumped() throws Exception {
    PipelineConfig pipelineConfig = fixture.pipelineConfig();
    BuildCause cause = modifySomeFiles(pipelineConfig);
    saveRev(cause);
    queue.schedule(fixture.pipelineName, cause);
    assertThat(queue.createPipeline(cause, pipelineConfig, new DefaultSchedulingContext(cause.getApprover(), new Agents()), "md5-test", new TimeProvider()), is(not(nullValue())));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 62 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method hasPipelineEverRunWith_shouldCacheResultsForPipelineNameMaterialIdAndModificationId.

@Test
public void hasPipelineEverRunWith_shouldCacheResultsForPipelineNameMaterialIdAndModificationId() {
    HgMaterial hgMaterial = MaterialsMother.hgMaterial("hgUrl", "dest");
    MaterialRevision materialRevision = saveOneScmModification(hgMaterial, "user", "file");
    PipelineConfig pipelineConfig = PipelineMother.createPipelineConfig("mingle", new MaterialConfigs(hgMaterial.config()), "dev");
    MaterialRevisions materialRevisions = new MaterialRevisions(materialRevision);
    Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, BuildCause.createManualForced(materialRevisions, Username.ANONYMOUS), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider());
    GoCache spyGoCache = spy(goCache);
    when(spyGoCache.get(any(String.class))).thenCallRealMethod();
    Mockito.doCallRealMethod().when(spyGoCache).put(any(String.class), any(Object.class));
    repo = new MaterialRepository(sessionFactory, spyGoCache, 2, transactionSynchronizationManager, materialConfigConverter, materialExpansionService, databaseStrategy);
    pipelineSqlMapDao.save(pipeline);
    MaterialRevisions revisions = new MaterialRevisions(new MaterialRevision(hgMaterial, materialRevision.getLatestModification()));
    assertThat("should hit the db and cache it", repo.hasPipelineEverRunWith("mingle", revisions), is(true));
    assertThat("should have cached the result on the previous call", repo.hasPipelineEverRunWith("mingle", revisions), is(true));
    verify(spyGoCache, times(1)).put(any(String.class), eq(Boolean.TRUE));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) GoCache(com.thoughtworks.go.server.cache.GoCache) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 63 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method hasPipelineEverRunWith.

@Test
public void hasPipelineEverRunWith() {
    HgMaterial hgMaterial = MaterialsMother.hgMaterial("hgUrl", "dest");
    MaterialRevision materialRevision = saveOneScmModification(hgMaterial, "user", "file");
    PipelineConfig pipelineConfig = PipelineMother.createPipelineConfig("mingle", new MaterialConfigs(hgMaterial.config()), "dev");
    MaterialRevisions materialRevisions = new MaterialRevisions(materialRevision);
    Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, BuildCause.createManualForced(materialRevisions, Username.ANONYMOUS), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider());
    pipelineSqlMapDao.save(pipeline);
    MaterialRevisions revisions = new MaterialRevisions(new MaterialRevision(hgMaterial, materialRevision.getLatestModification()));
    assertThat(repo.hasPipelineEverRunWith("mingle", revisions), is(true));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Test(org.junit.Test)

Example 64 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method hasPipelineEverRunWithMultipleMaterialsAndMultipleRuns.

@Test
public void hasPipelineEverRunWithMultipleMaterialsAndMultipleRuns() {
    HgMaterial hgMaterial1 = MaterialsMother.hgMaterial("hgUrl", "dest");
    MaterialRevision hgMaterialRevision1 = saveOneScmModification(hgMaterial1, "user", "file");
    DependencyMaterial depMaterial1 = new DependencyMaterial(new CaseInsensitiveString("blahPipeline"), new CaseInsensitiveString("blahStage"));
    MaterialRevision depMaterialRevision1 = saveOneDependencyModification(depMaterial1, "blahPipeline/1/blahStage/1");
    PipelineConfig pipelineConfig = PipelineMother.createPipelineConfig("mingle", new MaterialConfigs(hgMaterial1.config(), depMaterial1.config()), "dev");
    MaterialRevisions materialRevisions1 = new MaterialRevisions(hgMaterialRevision1, depMaterialRevision1);
    pipelineSqlMapDao.save(instanceFactory.createPipelineInstance(pipelineConfig, BuildCause.createManualForced(materialRevisions1, Username.ANONYMOUS), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()));
    HgMaterial hgMaterial2 = MaterialsMother.hgMaterial("hgUrl", "dest");
    MaterialRevision hgMaterialRevision2 = saveOneScmModification(hgMaterial2, "user", "file");
    DependencyMaterial depMaterial2 = new DependencyMaterial(new CaseInsensitiveString("blahPipeline"), new CaseInsensitiveString("blahStage"));
    MaterialRevision depMaterialRevision2 = saveOneDependencyModification(depMaterial2, "blahPipeline/2/blahStage/1");
    PipelineConfig pipelineConfig2 = PipelineMother.createPipelineConfig("mingle", new MaterialConfigs(hgMaterial2.config(), depMaterial2.config()), "dev");
    MaterialRevisions materialRevisions2 = new MaterialRevisions(hgMaterialRevision2, depMaterialRevision2);
    savePipeline(instanceFactory.createPipelineInstance(pipelineConfig2, BuildCause.createManualForced(materialRevisions2, Username.ANONYMOUS), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()));
    MaterialRevisions revisions = new MaterialRevisions(new MaterialRevision(depMaterial1, depMaterialRevision1.getLatestModification()), new MaterialRevision(hgMaterial2, hgMaterialRevision2.getLatestModification()));
    assertThat(repo.hasPipelineEverRunWith("mingle", revisions), is(true));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 65 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method savePipelineAndCreate_DMRs.

private DependencyMaterial savePipelineAndCreate_DMRs(Date d, MaterialRevisions hgMaterialRevisions, PipelineConfig config, int... dmrStageCounters) {
    Pipeline pipeline = savePipeline(instanceFactory.createPipelineInstance(config, BuildCause.createWithModifications(hgMaterialRevisions, "Loser"), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()));
    CaseInsensitiveString stageName = config.get(0).name();
    DependencyMaterial material = new DependencyMaterial(config.name(), stageName);
    String label = pipeline.getLabel();
    ArrayList<Modification> mods = new ArrayList<>();
    for (int i = 0; i < dmrStageCounters.length; i++) {
        int dmrStageCounter = dmrStageCounters[i];
        StageIdentifier stageIdentifier = new StageIdentifier(pipeline.getIdentifier(), CaseInsensitiveString.str(stageName), String.valueOf(dmrStageCounter));
        mods.add(new Modification(d, stageIdentifier.getStageLocator(), label, pipeline.getId()));
    }
    final MaterialRevision materialRevision = new MaterialRevision(material, mods);
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            repo.saveMaterialRevision(materialRevision);
            return null;
        }
    });
    return material;
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) TransactionStatus(org.springframework.transaction.TransactionStatus) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) TransactionCallback(org.springframework.transaction.support.TransactionCallback) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial)

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