]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/librbd/io/test_mock_QosImageDispatch.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / test / librbd / io / test_mock_QosImageDispatch.cc
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/librbd/test_mock_fixture.h"
5 #include "test/librbd/test_support.h"
6 #include "test/librbd/mock/MockImageCtx.h"
7 #include "test/librbd/mock/exclusive_lock/MockPolicy.h"
8 #include "librbd/io/ImageDispatchSpec.h"
9 #include "librbd/io/ImageRequestWQ.h"
10 #include "librbd/io/ImageRequest.h"
11
12 namespace librbd {
13 namespace io {
14
15 TEST_F(TestMockIoImageRequestWQ, QosNoLimit) {
16 librbd::ImageCtx *ictx;
17 ASSERT_EQ(0, open_image(m_image_name, &ictx));
18
19 MockTestImageCtx mock_image_ctx(*ictx);
20
21 MockImageDispatchSpec mock_queued_image_request;
22 expect_was_throttled(mock_queued_image_request, false);
23 expect_set_throttled(mock_queued_image_request);
24
25 InSequence seq;
26 MockImageRequestWQ mock_image_request_wq(&mock_image_ctx, "io", 60, nullptr);
27
28 mock_image_request_wq.apply_qos_limit(IMAGE_DISPATCH_FLAG_QOS_BPS_THROTTLE, 0,
29 0, 1);
30
31 expect_front(mock_image_request_wq, &mock_queued_image_request);
32 expect_is_refresh_request(mock_image_ctx, false);
33 expect_is_write_op(mock_queued_image_request, true);
34 expect_dequeue(mock_image_request_wq, &mock_queued_image_request);
35 ASSERT_TRUE(mock_image_request_wq.invoke_dequeue() == &mock_queued_image_request);
36 }
37
38 TEST_F(TestMockIoImageRequestWQ, BPSQosNoBurst) {
39 librbd::ImageCtx *ictx;
40 ASSERT_EQ(0, open_image(m_image_name, &ictx));
41
42 MockTestImageCtx mock_image_ctx(*ictx);
43
44 MockImageDispatchSpec mock_queued_image_request;
45 expect_was_throttled(mock_queued_image_request, false);
46 expect_set_throttled(mock_queued_image_request);
47
48 InSequence seq;
49 MockImageRequestWQ mock_image_request_wq(&mock_image_ctx, "io", 60, nullptr);
50
51 mock_image_request_wq.apply_qos_limit(IMAGE_DISPATCH_FLAG_QOS_BPS_THROTTLE, 1,
52 0, 1);
53
54 expect_front(mock_image_request_wq, &mock_queued_image_request);
55 expect_tokens_requested(mock_queued_image_request, 2, true);
56 expect_dequeue(mock_image_request_wq, &mock_queued_image_request);
57 expect_all_throttled(mock_queued_image_request, true);
58 expect_requeue_back(mock_image_request_wq);
59 expect_signal(mock_image_request_wq);
60 ASSERT_TRUE(mock_image_request_wq.invoke_dequeue() == nullptr);
61 }
62
63 TEST_F(TestMockIoImageRequestWQ, BPSQosWithBurst) {
64 librbd::ImageCtx *ictx;
65 ASSERT_EQ(0, open_image(m_image_name, &ictx));
66
67 MockTestImageCtx mock_image_ctx(*ictx);
68
69 MockImageDispatchSpec mock_queued_image_request;
70 expect_was_throttled(mock_queued_image_request, false);
71 expect_set_throttled(mock_queued_image_request);
72
73 InSequence seq;
74 MockImageRequestWQ mock_image_request_wq(&mock_image_ctx, "io", 60, nullptr);
75
76 mock_image_request_wq.apply_qos_limit(IMAGE_DISPATCH_FLAG_QOS_BPS_THROTTLE, 1,
77 1, 1);
78
79 expect_front(mock_image_request_wq, &mock_queued_image_request);
80 expect_tokens_requested(mock_queued_image_request, 2, true);
81 expect_dequeue(mock_image_request_wq, &mock_queued_image_request);
82 expect_all_throttled(mock_queued_image_request, true);
83 expect_requeue_back(mock_image_request_wq);
84 expect_signal(mock_image_request_wq);
85 ASSERT_TRUE(mock_image_request_wq.invoke_dequeue() == nullptr);
86 }
87
88 } // namespace io
89 } // namespace librbd