def test_memory_records_v0(): data_bytes = b"".join(record_batch_data_v0) records = MemoryRecords(data_bytes + b"\x00" * 4) assert records.size_in_bytes() == 114 records = MemoryRecords(data_bytes) assert records.has_next() is True batch = records.next_batch() recs = list(batch) assert len(recs) == 1 assert recs[0].value == b"123" assert recs[0].key is None assert recs[0].timestamp is None assert recs[0].timestamp_type is None assert recs[0].checksum == -22012481 & 0xffffffff assert records.next_batch() is not None assert records.next_batch() is not None assert records.next_batch() is not None assert records.has_next() is False assert records.next_batch() is None assert records.next_batch() is None
def test_memory_records_corrupt(): records = MemoryRecords(b"") assert records.size_in_bytes() == 0 assert records.has_next() is False records = MemoryRecords(b"\x00\x00\x00") assert records.size_in_bytes() == 3 assert records.has_next() is False with pytest.raises(CorruptRecordException): records = MemoryRecords( b"\x00\x00\x00\x00\x00\x00\x00\x03" # Offset=3 b"\x00\x00\x00\x03" # Length=3 b"\xfe\xb0\x1d", # Some random bytes ) records.next_batch()
def test_memory_records_v1(): data_bytes = b"".join(record_batch_data_v1) + b"\x00" * 4 records = MemoryRecords(data_bytes) assert records.size_in_bytes() == 146 assert records.has_next() is True batch = records.next_batch() recs = list(batch) assert len(recs) == 1 assert recs[0].value == b"123" assert recs[0].key is None assert recs[0].timestamp == 1503648000942 assert recs[0].timestamp_type == 0 assert recs[0].checksum == 1199974594 & 0xffffffff assert records.next_batch() is not None assert records.next_batch() is not None assert records.next_batch() is not None assert records.has_next() is False assert records.next_batch() is None assert records.next_batch() is None
def test_memory_records_v2(): data_bytes = b"".join(record_batch_data_v2) + b"\x00" * 4 records = MemoryRecords(data_bytes) assert records.size_in_bytes() == 222 assert records.has_next() is True batch = records.next_batch() recs = list(batch) assert len(recs) == 1 assert recs[0].value == b"123" assert recs[0].key is None assert recs[0].timestamp == 1503229838908 assert recs[0].timestamp_type == 0 assert recs[0].checksum is None assert recs[0].headers == [] assert records.next_batch() is not None assert records.next_batch() is not None assert records.has_next() is False assert records.next_batch() is None assert records.next_batch() is None