|
| 1 | +import pytest |
| 2 | + |
| 3 | +import kafka.admin |
| 4 | +from kafka.errors import IllegalArgumentError |
| 5 | + |
| 6 | + |
| 7 | +def test_config_resource(): |
| 8 | + with pytest.raises(KeyError): |
| 9 | + bad_resource = kafka.admin.ConfigResource('something', 'foo') |
| 10 | + good_resource = kafka.admin.ConfigResource('broker', 'bar') |
| 11 | + assert(good_resource.resource_type == kafka.admin.ConfigResourceType.BROKER) |
| 12 | + assert(good_resource.name == 'bar') |
| 13 | + assert(good_resource.configs is None) |
| 14 | + good_resource = kafka.admin.ConfigResource(kafka.admin.ConfigResourceType.TOPIC, 'baz', {'frob' : 'nob'}) |
| 15 | + assert(good_resource.resource_type == kafka.admin.ConfigResourceType.TOPIC) |
| 16 | + assert(good_resource.name == 'baz') |
| 17 | + assert(good_resource.configs == {'frob' : 'nob'}) |
| 18 | + |
| 19 | + |
| 20 | +def test_new_partitions(): |
| 21 | + good_partitions = kafka.admin.NewPartitions(6) |
| 22 | + assert(good_partitions.total_count == 6) |
| 23 | + assert(good_partitions.new_assignments is None) |
| 24 | + good_partitions = kafka.admin.NewPartitions(7, [[1, 2, 3]]) |
| 25 | + assert(good_partitions.total_count == 7) |
| 26 | + assert(good_partitions.new_assignments == [[1, 2, 3]]) |
| 27 | + |
| 28 | + |
| 29 | +def test_new_topic(): |
| 30 | + with pytest.raises(IllegalArgumentError): |
| 31 | + bad_topic = kafka.admin.NewTopic('foo', -1, -1) |
| 32 | + with pytest.raises(IllegalArgumentError): |
| 33 | + bad_topic = kafka.admin.NewTopic('foo', 1, -1) |
| 34 | + with pytest.raises(IllegalArgumentError): |
| 35 | + bad_topic = kafka.admin.NewTopic('foo', 1, 1, {1 : [1, 1, 1]}) |
| 36 | + good_topic = kafka.admin.NewTopic('foo', 1, 2) |
| 37 | + assert(good_topic.name == 'foo') |
| 38 | + assert(good_topic.num_partitions == 1) |
| 39 | + assert(good_topic.replication_factor == 2) |
| 40 | + assert(good_topic.replica_assignments == {}) |
| 41 | + assert(good_topic.topic_configs == {}) |
| 42 | + good_topic = kafka.admin.NewTopic('bar', -1, -1, {1 : [1, 2, 3]}, {'key' : 'value'}) |
| 43 | + assert(good_topic.name == 'bar') |
| 44 | + assert(good_topic.num_partitions == -1) |
| 45 | + assert(good_topic.replication_factor == -1) |
| 46 | + assert(good_topic.replica_assignments == {1: [1, 2, 3]}) |
| 47 | + assert(good_topic.topic_configs == {'key' : 'value'}) |
0 commit comments