summaryrefslogtreecommitdiffstats
path: root/src/test/neorados
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/neorados/CMakeLists.txt28
-rw-r--r--src/test/neorados/common_tests.cc34
-rw-r--r--src/test/neorados/common_tests.h41
-rw-r--r--src/test/neorados/completions.cc20
-rw-r--r--src/test/neorados/list_pool.cc166
-rw-r--r--src/test/neorados/op_speed.cc34
-rw-r--r--src/test/neorados/start_stop.cc174
-rw-r--r--src/test/neorados/test_neorados.cc47
8 files changed, 544 insertions, 0 deletions
diff --git a/src/test/neorados/CMakeLists.txt b/src/test/neorados/CMakeLists.txt
new file mode 100644
index 000000000..31e79a661
--- /dev/null
+++ b/src/test/neorados/CMakeLists.txt
@@ -0,0 +1,28 @@
+
+add_executable(ceph_test_neorados test_neorados.cc)
+target_link_libraries(ceph_test_neorados global libneorados
+ ${unittest_libs}
+ radostest
+ radostest-cxx
+ librados
+ GTest::GTest)
+
+add_executable(ceph_test_neorados_start_stop start_stop.cc)
+target_link_libraries(ceph_test_neorados_start_stop global libneorados
+ ${unittest_libs})
+
+add_executable(ceph_test_neorados_completions completions.cc)
+target_link_libraries(ceph_test_neorados_completions Boost::system pthread
+ ${unittest_libs})
+
+add_executable(ceph_test_neorados_op_speed op_speed.cc)
+target_link_libraries(ceph_test_neorados_op_speed
+ libneorados fmt::fmt ${unittest_libs})
+
+add_library(neoradostest-support STATIC common_tests.cc)
+target_link_libraries(neoradostest-support
+ libneorados fmt::fmt)
+
+add_executable(ceph_test_neorados_list_pool list_pool.cc)
+target_link_libraries(ceph_test_neorados_list_pool
+ libneorados neoradostest-support global fmt::fmt ${unittest_libs})
diff --git a/src/test/neorados/common_tests.cc b/src/test/neorados/common_tests.cc
new file mode 100644
index 000000000..4e4b6c0af
--- /dev/null
+++ b/src/test/neorados/common_tests.cc
@@ -0,0 +1,34 @@
+// -*- 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) 2020 Red Hat, Inc.
+ * Author: Adam C. Emerson <aemerson@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ */
+
+#include <cstring>
+#include <string>
+#include <string_view>
+
+#include <boost/asio/ip/host_name.hpp>
+
+#include <fmt/format.h>
+
+#include "common_tests.h"
+#include "include/neorados/RADOS.hpp"
+
+namespace ba = boost::asio;
+namespace R = neorados;
+
+std::string get_temp_pool_name(std::string_view prefix)
+{
+ static auto hostname = ba::ip::host_name();
+ static auto num = 1ull;
+ return fmt::format("{}{}-{}-{}", prefix, hostname, getpid(), num++);
+}
diff --git a/src/test/neorados/common_tests.h b/src/test/neorados/common_tests.h
new file mode 100644
index 000000000..ca3d7bf7f
--- /dev/null
+++ b/src/test/neorados/common_tests.h
@@ -0,0 +1,41 @@
+// -*- 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) 2020 Red Hat, Inc.
+ * Author: Adam C. Emerson <aemerson@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ */
+
+#include <string>
+#include <string_view>
+
+#include "include/neorados/RADOS.hpp"
+
+std::string get_temp_pool_name(std::string_view prefix = {});
+
+template<typename CompletionToken>
+auto create_pool(neorados::RADOS& r, std::string_view pname,
+ CompletionToken&& token)
+{
+ boost::asio::async_completion<CompletionToken,
+ void(boost::system::error_code,
+ std::int64_t)> init(token);
+ r.create_pool(pname, std::nullopt,
+ [&r, pname = std::string(pname),
+ h = std::move(init.completion_handler)]
+ (boost::system::error_code ec) mutable {
+ r.lookup_pool(
+ pname,
+ [h = std::move(h)]
+ (boost::system::error_code ec, std::int64_t pool) mutable {
+ std::move(h)(ec, pool);
+ });
+ });
+ return init.result.get();
+}
diff --git a/src/test/neorados/completions.cc b/src/test/neorados/completions.cc
new file mode 100644
index 000000000..d9c0e0870
--- /dev/null
+++ b/src/test/neorados/completions.cc
@@ -0,0 +1,20 @@
+#include <cassert>
+#include <boost/asio.hpp>
+#include <boost/system/system_error.hpp>
+
+constexpr int max_completions = 10'000'000;
+int completed = 0;
+
+boost::asio::io_context c;
+
+void nested_cb() {
+ if (++completed < max_completions)
+ c.post(&nested_cb);
+}
+
+int main(void) {
+ c.post(&nested_cb);
+ c.run();
+ assert(completed == max_completions);
+ return 0;
+}
diff --git a/src/test/neorados/list_pool.cc b/src/test/neorados/list_pool.cc
new file mode 100644
index 000000000..ae36c36e6
--- /dev/null
+++ b/src/test/neorados/list_pool.cc
@@ -0,0 +1,166 @@
+// -*- 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) 2019 Red Hat <contact@redhat.com>
+ * Author: Adam C. Emerson <aemerson@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include <iostream>
+#include <initializer_list>
+#include <optional>
+#include <thread>
+#include <tuple>
+#include <string_view>
+#include <vector>
+
+#include <sys/param.h>
+
+#include <unistd.h>
+
+#include <boost/system/system_error.hpp>
+
+#include <fmt/format.h>
+
+#include "include/neorados/RADOS.hpp"
+
+#include "include/scope_guard.h"
+
+#include "common/async/context_pool.h"
+#include "common/ceph_time.h"
+#include "common/ceph_argparse.h"
+#include "common/async/blocked_completion.h"
+
+#include "global/global_init.h"
+
+#include "test/neorados/common_tests.h"
+
+
+namespace ba = boost::asio;
+namespace bs = boost::system;
+namespace ca = ceph::async;
+namespace R = neorados;
+
+std::string_view hostname() {
+ static char hostname[MAXHOSTNAMELEN] = { 0 };
+ static size_t len = 0;
+ if (!len) {
+ auto r = gethostname(hostname, sizeof(hostname));
+ if (r != 0) {
+ throw bs::system_error(
+ errno, bs::system_category());
+ }
+ len = std::strlen(hostname);
+ }
+ return {hostname, len};
+}
+
+std::string temp_pool_name(const std::string_view prefix)
+{
+ using namespace std::chrono;
+ static std::uint64_t num = 1;
+ return fmt::format(
+ "{}-{}-{}-{}-{}",
+ prefix,
+ hostname(),
+ getpid(),
+ duration_cast<milliseconds>(ceph::coarse_real_clock::now()
+ .time_since_epoch()).count(),
+ num++);
+}
+
+bs::error_code noisy_list(R::RADOS& r, int64_t p)
+{
+ auto b = R::Cursor::begin();
+ auto e = R::Cursor::end();
+
+ std::cout << "begin = " << b.to_str() << std::endl;
+ std::cout << "end = " << e.to_str() << std::endl;
+ try {
+ auto [v, next] = r.enumerate_objects(p, b, e, 1000, {}, ca::use_blocked,
+ R::all_nspaces);
+
+ std::cout << "Got " << v.size() << " entries." << std::endl;
+ std::cout << "next cursor = " << next.to_str() << std::endl;
+ std::cout << "next == end: " << (next == e) << std::endl;
+ std::cout << "Returned Objects: ";
+ std::cout << "[";
+ auto o = v.cbegin();
+ while (o != v.cend()) {
+ std::cout << *o;
+ if (++o != v.cend())
+ std::cout << " ";
+ }
+ std::cout << "]" << std::endl;
+ } catch (const bs::system_error& e) {
+ std::cerr << "RADOS::enumerate_objects: " << e.what() << std::endl;
+ return e.code();
+ }
+ return {};
+}
+
+bs::error_code create_several(R::RADOS& r, const R::IOContext& i,
+ std::initializer_list<std::string> l)
+{
+ for (const auto& o : l) try {
+ R::WriteOp op;
+ std::cout << "Creating " << o << std::endl;
+ ceph::bufferlist bl;
+ bl.append("My bologna has no name.");
+ op.write_full(std::move(bl));
+ r.execute(o, i, std::move(op), ca::use_blocked);
+ } catch (const bs::system_error& e) {
+ std::cerr << "RADOS::execute: " << e.what() << std::endl;
+ return e.code();
+ }
+ return {};
+}
+
+int main(int argc, char** argv)
+{
+ using namespace std::literals;
+
+ auto args = argv_to_vec(argc, argv);
+ env_to_vec(args);
+
+ auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
+ CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(cct.get());
+
+ try {
+ ca::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p, ca::use_blocked);
+
+ auto pool_name = get_temp_pool_name("ceph_test_RADOS_list_pool"sv);
+ r.create_pool(pool_name, std::nullopt, ca::use_blocked);
+ auto pd = make_scope_guard(
+ [&pool_name, &r]() {
+ r.delete_pool(pool_name, ca::use_blocked);
+ });
+ auto pool = r.lookup_pool(pool_name, ca::use_blocked);
+ R::IOContext i(pool);
+
+ if (noisy_list(r, pool)) {
+ return 1;
+ }
+ if (create_several(r, i, {"meow", "woof", "squeak"})) {
+ return 1;
+ }
+ if (noisy_list(r, pool)) {
+ return 1;
+ }
+
+ } catch (const bs::system_error& e) {
+ std::cerr << "Error: " << e.what() << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/src/test/neorados/op_speed.cc b/src/test/neorados/op_speed.cc
new file mode 100644
index 000000000..587c345d4
--- /dev/null
+++ b/src/test/neorados/op_speed.cc
@@ -0,0 +1,34 @@
+// -*- 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) 2019 Red Hat <contact@redhat.com>
+ * Author: Adam C. Emerson <aemerson@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include "include/neorados/RADOS.hpp"
+
+constexpr int to_create = 10'000'000;
+
+int main() {
+ for (int i = 0; i < to_create; ++i) {
+ neorados::ReadOp op;
+ bufferlist bl;
+ std::uint64_t sz;
+ ceph::real_time tm;
+ boost::container::flat_map<std::string, ceph::buffer::list> xattrs;
+ boost::container::flat_map<std::string, ceph::buffer::list> omap;
+ bool trunc;
+ op.read(0, 0, &bl);
+ op.stat(&sz, &tm);
+ op.get_xattrs(&xattrs);
+ op.get_omap_vals(std::nullopt, std::nullopt, 1000, &omap, &trunc);
+ }
+}
diff --git a/src/test/neorados/start_stop.cc b/src/test/neorados/start_stop.cc
new file mode 100644
index 000000000..4ea0ae564
--- /dev/null
+++ b/src/test/neorados/start_stop.cc
@@ -0,0 +1,174 @@
+// -*- 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) 2019 Red Hat <contact@redhat.com>
+ * Author: Adam C. Emerson <aemerson@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include <thread>
+#include <vector>
+
+#include "include/neorados/RADOS.hpp"
+
+#include "common/async/context_pool.h"
+#include "common/ceph_argparse.h"
+
+#include "global/global_init.h"
+
+namespace R = neorados;
+
+
+int main(int argc, char** argv)
+{
+ using namespace std::literals;
+
+ auto args = argv_to_vec(argc, argv);
+ env_to_vec(args);
+
+ auto cct = global_init(nullptr, args, CEPH_ENTITY_TYPE_CLIENT,
+ CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(cct.get());
+
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(30s);
+ }
+ std::this_thread::sleep_for(30s);
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(30s);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(1s);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(1s);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(1s);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(1s);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(1s);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(1s);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(1s);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(500ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(500ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(50ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(50ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(50ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(5ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(5ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(5ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(5ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(5ms);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(5us);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(5us);
+ }
+ {
+ ceph::async::io_context_pool p(1);
+ auto r = R::RADOS::make_with_cct(cct.get(), p,
+ boost::asio::use_future).get();
+ std::this_thread::sleep_for(5us);
+ }
+ return 0;
+}
diff --git a/src/test/neorados/test_neorados.cc b/src/test/neorados/test_neorados.cc
new file mode 100644
index 000000000..953e772e1
--- /dev/null
+++ b/src/test/neorados/test_neorados.cc
@@ -0,0 +1,47 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "include/rados/librados.hpp"
+#include "include/neorados/RADOS.hpp"
+#include "common/async/blocked_completion.h"
+#include "test/librados/test_cxx.h"
+#include "gtest/gtest.h"
+#include <iostream>
+
+namespace neorados {
+
+class TestNeoRADOS : public ::testing::Test {
+public:
+ TestNeoRADOS() {
+ }
+};
+
+TEST_F(TestNeoRADOS, MakeWithLibRADOS) {
+ librados::Rados paleo_rados;
+ auto result = connect_cluster_pp(paleo_rados);
+ ASSERT_EQ("", result);
+
+ auto rados = RADOS::make_with_librados(paleo_rados);
+
+ ReadOp op;
+ bufferlist bl;
+ op.read(0, 0, &bl);
+
+ // provide pool that doesn't exists -- just testing round-trip
+ ASSERT_THROW(
+ rados.execute({"dummy-obj"}, std::numeric_limits<int64_t>::max(),
+ std::move(op), nullptr, ceph::async::use_blocked),
+ boost::system::system_error);
+}
+
+} // namespace neorados
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+
+ int seed = getpid();
+ std::cout << "seed " << seed << std::endl;
+ srand(seed);
+
+ return RUN_ALL_TESTS();
+}