Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_cassandra.py
Show First 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | def swh_storage_backend_config(cassandra_cluster, keyspace): | ||||
for table in TABLES: | for table in TABLES: | ||||
storage._cql_runner._session.execute('TRUNCATE TABLE "%s"' % table) | storage._cql_runner._session.execute('TRUNCATE TABLE "%s"' % table) | ||||
storage._cql_runner._cluster.shutdown() | storage._cql_runner._cluster.shutdown() | ||||
@pytest.mark.cassandra | @pytest.mark.cassandra | ||||
class TestCassandraStorage(_TestStorage): | class TestCassandraStorage(_TestStorage): | ||||
def test_content_add_murmur3_collision( | def test_content_add_murmur3_collision(self, swh_storage, mocker, sample_data): | ||||
self, swh_storage, mocker, sample_data_model | |||||
): | |||||
"""The Murmur3 token is used as link from index tables to the main | """The Murmur3 token is used as link from index tables to the main | ||||
table; and non-matching contents with colliding murmur3-hash | table; and non-matching contents with colliding murmur3-hash | ||||
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_model["content"][:2] | cont, cont2 = sample_data["content"][:2] | ||||
# always return a token | # always return a token | ||||
def mock_cgtfsh(algo, hash_): | def mock_cgtfsh(algo, hash_): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
assert algo in ("sha1", "sha1_git") | assert algo in ("sha1", "sha1_git") | ||||
return [123456] | return [123456] | ||||
Show All 17 Lines | def test_content_add_murmur3_collision(self, swh_storage, mocker, sample_data): | ||||
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, | ||||
} | } | ||||
def test_content_get_metadata_murmur3_collision( | def test_content_get_metadata_murmur3_collision( | ||||
self, swh_storage, mocker, sample_data_model | self, swh_storage, mocker, sample_data | ||||
): | ): | ||||
"""The Murmur3 token is used as link from index tables to the main | """The Murmur3 token is used as link from index tables to the main | ||||
table; and non-matching contents with colliding murmur3-hash | table; and non-matching contents with colliding murmur3-hash | ||||
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 = [ | cont, cont2 = [attr.evolve(c, ctime=now()) for c in sample_data["content"][:2]] | ||||
attr.evolve(c, ctime=now()) for c in sample_data_model["content"][:2] | |||||
] | |||||
# always return a token | # always return a token | ||||
def mock_cgtfsh(algo, hash_): | def mock_cgtfsh(algo, hash_): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
assert algo in ("sha1", "sha1_git") | assert algo in ("sha1", "sha1_git") | ||||
return [123456] | return [123456] | ||||
Show All 23 Lines | ): | ||||
# dropping extra column not returned | # dropping extra column not returned | ||||
expected_cont = attr.evolve(cont, data=None, ctime=None).to_dict() | expected_cont = attr.evolve(cont, data=None, ctime=None).to_dict() | ||||
del expected_cont["ctime"] # forced to pop it as to_dict does not | del expected_cont["ctime"] # forced to pop it as to_dict does not | ||||
# but cont2 should be filtered out | # but cont2 should be filtered out | ||||
assert actual_result == {cont.sha1: [expected_cont]} | assert actual_result == {cont.sha1: [expected_cont]} | ||||
def test_content_find_murmur3_collision( | def test_content_find_murmur3_collision(self, swh_storage, mocker, sample_data): | ||||
self, swh_storage, mocker, sample_data_model | |||||
): | |||||
"""The Murmur3 token is used as link from index tables to the main | """The Murmur3 token is used as link from index tables to the main | ||||
table; and non-matching contents with colliding murmur3-hash | table; and non-matching contents with colliding murmur3-hash | ||||
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 = [ | cont, cont2 = [attr.evolve(c, ctime=now()) for c in sample_data["content"][:2]] | ||||
attr.evolve(c, ctime=now()) for c in sample_data_model["content"][:2] | |||||
] | |||||
# always return a token | # always return a token | ||||
def mock_cgtfsh(algo, hash_): | def mock_cgtfsh(algo, hash_): | ||||
nonlocal called | nonlocal called | ||||
called += 1 | called += 1 | ||||
assert algo in ("sha1", "sha1_git") | assert algo in ("sha1", "sha1_git") | ||||
return [123456] | return [123456] | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |