test/librados: use a test case instead of duplicating code everywhere

These tests don't have any special requirements on their ioctx and
pools, so they can also run much faster by using different namespaces
per test instead of new pools. For the few tests that do depend on
namespace, reset the ioctx to the default namespace.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
This commit is contained in:
Josh Durgin 2014-02-03 00:54:21 -08:00
parent c6d8d0ef26
commit 5497e1cbd3
6 changed files with 104 additions and 591 deletions

View File

@ -1,6 +1,10 @@
// -*- 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.h"
#include "include/rados/librados.hpp" #include "include/rados/librados.hpp"
#include "test/librados/test.h" #include "test/librados/test.h"
#include "test/librados/TestCase.h"
#include <errno.h> #include <errno.h>
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -8,63 +12,41 @@
using namespace librados; using namespace librados;
using std::string; using std::string;
TEST(LibRadosIo, SimpleWrite) { typedef RadosTest LibRadosIo;
typedef RadosTestPP LibRadosIoPP;
TEST_F(LibRadosIo, SimpleWrite) {
char buf[128]; 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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
rados_ioctx_set_namespace(ioctx, "nspace"); rados_ioctx_set_namespace(ioctx, "nspace");
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); 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]; 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)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
bl.append(buf, sizeof(buf)); bl.append(buf, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl, sizeof(buf), 0));
ioctx.set_namespace("nspace"); ioctx.set_namespace("nspace");
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl, sizeof(buf), 0)); 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 buf[128];
char buf2[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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
memset(buf2, 0, sizeof(buf2)); memset(buf2, 0, sizeof(buf2));
ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "foo", buf2, sizeof(buf2), 0)); ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "foo", buf2, sizeof(buf2), 0));
ASSERT_EQ(0, memcmp(buf, buf2, sizeof(buf))); 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 buf[128];
char buf2[128]; char buf2[128];
Rados cluster; 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)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
bl.append(buf, sizeof(buf)); bl.append(buf, sizeof(buf));
@ -72,19 +54,12 @@ TEST(LibRadosIo, RoundTripPP) {
bufferlist cl; bufferlist cl;
ASSERT_EQ((int)sizeof(buf2), ioctx.read("foo", cl, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf2), ioctx.read("foo", cl, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(buf, cl.c_str(), sizeof(buf))); 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 buf[128];
char buf2[64]; char buf2[64];
char buf3[128]; 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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
memset(buf2, 0xdd, sizeof(buf2)); memset(buf2, 0xdd, sizeof(buf2));
@ -93,18 +68,11 @@ TEST(LibRadosIo, OverlappingWriteRoundTrip) {
ASSERT_EQ((int)sizeof(buf3), rados_read(ioctx, "foo", buf3, sizeof(buf3), 0)); 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, buf2, sizeof(buf2)));
ASSERT_EQ(0, memcmp(buf3 + sizeof(buf2), buf, sizeof(buf) - 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 buf[128];
char buf2[64]; 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)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl1; bufferlist bl1;
bl1.append(buf, sizeof(buf)); bl1.append(buf, sizeof(buf));
@ -117,19 +85,12 @@ TEST(LibRadosIo, OverlappingWriteRoundTripPP) {
ASSERT_EQ((int)sizeof(buf), ioctx.read("foo", bl3, sizeof(buf), 0)); 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(), buf2, sizeof(buf2)));
ASSERT_EQ(0, memcmp(bl3.c_str() + sizeof(buf2), buf, sizeof(buf) - 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 buf[128];
char buf2[64]; char buf2[64];
char buf3[128]; 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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
memset(buf2, 0xdd, sizeof(buf2)); memset(buf2, 0xdd, sizeof(buf2));
@ -137,18 +98,11 @@ TEST(LibRadosIo, WriteFullRoundTrip) {
memset(buf3, 0xdd, sizeof(buf3)); memset(buf3, 0xdd, sizeof(buf3));
ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "foo", buf3, sizeof(buf3), 0)); ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "foo", buf3, sizeof(buf3), 0));
ASSERT_EQ(0, memcmp(buf2, buf2, sizeof(buf2))); 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 buf[128];
char buf2[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, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl1; bufferlist bl1;
bl1.append(buf, sizeof(buf)); bl1.append(buf, sizeof(buf));
@ -160,19 +114,12 @@ TEST(LibRadosIo, WriteFullRoundTripPP) {
bufferlist bl3; bufferlist bl3;
ASSERT_EQ((int)sizeof(buf2), ioctx.read("foo", bl3, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf2), ioctx.read("foo", bl3, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(bl3.c_str(), buf2, sizeof(buf2))); 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 buf[64];
char buf2[64]; char buf2[64];
char buf3[sizeof(buf) + sizeof(buf2)]; 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)); memset(buf, 0xde, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf))); ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
memset(buf2, 0xad, sizeof(buf2)); memset(buf2, 0xad, sizeof(buf2));
@ -181,18 +128,11 @@ TEST(LibRadosIo, AppendRoundTrip) {
ASSERT_EQ((int)sizeof(buf3), rados_read(ioctx, "foo", buf3, sizeof(buf3), 0)); 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, buf, sizeof(buf)));
ASSERT_EQ(0, memcmp(buf3 + sizeof(buf), buf2, sizeof(buf2))); 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 buf[64];
char buf2[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)); memset(buf, 0xde, sizeof(buf));
bufferlist bl1; bufferlist bl1;
bl1.append(buf, sizeof(buf)); bl1.append(buf, sizeof(buf));
@ -207,35 +147,21 @@ TEST(LibRadosIo, AppendRoundTripPP) {
const char *bl3_str = bl3.c_str(); const char *bl3_str = bl3.c_str();
ASSERT_EQ(0, memcmp(bl3_str, buf, sizeof(buf))); ASSERT_EQ(0, memcmp(bl3_str, buf, sizeof(buf)));
ASSERT_EQ(0, memcmp(bl3_str + sizeof(buf), buf2, sizeof(buf2))); 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 buf[128];
char buf2[sizeof(buf)]; 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)); memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf))); ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
ASSERT_EQ(0, rados_trunc(ioctx, "foo", sizeof(buf) / 2)); ASSERT_EQ(0, rados_trunc(ioctx, "foo", sizeof(buf) / 2));
memset(buf2, 0, sizeof(buf2)); memset(buf2, 0, sizeof(buf2));
ASSERT_EQ((int)(sizeof(buf)/2), rados_read(ioctx, "foo", buf2, sizeof(buf2), 0)); ASSERT_EQ((int)(sizeof(buf)/2), rados_read(ioctx, "foo", buf2, sizeof(buf2), 0));
ASSERT_EQ(0, memcmp(buf, buf2, sizeof(buf)/2)); 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]; 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)); memset(buf, 0xaa, sizeof(buf));
bufferlist bl; bufferlist bl;
bl.append(buf, sizeof(buf)); bl.append(buf, sizeof(buf));
@ -244,34 +170,20 @@ TEST(LibRadosIo, TruncTestPP) {
bufferlist bl2; bufferlist bl2;
ASSERT_EQ((int)(sizeof(buf)/2), ioctx.read("foo", bl2, sizeof(buf), 0)); ASSERT_EQ((int)(sizeof(buf)/2), ioctx.read("foo", bl2, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(bl2.c_str(), buf, sizeof(buf)/2)); 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 buf[128];
char buf2[sizeof(buf)]; 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)); memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf))); ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
ASSERT_EQ(0, rados_remove(ioctx, "foo")); ASSERT_EQ(0, rados_remove(ioctx, "foo"));
memset(buf2, 0, sizeof(buf2)); memset(buf2, 0, sizeof(buf2));
ASSERT_EQ(-ENOENT, rados_read(ioctx, "foo", buf2, sizeof(buf2), 0)); 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]; 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)); memset(buf, 0xaa, sizeof(buf));
bufferlist bl1; bufferlist bl1;
bl1.append(buf, sizeof(buf)); bl1.append(buf, sizeof(buf));
@ -279,19 +191,12 @@ TEST(LibRadosIo, RemoveTestPP) {
ASSERT_EQ(0, ioctx.remove("foo")); ASSERT_EQ(0, ioctx.remove("foo"));
bufferlist bl2; bufferlist bl2;
ASSERT_EQ(-ENOENT, ioctx.read("foo", bl2, sizeof(buf), 0)); 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 buf[128];
char attr1[] = "attr1"; char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz"; 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)); memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, 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(-ENODATA, rados_getxattr(ioctx, "foo", attr1, buf, sizeof(buf)));
@ -299,19 +204,12 @@ TEST(LibRadosIo, XattrsRoundTrip) {
ASSERT_EQ((int)sizeof(attr1_buf), ASSERT_EQ((int)sizeof(attr1_buf),
rados_getxattr(ioctx, "foo", attr1, buf, sizeof(buf))); rados_getxattr(ioctx, "foo", attr1, buf, sizeof(buf)));
ASSERT_EQ(0, memcmp(attr1_buf, buf, sizeof(attr1_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 buf[128];
char attr1[] = "attr1"; char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz"; 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)); memset(buf, 0xaa, sizeof(buf));
bufferlist bl1; bufferlist bl1;
bl1.append(buf, sizeof(buf)); bl1.append(buf, sizeof(buf));
@ -325,38 +223,24 @@ TEST(LibRadosIo, XattrsRoundTripPP) {
ASSERT_EQ((int)sizeof(attr1_buf), ASSERT_EQ((int)sizeof(attr1_buf),
ioctx.getxattr("foo", attr1, bl4)); ioctx.getxattr("foo", attr1, bl4));
ASSERT_EQ(0, memcmp(bl4.c_str(), attr1_buf, sizeof(attr1_buf))); 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 buf[128];
char attr1[] = "attr1"; char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz"; 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)); memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf))); ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, sizeof(buf)));
ASSERT_EQ(0, ASSERT_EQ(0,
rados_setxattr(ioctx, "foo", attr1, attr1_buf, sizeof(attr1_buf))); rados_setxattr(ioctx, "foo", attr1, attr1_buf, sizeof(attr1_buf)));
ASSERT_EQ(0, rados_rmxattr(ioctx, "foo", attr1)); ASSERT_EQ(0, rados_rmxattr(ioctx, "foo", attr1));
ASSERT_EQ(-ENODATA, rados_getxattr(ioctx, "foo", attr1, buf, sizeof(buf))); 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 buf[128];
char attr1[] = "attr1"; char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz"; 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)); memset(buf, 0xaa, sizeof(buf));
bufferlist bl1; bufferlist bl1;
bl1.append(buf, sizeof(buf)); bl1.append(buf, sizeof(buf));
@ -367,11 +251,9 @@ TEST(LibRadosIo, RmXattrPP) {
ASSERT_EQ(0, ioctx.rmxattr("foo", attr1)); ASSERT_EQ(0, ioctx.rmxattr("foo", attr1));
bufferlist bl3; bufferlist bl3;
ASSERT_EQ(-ENODATA, ioctx.getxattr("foo", attr1, 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 buf[128];
char attr1[] = "attr1"; char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz"; char attr1_buf[] = "foo bar baz";
@ -380,11 +262,6 @@ TEST(LibRadosIo, XattrIter) {
for (size_t j = 0; j < sizeof(attr2_buf); ++j) { for (size_t j = 0; j < sizeof(attr2_buf); ++j) {
attr2_buf[j] = j % 0xff; 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)); memset(buf, 0xaa, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_append(ioctx, "foo", buf, 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_setxattr(ioctx, "foo", attr1, attr1_buf, sizeof(attr1_buf)));
@ -414,11 +291,9 @@ TEST(LibRadosIo, XattrIter) {
} }
} }
rados_getxattrs_end(iter); 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 buf[128];
char attr1[] = "attr1"; char attr1[] = "attr1";
char attr1_buf[] = "foo bar baz"; char attr1_buf[] = "foo bar baz";
@ -427,11 +302,6 @@ TEST(LibRadosIo, XattrListPP) {
for (size_t j = 0; j < sizeof(attr2_buf); ++j) { for (size_t j = 0; j < sizeof(attr2_buf); ++j) {
attr2_buf[j] = j % 0xff; 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)); memset(buf, 0xaa, sizeof(buf));
bufferlist bl1; bufferlist bl1;
bl1.append(buf, sizeof(buf)); bl1.append(buf, sizeof(buf));
@ -456,6 +326,4 @@ TEST(LibRadosIo, XattrListPP) {
ASSERT_EQ(0, 1); ASSERT_EQ(0, 1);
} }
} }
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }

View File

@ -3,6 +3,7 @@
#include "include/rados/librados.hpp" #include "include/rados/librados.hpp"
#include "include/stringify.h" #include "include/stringify.h"
#include "test/librados/test.h" #include "test/librados/test.h"
#include "test/librados/TestCase.h"
#include "include/types.h" #include "include/types.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -11,13 +12,11 @@
using namespace librados; using namespace librados;
TEST(LibRadosList, ListObjects) { typedef RadosTest LibRadosList;
typedef RadosTestPP LibRadosListPP;
TEST_F(LibRadosList, ListObjects) {
char buf[128]; 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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
rados_list_ctx_t ctx; rados_list_ctx_t ctx;
@ -30,16 +29,9 @@ TEST(LibRadosList, ListObjects) {
} }
ASSERT_TRUE(foundit); ASSERT_TRUE(foundit);
rados_objects_list_close(ctx); rados_objects_list_close(ctx);
rados_ioctx_destroy(ioctx);
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
} }
TEST(LibRadosList, ListObjectsPP) { TEST_F(LibRadosListPP, 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);
char buf[128]; char buf[128];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl1; bufferlist bl1;
@ -53,8 +45,6 @@ TEST(LibRadosList, ListObjectsPP) {
++iter; ++iter;
} }
ASSERT_TRUE(foundit); 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) static void check_list(std::set<std::string>& myset, rados_list_ctx_t& ctx)
@ -74,15 +64,11 @@ static void check_list(std::set<std::string>& myset, rados_list_ctx_t& ctx)
ASSERT_TRUE(myset.empty()); ASSERT_TRUE(myset.empty());
} }
TEST(LibRadosList, ListObjectsNS) { TEST_F(LibRadosList, ListObjectsNS) {
char buf[128]; 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)); memset(buf, 0xcc, sizeof(buf));
// Create :foo1, :foo2, :foo3, n1:foo1, ns1:foo4, ns1:foo5, ns2:foo6, n2:foo7 // 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)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo1", buf, sizeof(buf), 0));
rados_ioctx_set_namespace(ioctx, "ns1"); rados_ioctx_set_namespace(ioctx, "ns1");
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo1", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo1", buf, sizeof(buf), 0));
@ -124,9 +110,6 @@ TEST(LibRadosList, ListObjectsNS) {
ASSERT_EQ(0, rados_objects_list_open(ioctx, &ctx)); ASSERT_EQ(0, rados_objects_list_open(ioctx, &ctx));
check_list(ns2, ctx); check_list(ns2, ctx);
rados_objects_list_close(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) static void check_listpp(std::set<std::string>& myset, IoCtx& ioctx)
@ -147,17 +130,13 @@ static void check_listpp(std::set<std::string>& myset, IoCtx& ioctx)
ASSERT_TRUE(myset.empty()); ASSERT_TRUE(myset.empty());
} }
TEST(LibRadosList, ListObjectsPPNS) { TEST_F(LibRadosListPP, 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);
char buf[128]; char buf[128];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl1; bufferlist bl1;
bl1.append(buf, sizeof(buf)); bl1.append(buf, sizeof(buf));
// Create :foo1, :foo2, :foo3, n1:foo1, ns1:foo4, ns1:foo5, ns2:foo6, n2:foo7 // 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)); ASSERT_EQ((int)sizeof(buf), ioctx.write("foo1", bl1, sizeof(buf), 0));
ioctx.set_namespace("ns1"); ioctx.set_namespace("ns1");
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo1", bl1, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), ioctx.write("foo1", bl1, sizeof(buf), 0));
@ -189,18 +168,9 @@ TEST(LibRadosList, ListObjectsPPNS) {
ioctx.set_namespace("ns2"); ioctx.set_namespace("ns2");
check_listpp(ns2, ioctx); check_listpp(ns2, ioctx);
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosList, ListObjectsManyPP) { TEST_F(LibRadosListPP, 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);
char buf[128]; char buf[128];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
@ -224,20 +194,9 @@ TEST(LibRadosList, ListObjectsManyPP) {
// make sure they are 0..n // make sure they are 0..n
for (unsigned i = 0; i < saw_pg.size(); ++i) for (unsigned i = 0; i < saw_pg.size(); ++i)
ASSERT_TRUE(saw_pg.count(i)); ASSERT_TRUE(saw_pg.count(i));
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST_F(LibRadosList, ListObjectsStart) {
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);
char buf[128]; char buf[128];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
@ -268,17 +227,9 @@ TEST(LibRadosList, ListObjectsStart) {
++p; ++p;
} }
rados_objects_list_close(ctx); rados_objects_list_close(ctx);
rados_ioctx_destroy(ioctx);
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
} }
TEST(LibRadosList, ListObjectsStartPP) { TEST_F(LibRadosListPP, 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);
char buf[128]; char buf[128];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
@ -304,7 +255,4 @@ TEST(LibRadosList, ListObjectsStartPP) {
ASSERT_TRUE(p->second.count(it->first)); ASSERT_TRUE(p->second.count(it->first));
++p; ++p;
} }
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }

