Skip to content

Commit

Permalink
Minor aesthetic cleanup of partitioner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwidman committed Oct 27, 2018
1 parent 2b67493 commit 1945ad1
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions test/test_partitioner.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import absolute_import

import pytest

from kafka.partitioner import DefaultPartitioner, Murmur2Partitioner, RoundRobinPartitioner
from kafka.partitioner.hashed import murmur2


def test_default_partitioner():
partitioner = DefaultPartitioner()
all_partitions = list(range(100))
available = all_partitions
all_partitions = available = list(range(100))
# partitioner should return the same partition for the same key
p1 = partitioner(b'foo', all_partitions, available)
p2 = partitioner(b'foo', all_partitions, available)
Expand All @@ -23,8 +24,7 @@ def test_default_partitioner():

def test_roundrobin_partitioner():
partitioner = RoundRobinPartitioner()
all_partitions = list(range(100))
available = all_partitions
all_partitions = available = list(range(100))
# partitioner should cycle between partitions
i = 0
max_partition = all_partitions[len(all_partitions) - 1]
Expand Down Expand Up @@ -53,15 +53,14 @@ def test_roundrobin_partitioner():
i += 1


def test_murmur2_java_compatibility():
@pytest.mark.parametrize("bytes_payload,partition_number", [
(b'', 681), (b'a', 524), (b'ab', 434), (b'abc', 107), (b'123456789', 566),
(b'\x00 ', 742)
])
def test_murmur2_java_compatibility(bytes_payload, partition_number):
p = Murmur2Partitioner(range(1000))
# compare with output from Kafka's org.apache.kafka.clients.producer.Partitioner
assert p.partition(b'') == 681
assert p.partition(b'a') == 524
assert p.partition(b'ab') == 434
assert p.partition(b'abc') == 107
assert p.partition(b'123456789') == 566
assert p.partition(b'\x00 ') == 742
assert p.partition(bytes_payload) == partition_number


def test_murmur2_not_ascii():
Expand Down

0 comments on commit 1945ad1

Please sign in to comment.