Exemplo n.º 1
0
    def test_skipping_steps_prototype(self):
        class SkipLogAdvice(object):
            def should_skip(self, attr):
                '''
                Skip all scheduling actions.
                :return:  Bool indicating whether to activate.
                '''
                return 'schedule' in attr.func_name

            def prelude(self, attr, _):
                if self.should_skip(attr):
                    set_skip_log(True)

        advice_to_apply = SkipLogAdvice()
        advice_dict = {}
        for target in dir(CustomerServiceWorkflow):
            if target[:2] != "__":
                advice_dict[eval('CustomerServiceWorkflow.' +
                                 target)] = advice_to_apply
                advice_dict[eval('SpecialistWorkflow.' +
                                 target)] = advice_to_apply

        weave_clazz(CustomerServiceWorkflow, advice_dict)
        weave_clazz(SpecialistWorkflow, advice_dict)

        self.company.recieve_message('start')
        self.clock.tick(100)

        for logged_item in map(lambda event: event[1], action_log[0]):
            self.assertTrue('schedule' not in logged_item)

        generate_XES(log_path='skipped_scheduling.xes')
Exemplo n.º 2
0
def run_model(FuzzerClass,
              num_ticks=100000,
              num_start_messages=1000,
              fuzzer_args=list(),
              fuzzer_kwargs=dict()):

    advice_to_apply = FuzzerClass(*fuzzer_args, **fuzzer_kwargs)
    advice_dict = {}
    for target in dir(CustomerServiceWorkflow):
        if target[:2] != "__":
            advice_dict[eval('CustomerServiceWorkflow.' +
                             target)] = advice_to_apply
            advice_dict[eval('SpecialistWorkflow.' + target)] = advice_to_apply

    weave_clazz(CustomerServiceWorkflow, advice_dict)
    weave_clazz(SpecialistWorkflow, advice_dict)
    '''
    @issue: correct-message-pickup
    @description
    I'd bet that, because work gets put to the back of a queue, these start messages all get processed
    before any of the work they produce --- not ideal. Should change to either pick up work from the queue randomly,
    or space them after random (but sensible) number of ticks.

    (This might be a change to the Troupe, if they pick up work randomly, or a change to
    how I deploy the messages otherwise.)
    '''

    [company.recieve_message('start') for _ in range(num_start_messages)]
    clock.tick(num_ticks)
Exemplo n.º 3
0
 def apply_to_specialist_workers():
     advice_dict = dict()
     forbidden = ['START', 'END']
     for target in dir(SpecialistWorkflow):
         if target[:2] != "__" and target not in forbidden:
             advice_dict[eval('SpecialistActor.' +
                              target)] = advice_to_apply
     weave_clazz(SpecialistActor, advice_dict)
Exemplo n.º 4
0
 def apply_to_customer_service_workers():
     advice_dict = dict()
     forbidden = ['START', 'END']
     for target in dir(CustomerServiceWorkflow):
         if target[:2] != "__" and target not in forbidden:
             advice_dict[eval('CustomerServiceActor.' +
                              target)] = advice_to_apply
     weave_clazz(CustomerServiceActor, advice_dict)
Exemplo n.º 5
0
    def test_before_and_after(self):

        counting_aspect = CountingAspect()
        advice = {Target.foo: counting_aspect}
        weave_clazz(Target, advice)

        Target().foo().foo().foo()

        self.assertEqual(3, counting_aspect.invocations)
Exemplo n.º 6
0
    def test_encore_decorator(self):

        @encore
        def set_count_to_5_after_running(attr, context, *args, **kwargs):
            context.count = 5

        advice = {Target.increment_count: set_count_to_5_after_running}
        weave_clazz(Target, advice)

        target = Target()
        target.increment_count()

        self.assertEqual(target.count, 5)
Exemplo n.º 7
0
    def test_error_handling_decorator(self):
        @error_handler
        def handle_exception(attribute, context, exception):
            self.assertTrue(True)  # We caught the exception successfully! Pass!

        advice = {Target.raise_exception: handle_exception}
        weave_clazz(Target, advice)

        target = Target()

        try:
            target.raise_exception()
        except:
            self.assertTrue(False)  # We should have caught this; fail the test.
Exemplo n.º 8
0
    def test_error_raising(self):
        class ExceptionHandlingCounter(CountingAspect):
            def error_handling(aspect_self, attribute, context, exception):
                self.assertTrue(True)  # We handled! Pass the test!

        ehc = ExceptionHandlingCounter()
        advice = {Target.raise_exception: ehc}
        weave_clazz(Target, advice)

        target = Target()

        try:
            target.raise_exception()
        except:
            self.assertTrue(False)  # We should have caught this; fail the test.
