Search in sources :

Example 16 with PipelineConfigDependencyGraph

use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.

the class MaterialRevisionBuilder method depInstance.

public Tuple depInstance(String pipelineName, int counter, Date modifiedTime, Tuple... buildCause) {
    String key = key(pipelineName, counter, modifiedTime);
    if (!instanceToRevision.containsKey(key)) {
        if (buildCause.length == 0) {
            throw new RuntimeException("Cannot create instance without a buildcause. You can retrive it without buildcause once it has been created");
        }
        DependencyMaterial material = new DependencyMaterial(new CaseInsensitiveString(pipelineName), new CaseInsensitiveString(STAGE_NAME));
        DependencyMaterialRevision revision = DependencyMaterialRevision.create(pipelineName, counter, "label", STAGE_NAME, 1);
        instanceToRevision.put(key, revision.convert(material, modifiedTime));
        final long id = getNextId();
        org.mockito.Mockito.when(pipelineDao.findPipelineByNameAndCounter(pipelineName, counter)).thenReturn(pipeline(id));
        org.mockito.Mockito.when(materialRepository.findMaterialRevisionsForPipeline(id)).thenReturn(buildCauseOfThisPipeline(buildCause));
    }
    MaterialRevision materialRevision = instanceToRevision.get(key);
    Materials materials = new Materials();
    for (MaterialRevision revision : buildCauseOfThisPipeline(buildCause)) {
        materials.add(revision.getMaterial());
    }
    PipelineConfig config = new PipelineConfig(new CaseInsensitiveString(pipelineName), materials.convertToConfigs(), new StageConfig(new CaseInsensitiveString(STAGE_NAME), new JobConfigs()));
    return new Tuple(new PipelineConfigDependencyGraph(config, dependencyGraphsFor(buildCause)), materialRevision);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Materials(com.thoughtworks.go.config.materials.Materials) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageConfig(com.thoughtworks.go.config.StageConfig) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) JobConfigs(com.thoughtworks.go.config.JobConfigs) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision)

Example 17 with PipelineConfigDependencyGraph

use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.

the class AutoBuildCauseTest method shouldNotFallbackToFanInOffTriangleDependencyBehaviourOnNoCompatibleUpstreamRevisionsException.

@Test
public void shouldNotFallbackToFanInOffTriangleDependencyBehaviourOnNoCompatibleUpstreamRevisionsException() throws Exception {
    PipelineConfigDependencyGraph dependencyGraph = dependencyGraphOfDepthOne(MaterialConfigsMother.hgMaterialConfig());
    String targetPipeline = dependencyGraph.getCurrent().name().toLower();
    MaterialRevisions revisions = createHgMaterialWithMultipleRevisions(1, oneModifiedFile("2"));
    MaterialRevision dependencyRevision = dependencyMaterialRevision("up1", 1, "label", "first", 1, new Date());
    dependencyRevision.markAsChanged();
    revisions.addRevision(dependencyRevision);
    NoCompatibleUpstreamRevisionsException expectedException = NoCompatibleUpstreamRevisionsException.failedToFindCompatibleRevision(new CaseInsensitiveString("downstream"), null);
    when(goConfigService.upstreamDependencyGraphOf(targetPipeline, cruiseConfig)).thenReturn(dependencyGraph);
    when(pipelineService.getRevisionsBasedOnDependencies(eq(revisions), eq(cruiseConfig), eq(dependencyGraph.getCurrent().name()))).thenThrow(expectedException);
    when(systemEnvironment.enforceRevisionCompatibilityWithUpstream()).thenReturn(true);
    when(systemEnvironment.enforceFanInFallbackBehaviour()).thenReturn(false);
    try {
        new AutoBuild(goConfigService, pipelineService, targetPipeline, systemEnvironment, materialChecker, serverHealthService).onModifications(revisions, false, null);
        fail("should have thrown exception");
    } catch (NoCompatibleUpstreamRevisionsException e) {
        assertThat(e, is(expectedException));
    }
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Date(java.util.Date) Test(org.junit.Test)

Example 18 with PipelineConfigDependencyGraph

use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.

the class AutoBuildCauseTest method shouldReturnNullIfUpstreamMaterialHasChangedButNoFirstOrderMaterialHas_WithFaninOff.

@Test
public void shouldReturnNullIfUpstreamMaterialHasChangedButNoFirstOrderMaterialHas_WithFaninOff() throws Exception {
    HgMaterialConfig hg = MaterialConfigsMother.hgMaterialConfig();
    PipelineConfig third = PipelineConfigMother.pipelineConfig("third", MaterialConfigsMother.dependencyMaterialConfig("second", "mingle"), new JobConfigs());
    PipelineConfig second = PipelineConfigMother.pipelineConfig("second", MaterialConfigsMother.dependencyMaterialConfig("first", "mingle"), new JobConfigs());
    PipelineConfig first = PipelineConfigMother.pipelineConfig("first", hg, new JobConfigs());
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(third, new PipelineConfigDependencyGraph(second, new PipelineConfigDependencyGraph(first)), new PipelineConfigDependencyGraph(first));
    MaterialRevisions revisions = new MaterialRevisions();
    MaterialRevision firstRev = dependencyMaterialRevision("first", 1, "label", "mingle", 1, new Date());
    firstRev.markAsChanged();
    MaterialRevision secondRev = dependencyMaterialRevision("second", 1, "label", "mingle", 1, new Date());
    secondRev.markAsNotChanged();
    revisions.addRevision(secondRev);
    revisions.addRevision(firstRev);
    when(goConfigService.upstreamDependencyGraphOf("third", cruiseConfig)).thenReturn(dependencyGraph);
    when(systemEnvironment.enforceRevisionCompatibilityWithUpstream()).thenReturn(false);
    AutoBuild build = new AutoBuild(goConfigService, pipelineService, "third", systemEnvironment, materialChecker, serverHealthService);
    BuildCause cause = build.onModifications(revisions, false, null);
    assertThat(cause, is(nullValue()));
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 19 with PipelineConfigDependencyGraph

use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.

the class AutoBuildTriangleDependencyTest method should_useTriangleDependencyResolution_whenFainInIsOptedOut.

@Test
public void should_useTriangleDependencyResolution_whenFainInIsOptedOut() throws Exception {
    SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
    when(systemEnvironment.enforceRevisionCompatibilityWithUpstream()).thenReturn(false);
    String pipelineName = "downstream";
    PipelineConfigDependencyGraph dependencyGraph = mock(PipelineConfigDependencyGraph.class);
    MaterialRevisions originalRevisions = mock(MaterialRevisions.class);
    MaterialRevisions recomputedRevisions = mock(MaterialRevisions.class);
    when(originalRevisions.isEmpty()).thenReturn(false);
    when(originalRevisions.hasDependencyMaterials()).thenReturn(true);
    when(goConfigService.upstreamDependencyGraphOf(pipelineName, cruiseConfig)).thenReturn(dependencyGraph);
    when(pipelineService.getRevisionsBasedOnDependencies(dependencyGraph, originalRevisions)).thenReturn(recomputedRevisions);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"));
    when(dependencyGraph.unsharedMaterialConfigs()).thenReturn(new MaterialConfigs(dependencyMaterial.config()));
    when(originalRevisions.findRevisionFor(dependencyMaterial)).thenReturn(new MaterialRevision(dependencyMaterial, new Modification()));
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, systemEnvironment, materialChecker, serverHealthService);
    AutoBuild spyAutoBuild = spy(autoBuild);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return true;
        }
    }).when(spyAutoBuild).hasAnyUnsharedMaterialChanged(dependencyGraph, originalRevisions);
    BuildCause buildCause = spyAutoBuild.onModifications(originalRevisions, false, null);
    verify(pipelineService).getRevisionsBasedOnDependencies(dependencyGraph, originalRevisions);
    verify(pipelineService, never()).getRevisionsBasedOnDependencies(any(MaterialRevisions.class), any(BasicCruiseConfig.class), any(CaseInsensitiveString.class));
    assertThat(buildCause.getMaterialRevisions(), is(recomputedRevisions));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Example 20 with PipelineConfigDependencyGraph

