Skip to content

Commit

Permalink
d4n/test: Update unit tests to use one connection across D4N structures
Browse files Browse the repository at this point in the history
Signed-off-by: Samarah <[email protected]>
  • Loading branch information
Samarah committed Jan 16, 2024
1 parent c132faf commit ab1a292
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
37 changes: 14 additions & 23 deletions src/test/rgw/test_d4n_directory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class Environment : public ::testing::Environment {
class ObjectDirectoryFixture: public ::testing::Test {
protected:
virtual void SetUp() {
dir = new rgw::d4n::ObjectDirectory{io};
conn = std::make_shared<connection>(boost::asio::make_strand(io));
dir = new rgw::d4n::ObjectDirectory{conn};
obj = new rgw::d4n::CacheObj{
.objName = "testName",
.bucketName = "testBucket",
Expand All @@ -58,13 +59,11 @@ class ObjectDirectoryFixture: public ::testing::Test {
.hostsList = { env->redisHost }
};

conn = new connection{boost::asio::make_strand(io)};

ASSERT_NE(obj, nullptr);
ASSERT_NE(dir, nullptr);
ASSERT_NE(conn, nullptr);

dir->init(env->cct, env->dpp);
dir->init(env->cct);

/* Run fixture's connection */
config cfg;
Expand All @@ -75,7 +74,9 @@ class ObjectDirectoryFixture: public ::testing::Test {
}

virtual void TearDown() {
delete conn;
// call cancel() on the connection's executor
boost::asio::dispatch(conn->get_executor(), [c = conn] { c->cancel(); });

delete obj;
delete dir;
}
Expand All @@ -84,7 +85,7 @@ class ObjectDirectoryFixture: public ::testing::Test {
rgw::d4n::ObjectDirectory* dir;

net::io_context io;
connection* conn;
std::shared_ptr<connection> conn;

std::vector<std::string> vals{"testName", "testBucket", "", "0", env->redisHost};
std::vector<std::string> fields{"objName", "bucketName", "creationTime", "dirty", "objHosts"};
Expand All @@ -93,7 +94,8 @@ class ObjectDirectoryFixture: public ::testing::Test {
class BlockDirectoryFixture: public ::testing::Test {
protected:
virtual void SetUp() {
dir = new rgw::d4n::BlockDirectory{io};
conn = std::make_shared<connection>(boost::asio::make_strand(io));
dir = new rgw::d4n::BlockDirectory{conn};
block = new rgw::d4n::CacheBlock{
.cacheObj = {
.objName = "testName",
Expand All @@ -108,13 +110,11 @@ class BlockDirectoryFixture: public ::testing::Test {
.hostsList = { env->redisHost }
};

conn = new connection{boost::asio::make_strand(io)};

ASSERT_NE(block, nullptr);
ASSERT_NE(dir, nullptr);
ASSERT_NE(conn, nullptr);

dir->init(env->cct, env->dpp);
dir->init(env->cct);

/* Run fixture's connection */
config cfg;
Expand All @@ -125,7 +125,9 @@ class BlockDirectoryFixture: public ::testing::Test {
}

virtual void TearDown() {
delete conn;
// call cancel() on the connection's executor
boost::asio::dispatch(conn->get_executor(), [c = conn] { c->cancel(); });

delete block;
delete dir;
}
Expand All @@ -134,7 +136,7 @@ class BlockDirectoryFixture: public ::testing::Test {
rgw::d4n::BlockDirectory* dir;

net::io_context io;
connection* conn;
std::shared_ptr<connection> conn;

std::vector<std::string> vals{"0", "", "0", "0", env->redisHost,
"testName", "testBucket", "", "0", env->redisHost};
Expand All @@ -146,7 +148,6 @@ TEST_F(ObjectDirectoryFixture, SetYield)
{
spawn::spawn(io, [this] (spawn::yield_context yield) {
ASSERT_EQ(0, dir->set(obj, optional_yield{io, yield}));
dir->shutdown();

boost::system::error_code ec;
request req;
Expand Down Expand Up @@ -185,7 +186,6 @@ TEST_F(ObjectDirectoryFixture, GetYield)

ASSERT_EQ(0, dir->get(obj, optional_yield{io, yield}));
EXPECT_EQ(obj->objName, "newoid");
dir->shutdown();

{
boost::system::error_code ec;
Expand All @@ -207,7 +207,6 @@ TEST_F(ObjectDirectoryFixture, CopyYield)
spawn::spawn(io, [this] (spawn::yield_context yield) {
ASSERT_EQ(0, dir->set(obj, optional_yield{io, yield}));
ASSERT_EQ(0, dir->copy(obj, "copyTestName", "copyBucketName", optional_yield{io, yield}));
dir->shutdown();

boost::system::error_code ec;
request req;
Expand Down Expand Up @@ -252,7 +251,6 @@ TEST_F(ObjectDirectoryFixture, DelYield)
}

ASSERT_EQ(0, dir->del(obj, optional_yield{io, yield}));
dir->shutdown();

{
boost::system::error_code ec;
Expand All @@ -279,7 +277,6 @@ TEST_F(ObjectDirectoryFixture, UpdateFieldYield)
ASSERT_EQ(0, dir->set(obj, optional_yield{io, yield}));
ASSERT_EQ(0, dir->update_field(obj, "objName", "newTestName", optional_yield{io, yield}));
ASSERT_EQ(0, dir->update_field(obj, "objHosts", "127.0.0.1:5000", optional_yield{io, yield}));
dir->shutdown();

boost::system::error_code ec;
request req;
Expand All @@ -305,7 +302,6 @@ TEST_F(BlockDirectoryFixture, SetYield)
{
spawn::spawn(io, [this] (spawn::yield_context yield) {
ASSERT_EQ(0, dir->set(block, optional_yield{io, yield}));
dir->shutdown();

boost::system::error_code ec;
request req;
Expand Down Expand Up @@ -344,7 +340,6 @@ TEST_F(BlockDirectoryFixture, GetYield)

ASSERT_EQ(0, dir->get(block, optional_yield{io, yield}));
EXPECT_EQ(block->cacheObj.objName, "newoid");
dir->shutdown();

{
boost::system::error_code ec;
Expand All @@ -366,7 +361,6 @@ TEST_F(BlockDirectoryFixture, CopyYield)
spawn::spawn(io, [this] (spawn::yield_context yield) {
ASSERT_EQ(0, dir->set(block, optional_yield{io, yield}));
ASSERT_EQ(0, dir->copy(block, "copyTestName", "copyBucketName", optional_yield{io, yield}));
dir->shutdown();

boost::system::error_code ec;
request req;
Expand Down Expand Up @@ -411,7 +405,6 @@ TEST_F(BlockDirectoryFixture, DelYield)
}

ASSERT_EQ(0, dir->del(block, optional_yield{io, yield}));
dir->shutdown();

{
boost::system::error_code ec;
Expand All @@ -438,7 +431,6 @@ TEST_F(BlockDirectoryFixture, UpdateFieldYield)
ASSERT_EQ(0, dir->set(block, optional_yield{io, yield}));
ASSERT_EQ(0, dir->update_field(block, "objName", "newTestName", optional_yield{io, yield}));
ASSERT_EQ(0, dir->update_field(block, "blockHosts", "127.0.0.1:5000", optional_yield{io, yield}));
dir->shutdown();

boost::system::error_code ec;
request req;
Expand Down Expand Up @@ -481,7 +473,6 @@ TEST_F(BlockDirectoryFixture, RemoveHostYield)
}

ASSERT_EQ(0, dir->remove_host(block, "127.0.0.1:6000", optional_yield{io, yield}));
dir->shutdown();

{
boost::system::error_code ec;
Expand Down
22 changes: 9 additions & 13 deletions src/test/rgw/test_d4n_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ class LFUDAPolicyFixture : public ::testing::Test {
.hostsList = { env->redisHost }
};

conn = std::make_shared<connection>(boost::asio::make_strand(io));
rgw::cache::Partition partition_info{ .location = "RedisCache", .size = 1000 };
cacheDriver = new rgw::cache::RedisDriver{io, partition_info};
policyDriver = new rgw::d4n::PolicyDriver(io, cacheDriver, "lfuda");
dir = new rgw::d4n::BlockDirectory{io};
conn = new connection{boost::asio::make_strand(io)};
policyDriver = new rgw::d4n::PolicyDriver(conn, cacheDriver, "lfuda");
dir = new rgw::d4n::BlockDirectory{conn};

ASSERT_NE(dir, nullptr);
ASSERT_NE(cacheDriver, nullptr);
ASSERT_NE(policyDriver, nullptr);
ASSERT_NE(conn, nullptr);

dir->init(env->cct, env->dpp);
dir->init(env->cct);
cacheDriver->initialize(env->dpp);
policyDriver->get_cache_policy()->init(env->cct, env->dpp);
policyDriver->get_cache_policy()->init(env->cct);

bl.append("test data");
bufferlist attrVal;
Expand All @@ -89,7 +89,9 @@ class LFUDAPolicyFixture : public ::testing::Test {
}

virtual void TearDown() {
delete conn;
// call cancel() on the connection's executor
boost::asio::dispatch(conn->get_executor(), [c = conn] { c->cancel(); });

delete block;
delete dir;
delete cacheDriver;
Expand Down Expand Up @@ -150,7 +152,7 @@ class LFUDAPolicyFixture : public ::testing::Test {
rgw::cache::RedisDriver* cacheDriver;

net::io_context io;
connection* conn;
std::shared_ptr<connection> conn;

bufferlist bl;
rgw::sal::Attrs attrs;
Expand All @@ -165,9 +167,7 @@ TEST_F(LFUDAPolicyFixture, LocalGetBlockYield)

ASSERT_GE(lfuda(env->dpp, block, cacheDriver, optional_yield{io, yield}), 0);

dir->shutdown();
cacheDriver->shutdown();
dynamic_cast<rgw::d4n::LFUDAPolicy*>(policyDriver->get_cache_policy())->shutdown();

boost::system::error_code ec;
request req;
Expand Down Expand Up @@ -228,9 +228,7 @@ TEST_F(LFUDAPolicyFixture, RemoteGetBlockYield)

ASSERT_GE(lfuda(env->dpp, block, cacheDriver, optional_yield{io, yield}), 0);

dir->shutdown();
cacheDriver->shutdown();
dynamic_cast<rgw::d4n::LFUDAPolicy*>(policyDriver->get_cache_policy())->shutdown();

std::string key = block->cacheObj.bucketName + "_" + block->cacheObj.objName + "_" + std::to_string(block->blockID) + "_" + std::to_string(block->size);
boost::system::error_code ec;
Expand Down Expand Up @@ -260,9 +258,7 @@ TEST_F(LFUDAPolicyFixture, BackendGetBlockYield)
spawn::spawn(io, [this] (spawn::yield_context yield) {
ASSERT_GE(lfuda(env->dpp, block, cacheDriver, optional_yield{io, yield}), 0);

dir->shutdown();
cacheDriver->shutdown();
dynamic_cast<rgw::d4n::LFUDAPolicy*>(policyDriver->get_cache_policy())->shutdown();

boost::system::error_code ec;
request req;
Expand Down

0 comments on commit ab1a292

Please sign in to comment.