Пример #1
0
def test_double_dynamic_routing_zmqlet():
    args1 = get_args()
    args2 = get_args()
    args3 = get_args()

    logger = JinaLogger('zmq-test')
    with Zmqlet(args1, logger) as z1, Zmqlet(args2, logger) as z2, Zmqlet(
        args3, logger
    ) as z3:
        assert z1.msg_sent == 0
        assert z2.msg_sent == 0
        assert z3.msg_sent == 0
        req = jina_pb2.RequestProto()
        req.request_id = random_identity()
        d = req.data.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        routing_table = {
            'active_pod': 'executor1',
            'pods': {
                'executor1': {
                    'host': __default_host__,
                    'port': args1.port_in,
                    'expected_parts': 0,
                    'out_edges': [{'pod': 'executor2'}, {'pod': 'executor3'}],
                },
                'executor2': {
                    'host': __default_host__,
                    'port': args2.port_in,
                    'expected_parts': 1,
                    'out_edges': [],
                },
                'executor3': {
                    'host': __default_host__,
                    'port': args3.port_in,
                    'expected_parts': 1,
                    'out_edges': [],
                },
            },
        }
        msg.envelope.routing_table.CopyFrom(RoutingTable(routing_table).proto)

        number_messages = 100
        trips = 10
        for i in range(trips):
            for j in range(number_messages):
                z1.send_message(msg)
            time.sleep(1)
            for i in range(number_messages):
                z2.recv_message(callback)
                z3.recv_message(callback)

        total_number_messages = number_messages * trips

        assert z1.msg_sent == 2 * total_number_messages
        assert z2.msg_sent == 0
        assert z2.msg_recv == total_number_messages
        assert z3.msg_sent == 0
        assert z3.msg_recv == total_number_messages
Пример #2
0
def test_remote_local_dynamic_routing_zmqlet():
    args1 = get_args()

    args2 = get_args()
    args2.zmq_identity = 'test-identity'
    args2.hosts_in_connect = [f'{args1.host}:{args1.port_out}']

    logger = JinaLogger('zmq-test')
    with Zmqlet(args1, logger) as z1, Zmqlet(args2, logger) as z2:
        assert z1.msg_sent == 0
        assert z1.msg_recv == 0
        assert z2.msg_sent == 0
        assert z2.msg_recv == 0
        req = jina_pb2.RequestProto()
        req.request_id = random_identity()
        d = req.data.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        routing_pb = jina_pb2.RoutingTableProto()
        routing_table = {
            'active_pod': 'pod1',
            'pods': {
                'pod1': {
                    'host': '0.0.0.0',
                    'port': args1.port_in,
                    'expected_parts': 0,
                    'out_edges': [{
                        'pod': 'pod2',
                        'send_as_bind': True
                    }],
                },
                'pod2': {
                    'host': '0.0.0.0',
                    'port': args2.port_in,
                    'expected_parts': 1,
                    'out_edges': [],
                    'target_identity': args2.zmq_identity,
                },
            },
        }
        json_format.ParseDict(routing_table, routing_pb)
        msg.envelope.routing_table.CopyFrom(routing_pb)
        z2.recv_message(callback)

        assert z2.msg_sent == 0
        assert z2.msg_recv == 0

        z1.send_message(msg)
        z2.recv_message(callback)

        assert z1.msg_sent == 1
        assert z1.msg_recv == 0
        assert z2.msg_sent == 0
        assert z2.msg_recv == 1
Пример #3
0
def test_simple_zmqlet():
    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'
    ])

    logger = logging.getLogger('zmq-test')
    with BasePea(args2) as z1, Zmqlet(args, logger) as z:
        req = jina_pb2.RequestProto()
        req.request_id = get_random_identity()
        d = req.index.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        z.send_message(msg)
