diff --git a/elasticsearch/connection_pool.py b/elasticsearch/connection_pool.py index 13d545e3..a36a820c 100644 --- a/elasticsearch/connection_pool.py +++ b/elasticsearch/connection_pool.py @@ -7,6 +7,8 @@ try: except ImportError: from queue import PriorityQueue, Empty +from .exceptions import ImproperlyConfigured + logger = logging.getLogger('elasticsearch') class ConnectionSelector(object): @@ -100,6 +102,9 @@ class ConnectionPool(object): :arg randomize_hosts: shuffle the list of connections upon arrival to avoid dog piling effect across processes """ + if not connections: + raise ImproperlyConfigured("No defined connections, you need to \ + specify at least one host.") self.connection_opts = connections self.connections = [c for (c, opts) in connections] # PriorityQueue for thread safety and ease of timeout management diff --git a/test_elasticsearch/test_connection_pool.py b/test_elasticsearch/test_connection_pool.py index e67a7d87..13b316a5 100644 --- a/test_elasticsearch/test_connection_pool.py +++ b/test_elasticsearch/test_connection_pool.py @@ -1,10 +1,14 @@ import time from elasticsearch.connection_pool import ConnectionPool, RoundRobinSelector +from elasticsearch.exceptions import ImproperlyConfigured from .test_cases import TestCase class TestConnectionPool(TestCase): + def test_raises_exception_when_no_connections_defined(self): + self.assertRaises(ImproperlyConfigured, ConnectionPool, []) + def test_default_round_robin(self): pool = ConnectionPool([(x, {}) for x in range(100)])