From: Jason Dillaman Date: Mon, 8 Jun 2015 20:39:24 +0000 (-0400) Subject: tests: new cls_journal_client test cases X-Git-Tag: v10.0.1~102^2~41 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=050763f7127dacde755798521a99eec04e64a59b;p=ceph.git tests: new cls_journal_client test cases Signed-off-by: Jason Dillaman --- diff --git a/src/test/Makefile-client.am b/src/test/Makefile-client.am index 42a9e7418a69..41b816fc2849 100644 --- a/src/test/Makefile-client.am +++ b/src/test/Makefile-client.am @@ -184,6 +184,13 @@ ceph_test_cls_numops_LDADD = \ ceph_test_cls_numops_CXXFLAGS = $(UNITTEST_CXXFLAGS) bin_DEBUGPROGRAMS += ceph_test_cls_numops +ceph_test_cls_journal_SOURCES = test/cls_journal/test_cls_journal.cc +ceph_test_cls_journal_LDADD = \ + libcls_journal_client.la $(LIBRADOS) \ + $(LIBCOMMON) $(CRYPTO_LIBS) $(UNITTEST_LDADD) $(RADOS_TEST_LDADD) -luuid +ceph_test_cls_journal_CXXFLAGS = $(UNITTEST_CXXFLAGS) +bin_DEBUGPROGRAMS += ceph_test_cls_journal + ceph_test_rados_api_cmd_SOURCES = test/librados/cmd.cc ceph_test_rados_api_cmd_LDADD = \ $(LIBCOMMON) $(LIBRADOS) $(CRYPTO_LIBS) \ diff --git a/src/test/cls_journal/test_cls_journal.cc b/src/test/cls_journal/test_cls_journal.cc new file mode 100644 index 000000000000..dc87593c326d --- /dev/null +++ b/src/test/cls_journal/test_cls_journal.cc @@ -0,0 +1,377 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "cls/journal/cls_journal_client.h" +#include "include/stringify.h" +#include "common/Cond.h" +#include "test/librados/test.h" +#include "gtest/gtest.h" +#include +#include +#include +#include + +using namespace cls::journal; + +class TestClsJournal : public ::testing::Test { +public: + + static void SetUpTestCase() { + _pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool_pp(_pool_name, _rados)); + } + + static void TearDownTestCase() { + ASSERT_EQ(0, destroy_one_pool_pp(_pool_name, _rados)); + } + + std::string get_temp_image_name() { + ++_image_number; + return "image" + stringify(_image_number); + } + + static std::string _pool_name; + static librados::Rados _rados; + static uint64_t _image_number; + +}; + +std::string TestClsJournal::_pool_name; +librados::Rados TestClsJournal::_rados; +uint64_t TestClsJournal::_image_number = 0; + +TEST_F(TestClsJournal, Create) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + uint8_t order = 1; + uint8_t splay_width = 2; + ASSERT_EQ(0, client::create(ioctx, oid, order, splay_width)); + + uint8_t read_order; + uint8_t read_splay_width; + ASSERT_EQ(0, client::get_immutable_metadata(ioctx, oid, &read_order, + &read_splay_width)); + ASSERT_EQ(order, read_order); + ASSERT_EQ(splay_width, read_splay_width); +} + +TEST_F(TestClsJournal, MinimumSet) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 2, 4)); + + librados::ObjectWriteOperation op1; + client::set_active_set(&op1, 300); + ASSERT_EQ(0, ioctx.operate(oid, &op1)); + + uint64_t minimum_set = 123; + librados::ObjectWriteOperation op2; + client::set_minimum_set(&op2, minimum_set); + ASSERT_EQ(0, ioctx.operate(oid, &op2)); + + C_SaferCond cond; + uint64_t read_minimum_set; + uint64_t read_active_set; + std::set read_clients; + client::get_mutable_metadata(ioctx, oid, &read_minimum_set, &read_active_set, + &read_clients, &cond); + ASSERT_EQ(0, cond.wait()); + ASSERT_EQ(minimum_set, read_minimum_set); +} + +TEST_F(TestClsJournal, MinimumSetStale) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 2, 4)); + + librados::ObjectWriteOperation op1; + client::set_active_set(&op1, 300); + ASSERT_EQ(0, ioctx.operate(oid, &op1)); + + uint64_t minimum_set = 123; + librados::ObjectWriteOperation op2; + client::set_minimum_set(&op2, minimum_set); + ASSERT_EQ(0, ioctx.operate(oid, &op2)); + + librados::ObjectWriteOperation op3; + client::set_minimum_set(&op3, 1); + ASSERT_EQ(-ESTALE, ioctx.operate(oid, &op3)); + + C_SaferCond cond; + uint64_t read_minimum_set; + uint64_t read_active_set; + std::set read_clients; + client::get_mutable_metadata(ioctx, oid, &read_minimum_set, &read_active_set, + &read_clients, &cond); + ASSERT_EQ(0, cond.wait()); + ASSERT_EQ(minimum_set, read_minimum_set); +} + +TEST_F(TestClsJournal, MinimumSetOrderConstraint) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 2, 4)); + + librados::ObjectWriteOperation op1; + client::set_minimum_set(&op1, 123); + ASSERT_EQ(-EINVAL, ioctx.operate(oid, &op1)); + + C_SaferCond cond; + uint64_t read_minimum_set; + uint64_t read_active_set; + std::set read_clients; + client::get_mutable_metadata(ioctx, oid, &read_minimum_set, &read_active_set, + &read_clients, &cond); + ASSERT_EQ(0, cond.wait()); + ASSERT_EQ(0U, read_minimum_set); +} + +TEST_F(TestClsJournal, ActiveSet) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 2, 4)); + + uint64_t active_set = 234; + librados::ObjectWriteOperation op1; + client::set_active_set(&op1, active_set); + ASSERT_EQ(0, ioctx.operate(oid, &op1)); + + C_SaferCond cond; + uint64_t read_minimum_set; + uint64_t read_active_set; + std::set read_clients; + client::get_mutable_metadata(ioctx, oid, &read_minimum_set, &read_active_set, + &read_clients, &cond); + ASSERT_EQ(0, cond.wait()); + ASSERT_EQ(active_set, read_active_set); +} + +TEST_F(TestClsJournal, ActiveSetStale) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 2, 4)); + + librados::ObjectWriteOperation op1; + client::set_active_set(&op1, 345); + ASSERT_EQ(0, ioctx.operate(oid, &op1)); + + librados::ObjectWriteOperation op2; + client::set_active_set(&op2, 3); + ASSERT_EQ(-ESTALE, ioctx.operate(oid, &op2)); +} + +TEST_F(TestClsJournal, CreateDuplicate) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 2, 4)); + ASSERT_EQ(-EEXIST, client::create(ioctx, oid, 3, 5)); +} + +TEST_F(TestClsJournal, ClientRegister) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::client_register(ioctx, oid, "id1", "desc1")); + + std::set clients; + ASSERT_EQ(0, client::client_list(ioctx, oid, &clients)); + + std::set expected_clients = boost::assign::list_of( + Client("id1", "desc1")); + ASSERT_EQ(expected_clients, clients); +} + +TEST_F(TestClsJournal, ClientRegisterDuplicate) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::client_register(ioctx, oid, "id1", "desc1")); + ASSERT_EQ(-EEXIST, client::client_register(ioctx, oid, "id1", "desc2")); +} + +TEST_F(TestClsJournal, ClientUnregister) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::client_register(ioctx, oid, "id1", "desc1")); + ASSERT_EQ(0, client::client_unregister(ioctx, oid, "id1")); +} + +TEST_F(TestClsJournal, ClientUnregisterDNE) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::client_register(ioctx, oid, "id1", "desc1")); + ASSERT_EQ(0, client::client_unregister(ioctx, oid, "id1")); + ASSERT_EQ(-ENOENT, client::client_unregister(ioctx, oid, "id1")); +} + +TEST_F(TestClsJournal, ClientCommit) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 2, 2)); + ASSERT_EQ(0, client::client_register(ioctx, oid, "id1", "desc1")); + + cls::journal::EntryPositions entry_positions; + entry_positions = boost::assign::list_of( + cls::journal::EntryPosition("tag1", 120))( + cls::journal::EntryPosition("tag2", 121)); + cls::journal::ObjectSetPosition object_set_position( + 1, entry_positions); + + librados::ObjectWriteOperation op2; + client::client_commit(&op2, "id1", object_set_position); + ASSERT_EQ(0, ioctx.operate(oid, &op2)); + + std::set clients; + ASSERT_EQ(0, client::client_list(ioctx, oid, &clients)); + + std::set expected_clients = boost::assign::list_of( + Client("id1", "desc1", object_set_position)); + ASSERT_EQ(expected_clients, clients); +} + +TEST_F(TestClsJournal, ClientCommitInvalid) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 2, 2)); + ASSERT_EQ(0, client::client_register(ioctx, oid, "id1", "desc1")); + + cls::journal::EntryPositions entry_positions; + entry_positions = boost::assign::list_of( + cls::journal::EntryPosition("tag1", 120))( + cls::journal::EntryPosition("tag1", 121))( + cls::journal::EntryPosition("tag2", 121)); + cls::journal::ObjectSetPosition object_set_position( + 1, entry_positions); + + librados::ObjectWriteOperation op2; + client::client_commit(&op2, "id1", object_set_position); + ASSERT_EQ(-EINVAL, ioctx.operate(oid, &op2)); +} + +TEST_F(TestClsJournal, ClientCommitDNE) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + cls::journal::ObjectSetPosition object_set_position; + + librados::ObjectWriteOperation op1; + client::client_commit(&op1, "id1", object_set_position); + ASSERT_EQ(-ENOENT, ioctx.operate(oid, &op1)); +} + +TEST_F(TestClsJournal, ClientList) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + ASSERT_EQ(0, client::create(ioctx, oid, 12, 5)); + + std::set expected_clients; + librados::ObjectWriteOperation op1; + for (uint32_t i = 0; i < 512; ++i) { + std::string id = "id" + stringify(i + 1); + expected_clients.insert(Client(id, "")); + client::client_register(&op1, id, ""); + } + ASSERT_EQ(0, ioctx.operate(oid, &op1)); + + std::set clients; + ASSERT_EQ(0, client::client_list(ioctx, oid, &clients)); + ASSERT_EQ(expected_clients, clients); + + C_SaferCond cond; + uint64_t read_minimum_set; + uint64_t read_active_set; + std::set read_clients; + client::get_mutable_metadata(ioctx, oid, &read_minimum_set, &read_active_set, + &read_clients, &cond); + ASSERT_EQ(0, cond.wait()); + ASSERT_EQ(expected_clients, read_clients); +} + +TEST_F(TestClsJournal, GuardAppend) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + bufferlist bl; + bl.append("journal entry!"); + + librados::ObjectWriteOperation op1; + op1.append(bl); + ASSERT_EQ(0, ioctx.operate(oid, &op1)); + + librados::ObjectWriteOperation op2; + client::guard_append(&op2, 1024); + ASSERT_EQ(0, ioctx.operate(oid, &op2)); +} + +TEST_F(TestClsJournal, GuardAppendDNE) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + librados::ObjectWriteOperation op2; + client::guard_append(&op2, 1024); + ASSERT_EQ(0, ioctx.operate(oid, &op2)); +} + +TEST_F(TestClsJournal, GuardAppendOverflow) { + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + std::string oid = get_temp_image_name(); + + bufferlist bl; + bl.append("journal entry!"); + + librados::ObjectWriteOperation op1; + op1.append(bl); + ASSERT_EQ(0, ioctx.operate(oid, &op1)); + + librados::ObjectWriteOperation op2; + client::guard_append(&op2, 1); + ASSERT_EQ(-EOVERFLOW, ioctx.operate(oid, &op2)); +}