aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/channel
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-07-13 12:09:55 -0700
committerGravatar ncteisen <ncteisen@gmail.com>2018-07-15 22:25:17 -0700
commit9a6c722e301be70715fa4f16cea22d172d605615 (patch)
tree48cf910926b9b8786cbb8d2f04e94bae165adb41 /test/core/channel
parent4f840eafecfed75aeee50ff850eaa79094cde248 (diff)
Rewrite registry to know type
Diffstat (limited to 'test/core/channel')
-rw-r--r--test/core/channel/channelz_registry_test.cc102
1 files changed, 56 insertions, 46 deletions
diff --git a/test/core/channel/channelz_registry_test.cc b/test/core/channel/channelz_registry_test.cc
index 24e50933d7..06363d00e2 100644
--- a/test/core/channel/channelz_registry_test.cc
+++ b/test/core/channel/channelz_registry_test.cc
@@ -19,17 +19,20 @@
#include <stdlib.h>
#include <string.h>
+#include <grpc/grpc.h>
#include <gtest/gtest.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_trace.h"
+#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/channel/channelz_registry.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/json/json.h"
+#include "src/core/lib/surface/channel.h"
#include "test/core/util/test_config.h"
@@ -37,27 +40,55 @@
#include <string.h>
namespace grpc_core {
+namespace channelz {
namespace testing {
+namespace {
+
+class ChannelFixture {
+ public:
+ ChannelFixture() {
+ grpc_arg client_a[1];
+ client_a[0].type = GRPC_ARG_INTEGER;
+ client_a[0].key = const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ);
+ client_a[0].value.integer = true;
+ grpc_channel_args client_args = {GPR_ARRAY_SIZE(client_a), client_a};
+ channel_ =
+ grpc_insecure_channel_create("fake_target", &client_args, nullptr);
+ }
+
+ ~ChannelFixture() { grpc_channel_destroy(channel_); }
+
+ grpc_channel* channel() { return channel_; }
+
+ private:
+ grpc_channel* channel_;
+};
+
+} // namespace
// Tests basic ChannelTrace functionality like construction, adding trace, and
// lookups by uuid.
TEST(ChannelzRegistryTest, UuidStartsAboveZeroTest) {
- int object_to_register;
- intptr_t uuid = ChannelzRegistry::Register(&object_to_register);
+ ChannelFixture channel;
+ ChannelNode* channelz_channel =
+ grpc_channel_get_channelz_node(channel.channel());
+ intptr_t uuid = ChannelzRegistry::RegisterChannelNode(channelz_channel);
EXPECT_GT(uuid, 0) << "First uuid chose must be greater than zero. Zero if "
"reserved according to "
"https://github.com/grpc/proposal/blob/master/"
"A14-channelz.md";
- ChannelzRegistry::Unregister(uuid);
+ ChannelzRegistry::UnregisterChannelNode(uuid);
}
TEST(ChannelzRegistryTest, UuidsAreIncreasing) {
- int object_to_register;
+ ChannelFixture channel;
+ ChannelNode* channelz_channel =
+ grpc_channel_get_channelz_node(channel.channel());
std::vector<intptr_t> uuids;
uuids.reserve(10);
for (int i = 0; i < 10; ++i) {
// reregister the same object. It's ok since we are just testing uuids
- uuids.push_back(ChannelzRegistry::Register(&object_to_register));
+ uuids.push_back(ChannelzRegistry::RegisterChannelNode(channelz_channel));
}
for (size_t i = 1; i < uuids.size(); ++i) {
EXPECT_LT(uuids[i - 1], uuids[i]) << "Uuids must always be increasing";
@@ -65,60 +96,39 @@ TEST(ChannelzRegistryTest, UuidsAreIncreasing) {
}
TEST(ChannelzRegistryTest, RegisterGetTest) {
- int object_to_register = 42;
- intptr_t uuid = ChannelzRegistry::Register(&object_to_register);
- int* retrieved = ChannelzRegistry::Get<int>(uuid);
- EXPECT_EQ(&object_to_register, retrieved);
-}
-
-TEST(ChannelzRegistryTest, MultipleTypeTest) {
- int int_to_register = 42;
- intptr_t int_uuid = ChannelzRegistry::Register(&int_to_register);
- std::string str_to_register = "hello world";
- intptr_t str_uuid = ChannelzRegistry::Register(&str_to_register);
- int* retrieved_int = ChannelzRegistry::Get<int>(int_uuid);
- std::string* retrieved_str = ChannelzRegistry::Get<std::string>(str_uuid);
- EXPECT_EQ(&int_to_register, retrieved_int);
- EXPECT_EQ(&str_to_register, retrieved_str);
+ ChannelFixture channel;
+ ChannelNode* channelz_channel =
+ grpc_channel_get_channelz_node(channel.channel());
+ intptr_t uuid = ChannelzRegistry::RegisterChannelNode(channelz_channel);
+ ChannelNode* retrieved = ChannelzRegistry::GetChannelNode(uuid);
+ EXPECT_EQ(channelz_channel, retrieved);
}
TEST(ChannelzRegistryTest, RegisterManyItems) {
- int object_to_register = 42;
+ ChannelFixture channel;
+ ChannelNode* channelz_channel =
+ grpc_channel_get_channelz_node(channel.channel());
for (int i = 0; i < 100; i++) {
- intptr_t uuid = ChannelzRegistry::Register(&object_to_register);
- int* retrieved = ChannelzRegistry::Get<int>(uuid);
- EXPECT_EQ(&object_to_register, retrieved);
+ intptr_t uuid = ChannelzRegistry::RegisterChannelNode(channelz_channel);
+ ChannelNode* retrieved = ChannelzRegistry::GetChannelNode(uuid);
+ EXPECT_EQ(channelz_channel, retrieved);
}
}
-namespace {
-class Foo {
- public:
- int bar;
-};
-} // namespace
-
-TEST(ChannelzRegistryTest, CustomObjectTest) {
- Foo* foo = New<Foo>();
- foo->bar = 1024;
- intptr_t uuid = ChannelzRegistry::Register(foo);
- Foo* retrieved = ChannelzRegistry::Get<Foo>(uuid);
- EXPECT_EQ(foo, retrieved);
- Delete(foo);
-}
-
TEST(ChannelzRegistryTest, NullIfNotPresentTest) {
- int object_to_register = 42;
- intptr_t uuid = ChannelzRegistry::Register(&object_to_register);
+ ChannelFixture channel;
+ ChannelNode* channelz_channel =
+ grpc_channel_get_channelz_node(channel.channel());
+ intptr_t uuid = ChannelzRegistry::RegisterChannelNode(channelz_channel);
// try to pull out a uuid that does not exist.
- int* nonexistant = ChannelzRegistry::Get<int>(uuid + 1);
+ ChannelNode* nonexistant = ChannelzRegistry::GetChannelNode(uuid + 1);
EXPECT_EQ(nonexistant, nullptr);
- int* retrieved = ChannelzRegistry::Get<int>(uuid);
- EXPECT_EQ(object_to_register, *retrieved);
- EXPECT_EQ(&object_to_register, retrieved);
+ ChannelNode* retrieved = ChannelzRegistry::GetChannelNode(uuid);
+ EXPECT_EQ(channelz_channel, retrieved);
}
} // namespace testing
+} // namespace channelz
} // namespace grpc_core
int main(int argc, char** argv) {