use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class FaninDependencyResolutionTest method shouldResolveDiamondDependencyWithChildrenDependingOnDifferentStageDependency.
@Test
public void shouldResolveDiamondDependencyWithChildrenDependingOnDifferentStageDependency() throws Exception {
/*
+---> P3 ---+
| v
pkg -> P2 P5
| ^
+--> P4 ----+
*/
GitMaterial git = u.wf(new GitMaterial("git"), "f");
u.checkinInOrder(git, "g1");
ScheduleTestUtil.AddedPipeline p2_s1 = u.saveConfigWith("p2", "s1", u.m(git));
ScheduleTestUtil.AddedPipeline p2_s2 = u.addStageToPipeline(p2_s1.config.name(), "s2");
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(new DependencyMaterial(p2_s1.config.name(), new CaseInsensitiveString("s1"))));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(new DependencyMaterial(p2_s1.config.name(), new CaseInsensitiveString("s2"))));
ScheduleTestUtil.AddedPipeline p5 = u.saveConfigWith("p5", u.m(p3), u.m(p4));
String p2_s1_1 = u.runAndPass(p2_s1, "g1");
String p2_s2_1 = u.runAndPass(p2_s2, "g1");
String p3_1 = u.runAndPass(p3, p2_s1_1);
String p4_1 = u.runAndPass(p4, p2_s2_1);
MaterialRevisions given = u.mrs(u.mr(p3, true, p3_1), u.mr(p4, true, p4_1));
MaterialRevisions revisionsBasedOnDependencies = getRevisionsBasedOnDependencies(p5, goConfigDao.load(), given);
assertThat(revisionsBasedOnDependencies, is(given));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class FaninDependencyResolutionTest method shouldComputeRevisionCorrectlyWhenUpstreamPipelineHasModifications_ForDifferentStages.
@Test
public void shouldComputeRevisionCorrectlyWhenUpstreamPipelineHasModifications_ForDifferentStages() throws Exception {
/*
/-->P1------\ p2(s1) --> p4
git P3
\-->P2(S2)--/
*/
GitMaterial git = u.wf(new GitMaterial("git"), "f");
ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("p1", u.m(git));
ScheduleTestUtil.AddedPipeline p2_s1 = u.saveConfigWith("p2", "s1", u.m(git));
ScheduleTestUtil.AddedPipeline p2_s2 = u.addStageToPipeline(p2_s1.config.name(), "s2");
ScheduleTestUtil.MaterialDeclaration p2_material = u.m(new DependencyMaterial(p2_s1.config.name(), new CaseInsensitiveString("s2")));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", p2_material, u.m(p1));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(new DependencyMaterial(p2_s1.config.name(), new CaseInsensitiveString("s1"))));
u.checkinInOrder(git, "g1");
String p1_1 = u.runAndPass(p1, "g1");
String p2_s2_1 = u.runAndPass(p2_s2, "g1");
MaterialRevisions given = u.mrs(u.mr(p1, true, p1_1), u.mr(p2_s2, true, p2_s2_1));
MaterialRevisions revisionsBasedOnDependencies = getRevisionsBasedOnDependencies(p3, goConfigDao.load(), given);
assertThat(revisionsBasedOnDependencies, is(given));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterIntegrationTest method shouldInsertAllRunsAfterLastKnownOfUpstreamStage.
@Test
public void shouldInsertAllRunsAfterLastKnownOfUpstreamStage() throws Exception {
PipelineConfig mingleConfig = PipelineConfigMother.createPipelineConfig("acceptance", "stage-name", "job");
goConfigService.addPipeline(mingleConfig, "pipeline-group");
Pipeline passed1 = dbHelper.schedulePipeline(mingleConfig, new TimeProvider());
dbHelper.passStage(passed1.getStages().get(0));
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("acceptance"), new CaseInsensitiveString("stage-name"));
String revision1 = String.format("acceptance/%s/stage-name/1", passed1.getCounter());
updater.updateMaterial(dependencyMaterial);
assertThat(materialRepository.findModificationWithRevision(dependencyMaterial, revision1), is(not(nullValue())));
Pipeline cancelledPipeline = dbHelper.schedulePipeline(mingleConfig, new TimeProvider());
dbHelper.cancelStage(cancelledPipeline.getStages().get(0));
Pipeline passed2 = dbHelper.schedulePipeline(mingleConfig, new TimeProvider());
dbHelper.passStage(passed2.getStages().get(0));
updater.updateMaterial(dependencyMaterial);
assertThat(materialRepository.findModificationWithRevision(dependencyMaterial, String.format("acceptance/%s/stage-name/1", cancelledPipeline.getCounter())), is(nullValue()));
Modification modification1 = materialRepository.findModificationWithRevision(dependencyMaterial, revision1);
assertThat(modification1, is(not(nullValue())));
assertThat(modification1.getRevision(), is(revision1));
assertThat(modification1.getPipelineLabel(), is(passed1.getCounter().toString()));
assertThat(modification1.getPipelineId(), is(passed1.getId()));
String revision2 = String.format("acceptance/%s/stage-name/1", passed2.getCounter());
Modification modification2 = materialRepository.findModificationWithRevision(dependencyMaterial, revision2);
assertThat(modification2, is(not(nullValue())));
assertThat(modification2.getRevision(), is(revision2));
assertThat(modification2.getPipelineLabel(), is(passed2.getCounter().toString()));
assertThat(modification2.getPipelineId(), is(passed2.getId()));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldReturnNoNewModificationsIfPipelineHasNeverBeenScheduled.
@Test
public void shouldReturnNoNewModificationsIfPipelineHasNeverBeenScheduled() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
stubStageServiceGetHistory(null);
updater.updateMaterial(dependencyMaterial);
MaterialRevisions materialRevisions = materialRepository.findLatestModification(dependencyMaterial);
assertThat("materialRevisions.isEmpty()", materialRevisions.isEmpty(), is(true));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method stubStageServiceGetHistoryAfter.
private void stubStageServiceGetHistoryAfter(DependencyMaterial material, int pipelineCounter, Stages... stageses) {
if (material == null) {
material = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
}
StageIdentifier identifier = new StageIdentifier(String.format("%s/%s/%s/0", material.getPipelineName().toString(), pipelineCounter, material.getStageName().toString()));
for (int i = 0; i < stageses.length; i++) {
Stages stages = stageses[i];
List<Modification> mods = new ArrayList<>();
for (Stage stage : stages) {
StageIdentifier id = stage.getIdentifier();
mods.add(new Modification(stage.completedDate(), id.stageLocator(), id.getPipelineLabel(), stage.getPipelineId()));
}
Mockito.when(dependencyMaterialSourceDao.getPassedStagesAfter(identifier.stageLocator(), material, Pagination.pageStartingAt(i * MaterialDatabaseUpdater.STAGES_PER_PAGE, null, MaterialDatabaseUpdater.STAGES_PER_PAGE))).thenReturn(mods);
}
when(dependencyMaterialSourceDao.getPassedStagesAfter(identifier.stageLocator(), material, Pagination.pageStartingAt(MaterialDatabaseUpdater.STAGES_PER_PAGE * stageses.length, null, MaterialDatabaseUpdater.STAGES_PER_PAGE))).thenReturn(new ArrayList<>());
}
Aggregations