Search in sources :

Example 1 with NodeStepNamePredicate

use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepNamePredicate in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method verifySucceededCleanly.

static void verifySucceededCleanly(Jenkins j, WorkflowRun run) throws Exception {
    Assert.assertEquals(Result.SUCCESS, run.getResult());
    int outputHash = run.getLog().hashCode();
    FlowExecution exec = run.getExecution();
    verifyCompletedCleanly(j, run);
    // Confirm the flow graph is fully navigable and contains the heads with appropriate ending
    DepthFirstScanner scan = new DepthFirstScanner();
    List<FlowNode> allNodes = scan.allNodes(exec);
    FlowNode endNode = exec.getCurrentHeads().get(0);
    Assert.assertEquals(FlowEndNode.class, endNode.getClass());
    assert allNodes.contains(endNode);
    Assert.assertEquals(8, allNodes.size());
    // Graph structure assertions
    Assert.assertEquals(2, scan.filteredNodes(endNode, (Predicate) (Predicates.instanceOf(StepStartNode.class))).size());
    Assert.assertEquals(2, scan.filteredNodes(endNode, (Predicate) (Predicates.instanceOf(StepEndNode.class))).size());
    Assert.assertEquals(1, scan.filteredNodes(endNode, (Predicate) (Predicates.instanceOf(FlowStartNode.class))).size());
    Predicate<FlowNode> sleepOrSemaphoreMatch = Predicates.or(new NodeStepNamePredicate(StepDescriptor.byFunctionName("semaphore").getId()), new NodeStepNamePredicate(StepDescriptor.byFunctionName("sleep").getId()));
    Assert.assertEquals(1, scan.filteredNodes(endNode, sleepOrSemaphoreMatch).size());
    Assert.assertEquals(1, scan.filteredNodes(endNode, new NodeStepNamePredicate(StepDescriptor.byFunctionName("echo").getId())).size());
    for (FlowNode node : (List<FlowNode>) (scan.filteredNodes(endNode, (Predicate) (Predicates.instanceOf(StepNode.class))))) {
        Assert.assertNotNull("Node: " + node.toString() + " does not have a TimingAction", node.getAction(TimingAction.class));
    }
    assertHasTimingAction(run.getExecution());
}
Also used : FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) StepStartNode(org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode) TimingAction(org.jenkinsci.plugins.workflow.actions.TimingAction) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) NodeStepNamePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepNamePredicate) FlowDurabilityHint(org.jenkinsci.plugins.workflow.flow.FlowDurabilityHint) DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) StepNode(org.jenkinsci.plugins.workflow.cps.nodes.StepNode) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) List(java.util.List) ArrayList(java.util.ArrayList) CopyOnWriteList(hudson.util.CopyOnWriteList) FlowExecutionList(org.jenkinsci.plugins.workflow.flow.FlowExecutionList) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Aggregations

CopyOnWriteList (hudson.util.CopyOnWriteList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TimingAction (org.jenkinsci.plugins.workflow.actions.TimingAction)1 StepEndNode (org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode)1 StepNode (org.jenkinsci.plugins.workflow.cps.nodes.StepNode)1 StepStartNode (org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode)1 FlowDurabilityHint (org.jenkinsci.plugins.workflow.flow.FlowDurabilityHint)1 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)1 FlowExecutionList (org.jenkinsci.plugins.workflow.flow.FlowExecutionList)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1 FlowStartNode (org.jenkinsci.plugins.workflow.graph.FlowStartNode)1 DepthFirstScanner (org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner)1 NodeStepNamePredicate (org.jenkinsci.plugins.workflow.graphanalysis.NodeStepNamePredicate)1