]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/librbd/managed_lock/test_mock_ReleaseRequest.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / test / librbd / managed_lock / test_mock_ReleaseRequest.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#include "test/librbd/test_mock_fixture.h"
5#include "test/librbd/test_support.h"
6#include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
7#include "librbd/managed_lock/ReleaseRequest.h"
8#include "common/WorkQueue.h"
9#include "gmock/gmock.h"
10#include "gtest/gtest.h"
11#include <list>
12
13namespace librbd {
14namespace watcher {
15template <>
16struct Traits<MockImageCtx> {
17 typedef librbd::MockImageWatcher Watcher;
18};
19}
20}
21
22// template definitions
23#include "librbd/managed_lock/ReleaseRequest.cc"
24template class librbd::managed_lock::ReleaseRequest<librbd::MockImageCtx>;
25
26namespace librbd {
27namespace managed_lock {
28
29using ::testing::_;
30using ::testing::InSequence;
31using ::testing::Invoke;
32using ::testing::Return;
33using ::testing::StrEq;
34
35static const std::string TEST_COOKIE("auto 123");
36
37class TestMockManagedLockReleaseRequest : public TestMockFixture {
38public:
39 typedef ReleaseRequest<MockImageCtx> MockReleaseRequest;
40
41 void expect_unlock(MockImageCtx &mock_image_ctx, int r) {
42 EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
43 exec(mock_image_ctx.header_oid, _, StrEq("lock"),
f67539c2 44 StrEq("unlock"), _, _, _, _))
7c673cae
FG
45 .WillOnce(Return(r));
46 }
47
48};
49
50TEST_F(TestMockManagedLockReleaseRequest, Success) {
51
52 librbd::ImageCtx *ictx;
53 ASSERT_EQ(0, open_image(m_image_name, &ictx));
54
55 MockImageCtx mock_image_ctx(*ictx);
56 expect_op_work_queue(mock_image_ctx);
57
58 InSequence seq;
59
60 expect_unlock(mock_image_ctx, 0);
61
62 C_SaferCond ctx;
63 MockReleaseRequest *req = MockReleaseRequest::create(
64 mock_image_ctx.md_ctx, mock_image_ctx.image_watcher, ictx->op_work_queue,
65 mock_image_ctx.header_oid, TEST_COOKIE, &ctx);
66 req->send();
67 ASSERT_EQ(0, ctx.wait());
68}
69
70TEST_F(TestMockManagedLockReleaseRequest, UnlockError) {
71 librbd::ImageCtx *ictx;
72 ASSERT_EQ(0, open_image(m_image_name, &ictx));
73
74 MockImageCtx mock_image_ctx(*ictx);
75 expect_op_work_queue(mock_image_ctx);
76
77 InSequence seq;
78
79 expect_unlock(mock_image_ctx, -EINVAL);
80
81 C_SaferCond ctx;
82 MockReleaseRequest *req = MockReleaseRequest::create(
83 mock_image_ctx.md_ctx, mock_image_ctx.image_watcher, ictx->op_work_queue,
84 mock_image_ctx.header_oid, TEST_COOKIE, &ctx);
85 req->send();
86 ASSERT_EQ(0, ctx.wait());
87
88}
89
90} // namespace managed_lock
91} // namespace librbd