예제 #1
0
 def test_exclusive_gateway(self):
     gw_id = '1'
     conditions = [Condition(None, None), Condition(None, None)]
     ex_gateway = ExclusiveGateway(id=gw_id, conditions=conditions)
     self.assertTrue(isinstance(ex_gateway, FlowNode))
     self.assertTrue(isinstance(ex_gateway, Gateway))
     self.assertEqual(conditions, ex_gateway.conditions)
    def test_targets_meet_condition__raise_exhausted(self):
        condition_1 = Condition(evaluate='1 == 0',
                                sequence_flow=SequenceFlow(id=self.id,
                                                           source='1',
                                                           target='1'))
        condition_2 = Condition(evaluate='1 == 0',
                                sequence_flow=SequenceFlow(id=self.id,
                                                           source='2',
                                                           target='2'))
        condition_3 = Condition(evaluate='1 == 0',
                                sequence_flow=SequenceFlow(id=self.id,
                                                           source='3',
                                                           target='3'))
        condition_4 = Condition(evaluate='1 == 0',
                                sequence_flow=SequenceFlow(id=self.id,
                                                           source='4',
                                                           target='4'))
        cpg = ConditionalParallelGateway(
            id=self.id,
            converge_gateway_id=self.converge_gateway_id,
            conditions=[condition_1, condition_2, condition_3, condition_4])

        self.assertRaises(ConditionExhaustedException,
                          cpg.targets_meet_condition, {})
    def test_targets_meet_condition__normal(self):
        condition_1 = Condition(evaluate='1 == 1',
                                sequence_flow=SequenceFlow(id=self.id,
                                                           source='1',
                                                           target='1'))
        condition_2 = Condition(evaluate='1 == 0',
                                sequence_flow=SequenceFlow(id=self.id,
                                                           source='2',
                                                           target='2'))
        condition_3 = Condition(evaluate='1 == 1',
                                sequence_flow=SequenceFlow(id=self.id,
                                                           source='3',
                                                           target='3'))
        condition_4 = Condition(evaluate='1 == 0',
                                sequence_flow=SequenceFlow(id=self.id,
                                                           source='4',
                                                           target='4'))
        cpg = ConditionalParallelGateway(
            id=self.id,
            converge_gateway_id=self.converge_gateway_id,
            conditions=[condition_1, condition_2, condition_3, condition_4])

        targets = cpg.targets_meet_condition({})
        self.assertEqual(targets, ['1', '3'])
예제 #4
0
    def setUp(self):
        ex_gateway1 = ExclusiveGateway(id='1')
        next_node1 = ParallelGateway(id='1', converge_gateway_id='cvg')
        next_node2 = ParallelGateway(id='2', converge_gateway_id='cvg')
        flow1 = SequenceFlow('flow1', ex_gateway1, next_node1)
        flow2 = SequenceFlow('flow2', ex_gateway1, next_node2)
        condition1 = Condition('a == 1', flow1)
        condition2 = Condition('a != 1', flow2)
        ex_gateway1.add_condition(condition1)
        ex_gateway1.add_condition(condition2)
        ex_gateway1.outgoing.add_flow(flow1)
        ex_gateway1.outgoing.add_flow(flow2)
        next_node1.incoming.add_flow(flow1)
        next_node2.incoming.add_flow(flow2)

        self.gateway_for_test_determine = ex_gateway1

        ex_gateway2 = ExclusiveGateway(id='2')
        next_node3 = ParallelGateway(id='3', converge_gateway_id='cvg')
        next_node4 = ParallelGateway(id='4', converge_gateway_id='cvg')
        next_node5 = ParallelGateway(id='5', converge_gateway_id='cvg')
        flow3 = SequenceFlow('flow3', ex_gateway2, next_node3)
        flow4 = SequenceFlow('flow4', ex_gateway2, next_node4)
        flow5 = SequenceFlow('flow5', ex_gateway2, next_node5, is_default=True)
        condition3 = Condition('a == 1', flow3)
        condition4 = Condition('a != 1', flow4)
        ex_gateway2.add_condition(condition3)
        ex_gateway2.add_condition(condition4)
        ex_gateway2.outgoing.add_flow(flow3)
        ex_gateway2.outgoing.add_flow(flow4)
        ex_gateway2.outgoing.add_flow(flow5)
        next_node3.incoming.add_flow(flow3)
        next_node4.incoming.add_flow(flow4)
        next_node5.incoming.add_flow(flow5)

        self.gateway_for_test_next = ex_gateway2
