Ejemplo n.º 1
0
def test_simple_schedule_pipeline():
    start_event_a_id = node_uniqid()
    act_b_id = node_uniqid()
    end_event_c_id = node_uniqid()

    start_event = EmptyStartEvent(start_event_a_id)
    act = ServiceActivity(act_b_id,
                          service=ScheduleService(),
                          data=DataObject({}))
    end_event = EmptyEndEvent(end_event_c_id)

    flow_ab = SequenceFlow('ab', start_event, act)
    flow_bc = SequenceFlow('bc', act, end_event)

    start_event.outgoing.add_flow(flow_ab)
    act.incoming.add_flow(flow_ab)
    act.outgoing.add_flow(flow_bc)
    end_event.incoming.add_flow(flow_bc)

    spec = PipelineSpec(start_event,
                        end_event, [flow_ab, flow_bc], [act], [],
                        data=DataObject({}),
                        context=context.Context({}))
    pipeline = Pipeline(node_uniqid(), spec)
    run_pipeline(pipeline)
Ejemplo n.º 2
0
    def subprocess():
        start_event_a_id = node_uniqid()
        act_b_id = node_uniqid()
        end_event_c_id = node_uniqid()

        start_event = EmptyStartEvent(start_event_a_id)
        act = ServiceActivity(act_b_id,
                              service=RetryTestService(),
                              data=DataObject({'data': '0'}))
        end_event = EmptyEndEvent(end_event_c_id)

        flow_ab = SequenceFlow('ab', start_event, act)
        flow_bc = SequenceFlow('bc', act, end_event)

        start_event.outgoing.add_flow(flow_ab)
        act.incoming.add_flow(flow_ab)
        act.outgoing.add_flow(flow_bc)
        end_event.incoming.add_flow(flow_bc)

        spec = PipelineSpec(start_event,
                            end_event, [flow_ab, flow_bc], [act], [],
                            data=DataObject({}),
                            context=context.Context({}))
        pipeline = Pipeline(node_uniqid(), spec)
        return pipeline
Ejemplo n.º 3
0
def get_simple_pipeline():
    start_event_a_id = node_uniqid()
    act_b_id = node_uniqid()
    end_event_c_id = node_uniqid()

    start_event = EmptyStartEvent(start_event_a_id)
    act = ServiceActivity(id=act_b_id,
                          service=RetryTestService(),
                          data=DataObject({
                              'data': '0',
                              'value2': '2',
                              'value3': '3',
                              'timing': 1000
                          }))
    end_event = EmptyEndEvent(end_event_c_id)

    flow_ab = SequenceFlow('ab', start_event, act)
    flow_bc = SequenceFlow('bc', act, end_event)

    start_event.outgoing.add_flow(flow_ab)
    act.incoming.add_flow(flow_ab)
    act.outgoing.add_flow(flow_bc)
    end_event.incoming.add_flow(flow_bc)

    spec = PipelineSpec(start_event,
                        end_event, [flow_ab, flow_bc], [act], [],
                        data=DataObject({}),
                        context=context.Context({}))
    return Pipeline(node_uniqid(), spec)
Ejemplo n.º 4
0
 def test_all_target(self):
     targets = [Obj(), Obj(), Obj()]
     flow1 = SequenceFlow('1', Obj(), targets[0])
     flow2 = SequenceFlow('4', Obj(), targets[1])
     flow3 = SequenceFlow('7', Obj(), targets[2])
     flows = [flow1, flow2, flow3]
     collection = SequenceFlowCollection(*flows)
     self.assertEqual(targets, collection.all_target_node())
Ejemplo n.º 5
0
 def test_all_source(self):
     sources = [Obj(), Obj(), Obj()]
     flow1 = SequenceFlow('1', sources[0], Obj())
     flow2 = SequenceFlow('4', sources[1], Obj())
     flow3 = SequenceFlow('7', sources[2], Obj())
     flows = [flow1, flow2, flow3]
     collection = SequenceFlowCollection(*flows)
     self.assertEqual(sources, collection.all_source_node())
Ejemplo n.º 6
0
 def test_sequence_flow_collection(self):
     flow1 = SequenceFlow('1', Obj(), Obj())
     flow2 = SequenceFlow('4', Obj(), Obj())
     flow3 = SequenceFlow('7', Obj(), Obj())
     flows = [flow1, flow2, flow3]
     flow_dict = {flow1.id: flow1, flow2.id: flow2, flow3.id: flow3}
     collection = SequenceFlowCollection(*flows)
     self.assertEqual(flows, collection.flows)
     self.assertEqual(flow_dict, collection.flow_dict)
Ejemplo n.º 7
0
 def test_get_flow(self):
     flow1 = SequenceFlow('1', Obj(), Obj())
     flow2 = SequenceFlow('4', Obj(), Obj())
     flow3 = SequenceFlow('7', Obj(), Obj())
     flows = [flow1, flow2, flow3]
     collection = SequenceFlowCollection(*flows)
     self.assertEqual(flow1, collection.get_flow(flow1.id))
     self.assertEqual(flow2, collection.get_flow(flow2.id))
     self.assertEqual(flow3, collection.get_flow(flow3.id))
