def test_cont_gateway(self): f1_args = set_gateway_parser().parse_args(['--allow-spawn']) f2_args = set_gateway_parser().parse_args([]) with GatewayPod(f1_args): pass with GatewayPod(f2_args): pass
def _update_autocomplete(): from jina.main.parser import get_main_parser, set_pea_parser, \ set_hw_parser, set_flow_parser, set_pod_parser, \ set_check_parser, set_gateway_parser, set_ping_parser, set_client_cli_parser, set_logger_parser def _gaa(parser): _compl = [] for v in parser._actions: if v.option_strings: _compl.extend(v.option_strings) elif v.choices: _compl.extend(v.choices) # filer out single dash, as they serve as abbrev _compl = [k for k in _compl if (not k.startswith('-') or k.startswith('--'))] return _compl compl = { 'commands': _gaa(get_main_parser()), 'completions': { 'pea': _gaa(set_pea_parser()), 'hello-world': _gaa(set_hw_parser()), 'flow': _gaa(set_flow_parser()), 'pod': _gaa(set_pod_parser()), 'check': _gaa(set_check_parser()), 'gateway': _gaa(set_gateway_parser()), 'ping': _gaa(set_ping_parser()), 'client': _gaa(set_client_cli_parser()), 'log': _gaa(set_logger_parser()) } } with open(__file__, 'a') as fp: fp.write(f'\nac_table = {compl}\n')
def test_remote_two_pea(self): # NOTE: right now there is no way to spawn two peas with one gateway!!! f_args = set_gateway_parser().parse_args(['--allow-spawn']) def start_gateway(): with GatewayPod(f_args): time.sleep(5) def start_client(d): print('im running %d' % d) p_args = set_pea_parser().parse_args( ['--host', 'localhost', '--name', 'testpea%d' % d, '--port-grpc', str(f_args.port_grpc)]) PeaSpawnHelper(p_args).start() t = Process(target=start_gateway) t.daemon = True t.start() time.sleep(1) c1 = Process(target=start_client, args=(1,)) c2 = Process(target=start_client, args=(2,)) c1.daemon = True c2.daemon = True c1.start() c2.start() time.sleep(5) c1.join() c2.join()
def test_index_remote(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) def start_gateway(): with GatewayPod(f_args): time.sleep(20) t = mp.Process(target=start_gateway) t.daemon = True t.start() f = Flow().add(yaml_path=os.path.join(cur_dir, 'yaml/test-index.yml'), replicas=3, separated_workspace=True, host='localhost', port_expose=f_args.port_expose) with f: f.index(input_fn=random_docs(1000)) time.sleep(3) for j in range(3): self.assertTrue(os.path.exists(f'test2-{j + 1}/test2.bin')) self.assertTrue(os.path.exists(f'test2-{j + 1}/tmp2')) self.add_tmpfile(f'test2-{j + 1}/test2.bin', f'test2-{j + 1}/tmp2', f'test2-{j + 1}')
def test_remote_not_allowed(self): f_args = set_gateway_parser().parse_args([]) p_args = set_pea_parser().parse_args( ['--host', 'localhost', '--port-expose', str(f_args.port_expose)]) with GatewayPod(f_args): PeaSpawnHelper(p_args).start()
def test_gateway_ready(self): p = set_gateway_parser().parse_args([]) with RESTGatewayPea(p): a = requests.get(f'http://0.0.0.0:{p.port_expose}/ready') self.assertEqual(a.status_code, 200) with RESTGatewayPea(p): a = requests.post(f'http://0.0.0.0:{p.port_expose}/api/ass') self.assertEqual(a.status_code, 405)
def test_remote_pod_process(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) p_args = set_pod_parser().parse_args( ['--host', 'localhost', '--replicas', '3', '--port-grpc', str(f_args.port_grpc), '--runtime', 'process']) def start_spawn(): PodSpawnHelper(p_args).start() with GatewayPod(f_args): t = Process(target=start_spawn) t.daemon = True t.start() time.sleep(5)
def test_remote_pod2(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) p_args = set_pea_parser().parse_args(['--host', 'localhost', '--port-grpc', str(f_args.port_grpc)]) def start_gateway(): with GatewayPod(f_args): time.sleep(5) t = Process(target=start_gateway) t.daemon = True t.start() with RemotePod(p_args): pass t.join()
def test_customized_pod(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) p_args = set_pod_parser().parse_args( ['--host', 'localhost', '--replicas', '3', '--port-grpc', str(f_args.port_grpc)]) p = BasePod(p_args) def start_gateway(): with GatewayPod(f_args): time.sleep(5) t = Process(target=start_gateway) t.daemon = True t.start() MutablePodSpawnHelper(p.peas_args).start()
def test_remote_pod(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) p_args = set_pod_parser().parse_args([ '--host', 'localhost', '--parallel', '3', '--port-expose', str(f_args.port_expose) ]) def start_gateway(): with GatewayPod(f_args): time.sleep(5) t = Process(target=start_gateway) t.daemon = True t.start() PodSpawnHelper(p_args).start() t.join()
def test_index_remote_rpi(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) def start_gateway(): with GatewayPod(f_args): time.sleep(50) t = mp.Process(target=start_gateway) t.daemon = True t.start() f = (Flow(optimize_level=FlowOptimizeLevel.IGNORE_GATEWAY) .add(uses=os.path.join(cur_dir, 'yaml/test-index.yml'), parallel=3, separated_workspace=True, host='192.168.31.76', port_expose=44444)) with f: f.index(input_fn=random_docs(1000))
def test_customized_pod2(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) p_args = set_pod_parser().parse_args([ '--host', 'localhost', '--parallel', '3', '--port-expose', str(f_args.port_expose) ]) p = BasePod(p_args) def start_gateway(): with GatewayPod(f_args): time.sleep(5) t = Process(target=start_gateway) t.daemon = True t.start() with RemoteMutablePod(p.peas_args): pass t.join()
def test_index_remote_rpi(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) def start_gateway(): with GatewayPod(f_args): time.sleep(50) t = mp.Process(target=start_gateway) t.daemon = True t.start() f = (Flow(optimize_level=FlowOptimizeLevel.IGNORE_GATEWAY).add( yaml_path='yaml/test-index.yml', replicas=3, separated_workspace=True, host='192.168.31.76', port_grpc=44444)) with f: f.index(raw_bytes=random_docs(1000), in_proto=True)
def _test_gateway_pod(runtime): args = set_gateway_parser().parse_args(['--runtime', runtime]) with GatewayPod(args): pass GatewayPod(args).start().close()