本文整理汇总了Python中elasticsearch.transport.Transport类的典型用法代码示例。如果您正苦于以下问题:Python Transport类的具体用法?Python Transport怎么用?Python Transport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sniff_reuses_connection_instances_if_possible
def test_sniff_reuses_connection_instances_if_possible(self):
t = Transport([{'data': CLUSTER_NODES}, {"host": "1.1.1.1", "port": 123}], connection_class=DummyConnection, randomize_hosts=False)
connection = t.connection_pool.connections[1]
t.sniff_hosts()
self.assertEquals(1, len(t.connection_pool.connections))
self.assertIs(connection, t.get_connection())
示例2: test_sniff_on_start_fetches_and_uses_nodes_list_for_its_schema
def test_sniff_on_start_fetches_and_uses_nodes_list_for_its_schema(self):
class DummyThriftConnection(DummyConnection):
transport_schema = "thrift"
t = Transport([{"data": CLUSTER_NODES}], connection_class=DummyThriftConnection, sniff_on_start=True)
self.assertEquals(1, len(t.connection_pool.connections))
self.assertEquals("thrift://1.1.1.1:9500", t.get_connection().host)
示例3: test_sniff_on_fail_triggers_sniffing_on_fail
def test_sniff_on_fail_triggers_sniffing_on_fail(self):
t = Transport([{'exception': ConnectionError('abandon ship')}, {"data": CLUSTER_NODES}],
connection_class=DummyConnection, sniff_on_connection_fail=True, max_retries=0, randomize_hosts=False)
self.assertRaises(ConnectionError, t.perform_request, 'GET', '/')
self.assertEquals(1, len(t.connection_pool.connections))
self.assertEquals('http://1.1.1.1:123', t.get_connection().host)
示例4: test_body_bytes_get_passed_untouched
def test_body_bytes_get_passed_untouched(self):
t = Transport([{}], connection_class=DummyConnection)
body = b'\xe4\xbd\xa0\xe5\xa5\xbd'
t.perform_request('GET', '/', body=body)
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('GET', '/', None, body), t.get_connection().calls[0][0])
示例5: test_send_get_body_as_source
def test_send_get_body_as_source(self):
t = Transport([{}], send_get_body_as="source", connection_class=DummyConnection)
t.perform_request("GET", "/", body={})
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(
("GET", "/", {"source": "{}"}, None), t.get_connection().calls[0][0]
)
示例6: test_resurrected_connection_will_be_marked_as_live_on_success
def test_resurrected_connection_will_be_marked_as_live_on_success(self):
t = Transport([{}], connection_class=DummyConnection)
con = t.connection_pool.get_connection()
t.connection_pool.mark_dead(con)
t.perform_request('GET', '/')
self.assertEquals(1, len(t.connection_pool.connections))
self.assertEquals(0, len(t.connection_pool.dead_count))
示例7: test_sniff_on_start_fetches_and_uses_nodes_list
def test_sniff_on_start_fetches_and_uses_nodes_list(self):
t = Transport(
[{"data": CLUSTER_NODES}],
connection_class=DummyConnection,
sniff_on_start=True,
)
self.assertEquals(1, len(t.connection_pool.connections))
self.assertEquals("http://1.1.1.1:123", t.get_connection().host)
示例8: test_request_will_fail_after_X_retries
def test_request_will_fail_after_X_retries(self):
t = Transport(
[{"exception": ConnectionError("abandon ship")}],
connection_class=DummyConnection,
)
self.assertRaises(ConnectionError, t.perform_request, "GET", "/")
self.assertEquals(4, len(t.get_connection().calls))
示例9: test_add_connection
def test_add_connection(self):
t = Transport([{}], randomize_hosts=False)
t.add_connection({"host": "google.com", "port": 1234})
self.assertEquals(2, len(t.connection_pool.connections))
self.assertEquals(
"http://google.com:1234", t.connection_pool.connections[1].host
)
示例10: test_body_surrogates_replaced_encoded_into_bytes
def test_body_surrogates_replaced_encoded_into_bytes(self):
t = Transport([{}], connection_class=DummyConnection)
t.perform_request("GET", "/", body="你好\uda6a")
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(
("GET", "/", None, b"\xe4\xbd\xa0\xe5\xa5\xbd\xed\xa9\xaa"),
t.get_connection().calls[0][0],
)
示例11: test_sniff_uses_sniff_timeout
def test_sniff_uses_sniff_timeout(self):
t = Transport(
[{"data": CLUSTER_NODES}],
connection_class=DummyConnection,
sniff_timeout=42,
)
t.sniff_hosts()
self.assertEquals(
(("GET", "/_nodes/_all/http"), {"timeout": 42}),
t.seed_connections[0].calls[0],
)
示例12: __init__
def __init__(self, urls, timeout=60, max_retries=0):
"""
:arg urls: A URL or iterable of URLs of ES nodes. These are full URLs
with port numbers, like ``http://elasticsearch.example.com:9200``.
:arg timeout: Number of seconds to wait for each request before raising
Timeout
:arg max_retries: How many other servers to try, in series, after a
request times out or a connection fails
"""
if isinstance(urls, string_types):
urls = [urls]
urls = [u.rstrip('/') for u in urls]
self.json_encoder = JsonEncoder
# Automatic node sniffing is off for now.
parsed_urls = (urlparse(url) for url in urls)
self._transport = Transport(
[{'host': url.hostname,
'port': url.port or 9200,
'http_auth': (url.username, url.password) if
url.username or url.password else None}
for url in parsed_urls],
max_retries=max_retries,
retry_on_timeout=True,
timeout=timeout,
selector_class=RandomSelector)
示例13: __init__
def __init__(
self,
urls="http://localhost",
timeout=60,
max_retries=0,
port=9200,
username=None,
password=None,
ca_certs=certifi.where(),
client_cert=None,
):
"""
:arg urls: A URL or iterable of URLs of ES nodes. These can be full
URLs with port numbers, like
``http://elasticsearch.example.com:9200``, or you can pass the
port separately using the ``port`` kwarg. To do HTTP basic
authentication, you can use RFC-2617-style URLs like
``http://someuser:[email protected]:9200`` or the separate
``username`` and ``password`` kwargs below.
:arg timeout: Number of seconds to wait for each request before raising
Timeout
:arg max_retries: How many other servers to try, in series, after a
request times out or a connection fails
:arg username: Authentication username to send via HTTP basic auth
:arg password: Password to use in HTTP basic auth. If a username and
password are embedded in a URL, those are favored.
:arg port: The default port to connect on, for URLs that don't include
an explicit port
:arg ca_certs: A path to a bundle of CA certificates to trust. The
default is to use Mozilla's bundle, the same one used by Firefox.
:arg client_cert: A certificate to authenticate the client to the
server
"""
if isinstance(urls, string_types):
urls = [urls]
urls = [u.rstrip("/") for u in urls]
# Automatic node sniffing is off for now.
parsed_urls = (urlparse(url) for url in urls)
auth_default = None if username is None else (username, password)
self._transport = Transport(
[
{
"host": url.hostname,
"port": url.port or port,
"http_auth": (url.username, url.password) if url.username or url.password else auth_default,
"use_ssl": url.scheme == "https",
"verify_certs": True,
"ca_certs": ca_certs,
"cert_file": client_cert,
}
for url in parsed_urls
],
max_retries=max_retries,
retry_on_timeout=True,
timeout=timeout,
selector_class=RandomSelector,
)
示例14: test_sniff_after_n_seconds
def test_sniff_after_n_seconds(self):
t = Transport([{"data": CLUSTER_NODES}], connection_class=DummyConnection, sniffer_timeout=5)
for _ in range(4):
t.perform_request("GET", "/")
self.assertEquals(1, len(t.connection_pool.connections))
self.assertIsInstance(t.get_connection(), DummyConnection)
t.last_sniff = time.time() - 5.1
t.perform_request("GET", "/")
self.assertEquals(1, len(t.connection_pool.connections))
self.assertEquals("http://1.1.1.1:123", t.get_connection().host)
self.assertTrue(time.time() - 1 < t.last_sniff < time.time() + 0.01)
示例15: test_request_timeout_extracted_from_params_and_passed
def test_request_timeout_extracted_from_params_and_passed(self):
t = Transport([{}], connection_class=DummyConnection)
t.perform_request('GET', '/', params={'request_timeout': 42})
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('GET', '/', {}, None), t.get_connection().calls[0][0])
self.assertEquals({'timeout': 42, 'ignore': ()}, t.get_connection().calls[0][1])