]>
Commit | Line | Data |
---|---|---|
224ce89b WB |
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" | |
6 | ||
7 | #include <algorithm> | |
8 | #include <errno.h> | |
9 | #include "gtest/gtest.h" | |
10 | #include "test/unit.cc" | |
11 | ||
12 | using namespace librados; | |
13 | ||
c07f9fc5 FG |
14 | TEST(LibRadosService, RegisterEarly) { |
15 | rados_t cluster; | |
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)); | |
19 | ||
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")); | |
25 | ||
26 | ASSERT_EQ(0, rados_connect(cluster)); | |
27 | sleep(5); | |
28 | rados_shutdown(cluster); | |
29 | } | |
30 | ||
31 | TEST(LibRadosService, RegisterLate) { | |
32 | rados_t cluster; | |
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)); | |
37 | ||
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); | |
44 | } | |
45 | ||
46 | TEST(LibRadosService, Status) { | |
47 | rados_t cluster; | |
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)); | |
51 | ||
52 | ASSERT_EQ(-ENOTCONN, rados_service_update_status(cluster, | |
53 | "testing\0testing\0")); | |
54 | ||
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")); | |
59 | ||
60 | for (int i=0; i<20; ++i) { | |
61 | char buffer[1024]; | |
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)); | |
66 | sleep(1); | |
67 | } | |
68 | rados_shutdown(cluster); | |
69 | } | |
70 | ||
224ce89b WB |
71 | TEST(LibRadosServicePP, RegisterEarly) { |
72 | Rados cluster; | |
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()); | |
82 | sleep(5); | |
83 | cluster.shutdown(); | |
84 | } | |
85 | ||
86 | TEST(LibRadosServicePP, RegisterLate) { | |
87 | Rados cluster; | |
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"}})); | |
95 | } | |
96 | ||
97 | TEST(LibRadosServicePP, Status) { | |
98 | Rados cluster; | |
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)} | |
112 | })); | |
113 | sleep(1); | |
114 | } | |
115 | cluster.shutdown(); | |
116 | } |