Exemplo n.º 9
0
    def test_around_decorator(self):

        def set_count_to_5_before_running(attr, context, *args, **kwargs):
            context.count = 5

        def increment_counter_after_running(attr, context, *args, **kwargs):
            context.count += 1

        around_advice = generate_around_advice(set_count_to_5_before_running, increment_counter_after_running)
        advice = {Target.increment_count: around_advice}
        weave_clazz(Target, advice)

        target = Target()
        target.increment_count()

        self.assertEqual(target.count, 5+1+1)
Exemplo n.º 10
0
    def test_confidence_interval(self):
        advice_to_apply = TestConfidenceIntervals.SkipWhenOverconfident()
        advice_dict = {}
        for target in dir(CustomerServiceWorkflow):
            if target[:2] != "__":
                advice_dict[eval('CustomerServiceWorkflow.' +
                                 target)] = advice_to_apply
                advice_dict[eval('SpecialistWorkflow.' +
                                 target)] = advice_to_apply

        weave_clazz(CustomerServiceWorkflow, advice_dict)
        weave_clazz(SpecialistWorkflow, advice_dict)

        [self.company.recieve_message('start') for _ in range(1000)]
        self.clock.tick(100000)

        generate_XES(log_path='confident_actor_trace.xes')
Exemplo n.º 11
0
    def test_around(self):

        class AroundTestingAspect(object):
            def around(self, attribute, context, *args, **kwargs):
                context.count = context.count ** 3
                result = attribute(*args, **kwargs)
                context.count *= 2
                return result

            def prelude(self, attribute, context, *args, **kwargs):
                context.count += 2

        test_around = AroundTestingAspect()
        advice = {Target.increment_count: test_around}
        weave_clazz(Target, advice)

        target = Target()
        target.increment_count()

        # We add two in the prelude, then ^3, then add one, then multiply by two.
        # This tests that the prelude is being executed before the around, but also that both are being executed.
        self.assertEqual(target.count, ((2**3)+1)*2)
Exemplo n.º 12
0
def run_model_advanced_aspect_application(
        class_identifier_tuple,  # Format (FuzzerClass, target_identifying_string, args, kwargs)
        num_ticks=10000,
        num_start_messages=100):
    '''

    :param class_identifier_tuple: Format (FuzzerClass, target_identifying_string, args, kwargs)
    :param num_ticks:
    :param num_start_messages:
    :param fuzzer_args:
    :param fuzzer_kwargs:
    :return:
    '''

    for FuzzerClass, fuzzer_target_identifier, args, kwargs in class_identifier_tuple:

        advice_to_apply = FuzzerClass(*args, **kwargs)

        def apply_to_customer_service_workers():
            advice_dict = dict()
            forbidden = ['START', 'END']
            for target in dir(CustomerServiceWorkflow):
                if target[:2] != "__" and target not in forbidden:
                    advice_dict[eval('CustomerServiceActor.' +
                                     target)] = advice_to_apply
            weave_clazz(CustomerServiceActor, advice_dict)

        def apply_to_specialist_workers():
            advice_dict = dict()
            forbidden = ['START', 'END']
            for target in dir(SpecialistWorkflow):
                if target[:2] != "__" and target not in forbidden:
                    advice_dict[eval('SpecialistActor.' +
                                     target)] = advice_to_apply
            weave_clazz(SpecialistActor, advice_dict)

        if fuzzer_target_identifier == 'get_next_task':
            advice_dict = dict()
            advice_dict[CustomerServiceActor.get_next_task] = advice_to_apply
            weave_clazz(CustomerServiceActor, advice_dict)
            advice_dict = dict()
            advice_dict[SpecialistActor.get_next_task] = advice_to_apply
            weave_clazz(SpecialistActor, advice_dict)
        elif fuzzer_target_identifier == 'customer service actors':
            apply_to_customer_service_workers()
        elif fuzzer_target_identifier == 'specialist actors':
            apply_to_specialist_workers()
        elif fuzzer_target_identifier == 'all workflows':
            apply_to_specialist_workers()
            apply_to_customer_service_workers()
        elif fuzzer_target_identifier == 'end':

            advice_dict = dict()
            advice_dict[SpecialistActor.END] = advice_to_apply
            weave_clazz(SpecialistActor, advice_dict)

            advice_dict = dict()
            advice_dict[CustomerServiceActor.END] = advice_to_apply
            weave_clazz(CustomerServiceActor, advice_dict)

        elif fuzzer_target_identifier == 'start':

            advice_dict = dict()
            advice_dict[SpecialistActor.START] = advice_to_apply
            weave_clazz(SpecialistActor, advice_dict)

            advice_dict = dict()
            advice_dict[CustomerServiceActor.START] = advice_to_apply
            weave_clazz(CustomerServiceActor, advice_dict)

    [company.recieve_message('start') for _ in range(num_start_messages)]
    old_man_time.tick(num_ticks)