Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #164 from hannosch/c11-exception-changes
Browse files Browse the repository at this point in the history
C11 exception base class changes vs. pool retry
  • Loading branch information
thobbs committed Jul 23, 2012
2 parents 1adde9c + 00cd392 commit ca12fca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pycassa/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import Queue

from thrift import Thrift
from thrift.transport.TTransport import TTransportException
from connection import Connection
from logging.pool_logger import PoolLogger
from util import as_interface
Expand Down Expand Up @@ -128,7 +129,8 @@ def new_f(self, *args, **kwargs):
self._pool._decrement_overflow()
self._pool._clear_current()
raise app_exc
except (TimedOutException, UnavailableException, Thrift.TException,
except (TimedOutException, UnavailableException,
TTransportException,
socket.error, IOError, EOFError), exc:
self._pool._notify_on_failure(exc, server=self.server, connection=self)

Expand Down Expand Up @@ -400,7 +402,7 @@ def _create_connection(self):
server = self._get_next_server()
wrapper = self._get_new_wrapper(server)
return wrapper
except (Thrift.TException, socket.error, IOError, EOFError), exc:
except (TTransportException, socket.error, IOError, EOFError), exc:
self._notify_on_failure(exc, server)
failure_count += 1
raise AllServersUnavailable('An attempt was made to connect to each of the servers ' +
Expand Down
18 changes: 18 additions & 0 deletions tests/test_connection_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from pycassa import ColumnFamily, ConnectionPool, PoolListener, InvalidRequestError,\
NoConnectionAvailable, MaximumRetryException, AllServersUnavailable
from pycassa.cassandra.ttypes import ColumnPath
from pycassa.cassandra.ttypes import InvalidRequestException
from pycassa.cassandra.ttypes import NotFoundException


_credentials = {'username':'jsmith', 'password':'havebadpass'}

Expand Down Expand Up @@ -486,6 +489,21 @@ def test_failure_connection_info(self):
assert_equal(request['args'], ('greunt', ColumnPath('Counter1', None, 'col'), 1))
assert_equal(request['kwargs'], {})

def test_pool_invalid_request(self):
listener = _TestListener()
pool = ConnectionPool(pool_size=1, max_overflow=0, recycle=10000,
prefill=True, max_retries=3,
keyspace='PycassaTestKeyspace',
credentials=_credentials,
listeners=[listener], use_threadlocal=False,
server_list=['localhost:9160'])
cf = ColumnFamily(pool, 'Standard1')
# Make sure the pool doesn't hide and retries invalid requests
assert_raises(InvalidRequestException, cf.add, 'key', 'col')
assert_raises(NotFoundException, cf.get, 'none')
pool.dispose()


class _TestListener(PoolListener):

def __init__(self):
Expand Down

0 comments on commit ca12fca

Please sign in to comment.