Skip to content
Snippets Groups Projects
Commit e0b94db1 authored by Esun Kim's avatar Esun Kim
Browse files

Enforce abstract class rule

parent 24e1deaf
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/channel/channel_trace.h" #include "src/core/lib/channel/channel_trace.h"
#include "src/core/lib/channel/channelz.h" #include "src/core/lib/channel/channelz.h"
...@@ -33,7 +34,6 @@ ...@@ -33,7 +34,6 @@
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/json/json.h" #include "src/core/lib/json/json.h"
#include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/channel.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#include <stdlib.h> #include <stdlib.h>
...@@ -51,9 +51,13 @@ class ChannelzRegistryTest : public ::testing::Test { ...@@ -51,9 +51,13 @@ class ChannelzRegistryTest : public ::testing::Test {
void TearDown() override { ChannelzRegistry::Shutdown(); } void TearDown() override { ChannelzRegistry::Shutdown(); }
}; };
static RefCountedPtr<BaseNode> CreateTestNode() {
return MakeRefCounted<ListenSocketNode>(UniquePtr<char>(gpr_strdup("test")),
UniquePtr<char>(gpr_strdup("test")));
}
TEST_F(ChannelzRegistryTest, UuidStartsAboveZeroTest) { TEST_F(ChannelzRegistryTest, UuidStartsAboveZeroTest) {
RefCountedPtr<BaseNode> channelz_channel = RefCountedPtr<BaseNode> channelz_channel = CreateTestNode();
MakeRefCounted<BaseNode>(BaseNode::EntityType::kTopLevelChannel, nullptr);
intptr_t uuid = channelz_channel->uuid(); intptr_t uuid = channelz_channel->uuid();
EXPECT_GT(uuid, 0) << "First uuid chose must be greater than zero. Zero if " EXPECT_GT(uuid, 0) << "First uuid chose must be greater than zero. Zero if "
"reserved according to " "reserved according to "
...@@ -65,8 +69,7 @@ TEST_F(ChannelzRegistryTest, UuidsAreIncreasing) { ...@@ -65,8 +69,7 @@ TEST_F(ChannelzRegistryTest, UuidsAreIncreasing) {
std::vector<RefCountedPtr<BaseNode>> channelz_channels; std::vector<RefCountedPtr<BaseNode>> channelz_channels;
channelz_channels.reserve(10); channelz_channels.reserve(10);
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
channelz_channels.push_back(MakeRefCounted<BaseNode>( channelz_channels.push_back(CreateTestNode());
BaseNode::EntityType::kTopLevelChannel, nullptr));
} }
for (size_t i = 1; i < channelz_channels.size(); ++i) { for (size_t i = 1; i < channelz_channels.size(); ++i) {
EXPECT_LT(channelz_channels[i - 1]->uuid(), channelz_channels[i]->uuid()) EXPECT_LT(channelz_channels[i - 1]->uuid(), channelz_channels[i]->uuid())
...@@ -75,8 +78,7 @@ TEST_F(ChannelzRegistryTest, UuidsAreIncreasing) { ...@@ -75,8 +78,7 @@ TEST_F(ChannelzRegistryTest, UuidsAreIncreasing) {
} }
TEST_F(ChannelzRegistryTest, RegisterGetTest) { TEST_F(ChannelzRegistryTest, RegisterGetTest) {
RefCountedPtr<BaseNode> channelz_channel = RefCountedPtr<BaseNode> channelz_channel = CreateTestNode();
MakeRefCounted<BaseNode>(BaseNode::EntityType::kTopLevelChannel, nullptr);
RefCountedPtr<BaseNode> retrieved = RefCountedPtr<BaseNode> retrieved =
ChannelzRegistry::Get(channelz_channel->uuid()); ChannelzRegistry::Get(channelz_channel->uuid());
EXPECT_EQ(channelz_channel, retrieved); EXPECT_EQ(channelz_channel, retrieved);
...@@ -85,8 +87,7 @@ TEST_F(ChannelzRegistryTest, RegisterGetTest) { ...@@ -85,8 +87,7 @@ TEST_F(ChannelzRegistryTest, RegisterGetTest) {
TEST_F(ChannelzRegistryTest, RegisterManyItems) { TEST_F(ChannelzRegistryTest, RegisterManyItems) {
std::vector<RefCountedPtr<BaseNode>> channelz_channels; std::vector<RefCountedPtr<BaseNode>> channelz_channels;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
channelz_channels.push_back(MakeRefCounted<BaseNode>( channelz_channels.push_back(CreateTestNode());
BaseNode::EntityType::kTopLevelChannel, nullptr));
RefCountedPtr<BaseNode> retrieved = RefCountedPtr<BaseNode> retrieved =
ChannelzRegistry::Get(channelz_channels[i]->uuid()); ChannelzRegistry::Get(channelz_channels[i]->uuid());
EXPECT_EQ(channelz_channels[i], retrieved); EXPECT_EQ(channelz_channels[i], retrieved);
...@@ -94,8 +95,7 @@ TEST_F(ChannelzRegistryTest, RegisterManyItems) { ...@@ -94,8 +95,7 @@ TEST_F(ChannelzRegistryTest, RegisterManyItems) {
} }
TEST_F(ChannelzRegistryTest, NullIfNotPresentTest) { TEST_F(ChannelzRegistryTest, NullIfNotPresentTest) {
RefCountedPtr<BaseNode> channelz_channel = RefCountedPtr<BaseNode> channelz_channel = CreateTestNode();
MakeRefCounted<BaseNode>(BaseNode::EntityType::kTopLevelChannel, nullptr);
// try to pull out a uuid that does not exist. // try to pull out a uuid that does not exist.
RefCountedPtr<BaseNode> nonexistant = RefCountedPtr<BaseNode> nonexistant =
ChannelzRegistry::Get(channelz_channel->uuid() + 1); ChannelzRegistry::Get(channelz_channel->uuid() + 1);
...@@ -117,10 +117,8 @@ TEST_F(ChannelzRegistryTest, TestUnregistration) { ...@@ -117,10 +117,8 @@ TEST_F(ChannelzRegistryTest, TestUnregistration) {
std::vector<RefCountedPtr<BaseNode>> odd_channels; std::vector<RefCountedPtr<BaseNode>> odd_channels;
odd_channels.reserve(kLoopIterations); odd_channels.reserve(kLoopIterations);
for (int i = 0; i < kLoopIterations; i++) { for (int i = 0; i < kLoopIterations; i++) {
even_channels.push_back(MakeRefCounted<BaseNode>( even_channels.push_back(CreateTestNode());
BaseNode::EntityType::kTopLevelChannel, nullptr)); odd_channels.push_back(CreateTestNode());
odd_channels.push_back(MakeRefCounted<BaseNode>(
BaseNode::EntityType::kTopLevelChannel, nullptr));
odd_uuids.push_back(odd_channels[i]->uuid()); odd_uuids.push_back(odd_channels[i]->uuid());
} }
} }
...@@ -137,8 +135,7 @@ TEST_F(ChannelzRegistryTest, TestUnregistration) { ...@@ -137,8 +135,7 @@ TEST_F(ChannelzRegistryTest, TestUnregistration) {
std::vector<RefCountedPtr<BaseNode>> more_channels; std::vector<RefCountedPtr<BaseNode>> more_channels;
more_channels.reserve(kLoopIterations); more_channels.reserve(kLoopIterations);
for (int i = 0; i < kLoopIterations; i++) { for (int i = 0; i < kLoopIterations; i++) {
more_channels.push_back(MakeRefCounted<BaseNode>( more_channels.push_back(CreateTestNode());
BaseNode::EntityType::kTopLevelChannel, nullptr));
RefCountedPtr<BaseNode> retrieved = RefCountedPtr<BaseNode> retrieved =
ChannelzRegistry::Get(more_channels[i]->uuid()); ChannelzRegistry::Get(more_channels[i]->uuid());
EXPECT_EQ(more_channels[i], retrieved); EXPECT_EQ(more_channels[i], retrieved);
......
...@@ -24,11 +24,23 @@ ...@@ -24,11 +24,23 @@
#include "src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h" #include "src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/ext/filters/client_channel/resolver_registry.h"
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/iomgr/combiner.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
static grpc_combiner* g_combiner; static grpc_combiner* g_combiner;
class TestResultHandler : public grpc_core::Resolver::ResultHandler {
void ReturnResult(grpc_core::Resolver::Result result) override {}
void ReturnError(grpc_error* error) override {}
};
static grpc_core::UniquePtr<grpc_core::Resolver::ResultHandler>
create_test_result_handler() {
return grpc_core::UniquePtr<grpc_core::Resolver::ResultHandler>(
grpc_core::New<TestResultHandler>());
}
static void test_succeeds(grpc_core::ResolverFactory* factory, static void test_succeeds(grpc_core::ResolverFactory* factory,
const char* string) { const char* string) {
gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
...@@ -39,8 +51,7 @@ static void test_succeeds(grpc_core::ResolverFactory* factory, ...@@ -39,8 +51,7 @@ static void test_succeeds(grpc_core::ResolverFactory* factory,
grpc_core::ResolverArgs args; grpc_core::ResolverArgs args;
args.uri = uri; args.uri = uri;
args.combiner = g_combiner; args.combiner = g_combiner;
args.result_handler = args.result_handler = create_test_result_handler();
grpc_core::MakeUnique<grpc_core::Resolver::ResultHandler>();
grpc_core::OrphanablePtr<grpc_core::Resolver> resolver = grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
factory->CreateResolver(std::move(args)); factory->CreateResolver(std::move(args));
GPR_ASSERT(resolver != nullptr); GPR_ASSERT(resolver != nullptr);
...@@ -57,8 +68,7 @@ static void test_fails(grpc_core::ResolverFactory* factory, ...@@ -57,8 +68,7 @@ static void test_fails(grpc_core::ResolverFactory* factory,
grpc_core::ResolverArgs args; grpc_core::ResolverArgs args;
args.uri = uri; args.uri = uri;
args.combiner = g_combiner; args.combiner = g_combiner;
args.result_handler = args.result_handler = create_test_result_handler();
grpc_core::MakeUnique<grpc_core::Resolver::ResultHandler>();
grpc_core::OrphanablePtr<grpc_core::Resolver> resolver = grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
factory->CreateResolver(std::move(args)); factory->CreateResolver(std::move(args));
GPR_ASSERT(resolver == nullptr); GPR_ASSERT(resolver == nullptr);
......
...@@ -233,6 +233,11 @@ class InterceptTrailingFactory : public LoadBalancingPolicyFactory { ...@@ -233,6 +233,11 @@ class InterceptTrailingFactory : public LoadBalancingPolicyFactory {
return kInterceptRecvTrailingMetadataLbPolicyName; return kInterceptRecvTrailingMetadataLbPolicyName;
} }
RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
const grpc_json* json, grpc_error** error) const override {
return nullptr;
}
private: private:
InterceptRecvTrailingMetadataCallback cb_; InterceptRecvTrailingMetadataCallback cb_;
void* user_data_; void* user_data_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment