|
| 1 | +#include "gtest/gtest.h" |
| 2 | + |
| 3 | +#include "common/async/context_pool.h" |
| 4 | +#include "global/global_context.h" |
| 5 | + |
| 6 | +#include "msg/Messenger.h" |
| 7 | +#include "mon/MonClient.h" |
| 8 | +#include "osdc/ObjectCacher.h" |
| 9 | +#include "client/MetaRequest.h" |
| 10 | +#include "client/Client.h" |
| 11 | +#include "messages/MClientReclaim.h" |
| 12 | +#include "messages/MClientSession.h" |
| 13 | +#include "common/async/blocked_completion.h" |
| 14 | + |
| 15 | +#define dout_subsys ceph_subsys_client |
| 16 | + |
| 17 | +namespace bs = boost::system; |
| 18 | +namespace ca = ceph::async; |
| 19 | + |
| 20 | +class MonClientScaffold : public MonClient { |
| 21 | +public: |
| 22 | + MonClientScaffold(CephContext *cct_, boost::asio::io_context& service) : MonClient(cct_, service) {} |
| 23 | + virtual ~MonClientScaffold() {} |
| 24 | + |
| 25 | + bool check_monmap_subed () { |
| 26 | + return !sub_want("monmap", monmap.get_epoch() ? monmap.get_epoch() + 1 : 0, 0); |
| 27 | + } |
| 28 | + |
| 29 | + bool check_config_subed () { |
| 30 | + return !sub_want("config", 0, 0); |
| 31 | + } |
| 32 | +}; |
| 33 | + |
| 34 | +class TestPlodClient : public ::testing::Test { |
| 35 | +public: |
| 36 | + static void SetUpTestSuite() { |
| 37 | + icp.start(g_ceph_context->_conf.get_val<std::uint64_t>("client_asio_thread_count")); |
| 38 | + } |
| 39 | + static void TearDownTestSuite() { |
| 40 | + icp.stop(); |
| 41 | + } |
| 42 | + void SetUp() override { |
| 43 | + messenger = Messenger::create_client_messenger(g_ceph_context, "client"); |
| 44 | + if (messenger->start() != 0) { |
| 45 | + throw std::runtime_error("failed to start messenger"); |
| 46 | + } |
| 47 | + |
| 48 | + mc = new MonClientScaffold(g_ceph_context, icp); |
| 49 | + if (mc->build_initial_monmap() < 0) { |
| 50 | + throw std::runtime_error("build monmap"); |
| 51 | + } |
| 52 | + mc->set_messenger(messenger); |
| 53 | + mc->set_want_keys(CEPH_ENTITY_TYPE_MDS | CEPH_ENTITY_TYPE_OSD); |
| 54 | + if (mc->init() < 0) { |
| 55 | + throw std::runtime_error("init monclient"); |
| 56 | + } |
| 57 | + |
| 58 | + client = new StandaloneClient(messenger, mc, icp); |
| 59 | + client->init(); |
| 60 | + sleep(1); |
| 61 | + client->mount("/", myperm, true); |
| 62 | + } |
| 63 | + void TearDown() override { |
| 64 | + if (client->is_mounted()) |
| 65 | + client->unmount(); |
| 66 | + client->shutdown(); |
| 67 | + mc->shutdown(); |
| 68 | + messenger->shutdown(); |
| 69 | + messenger->wait(); |
| 70 | + |
| 71 | + delete client; |
| 72 | + client = nullptr; |
| 73 | + delete mc; |
| 74 | + mc = nullptr; |
| 75 | + delete messenger; |
| 76 | + messenger = nullptr; |
| 77 | + } |
| 78 | +protected: |
| 79 | + static inline ceph::async::io_context_pool icp; |
| 80 | + static inline UserPerm myperm{0,0}; |
| 81 | + MonClientScaffold* mc = nullptr; |
| 82 | + Messenger* messenger = nullptr; |
| 83 | + StandaloneClient* client = nullptr; |
| 84 | +}; |
0 commit comments