-
Notifications
You must be signed in to change notification settings - Fork 915
Feature/explicit read #427
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
Closed
martintaraz
wants to merge
18
commits into
confluentinc:master
from
martintaraz:feature/explicit-read
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
20e7690
adding support for explicit read schema
166fa4f
changes in travis config
dc31b40
reformat code for flake8 acceptance
e2bc9a6
started integration tests with landoop docker
23f611c
edit docker run command
405676e
edit travis.yml for execution order
83be110
add service docker for all travis env's
7666925
remove osx build
71067de
work on integration test for explicit read
6a6b71d
work on integration test for explicit read
44c0019
work on integration test for explicit read
bb5655f
work on integration test for explicit read
d667ee2
work on integration test for explicit read
67edebe
work on integration test for explicit read
6b44d7a
work on integration test for explicit read
f0a8f51
work on integration test for explicit read
388e61e
work on integration test for explicit read
39a3fba
Merge branch 'master' into feature/explicit-read
martintaraz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
""" Test script for confluent_kafka module """ | ||
|
||
import confluent_kafka | ||
from confluent_kafka import admin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove any integration test changes not related to the pull request itself. This helps to keep the commit history clean. If you wish to submit a PR which cleans up formatting, white space and imports I'd be happy to review and merge however :) |
||
import os | ||
import time | ||
import uuid | ||
|
@@ -34,13 +33,14 @@ | |
try: | ||
# Memory tracker | ||
from pympler import tracker | ||
|
||
with_pympler = True | ||
except Exception as e: | ||
with_pympler = False | ||
|
||
|
||
try: | ||
from progress.bar import Bar | ||
|
||
with_progress = True | ||
except ImportError as e: | ||
with_progress = False | ||
|
@@ -106,7 +106,6 @@ def throttle_cb(throttle_event): | |
|
||
|
||
class InMemorySchemaRegistry(object): | ||
|
||
schemas = {} | ||
next_idx = 0 | ||
|
||
|
@@ -522,9 +521,9 @@ def verify_producer_performance(with_dr_cb=True): | |
bar.finish() | ||
|
||
print('# producing %d messages (%.2fMb) took %.3fs: %d msgs/s, %.2f Mb/s' % | ||
(msgs_produced, bytecnt / (1024*1024), t_produce_spent, | ||
(msgs_produced, bytecnt / (1024 * 1024), t_produce_spent, | ||
msgs_produced / t_produce_spent, | ||
(bytecnt/t_produce_spent) / (1024*1024))) | ||
(bytecnt / t_produce_spent) / (1024 * 1024))) | ||
print('# %d temporary produce() failures due to backpressure (local queue full)' % msgs_backpressure) | ||
|
||
print('waiting for %d/%d deliveries' % (len(p), msgs_produced)) | ||
|
@@ -533,9 +532,9 @@ def verify_producer_performance(with_dr_cb=True): | |
t_delivery_spent = time.time() - t_produce_start | ||
|
||
print('# producing %d messages (%.2fMb) took %.3fs: %d msgs/s, %.2f Mb/s' % | ||
(msgs_produced, bytecnt / (1024*1024), t_produce_spent, | ||
(msgs_produced, bytecnt / (1024 * 1024), t_produce_spent, | ||
msgs_produced / t_produce_spent, | ||
(bytecnt/t_produce_spent) / (1024*1024))) | ||
(bytecnt / t_produce_spent) / (1024 * 1024))) | ||
|
||
# Fake numbers if not using a dr_cb | ||
if not with_dr_cb: | ||
|
@@ -544,9 +543,9 @@ def verify_producer_performance(with_dr_cb=True): | |
dr.bytes_delivered = bytecnt | ||
|
||
print('# delivering %d messages (%.2fMb) took %.3fs: %d msgs/s, %.2f Mb/s' % | ||
(dr.msgs_delivered, dr.bytes_delivered / (1024*1024), t_delivery_spent, | ||
(dr.msgs_delivered, dr.bytes_delivered / (1024 * 1024), t_delivery_spent, | ||
dr.msgs_delivered / t_delivery_spent, | ||
(dr.bytes_delivered/t_delivery_spent) / (1024*1024))) | ||
(dr.bytes_delivered / t_delivery_spent) / (1024 * 1024))) | ||
print('# post-produce delivery wait took %.3fs' % | ||
(t_delivery_spent - t_produce_spent)) | ||
|
||
|
@@ -671,7 +670,7 @@ def print_wmark(consumer, parts): | |
elif (msg.offset() % 4) == 0: | ||
offsets = c.commit(msg, asynchronous=False) | ||
assert len(offsets) == 1, 'expected 1 offset, not %s' % (offsets) | ||
assert offsets[0].offset == msg.offset()+1, \ | ||
assert offsets[0].offset == msg.offset() + 1, \ | ||
'expected offset %d to be committed, not %s' % \ | ||
(msg.offset(), offsets) | ||
print('Sync committed offset: %s' % offsets) | ||
|
@@ -789,8 +788,8 @@ def my_on_revoke(consumer, partitions): | |
if msgcnt > 0: | ||
t_spent = time.time() - t_first_msg | ||
print('%d messages (%.2fMb) consumed in %.3fs: %d msgs/s, %.2f Mb/s' % | ||
(msgcnt, bytecnt / (1024*1024), t_spent, msgcnt / t_spent, | ||
(bytecnt / t_spent) / (1024*1024))) | ||
(msgcnt, bytecnt / (1024 * 1024), t_spent, msgcnt / t_spent, | ||
(bytecnt / t_spent) / (1024 * 1024))) | ||
|
||
print('closing consumer') | ||
c.close() | ||
|
@@ -844,7 +843,7 @@ def verify_batch_consumer(): | |
elif (msg.offset() % 4) == 0: | ||
offsets = c.commit(msg, asynchronous=False) | ||
assert len(offsets) == 1, 'expected 1 offset, not %s' % (offsets) | ||
assert offsets[0].offset == msg.offset()+1, \ | ||
assert offsets[0].offset == msg.offset() + 1, \ | ||
'expected offset %d to be committed, not %s' % \ | ||
(msg.offset(), offsets) | ||
print('Sync committed offset: %s' % offsets) | ||
|
@@ -945,8 +944,8 @@ def my_on_revoke(consumer, partitions): | |
if msgcnt > 0: | ||
t_spent = time.time() - t_first_msg | ||
print('%d messages (%.2fMb) consumed in %.3fs: %d msgs/s, %.2f Mb/s' % | ||
(msgcnt, bytecnt / (1024*1024), t_spent, msgcnt / t_spent, | ||
(bytecnt / t_spent) / (1024*1024))) | ||
(msgcnt, bytecnt / (1024 * 1024), t_spent, msgcnt / t_spent, | ||
(bytecnt / t_spent) / (1024 * 1024))) | ||
|
||
print('closing consumer') | ||
c.close() | ||
|
@@ -1075,8 +1074,8 @@ def stats_cb(stats_json_str): | |
if msgcnt > 0: | ||
t_spent = time.time() - t_first_msg | ||
print('%d messages (%.2fMb) consumed in %.3fs: %d msgs/s, %.2f Mb/s' % | ||
(msgcnt, bytecnt / (1024*1024), t_spent, msgcnt / t_spent, | ||
(bytecnt / t_spent) / (1024*1024))) | ||
(msgcnt, bytecnt / (1024 * 1024), t_spent, msgcnt / t_spent, | ||
(bytecnt / t_spent) / (1024 * 1024))) | ||
|
||
print('closing consumer') | ||
c.close() | ||
|
@@ -1121,8 +1120,9 @@ def verify_topic_metadata(client, exp_topics): | |
|
||
|
||
def verify_admin(): | ||
""" Verify Admin API """ | ||
|
||
""" Verify Admin API """ | ||
from confluent_kafka import admin | ||
a = admin.AdminClient({'bootstrap.servers': bootstrap_servers}) | ||
our_topic = topic + '_admin_' + str(uuid.uuid4()) | ||
num_partitions = 2 | ||
|
@@ -1216,9 +1216,110 @@ def verify_config(expconfig, configs): | |
print("Topic {} marked for deletion".format(our_topic)) | ||
|
||
|
||
def verify_explicit_read(): | ||
""" verify that the explicit reading schema works""" | ||
from confluent_kafka import avro | ||
avsc_dir = os.path.join(os.path.dirname(__file__), os.pardir, 'tests', 'avro') | ||
|
||
# Producer config | ||
conf = {'bootstrap.servers': bootstrap_servers, | ||
'error_cb': error_cb, | ||
'api.version.request': api_version_request, | ||
'default.topic.config': {'produce.offset.report': True}} | ||
|
||
# Create producer | ||
if schema_registry_url: | ||
conf['schema.registry.url'] = schema_registry_url | ||
p = avro.AvroProducer(conf) | ||
else: | ||
p = avro.AvroProducer(conf, schema_registry=InMemorySchemaRegistry()) | ||
|
||
key_schema = avro.load(os.path.join(avsc_dir, "primitive_float.avsc")) | ||
schema1 = avro.load(os.path.join(avsc_dir, "read_test_schema.avsc")) | ||
schema2 = avro.load(os.path.join(avsc_dir, "incremented_read_test_schema.avsc")) | ||
float_value = 32. | ||
val = { | ||
"name": "abc", | ||
"favorite_number": 42, | ||
"favorite_colo": "orange" | ||
} | ||
val1 = { | ||
"name": "abc" | ||
} | ||
|
||
combinations = [ | ||
dict(value=val, value_schema=schema2, key=float_value, key_schema=key_schema, | ||
read_schema=schema1), | ||
dict(value=val1, value_schema=schema1, key=float_value, key_schema=key_schema, | ||
read_schema=schema2), | ||
] | ||
|
||
# Consumer config | ||
cons_conf = {'bootstrap.servers': bootstrap_servers, | ||
'group.id': 'test.py', | ||
'session.timeout.ms': 6000, | ||
'enable.auto.commit': False, | ||
'api.version.request': api_version_request, | ||
'on_commit': print_commit_result, | ||
'error_cb': error_cb, | ||
'default.topic.config': { | ||
'auto.offset.reset': 'earliest' | ||
}} | ||
|
||
for (i, combo) in enumerate(combinations): | ||
read_schema = combo.pop("read_schema") | ||
combo['topic'] = str(uuid.uuid4()) | ||
p.produce(**combo) | ||
p.poll(0) | ||
p.flush() | ||
|
||
# Create consumer | ||
conf = copy(cons_conf) | ||
if schema_registry_url: | ||
conf['schema.registry.url'] = schema_registry_url | ||
c = avro.AvroConsumer(conf, read_schema=read_schema) | ||
else: | ||
c = avro.AvroConsumer(conf, schema_registry=InMemorySchemaRegistry(), read_schema=read_schema) | ||
c.subscribe([combo['topic']]) | ||
|
||
while True: | ||
msg = c.poll(0) | ||
if msg is None: | ||
continue | ||
|
||
if msg.error(): | ||
if msg.error().code() == confluent_kafka.KafkaError._PARTITION_EOF: | ||
break | ||
else: | ||
continue | ||
|
||
tstype, timestamp = msg.timestamp() | ||
print('%s[%d]@%d: key=%s, value=%s, tstype=%d, timestamp=%s' % | ||
(msg.topic(), msg.partition(), msg.offset(), | ||
msg.key(), msg.value(), tstype, timestamp)) | ||
|
||
# omit empty Avro fields from payload for comparison | ||
record_key = msg.key() | ||
record_value = msg.value() | ||
if isinstance(msg.key(), dict): | ||
record_key = {k: v for k, v in msg.key().items() if v is not None} | ||
|
||
if isinstance(msg.value(), dict): | ||
record_value = {k: v for k, v in msg.value().items() if v is not None} | ||
|
||
assert combo.get('key') == record_key | ||
assert combo.get('value')['name'] == record_value['name'] | ||
c.commit(msg, asynchronous=False) | ||
# Close consumer | ||
c.close() | ||
pass | ||
|
||
|
||
# Exclude throttle since from default list | ||
default_modes = ['consumer', 'producer', 'avro', 'performance', 'admin'] | ||
all_modes = default_modes + ['throttle', 'avro-https', 'none'] | ||
# default_modes = ['consumer', 'producer', 'avro', 'performance', 'admin', 'explicit-read'] | ||
default_modes = ['consumer', 'producer', 'performance', 'explicit-read'] | ||
all_modes = default_modes + ['throttle', 'none'] | ||
|
||
"""All test modes""" | ||
|
||
|
||
|
@@ -1337,6 +1438,10 @@ def resolve_envs(_conf): | |
print('=' * 30, 'Verifying Admin API', '=' * 30) | ||
verify_admin() | ||
|
||
if 'explicit-read' in modes: | ||
print('=' * 30, 'Verifying Explicit Reading Schema', '=' * 30) | ||
verify_explicit_read() | ||
|
||
print('=' * 30, 'Done', '=' * 30) | ||
|
||
if with_pympler: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"type": "record", | ||
"name": "User", | ||
"fields": [ | ||
{"name": "name", "type": "string"}, | ||
{"name": "favorite_number", "type": ["null", "int"], "default": null}, | ||
{"name": "favorite_color", "type": ["null", "string"], "default": null} | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All changes to .travis.yml should be removed from this commit