]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / test / rbd_mirror / test_mock_ImageSyncThrottler.cc
CommitLineData
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 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 SUSE LINUX GmbH
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 "test/rbd_mirror/test_mock_fixture.h"
7c673cae 16#include "test/librbd/mock/MockImageCtx.h"
7c673cae
FG
17
18namespace librbd {
19
20namespace {
21
22struct MockTestImageCtx : public librbd::MockImageCtx {
23 MockTestImageCtx(librbd::ImageCtx &image_ctx)
24 : librbd::MockImageCtx(image_ctx) {
25 }
26};
27
28} // anonymous namespace
29
7c673cae
FG
30} // namespace librbd
31
7c673cae
FG
32// template definitions
33#include "tools/rbd_mirror/ImageSyncThrottler.cc"
34
35namespace rbd {
36namespace mirror {
37
38class TestMockImageSyncThrottler : public TestMockFixture {
39public:
40 typedef ImageSyncThrottler<librbd::MockTestImageCtx> MockImageSyncThrottler;
41
7c673cae
FG
42};
43
44TEST_F(TestMockImageSyncThrottler, Single_Sync) {
11fdf7f2 45 MockImageSyncThrottler throttler(g_ceph_context);
31f18b77
FG
46 C_SaferCond on_start;
47 throttler.start_op("id", &on_start);
48 ASSERT_EQ(0, on_start.wait());
49 throttler.finish_op("id");
7c673cae
FG
50}
51
52TEST_F(TestMockImageSyncThrottler, Multiple_Syncs) {
11fdf7f2 53 MockImageSyncThrottler throttler(g_ceph_context);
31f18b77
FG
54 throttler.set_max_concurrent_syncs(2);
55
56 C_SaferCond on_start1;
57 throttler.start_op("id1", &on_start1);
58 C_SaferCond on_start2;
59 throttler.start_op("id2", &on_start2);
60 C_SaferCond on_start3;
61 throttler.start_op("id3", &on_start3);
62 C_SaferCond on_start4;
63 throttler.start_op("id4", &on_start4);
64
65 ASSERT_EQ(0, on_start2.wait());
66 throttler.finish_op("id2");
67 ASSERT_EQ(0, on_start3.wait());
68 throttler.finish_op("id3");
69 ASSERT_EQ(0, on_start1.wait());
70 throttler.finish_op("id1");
71 ASSERT_EQ(0, on_start4.wait());
72 throttler.finish_op("id4");
7c673cae
FG
73}
74
75TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync) {
11fdf7f2 76 MockImageSyncThrottler throttler(g_ceph_context);
31f18b77
FG
77 C_SaferCond on_start;
78 throttler.start_op("id", &on_start);
79 ASSERT_EQ(0, on_start.wait());
80 ASSERT_FALSE(throttler.cancel_op("id"));
81 throttler.finish_op("id");
7c673cae
FG
82}
83
84TEST_F(TestMockImageSyncThrottler, Cancel_Waiting_Sync) {
11fdf7f2 85 MockImageSyncThrottler throttler(g_ceph_context);
31f18b77
FG
86 throttler.set_max_concurrent_syncs(1);
87
88 C_SaferCond on_start1;
89 throttler.start_op("id1", &on_start1);
90 C_SaferCond on_start2;
91 throttler.start_op("id2", &on_start2);
92
93 ASSERT_EQ(0, on_start1.wait());
94 ASSERT_TRUE(throttler.cancel_op("id2"));
95 ASSERT_EQ(-ECANCELED, on_start2.wait());
96 throttler.finish_op("id1");
7c673cae
FG
97}
98
7c673cae 99
31f18b77 100TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync_Start_Waiting) {
11fdf7f2 101 MockImageSyncThrottler throttler(g_ceph_context);
31f18b77
FG
102 throttler.set_max_concurrent_syncs(1);
103
104 C_SaferCond on_start1;
105 throttler.start_op("id1", &on_start1);
106 C_SaferCond on_start2;
107 throttler.start_op("id2", &on_start2);
108
109 ASSERT_EQ(0, on_start1.wait());
110 ASSERT_FALSE(throttler.cancel_op("id1"));
111 throttler.finish_op("id1");
112 ASSERT_EQ(0, on_start2.wait());
113 throttler.finish_op("id2");
7c673cae
FG
114}
115
494da23a
TL
116TEST_F(TestMockImageSyncThrottler, Duplicate) {
117 MockImageSyncThrottler throttler(g_ceph_context);
118 throttler.set_max_concurrent_syncs(1);
119
120 C_SaferCond on_start1;
121 throttler.start_op("id1", &on_start1);
122 ASSERT_EQ(0, on_start1.wait());
123
124 C_SaferCond on_start2;
125 throttler.start_op("id1", &on_start2);
126 ASSERT_EQ(0, on_start2.wait());
127
128 C_SaferCond on_start3;
129 throttler.start_op("id2", &on_start3);
130 C_SaferCond on_start4;
131 throttler.start_op("id2", &on_start4);
132 ASSERT_EQ(-ENOENT, on_start3.wait());
133
134 throttler.finish_op("id1");
135 ASSERT_EQ(0, on_start4.wait());
136 throttler.finish_op("id2");
137}
138
139TEST_F(TestMockImageSyncThrottler, Duplicate2) {
140 MockImageSyncThrottler throttler(g_ceph_context);
141 throttler.set_max_concurrent_syncs(2);
142
143 C_SaferCond on_start1;
144 throttler.start_op("id1", &on_start1);
145 ASSERT_EQ(0, on_start1.wait());
146 C_SaferCond on_start2;
147 throttler.start_op("id2", &on_start2);
148 ASSERT_EQ(0, on_start2.wait());
149
150 C_SaferCond on_start3;
151 throttler.start_op("id3", &on_start3);
152 C_SaferCond on_start4;
153 throttler.start_op("id3", &on_start4); // dup
154 ASSERT_EQ(-ENOENT, on_start3.wait());
155
156 C_SaferCond on_start5;
157 throttler.start_op("id4", &on_start5);
158
159 throttler.finish_op("id1");
160 ASSERT_EQ(0, on_start4.wait());
161
162 throttler.finish_op("id2");
163 ASSERT_EQ(0, on_start5.wait());
164
165 C_SaferCond on_start6;
166 throttler.start_op("id5", &on_start6);
167
168 throttler.finish_op("id3");
169 ASSERT_EQ(0, on_start6.wait());
170
171 throttler.finish_op("id4");
172 throttler.finish_op("id5");
173}
174
7c673cae 175TEST_F(TestMockImageSyncThrottler, Increase_Max_Concurrent_Syncs) {
11fdf7f2 176 MockImageSyncThrottler throttler(g_ceph_context);
31f18b77
FG
177 throttler.set_max_concurrent_syncs(2);
178
179 C_SaferCond on_start1;
180 throttler.start_op("id1", &on_start1);
181 C_SaferCond on_start2;
182 throttler.start_op("id2", &on_start2);
183 C_SaferCond on_start3;
184 throttler.start_op("id3", &on_start3);
185 C_SaferCond on_start4;
186 throttler.start_op("id4", &on_start4);
187 C_SaferCond on_start5;
188 throttler.start_op("id5", &on_start5);
189
190 ASSERT_EQ(0, on_start1.wait());
191 ASSERT_EQ(0, on_start2.wait());
192
193 throttler.set_max_concurrent_syncs(4);
194
195 ASSERT_EQ(0, on_start3.wait());
196 ASSERT_EQ(0, on_start4.wait());
197
198 throttler.finish_op("id4");
199 ASSERT_EQ(0, on_start5.wait());
200
201 throttler.finish_op("id1");
202 throttler.finish_op("id2");
203 throttler.finish_op("id3");
204 throttler.finish_op("id5");
7c673cae
FG
205}
206
207TEST_F(TestMockImageSyncThrottler, Decrease_Max_Concurrent_Syncs) {
11fdf7f2 208 MockImageSyncThrottler throttler(g_ceph_context);
31f18b77
FG
209 throttler.set_max_concurrent_syncs(4);
210
211 C_SaferCond on_start1;
212 throttler.start_op("id1", &on_start1);
213 C_SaferCond on_start2;
214 throttler.start_op("id2", &on_start2);
215 C_SaferCond on_start3;
216 throttler.start_op("id3", &on_start3);
217 C_SaferCond on_start4;
218 throttler.start_op("id4", &on_start4);
219 C_SaferCond on_start5;
220 throttler.start_op("id5", &on_start5);
221
222 ASSERT_EQ(0, on_start1.wait());
223 ASSERT_EQ(0, on_start2.wait());
224 ASSERT_EQ(0, on_start3.wait());
225 ASSERT_EQ(0, on_start4.wait());
226
227 throttler.set_max_concurrent_syncs(2);
228
229 throttler.finish_op("id1");
230 throttler.finish_op("id2");
231 throttler.finish_op("id3");
232
233 ASSERT_EQ(0, on_start5.wait());
234
235 throttler.finish_op("id4");
236 throttler.finish_op("id5");
7c673cae
FG
237}
238
7c673cae
FG
239} // namespace mirror
240} // namespace rbd
241