def test_hash(self):
        expected = [  # Expected values are from the Java implementation
            #  00000000 -> HEAP_DATA_OVERHEAD
            (b"00000000key-1", 1228513025, 107),
            (b"12345678key-1", 1228513025,
             107),  # Heap data overhead should not matter
            (b"00000000key-2", 1503416236, 105),
            (b"00000000key-3", 1876349747, 218),
            (b"00000000key-4", -914632498, 181),
            (b"00000000key-5", -803210507, 111),
            (b"00000000key-6", -847942313, 115),
            (b"00000000key-7", 1196747334, 223),
            (b"00000000key-8", -1444149994, 208),
            (b"00000000key-9", 1182720020, 140),
            # Test with different lengths
            (b"00000000", -1585187909, 238),
            (b"00000000a", -1686100800, 46),
            (b"00000000ab", 312914265, 50),
            (b"00000000abc", -2068121803, 208),
            (b"00000000abcd", -973615161, 236),
            (b"", -1585187909, 238),
        ]

        for key, mm_hash, partition_id in expected:
            h = murmur_hash3_x86_32(bytearray(key))
            p = hash_to_index(h, 271)
            self.assertEqual(h, mm_hash)
            self.assertEqual(p, partition_id)
 def get_partition_id(self, key):
     if self.partition_count == 0:
         # Partition count can not be zero for the SYNC mode.
         # On the SYNC mode, we are waiting for the first connection to be established.
         # We are initializing the partition count with the value coming from the server with authentication.
         # This error is used only for ASYNC mode client.
         raise ClientOfflineError()
     return hash_to_index(key.get_partition_hash(), self.partition_count)
Пример #3
0
    def get_partition_id(self, key):
        """
        Returns the partition id for a Data key.

        :param key: (object), the data key.
        :return: (int), the partition id.
        """
        data = self._client.serialization_service.to_data(key)
        count = self.get_partition_count()
        return hash_to_index(data.get_partition_hash(), count)
    def test_hash(self):
        expected = [
            ("key-1", 1228513025, 107),
            ("key-2", 1503416236, 105),
            ("key-3", 1876349747, 218),
            ("key-4", -914632498, 181),
            ("key-5", -803210507, 111),
            ("key-6", -847942313, 115),
            ("key-7", 1196747334, 223),
            ("key-8", -1444149994, 208),
            ("key-9", 1182720020, 140),
        ]

        for key, hash, partition_id in expected:
            h = murmur_hash3_x86_32(key, 0, len(key))
            p = hash_to_index(h, 271)
            self.assertEqual(h, hash)
            self.assertEqual(p, partition_id)
Пример #5
0
    def test_hash(self):
        expected = [
            (b"key-1", 1228513025, 107),
            (b"key-2", 1503416236, 105),
            (b"key-3", 1876349747, 218),
            (b"key-4", -914632498, 181),
            (b"key-5", -803210507, 111),
            (b"key-6", -847942313, 115),
            (b"key-7", 1196747334, 223),
            (b"key-8", -1444149994, 208),
            (b"key-9", 1182720020, 140),
        ]

        for key, hash, partition_id in expected:
            h = murmur_hash3_x86_32(key, 0, len(key))
            p = hash_to_index(h, 271)
            self.assertEqual(h, hash)
            self.assertEqual(p, partition_id)
 def get_partition_id(self, key):
     data = self._client.serializer.to_data(key)
     count = self.get_partition_count()
     return hash_to_index(data.get_partition_hash(), count)
Пример #7
0
 def get_partition_id(self, key):
     data = self._client.serialization_service.to_data(key)
     count = self.get_partition_count()
     return hash_to_index(data.get_partition_hash(), count)