Search in sources :

Example 16 with DependencyMaterialConfig

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

the class GoPartialConfigIntegrationTest method shouldMarkAnInvalidKnownPartialAsValidWhenLoadingAnotherPartialMakesThisOneValid_InterConfigRepoDependency.

@Test
public void shouldMarkAnInvalidKnownPartialAsValidWhenLoadingAnotherPartialMakesThisOneValid_InterConfigRepoDependency() {
    ConfigRepoConfig repoConfig3 = new ConfigRepoConfig(new GitMaterialConfig("url3"), "plugin");
    configHelper.addConfigRepo(repoConfig3);
    PartialConfig repo1 = PartialConfigMother.withPipeline("p1_repo1", new RepoConfigOrigin(repoConfig1, "1"));
    PartialConfig repo2 = PartialConfigMother.withPipeline("p2_repo2", new RepoConfigOrigin(repoConfig2, "1"));
    PartialConfig repo3 = PartialConfigMother.withPipeline("p3_repo3", new RepoConfigOrigin(repoConfig3, "1"));
    PipelineConfig p1 = repo1.getGroups().first().getPipelines().get(0);
    PipelineConfig p2 = repo2.getGroups().first().getPipelines().get(0);
    PipelineConfig p3 = repo3.getGroups().first().getPipelines().get(0);
    p2.addMaterialConfig(new DependencyMaterialConfig(p1.name(), p1.first().name()));
    p2.addMaterialConfig(new DependencyMaterialConfig(p3.name(), p3.first().name()));
    p1.addMaterialConfig(new DependencyMaterialConfig(p3.name(), p3.first().name()));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, repo2);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(false));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(false));
    ServerHealthState healthStateForInvalidConfigMerge = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0);
    assertThat(healthStateForInvalidConfigMerge.getMessage(), is("Invalid Merged Configuration"));
    assertThat(healthStateForInvalidConfigMerge.getDescription(), is("3+ errors :: Pipeline "p1_repo1" does not exist. It is used from pipeline "p2_repo2".;; Pipeline with name 'p1_repo1' does not exist, it is defined as a dependency for pipeline 'p2_repo2' (url2 at 1);; Pipeline with name 'p3_repo3' does not exist, it is defined as a dependency for pipeline 'p2_repo2' (url2 at 1);;  -  Config-Repo: url2 at 1"));
    assertThat(healthStateForInvalidConfigMerge.getLogLevel(), is(HealthStateLevel.ERROR));
    assertThat(cachedGoPartials.lastValidPartials().isEmpty(), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(1));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo1), is(false));
    goPartialConfig.onSuccessPartialConfig(repoConfig3, repo3);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p3.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(false));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p1.name()), is(false));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig3)).isEmpty(), is(true));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(1));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo2), is(false));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo3), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(2));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo3), is(true));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, repo1);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p1.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p3.name()), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(3));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo1), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo3), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(3));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo1), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo3), is(true));
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 17 with DependencyMaterialConfig

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

the class GoConfigMigrationIntegrationTest method shouldMigrateDependsOnTagToBeADependencyMaterial.

@Test
public void shouldMigrateDependsOnTagToBeADependencyMaterial() throws Exception {
    String content = FileUtils.readFileToString(new File("../common/test-resources/unit/data/config/version4/cruise-config-dependency-migration.xml"));
    CruiseConfig cruiseConfig = loadConfigFileWithContent(content);
    MaterialConfig actual = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("depends")).materialConfigs().first();
    assertThat(actual, instanceOf(DependencyMaterialConfig.class));
    DependencyMaterialConfig depends = (DependencyMaterialConfig) actual;
    assertThat(depends.getPipelineName(), is(new CaseInsensitiveString("multiple")));
    assertThat(depends.getStageName(), is(new CaseInsensitiveString("helloworld-part2")));
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 18 with DependencyMaterialConfig

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

the class PipelineServiceTriangleDependencyTest method shouldNotGetTheRevisionsFromUpStreamPipelineIfTheDependencyMaterialHasNotChanged.

