Search in sources :

Example 6 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldHandleCaseWhereSpecifiedRevisionDoesNotExist.

@Test
public void shouldHandleCaseWhereSpecifiedRevisionDoesNotExist() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
    when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1")))).thenThrow(new RuntimeException("Invalid specified revision"));
    ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
    final HashMap<String, String> stringStringHashMap = new HashMap<>();
    buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
    verify(mockServerHealthService).update(argThat(hasErrorHealthState("Error while scheduling pipeline: pipeline", "Invalid specified revision")));
}
Also used : HashMap(java.util.HashMap) ManualBuild(com.thoughtworks.go.server.service.ManualBuild) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 7 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.

@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
    String pipelineName = "pipeline";
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
    Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
    config.materialConfigs().clear();
    config.addMaterialConfig(svnMaterial.config());
    config.addMaterialConfig(dependencyMaterial.config());
    when(pipelineService.getRevisionsBasedOnDependencies(Matchers.<MaterialRevisions>any(), Matchers.<BasicCruiseConfig>any(), Matchers.<CaseInsensitiveString>any())).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
    when(pipelineScheduleQueue.mostRecentScheduled(pipelineName)).thenReturn(BuildCause.createNeverRun());
    Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
    when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
    when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
    when(specificMaterialRevisionFactory.create(Matchers.<String>any(), Matchers.<Map<String, String>>any())).thenReturn(MaterialRevisions.EMPTY);
    when(goConfigService.upstreamDependencyGraphOf(Matchers.<String>any(), Matchers.<BasicCruiseConfig>any())).thenReturn(new PipelineConfigDependencyGraph(config));
    MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
    Materials materials = new Materials(svnMaterial, dependencyMaterial);
    when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
    when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
    when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null, mockServerHealthService);
    ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
    assertThat(serverHealthState.isSuccess(), is(true));
}
Also used : AutoBuild(com.thoughtworks.go.server.service.AutoBuild) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) NoModificationsPresentForDependentMaterialException(com.thoughtworks.go.server.service.NoModificationsPresentForDependentMaterialException) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) Test(org.junit.Test)

Example 8 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldHandleCaseWhenExceptionWithoutMessageIsRaised.

@Test
public void shouldHandleCaseWhenExceptionWithoutMessageIsRaised() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
    when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1")))).thenThrow(new NullPointerException());
    ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
    final HashMap<String, String> stringStringHashMap = new HashMap<>();
    buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
    verify(mockServerHealthService).update(argThat(hasErrorHealthState("Error while scheduling pipeline: pipeline", "Details not available, please check server logs.")));
}
Also used : HashMap(java.util.HashMap) ManualBuild(com.thoughtworks.go.server.service.ManualBuild) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 9 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class ValueStreamMapService method traverseUpstream.

private void traverseUpstream(String pipelineName, BuildCause buildCause, ValueStreamMap graph, List<MaterialRevision> visitedNodes) {
    for (MaterialRevision materialRevision : buildCause.getMaterialRevisions()) {
        Material material = materialRevision.getMaterial();
        if (material instanceof DependencyMaterial) {
            String upstreamPipeline = ((DependencyMaterial) material).getPipelineName().toString();
            DependencyMaterialRevision revision = (DependencyMaterialRevision) materialRevision.getRevision();
            graph.addUpstreamNode(new PipelineDependencyNode(upstreamPipeline, upstreamPipeline), new PipelineRevision(revision.getPipelineName(), revision.getPipelineCounter(), revision.getPipelineLabel()), pipelineName);
            if (visitedNodes.contains(materialRevision)) {
                continue;
            }
            visitedNodes.add(materialRevision);
            DependencyMaterialRevision dmrOfUpstreamPipeline = buildCause.getMaterialRevisions().findDependencyMaterialRevision(upstreamPipeline);
            BuildCause buildCauseForUpstreamPipeline = pipelineService.buildCauseFor(dmrOfUpstreamPipeline.getPipelineName(), dmrOfUpstreamPipeline.getPipelineCounter());
            traverseUpstream(upstreamPipeline, buildCauseForUpstreamPipeline, graph, visitedNodes);
        } else {
            graph.addUpstreamMaterialNode(new SCMDependencyNode(material.getFingerprint(), material.getUriForDisplay(), materialRevision.getMaterialType()), material.getName(), pipelineName, materialRevision);
        }
    }
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 10 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class MaterialDatabaseDependencyUpdaterTest method shouldReturnLatestPipelineIfThereHasBeenANewOne.

@Test
public void shouldReturnLatestPipelineIfThereHasBeenANewOne() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
    stubStageServiceGetHistory(null, stages(9));
    updater.updateMaterial(dependencyMaterial);
    List<Modification> modification = materialRepository.findLatestModification(dependencyMaterial).getMaterialRevision(0).getModifications();
    stubStageServiceGetHistoryAfter(null, 9, stages(10));
    updater.updateMaterial(dependencyMaterial);
    List<Modification> newModifications = materialRepository.findModificationsSince(dependencyMaterial, new MaterialRevision(dependencyMaterial, modification));
    assertThat(newModifications.size(), is(1));
    assertThat(newModifications.get(0).getRevision(), is("pipeline-name/10/stage-name/0"));
    assertThat(newModifications.get(0).getPipelineLabel(), is("LABEL-10"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)96 Test (org.junit.Test)75 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)65 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)30 Modification (com.thoughtworks.go.domain.materials.Modification)30 Date (java.util.Date)24 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)19 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)18 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)16 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)15 Stage (com.thoughtworks.go.domain.Stage)14 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)13 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)13 Materials (com.thoughtworks.go.config.materials.Materials)12 Username (com.thoughtworks.go.server.domain.Username)12 Pipeline (com.thoughtworks.go.domain.Pipeline)11 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)11 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)10 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)9