diff options
author | Dana Powers <dana.powers@rd.io> | 2015-06-10 09:43:47 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@rd.io> | 2015-06-10 10:15:45 -0700 |
commit | ecdcdf531d232a923f4869f421d3a908dd735d4a (patch) | |
tree | 5d2c0e0a76d940bb2cd208a171235444042453f6 /test/test_consumer.py | |
parent | e60de943175c45d64602c0388b502b9763b34f27 (diff) | |
download | kafka-python-ecdcdf531d232a923f4869f421d3a908dd735d4a.tar.gz |
(test) Consumer commit() should log errors and return True/False, not raise exceptions
Diffstat (limited to 'test/test_consumer.py')
-rw-r--r-- | test/test_consumer.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/test_consumer.py b/test/test_consumer.py index bbced02..57c69a2 100644 --- a/test/test_consumer.py +++ b/test/test_consumer.py @@ -81,6 +81,30 @@ class TestSimpleConsumer(unittest.TestCase): with self.assertRaises(UnknownTopicOrPartitionError): consumer.get_messages(20) + def test_simple_consumer_commit_does_not_raise(self): + client = MagicMock() + client.get_partition_ids_for_topic.return_value = [0, 1] + + def mock_offset_fetch_request(group, payloads, **kwargs): + return [OffsetFetchResponse(p.topic, p.partition, 0, b'', 0) for p in payloads] + + client.send_offset_fetch_request.side_effect = mock_offset_fetch_request + + def mock_offset_commit_request(group, payloads, **kwargs): + raise FailedPayloadsError(payloads[0]) + + client.send_offset_commit_request.side_effect = mock_offset_commit_request + + consumer = SimpleConsumer(client, group='foobar', + topic='topic', partitions=[0, 1], + auto_commit=False) + + # Mock internal commit check + consumer.count_since_commit = 10 + + # This should not raise an exception + self.assertFalse(consumer.commit(partitions=[0, 1])) + @staticmethod def fail_requests_factory(error_factory): # Mock so that only the first request gets a valid response |