def test_buffer_count(self, inlet, outlet): buffer = Buffer(count_threshold=3) payload = [1, 2, 3, 4] records = [Record(payload=p) for p in payload] link = Link(inlet, outlet, interval=1, processors=buffer, copy_records=False) inlet._pull = pull_mock(records[:2]) link.transfer() outlet._push.assert_called_with( [], mock.ANY) # after first call we shouldn't have any records inlet._pull = pull_mock(records[2:]) link.transfer() outlet._push.assert_called_with( records, mock.ANY) # all records should be returned here
def test_flush(self, inlet, outlet): buffer = Buffer(count_threshold=100, time_threshold=10) payload = [1, 2, 3, 4] records = [Record(payload=p) for p in payload] link = Link(inlet, outlet, interval=1, processors=buffer, copy_records=False) inlet._pull = pull_mock(records[:2]) link.transfer() outlet._push.assert_called_with([], mock.ANY) # no records yet inlet._pull = pull_mock(records[2:]) link.transfer() outlet._push.assert_called_with([], mock.ANY) # no records yet buffer.flush = True inlet._pull = pull_mock([]) link.transfer() outlet._push.assert_called_with( records, mock.ANY) # all records should be flushed
def test_buffer_time(self, inlet, outlet): buffer = Buffer(time_threshold=0.02) payload = [1, 2, 3, 4] records = [Record(payload=p) for p in payload] link = Link(inlet, outlet, interval=1, processors=buffer, copy_records=False) inlet._pull = pull_mock(records[:2]) link.transfer() outlet._push.assert_called_with( [], mock.ANY) # not enough time have passed inlet._pull = pull_mock(records[2:]) link.transfer() outlet._push.assert_called_with( [], mock.ANY) # not enough time have passed time.sleep(0.02) inlet._pull = pull_mock([]) link.transfer() outlet._push.assert_called_with( records, mock.ANY) # all records should be returned here