summaryrefslogtreecommitdiffstats
path: root/src/test/cls_hello
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/test/cls_hello
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/cls_hello')
-rw-r--r--src/test/cls_hello/CMakeLists.txt15
-rw-r--r--src/test/cls_hello/test_cls_hello.cc185
2 files changed, 200 insertions, 0 deletions
diff --git a/src/test/cls_hello/CMakeLists.txt b/src/test/cls_hello/CMakeLists.txt
new file mode 100644
index 00000000..9efb95e0
--- /dev/null
+++ b/src/test/cls_hello/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_executable(ceph_test_cls_hello
+ test_cls_hello.cc
+ )
+target_link_libraries(ceph_test_cls_hello
+ librados
+ global
+ ${EXTRALIBS}
+ ${BLKID_LIBRARIES}
+ ${CMAKE_DL_LIBS}
+ radostest-cxx
+ ${UNITTEST_LIBS}
+ )
+install(TARGETS
+ ceph_test_cls_hello
+ DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/src/test/cls_hello/test_cls_hello.cc b/src/test/cls_hello/test_cls_hello.cc
new file mode 100644
index 00000000..7cf30125
--- /dev/null
+++ b/src/test/cls_hello/test_cls_hello.cc
@@ -0,0 +1,185 @@
+// -*- 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) 2013 Inktank
+ *
+ * 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 <errno.h>
+
+#include "include/rados/librados.hpp"
+#include "include/encoding.h"
+#include "test/librados/test_cxx.h"
+#include "gtest/gtest.h"
+
+using namespace librados;
+
+TEST(ClsHello, SayHello) {
+ Rados cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ bufferlist in, out;
+ ASSERT_EQ(-ENOENT, ioctx.exec("myobject", "hello", "say_hello", in, out));
+ ASSERT_EQ(0, ioctx.write_full("myobject", in));
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "say_hello", in, out));
+ ASSERT_EQ(std::string("Hello, world!"), std::string(out.c_str(), out.length()));
+
+ out.clear();
+ in.append("Tester");
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "say_hello", in, out));
+ ASSERT_EQ(std::string("Hello, Tester!"), std::string(out.c_str(), out.length()));
+
+ out.clear();
+ in.clear();
+ char buf[4096];
+ memset(buf, 1, sizeof(buf));
+ in.append(buf, sizeof(buf));
+ ASSERT_EQ(-EINVAL, ioctx.exec("myobject", "hello", "say_hello", in, out));
+
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+
+TEST(ClsHello, RecordHello) {
+ Rados cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ bufferlist in, out;
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "record_hello", in, out));
+ ASSERT_EQ(-EEXIST, ioctx.exec("myobject", "hello", "record_hello", in, out));
+
+ in.append("Tester");
+ ASSERT_EQ(0, ioctx.exec("myobject2", "hello", "record_hello", in, out));
+ ASSERT_EQ(-EEXIST, ioctx.exec("myobject2", "hello", "record_hello", in, out));
+ ASSERT_EQ(0u, out.length());
+
+ in.clear();
+ out.clear();
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "replay", in, out));
+ ASSERT_EQ(std::string("Hello, world!"), std::string(out.c_str(), out.length()));
+ out.clear();
+ ASSERT_EQ(0, ioctx.exec("myobject2", "hello", "replay", in, out));
+ ASSERT_EQ(std::string("Hello, Tester!"), std::string(out.c_str(), out.length()));
+
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+
+TEST(ClsHello, WriteReturnData) {
+ Rados cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ bufferlist in, out;
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "writes_dont_return_data", in, out));
+ ASSERT_EQ(std::string(), std::string(out.c_str(), out.length()));
+
+ char buf[4096];
+ memset(buf, 1, sizeof(buf));
+ in.append(buf, sizeof(buf));
+ ASSERT_EQ(-EINVAL, ioctx.exec("myobject2", "hello", "writes_dont_return_data", in, out));
+ ASSERT_EQ(std::string("too much input data!"), std::string(out.c_str(), out.length()));
+ ASSERT_EQ(-ENOENT, ioctx.getxattr("myobject2", "foo", out));
+
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+
+TEST(ClsHello, Loud) {
+ Rados cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ bufferlist in, out;
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "record_hello", in, out));
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "replay", in, out));
+ ASSERT_EQ(std::string("Hello, world!"), std::string(out.c_str(), out.length()));
+
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "turn_it_to_11", in, out));
+ ASSERT_EQ(0, ioctx.exec("myobject", "hello", "replay", in, out));
+ ASSERT_EQ(std::string("HELLO, WORLD!"), std::string(out.c_str(), out.length()));
+
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+
+TEST(ClsHello, BadMethods) {
+ Rados cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ bufferlist in, out;
+
+ ASSERT_EQ(0, ioctx.write_full("myobject", in));
+ ASSERT_EQ(-EIO, ioctx.exec("myobject", "hello", "bad_reader", in, out));
+ ASSERT_EQ(-EIO, ioctx.exec("myobject", "hello", "bad_writer", in, out));
+
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+
+TEST(ClsHello, Filter) {
+ Rados cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ char buf[128];
+ memset(buf, 0xcc, sizeof(buf));
+ bufferlist obj_content;
+ obj_content.append(buf, sizeof(buf));
+
+ std::string target_str = "content";
+
+ // Write xattr bare, no ::encod'ing
+ bufferlist target_val;
+ target_val.append(target_str);
+ bufferlist nontarget_val;
+ nontarget_val.append("rhubarb");
+
+ ASSERT_EQ(0, ioctx.write("has_xattr", obj_content, obj_content.length(), 0));
+ ASSERT_EQ(0, ioctx.write("has_wrong_xattr", obj_content, obj_content.length(), 0));
+ ASSERT_EQ(0, ioctx.write("no_xattr", obj_content, obj_content.length(), 0));
+
+ ASSERT_EQ(0, ioctx.setxattr("has_xattr", "theattr", target_val));
+ ASSERT_EQ(0, ioctx.setxattr("has_wrong_xattr", "theattr", nontarget_val));
+
+ bufferlist filter_bl;
+ std::string filter_name = "hello.hello";
+ encode(filter_name, filter_bl);
+ encode("_theattr", filter_bl);
+ encode(target_str, filter_bl);
+
+ NObjectIterator iter(ioctx.nobjects_begin(filter_bl));
+ bool foundit = false;
+ int k = 0;
+ while (iter != ioctx.nobjects_end()) {
+ foundit = true;
+ // We should only see the object that matches the filter
+ ASSERT_EQ((*iter).get_oid(), "has_xattr");
+ // We should only see it once
+ ASSERT_EQ(k, 0);
+ ++iter;
+ ++k;
+ }
+ ASSERT_TRUE(foundit);
+
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+