use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class LevelAssignmentTest method shouldAssignLevelsForDownstreamNodesOfCurrentMaterial.
@Test
public void shouldAssignLevelsForDownstreamNodesOfCurrentMaterial() throws Exception {
/*
---> p1 ----
/ \
git --> p ----------> p3
\ /
---> p2 ----
*/
Node p = new PipelineDependencyNode("p", "p");
Node p1 = new PipelineDependencyNode("p1", "p1");
Node p2 = new PipelineDependencyNode("p2", "p2");
Node p3 = new PipelineDependencyNode("p3", "p3");
GitMaterial material = new GitMaterial("url");
Modification modification = ModificationsMother.aCheckIn("1");
ValueStreamMap valueStreamMap = new ValueStreamMap(material, null, modification);
Node gitNode = valueStreamMap.getCurrentMaterial();
valueStreamMap.addDownstreamNode(p, gitNode.getId());
valueStreamMap.addDownstreamNode(p1, p.getId());
valueStreamMap.addDownstreamNode(p2, p.getId());
valueStreamMap.addDownstreamNode(p3, p1.getId());
valueStreamMap.addDownstreamNode(p3, p2.getId());
NodeLevelMap levelToNodeMap = new LevelAssignment().apply(valueStreamMap);
assertThat(valueStreamMap.getCurrentMaterial().getLevel(), is(0));
assertThat(p.getLevel(), is(1));
assertThat(p1.getLevel(), is(2));
assertThat(p2.getLevel(), is(2));
assertThat(p3.getLevel(), is(3));
assertThat(levelToNodeMap.get(0), contains(valueStreamMap.getCurrentMaterial()));
assertThat(levelToNodeMap.get(1), containsInAnyOrder(p));
assertThat(levelToNodeMap.get(2), containsInAnyOrder(p1, p2));
assertThat(levelToNodeMap.get(3), contains(p3));
}
use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class MaterialDatabaseGitUpdaterTest method shouldRemoveFlyweightWhenConfiguredBranchDoesNotExist.
@Test
public void shouldRemoveFlyweightWhenConfiguredBranchDoesNotExist() throws Exception {
File flyweightDir = new File("pipelines", "flyweight");
FileUtils.deleteQuietly(flyweightDir);
material = new GitMaterial(testRepo.projectRepositoryUrl(), "bad-bad-branch");
try {
updater.updateMaterial(material);
fail("material update should have failed as given branch does not exist in repository");
} catch (Exception e) {
//ignore
}
MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
assertThat(materialInstance, is(nullValue()));
//no flyweight dir left behind
assertThat(FileUtil.listFiles(flyweightDir).length, is(0));
}
use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldNotBlowUpReportErrorIfAnAttemptIsMadeToInsertOnlyDuplicateModificationsForAGivenMaterial.
@Test
public void shouldNotBlowUpReportErrorIfAnAttemptIsMadeToInsertOnlyDuplicateModificationsForAGivenMaterial() {
final MaterialInstance materialInstance = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
final ArrayList<Modification> firstSetOfModifications = getModifications(3);
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance, firstSetOfModifications);
return null;
}
});
Modifications firstSetOfModificationsFromDb = repo.getModificationsFor(materialInstance, Pagination.pageByNumber(1, 10, 10));
assertThat(firstSetOfModificationsFromDb.size(), is(3));
for (Modification modification : firstSetOfModifications) {
assertThat(firstSetOfModificationsFromDb.containsRevisionFor(modification), is(true));
}
final ArrayList<Modification> secondSetOfModificationsContainingAllDuplicateRevisions = getModifications(3);
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance, secondSetOfModificationsContainingAllDuplicateRevisions);
return null;
}
});
}
use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class DownstreamInstancePopulatorIntegrationTest method shouldPopulateInstancesBuiltFromCurrentMaterial.
@Test
public void shouldPopulateInstancesBuiltFromCurrentMaterial() {
/*
g1 -> P -> P2 --> P4
| \ /
| + P3 +
+-> Q
|
+-> R
*/
GitMaterial g1 = u.wf(new GitMaterial("g1"), "folder3");
u.checkinInOrder(g1, "g_1", "g_2");
ScheduleTestUtil.AddedPipeline p = u.saveConfigWith("p", u.m(g1));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(p));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(p2));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(p2), u.m(p3));
ScheduleTestUtil.AddedPipeline q = u.saveConfigWith("q", u.m(g1));
ScheduleTestUtil.AddedPipeline r = u.saveConfigWith("r", u.m(g1));
String p_1 = u.runAndPass(p, "g_1");
String p2_1 = u.runAndPass(p2, p_1);
String p3_1 = u.runAndPass(p3, p2_1);
String p4_1 = u.runAndPass(p4, p2_1, p3_1);
String q_1 = u.runAndPass(q, "g_1");
String q_2 = u.runAndPass(q, "g_1");
MaterialInstance g1Instance = materialRepository.findMaterialInstance(g1);
Modification g1Modification = materialRepository.findModificationWithRevision(g1, "g_1");
ValueStreamMap valueStreamMap = new ValueStreamMap(g1, g1Instance, g1Modification);
Node gitNode = valueStreamMap.getCurrentMaterial();
Node nodep1 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p", "p"), gitNode.getId());
Node nodep2 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p2", "p2"), "p");
Node nodep3 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p3", "p3"), "p2");
Node nodep4 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p4", "p4"), "p3");
valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p4", "p4"), "p2");
Node nodep5 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("q", "q"), gitNode.getId());
Node nodep6 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("r", "r"), gitNode.getId());
downstreamInstancePopulator.apply(valueStreamMap);
assertInstances(nodep1, "p", 1);
assertInstances(nodep2, "p2", 1);
assertInstances(nodep3, "p3", 1);
assertInstances(nodep4, "p4", 1);
assertInstances(nodep5, "q", 1, 2);
assertThat(nodep6.revisions().size(), is(0));
}
use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class DownstreamInstancePopulatorIntegrationTest method shouldPopulateMultipleInstancesBuiltFromUpstreamRevisions.
@Test
public void shouldPopulateMultipleInstancesBuiltFromUpstreamRevisions() {
/*
g1 -> P -> P2 --> P4 --> P5
\ /
+ P3 +
*/
ValueStreamMap valueStreamMap = new ValueStreamMap("p", new PipelineRevision("p", 1, "13.1.1"));
Node nodep2 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p2", "p2"), "p");
Node nodep3 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p3", "p3"), "p2");
Node nodep4 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p4", "p4"), "p3");
valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p4", "p4"), "p2");
valueStreamMap.addUpstreamMaterialNode(new SCMDependencyNode("g1", "g1", "git"), new CaseInsensitiveString("git"), "p", new MaterialRevision(null));
GitMaterial g1 = u.wf(new GitMaterial("g1"), "folder3");
u.checkinInOrder(g1, "g_1");
ScheduleTestUtil.AddedPipeline p = u.saveConfigWith("p", u.m(g1));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(p));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(p2));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(p2), u.m(p3));
String p_1 = u.runAndPass(p, "g_1");
String p2_1 = u.runAndPass(p2, p_1);
String p2_2 = u.runAndPass(p2, p_1);
String p3_1 = u.runAndPass(p3, p2_2);
String p4_1 = u.runAndPass(p4, p2_1, p3_1);
String p4_2 = u.runAndPass(p4, p2_2, p3_1);
downstreamInstancePopulator.apply(valueStreamMap);
assertInstances(nodep2, "p2", 1, 2);
assertInstances(nodep3, "p3", 1);
assertInstances(nodep4, "p4", 1, 2);
}
Aggregations