def test_envelope_in_sep_request(): """ ser/des on envelope only much faster :return: """ recv = [(rr.envelope, rr.request.SerializeToString()) for rr in (add_envelope(r, 'test', '123') for r in _generate(random_docs(num_docs)))] with TimeContext('serialize and deserialize'): for _ in range( num_reqs ): # mimic chaining _pass, no need to deserialize request sent = [(msg[0].SerializeToString(), msg[1]) for msg in recv] # mimic sent # mimic receive recv.clear() for m in sent: msg = jina_pb2.EnvelopeProto() msg.ParseFromString(m[0]) msg.request_id += 'r' recv.append((msg, m[1])) for r in recv: assert r[0].request_id.endswith('r' * num_reqs)
def _add_envelope(self, msg, routing_table): if not self._static_routing_table: new_envelope = jina_pb2.EnvelopeProto() new_envelope.CopyFrom(msg.envelope) new_envelope.routing_table.CopyFrom(routing_table.proto) new_message = Message(request=msg.request, envelope=new_envelope) return new_message else: return msg
def test_lazy_msg_access_with_envelope(): envelope_proto = jina_pb2.EnvelopeProto() envelope_proto.compression.algorithm = 'NONE' envelope_proto.request_type = 'DataRequest' messages = [ Message( envelope_proto, r.SerializeToString(), ) for r in request_generator('/', random_docs(10)) ] for m in messages: assert not m.request.is_decompressed assert m.envelope assert len(m.dump()) == 3 assert not m.request.is_decompressed assert m.request._pb_body is None assert m.request._buffer is not None assert m.proto assert m.request.is_decompressed assert m.request._pb_body is not None assert m.request._buffer is None