|
|
|
@ -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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 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) { |
|
|
|
|
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()) { |
|
|
|
@ -72,7 +107,7 @@ void MaybeEchoDeadline(experimental::ServerContextBase* context, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CheckServerAuthContext( |
|
|
|
|
void static CheckServerAuthContext( |
|
|
|
|
const experimental::ServerContextBase* context, |
|
|
|
|
const grpc::string& expected_transport_security_type, |
|
|
|
|
const grpc::string& expected_client_identity) { |
|
|
|
@ -95,7 +130,7 @@ void CheckServerAuthContext( |
|
|
|
|
|
|
|
|
|
// 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( |
|
|
|
|
int static MetadataMatchCount( |
|
|
|
|
const std::multimap<grpc::string_ref, grpc::string_ref>& metadata, |
|
|
|
|
const grpc::string& key, const grpc::string& value) { |
|
|
|
|
int count = 0; |
|
|
|
@ -107,10 +142,8 @@ 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) { |
|
|
|
@ -123,14 +156,14 @@ 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"); |
|
|
|
@ -141,44 +174,6 @@ void ServerTryCancel(ServerContext* context) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // 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) { |
|
|
|
|