+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*
+// vim: ts=8 sw=2 smarttab
+
#include "include/rados/librados.h"
#include "include/rados/librados.hpp"
#include "test/librados/test.h"
+#include "test/librados/TestCase.h"
#include <errno.h>
#include "gtest/gtest.h"
using namespace librados;
using std::string;
-TEST(LibRadosIo, SimpleWrite) {
+typedef RadosTest LibRadosIo;
+typedef RadosTestPP LibRadosIoPP;
+
+TEST_F(LibRadosIo, SimpleWrite) {
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
rados_ioctx_set_namespace(ioctx, "nspace");
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, SimpleWritePP) {
+TEST_F(LibRadosIoPP, SimpleWritePP) {
char buf[128];
- std::string pool_name = get_temp_pool_name();
- Rados cluster;
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- cluster.ioctx_create(pool_name.c_str(), ioctx);
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
bl.append(buf, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl, sizeof(buf), 0));
ioctx.set_namespace("nspace");
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl, sizeof(buf), 0));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, RoundTrip) {
+TEST_F(LibRadosIo, RoundTrip) {
char buf[128];
char buf2[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
memset(buf2, 0, sizeof(buf2));
ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "foo", buf2, sizeof(buf2), 0));
ASSERT_EQ(0, memcmp(buf, buf2, sizeof(buf)));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, RoundTripPP) {
+TEST_F(LibRadosIoPP, RoundTripPP) {
char buf[128];
char buf2[128];
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);
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
bl.append(buf, sizeof(buf));
bufferlist cl;
ASSERT_EQ((int)sizeof(buf2), ioctx.read("foo", cl, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(buf, cl.c_str(), sizeof(buf)));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, OverlappingWriteRoundTrip) {
+TEST_F(LibRadosIo, OverlappingWriteRoundTrip) {
char buf[128];
char buf2[64];
char buf3[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
memset(buf2, 0xdd, sizeof(buf2));
ASSERT_EQ((int)sizeof(buf3), rados_read(ioctx, "foo", buf3, sizeof(buf3), 0));
ASSERT_EQ(0, memcmp(buf3, buf2, sizeof(buf2)));
ASSERT_EQ(0, memcmp(buf3 + sizeof(buf2), buf, sizeof(buf) - sizeof(buf2)));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, OverlappingWriteRoundTripPP) {
+TEST_F(LibRadosIoPP, OverlappingWriteRoundTripPP) {
char buf[128];
char buf2[64];
- 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);
memset(buf, 0xcc, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), ioctx.read("foo", bl3, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(bl3.c_str(), buf2, sizeof(buf2)));
ASSERT_EQ(0, memcmp(bl3.c_str() + sizeof(buf2), buf, sizeof(buf) - sizeof(buf2)));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, WriteFullRoundTrip) {
+TEST_F(LibRadosIo, WriteFullRoundTrip) {
char buf[128];
char buf2[64];
char buf3[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
memset(buf2, 0xdd, sizeof(buf2));
memset(buf3, 0xdd, sizeof(buf3));
ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "foo", buf3, sizeof(buf3), 0));
ASSERT_EQ(0, memcmp(buf2, buf2, sizeof(buf2)));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, WriteFullRoundTripPP) {
+TEST_F(LibRadosIoPP, WriteFullRoundTripPP) {
char buf[128];
char buf2[64];
- Rados cluster;
- IoCtx ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- cluster.ioctx_create(pool_name.c_str(), ioctx);
memset(buf, 0xcc, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
bufferlist bl3;
ASSERT_EQ((int)sizeof(buf2), ioctx.read("foo", bl3, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(bl3.c_str(), buf2, sizeof(buf2)));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, AppendRoundTrip) {
+TEST_F(LibRadosIo, AppendRoundTrip) {
char buf[64];
char buf2[64];
char buf3[sizeof(buf) + sizeof(buf2)];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xde, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
memset(buf2, 0xad, sizeof(buf2));
ASSERT_EQ((int)sizeof(buf3), rados_read(ioctx, "foo", buf3, sizeof(buf3), 0));
ASSERT_EQ(0, memcmp(buf3, buf, sizeof(buf)));
ASSERT_EQ(0, memcmp(buf3 + sizeof(buf), buf2, sizeof(buf2)));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, AppendRoundTripPP) {
+TEST_F(LibRadosIoPP, AppendRoundTripPP) {
char buf[64];
char buf2[64];
- Rados cluster;
- IoCtx ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- cluster.ioctx_create(pool_name.c_str(), ioctx);
memset(buf, 0xde, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
const char *bl3_str = bl3.c_str();
ASSERT_EQ(0, memcmp(bl3_str, buf, sizeof(buf)));
ASSERT_EQ(0, memcmp(bl3_str + sizeof(buf), buf2, sizeof(buf2)));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, TruncTest) {
+TEST_F(LibRadosIo, TruncTest) {
char buf[128];
char buf2[sizeof(buf)];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
ASSERT_EQ(0, rados_trunc(ioctx, "foo", sizeof(buf) / 2));
memset(buf2, 0, sizeof(buf2));
ASSERT_EQ((int)(sizeof(buf)/2), rados_read(ioctx, "foo", buf2, sizeof(buf2), 0));
ASSERT_EQ(0, memcmp(buf, buf2, sizeof(buf)/2));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, TruncTestPP) {
+TEST_F(LibRadosIoPP, TruncTestPP) {
char buf[128];
- Rados cluster;
- IoCtx ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- cluster.ioctx_create(pool_name.c_str(), ioctx);
memset(buf, 0xaa, sizeof(buf));
bufferlist bl;
bl.append(buf, sizeof(buf));
bufferlist bl2;
ASSERT_EQ((int)(sizeof(buf)/2), ioctx.read("foo", bl2, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(bl2.c_str(), buf, sizeof(buf)/2));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, RemoveTest) {
+TEST_F(LibRadosIo, RemoveTest) {
char buf[128];
char buf2[sizeof(buf)];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
ASSERT_EQ(0, rados_remove(ioctx, "foo"));
memset(buf2, 0, sizeof(buf2));
ASSERT_EQ(-ENOENT, rados_read(ioctx, "foo", buf2, sizeof(buf2), 0));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, RemoveTestPP) {
+TEST_F(LibRadosIoPP, RemoveTestPP) {
char buf[128];
- Rados cluster;
- IoCtx ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- cluster.ioctx_create(pool_name.c_str(), ioctx);
memset(buf, 0xaa, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
ASSERT_EQ(0, ioctx.remove("foo"));
bufferlist bl2;
ASSERT_EQ(-ENOENT, ioctx.read("foo", bl2, sizeof(buf), 0));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, XattrsRoundTrip) {
+TEST_F(LibRadosIo, XattrsRoundTrip) {
char buf[128];
char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz";
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
ASSERT_EQ(-ENODATA, rados_getxattr(ioctx, "foo", attr1, buf, sizeof(buf)));
ASSERT_EQ((int)sizeof(attr1_buf),
rados_getxattr(ioctx, "foo", attr1, buf, sizeof(buf)));
ASSERT_EQ(0, memcmp(attr1_buf, buf, sizeof(attr1_buf)));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, XattrsRoundTripPP) {
+TEST_F(LibRadosIoPP, XattrsRoundTripPP) {
char buf[128];
char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz";
- Rados cluster;
- IoCtx ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- cluster.ioctx_create(pool_name.c_str(), ioctx);
memset(buf, 0xaa, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
ASSERT_EQ((int)sizeof(attr1_buf),
ioctx.getxattr("foo", attr1, bl4));
ASSERT_EQ(0, memcmp(bl4.c_str(), attr1_buf, sizeof(attr1_buf)));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, RmXattr) {
+TEST_F(LibRadosIo, RmXattr) {
char buf[128];
char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz";
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
ASSERT_EQ(0,
rados_setxattr(ioctx, "foo", attr1, attr1_buf, sizeof(attr1_buf)));
ASSERT_EQ(0, rados_rmxattr(ioctx, "foo", attr1));
ASSERT_EQ(-ENODATA, rados_getxattr(ioctx, "foo", attr1, buf, sizeof(buf)));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, RmXattrPP) {
+TEST_F(LibRadosIoPP, RmXattrPP) {
char buf[128];
char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz";
- Rados cluster;
- IoCtx ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- cluster.ioctx_create(pool_name.c_str(), ioctx);
memset(buf, 0xaa, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
ASSERT_EQ(0, ioctx.rmxattr("foo", attr1));
bufferlist bl3;
ASSERT_EQ(-ENODATA, ioctx.getxattr("foo", attr1, bl3));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosIo, XattrIter) {
+TEST_F(LibRadosIo, XattrIter) {
char buf[128];
char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz";
for (size_t j = 0; j < sizeof(attr2_buf); ++j) {
attr2_buf[j] = j % 0xff;
}
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
ASSERT_EQ(0, rados_setxattr(ioctx, "foo", attr1, attr1_buf, sizeof(attr1_buf)));
}
}
rados_getxattrs_end(iter);
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosIo, XattrListPP) {
+TEST_F(LibRadosIoPP, XattrListPP) {
char buf[128];
char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz";
for (size_t j = 0; j < sizeof(attr2_buf); ++j) {
attr2_buf[j] = j % 0xff;
}
- Rados cluster;
- IoCtx ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- cluster.ioctx_create(pool_name.c_str(), ioctx);
memset(buf, 0xaa, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
ASSERT_EQ(0, 1);
}
}
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
#include "include/rados/librados.hpp"
#include "include/stringify.h"
#include "test/librados/test.h"
+#include "test/librados/TestCase.h"
#include "include/types.h"
#include "gtest/gtest.h"
using namespace librados;
-TEST(LibRadosList, ListObjects) {
+typedef RadosTest LibRadosList;
+typedef RadosTestPP LibRadosListPP;
+
+TEST_F(LibRadosList, ListObjects) {
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
rados_list_ctx_t ctx;
}
ASSERT_TRUE(foundit);
rados_objects_list_close(ctx);
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosList, ListObjectsPP) {
- std::string pool_name = get_temp_pool_name();
- Rados cluster;
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- cluster.ioctx_create(pool_name.c_str(), ioctx);
+TEST_F(LibRadosListPP, ListObjectsPP) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl1;
++iter;
}
ASSERT_TRUE(foundit);
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
static void check_list(std::set<std::string>& myset, rados_list_ctx_t& ctx)
ASSERT_TRUE(myset.empty());
}
-TEST(LibRadosList, ListObjectsNS) {
+TEST_F(LibRadosList, ListObjectsNS) {
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
// Create :foo1, :foo2, :foo3, n1:foo1, ns1:foo4, ns1:foo5, ns2:foo6, n2:foo7
+ rados_ioctx_set_namespace(ioctx, "");
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo1", buf, sizeof(buf), 0));
rados_ioctx_set_namespace(ioctx, "ns1");
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo1", buf, sizeof(buf), 0));
ASSERT_EQ(0, rados_objects_list_open(ioctx, &ctx));
check_list(ns2, ctx);
rados_objects_list_close(ctx);
-
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
static void check_listpp(std::set<std::string>& myset, IoCtx& ioctx)
ASSERT_TRUE(myset.empty());
}
-TEST(LibRadosList, ListObjectsPPNS) {
- std::string pool_name = get_temp_pool_name();
- Rados cluster;
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- cluster.ioctx_create(pool_name.c_str(), ioctx);
+TEST_F(LibRadosListPP, ListObjectsPPNS) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl1;
bl1.append(buf, sizeof(buf));
// Create :foo1, :foo2, :foo3, n1:foo1, ns1:foo4, ns1:foo5, ns2:foo6, n2:foo7
+ ioctx.set_namespace("");
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo1", bl1, sizeof(buf), 0));
ioctx.set_namespace("ns1");
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo1", bl1, sizeof(buf), 0));
ioctx.set_namespace("ns2");
check_listpp(ns2, ioctx);
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosList, ListObjectsManyPP) {
- std::string pool_name = get_temp_pool_name();
- Rados cluster;
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- cluster.ioctx_create(pool_name.c_str(), ioctx);
-
+TEST_F(LibRadosListPP, ListObjectsManyPP) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
// make sure they are 0..n
for (unsigned i = 0; i < saw_pg.size(); ++i)
ASSERT_TRUE(saw_pg.count(i));
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-
-
-TEST(LibRadosList, ListObjectsStart) {
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
-
+TEST_F(LibRadosList, ListObjectsStart) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
++p;
}
rados_objects_list_close(ctx);
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosList, ListObjectsStartPP) {
- std::string pool_name = get_temp_pool_name();
- Rados cluster;
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- cluster.ioctx_create(pool_name.c_str(), ioctx);
-
+TEST_F(LibRadosListPP, ListObjectsStartPP) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
ASSERT_TRUE(p->second.count(it->first));
++p;
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
#include "include/rados/librados.h"
#include "include/rados/librados.hpp"
#include "test/librados/test.h"
+#include "test/librados/TestCase.h"
#include "cls/lock/cls_lock_client.h"
#include <algorithm>
using namespace librados;
-TEST(LibRadosLock, LockExclusive) {
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
+typedef RadosTest LibRadosLock;
+typedef RadosTestPP LibRadosLockPP;
+
+TEST_F(LibRadosLock, LockExclusive) {
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(-EEXIST, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosLock, LockExclusivePP) {
- 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);
+TEST_F(LibRadosLockPP, LockExclusivePP) {
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(-EEXIST, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosLock, LockShared) {
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
+TEST_F(LibRadosLock, LockShared) {
ASSERT_EQ(0, rados_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
ASSERT_EQ(-EEXIST, rados_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosLock, LockSharedPP) {
- 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);
+TEST_F(LibRadosLockPP, LockSharedPP) {
ASSERT_EQ(0, ioctx.lock_shared("foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
ASSERT_EQ(-EEXIST, ioctx.lock_shared("foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosLock, LockExclusiveDur) {
+TEST_F(LibRadosLock, LockExclusiveDur) {
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", &tv, 0));
sleep(1);
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosLock, LockExclusiveDurPP) {
+TEST_F(LibRadosLockPP, LockExclusiveDurPP) {
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
- 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);
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", &tv, 0));
sleep(1);
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosLock, LockSharedDur) {
+TEST_F(LibRadosLock, LockSharedDur) {
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
ASSERT_EQ(0, rados_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", &tv, 0));
sleep(1);
ASSERT_EQ(0, rados_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosLock, LockSharedDurPP) {
+TEST_F(LibRadosLockPP, LockSharedDurPP) {
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
- 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);
ASSERT_EQ(0, ioctx.lock_shared("foo", "TestLock", "Cookie", "Tag", "", &tv, 0));
sleep(1);
ASSERT_EQ(0, ioctx.lock_shared("foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosLock, LockRenew) {
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
+TEST_F(LibRadosLock, LockRenew) {
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(-EEXIST, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, LOCK_FLAG_RENEW));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosLock, LockRenewPP) {
- 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);
+TEST_F(LibRadosLockPP, LockRenewPP) {
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(-EEXIST, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, LOCK_FLAG_RENEW));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosLock, Unlock) {
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
+TEST_F(LibRadosLock, Unlock) {
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(0, rados_unlock(ioctx, "foo", "TestLock", "Cookie"));
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosLock, UnlockPP) {
- 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);
+TEST_F(LibRadosLockPP, UnlockPP) {
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(0, ioctx.unlock("foo", "TestLock", "Cookie"));
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosLock, ListLockers) {
+TEST_F(LibRadosLock, ListLockers) {
int exclusive;
char tag[1024];
char clients[1024];
size_t clients_len = 1024;
size_t cookies_len = 1024;
size_t addresses_len = 1024;
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
std::stringstream sstm;
sstm << "client." << rados_get_instance_id(cluster);
std::string me = sstm.str();
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
ASSERT_EQ(0, rados_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
ASSERT_EQ(0, rados_unlock(ioctx, "foo", "TestLock", "Cookie"));
ASSERT_EQ(0, rados_list_lockers(ioctx, "foo", "TestLock", &exclusive, tag, &tag_len, clients, &clients_len, cookies, &cookies_len, addresses, &addresses_len ));
ASSERT_EQ(me.size() + 1, clients_len);
ASSERT_EQ(0, strcmp(cookies, "Cookie"));
ASSERT_EQ(strlen("Cookie") + 1, cookies_len);
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosLock, ListLockersPP) {
- 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);
+TEST_F(LibRadosLockPP, ListLockersPP) {
std::stringstream sstm;
sstm << "client." << cluster.get_instance_id();
std::string me = sstm.str();
ASSERT_EQ(me, it->client);
ASSERT_EQ("Cookie", it->cookie);
}
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosLock, BreakLock) {
+TEST_F(LibRadosLock, BreakLock) {
int exclusive;
char tag[1024];
char clients[1024];
size_t clients_len = 1024;
size_t cookies_len = 1024;
size_t addresses_len = 1024;
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
std::stringstream sstm;
sstm << "client." << rados_get_instance_id(cluster);
std::string me = sstm.str();
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(1, rados_list_lockers(ioctx, "foo", "TestLock", &exclusive, tag, &tag_len, clients, &clients_len, cookies, &cookies_len, addresses, &addresses_len ));
ASSERT_EQ(1, exclusive);
ASSERT_EQ(0, strcmp(cookies, "Cookie"));
ASSERT_EQ(strlen("Cookie") + 1, cookies_len);
ASSERT_EQ(0, rados_break_lock(ioctx, "foo", "TestLock", clients, "Cookie"));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosLock, BreakLockPP) {
+TEST_F(LibRadosLockPP, BreakLockPP) {
int exclusive;
std::string tag;
std::list<librados::locker_t> lockers;
- 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);
std::stringstream sstm;
sstm << "client." << cluster.get_instance_id();
std::string me = sstm.str();
ASSERT_EQ(me, it->client);
ASSERT_EQ("Cookie", it->cookie);
ASSERT_EQ(0, ioctx.break_lock("foo", "TestLock", it->client, "Cookie"));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
#include "common/ceph_argparse.h"
#include "common/common_init.h"
#include "test/librados/test.h"
+#include "test/librados/TestCase.h"
#include <errno.h>
#include <map>
using std::ostringstream;
using std::string;
-TEST(LibRadosMisc, Version) {
+typedef RadosTest LibRadosMisc;
+typedef RadosTestPP LibRadosMiscPP;
+
+TEST(LibRadosMiscVersion, Version) {
int major, minor, extra;
rados_version(&major, &minor, &extra);
}
-TEST(LibRadosMisc, VersionPP) {
+TEST(LibRadosMiscVersion, VersionPP) {
int major, minor, extra;
Rados::version(&major, &minor, &extra);
}
-TEST(LibRadosMisc, ClusterFSID) {
- rados_t cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
-
+TEST_F(LibRadosMisc, ClusterFSID) {
char fsid[37];
ASSERT_EQ(-ERANGE, rados_cluster_fsid(cluster, fsid, sizeof(fsid) - 1));
ASSERT_EQ(sizeof(fsid) - 1,
(size_t)rados_cluster_fsid(cluster, fsid, sizeof(fsid)));
-
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosMisc, WaitOSDMapPP) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
-
+TEST_F(LibRadosMiscPP, WaitOSDMapPP) {
ASSERT_EQ(0, cluster.wait_for_latest_osdmap());
-
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
static std::string read_key_from_tmap(IoCtx& ioctx, const std::string &obj,
return ret;
}
-TEST(LibRadosMisc, TmapUpdatePP) {
- 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);
-
+TEST_F(LibRadosMiscPP, TmapUpdatePP) {
// create tmap
{
__u8 c = CEPH_OSD_TMAP_CREATE;
// key should be removed
ASSERT_EQ(string(""), read_key_from_tmap(ioctx, "foo", "key1"));
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, TmapUpdateMisorderedPP) {
- 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);
-
+TEST_F(LibRadosMiscPP, TmapUpdateMisorderedPP) {
// create tmap
{
__u8 c = CEPH_OSD_TMAP_CREATE;
ASSERT_EQ(0, remove_key_from_tmap(ioctx, "foo", "b"));
ASSERT_EQ(string(""), read_key_from_tmap(ioctx, "foo", "a"));
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, TmapUpdateMisorderedPutPP) {
- 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);
-
+TEST_F(LibRadosMiscPP, TmapUpdateMisorderedPutPP) {
// create unsorted tmap
string h("header");
bufferlist bl;
bufferlist newbl;
ioctx.read("foo", newbl, orig.length(), 0);
ASSERT_EQ(orig.contents_equal(newbl), false);
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, Tmap2OmapPP) {
- 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);
-
+TEST_F(LibRadosMiscPP, Tmap2OmapPP) {
// create tmap
bufferlist hdr;
hdr.append("header");
}
ASSERT_TRUE(same);
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, Exec) {
+TEST_F(LibRadosMisc, Exec) {
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
char buf2[512];
uint64_t all_features;
::decode(all_features, iter);
ASSERT_EQ(all_features, (uint64_t)RBD_FEATURES_ALL);
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosMisc, ExecPP) {
- 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);
+TEST_F(LibRadosMiscPP, ExecPP) {
bufferlist bl;
ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0));
bufferlist bl2, out;
uint64_t all_features;
::decode(all_features, iter);
ASSERT_EQ(all_features, (uint64_t)RBD_FEATURES_ALL);
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, Operate1PP) {
- 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);
-
+TEST_F(LibRadosMiscPP, Operate1PP) {
ObjectWriteOperation o;
{
bufferlist bl;
o3.cmpxattr("key1", CEPH_OSD_CMPXATTR_OP_EQ, bl);
}
ASSERT_LT(ioctx.operate("foo", &o3), 0);
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, Operate2PP) {
- 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);
-
+TEST_F(LibRadosMiscPP, Operate2PP) {
ObjectWriteOperation o;
{
bufferlist bl;
time_t mtime;
ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
ASSERT_EQ(0U, size);
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, BigObjectPP) {
- 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);
-
+TEST_F(LibRadosMiscPP, BigObjectPP) {
bufferlist bl;
bl.append("abcdefg");
ASSERT_EQ((int)bl.length(), ioctx.write("foo", bl, bl.length(), 0));
// this test only works on 64-bit platforms
ASSERT_EQ(-EFBIG, ioctx.write("foo", bl, bl.length(), 500000000000ull));
#endif
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
void set_completion_complete(rados_completion_t cb, void *arg)
*my_aio_complete = true;
}
-TEST(LibRadosMisc, AioOperatePP) {
- 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);
-
+TEST_F(LibRadosMiscPP, AioOperatePP) {
bool my_aio_complete = false;
AioCompletion *my_completion = cluster.aio_create_completion(
(void*)&my_aio_complete, set_completion_complete, NULL);
time_t mtime;
ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
ASSERT_EQ(1024U, size);
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, CloneRangePP) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
+TEST_F(LibRadosMiscPP, CloneRangePP) {
char buf[64];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
bufferlist bl2;
ASSERT_EQ(sizeof(buf), (size_t)ioctx.read("bar", bl2, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(buf, bl2.c_str(), sizeof(buf)));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, CloneRange) {
+TEST_F(LibRadosMisc, CloneRange) {
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "src", buf, sizeof(buf), 0));
rados_ioctx_locator_set_key(ioctx, "src");
memset(buf2, 0, sizeof(buf2));
ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "dst", buf2, sizeof(buf2), 0));
ASSERT_EQ(0, memcmp(buf, buf2, sizeof(buf)));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosMisc, AssertExistsPP) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
-
+TEST_F(LibRadosMiscPP, AssertExistsPP) {
char buf[64];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
ASSERT_EQ(0, ioctx.create("asdffoo", true));
ASSERT_EQ(0, ioctx.operate("asdffoo", &op));
ASSERT_EQ(-EEXIST, ioctx.create("asdffoo", true));
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, BigAttrPP) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
-
+TEST_F(LibRadosMiscPP, BigAttrPP) {
char buf[64];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
ASSERT_EQ((int)bl.length(), ioctx.getxattr("foo", n, got));
ASSERT_TRUE(bl.contents_equal(got));
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosMisc, CopyPP) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
-
+TEST_F(LibRadosMiscPP, CopyPP) {
bufferlist bl, x;
bl.append("hi there");
x.append("bar");
ASSERT_EQ((int)x.length(), ioctx.getxattr("foo.copy2", "myattr", x2));
ASSERT_TRUE(x.contents_equal(x2));
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
int main(int argc, char **argv)
#include "include/rados/librados.h"
#include "include/rados/librados.hpp"
#include "test/librados/test.h"
+#include "test/librados/TestCase.h"
#include <algorithm>
#include <errno.h>
using namespace librados;
-TEST(LibRadosStat, Stat) {
+typedef RadosTest LibRadosStat;
+typedef RadosTestPP LibRadosStatPP;
+
+TEST_F(LibRadosStat, Stat) {
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
uint64_t size;
ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
ASSERT_EQ(sizeof(buf), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosStat, StatPP) {
+TEST_F(LibRadosStatPP, StatPP) {
char buf[128];
- 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);
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
bl.append(buf, sizeof(buf));
ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
ASSERT_EQ(sizeof(buf), size);
ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosStat, StatNS) {
+TEST_F(LibRadosStat, StatNS) {
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
+ rados_ioctx_set_namespace(ioctx, "");
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo2", buf, sizeof(buf), 0));
ASSERT_EQ(sizeof(buf2), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "foo2", &size, &mtime));
-
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosStat, StatPPNS) {
+TEST_F(LibRadosStatPP, StatPPNS) {
char buf[128];
- 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);
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;
bl.append(buf, sizeof(buf));
+ ioctx.set_namespace("");
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl, sizeof(buf), 0));
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo2", bl, sizeof(buf), 0));
ASSERT_EQ(sizeof(buf2), size);
ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
ASSERT_EQ(-ENOENT, ioctx.stat("foo2", &size, &mtime));
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosStat, ClusterStat) {
- rados_t cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
+TEST_F(LibRadosStat, ClusterStat) {
struct rados_cluster_stat_t result;
ASSERT_EQ(0, rados_cluster_stat(cluster, &result));
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosStat, ClusterStatPP) {
- Rados cluster;
+TEST_F(LibRadosStatPP, ClusterStatPP) {
cluster_stat_t cstat;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
ASSERT_EQ(0, cluster.cluster_stat(cstat));
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosStat, PoolStat) {
+TEST_F(LibRadosStat, PoolStat) {
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
char actual_pool_name[80];
unsigned l = rados_ioctx_get_pool_name(ioctx, actual_pool_name, sizeof(actual_pool_name));
ASSERT_EQ(strlen(actual_pool_name), l);
struct rados_pool_stat_t stats;
memset(&stats, 0, sizeof(stats));
ASSERT_EQ(0, rados_ioctx_pool_stat(ioctx, &stats));
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}
-TEST(LibRadosStat, PoolStatPP) {
- 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);
+TEST_F(LibRadosStatPP, PoolStatPP) {
std::string n = ioctx.get_pool_name();
ASSERT_EQ(n, pool_name);
char buf[128];
std::list<std::string> v;
std::map<std::string,stats_map> stats;
ASSERT_EQ(0, cluster.get_pool_stats(v, stats));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
#include "include/rados/librados.hpp"
#include "include/rados/rados_types.h"
#include "test/librados/test.h"
+#include "test/librados/TestCase.h"
#include <errno.h>
#include <semaphore.h>
using namespace librados;
+typedef RadosTest LibRadosWatchNotify;
+typedef RadosTestPP LibRadosWatchNotifyPP;
+
static sem_t sem;
static void watch_notify_test_cb(uint8_t opcode, uint64_t ver, void *arg)
}
};
-TEST(LibRadosWatchNotify, WatchNotifyTest) {
+TEST_F(LibRadosWatchNotify, WatchNotifyTest) {
ASSERT_EQ(0, sem_init(&sem, 0, 0));
char buf[128];
- rados_t cluster;
- rados_ioctx_t ioctx;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool(pool_name, &cluster));
- rados_ioctx_create(cluster, pool_name.c_str(), &ioctx);
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
uint64_t handle;
TestAlarm alarm;
sem_wait(&sem);
rados_unwatch(ioctx, "foo", handle);
- rados_ioctx_destroy(ioctx);
- ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
sem_destroy(&sem);
}
-TEST(LibRadosWatchNotify, WatchNotifyTestPP) {
+TEST_F(LibRadosWatchNotifyPP, WatchNotifyTestPP) {
ASSERT_EQ(0, sem_init(&sem, 0, 0));
- 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 bl1;
TestAlarm alarm;
sem_wait(&sem);
ioctx.unwatch("foo", handle);
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
sem_destroy(&sem);
}
-TEST(LibRadosWatchNotify, WatchNotifyTimeoutTestPP) {
+TEST_F(LibRadosWatchNotifyPP, WatchNotifyTimeoutTestPP) {
ASSERT_EQ(0, sem_init(&sem, 0, 0));
- 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);
ioctx.set_notify_timeout(1);
uint64_t handle;
WatchNotifyTestCtx ctx;
ASSERT_EQ(0, ioctx.watch("foo", 0, &handle, &ctx));
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
sem_destroy(&sem);
}