def test_db_diff_inspection(series_of_diffs, expected_updates, expected_deletions): diffs = [] for changes in series_of_diffs: tracker = DBDiffTracker() for key, val in changes.items(): if val is None: del tracker[key] else: tracker[key] = val diffs.append(tracker.diff()) actual_diff = DBDiff.join(diffs) if expected_updates: expected_keys, _ = zip(*expected_updates.items()) else: expected_keys = tuple() assert actual_diff.pending_keys() == expected_keys assert actual_diff.pending_items() == tuple(expected_updates.items()) assert actual_diff.deleted_keys() == tuple(expected_deletions)
def diff(self) -> DBDiff: """ Generate a DBDiff of all pending changes. These are the changes that would occur if :meth:`persist()` were called. """ tracker = DBDiffTracker() visited_keys = set() # type: Set[bytes] # Iterate in reverse, so you can skip over any keys from old checkpoints. # This is purely for performance, not correctness. for changeset in reversed(self.journal.journal_data.values()): for key, value in changeset.items(): if key in visited_keys: # this old change has already been tracked continue elif value is DELETED_ENTRY: del tracker[key] else: tracker[ key] = value # type: ignore # This is always bytes, but mypy can't tell visited_keys.add(key) return tracker.diff()
def __init__(self, write_target_db: BaseDB) -> None: self._write_target_db = write_target_db self._track_diff = DBDiffTracker()
def __init__(self, db: DatabaseAPI) -> None: self._db = db self._track_diff = DBDiffTracker()
def __init__(self, original_read_db: BaseDB, write_batch: 'plyvel.WriteBatch') -> None: self._original_read_db = original_read_db self._write_batch = write_batch # keep track of the temporary changes made self._track_diff = DBDiffTracker()
def clear(self): self._track_diff = DBDiffTracker()
def __init__(self, wrapped_db: BaseDB) -> None: self.wrapped_db = wrapped_db self._track_diff = DBDiffTracker()
def clear(self) -> None: self._track_diff = DBDiffTracker()
def __init__(self, wrapped_db: BaseDB, read_through_deletes: bool = False) -> None: self.wrapped_db = wrapped_db self._track_diff = DBDiffTracker() self._read_through_deletes = read_through_deletes
def db(): return DBDiffTracker()
def __init__(self, write_target_db: DatabaseAPI) -> None: self._write_target_db = write_target_db self._track_diff = DBDiffTracker()