Example #1
0
class PipelineExecutor:
    """
    pipeline - dictionary with main key `pipeline`, parsed yaml or any other
    """
    def __init__(self, pipeline_wrapper):
        self.pipeline_raw = pipeline_wrapper.pipeline
        self.log_manager = pipeline_wrapper.log_manager
        self.output_method = pipeline_wrapper.output_method
        self.prepare_output()
        if pipeline_valid(self.pipeline_raw)['hasError'] is True:
            pass

    def prepare_output(self):
        self.output_publisher = OutputPublisher()
        self.output_consumer = OutputMethod[self.output_method].value
        self.output_publisher.add_consumer(self.output_consumer)

    def start(self):
        self.parse_pipeline()

    def parse_pipeline(self):
        event = OutputEvent(
            Signal.a, 'Pipeline parsing started',
            'Executor initialized correctly, and Pipeline parsing started at '
            + str(datetime.datetime.today()))
        self.output_publisher.collect(event)
Example #2
0
    def test_should_put_correctly_OutputEvent_to_queue(self):
        out = OutputPublisher()
        event = prepare_event()
        out.collect(event)

        self.assertIsNotNone(out.event_queue)
        self.assertEqual(1, out.event_queue.qsize())
Example #3
0
    def test_should_cannot_put_to_queue_other_object_than_OutputEvent(self):
        out = OutputPublisher()
        ob = 'wrong object'

        with self.assertRaises(OutputEvent.EventException):
            out.collect(ob)
        self.assertEqual(0, out.event_queue.qsize())
Example #4
0
    def test_should_consume_one_event_successfully(self):
        out = OutputPublisher()
        out.collect(prepare_event())

        consumed = out.publish()
        self.assertIsNotNone(consumed)
        self.assertIsNotNone(consumed.timestamp)
        self.assertEqual(0, out.event_queue.qsize())
Example #5
0
    def test_should_put_correctly_many_OutputEvent_objects_to_queue(self):
        out = OutputPublisher()
        event_list = prepare_event_sequence()
        for event in event_list:
            out.collect(event)

        self.assertIsNotNone(out.event_queue)
        self.assertEqual(len(event_list), out.event_queue.qsize())
Example #6
0
    def test_should_collect_event_and_publish_it_to_each_consumer(self):
        publisher = OutputPublisher()
        consumer = TerminalOutputConsumer()
        publisher.add_consumer(consumer)

        event = prepare_event()
        publisher.collect(event)
        publisher.publish()

        self.assertTrue(consumer._received)
        self.assertEqual(0, publisher.event_queue.qsize())
        self.assertEqual(1, len(publisher.consumers))
Example #7
0
    def test_should_first_event_put_on_queue_should_first_out(self):
        out = OutputPublisher()
        event_list = prepare_event_sequence()
        first_event = event_list[0]
        for event in event_list:
            out.collect(event)

        first_on_queue = out.event_queue.get()
        self.assertEqual(len(event_list) - 1, out.event_queue.qsize())
        self.assertEqual(first_event.signal, first_on_queue.signal)
        self.assertEqual(first_event.title, first_on_queue.title)
        self.assertEqual(first_event.content, first_on_queue.content)
        self.assertEqual(first_event.error, first_on_queue.error)
        self.assertIsNotNone(first_on_queue.timestamp)
Example #8
0
    def test_should_queue_be_overloaded_and_raise_exception(self):
        out = OutputPublisher()

        with self.assertRaises(OutputPublisher.QueueOverloadedException):
            [
                out.collect(prepare_event())
                for _ in range(out._max_queue_size + 1)
            ]