]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/cls_hello/test_cls_hello.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Inktank
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
18 #include "include/rados/librados.hpp"
19 #include "include/encoding.h"
20 #include "test/librados/test.h"
21 #include "gtest/gtest.h"
23 using namespace librados
;
25 TEST(ClsHello
, SayHello
) {
27 std::string pool_name
= get_temp_pool_name();
28 ASSERT_EQ("", create_one_pool_pp(pool_name
, cluster
));
30 cluster
.ioctx_create(pool_name
.c_str(), ioctx
);
33 ASSERT_EQ(-ENOENT
, ioctx
.exec("myobject", "hello", "say_hello", in
, out
));
34 ASSERT_EQ(0, ioctx
.write_full("myobject", in
));
35 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "say_hello", in
, out
));
36 ASSERT_EQ(std::string("Hello, world!"), std::string(out
.c_str(), out
.length()));
40 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "say_hello", in
, out
));
41 ASSERT_EQ(std::string("Hello, Tester!"), std::string(out
.c_str(), out
.length()));
46 memset(buf
, 1, sizeof(buf
));
47 in
.append(buf
, sizeof(buf
));
48 ASSERT_EQ(-EINVAL
, ioctx
.exec("myobject", "hello", "say_hello", in
, out
));
50 ASSERT_EQ(0, destroy_one_pool_pp(pool_name
, cluster
));
53 TEST(ClsHello
, RecordHello
) {
55 std::string pool_name
= get_temp_pool_name();
56 ASSERT_EQ("", create_one_pool_pp(pool_name
, cluster
));
58 cluster
.ioctx_create(pool_name
.c_str(), ioctx
);
61 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "record_hello", in
, out
));
62 ASSERT_EQ(-EEXIST
, ioctx
.exec("myobject", "hello", "record_hello", in
, out
));
65 ASSERT_EQ(0, ioctx
.exec("myobject2", "hello", "record_hello", in
, out
));
66 ASSERT_EQ(-EEXIST
, ioctx
.exec("myobject2", "hello", "record_hello", in
, out
));
67 ASSERT_EQ(0u, out
.length());
71 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "replay", in
, out
));
72 ASSERT_EQ(std::string("Hello, world!"), std::string(out
.c_str(), out
.length()));
74 ASSERT_EQ(0, ioctx
.exec("myobject2", "hello", "replay", in
, out
));
75 ASSERT_EQ(std::string("Hello, Tester!"), std::string(out
.c_str(), out
.length()));
77 ASSERT_EQ(0, destroy_one_pool_pp(pool_name
, cluster
));
80 TEST(ClsHello
, WriteReturnData
) {
82 std::string pool_name
= get_temp_pool_name();
83 ASSERT_EQ("", create_one_pool_pp(pool_name
, cluster
));
85 cluster
.ioctx_create(pool_name
.c_str(), ioctx
);
88 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "writes_dont_return_data", in
, out
));
89 ASSERT_EQ(std::string(), std::string(out
.c_str(), out
.length()));
92 memset(buf
, 1, sizeof(buf
));
93 in
.append(buf
, sizeof(buf
));
94 ASSERT_EQ(-EINVAL
, ioctx
.exec("myobject2", "hello", "writes_dont_return_data", in
, out
));
95 ASSERT_EQ(std::string("too much input data!"), std::string(out
.c_str(), out
.length()));
96 ASSERT_EQ(-ENOENT
, ioctx
.getxattr("myobject2", "foo", out
));
98 ASSERT_EQ(0, destroy_one_pool_pp(pool_name
, cluster
));
101 TEST(ClsHello
, Loud
) {
103 std::string pool_name
= get_temp_pool_name();
104 ASSERT_EQ("", create_one_pool_pp(pool_name
, cluster
));
106 cluster
.ioctx_create(pool_name
.c_str(), ioctx
);
109 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "record_hello", in
, out
));
110 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "replay", in
, out
));
111 ASSERT_EQ(std::string("Hello, world!"), std::string(out
.c_str(), out
.length()));
113 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "turn_it_to_11", in
, out
));
114 ASSERT_EQ(0, ioctx
.exec("myobject", "hello", "replay", in
, out
));
115 ASSERT_EQ(std::string("HELLO, WORLD!"), std::string(out
.c_str(), out
.length()));
117 ASSERT_EQ(0, destroy_one_pool_pp(pool_name
, cluster
));
120 TEST(ClsHello
, BadMethods
) {
122 std::string pool_name
= get_temp_pool_name();
123 ASSERT_EQ("", create_one_pool_pp(pool_name
, cluster
));
125 cluster
.ioctx_create(pool_name
.c_str(), ioctx
);
129 ASSERT_EQ(0, ioctx
.write_full("myobject", in
));
130 ASSERT_EQ(-EIO
, ioctx
.exec("myobject", "hello", "bad_reader", in
, out
));
131 ASSERT_EQ(-EIO
, ioctx
.exec("myobject", "hello", "bad_writer", in
, out
));
133 ASSERT_EQ(0, destroy_one_pool_pp(pool_name
, cluster
));
136 TEST(ClsHello
, Filter
) {
138 std::string pool_name
= get_temp_pool_name();
139 ASSERT_EQ("", create_one_pool_pp(pool_name
, cluster
));
141 cluster
.ioctx_create(pool_name
.c_str(), ioctx
);
144 memset(buf
, 0xcc, sizeof(buf
));
145 bufferlist obj_content
;
146 obj_content
.append(buf
, sizeof(buf
));
148 std::string target_str
= "content";
150 // Write xattr bare, no ::encod'ing
151 bufferlist target_val
;
152 target_val
.append(target_str
);
153 bufferlist nontarget_val
;
154 nontarget_val
.append("rhubarb");
156 ASSERT_EQ(0, ioctx
.write("has_xattr", obj_content
, obj_content
.length(), 0));
157 ASSERT_EQ(0, ioctx
.write("has_wrong_xattr", obj_content
, obj_content
.length(), 0));
158 ASSERT_EQ(0, ioctx
.write("no_xattr", obj_content
, obj_content
.length(), 0));
160 ASSERT_EQ(0, ioctx
.setxattr("has_xattr", "theattr", target_val
));
161 ASSERT_EQ(0, ioctx
.setxattr("has_wrong_xattr", "theattr", nontarget_val
));
163 bufferlist filter_bl
;
164 std::string filter_name
= "hello.hello";
165 ::encode(filter_name
, filter_bl
);
166 ::encode("_theattr", filter_bl
);
167 ::encode(target_str
, filter_bl
);
169 NObjectIterator
iter(ioctx
.nobjects_begin(filter_bl
));
170 bool foundit
= false;
172 while (iter
!= ioctx
.nobjects_end()) {
174 // We should only see the object that matches the filter
175 ASSERT_EQ((*iter
).get_oid(), "has_xattr");
176 // We should only see it once
181 ASSERT_TRUE(foundit
);
183 ASSERT_EQ(0, destroy_one_pool_pp(pool_name
, cluster
));