Ejemplo n.º 1
0
 def test_key_bytearray(self):
     # 15 letters long to hit 'if extrabytes == 3:'
     key = bytearray('lasquinceletras')
     expected = 4030895744 % 100000  # Int is from java murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 2
0
 def test_key_bytearray(self):
     # 15 letters long to hit 'if extrabytes == 3:'
     key = bytearray('lasquinceletras')
     expected = (4030895744 & 0x7FFFFFFF) % 100000  # Int is from murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 3
0
 def test_key_match_java(self):
     key = 'cc54d7f5-8508-4302-bc23-c5d16cfb50fd'
     key = key.decode(encoding='UTF-8', errors='strict')
     parts = xrange(10)
     expected = 4
     p = HashedPartitioner(self.T1, parts)
     part = p.partition(key, parts)
     self.assertEqual(expected, part)
Ejemplo n.º 4
0
 def test_key_str(self):
     """
     Bytestring keys are hashed directly.
     """
     key = b'The rain in Spain falls mainly on the plain.'
     expected = (2823782121 & 0x7FFFFFFF) % 100000  # Int is from murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 5
0
 def test_key_str(self):
     """
     Bytestring keys are hashed directly.
     """
     key = b'The rain in Spain falls mainly on the plain.'
     expected = (2823782121 & 0x7FFFFFFF) % 100000  # Int is from murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 6
0
 def test_key_large(self):
     """
     The hashed partitioner does not limit key length.
     """
     key = u''.join([u"Key:{} ".format(i) for i in range(4096)]).encode('ascii')
     expected = 1765856722 % 100000  # Int is from online hash tool
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 7
0
 def test_key_large(self):
     """
     The hashed partitioner does not limit key length.
     """
     key = u''.join([u"Key:{} ".format(i)
                     for i in range(4096)]).encode('ascii')
     expected = 1765856722 % 100000  # Int is from online hash tool
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 8
0
 def test_key_unicode(self):
     """
     Text string keys are converted to UTF-8 and hashed to match the Java
     implementation.
     """
     key = u'슬듢芬'
     expected = (3978338664 & 0x7FFFFFFF) % 100000  # Int is from murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 9
0
 def test_key_bytearray(self):
     """
     :class:`bytearray` keys are hashed directly.
     """
     # 15 letters long to hit 'if extrabytes == 3:'
     key = bytearray(b'lasquinceletras')
     expected = (4030895744 & 0x7FFFFFFF) % 100000  # Int is from murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 10
0
 def test_key_unicode(self):
     """
     Text string keys are converted to UTF-8 and hashed to match the Java
     implementation.
     """
     key = u'슬듢芬'
     expected = (3978338664 & 0x7FFFFFFF) % 100000  # Int is from murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 11
0
 def test_key_match_java(self):
     """
     Hashing a UUID produces the same result the Java implementation would.
     """
     key = b'cc54d7f5-8508-4302-bc23-c5d16cfb50fd'
     key = key.decode(encoding='UTF-8', errors='strict')
     parts = range(10)
     expected = 4
     p = HashedPartitioner(self.T1, parts)
     part = p.partition(key, parts)
     self.assertEqual(expected, part)
Ejemplo n.º 12
0
 def test_key_match_java(self):
     """
     Hashing a UUID produces the same result the Java implementation would.
     """
     key = b'cc54d7f5-8508-4302-bc23-c5d16cfb50fd'
     key = key.decode(encoding='UTF-8', errors='strict')
     parts = range(10)
     expected = 4
     p = HashedPartitioner(self.T1, parts)
     part = p.partition(key, parts)
     self.assertEqual(expected, part)
Ejemplo n.º 13
0
    def test_partition_distribution(self):
        parts = [1, 2, 3, 4, 5]
        p = HashedPartitioner(self.T1, parts)

        # Make sure we have decent distribution
        keycount = 10000
        key_list = []
        part_keycount = defaultdict(lambda: 0)
        key_to_part = {}
        for i in xrange(keycount):
            key = random_string(16)
            key_list.append(key)
            part = p.partition(key, parts)
            part_keycount[part] += 1
            key_to_part[key] = part

        self.assertLess(std(part_keycount.values()), keycount / 100)

        # Ensure we get the same partition for the same key
        for key in key_to_part.keys():
            part = p.partition(key, parts)
            self.assertEqual(part, key_to_part[key])
Ejemplo n.º 14
0
    def test_partition_distribution(self):
        parts = [1, 2, 3, 4, 5]
        p = HashedPartitioner(self.T1, parts)

        # Make sure we have decent distribution
        keycount = 10000
        key_list = []
        part_keycount = defaultdict(lambda: 0)
        key_to_part = {}
        for _i in range(keycount):
            key = random_string(16)
            key_list.append(key)
            part = p.partition(key, parts)
            part_keycount[part] += 1
            key_to_part[key] = part

        self.assertLess(std(part_keycount.values()), keycount / 100)

        # Ensure we get the same partition for the same key
        for key in key_to_part.keys():
            part = p.partition(key, parts)
            self.assertEqual(part, key_to_part[key])
Ejemplo n.º 15
0
 def test_key_none(self):
     key = None
     expected = 275646681 % 100000  # Int is from java murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 16
0
 def test_key_unicode(self):
     key = u'슬듢芬'
     expected = 3978338664 % 100000  # Int is from java murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 17
0
 def test_key_large(self):
     key = ''.join(["Key:{} ".format(i) for i in xrange(4096)])
     expected = 1765856722 % 100000  # Int is from online hash tool
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 18
0
 def test_key_integer(self):
     key = 123456789
     expected = 2472730214 % 100000  # Int is from java murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 19
0
 def test_key_integer(self):
     key = 123456789
     expected = (2472730214 & 0x7FFFFFFF) % 100000  # Int is from murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 20
0
 def test_key_unicode(self):
     key = u'슬듢芬'
     expected = (3978338664 & 0x7FFFFFFF) % 100000  # Int is from murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 21
0
 def test_key_none(self):
     key = None
     expected = 275646681 % 100000  # Int is from java murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 22
0
 def test_key_large(self):
     key = ''.join(["Key:{} ".format(i) for i in xrange(4096)])
     expected = 1765856722 % 100000  # Int is from online hash tool
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 23
0
 def test_key_str(self):
     key = 'The rain in Spain falls mainly on the plain.'
     expected = 2823782121 % 100000  # Int is from java murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)
Ejemplo n.º 24
0
 def test_key_str(self):
     key = 'The rain in Spain falls mainly on the plain.'
     expected = 2823782121 % 100000  # Int is from java murmur2
     p = HashedPartitioner(self.T1, self.parts)
     part = p.partition(key, self.parts)
     self.assertEqual(expected, part)