Skip to content

Commit

Permalink
Add tests for apache#199
Browse files Browse the repository at this point in the history
  • Loading branch information
BewareMyPower committed Mar 14, 2024
1 parent bcb9f2a commit 5f23bd7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
48 changes: 48 additions & 0 deletions tests/consumer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

from unittest import TestCase, main
import time

from pulsar import Client, MessageId

class ConsumerTest(TestCase):

service_url = 'pulsar://localhost:6650'

def test_has_message_available_after_seek(self):
topic = f'test_has_message_available_after_seek-{time.time()}'
client = Client(self.service_url)
producer = client.create_producer(topic)
reader = client.create_reader(topic, start_message_id=MessageId.earliest)

producer.send('msg-0'.encode())
self.assertTrue(reader.has_message_available())

reader.seek(MessageId.latest)
self.assertFalse(reader.has_message_available())

producer.send('msg-1'.encode())
self.assertTrue(reader.has_message_available())

client.close()

if __name__ == "__main__":
main()
12 changes: 8 additions & 4 deletions tests/pulsar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from _pulsar import ProducerConfiguration, ConsumerConfiguration, RegexSubscriptionMode

from schema_test import *
from consumer_test import *

from urllib.request import urlopen, Request

Expand Down Expand Up @@ -1355,17 +1356,20 @@ def test_get_partitioned_topic_name(self):
client.close()

def test_shutdown_client(self):
client = Client(self.serviceUrl)
producer = client.create_producer("persistent://public/default/partitioned_topic_name_test")
client = Client(self.serviceUrl,
logger=pulsar.ConsoleLogger(pulsar.LoggerLevel.Debug))
producer = client.create_producer("persistent://public/default/test_shutdown_client")
producer.send(b"hello")
client.shutdown()

try:
producer.send(b"hello")
self.assertTrue(False)
except pulsar.PulsarException:
except pulsar.PulsarException as e:
print(f'{type(e)} | {e}')
# Expected
pass
time.sleep(1)
print('done')

def test_listener_name_client(self):
client = Client(self.serviceUrl, listener_name='test')
Expand Down

0 comments on commit 5f23bd7

Please sign in to comment.