Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_cassandra.py
Show First 20 Lines • Show All 270 Lines • ▼ Show 20 Lines | def test_content_add_murmur3_collision(self, swh_storage, mocker, sample_data): | ||||
are filtered-out when reading the main table. | are filtered-out when reading the main table. | ||||
This test checks the content methods do filter out these collision. | This test checks the content methods do filter out these collision. | ||||
""" | """ | ||||
called = 0 | called = 0 | ||||
cont, cont2 = sample_data.contents[:2] | cont, cont2 = sample_data.contents[:2] | ||||
# always return a token | # always return a token | ||||
def mock_cgtfsh(algo, hash_): | def mock_cgtfsa(algo, hashes): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
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_hash", mock_cgtfsh, | 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(token): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
return [ | return [ | ||||
ContentRow( | ContentRow( | ||||
Show All 24 Lines | ): | ||||
are filtered-out when reading the main table. | are filtered-out when reading the main table. | ||||
This test checks the content methods do filter out these collisions. | This test checks the content methods do filter out these collisions. | ||||
""" | """ | ||||
called = 0 | called = 0 | ||||
cont, cont2 = [attr.evolve(c, ctime=now()) for c in sample_data.contents[:2]] | cont, cont2 = [attr.evolve(c, ctime=now()) for c in sample_data.contents[:2]] | ||||
# always return a token | # always return a token | ||||
def mock_cgtfsh(algo, hash_): | def mock_cgtfsa(algo, hashes): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
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_hash", mock_cgtfsh, | 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(token): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
Show All 21 Lines | def test_content_find_murmur3_collision(self, swh_storage, mocker, sample_data): | ||||
are filtered-out when reading the main table. | are filtered-out when reading the main table. | ||||
This test checks the content methods do filter out these collisions. | This test checks the content methods do filter out these collisions. | ||||
""" | """ | ||||
called = 0 | called = 0 | ||||
cont, cont2 = [attr.evolve(c, ctime=now()) for c in sample_data.contents[:2]] | cont, cont2 = [attr.evolve(c, ctime=now()) for c in sample_data.contents[:2]] | ||||
# always return a token | # always return a token | ||||
def mock_cgtfsh(algo, hash_): | def mock_cgtfsa(algo, hashes): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
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_hash", mock_cgtfsh, | 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(token): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
▲ Show 20 Lines • Show All 358 Lines • Show Last 20 Lines |