replayer_storage_and_client = (<swh.storage.in_memory.InMemoryStorage object at 0x7f50f7258b00>, <swh.journal.client.JournalClient object at 0x7f50f9359940>)
caplog = <_pytest.logging.LogCaptureFixture object at 0x7f50f93929e8>
def test_storage_replayer(replayer_storage_and_client, caplog):
"""Optimal replayer scenario.
This:
- writes objects to a source storage
- replayer consumes objects from the topic and replays them
- a destination storage is filled from this
In the end, both storages should have the same content.
"""
src, replayer = replayer_storage_and_client
# Fill Kafka using a source storage
nb_sent = 0
for object_type, objects in TEST_OBJECTS.items():
method = getattr(src, object_type + "_add")
method(objects)
if object_type == "origin_visit":
nb_sent += len(objects) # origin-visit-add adds origin-visit-status as well
nb_sent += len(objects)
caplog.set_level(logging.ERROR, "swh.journal.replay")
# Fill the destination storage from Kafka
dst = get_storage(cls="memory")
worker_fn = functools.partial(process_replay_objects, storage=dst)
nb_inserted = replayer.process(worker_fn)
assert nb_sent == nb_inserted
> _check_replayed(src, dst)
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_replay.py:87:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src = <swh.storage.in_memory.InMemoryStorage object at 0x7f50f7258b00>
dst = <swh.storage.in_memory.InMemoryStorage object at 0x7f50f1772710>
exclude = None
def _check_replayed(
src: InMemoryStorage, dst: InMemoryStorage, exclude: Optional[Container] = None
):
"""Simple utility function to compare the content of 2 in_memory storages
"""
expected_persons = set(src._persons.values())
got_persons = set(dst._persons.values())
assert got_persons == expected_persons
for attr in (
"contents",
"skipped_contents",
"directories",
"revisions",
"releases",
"snapshots",
"origins",
"origin_visits",
):
if exclude and attr in exclude:
continue
expected_objects = sorted(getattr(src, f"_{attr}").items())
got_objects = sorted(getattr(dst, f"_{attr}").items())
> assert got_objects == expected_objects, f"Mismatch object list for {attr}"
E AssertionError: Mismatch object list for origin_visits
E assert [('https://ov...}, visit=3)])] == [('https://ov...den/fox', [])]
E At index 0 diff: ('https://overtherainbow.org/fox/den', [OriginVisit(origin='https://overtherainbow.org/fox/den', date=datetime.datetime(2014, 11, 27, 17, 20, 39, tzinfo=tzlocal()), status='ongoing', type='hg', snapshot=None, metadata={'baz': 'qux'}, visit=1), OriginVisit(origin='https://overtherainbow.org/fox/den', date=datetime.datetime(2015, 11, 27, 17, 20, 39, tzinfo=tzlocal()), status='partial', type='hg', snapshot=b'\xec\xeeH9z\x92\xb0\xd04\xe9u*\x17E\x9f6\x91\xa7>\xf9', metadata={'something': 'wrong occurred'}, visit=2)]) != ('https://overtherainbow.org/fox/den',...
E
E ...Full output truncated (13 lines hidden), use '-vv' to show
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_replay.py:209: AssertionError
TEST RESULT
TEST RESULT
- Run At
- Jun 11 2020, 4:27 PM