Rename GetSendMessage to GetSerializedSendMessage and GetOriginalSendMessage to GetSendMessage

pull/17609/head
Yash Tibrewal 6 years ago
parent c6261f4b91
commit 50c60f03ba
  1. 4
      include/grpcpp/impl/codegen/interceptor.h
  2. 8
      include/grpcpp/impl/codegen/interceptor_common.h
  3. 15
      test/cpp/end2end/client_interceptors_end2end_test.cc
  4. 25
      test/cpp/end2end/server_interceptors_end2end_test.cc

@ -109,13 +109,13 @@ class InterceptorBatchMethods {
/// Returns a modifable ByteBuffer holding the serialized form of the message
/// that is going to be sent. Valid for PRE_SEND_MESSAGE interceptions.
/// A return value of nullptr indicates that this ByteBuffer is not valid.
virtual ByteBuffer* GetSendMessage() = 0;
virtual ByteBuffer* GetSerializedSendMessage() = 0;
/// Returns a non-modifiable pointer to the original non-serialized form of
/// the message. Valid for PRE_SEND_MESSAGE interceptions. A return value of
/// nullptr indicates that this field is not valid. Also note that this is
/// only supported for sync and callback APIs at the present moment.
virtual const void* GetOriginalSendMessage() = 0;
virtual const void* GetSendMessage() = 0;
/// Returns a modifiable multimap of the initial metadata to be sent. Valid
/// for PRE_SEND_INITIAL_METADATA interceptions. A value of nullptr indicates

@ -79,9 +79,9 @@ class InterceptorBatchMethodsImpl
hooks_[static_cast<size_t>(type)] = true;
}
ByteBuffer* GetSendMessage() override { return send_message_; }
ByteBuffer* GetSerializedSendMessage() override { return send_message_; }
const void* GetOriginalSendMessage() override { return orig_send_message_; }
const void* GetSendMessage() override { return orig_send_message_; }
std::multimap<grpc::string, grpc::string>* GetSendInitialMetadata() override {
return send_initial_metadata_;
@ -385,14 +385,14 @@ class CancelInterceptorBatchMethods
"Cancel notification");
}
ByteBuffer* GetSendMessage() override {
ByteBuffer* GetSerializedSendMessage() override {
GPR_CODEGEN_ASSERT(false &&
"It is illegal to call GetSendMessage on a method which "
"has a Cancel notification");
return nullptr;
}
const void* GetOriginalSendMessage() override {
const void* GetSendMessage() override {
GPR_CODEGEN_ASSERT(
false &&
"It is illegal to call GetOriginalSendMessage on a method which "

@ -68,7 +68,7 @@ class HijackingInterceptor : public experimental::Interceptor {
if (methods->QueryInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)) {
EchoRequest req;
auto* buffer = methods->GetSendMessage();
auto* buffer = methods->GetSerializedSendMessage();
auto copied_buffer = *buffer;
EXPECT_TRUE(
SerializationTraits<EchoRequest>::Deserialize(&copied_buffer, &req)
@ -173,7 +173,7 @@ class HijackingInterceptorMakesAnotherCall : public experimental::Interceptor {
if (methods->QueryInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)) {
EchoRequest req;
auto* buffer = methods->GetSendMessage();
auto* buffer = methods->GetSerializedSendMessage();
auto copied_buffer = *buffer;
EXPECT_TRUE(
SerializationTraits<EchoRequest>::Deserialize(&copied_buffer, &req)
@ -287,17 +287,16 @@ class LoggingInterceptor : public experimental::Interceptor {
if (methods->QueryInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)) {
EchoRequest req;
auto* buffer = methods->GetSendMessage();
auto* buffer = methods->GetSerializedSendMessage();
auto copied_buffer = *buffer;
EXPECT_TRUE(
SerializationTraits<EchoRequest>::Deserialize(&copied_buffer, &req)
.ok());
EXPECT_TRUE(req.message().find("Hello") == 0u);
EXPECT_EQ(
static_cast<const EchoRequest*>(methods->GetOriginalSendMessage())
->message()
.find("Hello"),
0u);
EXPECT_EQ(static_cast<const EchoRequest*>(methods->GetSendMessage())
->message()
.find("Hello"),
0u);
}
if (methods->QueryInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_CLOSE)) {

@ -83,7 +83,7 @@ class LoggingInterceptor : public experimental::Interceptor {
if (methods->QueryInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)) {
EchoRequest req;
auto* buffer = methods->GetSendMessage();
auto* buffer = methods->GetSerializedSendMessage();
auto copied_buffer = *buffer;
EXPECT_TRUE(
SerializationTraits<EchoRequest>::Deserialize(&copied_buffer, &req)
@ -142,30 +142,29 @@ class LoggingInterceptorFactory
}
};
// Test if GetOriginalSendMessage works as expected
class GetOriginalSendMessageTester : public experimental::Interceptor {
// Test if GetSendMessage works as expected
class GetSendMessageTester : public experimental::Interceptor {
public:
GetOriginalSendMessageTester(experimental::ServerRpcInfo* info) {}
GetSendMessageTester(experimental::ServerRpcInfo* info) {}
void Intercept(experimental::InterceptorBatchMethods* methods) override {
if (methods->QueryInterceptionHookPoint(
experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)) {
EXPECT_EQ(
static_cast<const EchoRequest*>(methods->GetOriginalSendMessage())
->message()
.find("Hello"),
0u);
EXPECT_EQ(static_cast<const EchoRequest*>(methods->GetSendMessage())
->message()
.find("Hello"),
0u);
}
methods->Proceed();
}
};
class GetOriginalSendMessageTesterFactory
class GetSendMessageTesterFactory
: public experimental::ServerInterceptorFactoryInterface {
public:
virtual experimental::Interceptor* CreateServerInterceptor(
experimental::ServerRpcInfo* info) override {
return new GetOriginalSendMessageTester(info);
return new GetSendMessageTester(info);
}
};
@ -205,7 +204,7 @@ class ServerInterceptorsEnd2endSyncUnaryTest : public ::testing::Test {
new LoggingInterceptorFactory()));
creators.push_back(
std::unique_ptr<experimental::ServerInterceptorFactoryInterface>(
new GetOriginalSendMessageTesterFactory()));
new GetSendMessageTesterFactory()));
// Add 20 dummy interceptor factories and null interceptor factories
for (auto i = 0; i < 20; i++) {
creators.push_back(std::unique_ptr<DummyInterceptorFactory>(
@ -248,7 +247,7 @@ class ServerInterceptorsEnd2endSyncStreamingTest : public ::testing::Test {
new LoggingInterceptorFactory()));
creators.push_back(
std::unique_ptr<experimental::ServerInterceptorFactoryInterface>(
new GetOriginalSendMessageTesterFactory()));
new GetSendMessageTesterFactory()));
for (auto i = 0; i < 20; i++) {
creators.push_back(std::unique_ptr<DummyInterceptorFactory>(
new DummyInterceptorFactory()));

Loading…
Cancel
Save