Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_replay.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2020 The Software Heritage developers | |||||||||||||||||||||||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | |||||||||||||||||||||||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | |||||||||||||||||||||||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | |||||||||||||||||||||||||
import dataclasses | import dataclasses | |||||||||||||||||||||||||
import datetime | import datetime | |||||||||||||||||||||||||
import functools | import functools | |||||||||||||||||||||||||
import logging | import logging | |||||||||||||||||||||||||
from typing import Any, Container, Dict, Optional | from typing import Any, Container, Dict, Optional | |||||||||||||||||||||||||
import attr | import attr | |||||||||||||||||||||||||
import pytest | import pytest | |||||||||||||||||||||||||
from swh.journal.client import JournalClient | from swh.journal.client import JournalClient | |||||||||||||||||||||||||
from swh.journal.serializers import key_to_kafka, value_to_kafka | from swh.journal.serializers import key_to_kafka, value_to_kafka | |||||||||||||||||||||||||
from swh.model.hashutil import DEFAULT_ALGORITHMS, MultiHash, hash_to_hex | from swh.model.hashutil import DEFAULT_ALGORITHMS, MultiHash, hash_to_bytes, hash_to_hex | |||||||||||||||||||||||||
from swh.model.tests.swh_model_data import DUPLICATE_CONTENTS, TEST_OBJECTS | from swh.model.model import Revision, RevisionType | |||||||||||||||||||||||||
from swh.model.tests.swh_model_data import ( | ||||||||||||||||||||||||||
COMMITTERS, | ||||||||||||||||||||||||||
DATES, | ||||||||||||||||||||||||||
DUPLICATE_CONTENTS, | ||||||||||||||||||||||||||
REVISIONS, | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
from swh.model.tests.swh_model_data import TEST_OBJECTS as _TEST_OBJECTS | ||||||||||||||||||||||||||
from swh.storage import get_storage | from swh.storage import get_storage | |||||||||||||||||||||||||
from swh.storage.cassandra.model import ContentRow, SkippedContentRow | from swh.storage.cassandra.model import ContentRow, SkippedContentRow | |||||||||||||||||||||||||
from swh.storage.in_memory import InMemoryStorage | from swh.storage.in_memory import InMemoryStorage | |||||||||||||||||||||||||
from swh.storage.replay import process_replay_objects | from swh.storage.replay import process_replay_objects | |||||||||||||||||||||||||
UTC = datetime.timezone.utc | UTC = datetime.timezone.utc | |||||||||||||||||||||||||
vlorentz: why the copy? | ||||||||||||||||||||||||||
Done Inline Actionsbecause I don't want to modify the original TEST_OBJECT dict douardda: because I don't want to modify the original TEST_OBJECT dict | ||||||||||||||||||||||||||
TEST_OBJECTS = _TEST_OBJECTS.copy() | ||||||||||||||||||||||||||
TEST_OBJECTS["revision"] = list(_TEST_OBJECTS["revision"]) + [ | ||||||||||||||||||||||||||
Revision( | ||||||||||||||||||||||||||
id=hash_to_bytes("a569b03ebe6e5f9f2f6077355c40d89bd6986d0c"), | ||||||||||||||||||||||||||
message=b"hello again", | ||||||||||||||||||||||||||
date=DATES[1], | ||||||||||||||||||||||||||
committer=COMMITTERS[1], | ||||||||||||||||||||||||||
author=COMMITTERS[0], | ||||||||||||||||||||||||||
committer_date=DATES[0], | ||||||||||||||||||||||||||
type=RevisionType.GIT, | ||||||||||||||||||||||||||
directory=b"\x03" * 20, | ||||||||||||||||||||||||||
synthetic=False, | ||||||||||||||||||||||||||
metadata={"something": "interesting"}, | ||||||||||||||||||||||||||
parents=(REVISIONS[0].id,), | ||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||
Not Done Inline Actions
more readable IMO vlorentz: more readable IMO | ||||||||||||||||||||||||||
Done Inline ActionsI find it more cryptic, but meh douardda: I find it more cryptic, but meh | ||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||
def nullify_ctime(obj): | def nullify_ctime(obj): | |||||||||||||||||||||||||
if isinstance(obj, (ContentRow, SkippedContentRow)): | if isinstance(obj, (ContentRow, SkippedContentRow)): | |||||||||||||||||||||||||
return dataclasses.replace(obj, ctime=None) | return dataclasses.replace(obj, ctime=None) | |||||||||||||||||||||||||
else: | else: | |||||||||||||||||||||||||
return obj | return obj | |||||||||||||||||||||||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | def fix_expected(attr, row): | |||||||||||||||||||||||||
row, author=row.author and row.author.anonymize() | row, author=row.author and row.author.anonymize() | |||||||||||||||||||||||||
) | ) | |||||||||||||||||||||||||
elif attr == "revisions": | elif attr == "revisions": | |||||||||||||||||||||||||
row = dataclasses.replace( | row = dataclasses.replace( | |||||||||||||||||||||||||
row, | row, | |||||||||||||||||||||||||
author=row.author.anonymize(), | author=row.author.anonymize(), | |||||||||||||||||||||||||
committer=row.committer.anonymize(), | committer=row.committer.anonymize(), | |||||||||||||||||||||||||
) | ) | |||||||||||||||||||||||||
if attr == "revisions": | ||||||||||||||||||||||||||
# the replayer should now drop the metadata attribute; see | ||||||||||||||||||||||||||
# swh/storgae/replay.py:_insert_objects() | ||||||||||||||||||||||||||
row.metadata = "null" | ||||||||||||||||||||||||||
return row | return row | |||||||||||||||||||||||||
for attr_ in ( | for attr_ in ( | |||||||||||||||||||||||||
"contents", | "contents", | |||||||||||||||||||||||||
"skipped_contents", | "skipped_contents", | |||||||||||||||||||||||||
"directories", | "directories", | |||||||||||||||||||||||||
"extid", | "extid", | |||||||||||||||||||||||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |
why the copy?