8000 test: add local-remote-local topology test by JoanFM · Pull Request #1665 · jina-ai/serve · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: add local-remote-local topology test #1665

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

Merged
merged 1 commit into from
Jan 12, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JINA_WORKSPACE=workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
!DummyCrafter
with:
{}
metas:
py_modules: dummy-crafter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3.3"
services:
encoder:
image: test_local_flow_local_remote_local
build:
context: .
dockerfile: Dockerfiles/debianx.Dockerfile
ports:
- "8000:8000"
- "45000:45000"
- "45001:45001"
- "45002:45002"
- "45003:45003"
- "45004:45004"
- "45005:45005"
- "45006:45006"
env_file:
- tests/jinad/integration/distributed/test_local_flow_remote_local_remote/.env
expose:
- 10000-60000
networks:
testing_net:
ipv4_address: 172.28.1.1
networks:
testing_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
__copyright__ = "Copyright (c) 2020 Jina AI Limited. All rights reserved."
__license__ = "Apache-2.0"

from jina.executors.crafters import BaseCrafter


class DummyCrafter(BaseCrafter):
def __init__(self,
*args,
**kwargs):
super().__init__(*args, **kwargs)

def craft(self, text, *args, **kwargs):
return {'text': text}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
__copyright__ = "Copyright (c) 2020 Jina AI Limited. All rights reserved."
__license__ = "Apache-2.0"

import numpy as np

from jina.executors.encoders import BaseEncoder
from jina.executors.decorators import batching


class DummyEncoder(BaseEncoder):
def __init__(self,
*args,
**kwargs):
super().__init__(*args, **kwargs)

@batching(batch_size=1)
def encode(self, data: 'np.ndarray', *args, **kwargs) -> 'np.ndarray':
return np.random.random((1, 3))
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
!DummyEncoder
with:
{}
metas:
py_modules: dummy-encoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
!Flow
with:
read_only: true
pods:
crafter:
# for now all the uploaded files are stored in the same folder, so no subpaths allowed in remote
uses: craft.yml
read_only: False
show-exc-info: True
#port_out: 45003
encoder:
show-exc-info: True
uses: encode.yml
host: $JINA_ENCODER_HOST
port_in: 45003
port_ctrl: 45006
#port_out: 45004
port_expose: 8000
indexer:
# for now all the uploaded files are stored in the same folder, so no subpaths allowed in remote
#port_in: 45004
uses: index.yml
read_only: False
show-exc-info: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
!CompoundIndexer
components:
- !NumpyIndexer
with:
index_filename: vec.gz
metric: euclidean
metas:
name: vecidx
workspace: $JINA_WORKSPACE
- !BinaryPbIndexer
with:
index_filename: doc.gz
metas:
name: docidx
workspace: $JINA_WORKSPACE
metas:
name: indexer
workspace: $JINA_WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os

import pytest

from jina import Document
from jina.flow import Flow

cur_dir = os.path.dirname(os.path.abspath(__file__))
compose_yml = os.path.join(cur_dir, 'docker-compose.yml')
flow_yml = os.path.join(cur_dir, 'flow.yml')


@pytest.mark.parametrize('docker_compose', [compose_yml], indirect=['docker_compose'])
def test_flow(docker_compose, tmpdir, mocker):
text = 'cats rules'
m = mocker.Mock()

def validate_output(resp):
m()
assert len(resp.index.docs) == 1
assert resp.index.docs[0].text == text

os.environ['JINA_ENCODER_HOST'] = '172.28.1.1'
os.environ['JINA_WORKSPACE'] = str(tmpdir)

with Document() as doc:
doc.content = text

with Flow.load_config(flow_yml) as f:
f.index([doc], on_done=validate_output)

m.assert_called_once()
0