Piotr Kliczewski has uploaded a new change for review.
Change subject: tests: AsyncClient test suite ......................................................................
tests: AsyncClient test suite
Change-Id: Ie102948c2bb7ff964586701b9b81b2867f7ba840 Signed-off-by: pkliczewski piotr.kliczewski@gmail.com --- M lib/yajsonrpc/stomp.py M tests/Makefile.am A tests/stompAsyncClientTests.py 3 files changed, 137 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/93/43393/1
diff --git a/lib/yajsonrpc/stomp.py b/lib/yajsonrpc/stomp.py index 7436984..a02a06f 100644 --- a/lib/yajsonrpc/stomp.py +++ b/lib/yajsonrpc/stomp.py @@ -525,8 +525,13 @@ return sub
def unsubscribe(self, sub): - self.queue_frame(Frame(Command.UNSUBSCRIBE, - {"id": sub.id})) + try: + del self._subscriptions[sub.id] + except KeyError: + self.log.warning('No subscription with %s id', sub.id) + else: + self.queue_frame(Frame(Command.UNSUBSCRIBE, + {"id": sub.id}))
class _Subscription(object): diff --git a/tests/Makefile.am b/tests/Makefile.am index eff79f5..4d42b55 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -95,6 +95,7 @@ sslhelper.py \ sslTests.py \ stompAdapterTests.py \ + stompAsyncClientTests.py \ storageMailboxTests.py \ storageMonitorTests.py \ storageServerTests.py \ diff --git a/tests/stompAsyncClientTests.py b/tests/stompAsyncClientTests.py new file mode 100644 index 0000000..4ffc327 --- /dev/null +++ b/tests/stompAsyncClientTests.py @@ -0,0 +1,129 @@ +# +# Copyright 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# +from uuid import uuid4 + +from testlib import VdsmTestCase as TestCaseBase +from yajsonrpc.stomp import AsyncClient, Command, Frame, Headers, StompError +from stompAdapterTests import TestSubscription + + +class AsyncClientTest(TestCaseBase): + + def test_connect(self): + client = AsyncClient() + client.handle_connect() + + req_frame = client.pop_message() + + self.assertEquals(req_frame.command, Command.CONNECT) + self.assertEquals(req_frame.headers[Headers.ACCEPT_VERSION], '1.2') + self.assertEquals(req_frame.headers[Headers.HEARTEBEAT], '0,5000') + + def test_subscribe(self): + client = AsyncClient() + + id = str(uuid4()) + client.subscribe(destination='jms.queue.events', ack='client', + sub_id=id) + + req_frame = client.pop_message() + self.assertTrue(len(client._subscriptions) == 1) + self.assertEquals(req_frame.command, Command.SUBSCRIBE) + self.assertEquals(req_frame.headers['destination'], 'jms.queue.events') + self.assertEquals(req_frame.headers['id'], id) + self.assertEquals(req_frame.headers['ack'], 'client') + + def test_manage_subscription(self): + client = AsyncClient() + + subscription = client.subscribe(destination='jms.queue.events', + ack='client', + sub_id=str(uuid4())) + client.unsubscribe(subscription) + self.assertTrue(len(client._subscriptions) == 0) + + def test_unsubscribe_with_different_id(self): + client = AsyncClient() + + client.subscribe(destination='jms.queue.events', + ack='client-individual', + sub_id=str(uuid4())) + # ignore subscribe frame + client.pop_message() + + client.unsubscribe(TestSubscription('jms.queue.events', + 'ad052acb-a934-4e10-8ec3')) + + self.assertTrue(len(client._subscriptions) == 1) + self.assertFalse(client.has_outgoing_messages) + + def test_send(self): + client = AsyncClient() + data = ('{"jsonrpc":"2.0","method":"Host.getAllVmStats","params":{},' + '"id":"e8a936a6-d886-4cfa-97b9-2d54209053ff"}') + headers = {Headers.REPLY_TO: 'jms.topic.vdsm_responses', + Headers.CONTENT_LENGTH: '103'} + client.send('jms.topic.vdsm_requests', data, headers) + + req_frame = client.pop_message() + self.assertEquals(req_frame.command, Command.SEND) + self.assertEquals(req_frame.headers['destination'], + 'jms.topic.vdsm_requests') + self.assertEquals(req_frame.headers[Headers.REPLY_TO], + 'jms.topic.vdsm_responses') + self.assertEquals(req_frame.body, data) + + def test_receive_connected(self): + client = AsyncClient() + frame = Frame(Command.CONNECTED, + {'version': '1.2', Headers.HEARTEBEAT: '8000,0'}) + + client.handle_frame(None, frame) + + self.assertTrue(client.connected) + + def test_receive_message(self): + client = AsyncClient() + id = 'ad052acb-a934-4e10-8ec3-00c7417ef8d1' + headers = {Headers.CONTENT_LENGTH: '78', + Headers.DESTINATION: 'jms.topic.vdsm_responses', + Headers.CONTENT_TYPE: 'application/json', + Headers.SUBSCRIPTION: id} + body = ('{"jsonrpc": "2.0", "id": "e8a936a6-d886-4cfa-97b9-2d54209053f' + 'f", "result": []}') + frame = Frame(command=Command.MESSAGE, headers=headers, body=body) + + def message_handler(sub, frame): + client.queue_frame(frame) + + client.subscribe('', 'auto', id, message_handler) + # ignore subscribe frame + client.pop_message() + + client.handle_frame(None, frame) + + self.assertEquals(frame, client.pop_message()) + + def test_receive_error(self): + client = AsyncClient() + frame = Frame(command=Command.ERROR, body='Test error') + + with self.assertRaises(StompError): + client.handle_frame(None, frame)
automation@ovirt.org has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Piotr Kliczewski has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 1: Verified+1
Verified by running local build.
automation@ovirt.org has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 2:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Piotr Kliczewski has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 2: Verified+1
Rebase only, no code changes. Copying verification flag from previous patch set.
Yaniv Bronhaim has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 2: Code-Review-1
(1 comment)
https://gerrit.ovirt.org/#/c/43393/2/lib/yajsonrpc/stomp.py File lib/yajsonrpc/stomp.py:
Line 530: except KeyError: Line 531: self.log.warning('No subscription with %s id', sub.id) Line 532: else: Line 533: self.queue_frame(Frame(Command.UNSUBSCRIBE, Line 534: {"id": sub.id})) this is bug fix .. its not related to the patch Line 535: Line 536: Line 537: class _Subscription(object): Line 538:
Piotr Kliczewski has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 2:
(1 comment)
https://gerrit.ovirt.org/#/c/43393/2/lib/yajsonrpc/stomp.py File lib/yajsonrpc/stomp.py:
Line 530: except KeyError: Line 531: self.log.warning('No subscription with %s id', sub.id) Line 532: else: Line 533: self.queue_frame(Frame(Command.UNSUBSCRIBE, Line 534: {"id": sub.id}))
this is bug fix .. its not related to the patch
Will split it to separate patch. Line 535: Line 536: Line 537: class _Subscription(object): Line 538:
automation@ovirt.org has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 3:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Piotr Kliczewski has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 3: Verified+1
Verified by running local build.
automation@ovirt.org has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 4:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Piotr Kliczewski has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 4: Verified+1
Verified by running vdsm build
automation@ovirt.org has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 5:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Piotr Kliczewski has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 5: Verified+1
Rebased only.
Yaniv Bronhaim has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 5: Code-Review+1
Dan Kenigsberg has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 5: Code-Review+2
Dan Kenigsberg has submitted this change and it was merged.
Change subject: tests: AsyncClient test suite ......................................................................
tests: AsyncClient test suite
Change-Id: Ie102948c2bb7ff964586701b9b81b2867f7ba840 Signed-off-by: pkliczewski piotr.kliczewski@gmail.com Reviewed-on: https://gerrit.ovirt.org/43393 Continuous-Integration: Jenkins CI Reviewed-by: Yaniv Bronhaim Reviewed-by: Dan Kenigsberg danken@redhat.com --- M tests/Makefile.am A tests/stompAsyncClientTests.py 2 files changed, 130 insertions(+), 0 deletions(-)
Approvals: Yaniv Bronhaim: Looks good to me, but someone else must approve Piotr Kliczewski: Verified Jenkins CI: Passed CI tests Dan Kenigsberg: Looks good to me, approved
automation@ovirt.org has posted comments on this change.
Change subject: tests: AsyncClient test suite ......................................................................
Patch Set 6:
* Update tracker::IGNORE, no Bug-Url found * Set MODIFIED::IGNORE, no Bug-Url found.
vdsm-patches@lists.fedorahosted.org