Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/replayer/tests/test_cli.py
Show All 14 Lines | |||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||
from confluent_kafka import Producer | from confluent_kafka import Producer | ||||
import msgpack | import msgpack | ||||
import pytest | import pytest | ||||
import yaml | import yaml | ||||
from swh.journal.serializers import key_to_kafka | from swh.journal.serializers import key_to_kafka | ||||
from swh.model.hashutil import hash_to_hex | from swh.model.hashutil import MultiHash, hash_to_hex | ||||
from swh.objstorage.backends.in_memory import InMemoryObjStorage | from swh.objstorage.backends.in_memory import InMemoryObjStorage | ||||
from swh.objstorage.replayer.cli import objstorage_cli_group | from swh.objstorage.replayer.cli import objstorage_cli_group | ||||
from swh.objstorage.replayer.replay import CONTENT_REPLAY_RETRIES | from swh.objstorage.replayer.replay import CONTENT_REPLAY_RETRIES | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
CLI_CONFIG = { | CLI_CONFIG = { | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | producer = Producer( | ||||
"client.id": "test-producer", | "client.id": "test-producer", | ||||
"acks": "all", | "acks": "all", | ||||
} | } | ||||
) | ) | ||||
contents = {} | contents = {} | ||||
for i in range(NUM_CONTENTS): | for i in range(NUM_CONTENTS): | ||||
content = b"\x00" * 19 + bytes([i]) | content = b"\x00" * 19 + bytes([i]) | ||||
sha1 = objstorage.add(content) | sha1 = MultiHash(["sha1"]).from_data(content).digest()["sha1"] | ||||
objstorage.add(content=content, obj_id=sha1) | |||||
contents[sha1] = content | contents[sha1] = content | ||||
producer.produce( | producer.produce( | ||||
topic=kafka_prefix + ".content", | topic=kafka_prefix + ".content", | ||||
key=key_to_kafka(sha1), | key=key_to_kafka(sha1), | ||||
value=key_to_kafka( | value=key_to_kafka( | ||||
{ | { | ||||
"sha1": sha1, | "sha1": sha1, | ||||
"status": "visible", | "status": "visible", | ||||
▲ Show 20 Lines • Show All 572 Lines • Show Last 20 Lines |