diff --git a/README.md b/README.md index 3647b6cf230077c0b4c954766d022af257047ed4..2a185806b8f5f2d587273db962b2df2a589e63bf 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,14 @@ Why CoolAMQP? * [Publisher confirms](https://www.rabbitmq.com/docs/confirms#publisher-confirms) * [Negative Acknowledgements](https://www.rabbitmq.com/docs/nack) * traceable using [opentracing](https://opentracing.io/) -* code coverage is 81% at the moment +* high coverage +* tested in production conditions * full support for [streams](https://www.rabbitmq.com/docs/streams) * 120 second stress tests are part of each release -[]() - **Warning!!** Since v1.3.1 development has been moved -from [GitHub](https://github.com/smok-serwis/coolamqp) to this GitLab. +from [GitHub](https://github.com/smok-serwis/coolamqp) to this [GitLab](https://git.dms-serwis.com.pl/smokserwis/coolamqp). To install CoolAMQP please use ```bash @@ -111,7 +110,7 @@ and you're all set. The only files modified is ### [docs](docs/) Sources for the documentation, available -[here](https://coolamqp.readthedocs.io/en/latest/). +[here](http://smokserwis.docs.smok.co/coolamqp). ## Running unit tests @@ -122,7 +121,7 @@ The default username used is guest, and password is guest. You can also run unit tests from Docker, if you wish so. To launch the unit test suite: ```bash -docker-compose up unittest +docker-compose up --build unittest ``` To launch the stress test suite diff --git a/coolamqp/__init__.py b/coolamqp/__init__.py index a33997dd1004d8fb312324a652e27fcab292f4eb..64142ce8c74e812ac648aa05adcd069e1140d64f 100644 --- a/coolamqp/__init__.py +++ b/coolamqp/__init__.py @@ -1 +1 @@ -__version__ = '2.1.0' +__version__ = '2.1.2a1' diff --git a/coolamqp/argumentify.py b/coolamqp/argumentify.py index 4709d573c89ae31d6d20e657205c91b69017f3e3..ed9b622dad7bf4160b0082bebe8c5fb46f488b80 100644 --- a/coolamqp/argumentify.py +++ b/coolamqp/argumentify.py @@ -17,20 +17,13 @@ def tobytes(q): def toutf8(q): if isinstance(q, memoryview): - q = q.tobytes() + q = q.tobytes().decode('utf-8') return q.decode('utf-8') if isinstance(q, six.binary_type) else q def argumentify(arguments): if arguments is None: return [] - # Was it argumented already? - # if isinstance(arguments, list): - # if len(arguments) >= 1: - # if isinstance(arguments[0], tuple): - # if isinstance(arguments[0][1], str) and len(arguments[0][1]) == 1: - # # Looks argumentified already - # return arguments args = [] if isinstance(arguments, dict): for key, value in arguments.items(): @@ -46,6 +39,5 @@ def argumentify(arguments): for value in arguments: args.append((value, get_type_for(value))) return (args, 'A') - else: - warnings.warn('Unnecessary call to argumentify, see issue #11 for details', UserWarning) - return args + warnings.warn('Unnecessary call to argumentify, see issue #11 for details', UserWarning) + return args diff --git a/coolamqp/clustering/cluster.py b/coolamqp/clustering/cluster.py index 1699259ab0f1fec8c79e66dccda91a680b1784ff..6c076612f6cbe7f1fe701d00c497771c1692e5ca 100644 --- a/coolamqp/clustering/cluster.py +++ b/coolamqp/clustering/cluster.py @@ -4,12 +4,11 @@ from __future__ import print_function, absolute_import, division import logging import time import typing as tp -import warnings from concurrent.futures import Future import six -from coolamqp.argumentify import argumentify +from coolamqp.argumentify import argumentify, tobytes from coolamqp.attaches import Publisher, AttacheGroup, Consumer, Declarer from coolamqp.attaches.utils import close_future from coolamqp.clustering.events import ConnectionLost, MessageReceived, \ @@ -55,7 +54,8 @@ class Cluster(object): :type nodes: NodeDefinition :param on_fail: callable/0 to call when connection fails in an unclean way. This is a one-shot - :param extra_properties: refer to :class:`coolamqp.uplink.connection.Connection` + :param extra_properties: refer to :class:`coolamqp.uplink.connection.Connection`, or just pass a dictionary + of anything you'd like :param log_frames: an object that supports logging each and every frame CoolAMQP sends and receives from the broker :type log_frames: tp.Optional[:class:`coolamqp.tracing.BaseFrameTracer`] @@ -77,6 +77,12 @@ class Cluster(object): except ImportError: raise RuntimeError('tracer given, but opentracing is not installed!') + if isinstance(extra_properties, dict): + extra_props = [] + for key, value in extra_props.items(): + extra_props.append((tobytes(key), argumentify(value))) + extra_properties = extra_props + self.started = False # type: bool self.tracer = tracer self.name = name or 'CoolAMQP' # type: str diff --git a/tests/test_clustering/test_streams.py b/tests/test_clustering/test_streams.py index 871dc22bb1a368dbcf310fb6cc07bee60f9a27eb..df000df10622edc465a8dc58e576834041767351 100644 --- a/tests/test_clustering/test_streams.py +++ b/tests/test_clustering/test_streams.py @@ -43,9 +43,9 @@ class TestStreams(unittest.TestCase): fut.result() time.sleep(3) cons.cancel().result() - self.assertEqual(test['a'], 6) + self.assertGreaterEqual(test['a'], 6) # might have some messages from previous runs cons, fut = c.consume(stream, qos=10, on_message=handle_msg, arguments={'x-stream-offset': 'first'}, no_ack=False) fut.result() time.sleep(3) cons.cancel() - self.assertEqual(test['a'], 16) + self.assertGreaterEqual(test['a'], 16) # might have some messages from previous runs diff --git a/tests/test_clustering/test_things.py b/tests/test_clustering/test_things.py index dee2bafe64df486159702c76a9771206ad01e830..c64d7ec0e65087ae014f1a39f22b1aaca4e142e7 100644 --- a/tests/test_clustering/test_things.py +++ b/tests/test_clustering/test_things.py @@ -18,6 +18,11 @@ logging.getLogger('coolamqp').setLevel(logging.DEBUG) class TestConnecting(unittest.TestCase): + def test_dict_extra_args(self): + c = Cluster([NODE], extra_properties={'test': 'something'}) + c.start(wait=True, timeout=None) + c.shutdown(True) + def test_argumented_exchange(self): xchg = Exchange('test-wer', durable=True) c = Cluster([NODE]) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 08f81a9834a6ed1b3f5941e7d875ebdd583c2ade..f9bddde027446ea9041070ab31889e4c573b8823 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -3,10 +3,15 @@ from __future__ import print_function, absolute_import, division import unittest +from coolamqp.argumentify import toutf8 from coolamqp.exceptions import AMQPError class TestExcs(unittest.TestCase): + + def test_utf8(self): + self.assertEqual(toutf8(memoryview(b'test')), 'test') + def test_exist(self): e = AMQPError(100, u'wtf', 0, 0) diff --git a/tests/test_objects.py b/tests/test_objects.py index 19f12ca2e105f7a08f48833cad6849ecf625ac35..7127d87baeea4ed72dfc09c66c1328405c27b8da 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -25,6 +25,10 @@ class TestObjects(unittest.TestCase): self.assertRaises(ValueError, Queue, None, auto_delete=False) self.assertRaises(ValueError, Queue, 'test', auto_delete=True, exclusive=False) + def test_queue_repr(self): + q = Queue('test') + repr(q) + @unittest.skipUnless(sys.version.startswith('3'), 'Needs Python 3.x') def test_queue_warns(self): warnings.resetwarnings()