예제 #5
0
def get_exclusive_gateway_pipeline(result):
    start_event_a_id = node_uniqid()
    act_b_id = node_uniqid()
    gateway_c_id = node_uniqid()
    act_d_id = node_uniqid()
    act_e_id = node_uniqid()
    act_f_id = node_uniqid()
    gateway_g_id = node_uniqid()
    end_event_h_id = node_uniqid()

    start_event_a = EmptyStartEvent(start_event_a_id)
    b_act = ServiceActivity(act_b_id,
                            service=EchoService(),
                            data=DataObject({'a': 3}))
    c_gateway = ExclusiveGateway(gateway_c_id, gateway_g_id)
    d_act = ServiceActivity(act_d_id,
                            service=LogService(),
                            data=DataObject({'node': 'd'}))
    e_act = ServiceActivity(act_e_id,
                            service=EchoService(),
                            data=DataObject({'node': 'e'}))
    f_act = ServiceActivity(act_f_id,
                            service=TestService(),
                            data=DataObject({'node': 'f'}))
    g_gateway = ConvergeGateway(gateway_g_id)
    end_event_h = EmptyEndEvent(end_event_h_id)

    ab_flow = SequenceFlow('ab', start_event_a, b_act)
    bc_flow = SequenceFlow('bc', b_act, c_gateway)
    cd_flow = SequenceFlow('cd', c_gateway, d_act)
    ce_flow = SequenceFlow('ce', c_gateway, e_act)
    cf_flow = SequenceFlow('cf', c_gateway, f_act)
    dg_flow = SequenceFlow('dg', d_act, g_gateway)
    eg_flow = SequenceFlow('eg', e_act, g_gateway)
    fg_flow = SequenceFlow('fg', f_act, g_gateway)
    gh_flow = SequenceFlow('gh', g_gateway, end_event_h)

    start_event_a.outgoing.add_flow(ab_flow)
    b_act.incoming.add_flow(ab_flow)
    b_act.outgoing.add_flow(bc_flow)
    c_gateway.incoming.add_flow(bc_flow)
    c_gateway.outgoing.add_flow(cd_flow)
    c_gateway.outgoing.add_flow(ce_flow)
    c_gateway.outgoing.add_flow(cf_flow)
    d_act.incoming.add_flow(cd_flow)
    d_act.outgoing.add_flow(dg_flow)
    e_act.incoming.add_flow(ce_flow)
    e_act.outgoing.add_flow(eg_flow)
    f_act.incoming.add_flow(cf_flow)
    f_act.outgoing.add_flow(fg_flow)
    g_gateway.incoming.add_flow(dg_flow)
    g_gateway.incoming.add_flow(eg_flow)
    g_gateway.incoming.add_flow(fg_flow)
    g_gateway.outgoing.add_flow(gh_flow)
    end_event_h.incoming.add_flow(gh_flow)

    c_gateway.add_condition(Condition('result == 1', cd_flow))
    c_gateway.add_condition(Condition('result == 2', ce_flow))
    c_gateway.add_condition(Condition('result == 3', cf_flow))
    spec = PipelineSpec(start_event_a,
                        end_event_h, [
                            ab_flow, bc_flow, cd_flow, ce_flow, cf_flow,
                            dg_flow, eg_flow, fg_flow, gh_flow
                        ], [b_act, d_act, e_act, f_act],
                        [c_gateway, g_gateway],
                        data=DataObject({}),
                        context=context.Context(act_outputs={},
                                                scope={'result': result}))
    return Pipeline(node_uniqid(), spec)