@Test
public void shouldNotGetTheRevisionsFromUpStreamPipelineIfTheDependencyMaterialHasNotChanged() throws Exception {
    MaterialRevisions expected = createHgMaterialWithMultipleRevisions(1L, first);
    MaterialRevision up1Revision = dependencyMaterialRevision("up1", 1, "label", "stage", 1, new Date());
    expected.addRevision(up1Revision);
    MaterialRevisions actual = createHgMaterialWithMultipleRevisions(1L, third);
    actual.addRevision(up1Revision);
    up1Revision.markAsNotChanged();
    PipelineConfig current = createPipelineConfigWithMaterialConfig("current", actual.getMaterials().get(0).config(), new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")));
    PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", expected.getMaterials().get(0).config());
    when(pipelineDao.findBuildCauseOfPipelineByNameAndCounter("up1", 1)).thenReturn(BuildCause.createManualForced(expected, new Username(str("loser"))));
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1));
    assertThat(service.getRevisionsBasedOnDependencies(dependencyGraph, actual), is(actual));
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Username(com.thoughtworks.go.server.domain.Username) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.dependencyMaterialRevision(com.thoughtworks.go.helper.ModificationsMother.dependencyMaterialRevision) ModificationsMother.changedDependencyMaterialRevision(com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 19 with DependencyMaterialConfig

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

the class PipelineServiceTriangleDependencyTest method shouldGetTheRevisionsForDependencyMaterialFromUpStreamPipeline.

@Test
public void shouldGetTheRevisionsForDependencyMaterialFromUpStreamPipeline() throws Exception {
    Date modifiedTime = new Date();
    MaterialRevisions expected = new MaterialRevisions();
    expected.addRevision(dependencyMaterialRevision("up1", 1, "label", "stage", 1, modifiedTime));
    expected.addRevision(dependencyMaterialRevision("common", 3, "label", "first", 1, modifiedTime));
    MaterialRevisions actual = new MaterialRevisions();
    actual.addRevision(changedDependencyMaterialRevision("up1", 1, "label", "stage", 1, modifiedTime));
    actual.addRevision(dependencyMaterialRevision("common", 4, "label", "first", 1, modifiedTime));
    PipelineConfig current = createPipelineConfigWithMaterialConfig("current", new DependencyMaterialConfig(new CaseInsensitiveString("common"), new CaseInsensitiveString("first")), new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")));
    PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", new DependencyMaterialConfig(new CaseInsensitiveString("common"), new CaseInsensitiveString("first")));
    PipelineConfig common = createPipelineConfigWithMaterialConfig("common", MaterialConfigsMother.hgMaterialConfig());
    Pipeline pipeline = PipelineMother.passedPipelineInstance("up1", "stage", "job");
    pipeline.setId(10);
    when(pipelineDao.findPipelineByNameAndCounter("up1", 1)).thenReturn(pipeline);
    MaterialRevisions upStreamPipelinesRevisions = new MaterialRevisions();
    upStreamPipelinesRevisions.addRevision(dependencyMaterialRevision("common", 3, "label", "first", 1, modifiedTime));
    when(materialRepository.findMaterialRevisionsForPipeline(10)).thenReturn(upStreamPipelinesRevisions);
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1, new PipelineConfigDependencyGraph(common)));
    MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(dependencyGraph, actual);
    assertThat(finalRevisions, is(expected));
    for (int i = 0; i < expected.numberOfRevisions(); i++) {
        assertTrue(finalRevisions.getMaterialRevision(i) == actual.getMaterialRevision(i));
    }
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 20 with DependencyMaterialConfig

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

the class PipelineServiceTriangleDependencyTest method shouldGetTheRevisionsFromTheUpStreamPipelineFor2SameMaterial.

@Test
public void shouldGetTheRevisionsFromTheUpStreamPipelineFor2SameMaterial() throws Exception {
    MaterialRevision up1Revision = dependencyMaterialRevision("up1", 1, "label", "stage", 1, new Date());
    up1Revision.markAsChanged();
    MaterialRevisions expected = new MaterialRevisions();
    expected.addRevision(up1Revision);
    expected.addAll(createHgMaterialWithMultipleRevisions(1L, first));
    expected.addAll(createSvnMaterialWithMultipleRevisions(2L, first));
    MaterialRevisions actual = new MaterialRevisions();
    actual.addRevision(up1Revision);
    actual.addAll(createHgMaterialWithMultipleRevisions(1L, third));
    actual.addAll(createSvnMaterialWithMultipleRevisions(2L, third));
    PipelineConfig current = createPipelineConfigWithMaterialConfig("current", new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")), MaterialConfigsMother.hgMaterialConfig(), MaterialConfigsMother.svnMaterialConfig());
    PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", MaterialConfigsMother.hgMaterialConfig(), MaterialConfigsMother.svnMaterialConfig());
    Pipeline pipeline = PipelineMother.passedPipelineInstance("up1", "stage", "job");
    pipeline.setId(10);
    when(pipelineDao.findPipelineByNameAndCounter("up1", 1)).thenReturn(pipeline);
    when(materialRepository.findMaterialRevisionsForPipeline(10)).thenReturn(expected);
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1));
    assertThat(service.getRevisionsBasedOnDependencies(dependencyGraph, actual), is(expected));
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.dependencyMaterialRevision(com.thoughtworks.go.helper.ModificationsMother.dependencyMaterialRevision) ModificationsMother.changedDependencyMaterialRevision(com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Aggregations

DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)131 Test (org.junit.Test)83 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)23 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)22 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)22 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)17 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)13 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)11 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)10 Date (java.util.Date)10 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)9 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)8 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)8 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)8 Pipeline (com.thoughtworks.go.domain.Pipeline)8 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)8 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)7 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)7 ModificationsMother.changedDependencyMaterialRevision (com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision)7