1 #include "include/rados/librados.h"
2 #include "include/rados/librados.hpp"
3 #include "test/librados/test.h"
4 #include "test/librados/TestCase.h"
5 #include "include/stringify.h"
9 #include "gtest/gtest.h"
10 #include "test/unit.cc"
12 using namespace librados;
14 TEST(LibRadosService, RegisterEarly) {
16 ASSERT_EQ(0, rados_create(&cluster, "admin"));
17 ASSERT_EQ(0, rados_conf_read_file(cluster, NULL));
18 ASSERT_EQ(0, rados_conf_parse_env(cluster, NULL));
20 string name = string("pid") + stringify(getpid());
21 ASSERT_EQ(0, rados_service_register(cluster, "laundry", name.c_str(),
22 "foo\0bar\0this\0that\0"));
23 ASSERT_EQ(-EEXIST, rados_service_register(cluster, "laundry", name.c_str(),
24 "foo\0bar\0this\0that\0"));
26 ASSERT_EQ(0, rados_connect(cluster));
28 rados_shutdown(cluster);
31 TEST(LibRadosService, RegisterLate) {
33 ASSERT_EQ(0, rados_create(&cluster, "admin"));
34 ASSERT_EQ(0, rados_conf_read_file(cluster, NULL));
35 ASSERT_EQ(0, rados_conf_parse_env(cluster, NULL));
36 ASSERT_EQ(0, rados_connect(cluster));
38 string name = string("pid") + stringify(getpid());
39 ASSERT_EQ(0, rados_service_register(cluster, "laundry", name.c_str(),
40 "foo\0bar\0this\0that\0"));
41 ASSERT_EQ(-EEXIST, rados_service_register(cluster, "laundry", name.c_str(),
42 "foo\0bar\0this\0that\0"));
43 rados_shutdown(cluster);
46 TEST(LibRadosService, Status) {
48 ASSERT_EQ(0, rados_create(&cluster, "admin"));
49 ASSERT_EQ(0, rados_conf_read_file(cluster, NULL));
50 ASSERT_EQ(0, rados_conf_parse_env(cluster, NULL));
52 ASSERT_EQ(-ENOTCONN, rados_service_update_status(cluster,
53 "testing\0testing\0"));
55 ASSERT_EQ(0, rados_connect(cluster));
56 string name = string("pid") + stringify(getpid());
57 ASSERT_EQ(0, rados_service_register(cluster, "laundry", name.c_str(),
58 "foo\0bar\0this\0that\0"));
60 for (int i=0; i<20; ++i) {
62 snprintf(buffer, sizeof(buffer), "%s%c%s%c%s%c%d%c",
63 "testing", '\0', "testing", '\0',
64 "count", '\0', i, '\0');
65 ASSERT_EQ(0, rados_service_update_status(cluster, buffer));
68 rados_shutdown(cluster);
71 TEST(LibRadosServicePP, RegisterEarly) {
73 cluster.init("admin");
74 ASSERT_EQ(0, cluster.conf_read_file(NULL));
75 cluster.conf_parse_env(NULL);
76 string name = string("pid") + stringify(getpid());
77 ASSERT_EQ(0, cluster.service_daemon_register(
78 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
79 ASSERT_EQ(-EEXIST, cluster.service_daemon_register(
80 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
81 ASSERT_EQ(0, cluster.connect());
86 TEST(LibRadosServicePP, RegisterLate) {
88 cluster.init("admin");
89 ASSERT_EQ(0, cluster.conf_read_file(NULL));
90 cluster.conf_parse_env(NULL);
91 ASSERT_EQ("", connect_cluster_pp(cluster));
92 string name = string("pid") + stringify(getpid());
93 ASSERT_EQ(0, cluster.service_daemon_register(
94 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
97 TEST(LibRadosServicePP, Status) {
99 cluster.init("admin");
100 ASSERT_EQ(0, cluster.conf_read_file(NULL));
101 cluster.conf_parse_env(NULL);
102 string name = string("pid") + stringify(getpid());
103 ASSERT_EQ(-ENOTCONN, cluster.service_daemon_update_status(
104 {{"testing", "starting"}}));
105 ASSERT_EQ(0, cluster.connect());
106 ASSERT_EQ(0, cluster.service_daemon_register(
107 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
108 for (int i=0; i<20; ++i) {
109 ASSERT_EQ(0, cluster.service_daemon_update_status({
110 {"testing", "running"},
111 {"count", stringify(i)}