Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F timeout issue 140 #159

Merged
merged 2 commits into from
Jun 10, 2019
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
5 changes: 4 additions & 1 deletion pydruid/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AsyncPyDruid(BaseDruidClient):

:param str url: URL of Broker node in the Druid cluster
:param str endpoint: Endpoint that Broker listens for queries on
:param dict defaults: (optional) Dict of parameters for the Async HTTP Client subclass

Example

Expand Down Expand Up @@ -95,11 +96,13 @@ class AsyncPyDruid(BaseDruidClient):
1 6 2013-10-04T00:00:00.000Z user_2
"""

def __init__(self, url, endpoint):
def __init__(self, url, endpoint, defaults=None):
super(AsyncPyDruid, self).__init__(url, endpoint)
self.async_http_defaults = defaults

@gen.coroutine
def _post(self, query):
AsyncHTTPClient.configure(None, defaults=self.async_http_defaults)
http_client = AsyncHTTPClient()
try:
headers, querystr, url = self._prepare_url_headers_and_body(query)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,25 @@ def test_client_allows_to_export_last_query(self):
# assert that last_query.export_tsv method was called (it should throw an exception, given empty path)
with pytest.raises(TypeError):
client.export_tsv(None)

@tornado.testing.gen_test
def test_client_allows_passing_default_parameters(self):
# given
client = AsyncPyDruid("http://localhost:%s" % (self.get_http_port(), ),
"druid/v2/return_results",
defaults=dict(request_timeout=120))
top = yield client.topn(
datasource="testdatasource",
granularity="all",
intervals="2015-12-29/pt1h",
aggregations={"count": doublesum("count")},
dimension="user_name",
metric="count",
filter=Dimension("user_lang") == "en",
threshold=1,
context={"timeout": 1000})

# then
self.assertIsNotNone(top)
self.assertEqual(len(top.result), 1)
self.assertEqual(len(top.result[0]['result']), 1)