]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef LIBRADOS_TEST_STUB_MOCK_TEST_MEM_RADOS_CLIENT_H | |
5 | #define LIBRADOS_TEST_STUB_MOCK_TEST_MEM_RADOS_CLIENT_H | |
6 | ||
7 | #include "test/librados_test_stub/TestMemRadosClient.h" | |
8 | #include "test/librados_test_stub/MockTestMemIoCtxImpl.h" | |
9 | #include "gmock/gmock.h" | |
10 | ||
11 | namespace librados { | |
12 | ||
13 | class TestMemCluster; | |
14 | ||
15 | class MockTestMemRadosClient : public TestMemRadosClient { | |
16 | public: | |
17 | MockTestMemRadosClient(CephContext *cct, TestMemCluster *test_mem_cluster) | |
18 | : TestMemRadosClient(cct, test_mem_cluster) { | |
19 | default_to_dispatch(); | |
20 | } | |
21 | ||
11fdf7f2 TL |
22 | MOCK_METHOD0(connect, int()); |
23 | int do_connect() { | |
24 | return TestMemRadosClient::connect(); | |
25 | } | |
26 | ||
7c673cae FG |
27 | MOCK_METHOD2(create_ioctx, TestIoCtxImpl *(int64_t pool_id, |
28 | const std::string &pool_name)); | |
11fdf7f2 TL |
29 | MockTestMemIoCtxImpl* do_create_ioctx(int64_t pool_id, |
30 | const std::string &pool_name) { | |
7c673cae FG |
31 | return new ::testing::NiceMock<MockTestMemIoCtxImpl>( |
32 | this, this, pool_id, pool_name, | |
33 | get_mem_cluster()->get_pool(pool_name)); | |
34 | } | |
35 | ||
f67539c2 | 36 | MOCK_METHOD2(blocklist_add, int(const std::string& client_address, |
7c673cae | 37 | uint32_t expire_seconds)); |
f67539c2 | 38 | int do_blocklist_add(const std::string& client_address, |
7c673cae | 39 | uint32_t expire_seconds) { |
f67539c2 | 40 | return TestMemRadosClient::blocklist_add(client_address, expire_seconds); |
7c673cae FG |
41 | } |
42 | ||
11fdf7f2 TL |
43 | MOCK_METHOD1(get_min_compatible_osd, int(int8_t*)); |
44 | int do_get_min_compatible_osd(int8_t* require_osd_release) { | |
45 | return TestMemRadosClient::get_min_compatible_osd(require_osd_release); | |
46 | } | |
47 | ||
48 | MOCK_METHOD2(get_min_compatible_client, int(int8_t*, int8_t*)); | |
49 | int do_get_min_compatible_client(int8_t* min_compat_client, | |
50 | int8_t* require_min_compat_client) { | |
51 | return TestMemRadosClient::get_min_compatible_client( | |
52 | min_compat_client, require_min_compat_client); | |
53 | } | |
54 | ||
c07f9fc5 FG |
55 | MOCK_METHOD3(service_daemon_register, |
56 | int(const std::string&, | |
57 | const std::string&, | |
58 | const std::map<std::string,std::string>&)); | |
59 | int do_service_daemon_register(const std::string& service, | |
60 | const std::string& name, | |
61 | const std::map<std::string,std::string>& metadata) { | |
62 | return TestMemRadosClient::service_daemon_register(service, name, metadata); | |
63 | } | |
64 | ||
11fdf7f2 TL |
65 | // workaround of https://github.com/google/googletest/issues/1155 |
66 | MOCK_METHOD1(service_daemon_update_status_r, | |
c07f9fc5 | 67 | int(const std::map<std::string,std::string>&)); |
11fdf7f2 TL |
68 | int do_service_daemon_update_status_r(const std::map<std::string,std::string>& status) { |
69 | auto s = status; | |
70 | return TestMemRadosClient::service_daemon_update_status(std::move(s)); | |
c07f9fc5 FG |
71 | } |
72 | ||
f67539c2 TL |
73 | MOCK_METHOD4(mon_command, int(const std::vector<std::string>&, |
74 | const bufferlist&, bufferlist*, std::string*)); | |
75 | int do_mon_command(const std::vector<std::string>& cmd, | |
76 | const bufferlist &inbl, bufferlist *outbl, | |
77 | std::string *outs) { | |
78 | return mon_command(cmd, inbl, outbl, outs); | |
79 | } | |
80 | ||
81 | MOCK_METHOD0(wait_for_latest_osd_map, int()); | |
82 | int do_wait_for_latest_osd_map() { | |
83 | return wait_for_latest_osd_map(); | |
84 | } | |
85 | ||
7c673cae FG |
86 | void default_to_dispatch() { |
87 | using namespace ::testing; | |
88 | ||
11fdf7f2 | 89 | ON_CALL(*this, connect()).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_connect)); |
7c673cae | 90 | ON_CALL(*this, create_ioctx(_, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_create_ioctx)); |
f67539c2 | 91 | ON_CALL(*this, blocklist_add(_, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_blocklist_add)); |
11fdf7f2 TL |
92 | ON_CALL(*this, get_min_compatible_osd(_)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_get_min_compatible_osd)); |
93 | ON_CALL(*this, get_min_compatible_client(_, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_get_min_compatible_client)); | |
c07f9fc5 | 94 | ON_CALL(*this, service_daemon_register(_, _, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_service_daemon_register)); |
11fdf7f2 | 95 | ON_CALL(*this, service_daemon_update_status_r(_)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_service_daemon_update_status_r)); |
f67539c2 TL |
96 | ON_CALL(*this, mon_command(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_mon_command)); |
97 | ON_CALL(*this, wait_for_latest_osd_map()).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_wait_for_latest_osd_map)); | |
7c673cae FG |
98 | } |
99 | }; | |
100 | ||
101 | } // namespace librados | |
102 | ||
103 | #endif // LIBRADOS_TEST_STUB_MOCK_TEST_MEM_RADOS_CLIENT_H |