arrow::Status TestCustomGrpcImpl()

in cpp/code/flight.cc [346:393]


arrow::Status TestCustomGrpcImpl() {
  // Build flight service as usual
  auto fs = std::make_shared<arrow::fs::LocalFileSystem>();
  ARROW_RETURN_NOT_OK(fs->CreateDir("./flight_datasets/"));
  ARROW_RETURN_NOT_OK(fs->DeleteDirContents("./flight_datasets/"));
  auto root = std::make_shared<arrow::fs::SubTreeFileSystem>("./flight_datasets/", fs);

  StartRecipe("CustomGrpcImpl::StartServer");
  arrow::flight::Location server_location;
  ARROW_ASSIGN_OR_RAISE(server_location,
      arrow::flight::Location::ForGrpcTcp("0.0.0.0", 5000));

  arrow::flight::FlightServerOptions options(server_location);
  auto server = std::unique_ptr<arrow::flight::FlightServerBase>(
      new ParquetStorageService(std::move(root)));

  // Create hello world service
  HelloWorldServiceImpl grpc_service;

  // Use builder_hook to register grpc service
  options.builder_hook = [&](void* raw_builder) {
    auto* builder = reinterpret_cast<grpc::ServerBuilder*>(raw_builder);
    builder->RegisterService(&grpc_service);
  };

  ARROW_RETURN_NOT_OK(server->Init(options));
  rout << "Listening on port " << server->port() << std::endl;
  EndRecipe("CustomGrpcImpl::StartServer");

  StartRecipe("CustomGrpcImpl::CreateClient");
  auto client_channel =
      grpc::CreateChannel("0.0.0.0:5000", grpc::InsecureChannelCredentials());

  auto stub = HelloWorldService::NewStub(client_channel);

  grpc::ClientContext context;
  HelloRequest request;
  request.set_name("Arrow User");
  HelloResponse response;
  grpc::Status status = stub->SayHello(&context, request, &response);
  if (!status.ok()) {
    return arrow::Status::IOError(status.error_message());
  }
  rout << response.reply();

  EndRecipe("CustomGrpcImpl::CreateClient");
  return arrow::Status::OK();
}