|
|
|
@ -57,12 +57,47 @@ typedef enum { |
|
|
|
|
CANCEL_AFTER_PROCESSING |
|
|
|
|
} ServerTryCancelRequestPhase; |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
class TestServiceSignaller { |
|
|
|
|
public: |
|
|
|
|
void ClientWaitUntilRpcStarted() { |
|
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
cv_rpc_started_.wait(lock, [this] { return rpc_started_; }); |
|
|
|
|
} |
|
|
|
|
void ServerWaitToContinue() { |
|
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
cv_server_continue_.wait(lock, [this] { return server_should_continue_; }); |
|
|
|
|
} |
|
|
|
|
void SignalClientThatRpcStarted() { |
|
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
rpc_started_ = true; |
|
|
|
|
cv_rpc_started_.notify_one(); |
|
|
|
|
} |
|
|
|
|
void SignalServerToContinue() { |
|
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
server_should_continue_ = true; |
|
|
|
|
cv_server_continue_.notify_one(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// When echo_deadline is requested, deadline seen in the ServerContext is set in
|
|
|
|
|
// the response in seconds.
|
|
|
|
|
void MaybeEchoDeadline(experimental::ServerContextBase* context, |
|
|
|
|
const EchoRequest* request, EchoResponse* response) { |
|
|
|
|
private: |
|
|
|
|
std::mutex mu_; |
|
|
|
|
std::condition_variable cv_rpc_started_; |
|
|
|
|
bool rpc_started_ /* GUARDED_BY(mu_) */ = false; |
|
|
|
|
std::condition_variable cv_server_continue_; |
|
|
|
|
bool server_should_continue_ /* GUARDED_BY(mu_) */ = false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename RpcService> |
|
|
|
|
class TestMultipleServiceImpl : public RpcService { |
|
|
|
|
public: |
|
|
|
|
TestMultipleServiceImpl() : signal_client_(false), host_() {} |
|
|
|
|
explicit TestMultipleServiceImpl(const grpc::string& host) |
|
|
|
|
: signal_client_(false), host_(new grpc::string(host)) {} |
|
|
|
|
|
|
|
|
|
// When echo_deadline is requested, deadline seen in the ServerContext is set
|
|
|
|
|
// in the response in seconds.
|
|
|
|
|
void static MaybeEchoDeadline(experimental::ServerContextBase* context, |
|
|
|
|
const EchoRequest* request, |
|
|
|
|
EchoResponse* response) { |
|
|
|
|
if (request->has_param() && request->param().echo_deadline()) { |
|
|
|
|
gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); |
|
|
|
|
if (context->deadline() != system_clock::time_point::max()) { |
|
|
|
@ -70,9 +105,9 @@ void MaybeEchoDeadline(experimental::ServerContextBase* context, |
|
|
|
|
} |
|
|
|
|
response->mutable_param()->set_request_deadline(deadline.tv_sec); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CheckServerAuthContext( |
|
|
|
|
void static CheckServerAuthContext( |
|
|
|
|
const experimental::ServerContextBase* context, |
|
|
|
|
const grpc::string& expected_transport_security_type, |
|
|
|
|
const grpc::string& expected_client_identity) { |
|
|
|
@ -91,11 +126,11 @@ void CheckServerAuthContext( |
|
|
|
|
EXPECT_EQ(1u, identity.size()); |
|
|
|
|
EXPECT_EQ(expected_client_identity, identity[0]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Returns the number of pairs in metadata that exactly match the given
|
|
|
|
|
// key-value pair. Returns -1 if the pair wasn't found.
|
|
|
|
|
int MetadataMatchCount( |
|
|
|
|
// Returns the number of pairs in metadata that exactly match the given
|
|
|
|
|
// key-value pair. Returns -1 if the pair wasn't found.
|
|
|
|
|
int static MetadataMatchCount( |
|
|
|
|
const std::multimap<grpc::string_ref, grpc::string_ref>& metadata, |
|
|
|
|
const grpc::string& key, const grpc::string& value) { |
|
|
|
|
int count = 0; |
|
|
|
@ -106,11 +141,9 @@ int MetadataMatchCount( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return count; |
|
|
|
|
} |
|
|
|
|
} // namespace
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
int GetIntValueFromMetadataHelper( |
|
|
|
|
int static GetIntValueFromMetadataHelper( |
|
|
|
|
const char* key, |
|
|
|
|
const std::multimap<grpc::string_ref, grpc::string_ref>& metadata, |
|
|
|
|
int default_value) { |
|
|
|
@ -121,16 +154,16 @@ int GetIntValueFromMetadataHelper( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return default_value; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int GetIntValueFromMetadata( |
|
|
|
|
int static GetIntValueFromMetadata( |
|
|
|
|
const char* key, |
|
|
|
|
const std::multimap<grpc::string_ref, grpc::string_ref>& metadata, |
|
|
|
|
int default_value) { |
|
|
|
|
return GetIntValueFromMetadataHelper(key, metadata, default_value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ServerTryCancel(ServerContext* context) { |
|
|
|
|
void static ServerTryCancel(ServerContext* context) { |
|
|
|
|
EXPECT_FALSE(context->IsCancelled()); |
|
|
|
|
context->TryCancel(); |
|
|
|
|
gpr_log(GPR_INFO, "Server called TryCancel() to cancel the request"); |
|
|
|
@ -139,46 +172,8 @@ void ServerTryCancel(ServerContext* context) { |
|
|
|
|
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), |
|
|
|
|
gpr_time_from_micros(1000, GPR_TIMESPAN))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
class TestServiceSignaller { |
|
|
|
|
public: |
|
|
|
|
void ClientWaitUntilRpcStarted() { |
|
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
cv_rpc_started_.wait(lock, [this] { return rpc_started_; }); |
|
|
|
|
} |
|
|
|
|
void ServerWaitToContinue() { |
|
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
cv_server_continue_.wait(lock, [this] { return server_should_continue_; }); |
|
|
|
|
} |
|
|
|
|
void SignalClientThatRpcStarted() { |
|
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
rpc_started_ = true; |
|
|
|
|
cv_rpc_started_.notify_one(); |
|
|
|
|
} |
|
|
|
|
void SignalServerToContinue() { |
|
|
|
|
std::unique_lock<std::mutex> lock(mu_); |
|
|
|
|
server_should_continue_ = true; |
|
|
|
|
cv_server_continue_.notify_one(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
std::mutex mu_; |
|
|
|
|
std::condition_variable cv_rpc_started_; |
|
|
|
|
bool rpc_started_ /* GUARDED_BY(mu_) */ = false; |
|
|
|
|
std::condition_variable cv_server_continue_; |
|
|
|
|
bool server_should_continue_ /* GUARDED_BY(mu_) */ = false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename RpcService> |
|
|
|
|
class TestMultipleServiceImpl : public RpcService { |
|
|
|
|
public: |
|
|
|
|
TestMultipleServiceImpl() : signal_client_(false), host_() {} |
|
|
|
|
explicit TestMultipleServiceImpl(const grpc::string& host) |
|
|
|
|
: signal_client_(false), host_(new grpc::string(host)) {} |
|
|
|
|
|
|
|
|
|
Status Echo(ServerContext* context, const EchoRequest* request, |
|
|
|
|
EchoResponse* response) { |
|
|
|
|
if (request->has_param() && |
|
|
|
@ -311,6 +306,7 @@ class TestMultipleServiceImpl : public RpcService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Unimplemented is left unimplemented to test the returned error.
|
|
|
|
|
|
|
|
|
|
Status RequestStream(ServerContext* context, |
|
|
|
|
ServerReader<EchoRequest>* reader, |
|
|
|
|
EchoResponse* response) { |
|
|
|
|