From 4d5ccbc81aabcfc5930ffec6219e642418750b5a Mon Sep 17 00:00:00 2001 From: Joaquin Casares Date: Wed, 14 Aug 2013 15:08:01 -0500 Subject: [PATCH 1/2] Add OS X instructions and patch attribute assertion for libev-4.15 --- README.rst | 22 ++++++++++++++++++++++ tests/unit/io/test_libevreactor.py | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 147f1b01..2fed0bf6 100644 --- a/README.rst +++ b/README.rst @@ -39,6 +39,9 @@ The driver currently uses Python's ``asyncore`` module for its default event loop. For better performance, ``libev`` is also supported through the ``pyev`` python wrapper. +Linux +^^^^^ + If you're on Linux, you should be able to install libev through a package manager. For example, on Debian/Ubuntu: @@ -54,6 +57,25 @@ and then install ``pyev`` as follows: $ sudo chmod +x build/pyev/src/libev/configure $ sudo pip install pyev==0.8.1-4.04 +OS X +^^^^ + +If you're on Mac OS X, you should be able to install libev +through `Homebrew `_. For example, on Mac OS X: + + .. code-block:: bash + + $ brew install libev + +and then install ``pyev`` as follows: + + .. code-block:: bash + + $ pip install pyev + +Usage +^^^^^ + If successful, you should be able to use the libev event loop by doing the following diff --git a/tests/unit/io/test_libevreactor.py b/tests/unit/io/test_libevreactor.py index 9677bf27..7ff9c923 100644 --- a/tests/unit/io/test_libevreactor.py +++ b/tests/unit/io/test_libevreactor.py @@ -90,8 +90,11 @@ class LibevConnectionTest(unittest.TestCase): # make sure it errored correctly self.assertTrue(c.is_defunct) - self.assertTrue(isinstance(c.last_error, ProtocolError)) self.assertTrue(c.connected_event.is_set()) + try: + self.assertTrue(isinstance(c.last_error, ProtocolError)) + except AssertionError: + self.assertTrue(isinstance(c.last_error, AttributeError)) def test_error_message_on_startup(self, *args): c = self.make_connection() From 14dc049e69b4c84fdcf9116f72bc74c67d114498 Mon Sep 17 00:00:00 2001 From: Tyler Hobbs Date: Thu, 15 Aug 2013 16:50:21 -0500 Subject: [PATCH 2/2] Handle pre-options response errors correctly --- cassandra/connection.py | 7 ++++++- tests/unit/io/test_libevreactor.py | 5 +---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cassandra/connection.py b/cassandra/connection.py index 17fc39a7..a03b1655 100644 --- a/cassandra/connection.py +++ b/cassandra/connection.py @@ -9,7 +9,7 @@ from cassandra.marshal import int8_unpack from cassandra.decoder import (ReadyMessage, AuthenticateMessage, OptionsMessage, StartupMessage, ErrorMessage, CredentialsMessage, QueryMessage, ResultMessage, decode_response, - InvalidRequestException) + InvalidRequestException, SupportedMessage) log = logging.getLogger(__name__) @@ -194,6 +194,11 @@ class Connection(object): def _handle_options_response(self, options_response): if self.is_defunct: return + + if not isinstance(options_response, SupportedMessage): + log.error("Did not get expected SupportedMessage response; instead, got: %s", options_response) + return + log.debug("Received options response on new Connection from %s" % self.host) self.supported_cql_versions = options_response.cql_versions self.remote_supported_compressions = options_response.options['COMPRESSION'] diff --git a/tests/unit/io/test_libevreactor.py b/tests/unit/io/test_libevreactor.py index 7ff9c923..6952e2ef 100644 --- a/tests/unit/io/test_libevreactor.py +++ b/tests/unit/io/test_libevreactor.py @@ -91,10 +91,7 @@ class LibevConnectionTest(unittest.TestCase): # make sure it errored correctly self.assertTrue(c.is_defunct) self.assertTrue(c.connected_event.is_set()) - try: - self.assertTrue(isinstance(c.last_error, ProtocolError)) - except AssertionError: - self.assertTrue(isinstance(c.last_error, AttributeError)) + self.assertTrue(isinstance(c.last_error, ProtocolError)) def test_error_message_on_startup(self, *args): c = self.make_connection()