Пример #1
0
 def test_hash_doc_ids(self):
     N = 1001
     doc_ids = [str(i) for i in range(N)]
     hashes = ShardAccessor.hash_doc_ids_sql_for_testing(doc_ids)
     self.assertEqual(len(hashes), N)
     self.assertTrue(
         all(isinstance(hash_, int) for hash_ in hashes.values()))
Пример #2
0
    def test_hash_in_python(self):
        # test that python hashing matches with SQL hashing
        N = 2048
        doc_ids = [str(i) for i in range(N)]

        sql_hashes = ShardAccessor.hash_doc_ids_sql_for_testing(doc_ids)

        csiphash_hashes = ShardAccessor.hash_doc_ids_python(doc_ids)
        self.assertEquals(len(csiphash_hashes), N)
        self.assertTrue(all(isinstance(hash_, six.integer_types) for hash_ in csiphash_hashes.values()))

        N_shards = 1024
        part_mask = N_shards - 1

        sql_shards = {doc_id: hash_ & part_mask for doc_id, hash_ in sql_hashes.items()}
        python_shards = {doc_id: hash_ & part_mask for doc_id, hash_ in sql_hashes.items()}

        self.assertEqual(python_shards, sql_shards)
Пример #3
0
 def test_hash_doc_ids(self):
     N = 1001
     doc_ids = [str(i) for i in range(N)]
     hashes = ShardAccessor.hash_doc_ids_sql_for_testing(doc_ids)
     self.assertEquals(len(hashes), N)
     self.assertTrue(all(isinstance(hash_, int) for hash_ in hashes.values()))