Make sure we always have connections defined
This commit is contained in:
@@ -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)])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user