Beispiel #1
0
def test_queues_registry_load():
    ''' load queues to registry
    '''
    registry = QueuesRegistry()
    registry.load([
        {
            'name': 'TestQueue#1',
            'type': 'eventsflow.queues.local.EventsQueue',
        },
    ])
    assert registry is not None
    assert registry.get('TestQueue#1') is not None
    assert isinstance(registry.get('TestQueue#1'), EventsQueue)

    assert list(registry.queues) == [
        'TestQueue#1',
    ]
def test_process_worker_stop_processing_by_event():
    ''' test for Processing Worker, stop processing bt StopProcessing event
    '''
    queues = QueuesRegistry()
    queues.load([
        {'name': 'SourceQueue', 'type': 'eventsflow.queues.local.EventsQueue', },
    ])

    workers = WorkersRegistry(queues=queues)
    workers.load([
        {   'name': 'TestWorker',
            'type': 'common_libs.SampleProcessingWorker',
            'parameters': { 'timeout': 1, },
            'inputs': 'SourceQueue',
        },
    ])

    queues.get('SourceQueue').publish(EventStopProcessing())

    for worker in workers.workers():
        assert worker.consume() is None
Beispiel #3
0
def test_workers_registry_flow_start_workers_and_check_status():
    ''' run workers and check workers status
    '''
    queues_registry = QueuesRegistry()
    queues_registry.load([
        {
            'name': 'records',
            'type': 'eventsflow.queues.local.EventsQueue',
        }
    ])

    workers_registry = WorkersRegistry(queues=queues_registry)
    workers_registry.load([
        {
            'name': 'TestWorker',
            'type': 'tests.common_libs.SampleProcessingWorker',
            'inputs': 'records'
        },
    ])

    assert [ type(w) for w in workers_registry.workers(status='active')] == [ ]

    workers_registry.start()
    assert [
        type(w) for w in workers_registry.workers(status='active')
    ] == [ SampleProcessingWorker, ]

    queues_registry.get('records').publish(EventStopProcessing())
    time.sleep(1)

    assert [
        type(w) for w in workers_registry.workers(status='active')
    ] == []

    assert [
        type(w) for w in workers_registry.workers(status='inactive')
    ] == [ SampleProcessingWorker, ]
Beispiel #4
0
def test_workers_registry_load_workers_queues_with_events():
    ''' load workers to registry with queues and events
    '''

    queues_config = [
        {
            'name': 'SourceQueue',
            'type': 'eventsflow.queues.local.EventsQueue',
        },
        {
            'name': 'TargetQueue',
            'type': 'eventsflow.queues.local.EventsQueue',
        },
    ]
    queues = QueuesRegistry()
    queues.load(queues_config)

    test_events = [
        {
            'name': 'EventTest#1',
            'metadata': {},
            'payload': []
        },
        {
            'name': 'EventTest#1',
            'metadata': {},
            'payload': []
        },
        {
            'name': 'EventTest#1',
            'metadata': {},
            'payload': []
        },
    ]

    workers_config = [
        {
            'name':
            'TestWorker',
            'type':
            'eventsflow.workers.process.ProcessingWorker',
            'inputs': [{
                'name': 'default',
                'refs': 'SourceQueue',
                'events': test_events
            }],
            'outputs': [{
                'name': 'default',
                'refs': 'TargetQueue',
                'events': test_events
            }],
        },
    ]
    registry = WorkersRegistry(queues=queues)
    registry.load(workers_config)

    assert [type(w) for w in registry.workers()] == [
        ProcessingWorker,
    ]
    assert queues.get('SourceQueue')
    assert queues.get('TargetQueue')

    # Source Queue
    events = []
    for _ in test_events:
        event = queues.get('SourceQueue').consume()
        events.append(event.to_dict())

    assert events == test_events

    # Target Queue
    events = []
    for _ in test_events:
        event = queues.get('TargetQueue').consume()
        events.append(event.to_dict())

    assert events == test_events