def _test_grpc_multiple_pub(self, backend='thread', num_parallel=5):
        args = set_frontend_parser().parse_args([
            '--grpc_host',
            '127.0.0.1',
        ])

        p_args = set_router_parser().parse_args([
            '--port_in',
            str(args.port_out), '--port_out',
            str(args.port_in), '--socket_in',
            str(SocketType.PULL_CONNECT), '--socket_out',
            str(SocketType.PUSH_CONNECT), '--yaml_path', 'BaseRouter',
            '--num_parallel',
            str(num_parallel), '--parallel_backend', backend,
            '--parallel_type',
            str(ParallelType.PUB_BLOCK)
        ])

        with ServiceManager(
                RouterService,
                p_args), FrontendService(args), grpc.insecure_channel(
                    '%s:%d' % (args.grpc_host, args.grpc_port),
                    options=[
                        ('grpc.max_send_message_length', 70 * 1024 * 1024),
                        ('grpc.max_receive_message_length', 70 * 1024 * 1024)
                    ]) as channel:
            stub = gnes_pb2_grpc.GnesRPCStub(channel)
            resp = stub.Call(list(RequestGenerator.query(b'abc', 1))[0])
            self.assertEqual(resp.request_id, 0)
    def test_grpc_real_service(self):
        # to fix

        with DummyServer('%s:%d' % (self.s_args.grpc_host, self.s_args.grpc_port)), GRPCService(
                self.s_args), FrontendService(self.args), grpc.insecure_channel(
            '%s:%s' % (self.args.grpc_host, self.args.grpc_port),
            options=[('grpc.max_send_message_length', 70 * 1024 * 1024),
                     ('grpc.max_receive_message_length', 70 * 1024 * 1024)]) as channel:
            stub = gnes_pb2_grpc.GnesRPCStub(channel)
            resp = stub.Call(list(RequestGenerator.query(b'abc', 1))[0])
            self.assertEqual(resp.request_id, 0)  # idx start with 0, but +1 for final FLUSH
Exemple #3
0
 def query(self, all_bytes: List[bytes], stub):
     for idx, q in enumerate(all_bytes):
         for req in RequestGenerator.query(q,
                                           request_id_start=idx,
                                           top_k=self.args.top_k):
             resp = stub.Call(req)
             print(colored(req.search.query, 'green'))
             for k in resp.search.topk_results:
                 print(colored(k.doc.doc_id, 'magenta'))
                 print(colored(k.doc.raw_text, 'yellow'))
                 print(colored(k.score.value, 'blue'))
                 pprint.pprint(json.loads(k.score.explained))
                 input('press any key to continue...')
             input('on to next query, press any key to continue...')