use of com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode in project gocd by gocd.
the class CrossingMinimizationTest method shouldAssignNodesBasedOnMinimumDepthForDownstreamGraph.
@Test
public void shouldAssignNodesBasedOnMinimumDepthForDownstreamGraph() {
/*
g1 --> P ---> P1 P3
\ /
+-> P2
*/
CaseInsensitiveString p = new CaseInsensitiveString("P");
CaseInsensitiveString g1Name = new CaseInsensitiveString("g1");
CaseInsensitiveString p1Name = new CaseInsensitiveString("p1");
CaseInsensitiveString p2Name = new CaseInsensitiveString("P2");
CaseInsensitiveString p3Name = new CaseInsensitiveString("P3");
ValueStreamMap graph = new ValueStreamMap(p, null);
Node g1 = graph.addUpstreamMaterialNode(new SCMDependencyNode(g1Name.toString(), g1Name.toString(), "git"), null, p, new MaterialRevision(null));
Node p1 = graph.addDownstreamNode(new PipelineDependencyNode(p1Name, p1Name.toString()), p);
Node p2 = graph.addDownstreamNode(new PipelineDependencyNode(p2Name, p2Name.toString()), p);
Node p3 = graph.addDownstreamNode(new PipelineDependencyNode(p3Name, p3Name.toString()), p2Name);
NodeLevelMap levelToNodesMap = nodeLevelMap(graph);
crossingMinimization.apply(levelToNodesMap);
assertThat(levelToNodesMap.get(-1), is(Arrays.asList(g1)));
assertThat(levelToNodesMap.get(0), is(Arrays.asList(graph.getCurrentPipeline())));
assertThat(levelToNodesMap.get(1), is(Arrays.asList(p1, p2)));
assertThat(levelToNodesMap.get(2), is(Arrays.asList(p3)));
assertThat(p1.getDepth(), is(1));
assertThat(p2.getDepth(), is(2));
assertThat(p3.getDepth(), is(2));
}
use of com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode 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(new CaseInsensitiveString("p"), "p");
Node p1 = new PipelineDependencyNode(new CaseInsensitiveString("p1"), "p1");
Node p2 = new PipelineDependencyNode(new CaseInsensitiveString("p2"), "p2");
Node p3 = new PipelineDependencyNode(new CaseInsensitiveString("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.domain.valuestreammap.PipelineDependencyNode in project gocd by gocd.
the class LevelAssignmentTest method shouldAssignLevelsForUpstreamNodesOfCurrentPipeline.
@Test
public void shouldAssignLevelsForUpstreamNodesOfCurrentPipeline() throws Exception {
/*
---> p1 ---
/ \
g -----------p3
\ /
---> p2 ---
*/
CaseInsensitiveString current = new CaseInsensitiveString("p3");
CaseInsensitiveString p1name = new CaseInsensitiveString("p1");
CaseInsensitiveString p2name = new CaseInsensitiveString("p2");
Node p1 = new PipelineDependencyNode(p1name, p1name.toString());
Node p2 = new PipelineDependencyNode(p2name, p2name.toString());
Node gitNode = new SCMDependencyNode("git", "g", "git");
ValueStreamMap valueStreamMap = new ValueStreamMap(current, new PipelineRevision(current.toString(), 1, "1"));
valueStreamMap.addUpstreamNode(p1, new PipelineRevision(p1name.toString(), 1, "1"), current);
valueStreamMap.addUpstreamNode(p2, new PipelineRevision(p2name.toString(), 1, "1"), current);
valueStreamMap.addUpstreamMaterialNode(gitNode, new CaseInsensitiveString("trunk"), p1name, new MaterialRevision(null));
valueStreamMap.addUpstreamMaterialNode(gitNode, new CaseInsensitiveString("main-branch"), new CaseInsensitiveString("p3"), new MaterialRevision(null));
valueStreamMap.addUpstreamMaterialNode(gitNode, new CaseInsensitiveString("main-branch"), p2name, new MaterialRevision(null));
NodeLevelMap levelToNodeMap = new LevelAssignment().apply(valueStreamMap);
assertThat(valueStreamMap.getCurrentPipeline().getLevel(), is(0));
assertThat(p1.getLevel(), is(-1));
assertThat(p2.getLevel(), is(-1));
assertThat(gitNode.getLevel(), is(-2));
assertThat(levelToNodeMap.get(0), contains(valueStreamMap.getCurrentPipeline()));
assertThat(levelToNodeMap.get(-1), containsInAnyOrder(p1, p2));
assertThat(levelToNodeMap.get(-2), contains(gitNode));
}
use of com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode in project gocd by gocd.
the class DummyNodeCreationTest method shouldCreateDummyNodeAtRightIndexToHelpInMinimizingCrossings.
@Test
public void shouldCreateDummyNodeAtRightIndexToHelpInMinimizingCrossings() {
/*
+---> d1 ---> d4---->d5
d3 |
+---> X ------+
| |
------d2-----+
*/
CaseInsensitiveString currentPipeline = new CaseInsensitiveString("d5");
CaseInsensitiveString d4 = new CaseInsensitiveString("d4");
CaseInsensitiveString d1 = new CaseInsensitiveString("d1");
CaseInsensitiveString d3 = new CaseInsensitiveString("d3");
CaseInsensitiveString d2 = new CaseInsensitiveString("d2");
ValueStreamMap graph = new ValueStreamMap(currentPipeline, null);
graph.addUpstreamNode(new PipelineDependencyNode(d4, d4.toString()), null, currentPipeline);
graph.addUpstreamNode(new PipelineDependencyNode(d1, d1.toString()), null, d4);
graph.addUpstreamNode(new PipelineDependencyNode(d3, d3.toString()), null, d1);
graph.addUpstreamNode(new PipelineDependencyNode(d3, d3.toString()), null, d4);
graph.addUpstreamNode(new PipelineDependencyNode(d2, d2.toString()), null, d4);
graph.addUpstreamNode(new PipelineDependencyNode(d3, d3.toString()), null, d2);
NodeLevelMap nodeLevelMap = new LevelAssignment().apply(graph);
dummyNodeCreation.apply(graph, nodeLevelMap);
VSMTestHelper.assertNumberOfLevelsInGraph(nodeLevelMap, 4);
VSMTestHelper.assertThatNodeHasChildren(graph, d3, 1, d1, d2);
Node secondChildOfD3 = graph.findNode(d3).getChildren().get(1);
assertThat(secondChildOfD3.getType(), is(DependencyNodeType.DUMMY));
}
use of com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode in project gocd by gocd.
the class DummyNodeCreationTest method shouldHandleDeepTriangle.
@Test
public void shouldHandleDeepTriangle() {
/*
+---> d1 ---> d2 ---> d3
g ^
+---- x ----- x ------+
*/
CaseInsensitiveString currentPipeline = new CaseInsensitiveString("d3");
CaseInsensitiveString d1 = new CaseInsensitiveString("d1");
CaseInsensitiveString d2 = new CaseInsensitiveString("d2");
CaseInsensitiveString g = new CaseInsensitiveString("g");
ValueStreamMap graph = new ValueStreamMap(currentPipeline, null);
graph.addUpstreamNode(new PipelineDependencyNode(d2, d2.toString()), null, currentPipeline);
graph.addUpstreamNode(new PipelineDependencyNode(d1, d1.toString()), null, d2);
graph.addUpstreamMaterialNode(new SCMDependencyNode(g.toString(), g.toString(), "git"), null, d1, new MaterialRevision(null));
graph.addUpstreamMaterialNode(new SCMDependencyNode(g.toString(), g.toString(), "git"), null, currentPipeline, new MaterialRevision(null));
NodeLevelMap nodeLevelMap = new LevelAssignment().apply(graph);
dummyNodeCreation.apply(graph, nodeLevelMap);
VSMTestHelper.assertNumberOfLevelsInGraph(nodeLevelMap, 4);
VSMTestHelper.assertThatLevelHasNodes(nodeLevelMap.get(0), 0, currentPipeline);
VSMTestHelper.assertThatLevelHasNodes(nodeLevelMap.get(-1), 1, d2);
VSMTestHelper.assertThatLevelHasNodes(nodeLevelMap.get(-2), 1, d1);
VSMTestHelper.assertThatLevelHasNodes(nodeLevelMap.get(-3), 0, g);
}
Aggregations