Skip to content

Commit 3b4f3fb

Browse files
committed
Python 2/3 compat, minor test improvements
1 parent 136efd3 commit 3b4f3fb

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

confluent_kafka/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def _make_topics_result(f, futmap):
281281
"""
282282
try:
283283
result = f.result()
284-
for topic, error in result.iteritems():
284+
for topic, error in result.items():
285285
fut = futmap.get(topic, None)
286286
if fut is None:
287287
raise RuntimeError("Topic {} not found in future-map: {}".format(topic, futmap))
@@ -294,7 +294,7 @@ def _make_topics_result(f, futmap):
294294
fut.set_result(None)
295295
except Exception as e:
296296
# Request-level exception, raise the same for all topics
297-
for topic, fut in futmap.iteritems():
297+
for topic, fut in futmap.items():
298298
fut.set_exception(e)
299299

300300
@staticmethod
@@ -305,7 +305,7 @@ def _make_resource_result(f, futmap):
305305
"""
306306
try:
307307
result = f.result()
308-
for resource, configs in result.iteritems():
308+
for resource, configs in result.items():
309309
fut = futmap.get(resource, None)
310310
if fut is None:
311311
raise RuntimeError("Resource {} not found in future-map: {}".format(resource, futmap))
@@ -319,7 +319,7 @@ def _make_resource_result(f, futmap):
319319
fut.set_result(configs)
320320
except Exception as e:
321321
# Request-level exception, raise the same for all resources
322-
for resource, fut in futmap.iteritems():
322+
for resource, fut in futmap.items():
323323
fut.set_exception(e)
324324

325325
@staticmethod

examples/adminapi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def example_create_topics(a, topics):
3535
# Timeouts are preferably controlled by passing request_timeout=15.0
3636
# to the create_topics() call.
3737
# All futures will finish at the same time.
38-
for topic, f in fs.iteritems():
38+
for topic, f in fs.items():
3939
try:
4040
f.result() # The result itself is None
4141
print("Topic {} created".format(topic))
@@ -55,7 +55,7 @@ def example_delete_topics(a, topics):
5555
fs = a.delete_topics(topics, operation_timeout=30)
5656

5757
# Wait for operation to finish.
58-
for topic, f in fs.iteritems():
58+
for topic, f in fs.items():
5959
try:
6060
f.result() # The result itself is None
6161
print("Topic {} deleted".format(topic))
@@ -74,7 +74,7 @@ def example_create_partitions(a, topics):
7474
fs = a.create_partitions(new_parts, validate_only=False)
7575

7676
# Wait for operation to finish.
77-
for topic, f in fs.iteritems():
77+
for topic, f in fs.items():
7878
try:
7979
f.result() # The result itself is None
8080
print("Additional partitions created for topic {}".format(topic))
@@ -101,7 +101,7 @@ def example_describe_configs(a, args):
101101
fs = a.describe_configs(resources)
102102

103103
# Wait for operation to finish.
104-
for res, f in fs.iteritems():
104+
for res, f in fs.items():
105105
try:
106106
configs = f.result()
107107
for config in iter(configs.values()):
@@ -126,7 +126,7 @@ def example_alter_configs(a, args):
126126
fs = a.alter_configs(resources)
127127

128128
# Wait for operation to finish.
129-
for res, f in fs.iteritems():
129+
for res, f in fs.items():
130130
try:
131131
f.result() # empty, but raises exception on failure
132132
print("{} configuration successfully altered".format(res))

examples/integration_test.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ def print_wmark(consumer, parts):
509509

510510
example_headers = None
511511

512+
eof_reached = dict()
513+
512514
while True:
513515
# Consume until EOF or error
514516

@@ -521,7 +523,10 @@ def print_wmark(consumer, parts):
521523
if msg.error().code() == confluent_kafka.KafkaError._PARTITION_EOF:
522524
print('Reached end of %s [%d] at offset %d' %
523525
(msg.topic(), msg.partition(), msg.offset()))
524-
break
526+
eof_reached[(msg.topic(), msg.partition())] = True
527+
if len(eof_reached) == len(c.assignment()):
528+
print('EOF reached for all assigned partitions: exiting')
529+
break
525530
else:
526531
print('Consumer error: %s: ignoring' % msg.error())
527532
break
@@ -928,7 +933,7 @@ def verify_topic_metadata(client, exp_topics):
928933

929934
md = client.list_topics()
930935

931-
for exptopic, exppartcnt in exp_topics.iteritems():
936+
for exptopic, exppartcnt in exp_topics.items():
932937
if exptopic not in md.topics:
933938
print("Topic {} not yet reported in metadata: retrying".format(exptopic))
934939
do_retry += 1
@@ -973,7 +978,7 @@ def verify_admin():
973978
validate_only=validate,
974979
operation_timeout=10.0)
975980

976-
for topic2, f in fs.iteritems():
981+
for topic2, f in fs.items():
977982
f.result() # trigger exception if there was an error
978983

979984
#
@@ -989,7 +994,7 @@ def verify_admin():
989994
new_total_count=num_partitions)],
990995
operation_timeout=10.0)
991996

992-
for topic2, f in fs.iteritems():
997+
for topic2, f in fs.items():
993998
f.result() # trigger exception if there was an error
994999

9951000
#
@@ -1002,7 +1007,7 @@ def verify_config(expconfig, configs):
10021007
Verify that the config key,values in expconfig are found
10031008
and matches the ConfigEntry in configs.
10041009
"""
1005-
for key, expvalue in expconfig.iteritems():
1010+
for key, expvalue in expconfig.items():
10061011
entry = configs.get(key, None)
10071012
assert entry is not None, "Config {} not found in returned configs".format(key)
10081013

@@ -1025,7 +1030,7 @@ def verify_config(expconfig, configs):
10251030
topic_config["file.delete.delay.ms"] = 12345
10261031
topic_config["compression.type"] = "snappy"
10271032

1028-
for key, value in topic_config.iteritems():
1033+
for key, value in topic_config.items():
10291034
resource.set_config(key, value)
10301035

10311036
fs = a.alter_configs([resource])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy