Exemplo n.º 1
0
    def test_activation_context_scope(self):
        with activation.Context(first_scope='first_scope'):
            with activation.Context(second_scope='second_scope'):
                self.assertEqual(activation.context.first_scope, 'first_scope')
                self.assertEqual(activation.context.second_scope, 'second_scope')

            self.assertEqual(activation.context.first_scope, 'first_scope')
            self.assertTrue(hasattr(activation.context, 'first_scope'))
            self.assertFalse(hasattr(activation.context, 'second_scope'))

        self.assertFalse(hasattr(activation.context, 'first_scope'))
        self.assertFalse(hasattr(activation.context, 'second_scope'))
Exemplo n.º 2
0
    def test_jobactivation_lifecycle(self):
        class JobActivation(activation.AbstractJobActivation):
            def __init__(self, *args, **kwargs):
                self.throw_on_schedule_error = kwargs.pop(
                    'throw_on_schedule_error', False)
                super(JobActivation, self).__init__(*args, **kwargs)

            def async (self):
                if self.throw_on_schedule_error:
                    raise ValueError('Job scheduler error')

            def activate_next(self):
                pass

        flow_task = self.init_node(flow.Node())

        # construct job that throws error on schedule
        act = JobActivation(throw_on_schedule_error=True)
        act.initialize(flow_task, Test.TaskStub())

        # by default job exceptions are propogated
        act.assign()
        self.assertEqual(act.task.status, STATUS.ASSIGNED)
        self.assertRaises(ValueError, act.schedule)

        # disable error propogation
        with activation.Context(propagate_exception=False):
            act.schedule()
            act.retry()
            self.assertEqual(act.task.status, STATUS.ERROR)

        act.throw_on_schedule_error = False
        act.retry()
        self.assertEqual(act.task.status, STATUS.SCHEDULED)

        # faild job execution
        act.start()
        self.assertEqual(act.task.status, STATUS.STARTED)
        act.error()
        self.assertEqual(act.task.status, STATUS.ERROR)

        # successful job execution
        act.retry()
        self.assertEqual(act.task.status, STATUS.SCHEDULED)
        act.start()
        self.assertEqual(act.task.status, STATUS.STARTED)
        act.done()
        self.assertEqual(act.task.status, STATUS.DONE)

        # undo
        act.undo()
        self.assertEqual(act.task.status, STATUS.ASSIGNED)
        act.cancel()
        self.assertEqual(act.task.status, STATUS.CANCELED)
Exemplo n.º 3
0
    def test_gateactivation_lifecycle(self):
        flow_task = self.init(flow.Node())

        act = TestGateAcitation(throw_error=True)
        act.initialize(flow_task, TaskStub())

        self.assertRaises(ValueError, act.perform)

        with activation.Context(propagate_exception=False):
            act.perform()
            act.retry()

            act.throw_error = False
            act.retry()
            act.undo()
            act.cancel()
Exemplo n.º 4
0
    def test_gateactivation_lifecycle(self):
        class GateActivation(activation.AbstractGateActivation):
            def __init__(self, *args, **kwargs):
                self.throw_error = kwargs.pop('throw_error', False)
                super(GateActivation, self).__init__(*args, **kwargs)

            def calculate_next(self):
                if self.throw_error:
                    raise ValueError('Gate Error')

            def activate_next(self):
                pass

        flow_task = self.init_node(flow.Node())

        # construct gate that throws error
        act = GateActivation(throw_error=True)
        act.initialize(flow_task, Test.TaskStub())

        # by default gate exceptions are propogated
        self.assertRaises(ValueError, act.perform)

        # disable gate error propogation
        with activation.Context(propagate_exception=False):
            act.perform()
            self.assertEqual(act.task.status, STATUS.ERROR)

            act.retry()
            self.assertEqual(act.task.status, STATUS.ERROR)

        # fix gate data and retry
        act.throw_error = False
        act.retry()
        self.assertEqual(act.task.status, STATUS.DONE)

        # undo
        act.undo()
        self.assertEqual(act.task.status, STATUS.NEW)
        act.cancel()
        self.assertEqual(act.task.status, STATUS.CANCELED)
Exemplo n.º 5
0
    def test_jobactivation_lifecycle(self):
        flow_task = self.init(flow.Node())

        act = TestJobAcitation(throw_on_schedule_error=True)
        act.initialize(flow_task, TaskStub())

        act.assign()
        self.assertRaises(ValueError, act.schedule)

        with activation.Context(propagate_exception=False):
            act.schedule()
            act.retry()
            act.throw_on_schedule_error = False
            act.retry()

            act.start()
            act.error()

            act.retry()
            act.start()
            act.done()
            act.undo()
            act.cancel()