use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.

the class AutoBuildCauseTest method shouldReturnPeggedRevisionsForUpstreamMaterialWhenFirstOrderDependencyMaterialIsChanged.

@Test
public void shouldReturnPeggedRevisionsForUpstreamMaterialWhenFirstOrderDependencyMaterialIsChanged() throws Exception {
    HgMaterialConfig hg = MaterialConfigsMother.hgMaterialConfig();
    PipelineConfig third = PipelineConfigMother.pipelineConfig("third", MaterialConfigsMother.dependencyMaterialConfig("second", "mingle"), new JobConfigs());
    PipelineConfig second = PipelineConfigMother.pipelineConfig("second", MaterialConfigsMother.dependencyMaterialConfig("first", "mingle"), new JobConfigs());
    PipelineConfig first = PipelineConfigMother.pipelineConfig("first", hg, new JobConfigs());
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(third, new PipelineConfigDependencyGraph(second, new PipelineConfigDependencyGraph(first)), new PipelineConfigDependencyGraph(first));
    MaterialRevisions revisions = new MaterialRevisions();
    MaterialRevision firstRev = dependencyMaterialRevision("first", 10, "label", "mingle", 1, new Date());
    firstRev.markAsNotChanged();
    MaterialRevision secondRev = dependencyMaterialRevision("second", 1, "label", "mingle", 1, new Date());
    secondRev.markAsChanged();
    revisions.addRevision(secondRev);
    revisions.addRevision(firstRev);
    when(goConfigService.upstreamDependencyGraphOf("third", cruiseConfig)).thenReturn(dependencyGraph);
    MaterialRevisions expectedRevisions = new MaterialRevisions();
    when(pipelineService.getRevisionsBasedOnDependencies(eq(revisions), eq(cruiseConfig), eq(dependencyGraph.getCurrent().name()))).thenReturn(expectedRevisions);
    assertThat(new AutoBuild(goConfigService, pipelineService, "third", new SystemEnvironment(), materialChecker, serverHealthService).onModifications(revisions, false, null).getMaterialRevisions(), sameInstance(expectedRevisions));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)37 Test (org.junit.Test)32 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)31 Date (java.util.Date)28 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)21 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)16 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)12 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)11 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)8 Pipeline (com.thoughtworks.go.domain.Pipeline)7 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)7 ModificationsMother.changedDependencyMaterialRevision (com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision)7 ModificationsMother.dependencyMaterialRevision (com.thoughtworks.go.helper.ModificationsMother.dependencyMaterialRevision)7 MaterialRevisionBuilder (com.thoughtworks.go.server.functional.helpers.MaterialRevisionBuilder)6 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)3 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)3 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)3 Modification (com.thoughtworks.go.domain.materials.Modification)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 Materials (com.thoughtworks.go.config.materials.Materials)2