Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_cassandra.py
Show First 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | def test_content_add_murmur3_collision(self, swh_storage, mocker, sample_data): | ||||
assert algo in ("sha1", "sha1_git") | assert algo in ("sha1", "sha1_git") | ||||
return [123456] | return [123456] | ||||
mocker.patch.object( | mocker.patch.object( | ||||
swh_storage._cql_runner, "content_get_tokens_from_single_algo", mock_cgtfsa, | swh_storage._cql_runner, "content_get_tokens_from_single_algo", mock_cgtfsa, | ||||
) | ) | ||||
# For all tokens, always return cont | # For all tokens, always return cont | ||||
def mock_cgft(token): | def mock_cgft(tokens): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
return [ | return [ | ||||
ContentRow( | ContentRow( | ||||
length=10, | length=10, | ||||
ctime=datetime.datetime.now(), | ctime=datetime.datetime.now(), | ||||
status="present", | status="present", | ||||
**{algo: getattr(cont, algo) for algo in HASH_ALGORITHMS}, | **{algo: getattr(cont, algo) for algo in HASH_ALGORITHMS}, | ||||
) | ) | ||||
] | ] | ||||
mocker.patch.object( | mocker.patch.object( | ||||
swh_storage._cql_runner, "content_get_from_token", mock_cgft | swh_storage._cql_runner, "content_get_from_tokens", mock_cgft | ||||
) | ) | ||||
actual_result = swh_storage.content_add([cont2]) | actual_result = swh_storage.content_add([cont2]) | ||||
assert called == 4 | assert called == 4 | ||||
assert actual_result == { | assert actual_result == { | ||||
"content:add": 1, | "content:add": 1, | ||||
"content:add:bytes": cont2.length, | "content:add:bytes": cont2.length, | ||||
Show All 20 Lines | ): | ||||
mocker.patch.object( | mocker.patch.object( | ||||
swh_storage._cql_runner, "content_get_tokens_from_single_algo", mock_cgtfsa, | swh_storage._cql_runner, "content_get_tokens_from_single_algo", mock_cgtfsa, | ||||
) | ) | ||||
# For all tokens, always return cont and cont2 | # For all tokens, always return cont and cont2 | ||||
cols = list(set(cont.to_dict()) - {"data"}) | cols = list(set(cont.to_dict()) - {"data"}) | ||||
def mock_cgft(token): | def mock_cgft(tokens): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
return [ | return [ | ||||
ContentRow(**{col: getattr(cont, col) for col in cols},) | ContentRow(**{col: getattr(cont, col) for col in cols},) | ||||
for cont in [cont, cont2] | for cont in [cont, cont2] | ||||
] | ] | ||||
mocker.patch.object( | mocker.patch.object( | ||||
swh_storage._cql_runner, "content_get_from_token", mock_cgft | swh_storage._cql_runner, "content_get_from_tokens", mock_cgft | ||||
) | ) | ||||
actual_result = swh_storage.content_get([cont.sha1]) | actual_result = swh_storage.content_get([cont.sha1]) | ||||
assert called == 2 | assert called == 2 | ||||
# dropping extra column not returned | # dropping extra column not returned | ||||
expected_cont = attr.evolve(cont, data=None) | expected_cont = attr.evolve(cont, data=None) | ||||
Show All 19 Lines | def test_content_find_murmur3_collision(self, swh_storage, mocker, sample_data): | ||||
mocker.patch.object( | mocker.patch.object( | ||||
swh_storage._cql_runner, "content_get_tokens_from_single_algo", mock_cgtfsa, | swh_storage._cql_runner, "content_get_tokens_from_single_algo", mock_cgtfsa, | ||||
) | ) | ||||
# For all tokens, always return cont and cont2 | # For all tokens, always return cont and cont2 | ||||
cols = list(set(cont.to_dict()) - {"data"}) | cols = list(set(cont.to_dict()) - {"data"}) | ||||
def mock_cgft(token): | def mock_cgft(tokens): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
return [ | return [ | ||||
ContentRow(**{col: getattr(cont, col) for col in cols}) | ContentRow(**{col: getattr(cont, col) for col in cols}) | ||||
for cont in [cont, cont2] | for cont in [cont, cont2] | ||||
] | ] | ||||
mocker.patch.object( | mocker.patch.object( | ||||
swh_storage._cql_runner, "content_get_from_token", mock_cgft | swh_storage._cql_runner, "content_get_from_tokens", mock_cgft | ||||
) | ) | ||||
expected_content = attr.evolve(cont, data=None) | expected_content = attr.evolve(cont, data=None) | ||||
actual_result = swh_storage.content_find({"sha1": cont.sha1}) | actual_result = swh_storage.content_find({"sha1": cont.sha1}) | ||||
assert called == 2 | assert called == 2 | ||||
▲ Show 20 Lines • Show All 343 Lines • Show Last 20 Lines |