Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor aesthetic cleanup of partitioner tests #1618

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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