Skip to content

Commit

Permalink
raise AllServersUnavailable exception if server list is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander Piotrowski committed Mar 9, 2012
1 parent ef6eff5 commit 9ec8fd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pycassa/pool.py
Expand Up @@ -383,6 +383,8 @@ def _get_next_server(self):
def _create_connection(self):
"""Creates a ConnectionWrapper, which opens a
pycassa.connection.Connection."""
if not self.server_list:
raise AllServersUnavailable('Cannot connect to any servers as server list is empty!')
failure_count = 0
while failure_count < 2 * len(self.server_list):
try:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_connection_pooling.py
Expand Up @@ -4,7 +4,7 @@

from nose.tools import assert_raises, assert_equal
from pycassa import ColumnFamily, ConnectionPool, PoolListener, InvalidRequestError,\
NoConnectionAvailable, MaximumRetryException
NoConnectionAvailable, MaximumRetryException, AllServersUnavailable

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

Expand All @@ -25,6 +25,9 @@ def test_basic_pools(self):
cf.insert('key1', {'col':'val'})
pool.dispose()

def test_empty_list(self):
assert_raises(AllServersUnavailable, ConnectionPool, 'PycassaTestKeyspace', server_list=[])

def test_server_list_func(self):
listener = _TestListener()
pool = ConnectionPool('PycassaTestKeyspace', server_list=_get_list,
Expand Down

0 comments on commit 9ec8fd5

Please sign in to comment.