-
Notifications
You must be signed in to change notification settings - Fork 47
[Enhancement/Feature Issue #47] Added support for KeySharedPolicy for the consumer when in KeyShared mode. #109
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
Changes from all commits
3e2f6aa
bec4cce
a7e99b5
5027f1c
0d048d6
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 |
---|---|---|
|
@@ -17,3 +17,9 @@ wheelhouse | |
vcpkg_installed/ | ||
*.pyd | ||
*.lib | ||
|
||
|
||
lib_pulsar.so | ||
tests/test.log | ||
.tests-container-id.txt | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -32,6 +32,8 @@ | |||||||
MessageId, | ||||||||
CompressionType, | ||||||||
ConsumerType, | ||||||||
KeySharedMode, | ||||||||
ConsumerKeySharedPolicy, | ||||||||
PartitionsRoutingMode, | ||||||||
AuthenticationBasic, | ||||||||
AuthenticationTLS, | ||||||||
|
@@ -1437,6 +1439,134 @@ def send_callback(res, msg): | |||||||
producer.flush() | ||||||||
client.close() | ||||||||
|
||||||||
def test_keyshare_policy(self): | ||||||||
with self.assertRaises(ValueError): | ||||||||
# Raise error because sticky ranges are not provided. | ||||||||
pulsar.ConsumerKeySharedPolicy( | ||||||||
key_shared_mode=pulsar.KeySharedMode.Sticky, | ||||||||
allow_out_of_order_delivery=False, | ||||||||
) | ||||||||
|
||||||||
expected_key_shared_mode = pulsar.KeySharedMode.Sticky | ||||||||
expected_allow_out_of_order_delivery = True | ||||||||
expected_sticky_ranges = [(0, 100), (101,200)] | ||||||||
consumer_key_shared_policy = pulsar.ConsumerKeySharedPolicy( | ||||||||
key_shared_mode=expected_key_shared_mode, | ||||||||
allow_out_of_order_delivery=expected_allow_out_of_order_delivery, | ||||||||
sticky_ranges=expected_sticky_ranges | ||||||||
) | ||||||||
|
||||||||
self.assertEqual(consumer_key_shared_policy.key_shared_mode, expected_key_shared_mode) | ||||||||
self.assertEqual(consumer_key_shared_policy.allow_out_of_order_delivery, expected_allow_out_of_order_delivery) | ||||||||
self.assertEqual(consumer_key_shared_policy.sticky_ranges, expected_sticky_ranges) | ||||||||
|
||||||||
def test_keyshared_invalid_sticky_ranges(self): | ||||||||
client = Client(self.serviceUrl) | ||||||||
topic = "my-python-topic-keyshare-invalid-" + str(time.time()) | ||||||||
with self.assertRaises(ValueError): | ||||||||
consumer_key_shared_policy = pulsar.ConsumerKeySharedPolicy( | ||||||||
key_shared_mode=pulsar.KeySharedMode.Sticky, | ||||||||
allow_out_of_order_delivery=False, | ||||||||
sticky_ranges=[(0,65536)] | ||||||||
) | ||||||||
client.subscribe(topic, "my-sub", consumer_type=ConsumerType.KeyShared, | ||||||||
start_message_id_inclusive=True, | ||||||||
key_shared_policy=consumer_key_shared_policy) | ||||||||
|
||||||||
with self.assertRaises(ValueError): | ||||||||
consumer_key_shared_policy = pulsar.ConsumerKeySharedPolicy( | ||||||||
key_shared_mode=pulsar.KeySharedMode.Sticky, | ||||||||
allow_out_of_order_delivery=False, | ||||||||
sticky_ranges=[(0, 100), (50, 150)] | ||||||||
) | ||||||||
client.subscribe(topic, "my-sub", consumer_type=ConsumerType.KeyShared, | ||||||||
start_message_id_inclusive=True, | ||||||||
key_shared_policy=consumer_key_shared_policy) | ||||||||
|
||||||||
def test_keyshared_autosplit(self): | ||||||||
client = Client(self.serviceUrl) | ||||||||
topic = "my-python-topic-keyshare-autosplit-" + str(time.time()) | ||||||||
consumer_key_shared_policy = pulsar.ConsumerKeySharedPolicy( | ||||||||
key_shared_mode=pulsar.KeySharedMode.AutoSplit, | ||||||||
allow_out_of_order_delivery=True, | ||||||||
) | ||||||||
consumer = client.subscribe(topic, "my-sub", consumer_type=ConsumerType.KeyShared, consumer_name = 'con-1', | ||||||||
start_message_id_inclusive=True, key_shared_policy=consumer_key_shared_policy) | ||||||||
consumer2 = client.subscribe(topic, "my-sub", consumer_type=ConsumerType.KeyShared, consumer_name = 'con-2', | ||||||||
start_message_id_inclusive=True, key_shared_policy=consumer_key_shared_policy) | ||||||||
producer = client.create_producer(topic) | ||||||||
|
||||||||
for i in range(10): | ||||||||
if i > 0: | ||||||||
time.sleep(0.02) | ||||||||
Comment on lines
+1500
to
+1501
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. Why do we need to sleep 2 milliseconds before each send? 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. I added the sleep to keep in line with the other tests. You can see them here pulsar-client-python/tests/pulsar_test.py Line 861 in 39ac8f8
pulsar-client-python/tests/pulsar_test.py Line 931 in 39ac8f8
pulsar-client-python/tests/pulsar_test.py Line 1077 in 39ac8f8
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. I will leave the sleeps in for now assuming there is a reason for them in the other tests. But if that is not the case then I can remove them. 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. Oh I see. Most of the other |
||||||||
producer.send(b"hello-%d" % i) | ||||||||
|
||||||||
msgs = [] | ||||||||
while True: | ||||||||
try: | ||||||||
msg = consumer.receive(100) | ||||||||
except pulsar.Timeout: | ||||||||
break | ||||||||
msgs.append(msg) | ||||||||
consumer.acknowledge(msg) | ||||||||
|
||||||||
while True: | ||||||||
try: | ||||||||
msg = consumer2.receive(100) | ||||||||
except pulsar.Timeout: | ||||||||
break | ||||||||
msgs.append(msg) | ||||||||
consumer2.acknowledge(msg) | ||||||||
|
||||||||
self.assertEqual(len(msgs), 10) | ||||||||
client.close() | ||||||||
|
||||||||
def test_sticky_autosplit(self): | ||||||||
client = Client(self.serviceUrl) | ||||||||
topic = "my-python-topic-keyshare-sticky-" + str(time.time()) | ||||||||
consumer_key_shared_policy = pulsar.ConsumerKeySharedPolicy( | ||||||||
key_shared_mode=pulsar.KeySharedMode.Sticky, | ||||||||
allow_out_of_order_delivery=True, | ||||||||
sticky_ranges=[(0,30000)], | ||||||||
) | ||||||||
|
||||||||
consumer = client.subscribe(topic, "my-sub", consumer_type=ConsumerType.KeyShared, consumer_name='con-1', | ||||||||
start_message_id_inclusive=True, key_shared_policy=consumer_key_shared_policy) | ||||||||
|
||||||||
consumer2_key_shared_policy = pulsar.ConsumerKeySharedPolicy( | ||||||||
key_shared_mode=pulsar.KeySharedMode.Sticky, | ||||||||
allow_out_of_order_delivery=True, | ||||||||
sticky_ranges=[(30001, 65535)], | ||||||||
) | ||||||||
consumer2 = client.subscribe(topic, "my-sub", consumer_type=ConsumerType.KeyShared, consumer_name='con-2', | ||||||||
start_message_id_inclusive=True, key_shared_policy=consumer2_key_shared_policy) | ||||||||
producer = client.create_producer(topic) | ||||||||
|
||||||||
for i in range(10): | ||||||||
if i > 0: | ||||||||
time.sleep(0.02) | ||||||||
hyperevo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
producer.send(b"hello-%d" % i) | ||||||||
|
||||||||
msgs = [] | ||||||||
while True: | ||||||||
try: | ||||||||
msg = consumer.receive(100) | ||||||||
except pulsar.Timeout: | ||||||||
break | ||||||||
msgs.append(msg) | ||||||||
consumer.acknowledge(msg) | ||||||||
|
||||||||
while True: | ||||||||
try: | ||||||||
msg = consumer2.receive(100) | ||||||||
except pulsar.Timeout: | ||||||||
break | ||||||||
msgs.append(msg) | ||||||||
consumer2.acknowledge(msg) | ||||||||
|
||||||||
self.assertEqual(len(msgs), 10) | ||||||||
client.close() | ||||||||
|
||||||||
def test_acknowledge_failed(self): | ||||||||
client = Client(self.serviceUrl) | ||||||||
topic = 'test_acknowledge_failed' | ||||||||
|
@@ -1461,5 +1591,6 @@ def test_acknowledge_failed(self): | |||||||
client.close() | ||||||||
|
||||||||
|
||||||||
|
||||||||
if __name__ == "__main__": | ||||||||
main() |
Uh oh!
There was an error while loading. Please reload this page.