Example #1
0
    def test_multi_processor(self):

        config = Config(processors_tag_regex=['.+\.event_a','.+\.event_b'])
        app = App(config)

        class EventA(Event):
            __tag__ = 'test.event_a'
            pass

        class EventB(Event):
            __tag__ = 'test.event_b'
            pass

        @app.handler(EventA)
        def fooA(context, event):
            pass

        @app.handler(EventB)
        def fooB(context, event):
            pass

        app.emit(EventA())
        app.emit(EventB())

        self.assertEqual(app.processors[0].tag_regex, '.+\.event_a')
        self.assertEqual(app.processors[1].tag_regex, '.+\.event_b')
        self.assertEqual(app.processors[2].tag_regex, '.*')

        processor_event_a = app.get_processor_by_tag_regex('.+\.event_a')
        processor_event_b = app.get_processor_by_tag_regex('.+\.event_b')
        processor_default = app.get_processor_by_tag_regex('.*')

        self.assertEqual(processor_event_a.process_count, 1)
        self.assertEqual(processor_event_b.process_count, 1)
        self.assertEqual(processor_default.process_count, 0)
Example #2
0
@app.handler(MyEventA, derivative_events=[MyEventB])
def my_event_a_handler(context, event):

    time.sleep(random.random())

    print event. my_field_one
    print event. my_field_two

    choice = random.choice([0, 1])
    if choice == 0:
        return Emittion(MyEventB())
    else:
        return NoEmittion(MyEventB , 'choice == 1')

@app.handler(MyEventB)
def my_event_b_handler(context, event):

    time.sleep(random.random())

    choice = random.choice([0, 1])
    if choice == 0:
        return
    else:
        1 / 0

app.run_dashboard(True)

while True:
    time.sleep(10)
    app.emit(MyEventA())
Example #3
0
class TestDashboard(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super(TestDashboard, self).__init__(*args, **kwargs)
        self.config = Config(
            source_event_cls=(AEvent,),
            processors_tag_regex=['a\..+',]
        )
        self.app = App(self.config)

        @self.app.handler(AEvent)
        def foo(context, event):
            pass

        self.dashboard = Dashboard(self.app)
        self.client = self.dashboard.flask_app.test_client()
        self.dashboard.flask_app.debug = True
        # self.dashboard.run(daemon=False)

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_index(self):
        rv = self.client.get('/')
        self.assertTrue('Earo Dashboard' in rv.data)

    def test_configuration(self):
        rv = self.client.get('/configuration')
        result = json.loads(rv.data)
        self.assertEqual(result['c'], 0)
        self.assertTrue('app_name' in result['d'])

    def test_source_event_cls_list(self):
        rv = self.client.get('/source_event_cls_list')
        result = json.loads(rv.data)
        self.assertEqual(result['c'], 0)
        self.assertDictEqual(
            result['d'][0],
            {'source_event_cls': 'test_dashboard.AEvent',
             'source_event_tag': 'a.event',
             'source_event_description': 'This is AEvent\'s description.'})

    def test_processor_list(self):
        self.app.emit(AEvent())
        rv = self.client.get('/processor_list')
        result = json.loads(rv.data)
        self.assertEqual(result['c'], 0)
        self.assertSequenceEqual(result['d'][0]['tag_regex'], 'a\..+')
        self.assertSequenceEqual(result['d'][1]['tag_regex'], '.*')
        self.assertTrue('process_count' in result['d'][0])
        self.assertTrue('exception_count' in result['d'][0])
        self.assertTrue('event_statistics' in result['d'][0])
        self.assertTrue('test_dashboard.AEvent' in result[
                        'd'][0]['event_statistics'])
        self.assertTrue(
                        'process_count'
                        in
                        result['d'][0]['event_statistics']
                        ['test_dashboard.AEvent'])
        self.assertTrue('exception_count' in result['d'][0][
                        'event_statistics']['test_dashboard.AEvent'])
        self.assertTrue(
                        'min_time_cost'
                        in
                        result['d'][0]['event_statistics']
                        ['test_dashboard.AEvent'])
        self.assertTrue(
                        'max_time_cost'
                        in
                        result['d'][0]['event_statistics']
                        ['test_dashboard.AEvent'])

    def test_preview_process_flow(self):
        rv = self.client.get('/preview_process_flow/test_dashboard.AEvent')
        self.assertTrue('Preview Process Flow' in rv.data)

    def test_latest_process_flow(self):
        self.app._source_event_cls_to_latest_active_process_flow.clear()
        rv = self.client.get('/latest_process_flow/test_dashboard.AEvent')
        result = json.loads(rv.data)
        self.assertEqual(result['c'], -1)

        self.app.emit(AEvent())

        rv = self.client.get('/latest_process_flow/test_dashboard.AEvent')
        self.assertTrue('Latest Process Flow' in rv.data)