summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2015-12-02 13:34:33 -0800
committerDana Powers <dana.powers@gmail.com>2015-12-02 13:34:33 -0800
commit4fc15a5f27ff6f4c0c96ba39b55521891e96e5d5 (patch)
tree8efa8ab04427b0cd1dc1e7dc21c8b42a583d3cc1 /test
parent149d43cf6cfe121347c15b39600299b29b583dc1 (diff)
parentbb6283df6f9331595020d1d8c28818eeb1131957 (diff)
downloadkafka-python-4fc15a5f27ff6f4c0c96ba39b55521891e96e5d5.tar.gz
Merge pull request #439 from chrischamberlin/fix-murmur
Fix translation of Java murmur2 code, fix byte encoding for Python 3.
Diffstat (limited to 'test')
-rw-r--r--test/test_partitioner.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/test_partitioner.py b/test/test_partitioner.py
new file mode 100644
index 0000000..67cd83b
--- /dev/null
+++ b/test/test_partitioner.py
@@ -0,0 +1,23 @@
+import six
+from . import unittest
+
+from kafka.partitioner import (Murmur2Partitioner)
+
+class TestMurmurPartitioner(unittest.TestCase):
+ def test_hash_bytes(self):
+ p = Murmur2Partitioner(range(1000))
+ self.assertEqual(p.partition(bytearray(b'test')), p.partition(b'test'))
+
+ def test_hash_encoding(self):
+ p = Murmur2Partitioner(range(1000))
+ self.assertEqual(p.partition('test'), p.partition(u'test'))
+
+ def test_murmur2_java_compatibility(self):
+ p = Murmur2Partitioner(range(1000))
+ # compare with output from Kafka's org.apache.kafka.clients.producer.Partitioner
+ self.assertEqual(681, p.partition(b''))
+ self.assertEqual(524, p.partition(b'a'))
+ self.assertEqual(434, p.partition(b'ab'))
+ self.assertEqual(107, p.partition(b'abc'))
+ self.assertEqual(566, p.partition(b'123456789'))
+ self.assertEqual(742, p.partition(b'\x00 '))