Search in sources :

Example 21 with ValueStreamMap

use of com.thoughtworks.go.domain.valuestreammap.ValueStreamMap in project gocd by gocd.

the class CrossingMinimizationTest method shouldAssignNodesBasedOnMinimumDepthForUpstreamGraph.

@Test
public void shouldAssignNodesBasedOnMinimumDepthForUpstreamGraph() {
    /*
            g1 --> P1 --> P
               \        / ^
                \     /   |
            g2   +->P2    |
               \          |
                \         |
            g3 --> P3-----+
         */
    String p = "P";
    String p1 = "P1";
    String p2 = "P2";
    String p3 = "P3";
    String g1 = "g1";
    String g2 = "g2";
    String g3 = "g3";
    ValueStreamMap graph = new ValueStreamMap(p, null);
    graph.addUpstreamNode(new PipelineDependencyNode(p1, p1), null, p);
    graph.addUpstreamMaterialNode(new SCMDependencyNode(g1, g1, "git"), null, p1, new MaterialRevision(null));
    graph.addUpstreamNode(new PipelineDependencyNode(p2, p2), null, p);
    graph.addUpstreamMaterialNode(new SCMDependencyNode(g1, g1, "git"), null, p2, new MaterialRevision(null));
    graph.addUpstreamNode(new PipelineDependencyNode(p3, p3), null, p);
    graph.addUpstreamMaterialNode(new SCMDependencyNode(g2, g2, "git"), null, p3, new MaterialRevision(null));
    graph.addUpstreamMaterialNode(new SCMDependencyNode(g3, g3, "git"), null, p3, new MaterialRevision(null));
    NodeLevelMap levelToNodesMap = nodeLevelMap(graph);
    crossingMinimization.apply(levelToNodesMap);
    assertThat(levelToNodesMap.get(0), is(Arrays.asList(graph.findNode(p))));
    assertThat(levelToNodesMap.get(-1), is(Arrays.asList(graph.findNode(p1), graph.findNode(p2), graph.findNode(p3))));
    assertThat(levelToNodesMap.get(-2), is(Arrays.asList(graph.findNode(g1), graph.findNode(g2), graph.findNode(g3))));
    assertThat(graph.findNode(g1).getDepth(), is(1));
    assertThat(graph.findNode(g2).getDepth(), is(2));
    assertThat(graph.findNode(g3).getDepth(), is(3));
    assertThat(graph.findNode(p1).getDepth(), is(1));
    assertThat(graph.findNode(p2).getDepth(), is(2));
    assertThat(graph.findNode(p3).getDepth(), is(3));
    assertThat(graph.findNode(p).getDepth(), is(1));
}
Also used : ValueStreamMap(com.thoughtworks.go.domain.valuestreammap.ValueStreamMap) PipelineDependencyNode(com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode) SCMDependencyNode(com.thoughtworks.go.domain.valuestreammap.SCMDependencyNode) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) NodeLevelMap(com.thoughtworks.go.domain.valuestreammap.NodeLevelMap) Test(org.junit.Test)

Example 22 with ValueStreamMap

use of com.thoughtworks.go.domain.valuestreammap.ValueStreamMap in project gocd by gocd.

the class CrossingMinimizationTest method shouldReorderNodesBasedOnBaryCenterValueForUpstreamGraph.

@Test
public void shouldReorderNodesBasedOnBaryCenterValueForUpstreamGraph() {
    /*
            g1 --> P1--->P3
               \/      /
               /\    /
            g2    P2
         */
    String p3 = "P3";
    String p1 = "P1";
    String p2 = "P2";
    String g1 = "g1";
    String g2 = "g2";
    ValueStreamMap graph = new ValueStreamMap(p3, null);
    graph.addUpstreamNode(new PipelineDependencyNode(p1, p1), null, p3);
    graph.addUpstreamMaterialNode(new SCMDependencyNode(g1, g1, "git"), null, p1, new MaterialRevision(null));
    graph.addUpstreamMaterialNode(new SCMDependencyNode(g2, g2, "git"), null, p1, new MaterialRevision(null));
    graph.addUpstreamNode(new PipelineDependencyNode(p2, p2), null, p3);
    graph.addUpstreamMaterialNode(new SCMDependencyNode(g1, g1, "git"), null, p2, new MaterialRevision(null));
    NodeLevelMap levelToNodesMap = nodeLevelMap(graph);
    assertThat(levelToNodesMap.get(-1), is(Arrays.asList(graph.findNode(p1), graph.findNode(p2))));
    crossingMinimization.apply(levelToNodesMap);
    assertThat(levelToNodesMap.get(0), is(Arrays.asList(graph.findNode(p3))));
    assertThat(levelToNodesMap.get(-1), is(Arrays.asList(graph.findNode(p2), graph.findNode(p1))));
    assertThat(levelToNodesMap.get(-2), is(Arrays.asList(graph.findNode(g1), graph.findNode(g2))));
    assertThat(graph.findNode(g1).getDepth(), is(1));
    assertThat(graph.findNode(g2).getDepth(), is(2));
    assertThat(graph.findNode(p1).getDepth(), is(2));
    assertThat(graph.findNode(p2).getDepth(), is(1));
    assertThat(graph.findNode(p3).getDepth(), is(1));
}
Also used : ValueStreamMap(com.thoughtworks.go.domain.valuestreammap.ValueStreamMap) PipelineDependencyNode(com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode) SCMDependencyNode(com.thoughtworks.go.domain.valuestreammap.SCMDependencyNode) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) NodeLevelMap(com.thoughtworks.go.domain.valuestreammap.NodeLevelMap) Test(org.junit.Test)

Aggregations

PipelineDependencyNode (com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode)22 ValueStreamMap (com.thoughtworks.go.domain.valuestreammap.ValueStreamMap)22 Test (org.junit.Test)22 SCMDependencyNode (com.thoughtworks.go.domain.valuestreammap.SCMDependencyNode)21 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)18 NodeLevelMap (com.thoughtworks.go.domain.valuestreammap.NodeLevelMap)15 Node (com.thoughtworks.go.domain.valuestreammap.Node)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)8 PipelineRevision (com.thoughtworks.go.domain.valuestreammap.PipelineRevision)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)5 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)4 Stages (com.thoughtworks.go.domain.Stages)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)1 Stage (com.thoughtworks.go.domain.Stage)1 Date (java.util.Date)1