1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
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"
16 struct Traits<MockImageCtx> {
17 typedef librbd::MockImageWatcher Watcher;
22 // template definitions
23 #include "librbd/managed_lock/ReleaseRequest.cc"
24 template class librbd::managed_lock::ReleaseRequest<librbd::MockImageCtx>;
27 namespace managed_lock {
30 using ::testing::InSequence;
31 using ::testing::Invoke;
32 using ::testing::Return;
33 using ::testing::StrEq;
35 static const std::string TEST_COOKIE("auto 123");
37 class TestMockManagedLockReleaseRequest : public TestMockFixture {
39 typedef ReleaseRequest<MockImageCtx> MockReleaseRequest;
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"),
44 StrEq("unlock"), _, _, _))
50 TEST_F(TestMockManagedLockReleaseRequest, Success) {
52 librbd::ImageCtx *ictx;
53 ASSERT_EQ(0, open_image(m_image_name, &ictx));
55 MockImageCtx mock_image_ctx(*ictx);
56 expect_op_work_queue(mock_image_ctx);
60 expect_unlock(mock_image_ctx, 0);
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);
67 ASSERT_EQ(0, ctx.wait());
70 TEST_F(TestMockManagedLockReleaseRequest, UnlockError) {
71 librbd::ImageCtx *ictx;
72 ASSERT_EQ(0, open_image(m_image_name, &ictx));
74 MockImageCtx mock_image_ctx(*ictx);
75 expect_op_work_queue(mock_image_ctx);
79 expect_unlock(mock_image_ctx, -EINVAL);
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);
86 ASSERT_EQ(0, ctx.wait());
90 } // namespace managed_lock