예제 #1
0
def test_event(events):
    mock_producer = producer.EventProducer(
        max_wait=10,
        min_wait=2,
        events=events,
    )
    event = mock_producer.event

    assert event == {'id': 1, 'timestamp': '2019-12-21 09:51:10 -0300'}
예제 #2
0
파일: cli.py 프로젝트: tomasfarias/pipeline
def run_producer(args: argparse.Namespace):
    with open(args.input, 'r') as json_file:
        events = json.load(json_file)

    event_producer = producer.EventProducer(
        max_wait=args.max_wait,
        min_wait=args.min_wait,
        events=events,
        bootstrap_servers=[args.bootstrap_server],
        value_serializer=lambda m: json.dumps(m).encode('utf8'))

    event_producer.run(topic=args.topic)
예제 #3
0
def test_run(mock_flush, mock_send, events):
    mock_producer = producer.EventProducer(
        max_wait=0,
        min_wait=0,
        events=[events[0]],
    )

    mock_producer.run('test-topic')

    mock_send.assert_called_once_with('test-topic', {
        'id': 1,
        'timestamp': '2019-12-21 09:51:10 -0300'
    })
    mock_flush.assert_called_once()
예제 #4
0
def test_uncapped_get_wait_time(events):
    mock_producer = producer.EventProducer(
        max_wait=99999,
        min_wait=-1,
        events=events,
    )
    wait = mock_producer.get_wait_time()

    assert wait == 60

    mock_producer.events.pop(0)
    mock_producer.events.pop(0)

    wait = mock_producer.get_wait_time()

    assert wait == 0
예제 #5
0
def test_capped_get_wait_time(events):
    mock_producer = producer.EventProducer(
        max_wait=10,
        min_wait=2,
        events=events,
    )
    wait = mock_producer.get_wait_time()

    assert wait == 10

    mock_producer.events.pop(0)
    mock_producer.events.pop(0)

    wait = mock_producer.get_wait_time()

    assert wait == 2
예제 #6
0
def test_get_next_timestamp(events):
    mock_producer = producer.EventProducer(
        max_wait=10,
        min_wait=2,
        events=events,
    )
    ts = mock_producer.get_next_timestamp()
    expected = parser.parse('2019-12-21 09:52:10 -0300')

    assert ts == expected

    mock_producer.events.pop(0)
    mock_producer.events.pop(0)

    ts = mock_producer.get_next_timestamp()

    assert ts is None