Пример #4
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)
Пример #5
0
def test_simple_dynamic_routing_zmqlet():
    args1 = get_args()
    args2 = get_args()

    logger = JinaLogger('zmq-test')
    with Zmqlet(args1, logger) as z1, Zmqlet(args2, logger) as z2:
        assert z1.msg_sent == 0
        assert z1.msg_recv == 0
        assert z2.msg_sent == 0
        assert z2.msg_recv == 0
        req = jina_pb2.RequestProto()
        req.request_id = random_identity()
        d = req.data.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        routing_pb = jina_pb2.RoutingTableProto()
        routing_table = {
            'active_pod': 'executor1',
            'pods': {
                'executor1': {
                    'host': __default_host__,
                    'port': args1.port_in,
                    'expected_parts': 0,
                    'out_edges': [{'pod': 'executor2'}],
                },
                'executor2': {
                    'host': __default_host__,
                    'port': args2.port_in,
                    'expected_parts': 1,
                    'out_edges': [],
                },
            },
        }
        json_format.ParseDict(routing_table, routing_pb)
        msg.envelope.routing_table.CopyFrom(routing_pb)
        z2.recv_message(callback)

        assert z2.msg_sent == 0
        assert z2.msg_recv == 0

        z1.send_message(msg)
        z2.recv_message(callback)
        assert z1.msg_sent == 1
        assert z1.msg_recv == 0
        assert z2.msg_sent == 0
        assert z2.msg_recv == 1
Пример #6
0
def test_not_read_zmqlet():
    with MockBasePeaNotRead(args3), Zmqlet(args1, default_logger) as z:
        req = jina_pb2.RequestProto()
        req.request_id = get_random_identity()
        d = req.index.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        z.send_message(msg)
def test_recv_message_zmqlet(mocker):
    zmqlet1 = Zmqlet(args1, default_logger)
    zmqlet2 = Zmqlet(args2, default_logger)
    req = Request()
    req.request_id = random_identity()
    doc = req.data.docs.add()
    doc.tags['id'] = 2
    msg = Message(None, req, 'tmp', '')

    def callback(msg_):
        assert msg_.request.docs[0].tags['id'] == msg.request.data.docs[0].tags['id']

    mock = mocker.Mock()
    zmqlet1.send_message(msg)
    time.sleep(1)
    zmqlet2.recv_message(mock)
    validate_callback(mock, callback)
Пример #8
0
def test_read_zmqlet():
    with MockBasePeaRead(args2), Zmqlet(args1, default_logger) as z:
        req = jina_pb2.RequestProto()
        req.request_id = uuid.uuid1().hex
        d = req.index.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        z.send_message(msg)
Пример #9
0
def test_read_zmqlet():
    with MockBasePeaRead(args2), Zmqlet(args1, default_logger) as z:
        req = Request()
        req.request_id = random_identity()
        d = req.data.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        z.send_message(msg)
Пример #10
0
def test_not_decompressed_zmqlet(mocker):
    with MockPea(args2) as pea, Zmqlet(args1, default_logger) as z:
        req = Request()
        req.request_id = random_identity()
        d = req.data.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        mock = mocker.Mock()
        z.send_message(msg)
        time.sleep(1)
        z.recv_message(mock)

    def callback(msg_):
        pass

    validate_callback(mock, callback)
    print(f' joining pea')
    pea.join()
    print(f' joined pea')
Пример #11
0
def test_simple_zmqlet():
    args = set_pea_parser().parse_args(
        [
            '--host-in',
            '0.0.0.0',
            '--host-out',
            '0.0.0.0',
            '--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',
            str(args.port_out),
            '--port-out',
            str(args.port_in),
            '--socket-in',
            'PULL_BIND',
            '--socket-out',
            'PUSH_BIND',
            '--timeout-ctrl',
            '-1',
        ]
    )

    logger = JinaLogger('zmq-test')
    with BasePea(args2), Zmqlet(args, logger) as z:
        req = jina_pb2.RequestProto()
        req.request_id = random_identity()
        d = req.data.docs.add()
        d.tags['id'] = 2
        msg = Message(None, req, 'tmp', '')
        z.send_message(msg)