예제 #1
0
async def test_run_async_flow(restful, mocker):
    r_val = mocker.Mock(wrap=validate)
    with AsyncFlow(restful=restful).add() as f:
        async for r in f.index_ndarray(np.random.random([num_docs, 4]),
                                       on_done=r_val):
            assert isinstance(r, Response)
    r_val.assert_called()
예제 #2
0
async def run_async_flow_5s(restful):
    # WaitDriver pause 5s makes total roundtrip ~5s
    with AsyncFlow(restful=restful).add(uses='- !WaitDriver {}') as f:
        async for r in f.index_ndarray(
            np.random.random([num_docs, 4]), on_done=validate
        ):
            assert isinstance(r, Response)
예제 #3
0
async def test_return_results_async_flow_crud(return_results, restful):
    with AsyncFlow(restful=restful, return_results=return_results).add() as f:
        r = await f.index(documents(0, 10))
        if return_results:
            assert isinstance(r, list)
            assert isinstance(r[0], Response)
        else:
            assert r is None

        r = await f.delete(documents(0, 5))
        if return_results:
            assert isinstance(r, list)
            assert isinstance(r[0], Response)
        else:
            assert r is None

        r = await f.update(documents(5, 10))
        if return_results:
            assert isinstance(r, list)
            assert isinstance(r[0], Response)
        else:
            assert r is None

        r = await f.search(documents(0, 1))
        if return_results:
            assert isinstance(r, list)
            assert isinstance(r[0], Response)
        else:
            assert r is None
예제 #4
0
async def test_return_results_async_flow(return_results, restful):
    with AsyncFlow(restful=restful, return_results=return_results).add() as f:
        r = await f.index_ndarray(np.random.random([10, 2]))
        if return_results:
            assert isinstance(r, list)
            assert isinstance(r[0], Response)
        else:
            assert r is None
예제 #5
0
async def test_run_async_flow(restful, mocker):
    r_val = mocker.Mock()
    with AsyncFlow(restful=restful).add() as f:
        async for r in f.index(
            from_ndarray(np.random.random([num_docs, 4])), on_done=r_val
        ):
            assert isinstance(r, Response)
    validate_callback(r_val, validate)
예제 #6
0
async def test_async_flow_empty_data():
    from jina import Executor, requests

    class MyExec(Executor):
        @requests
        def foo(self, parameters, **kwargs):
            assert parameters['hello'] == 'world'

    with AsyncFlow().add(uses=MyExec) as f:
        async for r in f.post('/hello', parameters={'hello': 'world'}):
            assert isinstance(r, Response)
예제 #7
0
async def run_async_flow_5s(restful):
    # WaitDriver pause 5s makes total roundtrip ~5s
    from jina import Executor, requests

    class Wait5s(Executor):
        @requests
        def foo(self, **kwargs):
            print('im called!')
            time.sleep(5)

    with AsyncFlow(restful=restful).add(uses=Wait5s) as f:
        async for r in f.index(
            from_ndarray(np.random.random([num_docs, 4])),
            on_done=validate,
        ):
            assert isinstance(r, Response)
예제 #8
0
async def test_run_async_flow_async_input(restful, input_fn, mocker):
    r_val = mocker.Mock(wrap=validate)
    with AsyncFlow(restful=restful).add() as f:
        async for r in f.index(input_fn, on_done=r_val):
            assert isinstance(r, Response)
    r_val.assert_called()
예제 #9
0
async def test_return_results_async_flow_crud(return_results, restful,
                                              flow_api):
    with AsyncFlow(restful=restful, return_results=return_results).add() as f:
        async for r in getattr(f, flow_api)(documents(0, 10)):
            assert isinstance(r, Response)
예제 #10
0
async def test_return_results_async_flow(return_results, restful):
    with AsyncFlow(restful=restful, return_results=return_results).add() as f:
        async for r in f.index_ndarray(np.random.random([10, 2])):
            assert isinstance(r, Response)
예제 #11
0
async def run_async_flow_5s(restful):
    # WaitDriver pause 5s makes total roundtrip ~5s
    with AsyncFlow(restful=restful).add(uses='- !WaitDriver {}') as f:
        await f.index_ndarray(np.random.random([5, 4]), on_done=validate)
예제 #12
0
async def test_run_async_flow(restful):
    with AsyncFlow(restful=restful).add() as f:
        await f.index_ndarray(np.random.random([5, 4]), on_done=validate)
예제 #13
0
async def test_run_async_flow_async_input(restful, inputs, mocker):
    r_val = mocker.Mock()
    with AsyncFlow(restful=restful).add() as f:
        async for r in f.index(inputs, on_done=r_val):
            assert isinstance(r, Response)
    validate_callback(r_val, validate)
예제 #14
0
async def test_run_async_flow_async_input(restful, input_fn, mocker):
    r_val = mocker.Mock(wrap=validate)
    with AsyncFlow(restful=restful).add() as f:
        await f.index(input_fn, on_done=r_val)
    r_val.assert_called()
예제 #15
0
async def test_run_async_flow(restful, mocker):
    r_val = mocker.Mock(wrap=validate)
    with AsyncFlow(restful=restful).add() as f:
        await f.index_ndarray(np.random.random([num_docs, 4]), on_done=r_val)
    r_val.assert_called()