def test_status_and_delete_match(reads): """reader.status is consistent with writer.delete.""" from binlog.reader import TDSReader from binlog.writer import TDSWriter try: tmpdir = mktemp() writer = TDSWriter(tmpdir, max_log_events=MAX_LOG_EVENTS) reader = TDSReader(tmpdir, checkpoint='test') for x in range(25): writer.append(str(x).encode("ascii")) for x in range(reads): rec = reader.next_record() reader.ack(rec) reader.save() status = reader.status() for idx, can_delete in status.items(): if idx == max(status.keys()): # We cannot delete the last DB cause is current. assert not can_delete with pytest.raises(ValueError): writer.delete(idx) else: if can_delete: writer.delete(idx) except: raise finally: shutil.rmtree(tmpdir)
def test_status_and_delete_match(reads): """reader.status is consistent with writer.delete.""" from binlog.reader import TDSReader from binlog.writer import TDSWriter try: tmpdir = mktemp() writer = TDSWriter(tmpdir, max_log_events=MAX_LOG_EVENTS) reader = TDSReader(tmpdir, checkpoint='test') for x in range(25): writer.append(x) for x in range(reads): rec = reader.next_record() reader.ack(rec) reader.save() status = reader.status() for idx, can_delete in status.items(): if idx == max(status.keys()): # We cannot delete the last DB cause is current. assert not can_delete with pytest.raises(ValueError): writer.delete(idx) else: if can_delete: writer.delete(idx) except: raise finally: shutil.rmtree(tmpdir)
import signal import time from binlog.reader import TDSReader r = TDSReader('test', checkpoint='status') def save_status(): """ Save a checkpoint with the current status. Only the acknowledged entries will be included in the checkpoint. """ r.save() atexit.register(save_status) for i in cycle(range(1, 20001)): if i == 20000: # Make a checkpoint each 20k reads. save_status() n = r.next_record() # Read the next log entry. if n is None: time.sleep(1) else: print('.', end='', flush=True) r.ack(n) # Acknowledge the reception of the entry.