-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Added a test for MemoryRecordsBuilder and fixed some problems there #1448
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from kafka.record.memory_records import MemoryRecords | ||
from kafka.record.memory_records import MemoryRecords, MemoryRecordsBuilder | ||
|
||
__all__ = ["MemoryRecords"] | ||
__all__ = ["MemoryRecords", "MemoryRecordsBuilder"] | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,7 +135,7 @@ def append(self, timestamp, key, value, headers=[]): | |
(int, int): checksum and bytes written | ||
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. Return type in docstring is incorrect. |
||
""" | ||
if self._closed: | ||
return None, 0 | ||
return None | ||
|
||
offset = self._next_offset | ||
metadata = self._builder.append(offset, timestamp, key, value, headers) | ||
|
@@ -166,7 +166,7 @@ def size_in_bytes(self): | |
|
||
def compression_rate(self): | ||
assert self._closed | ||
return self.size_in_bytes() / self._bytes_written | ||
return self.size_in_bytes() / float(self._bytes_written) | ||
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. This is only required for python2; python3 division returns a float by default. I think a cleaner way to handle this compatibility is with
With that you shouldn't need to cast to float |
||
|
||
def is_full(self): | ||
if self._closed: | ||
|
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.
I'm not very familiar with this code, but I don't understand why this import is needed? Reading the bug description, it looks like the problems were all due to the code fixed in
kafka/record/memory_records.py
below... If the import were just forgotten, I would have thought it would have thrown problems before?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.
No particular reason, just used in tests. We can remove it, yea
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.
I'm fine leaving it in if you think it should be there, I just didn't understand if there was something I was missing.