kafka_prefix = 'wygpkodyyu', kafka_consumer_group = 'test-consumer-wygpkodyyu'
kafka_server = '127.0.0.1:48357'
def test_storage_play_anonymized(
kafka_prefix: str, kafka_consumer_group: str, kafka_server: str
):
"""Optimal replayer scenario.
This:
- writes objects to the topic
- replayer consumes objects from the topic and replay them
"""
writer_config = {
"cls": "kafka",
"brokers": [kafka_server],
"client_id": "kafka_writer",
"prefix": kafka_prefix,
"anonymize": True,
}
src_config: Dict[str, Any] = {"cls": "memory", "journal_writer": writer_config}
storage = get_storage(**src_config)
# Fill the src storage
nb_sent = 0
for obj_type, objs in TEST_OBJECTS.items():
if obj_type in ("origin_visit", "origin_visit_status"):
# these are unrelated with what we want to test here
continue
method = getattr(storage, obj_type + "_add")
method(objs)
nb_sent += len(objs)
# Fill a destination storage from Kafka **using anonymized topics**
dst_storage = get_storage(cls="memory")
replayer = JournalClient(
brokers=kafka_server,
group_id=kafka_consumer_group,
prefix=kafka_prefix,
stop_after_objects=nb_sent,
privileged=False,
)
worker_fn = functools.partial(process_replay_objects, storage=dst_storage)
nb_inserted = replayer.process(worker_fn)
assert nb_sent == nb_inserted
> check_replayed(storage, dst_storage, expected_anonymized=True)
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_replay.py:323:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src = <swh.storage.in_memory.InMemoryStorage object at 0x7fece9ed96a0>
dst = <swh.storage.in_memory.InMemoryStorage object at 0x7fece8d8de80>
expected_anonymized = True
def check_replayed(src, dst, expected_anonymized=False):
"""Simple utility function to compare the content of 2 in_memory storages
If expected_anonymized is True, objects from the source storage are anonymized
before comparing with the destination storage.
"""
def maybe_anonymize(attr_, row):
if expected_anonymized:
if attr_ == "releases":
row = dataclasses.replace(row, author=row.author.anonymize())
elif attr_ == "revisions":
row = dataclasses.replace(
row,
author=row.author.anonymize(),
committer=row.committer.anonymize(),
)
return row
expected_persons = {
> maybe_anonymize("persons", person) for person in src._persons.values()
}
E AttributeError: 'InMemoryStorage' object has no attribute '_persons'
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_replay.py:362: AttributeError
TEST RESULT
TEST RESULT
- Run At
- Aug 13 2020, 11:11 AM