Make sure we always have connections defined

This commit is contained in:
Honza Král
2014-12-08 14:32:52 +01:00
parent fe556873d8
commit 0f0630d8d7
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -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
@@ -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)])