|
|
@ -115,6 +115,11 @@ class InsertPluginServerBuilderOption : public ServerBuilderOption { |
|
|
|
void UpdatePlugins( |
|
|
|
void UpdatePlugins( |
|
|
|
std::map<grpc::string, std::unique_ptr<ServerBuilderPlugin>>* plugins) |
|
|
|
std::map<grpc::string, std::unique_ptr<ServerBuilderPlugin>>* plugins) |
|
|
|
GRPC_OVERRIDE { |
|
|
|
GRPC_OVERRIDE { |
|
|
|
|
|
|
|
auto it = plugins->begin(); |
|
|
|
|
|
|
|
while (it != plugins->end()) { |
|
|
|
|
|
|
|
plugins->erase(it++); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<TestServerBuilderPlugin> plugin( |
|
|
|
std::unique_ptr<TestServerBuilderPlugin> plugin( |
|
|
|
new TestServerBuilderPlugin()); |
|
|
|
new TestServerBuilderPlugin()); |
|
|
|
if (register_service_) plugin->SetRegisterService(); |
|
|
|
if (register_service_) plugin->SetRegisterService(); |
|
|
@ -127,13 +132,24 @@ class InsertPluginServerBuilderOption : public ServerBuilderOption { |
|
|
|
bool register_service_; |
|
|
|
bool register_service_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
namespace sBPTestServerBuilderPlugin { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<ServerBuilderPlugin> CreateTestServerBuilderPlugin() { |
|
|
|
std::unique_ptr<ServerBuilderPlugin> CreateTestServerBuilderPlugin() { |
|
|
|
return std::unique_ptr<ServerBuilderPlugin>(new TestServerBuilderPlugin()); |
|
|
|
return std::unique_ptr<ServerBuilderPlugin>(new TestServerBuilderPlugin()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace sBPTestServerBuilderPlugin
|
|
|
|
void grpc_AddServerBuilderPlugin_reflection() { |
|
|
|
|
|
|
|
static bool already_here = false; |
|
|
|
|
|
|
|
if (already_here) return; |
|
|
|
|
|
|
|
already_here = true; |
|
|
|
|
|
|
|
::grpc::ServerBuilder::InternalAddPluginFactory( |
|
|
|
|
|
|
|
&CreateTestServerBuilderPlugin); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Force AddServerBuilderPlugin() to be called at static initialization time.
|
|
|
|
|
|
|
|
struct StaticPluginInitializer_reflection { |
|
|
|
|
|
|
|
StaticPluginInitializer_reflection() { |
|
|
|
|
|
|
|
grpc_AddServerBuilderPlugin_reflection(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} static_plugin_initializer_reflection_; |
|
|
|
|
|
|
|
|
|
|
|
class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { |
|
|
|
class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { |
|
|
|
public: |
|
|
|
public: |
|
|
@ -146,8 +162,7 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { |
|
|
|
|
|
|
|
|
|
|
|
void InsertPlugin() { |
|
|
|
void InsertPlugin() { |
|
|
|
if (GetParam()) { |
|
|
|
if (GetParam()) { |
|
|
|
// Add ServerBuilder plugin directly
|
|
|
|
// Add ServerBuilder plugin in static initialization
|
|
|
|
GRPC_INIT_PLUGIN(builder_->plugins_, TestServerBuilderPlugin); |
|
|
|
|
|
|
|
EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); |
|
|
|
EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Add ServerBuilder plugin using ServerBuilder::SetOption()
|
|
|
|
// Add ServerBuilder plugin using ServerBuilder::SetOption()
|
|
|
@ -158,8 +173,7 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { |
|
|
|
|
|
|
|
|
|
|
|
void InsertPluginWithTestService() { |
|
|
|
void InsertPluginWithTestService() { |
|
|
|
if (GetParam()) { |
|
|
|
if (GetParam()) { |
|
|
|
// Add ServerBuilder plugin directly
|
|
|
|
// Add ServerBuilder plugin in static initialization
|
|
|
|
GRPC_INIT_PLUGIN(builder_->plugins_, TestServerBuilderPlugin); |
|
|
|
|
|
|
|
EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); |
|
|
|
EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); |
|
|
|
auto plugin = static_cast<TestServerBuilderPlugin*>( |
|
|
|
auto plugin = static_cast<TestServerBuilderPlugin*>( |
|
|
|
builder_->plugins_[PLUGIN_NAME].get()); |
|
|
|
builder_->plugins_[PLUGIN_NAME].get()); |
|
|
|