diff options
author | Mark Roberts <wizzat@fb.com> | 2014-09-03 10:56:22 -0700 |
---|---|---|
committer | Mark Roberts <wizzat@fb.com> | 2014-09-03 10:56:22 -0700 |
commit | e889c8aef01e9a0b0fc55c433314041ad3dccb2a (patch) | |
tree | 20f76d942e0885b03046d90f52c5bc2be9c06c7c | |
parent | 63350070350b0b41903ab78f41b388c518f9dad7 (diff) | |
download | kafka-python-e889c8aef01e9a0b0fc55c433314041ad3dccb2a.tar.gz |
Fix test errors related to mocks
-rw-r--r-- | kafka/client.py | 7 | ||||
-rw-r--r-- | test/test_client.py | 9 |
2 files changed, 10 insertions, 6 deletions
diff --git a/kafka/client.py b/kafka/client.py index 410573a..a918091 100644 --- a/kafka/client.py +++ b/kafka/client.py @@ -1,3 +1,4 @@ +import binascii import collections import copy import functools @@ -96,7 +97,7 @@ class KafkaClient(object): return response except Exception as e: log.warning("Could not send request [%r] to server %s:%i, " - "trying next server: %s" % (request, host, port, e)) + "trying next server: %s" % (binascii.b2a_hex(request), host, port, e)) raise KafkaUnavailableError("All servers failed to process request") @@ -160,11 +161,11 @@ class KafkaClient(object): response = conn.recv(requestId) except ConnectionError as e: log.warning("Could not receive response to request [%s] " - "from server %s: %s", request, conn, e) + "from server %s: %s", binascii.b2a_hex(request), conn, e) failed = True except ConnectionError as e: log.warning("Could not send request [%s] to server %s: %s", - request, conn, e) + binascii.b2a_hex(request), conn, e) failed = True if failed: diff --git a/test/test_client.py b/test/test_client.py index 601e454..40da7ee 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -4,6 +4,7 @@ import six from mock import MagicMock, patch from kafka import KafkaClient +import kafka.protocol from kafka.common import ( ProduceRequest, BrokerMetadata, PartitionMetadata, TopicAndPartition, KafkaUnavailableError, @@ -56,11 +57,12 @@ class TestKafkaClient(unittest.TestCase): with patch.object(KafkaClient, '_get_conn', side_effect=mock_get_conn): client = KafkaClient(hosts=['kafka01:9092', 'kafka02:9092']) + req = kafka.protocol.KafkaProtocol.encode_metadata_request(b'client', 0) with self.assertRaises(KafkaUnavailableError): - client._send_broker_unaware_request(1, 'fake request') + client._send_broker_unaware_request(1, req) for key, conn in six.iteritems(mocked_conns): - conn.send.assert_called_with(1, 'fake request') + conn.send.assert_called_with(1, req) def test_send_broker_unaware_request(self): 'Tests that call works when at least one of the host is available' @@ -83,7 +85,8 @@ class TestKafkaClient(unittest.TestCase): with patch.object(KafkaClient, '_get_conn', side_effect=mock_get_conn): client = KafkaClient(hosts='kafka01:9092,kafka02:9092') - resp = client._send_broker_unaware_request(1, 'fake request') + req = kafka.protocol.KafkaProtocol.encode_metadata_request(b'client', 0) + resp = client._send_broker_unaware_request(1, req) self.assertEqual('valid response', resp) mocked_conns[('kafka02', 9092)].recv.assert_called_with(1) |