]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/librados_test_stub/MockTestMemRadosClient.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / librados_test_stub / MockTestMemRadosClient.h
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
22 MOCK_METHOD0(connect, int());
23 int do_connect() {
24 return TestMemRadosClient::connect();
25 }
26
27 MOCK_METHOD2(create_ioctx, TestIoCtxImpl *(int64_t pool_id,
28 const std::string &pool_name));
29 MockTestMemIoCtxImpl* do_create_ioctx(int64_t pool_id,
30 const std::string &pool_name) {
31 return new ::testing::NiceMock<MockTestMemIoCtxImpl>(
32 this, this, pool_id, pool_name,
33 get_mem_cluster()->get_pool(pool_name));
34 }
35
36 MOCK_METHOD2(blacklist_add, int(const std::string& client_address,
37 uint32_t expire_seconds));
38 int do_blacklist_add(const std::string& client_address,
39 uint32_t expire_seconds) {
40 return TestMemRadosClient::blacklist_add(client_address, expire_seconds);
41 }
42
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
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
65 // workaround of https://github.com/google/googletest/issues/1155
66 MOCK_METHOD1(service_daemon_update_status_r,
67 int(const std::map<std::string,std::string>&));
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));
71 }
72
73 void default_to_dispatch() {
74 using namespace ::testing;
75
76 ON_CALL(*this, connect()).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_connect));
77 ON_CALL(*this, create_ioctx(_, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_create_ioctx));
78 ON_CALL(*this, blacklist_add(_, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_blacklist_add));
79 ON_CALL(*this, get_min_compatible_osd(_)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_get_min_compatible_osd));
80 ON_CALL(*this, get_min_compatible_client(_, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_get_min_compatible_client));
81 ON_CALL(*this, service_daemon_register(_, _, _)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_service_daemon_register));
82 ON_CALL(*this, service_daemon_update_status_r(_)).WillByDefault(Invoke(this, &MockTestMemRadosClient::do_service_daemon_update_status_r));
83 }
84 };
85
86 } // namespace librados
87
88 #endif // LIBRADOS_TEST_STUB_MOCK_TEST_MEM_RADOS_CLIENT_H