Ejemplo n.º 8
0
 def test_is_empty(self):
     flow1 = SequenceFlow('1', Obj(), Obj())
     flow2 = SequenceFlow('4', Obj(), Obj())
     flow3 = SequenceFlow('7', Obj(), Obj())
     flows = [flow1, flow2, flow3]
     not_empty_collection = SequenceFlowCollection(*flows)
     empty_collection = SequenceFlowCollection()
     self.assertTrue(empty_collection.is_empty())
     self.assertFalse(not_empty_collection.is_empty())
Ejemplo n.º 9
0
 def test_unique_one(self):
     flow1 = SequenceFlow('1', Obj(), Obj())
     flow2 = SequenceFlow('4', Obj(), Obj())
     flow3 = SequenceFlow('7', Obj(), Obj())
     flows = [flow1, flow2, flow3]
     not_unique_collection = SequenceFlowCollection(*flows)
     unique_collection = SequenceFlowCollection(flow1)
     self.assertEqual(flow1, unique_collection.unique_one())
     self.assertRaises(InvalidOperationException, not_unique_collection.unique_one)
Ejemplo n.º 10
0
 def test_next(self):
     cvg_gateway = ConvergeGateway('1')
     parallel_gateway = ParallelGateway('2', 'cvg')
     out_flow = SequenceFlow('flow', cvg_gateway, parallel_gateway)
     cvg_gateway.outgoing.add_flow(out_flow)
     parallel_gateway.incoming.add_flow(out_flow)
     self.assertEqual(parallel_gateway, cvg_gateway.next())
Ejemplo n.º 11
0
    def test_node(self):
        start_event = EmptyStartEvent(id='a')
        act = ServiceActivity(id='b', service=None)
        end_event = EmptyEndEvent(id='c')

        flow_ab = SequenceFlow('ab', start_event, act)
        flow_bc = SequenceFlow('bc', act, end_event)

        start_event.outgoing.add_flow(flow_ab)
        act.incoming.add_flow(flow_ab)
        act.outgoing.add_flow(flow_bc)
        end_event.incoming.add_flow(flow_bc)

        spec = PipelineSpec(start_event, end_event, [flow_ab, flow_bc], [act], [], None, None)
        pipeline = Pipeline('pipeline', spec)
        self.assertEqual(act, pipeline.node('b'))
Ejemplo n.º 12
0
 def test_add_flow(self):
     flow1 = SequenceFlow('1', Obj(), Obj())
     flow2 = SequenceFlow('4', Obj(), Obj())
     flow3 = SequenceFlow('7', Obj(), Obj())
     flow4 = SequenceFlow('10', Obj(), Obj())
     flows = [flow1, flow2, flow3]
     flows_after_added = [flow1, flow2, flow3, flow4]
     flow_dict_after_added = {
         flow1.id: flow1,
         flow2.id: flow2,
         flow3.id: flow3,
         flow4.id: flow4
     }
     collection = SequenceFlowCollection(*flows)
     collection.add_flow(flow4)
     self.assertEqual(flows_after_added, collection.flows)
     self.assertEqual(flow_dict_after_added, collection.flow_dict)
Ejemplo n.º 13
0
 def test_sequence_flow(self):
     flow_id = '1'
     source = ServiceActivity(id='1', service=None, data=DataObject({}))
     target = ServiceActivity(id='2', service=None, data=DataObject({}))
     flow = SequenceFlow(flow_id, source, target)
     self.assertTrue(isinstance(flow, FlowElement))
     self.assertEqual(flow_id, flow.id)
     self.assertEqual(source, flow.source)
     self.assertEqual(target, flow.target)
     self.assertEqual(False, flow.is_default)
Ejemplo n.º 14
0
def get_empty_parallel_gateway_test_pipeline():
    start_event_a_id = node_uniqid()
    gateway_b_id = node_uniqid()
    gateway_h_id = node_uniqid()
    end_event_i_id = node_uniqid()

    start_event_a = EmptyStartEvent(start_event_a_id)
    gateway_b = ParallelGateway(gateway_b_id, gateway_h_id)
    gateway_h = ConvergeGateway(gateway_h_id)
    end_event_i = EmptyEndEvent(end_event_i_id)

    flow_ab = SequenceFlow('ab', start_event_a, gateway_b)

    flow_bc = SequenceFlow('bc', gateway_b, gateway_h)
    flow_bd = SequenceFlow('bd', gateway_b, gateway_h)
    flow_be = SequenceFlow('be', gateway_b, gateway_h)

    flow_hi = SequenceFlow('hi', gateway_h, end_event_i)

    start_event_a.outgoing.add_flow(flow_ab)
    gateway_b.incoming.add_flow(flow_ab)

    gateway_b.outgoing.add_flow(flow_bc)
    gateway_b.outgoing.add_flow(flow_bd)
    gateway_b.outgoing.add_flow(flow_be)

    gateway_h.incoming.add_flow(flow_bc)
    gateway_h.incoming.add_flow(flow_bd)
    gateway_h.incoming.add_flow(flow_be)
    gateway_h.outgoing.add_flow(flow_hi)

    end_event_i.incoming.add_flow(flow_hi)

    spec = PipelineSpec(start_event_a,
                        end_event_i, [flow_ab, flow_bc, flow_bd, flow_be], [],
                        [gateway_b, gateway_h],
                        data=DataObject({}),
                        context=context.Context(act_outputs={}, output_key=[]))
    return Pipeline(node_uniqid(), spec)
    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'])
