]>
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 | #include "test/librados/test.h" | |
9f95a23c | 5 | #include "common/ceph_mutex.h" |
7c673cae FG |
6 | #include "common/Timer.h" |
7 | #include "journal/JournalMetadata.h" | |
8 | #include "cls/journal/cls_journal_types.h" | |
9 | #include "gtest/gtest.h" | |
10 | ||
11 | class ThreadPool; | |
12 | ||
13 | class RadosTestFixture : public ::testing::Test { | |
14 | public: | |
15 | static void SetUpTestCase(); | |
16 | static void TearDownTestCase(); | |
17 | ||
18 | static std::string get_temp_oid(); | |
19 | ||
20 | RadosTestFixture(); | |
21 | void SetUp() override; | |
22 | void TearDown() override; | |
23 | ||
24 | int create(const std::string &oid, uint8_t order = 14, | |
25 | uint8_t splay_width = 2); | |
9f95a23c | 26 | ceph::ref_t<journal::JournalMetadata> create_metadata(const std::string &oid, |
7c673cae FG |
27 | const std::string &client_id = "client", |
28 | double commit_internal = 0.1, | |
7c673cae FG |
29 | int max_concurrent_object_sets = 0); |
30 | int append(const std::string &oid, const bufferlist &bl); | |
31 | ||
32 | int client_register(const std::string &oid, const std::string &id = "client", | |
33 | const std::string &description = ""); | |
34 | int client_commit(const std::string &oid, const std::string &id, | |
35 | const cls::journal::ObjectSetPosition &commit_position); | |
36 | ||
37 | bufferlist create_payload(const std::string &payload); | |
38 | ||
39 | struct Listener : public journal::JournalMetadataListener { | |
40 | RadosTestFixture *test_fixture; | |
9f95a23c TL |
41 | ceph::mutex mutex = ceph::make_mutex("mutex"); |
42 | ceph::condition_variable cond; | |
7c673cae FG |
43 | std::map<journal::JournalMetadata*, uint32_t> updates; |
44 | ||
45 | Listener(RadosTestFixture *_test_fixture) | |
9f95a23c | 46 | : test_fixture(_test_fixture) {} |
7c673cae FG |
47 | |
48 | void handle_update(journal::JournalMetadata *metadata) override { | |
9f95a23c | 49 | std::lock_guard locker{mutex}; |
7c673cae | 50 | ++updates[metadata]; |
9f95a23c | 51 | cond.notify_all(); |
7c673cae FG |
52 | } |
53 | }; | |
54 | ||
9f95a23c | 55 | int init_metadata(const ceph::ref_t<journal::JournalMetadata>& metadata); |
7c673cae | 56 | |
9f95a23c | 57 | bool wait_for_update(const ceph::ref_t<journal::JournalMetadata>& metadata); |
7c673cae FG |
58 | |
59 | static std::string _pool_name; | |
60 | static librados::Rados _rados; | |
61 | static uint64_t _oid_number; | |
62 | static ThreadPool *_thread_pool; | |
63 | ||
64 | librados::IoCtx m_ioctx; | |
65 | ||
11fdf7f2 | 66 | ContextWQ *m_work_queue = nullptr; |
7c673cae | 67 | |
9f95a23c TL |
68 | ceph::mutex m_timer_lock; |
69 | SafeTimer *m_timer = nullptr; | |
7c673cae FG |
70 | |
71 | Listener m_listener; | |
72 | ||
9f95a23c | 73 | std::list<ceph::ref_t<journal::JournalMetadata>> m_metadatas; |
7c673cae | 74 | }; |