]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/client/TestClient.h
e1c0199b3105b70603eb502285e000db60ece143
[ceph.git] / ceph / src / test / client / TestClient.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2021 Red Hat
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include "gtest/gtest.h"
16
17 #include "common/async/context_pool.h"
18 #include "global/global_context.h"
19
20 #include "msg/Messenger.h"
21 #include "mon/MonClient.h"
22 #include "osdc/ObjectCacher.h"
23
24 #include "client/Client.h"
25
26 class TestClient : public ::testing::Test {
27 public:
28 static void SetUpTestSuite() {
29 icp.start(g_ceph_context->_conf.get_val<std::uint64_t>("client_asio_thread_count"));
30 }
31 static void TearDownTestSuite() {
32 icp.stop();
33 }
34 void SetUp() override {
35 messenger = Messenger::create_client_messenger(g_ceph_context, "client");
36 if (messenger->start() != 0) {
37 throw std::runtime_error("failed to start messenger");
38 }
39
40 mc = new MonClient(g_ceph_context, icp);
41 if (mc->build_initial_monmap() < 0) {
42 throw std::runtime_error("build monmap");
43 }
44 mc->set_messenger(messenger);
45 mc->set_want_keys(CEPH_ENTITY_TYPE_MDS | CEPH_ENTITY_TYPE_OSD);
46 if (mc->init() < 0) {
47 throw std::runtime_error("init monclient");
48 }
49
50 objecter = new Objecter(g_ceph_context, messenger, mc, icp);
51 objecter->set_client_incarnation(0);
52 objecter->init();
53 messenger->add_dispatcher_tail(objecter);
54 objecter->start();
55
56 client = new Client(messenger, mc, objecter);
57 client->init();
58 client->mount("/", myperm, true);
59 }
60 void TearDown() override {
61 if (client->is_mounted())
62 client->unmount();
63 client->shutdown();
64 objecter->shutdown();
65 mc->shutdown();
66 messenger->shutdown();
67 messenger->wait();
68
69 delete client;
70 client = nullptr;
71 delete objecter;
72 objecter = 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 MonClient* mc = nullptr;
82 Messenger* messenger = nullptr;
83 Objecter* objecter = nullptr;
84 Client* client = nullptr;
85 };