-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test/neorados: Rounding out test coverage, part 1
This includes cls, cmd, and read_operations. Signed-off-by: Adam Emerson <[email protected]>
- Loading branch information
1 parent
3775d7e
commit ef49105
Showing
4 changed files
with
1,009 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
/* | ||
* Ceph - scalable distributed file system | ||
* | ||
* Copyright (C) 2023 IBM | ||
* | ||
* See file COPYING for license information. | ||
* | ||
*/ | ||
|
||
#include <array> | ||
#include <coroutine> | ||
#include <memory> | ||
#include <string_view> | ||
#include <utility> | ||
|
||
#include <boost/asio/use_awaitable.hpp> | ||
|
||
#include <boost/system/errc.hpp> | ||
|
||
#include "include/neorados/RADOS.hpp" | ||
|
||
#include "common/ceph_json.h" | ||
|
||
#include "test/neorados/common_tests.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace asio = boost::asio; | ||
namespace sys = boost::system; | ||
|
||
using namespace std::literals; | ||
|
||
using neorados::ReadOp; | ||
using neorados::WriteOp; | ||
|
||
CORO_TEST_F(NeoRadosCls, DNE, NeoRadosTest) | ||
{ | ||
std::string_view oid = "obj"; | ||
co_await execute(oid, WriteOp{}.create(true)); | ||
// Call a bogus class | ||
co_await expect_error_code( | ||
execute(oid, ReadOp{}.exec("doesnotexistasdfasdf", "method", {})), | ||
sys::errc::operation_not_supported); | ||
|
||
// Call a bogus method on an existent class | ||
co_await expect_error_code( | ||
execute(oid, ReadOp{}.exec("lock", "doesnotexistasdfasdfasdf", {})), | ||
sys::errc::operation_not_supported); | ||
co_return; | ||
} | ||
|
||
CORO_TEST_F(NeoRadosCls, RemoteReads, NeoRadosTest) | ||
{ | ||
static constexpr std::size_t object_size = 4096; | ||
static constexpr std::array oids{"src_object.1"sv, "src_object.2"sv, | ||
"src_object.3"sv}; | ||
|
||
std::array<char, object_size> buf; | ||
buf.fill(1); | ||
|
||
for (const auto& oid : oids) { | ||
buffer::list in; | ||
in.append(buf.data(), buf.size()); | ||
co_await execute(oid, WriteOp{}.write_full(std::move(in))); | ||
} | ||
|
||
// Construct JSON request passed to "test_gather" method, and in | ||
// turn, to "test_read" method | ||
buffer::list in; | ||
{ | ||
auto formatter = std::make_unique<JSONFormatter>(true); | ||
formatter->open_object_section("foo"); | ||
encode_json("src_objects", oids, formatter.get()); | ||
encode_json("cls", "test_remote_reads", formatter.get()); | ||
encode_json("method", "test_read", formatter.get()); | ||
encode_json("pool", pool_name(), formatter.get()); | ||
formatter->close_section(); | ||
formatter->flush(in); | ||
} | ||
|
||
static const auto target = "tgt_object"s; | ||
|
||
// Create target object by combining data gathered from source | ||
// objects using "test_read" method | ||
co_await execute(target, | ||
WriteOp{}.exec("test_remote_reads", "test_gather", in)); | ||
|
||
|
||
// Read target object and check its size. | ||
buffer::list out; | ||
co_await execute(target, ReadOp{}.read(0, 0, &out)); | ||
EXPECT_EQ(3 * object_size, out.length()); | ||
|
||
co_return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
/* | ||
* Ceph - scalable distributed file system | ||
* | ||
* Copyright (C) 2023 IBM | ||
* | ||
* See file COPYING for license information. | ||
* | ||
*/ | ||
|
||
#include <array> | ||
#include <coroutine> | ||
|
||
#include <fmt/format.h> | ||
|
||
#include <boost/asio/as_tuple.hpp> | ||
#include <boost/asio/use_awaitable.hpp> | ||
|
||
#include <boost/system/errc.hpp> | ||
|
||
#include "include/neorados/RADOS.hpp" | ||
|
||
#include "include/stringify.h" | ||
|
||
#include "test/neorados/common_tests.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace asio = boost::asio; | ||
namespace sys = boost::system; | ||
namespace buffer = ceph::buffer; | ||
|
||
using neorados::ReadOp; | ||
|
||
using namespace std::literals; | ||
|
||
CORO_TEST_F(NeoRadosCmd, MonDescribe, NeoRadosTest) { | ||
std::string outs; | ||
buffer::list outbl; | ||
std::vector arg({R"({"prefix": "get_command_descriptions"})"s}); | ||
co_await rados().mon_command(std::move(arg), {}, &outs, &outbl, | ||
asio::use_awaitable); | ||
EXPECT_LT(0u, outbl.length()); | ||
EXPECT_LE(0u, outs.length()); | ||
co_return; | ||
} | ||
|
||
CORO_TEST_F(NeoRadosCmd, OSDCmd, NeoRadosTest) { | ||
{ | ||
std::vector arg({R"(asdfasdf)"s}); | ||
co_await expect_error_code( | ||
rados().osd_command(0, std::move(arg), | ||
{}, asio::use_awaitable), | ||
sys::errc::invalid_argument, sys::errc::no_such_device_or_address); | ||
} | ||
|
||
{ | ||
std::vector arg({R"(version)"s}); | ||
co_await expect_error_code( | ||
rados().osd_command(0, std::move(arg), | ||
{}, asio::use_awaitable), | ||
sys::errc::invalid_argument, sys::errc::no_such_device_or_address); | ||
} | ||
|
||
{ | ||
std::vector arg({R"({"prefix":"version"})"s}); | ||
auto [ec, outs, outbl] = co_await | ||
rados().osd_command(0, std::move(arg), {}, | ||
asio::as_tuple(asio::use_awaitable)); | ||
|
||
EXPECT_TRUE((!ec && outbl.length() > 0) || | ||
(ec == sys::errc::no_such_device_or_address && | ||
outbl.length() == 0)); | ||
|
||
} | ||
co_return; | ||
} | ||
|
||
CORO_TEST_F(NeoRadosCmd, PGCmd, NeoRadosTest) { | ||
const neorados::PG pgid{uint64_t(pool().get_pool()), 0}; | ||
|
||
{ | ||
std::vector arg({R"(asdfasdf)"s}); | ||
// note: tolerate NXIO here in case the cluster is thrashing out underneath us. | ||
co_await expect_error_code( | ||
rados().pg_command(pgid, std::move(arg), | ||
{}, asio::use_awaitable), | ||
sys::errc::invalid_argument, sys::errc::no_such_device_or_address); | ||
} | ||
|
||
// make sure the pg exists on the osd before we query it | ||
for (auto i = 0; i < 100; ++i) { | ||
co_await expect_error_code( | ||
rados().execute(fmt::format("obj{}", i), pool(), | ||
ReadOp{}.assert_exists(), nullptr, | ||
asio::use_awaitable), | ||
sys::errc::no_such_file_or_directory); | ||
} | ||
|
||
{ | ||
std::vector arg({fmt::format(R"({{"prefix":"pg", "cmd":"query", "pgid":"{}.{}"}})", | ||
pgid.pool, pgid.seed)}); | ||
// Working around a bug in GCC. | ||
auto coro = rados().pg_command(pgid, std::move(arg), | ||
{}, asio::as_tuple(asio::use_awaitable)); | ||
auto [ec, outs, outbl] = co_await std::move(coro); | ||
|
||
EXPECT_TRUE(!ec || ec == sys::errc::no_such_file_or_directory || | ||
ec == sys::errc::no_such_device_or_address); | ||
|
||
EXPECT_LT(0u, outbl.length()); | ||
} | ||
|
||
co_return; | ||
} |
Oops, something went wrong.