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(doc_ids) csiphash_hashes = ShardAccessor.hash_doc_ids_python(doc_ids) self.assertEquals(len(csiphash_hashes), N) self.assertTrue( all( isinstance(hash_, (int, long)) 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)
def test_hash_doc_ids(self): N = 1001 doc_ids = [str(i) for i in range(N)] hashes = ShardAccessor.hash_doc_ids_sql(doc_ids) self.assertEquals(len(hashes), N) self.assertTrue( all(isinstance(hash_, int) for hash_ in hashes.values()))
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(doc_ids) csiphash_hashes = ShardAccessor.hash_doc_ids_python(doc_ids) self.assertEquals(len(csiphash_hashes), N) self.assertTrue(all(isinstance(hash_, (int, long)) 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)
def test_hash_doc_ids(self): N = 1001 doc_ids = [str(i) for i in range(N)] hashes = ShardAccessor.hash_doc_ids_sql(doc_ids) self.assertEquals(len(hashes), N) self.assertTrue(all(isinstance(hash_, int) for hash_ in hashes.values()))