View File

@ -1,6 +1,7 @@
#include "include/rados/librados.h" #include "include/rados/librados.h"
#include "include/rados/librados.hpp" #include "include/rados/librados.hpp"
#include "test/librados/test.h" #include "test/librados/test.h"
#include "test/librados/TestCase.h"
#include "cls/lock/cls_lock_client.h" #include "cls/lock/cls_lock_client.h"
#include <algorithm> #include <algorithm>
@ -10,171 +11,90 @@
using namespace librados; using namespace librados;
TEST(LibRadosLock, LockExclusive) { typedef RadosTest LibRadosLock;
rados_t cluster; typedef RadosTestPP LibRadosLockPP;
rados_ioctx_t ioctx;
std::string pool_name = get_temp_pool_name(); TEST_F(LibRadosLock, LockExclusive) {
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", "", NULL, 0)); 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(-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) { TEST_F(LibRadosLockPP, 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);
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0)); ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(-EEXIST, 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) { TEST_F(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);
ASSERT_EQ(0, rados_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", NULL, 0)); 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)); 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) { TEST_F(LibRadosLockPP, 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);
ASSERT_EQ(0, ioctx.lock_shared("foo", "TestLock", "Cookie", "Tag", "", NULL, 0)); ASSERT_EQ(0, ioctx.lock_shared("foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
ASSERT_EQ(-EEXIST, 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; struct timeval tv;
tv.tv_sec = 1; tv.tv_sec = 1;
tv.tv_usec = 0; 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)); ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", &tv, 0));
sleep(1); sleep(1);
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0)); 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; struct timeval tv;
tv.tv_sec = 1; tv.tv_sec = 1;
tv.tv_usec = 0; 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)); ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", &tv, 0));
sleep(1); sleep(1);
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0)); 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; struct timeval tv;
tv.tv_sec = 1; tv.tv_sec = 1;
tv.tv_usec = 0; 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)); ASSERT_EQ(0, rados_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", &tv, 0));
sleep(1); sleep(1);
ASSERT_EQ(0, rados_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", NULL, 0)); 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; struct timeval tv;
tv.tv_sec = 1; tv.tv_sec = 1;
tv.tv_usec = 0; 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)); ASSERT_EQ(0, ioctx.lock_shared("foo", "TestLock", "Cookie", "Tag", "", &tv, 0));
sleep(1); sleep(1);
ASSERT_EQ(0, ioctx.lock_shared("foo", "TestLock", "Cookie", "Tag", "", NULL, 0)); 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) { TEST_F(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);
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0)); 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(-EEXIST, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, LOCK_FLAG_RENEW)); 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) { TEST_F(LibRadosLockPP, 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);
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0)); ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(-EEXIST, 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)); 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) { TEST_F(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);
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0)); 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_unlock(ioctx, "foo", "TestLock", "Cookie"));
ASSERT_EQ(0, rados_lock_exclusive(ioctx, "foo", "TestLock", "Cookie", "", NULL, 0)); 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) { TEST_F(LibRadosLockPP, 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);
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0)); ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0));
ASSERT_EQ(0, ioctx.unlock("foo", "TestLock", "Cookie")); ASSERT_EQ(0, ioctx.unlock("foo", "TestLock", "Cookie"));
ASSERT_EQ(0, ioctx.lock_exclusive("foo", "TestLock", "Cookie", "", NULL, 0)); 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; int exclusive;
char tag[1024]; char tag[1024];
char clients[1024]; char clients[1024];
@ -184,14 +104,9 @@ TEST(LibRadosLock, ListLockers) {
size_t clients_len = 1024; size_t clients_len = 1024;
size_t cookies_len = 1024; size_t cookies_len = 1024;
size_t addresses_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; std::stringstream sstm;
sstm << "client." << rados_get_instance_id(cluster); sstm << "client." << rados_get_instance_id(cluster);
std::string me = sstm.str(); 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_lock_shared(ioctx, "foo", "TestLock", "Cookie", "Tag", "", NULL, 0));
ASSERT_EQ(0, rados_unlock(ioctx, "foo", "TestLock", "Cookie")); 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(0, rados_list_lockers(ioctx, "foo", "TestLock", &exclusive, tag, &tag_len, clients, &clients_len, cookies, &cookies_len, addresses, &addresses_len ));
@ -209,16 +124,9 @@ TEST(LibRadosLock, ListLockers) {
ASSERT_EQ(me.size() + 1, clients_len); ASSERT_EQ(me.size() + 1, clients_len);
ASSERT_EQ(0, strcmp(cookies, "Cookie")); ASSERT_EQ(0, strcmp(cookies, "Cookie"));
ASSERT_EQ(strlen("Cookie") + 1, cookies_len); ASSERT_EQ(strlen("Cookie") + 1, cookies_len);
rados_ioctx_destroy(ioctx);
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
} }
TEST(LibRadosLock, ListLockersPP) { TEST_F(LibRadosLockPP, 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);
std::stringstream sstm; std::stringstream sstm;
sstm << "client." << cluster.get_instance_id(); sstm << "client." << cluster.get_instance_id();
std::string me = sstm.str(); std::string me = sstm.str();
@ -241,11 +149,9 @@ TEST(LibRadosLock, ListLockersPP) {
ASSERT_EQ(me, it->client); ASSERT_EQ(me, it->client);
ASSERT_EQ("Cookie", it->cookie); 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; int exclusive;
char tag[1024]; char tag[1024];
char clients[1024]; char clients[1024];
@ -255,14 +161,9 @@ TEST(LibRadosLock, BreakLock) {
size_t clients_len = 1024; size_t clients_len = 1024;
size_t cookies_len = 1024; size_t cookies_len = 1024;
size_t addresses_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; std::stringstream sstm;
sstm << "client." << rados_get_instance_id(cluster); sstm << "client." << rados_get_instance_id(cluster);
std::string me = sstm.str(); 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(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, 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(1, exclusive);
@ -273,19 +174,12 @@ TEST(LibRadosLock, BreakLock) {
ASSERT_EQ(0, strcmp(cookies, "Cookie")); ASSERT_EQ(0, strcmp(cookies, "Cookie"));
ASSERT_EQ(strlen("Cookie") + 1, cookies_len); ASSERT_EQ(strlen("Cookie") + 1, cookies_len);
ASSERT_EQ(0, rados_break_lock(ioctx, "foo", "TestLock", clients, "Cookie")); 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; int exclusive;
std::string tag; std::string tag;
std::list<librados::locker_t> lockers; 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; std::stringstream sstm;
sstm << "client." << cluster.get_instance_id(); sstm << "client." << cluster.get_instance_id();
std::string me = sstm.str(); std::string me = sstm.str();
@ -296,6 +190,4 @@ TEST(LibRadosLock, BreakLockPP) {
ASSERT_EQ(me, it->client); ASSERT_EQ(me, it->client);
ASSERT_EQ("Cookie", it->cookie); ASSERT_EQ("Cookie", it->cookie);
ASSERT_EQ(0, ioctx.break_lock("foo", "TestLock", it->client, "Cookie")); ASSERT_EQ(0, ioctx.break_lock("foo", "TestLock", it->client, "Cookie"));
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }

View File

@ -13,6 +13,7 @@
#include "common/ceph_argparse.h" #include "common/ceph_argparse.h"
#include "common/common_init.h" #include "common/common_init.h"
#include "test/librados/test.h" #include "test/librados/test.h"
#include "test/librados/TestCase.h"
#include <errno.h> #include <errno.h>
#include <map> #include <map>
@ -25,37 +26,28 @@ using std::map;
using std::ostringstream; using std::ostringstream;
using std::string; using std::string;
TEST(LibRadosMisc, Version) { typedef RadosTest LibRadosMisc;
typedef RadosTestPP LibRadosMiscPP;
TEST(LibRadosMiscVersion, Version) {
int major, minor, extra; int major, minor, extra;
rados_version(&major, &minor, &extra); rados_version(&major, &minor, &extra);
} }
TEST(LibRadosMisc, VersionPP) { TEST(LibRadosMiscVersion, VersionPP) {
int major, minor, extra; int major, minor, extra;
Rados::version(&major, &minor, &extra); Rados::version(&major, &minor, &extra);
} }
TEST(LibRadosMisc, ClusterFSID) { TEST_F(LibRadosMisc, ClusterFSID) {
rados_t cluster;
std::string pool_name = get_temp_pool_name();
ASSERT_EQ("", create_one_pool(pool_name, &cluster));
char fsid[37]; char fsid[37];
ASSERT_EQ(-ERANGE, rados_cluster_fsid(cluster, fsid, sizeof(fsid) - 1)); ASSERT_EQ(-ERANGE, rados_cluster_fsid(cluster, fsid, sizeof(fsid) - 1));
ASSERT_EQ(sizeof(fsid) - 1, ASSERT_EQ(sizeof(fsid) - 1,
(size_t)rados_cluster_fsid(cluster, fsid, sizeof(fsid))); (size_t)rados_cluster_fsid(cluster, fsid, sizeof(fsid)));
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
} }
TEST(LibRadosMisc, WaitOSDMapPP) { TEST_F(LibRadosMiscPP, WaitOSDMapPP) {
Rados cluster;
std::string pool_name = get_temp_pool_name();
ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
ASSERT_EQ(0, cluster.wait_for_latest_osdmap()); 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, static std::string read_key_from_tmap(IoCtx& ioctx, const std::string &obj,
@ -119,13 +111,7 @@ static int remove_key_from_tmap(IoCtx &ioctx, const std::string &obj,
return ret; return ret;
} }
TEST(LibRadosMisc, TmapUpdatePP) { TEST_F(LibRadosMiscPP, 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);
// create tmap // create tmap
{ {
__u8 c = CEPH_OSD_TMAP_CREATE; __u8 c = CEPH_OSD_TMAP_CREATE;
@ -152,18 +138,9 @@ TEST(LibRadosMisc, TmapUpdatePP) {
// key should be removed // key should be removed
ASSERT_EQ(string(""), read_key_from_tmap(ioctx, "foo", "key1")); 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) { TEST_F(LibRadosMiscPP, 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);
// create tmap // create tmap
{ {
__u8 c = CEPH_OSD_TMAP_CREATE; __u8 c = CEPH_OSD_TMAP_CREATE;
@ -229,18 +206,9 @@ TEST(LibRadosMisc, TmapUpdateMisorderedPP) {
ASSERT_EQ(0, remove_key_from_tmap(ioctx, "foo", "b")); ASSERT_EQ(0, remove_key_from_tmap(ioctx, "foo", "b"));
ASSERT_EQ(string(""), read_key_from_tmap(ioctx, "foo", "a")); 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) { TEST_F(LibRadosMiscPP, 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);
// create unsorted tmap // create unsorted tmap
string h("header"); string h("header");
bufferlist bl; bufferlist bl;
@ -260,18 +228,9 @@ TEST(LibRadosMisc, TmapUpdateMisorderedPutPP) {
bufferlist newbl; bufferlist newbl;
ioctx.read("foo", newbl, orig.length(), 0); ioctx.read("foo", newbl, orig.length(), 0);
ASSERT_EQ(orig.contents_equal(newbl), false); ASSERT_EQ(orig.contents_equal(newbl), false);
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosMisc, Tmap2OmapPP) { TEST_F(LibRadosMiscPP, 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);
// create tmap // create tmap
bufferlist hdr; bufferlist hdr;
hdr.append("header"); hdr.append("header");
@ -325,18 +284,10 @@ TEST(LibRadosMisc, Tmap2OmapPP) {
} }
ASSERT_TRUE(same); 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]; 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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
char buf2[512]; char buf2[512];
@ -349,16 +300,9 @@ TEST(LibRadosMisc, Exec) {
uint64_t all_features; uint64_t all_features;
::decode(all_features, iter); ::decode(all_features, iter);
ASSERT_EQ(all_features, (uint64_t)RBD_FEATURES_ALL); 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) { TEST_F(LibRadosMiscPP, 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);
bufferlist bl; bufferlist bl;
ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0)); ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0));
bufferlist bl2, out; bufferlist bl2, out;
@ -368,17 +312,9 @@ TEST(LibRadosMisc, ExecPP) {
uint64_t all_features; uint64_t all_features;
::decode(all_features, iter); ::decode(all_features, iter);
ASSERT_EQ(all_features, (uint64_t)RBD_FEATURES_ALL); ASSERT_EQ(all_features, (uint64_t)RBD_FEATURES_ALL);
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosMisc, Operate1PP) { TEST_F(LibRadosMiscPP, 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);
ObjectWriteOperation o; ObjectWriteOperation o;
{ {
bufferlist bl; bufferlist bl;
@ -416,17 +352,9 @@ TEST(LibRadosMisc, Operate1PP) {
o3.cmpxattr("key1", CEPH_OSD_CMPXATTR_OP_EQ, bl); o3.cmpxattr("key1", CEPH_OSD_CMPXATTR_OP_EQ, bl);
} }
ASSERT_LT(ioctx.operate("foo", &o3), 0); ASSERT_LT(ioctx.operate("foo", &o3), 0);
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosMisc, Operate2PP) { TEST_F(LibRadosMiscPP, 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);
ObjectWriteOperation o; ObjectWriteOperation o;
{ {
bufferlist bl; bufferlist bl;
@ -445,17 +373,9 @@ TEST(LibRadosMisc, Operate2PP) {
time_t mtime; time_t mtime;
ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime)); ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
ASSERT_EQ(0U, size); ASSERT_EQ(0U, size);
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosMisc, BigObjectPP) { TEST_F(LibRadosMiscPP, 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);
bufferlist bl; bufferlist bl;
bl.append("abcdefg"); bl.append("abcdefg");
ASSERT_EQ((int)bl.length(), ioctx.write("foo", bl, bl.length(), 0)); ASSERT_EQ((int)bl.length(), ioctx.write("foo", bl, bl.length(), 0));
@ -485,9 +405,6 @@ TEST(LibRadosMisc, BigObjectPP) {
// this test only works on 64-bit platforms // this test only works on 64-bit platforms
ASSERT_EQ(-EFBIG, ioctx.write("foo", bl, bl.length(), 500000000000ull)); ASSERT_EQ(-EFBIG, ioctx.write("foo", bl, bl.length(), 500000000000ull));
#endif #endif
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
void set_completion_complete(rados_completion_t cb, void *arg) void set_completion_complete(rados_completion_t cb, void *arg)
@ -496,13 +413,7 @@ void set_completion_complete(rados_completion_t cb, void *arg)
*my_aio_complete = true; *my_aio_complete = true;
} }
TEST(LibRadosMisc, AioOperatePP) { TEST_F(LibRadosMiscPP, 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);
bool my_aio_complete = false; bool my_aio_complete = false;
AioCompletion *my_completion = cluster.aio_create_completion( AioCompletion *my_completion = cluster.aio_create_completion(
(void*)&my_aio_complete, set_completion_complete, NULL); (void*)&my_aio_complete, set_completion_complete, NULL);
@ -533,16 +444,9 @@ TEST(LibRadosMisc, AioOperatePP) {
time_t mtime; time_t mtime;
ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime)); ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
ASSERT_EQ(1024U, size); ASSERT_EQ(1024U, size);
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosMisc, CloneRangePP) { TEST_F(LibRadosMiscPP, 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));
char buf[64]; char buf[64];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
@ -553,17 +457,10 @@ TEST(LibRadosMisc, CloneRangePP) {
bufferlist bl2; bufferlist bl2;
ASSERT_EQ(sizeof(buf), (size_t)ioctx.read("bar", bl2, sizeof(buf), 0)); ASSERT_EQ(sizeof(buf), (size_t)ioctx.read("bar", bl2, sizeof(buf), 0));
ASSERT_EQ(0, memcmp(buf, bl2.c_str(), sizeof(buf))); 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]; 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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "src", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "src", buf, sizeof(buf), 0));
rados_ioctx_locator_set_key(ioctx, "src"); rados_ioctx_locator_set_key(ioctx, "src");
@ -572,17 +469,9 @@ TEST(LibRadosMisc, CloneRange) {
memset(buf2, 0, sizeof(buf2)); memset(buf2, 0, sizeof(buf2));
ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "dst", buf2, sizeof(buf2), 0)); ASSERT_EQ((int)sizeof(buf2), rados_read(ioctx, "dst", buf2, sizeof(buf2), 0));
ASSERT_EQ(0, memcmp(buf, buf2, sizeof(buf))); ASSERT_EQ(0, memcmp(buf, buf2, sizeof(buf)));
rados_ioctx_destroy(ioctx);
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
} }
TEST(LibRadosMisc, AssertExistsPP) { TEST_F(LibRadosMiscPP, 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));
char buf[64]; char buf[64];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
@ -595,18 +484,9 @@ TEST(LibRadosMisc, AssertExistsPP) {
ASSERT_EQ(0, ioctx.create("asdffoo", true)); ASSERT_EQ(0, ioctx.create("asdffoo", true));
ASSERT_EQ(0, ioctx.operate("asdffoo", &op)); ASSERT_EQ(0, ioctx.operate("asdffoo", &op));
ASSERT_EQ(-EEXIST, ioctx.create("asdffoo", true)); ASSERT_EQ(-EEXIST, ioctx.create("asdffoo", true));
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosMisc, BigAttrPP) { TEST_F(LibRadosMiscPP, 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));
char buf[64]; char buf[64];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
@ -641,18 +521,9 @@ TEST(LibRadosMisc, BigAttrPP) {
ASSERT_EQ((int)bl.length(), ioctx.getxattr("foo", n, got)); ASSERT_EQ((int)bl.length(), ioctx.getxattr("foo", n, got));
ASSERT_TRUE(bl.contents_equal(got)); ASSERT_TRUE(bl.contents_equal(got));
} }
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosMisc, CopyPP) { TEST_F(LibRadosMiscPP, 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));
bufferlist bl, x; bufferlist bl, x;
bl.append("hi there"); bl.append("hi there");
x.append("bar"); x.append("bar");
@ -733,9 +604,6 @@ TEST(LibRadosMisc, CopyPP) {
ASSERT_EQ((int)x.length(), ioctx.getxattr("foo.copy2", "myattr", x2)); ASSERT_EQ((int)x.length(), ioctx.getxattr("foo.copy2", "myattr", x2));
ASSERT_TRUE(x.contents_equal(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) int main(int argc, char **argv)

View File

@ -1,6 +1,7 @@
#include "include/rados/librados.h" #include "include/rados/librados.h"
#include "include/rados/librados.hpp" #include "include/rados/librados.hpp"
#include "test/librados/test.h" #include "test/librados/test.h"
#include "test/librados/TestCase.h"
#include <algorithm> #include <algorithm>
#include <errno.h> #include <errno.h>
@ -8,13 +9,11 @@
using namespace librados; using namespace librados;
TEST(LibRadosStat, Stat) { typedef RadosTest LibRadosStat;
typedef RadosTestPP LibRadosStatPP;
TEST_F(LibRadosStat, Stat) {
char buf[128]; 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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
uint64_t size; uint64_t size;
@ -22,17 +21,10 @@ TEST(LibRadosStat, Stat) {
ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime)); ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
ASSERT_EQ(sizeof(buf), size); ASSERT_EQ(sizeof(buf), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime)); 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]; 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)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
bl.append(buf, sizeof(buf)); bl.append(buf, sizeof(buf));
@ -42,18 +34,12 @@ TEST(LibRadosStat, StatPP) {
ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime)); ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
ASSERT_EQ(sizeof(buf), size); ASSERT_EQ(sizeof(buf), size);
ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime)); 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]; 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)); 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, "foo", buf, sizeof(buf), 0));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo2", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo2", buf, sizeof(buf), 0));
@ -74,21 +60,14 @@ TEST(LibRadosStat, StatNS) {
ASSERT_EQ(sizeof(buf2), size); ASSERT_EQ(sizeof(buf2), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime)); ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "foo2", &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]; 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)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl; bufferlist bl;
bl.append(buf, sizeof(buf)); 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("foo", bl, sizeof(buf), 0));
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo2", bl, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), ioctx.write("foo2", bl, sizeof(buf), 0));
@ -111,36 +90,20 @@ TEST(LibRadosStat, StatPPNS) {
ASSERT_EQ(sizeof(buf2), size); ASSERT_EQ(sizeof(buf2), size);
ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime)); ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
ASSERT_EQ(-ENOENT, ioctx.stat("foo2", &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) { TEST_F(LibRadosStat, ClusterStat) {
rados_t cluster;
std::string pool_name = get_temp_pool_name();
ASSERT_EQ("", create_one_pool(pool_name, &cluster));
struct rados_cluster_stat_t result; struct rados_cluster_stat_t result;
ASSERT_EQ(0, rados_cluster_stat(cluster, &result)); ASSERT_EQ(0, rados_cluster_stat(cluster, &result));
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
} }
TEST(LibRadosStat, ClusterStatPP) { TEST_F(LibRadosStatPP, ClusterStatPP) {
Rados cluster;
cluster_stat_t cstat; 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, cluster.cluster_stat(cstat));
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }
TEST(LibRadosStat, PoolStat) { TEST_F(LibRadosStat, PoolStat) {
char buf[128]; 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]; char actual_pool_name[80];
unsigned l = rados_ioctx_get_pool_name(ioctx, actual_pool_name, sizeof(actual_pool_name)); unsigned l = rados_ioctx_get_pool_name(ioctx, actual_pool_name, sizeof(actual_pool_name));
ASSERT_EQ(strlen(actual_pool_name), l); ASSERT_EQ(strlen(actual_pool_name), l);
@ -150,16 +113,9 @@ TEST(LibRadosStat, PoolStat) {
struct rados_pool_stat_t stats; struct rados_pool_stat_t stats;
memset(&stats, 0, sizeof(stats)); memset(&stats, 0, sizeof(stats));
ASSERT_EQ(0, rados_ioctx_pool_stat(ioctx, &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) { TEST_F(LibRadosStatPP, 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);
std::string n = ioctx.get_pool_name(); std::string n = ioctx.get_pool_name();
ASSERT_EQ(n, pool_name); ASSERT_EQ(n, pool_name);
char buf[128]; char buf[128];
@ -170,6 +126,4 @@ TEST(LibRadosStat, PoolStatPP) {
std::list<std::string> v; std::list<std::string> v;
std::map<std::string,stats_map> stats; std::map<std::string,stats_map> stats;
ASSERT_EQ(0, cluster.get_pool_stats(v, stats)); ASSERT_EQ(0, cluster.get_pool_stats(v, stats));
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
} }

View File

@ -2,6 +2,7 @@
#include "include/rados/librados.hpp" #include "include/rados/librados.hpp"
#include "include/rados/rados_types.h" #include "include/rados/rados_types.h"
#include "test/librados/test.h" #include "test/librados/test.h"
#include "test/librados/TestCase.h"
#include <errno.h> #include <errno.h>
#include <semaphore.h> #include <semaphore.h>
@ -9,6 +10,9 @@
using namespace librados; using namespace librados;
typedef RadosTest LibRadosWatchNotify;
typedef RadosTestPP LibRadosWatchNotifyPP;
static sem_t sem; static sem_t sem;
static void watch_notify_test_cb(uint8_t opcode, uint64_t ver, void *arg) static void watch_notify_test_cb(uint8_t opcode, uint64_t ver, void *arg)
@ -25,14 +29,9 @@ public:
} }
}; };
TEST(LibRadosWatchNotify, WatchNotifyTest) { TEST_F(LibRadosWatchNotify, WatchNotifyTest) {
ASSERT_EQ(0, sem_init(&sem, 0, 0)); ASSERT_EQ(0, sem_init(&sem, 0, 0));
char buf[128]; 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)); memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0));
uint64_t handle; uint64_t handle;
@ -42,18 +41,11 @@ TEST(LibRadosWatchNotify, WatchNotifyTest) {
TestAlarm alarm; TestAlarm alarm;
sem_wait(&sem); sem_wait(&sem);
rados_unwatch(ioctx, "foo", handle); rados_unwatch(ioctx, "foo", handle);
rados_ioctx_destroy(ioctx);
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
sem_destroy(&sem); sem_destroy(&sem);
} }
TEST(LibRadosWatchNotify, WatchNotifyTestPP) { TEST_F(LibRadosWatchNotifyPP, WatchNotifyTestPP) {
ASSERT_EQ(0, sem_init(&sem, 0, 0)); 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]; char buf[128];
memset(buf, 0xcc, sizeof(buf)); memset(buf, 0xcc, sizeof(buf));
bufferlist bl1; bufferlist bl1;
@ -70,23 +62,14 @@ TEST(LibRadosWatchNotify, WatchNotifyTestPP) {
TestAlarm alarm; TestAlarm alarm;
sem_wait(&sem); sem_wait(&sem);
ioctx.unwatch("foo", handle); ioctx.unwatch("foo", handle);
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
sem_destroy(&sem); sem_destroy(&sem);
} }
TEST(LibRadosWatchNotify, WatchNotifyTimeoutTestPP) { TEST_F(LibRadosWatchNotifyPP, WatchNotifyTimeoutTestPP) {
ASSERT_EQ(0, sem_init(&sem, 0, 0)); 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); ioctx.set_notify_timeout(1);
uint64_t handle; uint64_t handle;
WatchNotifyTestCtx ctx; WatchNotifyTestCtx ctx;
ASSERT_EQ(0, ioctx.watch("foo", 0, &handle, &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); sem_destroy(&sem);
} }