Skip to content
This repository has been archived by the owner on Nov 7, 2021. It is now read-only.

Allow inject connector from ElasticSearch till Connection #138

Merged
merged 3 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions aioes/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ class Transport:

def __init__(self, endpoints, *,
sniffer_interval=None, sniffer_timeout=0.1, max_retries=3,
loop, verify_ssl=True):
loop, verify_ssl=True, connector_factory=lambda: None):
self._loop = loop
self._connector_factory = connector_factory
self._endpoints = self._convert_endpoints(endpoints)
self._pool = ConnectionPool([], loop=loop)
self._verify_ssl = verify_ssl
Expand Down Expand Up @@ -148,7 +149,8 @@ def _reinitialize_endpoints(self):
connections.append(Connection(
endpoint,
loop=self._loop,
verify_ssl=self._verify_ssl))
verify_ssl=self._verify_ssl,
connector=self._connector_factory()))
self._pool.close()
random.shuffle(connections)
self._pool = ConnectionPool(connections, loop=self._loop)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import aiohttp
import asyncio
import time
import urllib.parse
Expand Down Expand Up @@ -30,6 +31,27 @@ def test_ctor(make_transport, es_params):
assert 1 == len(tr._pool.connections)


@asyncio.coroutine
def test_connector_factory(es_params, loop):

class TCPConnector(aiohttp.TCPConnector):
used = False

def __init__(self, *args, **kwargs):
TCPConnector.used = True
super(TCPConnector, self).__init__(*args, **kwargs)

tr = Transport(
endpoints=[{'host': es_params['host']}],
sniffer_interval=None,
loop=loop,
connector_factory=lambda: TCPConnector(loop=loop)
)
assert 1 == len(tr._pool.connections)
assert TCPConnector.used
tr.close()


@asyncio.coroutine
def test_simple(make_transport):
tr = make_transport()
Expand Down