diff --git a/pycassa/pool.py b/pycassa/pool.py index 087d55eb..3d1772b3 100644 --- a/pycassa/pool.py +++ b/pycassa/pool.py @@ -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: diff --git a/tests/test_connection_pooling.py b/tests/test_connection_pooling.py index 29dcaa43..e38a8b28 100644 --- a/tests/test_connection_pooling.py +++ b/tests/test_connection_pooling.py @@ -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'} @@ -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,