Ejemplo n.º 1
0
    def test_simple_zmqlet(self):
        args = set_pea_parser().parse_args([
            '--host-in', '0.0.0.0',
            '--host-out', '0.0.0.0',
            '--port-in', '12346',
            '--port-out', '12347',
            '--socket-in', 'PULL_CONNECT',
            '--socket-out', 'PUSH_CONNECT',
            '--timeout-ctrl', '-1'])

        args2 = set_pea_parser().parse_args([
            '--host-in', '0.0.0.0',
            '--host-out', '0.0.0.0',
            '--port-in', '12347',
            '--port-out', '12346',
            '--socket-in', 'PULL_BIND',
            '--socket-out', 'PUSH_BIND',
            '--uses', '_logforward',
            '--timeout-ctrl', '-1'
        ])

        with BasePea(args2) as z1, Zmqlet(args) as z:
            req = jina_pb2.Request()
            req.request_id = 1
            d = req.index.docs.add()
            d.id = 2
            msg = add_envelope(req, 'tmp', '')
            z.send_message(msg)
Ejemplo n.º 2
0
def test_address_in_use():
    with pytest.raises(PeaFailToStart):
        args1 = set_pea_parser().parse_args(['--port-ctrl', '55555'])
        args2 = set_pea_parser().parse_args(['--port-ctrl', '55555'])
        with BasePea(args1), BasePea(args2):
            pass

    with pytest.raises(PeaFailToStart):
        args1 = set_pea_parser().parse_args(['--port-ctrl', '55555', '--runtime', 'thread'])
        args2 = set_pea_parser().parse_args(['--port-ctrl', '55555', '--runtime', 'thread'])
        with BasePea(args1), BasePea(args2):
            pass
Ejemplo n.º 3
0
    def test_address_in_use(self):
        args1 = set_pea_parser().parse_args(['--port-ctrl', '55555'])
        args2 = set_pea_parser().parse_args(['--port-ctrl', '55555'])
        with BasePea(args1), BasePea(args2):
            pass

        args1 = set_pea_parser().parse_args(['--port-ctrl', '55555', '--runtime', 'thread'])
        args2 = set_pea_parser().parse_args(['--port-ctrl', '55555', '--runtime', 'thread'])
        with BasePea(args1), BasePea(args2):
            pass

        print('everything should quit gracefully')
Ejemplo n.º 4
0
    def test_class_yaml(self):
        class DummyClass:
            pass

        yaml.register_class(DummyClass)

        a = yaml.load('!DummyClass {}')
        self.assertEqual(type(a), DummyClass)

        with open(
                resource_filename(
                    'jina', '/'.join(
                        ('resources', 'executors.requests.%s.yml' %
                         'BaseExecutor')))) as fp:
            b = fp.read()
            print(b)
            c = yaml.load(b)
            print(c)

        args = set_pea_parser().parse_args([])

        with BasePea(args) as p:
            pass

        from jina.executors.requests import _defaults
        self.assertIsNotNone(_defaults)
Ejemplo n.º 5
0
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')
Ejemplo n.º 6
0
    def test_simple_container_with_ext_yaml(self):
        args = set_pea_parser().parse_args(['--image', img_name,
                                            '--yaml-path', './mwu-encoder/mwu_encoder_ext.yml'])
        print(args)

        with ContainerPea(args):
            time.sleep(2)
Ejemplo n.º 7
0
    def test_simple_container_with_ext_yaml(self):
        args = set_pea_parser().parse_args(['--uses', img_name,
                                            '--uses-internal', os.path.join(cur_dir, 'mwu-encoder/mwu_encoder_ext.yml')])
        print(args)

        with ContainerPea(args):
            time.sleep(2)
Ejemplo n.º 8
0
 def start_client(d):
     print('im running %d' % d)
     p_args = set_pea_parser().parse_args([
         '--host', 'localhost', '--name',
         'testpea%d' % d, '--port-expose',
         str(f_args.port_expose)
     ])
     PeaSpawnHelper(p_args).start()
Ejemplo n.º 9
0
    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()
Ejemplo n.º 10
0
    def test_simple_container(self):
        args = set_pea_parser().parse_args(['--uses', img_name])
        print(args)

        with ContainerPea(args):
            pass

        time.sleep(2)
        ContainerPea(args).start().close()
Ejemplo n.º 11
0
    def test_container_ping(self):
        a4 = set_pea_parser().parse_args(['--image', img_name])
        a5 = set_ping_parser().parse_args(['0.0.0.0', str(a4.port_ctrl), '--print-response'])

        # test with container
        with self.assertRaises(SystemExit) as cm:
            with BasePea(a4):
                NetworkChecker(a5)

        self.assertEqual(cm.exception.code, 0)
Ejemplo n.º 12
0
    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()
Ejemplo n.º 13
0
    def test_ping(self):
        a1 = set_pea_parser().parse_args([])
        a2 = set_ping_parser().parse_args(['0.0.0.0', str(a1.port_ctrl), '--print-response'])
        a3 = set_ping_parser().parse_args(['0.0.0.1', str(a1.port_ctrl), '--timeout', '1000'])

        with self.assertRaises(SystemExit) as cm:
            with BasePea(a1):
                NetworkChecker(a2)

        self.assertEqual(cm.exception.code, 0)

        # test with bad addresss
        with self.assertRaises(SystemExit) as cm:
            with BasePea(a1):
                NetworkChecker(a3)

        self.assertEqual(cm.exception.code, 1)
Ejemplo n.º 14
0
def test_ping():
    a1 = set_pea_parser().parse_args([])
    a2 = set_ping_parser().parse_args(['0.0.0.0', str(a1.port_ctrl), '--print-response'])
    a3 = set_ping_parser().parse_args(['0.0.0.1', str(a1.port_ctrl), '--timeout', '1000'])

    with pytest.raises(SystemExit) as cm:
        with BasePea(a1):
            NetworkChecker(a2)

    assert cm.value.code == 0

    # test with bad addresss
    with pytest.raises(SystemExit) as cm:
        with BasePea(a1):
            NetworkChecker(a3)

    assert cm.value.code == 1
Ejemplo n.º 15
0
    def test_remote_pea(self):
        f_args = set_gateway_parser().parse_args(['--allow-spawn'])

        p_args = set_pea_parser().parse_args(
            ['--host', 'localhost', '--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()

        time.sleep(1)
        PeaSpawnHelper(p_args).start()
        t.join()
Ejemplo n.º 16
0
def test_pea_context(runtime):
    args = set_pea_parser().parse_args(['--runtime', runtime])
    with BasePea(args):
        pass

    BasePea(args).start().close()