MCPcopy Create free account
hub / github.com/apache/arrow / SetUp

Method SetUp

cpp/src/arrow/flight/flight_test.cc:458–690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

456class TestTls : public ::testing::Test {
457 public:
458 void SetUp() {
459 // Manually initialize gRPC to try to ensure some thread-locals
460 // get initialized.
461 // https://github.com/grpc/grpc/issues/13856
462 // https://github.com/grpc/grpc/issues/20311
463 // In general, gRPC on macOS struggles with TLS (both in the sense
464 // of thread-locals and encryption)
465 grpc_init();
466
467 server_.reset(new TlsTestServer);
468
469 ASSERT_OK_AND_ASSIGN(auto location, Location::ForGrpcTls("localhost", 0));
470 FlightServerOptions options(location);
471 ASSERT_RAISES(UnknownError, server_->Init(options));
472 ASSERT_OK(ExampleTlsCertificates(&options.tls_certificates));
473 ASSERT_OK(server_->Init(options));
474 server_is_initialized_ = true;
475
476 ASSERT_OK_AND_ASSIGN(location_, Location::ForGrpcTls("localhost", server_->port()));
477 ASSERT_OK(ConnectClient());
478 }
479
480 void TearDown() {
481 if (client_) {
482 ASSERT_OK(client_->Close());
483 }
484 if (server_is_initialized_) {
485 ASSERT_OK(server_->Shutdown());
486 }
487 grpc_shutdown();
488 }
489
490 Status ConnectClient() {
491 auto options = FlightClientOptions::Defaults();
492 CertKeyPair root_cert;
493 RETURN_NOT_OK(ExampleTlsCertificateRoot(&root_cert));
494 options.tls_root_certs = root_cert.pem_cert;
495 return FlightClient::Connect(location_, options).Value(&client_);
496 }
497
498 protected:
499 Location location_;
500 std::unique_ptr<FlightClient> client_;
501 std::unique_ptr<FlightServerBase> server_;
502 bool server_is_initialized_ = false;
503};
504
505// A server middleware that rejects all calls.
506class RejectServerMiddlewareFactory : public ServerMiddlewareFactory {
507 Status StartCall(const CallInfo& info, const ServerCallContext& context,
508 std::shared_ptr<ServerMiddleware>* middleware) override {
509 return MakeFlightError(FlightStatusCode::Unauthenticated, "All calls are rejected");
510 }
511};
512
513// A server middleware that counts the number of successful and failed
514// calls.
515class CountingServerMiddleware : public ServerMiddleware {

Callers

nothing calls this directly

Calls 1

resetMethod · 0.45

Tested by

no test coverage detected