-
Notifications
You must be signed in to change notification settings - Fork 41
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
support async bulk api #90
Open
RainJayTsai
wants to merge
19
commits into
aio-libs:master
Choose a base branch
from
RainJayTsai:feature/bulk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
dcfca3c
support async bulk api
RainJayTsai ee8551e
init test bulk
RainJayTsai a737407
fix assert error
RainJayTsai f284685
remove typing
RainJayTsai de03870
update bulk feature info
RainJayTsai ce9bd9b
fix assert error
RainJayTsai d3b7091
fix retry bug
RainJayTsai 4ecef47
update test
RainJayTsai 6a8cda2
fix concurrency bulk bug and add testing
RainJayTsai fc282e3
fix bug
RainJayTsai 51c6c55
manual rebase
RainJayTsai 41019c4
add testing
RainJayTsai c624960
fix bug
RainJayTsai 4c0d3bb
support py35
RainJayTsai 54479b2
update testing
RainJayTsai 1dcddcd
fix retry bug
RainJayTsai 1df5ab1
support py35 string format
RainJayTsai 24c2493
add retry_handler test
RainJayTsai 2b561e7
update readme
RainJayTsai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# -*- coding: utf-8 -*- | ||
import asyncio | ||
import logging | ||
|
||
import pytest | ||
|
||
from aioelasticsearch.helpers import bulk, concurrency_bulk, _retry_handler | ||
from aioelasticsearch import Elasticsearch, TransportError | ||
|
||
logger = logging.getLogger('elasticsearch') | ||
|
||
|
||
def gen_data1(): | ||
for i in range(10): | ||
yield {"_index": "test_aioes", | ||
"_type": "type_3", | ||
"_id": str(i), | ||
"foo": "1"} | ||
|
||
|
||
def gen_data2(): | ||
for i in range(10, 20): | ||
yield {"_index": "test_aioes", | ||
"_type": "type_3", | ||
"_id": str(i), | ||
"_source": {"foo": "1"} | ||
} | ||
|
||
|
||
@pytest.mark.run_loop | ||
async def test_bulk_simple(es): | ||
success, fails = await bulk(es, gen_data1(), | ||
stats_only=True) | ||
assert success == 10 | ||
assert fails == 0 | ||
|
||
success, fails = await bulk(es, gen_data2(), | ||
stats_only=True) | ||
assert success == 10 | ||
assert fails == 0 | ||
|
||
success, fails = await bulk(es, gen_data1(), | ||
stats_only=False) | ||
assert success == 10 | ||
assert fails == [] | ||
|
||
|
||
@pytest.mark.run_loop | ||
async def test_bulk_fails(es): | ||
datas = [{'_op_type': 'delete', | ||
'_index': 'test_aioes', | ||
'_type': 'type_3', '_id': "999"} | ||
] | ||
|
||
success, fails = await bulk(es, datas, stats_only=True, max_retries=1) | ||
assert success == 0 | ||
assert fails == 1 | ||
|
||
|
||
@pytest.mark.run_loop | ||
async def test_concurrency_bulk(es): | ||
success, fails = await concurrency_bulk(es, gen_data1()) | ||
assert success == 10 | ||
assert fails == 0 | ||
|
||
success, fails = await concurrency_bulk(es, gen_data2()) | ||
assert success == 10 | ||
assert fails == 0 | ||
|
||
|
||
@pytest.mark.run_loop | ||
async def test_bulk_raise_exception(loop): | ||
|
||
asyncio.set_event_loop(loop) | ||
es = Elasticsearch() | ||
datas = [{'_op_type': 'delete', | ||
'_index': 'test_aioes', | ||
'_type': 'type_3', '_id': "999"} | ||
] | ||
with pytest.raises(TransportError): | ||
success, fails = await bulk(es, datas, stats_only=True) | ||
|
||
|
||
@pytest.mark.run_loop | ||
async def test_retry_handler(es): | ||
async def mock_data(): | ||
# finish_count, [( es_action, source_data ), ... ] | ||
return 0, [( | ||
{'index': {'_index': 'test_aioes', '_type': 'test_aioes', '_id': 100}}, | ||
{'name': 'Karl 1', 'email': '[email protected]'}), | ||
({'index': {'_index': 'test_aioes', '_type': 'test_aioes','_id': 101}}, | ||
{'name': 'Karl 2', 'email': '[email protected]'})] | ||
|
||
done, fail = await _retry_handler(es, | ||
mock_data(), | ||
max_retries=1, | ||
initial_backoff=2, | ||
max_backoff=600) | ||
assert done == 2 | ||
assert fail == [] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about to make it async gen? It Should be really usefull