-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathnighthawk_service_client_impl.cc
42 lines (35 loc) · 1.63 KB
/
nighthawk_service_client_impl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "source/common/nighthawk_service_client_impl.h"
#include "external/envoy/source/common/common/assert.h"
namespace Nighthawk {
absl::StatusOr<nighthawk::client::ExecutionResponse>
NighthawkServiceClientImpl::PerformNighthawkBenchmark(
nighthawk::client::NighthawkService::StubInterface* nighthawk_service_stub,
const nighthawk::client::CommandLineOptions& command_line_options) const {
nighthawk::client::ExecutionRequest request;
nighthawk::client::ExecutionResponse response;
*request.mutable_start_request()->mutable_options() = command_line_options;
grpc::ClientContext context;
std::shared_ptr<grpc::ClientReaderWriterInterface<nighthawk::client::ExecutionRequest,
nighthawk::client::ExecutionResponse>>
stream(nighthawk_service_stub->ExecutionStream(&context));
if (!stream->Write(request)) {
return absl::UnavailableError("Failed to write request to the Nighthawk Service gRPC channel.");
} else if (!stream->WritesDone()) {
return absl::InternalError("WritesDone() failed on the Nighthawk Service gRPC channel.");
}
bool got_response = false;
while (stream->Read(&response)) {
RELEASE_ASSERT(!got_response,
"Nighthawk Service has started responding with more than one message.");
got_response = true;
}
if (!got_response) {
return absl::InternalError("Nighthawk Service did not send a gRPC response.");
}
grpc::Status status = stream->Finish();
if (!status.ok()) {
return absl::Status(static_cast<absl::StatusCode>(status.error_code()), status.error_message());
}
return response;
}
} // namespace Nighthawk