Ejemplo n.º 16
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
    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, {})
Ejemplo n.º 18
0
 def test_add_condition(self):
     ex_gateway = ExclusiveGateway(id='1')
     flow1 = SequenceFlow('flow1', ex_gateway, None)
     self.assertEqual([], ex_gateway.conditions)
     ex_gateway.add_condition(flow1)
     self.assertEqual([flow1], ex_gateway.conditions)
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
def get_parallel_gateway_test_pipeline():
    start_event_a_id = node_uniqid()
    gateway_b_id = node_uniqid()
    act_c_id = node_uniqid()
    act_d_id = node_uniqid()
    act_e_id = node_uniqid()
    act_f_id = node_uniqid()
    act_g_id = node_uniqid()
    gateway_h_id = node_uniqid()
    end_event_i_id = node_uniqid()

    start_event_a = EmptyStartEvent(start_event_a_id)
    gateway_b = ParallelGateway(gateway_b_id, gateway_h_id)
    act_c = ServiceActivity(act_c_id,
                            service=SleepService(),
                            data=DataObject({'data': '1'}))
    act_d = ServiceActivity(act_d_id,
                            service=SleepService(),
                            data=DataObject({'data': '1'}))
    act_e = ServiceActivity(act_e_id,
                            service=SleepService(),
                            data=DataObject({'data': '1'}))
    act_f = ServiceActivity(act_f_id,
                            service=SleepService(),
                            data=DataObject({'node_1': 'd'}))
    act_g = ServiceActivity(act_g_id,
                            service=SleepService(),
                            data=DataObject({'node_2': 'd'}))
    gateway_h = ConvergeGateway(gateway_h_id)
    end_event_i = EmptyEndEvent(end_event_i_id)

    flow_ab = SequenceFlow('ab', start_event_a, gateway_b)

    flow_bc = SequenceFlow('bc', gateway_b, act_c)
    flow_bd = SequenceFlow('bd', gateway_b, act_d)
    flow_be = SequenceFlow('be', gateway_b, act_e)

    flow_cf = SequenceFlow('cf', act_c, act_f)
    flow_dg = SequenceFlow('dg', act_d, act_g)

    flow_fh = SequenceFlow('fh', act_f, gateway_h)
    flow_gh = SequenceFlow('gh', act_g, gateway_h)
    flow_eh = SequenceFlow('eh', act_e, gateway_h)

    flow_hi = SequenceFlow('hi', gateway_h, end_event_i)

    start_event_a.outgoing.add_flow(flow_ab)
    gateway_b.incoming.add_flow(flow_ab)

    gateway_b.outgoing.add_flow(flow_bc)
    gateway_b.outgoing.add_flow(flow_bd)
    gateway_b.outgoing.add_flow(flow_be)
    act_c.incoming.add_flow(flow_bc)
    act_d.incoming.add_flow(flow_bd)
    act_e.incoming.add_flow(flow_be)

    act_c.outgoing.add_flow(flow_cf)
    act_d.outgoing.add_flow(flow_dg)
    act_e.outgoing.add_flow(flow_eh)

    act_f.incoming.add_flow(flow_cf)
    act_g.incoming.add_flow(flow_dg)
    act_f.outgoing.add_flow(flow_fh)
    act_g.outgoing.add_flow(flow_gh)

    gateway_h.incoming.add_flow(flow_fh)
    gateway_h.incoming.add_flow(flow_gh)
    gateway_h.incoming.add_flow(flow_eh)
    gateway_h.outgoing.add_flow(flow_hi)

    end_event_i.incoming.add_flow(flow_hi)

    spec = PipelineSpec(
        start_event_a,
        end_event_i, [
            flow_ab, flow_bc, flow_bd, flow_be, flow_cf, flow_dg, flow_fh,
            flow_gh, flow_eh
        ], [act_c, act_d, act_e, act_f, act_g], [gateway_b, gateway_h],
        data=DataObject({}),
        context=context.Context(act_outputs={
            act_f_id: {
                'node_1': 'node_1_heihei'
            },
            act_d_id: {
                'data': 'data_haha'
            }
        },
                                output_key=['node_1_heihei', 'data_haha']))
    return Pipeline(node_uniqid(), spec)