示例#1
0
def test_parse_kafka_broker_address_is_mandatory():
    parser = viewlib.get_cli_parser()
    with pytest.raises(SystemExit) as excinfo:
        parser.parse_args(['--topic', 'test'])
示例#2
0
def test_parse_default_service_listening_port_is_localhost():
    parser = viewlib.get_cli_parser()
    args = parser.parse_args(['--broker', 'addr', '--topic', 'test'])
    assert args.port == 8080
示例#3
0
def test_parse_kafka_topic_is_mandatory():
    parser = viewlib.get_cli_parser()
    with pytest.raises(SystemExit) as excinfo:
        parser.parse_args(['--broker', 'addr'])
示例#4
0
def test_parse_default_service_listening_address_is_localhost():
    parser = viewlib.get_cli_parser()
    args = parser.parse_args(['--broker', 'addr', '--topic', 'test'])
    assert args.addr == '127.0.0.1'
示例#5
0
                        headers={"content-type": "application/json"})


async def event_handler(message):
    """
    Called whenever a new event was received from
    the event store.

    Simply store the event in a local state arena.
    """
    bookshelf.append(message.value.decode('utf-8'))

    
if __name__ == '__main__':
    import asyncio
    
    from viewlib import get_cli_parser, run_view

    loop = asyncio.get_event_loop()
    try:
        run_view(loop,
                 get_cli_parser().parse_args(),
                 view=bookshelf_view,
                 event_handler=event_handler
        )
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        loop.close()