def test_pymode(self): args = set_frontend_parser().parse_args([]) p_args = set_preprocessor_parser().parse_args([ '--port_in', str(args.port_out), '--port_out', '5531', '--socket_in', str(SocketType.PULL_CONNECT), '--socket_out', str(SocketType.PUSH_BIND), '--yaml_path', '!UnaryPreprocessor {parameters: {doc_type: 1}}' ]) e_args = set_encoder_parser().parse_args([ '--port_in', str(p_args.port_out), '--port_out', str(args.port_in), '--socket_in', str(SocketType.PULL_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT), '--yaml_path', 'flair.yml', ]) with ServiceManager(EncoderService, e_args), \ ServiceManager(PreprocessorService, p_args), \ FrontendService(args), \ grpc.insecure_channel('%s:%s' % (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.index([b'hello world', b'goodbye!'], 1))[0]) self.assertEqual(resp.request_id, '0')
def test_pymode(self): args = set_frontend_parser().parse_args([]) p_args = set_preprocessor_parser().parse_args([ '--port_in', str(args.port_out), '--port_out', '5531', '--socket_in', str(SocketType.PULL_CONNECT), '--socket_out', str(SocketType.PUSH_BIND), '--yaml_path', 'SentSplitPreprocessor' ]) e_args = set_encoder_parser().parse_args([ '--port_in', str(p_args.port_out), '--port_out', str(args.port_in), '--socket_in', str(SocketType.PULL_CONNECT), '--socket_out', str(SocketType.PUSH_CONNECT), '--yaml_path', 'transformer.yml', '--py_path', 'distilbert.py' ]) with ServiceManager(EncoderService, e_args), \ ServiceManager(PreprocessorService, p_args), \ FrontendService(args), \ grpc.insecure_channel('%s:%s' % (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.index([ b'hello world, good to see you.', b'goodbye! wish to see you again!' ], 1))[0]) self.assertEqual(resp.request_id, 0)
def test_external_module(self): args = set_encoder_parser().parse_args([ '--yaml_path', os.path.join(self.dir_path, 'contrib', 'dummy.yml'), '--py_path', os.path.join(self.dir_path, 'contrib', 'dummy_contrib.py'), ]) with ServiceManager(RouterService, args): pass
def test_external_module(self): args = set_encoder_parser().parse_args([ '--yaml_path', os.path.join(self.dir_path, 'contrib', 'dummy.yml'), '--py_path', os.path.join(self.dir_path, 'contrib', 'dummy_contrib.py'), ]) with ServiceManager(RouterService, args): pass self.assertTrue(os.path.exists('foo_contrib_encoder.bin')) os.remove('foo_contrib_encoder.bin')
def test_empty_service(self): args = set_encoder_parser().parse_args(['--yaml_path', '!TestEncoder {gnes_config: {name: EncoderService, is_trained: true}}']) c_args = _set_client_parser().parse_args([ '--port_in', str(args.port_out), '--port_out', str(args.port_in)]) with ServiceManager(EncoderService, args), ZmqClient(c_args) as client: msg = gnes_pb2.Message() d = msg.request.index.docs.add() d.doc_type = gnes_pb2.Document.IMAGE c = d.chunks.add() c.blob.CopyFrom(array2blob(self.test_numeric)) client.send_message(msg) r = client.recv_message() self.assertEqual(len(r.request.index.docs), 1) self.assertEqual(r.response.index.status, gnes_pb2.Response.SUCCESS)
def test_empty_service(self): args = set_encoder_parser().parse_args([ '--yaml_path', self.yaml_path ]) with ServiceManager(EncoderService, args): pass