def test_flow(docker_compose, mocker, encoder_needs, indexer_needs): text = 'cats rules' def validate_output(resp): assert len(resp.data.docs) == 1 assert resp.data.docs[0].text == text os.environ['JINA_CRAFTER_HOST'] = '172.28.1.1' os.environ['JINA_INDEXER_HOST'] = '172.28.1.2' os.environ['JINA_INTERNAL_HOST'] = get_internal_ip() os.environ['JINA_ENCODER_NEEDS'] = encoder_needs os.environ['JINA_INDEXER_NEEDS'] = indexer_needs doc = Document(content=text) mock = mocker.Mock() with Flow.load_config(flow_yml) as f: f.index([doc], on_done=mock) mock.assert_called_once() validate_callback(mock, validate_output)
def test_pod_remote_pea_without_parallel(): args = set_pod_parser().parse_args( ['--peas-hosts', '0.0.0.1', '--parallel', str(1)] ) with Pod(args) as pod: peas = pod.peas for pea in peas: assert pea.args.host == pod.host @pytest.mark.parametrize( 'pod_host, pea1_host, expected_host_in, expected_host_out', [ ('0.0.0.0', '0.0.0.1', get_internal_ip(), get_internal_ip()), ('0.0.0.1', '0.0.0.2', '0.0.0.1', '0.0.0.1'), ('0.0.0.1', '0.0.0.0', '0.0.0.1', '0.0.0.1'), ], ) def test_pod_remote_pea_parallel_pea_host_set_partially( pod_host, pea1_host, expected_host_in, expected_host_out, ): args = set_pod_parser().parse_args( ['--peas-hosts', f'{pea1_host}', '--parallel', str(2), '--host', pod_host] ) assert args.host == pod_host pod = Pod(args)
def test_pod_remote_pea_without_parallel(): args = set_pod_parser().parse_args( ['--peas-hosts', '0.0.0.1', '--parallel', str(1)]) with Pod(args) as pod: peas = pod.peas for pea in peas: assert pea.args.host == pod.host @pytest.mark.parametrize( 'pod_host, pea1_host, expected_host_in, expected_host_out', [ ('0.0.0.0', '0.0.0.1', get_internal_ip(), get_internal_ip()), ('0.0.0.1', '0.0.0.2', '0.0.0.1', '0.0.0.1'), ('0.0.0.1', '0.0.0.0', '0.0.0.1', '0.0.0.1'), ], ) def test_pod_remote_pea_parallel_pea_host_set_partially( pod_host, pea1_host, expected_host_in, expected_host_out, ): args = set_pod_parser().parse_args([ '--peas-hosts', f'{pea1_host}', '--parallel', str(2), '--host', pod_host ]) assert args.host == pod_host
import pytest from jina import Flow, __default_host__ from jina.helper import get_internal_ip, get_public_ip @pytest.mark.parametrize('local_ip, on_public', [(get_internal_ip(), False), (get_public_ip(), True)]) def test_remote_pod_local_gateway(local_ip, on_public): # BIND socket's host must always be 0.0.0.0 remote_ip = '111.111.111.111' f = Flow(expose_public=on_public).add(host=remote_ip) f.build() for k, v in f: print(f'{v.name}\tIN: {v.address_in}\t{v.address_out}') assert f['pod0'].host_in == __default_host__ assert f['pod0'].host_out == __default_host__ assert f['gateway'].host_in == remote_ip assert f['gateway'].host_out == remote_ip @pytest.mark.parametrize('local_ip, on_public', [(get_internal_ip(), False), (get_public_ip(), True)]) def test_remote_pod_local_pod_local_gateway(local_ip, on_public): remote_ip = '111.111.111.111' f = Flow(expose_public=on_public).add(host=remote_ip).add() f.build() for k, v in f._pod_nodes.items(): print(f'{v.name}\tIN: {v.address_in}\t{v.address_out}') assert f['pod0'].host_in == __default_host__ assert f['pod0'].host_out == local_ip
assert p.num_peas == 4 def test_pod_remote_pea_without_replicas(): args = set_pod_parser().parse_args( ['--peas-hosts', '0.0.0.1', '--replicas', str(1)]) with Pod(args) as pod: pea = pod.replica_set._peas[0] assert pea.args.host == pod.host @pytest.mark.parametrize( 'pod_host, pea1_host, expected_host_in, expected_host_out', [ (__default_host__, '0.0.0.1', get_internal_ip(), get_internal_ip()), ('0.0.0.1', '0.0.0.2', '0.0.0.1', '0.0.0.1'), ('0.0.0.1', __default_host__, '0.0.0.1', '0.0.0.1'), ], ) def test_pod_remote_pea_replicas_pea_host_set_partially( pod_host, pea1_host, expected_host_in, expected_host_out, ): args = set_pod_parser().parse_args([ '--peas-hosts', f'{pea1_host}', '--replicas', str(2), '--host', pod_host ]) assert args.host == pod_host