-
Notifications
You must be signed in to change notification settings - Fork 387
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
feat(recipe): add support for curator SharedCount recipe #559
Conversation
this patch allows java clients using curator's SharedCount recipe and python clients using kazoo's Counter recipe to read and write from the same path without receiving type errors. example use: counter = zk.Counter("/curator", support_curator_shared_count=True) counter += 2 counter -= 1 counter.value == 1 counter.pre_value == 2 counter.post_value == 1 Closes python-zk#558
kazoo/tests/test_counter.py
Outdated
@@ -33,6 +49,8 @@ def test_errors(self): | |||
counter = self._makeOne() | |||
self.assertRaises(TypeError, counter.__add__, 2.1) | |||
self.assertRaises(TypeError, counter.__add__, b"a") | |||
with self.assertRaises(TypeError): | |||
counter = self._makeOne(default=0.0, support_curator_shared_count=True) |
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.
line too long (83 > 79 characters)
kazoo/tests/test_counter.py
Outdated
counter - 1 | ||
eq_(counter.value, -1) | ||
counter += 1 | ||
counter += 2147483647 |
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.
trailing whitespace
kazoo/recipe/counter.py
Outdated
self._ensured_path = False | ||
self.pre_value = None | ||
self.post_value = None | ||
if self.support_curator_shared_count and not isinstance(self.default, int): | ||
raise TypeError('when support_curator_shared_count is enabled the default type must be an int') |
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.
line too long (107 > 79 characters)
kazoo/recipe/counter.py
Outdated
self._ensured_path = False | ||
self.pre_value = None | ||
self.post_value = None | ||
if self.support_curator_shared_count and not isinstance(self.default, int): |
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.
line too long (83 > 79 characters)
kazoo/recipe/counter.py
Outdated
"""Create a Kazoo Counter | ||
|
||
:param client: A :class:`~kazoo.client.KazooClient` instance. | ||
:param path: The counter path to use. | ||
:param default: The default value. | ||
:param default: The default value to use for new counter paths. | ||
:param support_curator_shared_count: Enable if support for curator's SharedCount recipe is desired. |
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.
line too long (107 > 79 characters)
kazoo/recipe/counter.py
Outdated
either kazoo's counter recipe or curator's SharedCount recipe, you will | ||
need to enable the support_curator_shared_count flag. This flag limits | ||
support to integers only and does not use ascii encoding as described | ||
above. |
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.
trailing whitespace
kazoo/recipe/counter.py
Outdated
If you would like to support clients updating the same znode path using | ||
either kazoo's counter recipe or curator's SharedCount recipe, you will | ||
need to enable the support_curator_shared_count flag. This flag limits | ||
support to integers only and does not use ascii encoding as described |
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.
trailing whitespace
kazoo/recipe/counter.py
Outdated
@@ -19,6 +19,12 @@ class Counter(object): | |||
`type(counter.default)(value)` both using an ascii encoding. As | |||
such other data types might be used for the counter value. | |||
|
|||
If you would like to support clients updating the same znode path using | |||
either kazoo's counter recipe or curator's SharedCount recipe, you will | |||
need to enable the support_curator_shared_count flag. This flag limits |
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.
trailing whitespace
kazoo/recipe/counter.py
Outdated
@@ -19,6 +19,12 @@ class Counter(object): | |||
`type(counter.default)(value)` both using an ascii encoding. As | |||
such other data types might be used for the counter value. | |||
|
|||
If you would like to support clients updating the same znode path using | |||
either kazoo's counter recipe or curator's SharedCount recipe, you will |
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.
trailing whitespace
kazoo/recipe/counter.py
Outdated
@@ -19,6 +19,12 @@ class Counter(object): | |||
`type(counter.default)(value)` both using an ascii encoding. As | |||
such other data types might be used for the counter value. | |||
|
|||
If you would like to support clients updating the same znode path using |
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.
trailing whitespace
kazoo/recipe/counter.py
Outdated
"""Create a Kazoo Counter | ||
|
||
:param client: A :class:`~kazoo.client.KazooClient` instance. | ||
:param path: The counter path to use. | ||
:param default: The default value. | ||
:param default: The default value to use for new counter paths. | ||
:param support_curator: Enable if support for curator's SharedCount |
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.
trailing whitespace
Hi @BrianEaton1, Thanks a lot for your time to produce this PR. I will review it as soon as possible. |
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.
Thanks for this PR!
this patch allows java clients using curator's SharedCount recipe
and python clients using kazoo's Counter recipe to read and
write from the same path without receiving type errors.
example use:
counter = zk.Counter("/curator", support_curator=True)
counter += 2
counter -= 1
counter.value == 1
counter.pre_value == 2
counter.post_value == 1
Closes #558