Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
rgw/sfs: testing: use SFStore's DBConnRef where available
Browse files Browse the repository at this point in the history
If we're alrady using an SFStore, don't create a new DBConnRef, just use
the one that's already part of the SFStore.

Signed-off-by: Tim Serong <[email protected]>
  • Loading branch information
tserong committed Sep 25, 2023
1 parent 030745d commit e133fb0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
11 changes: 4 additions & 7 deletions src/test/rgw/sfs/test_rgw_sfs_concurrency.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class TestSFSConcurrency
const fs::path database_directory;

std::unique_ptr<rgw::sal::SFStore> store;
sqlite::DBConnRef dbconn;
BucketRef bucket;
ObjectRef predef_object;
sqlite::DBVersionedObject predef_db_object;
Expand All @@ -81,16 +80,15 @@ class TestSFSConcurrency
}
void SetUp() override {
ASSERT_TRUE(fs::exists(database_directory)) << database_directory;
dbconn = std::make_shared<sqlite::DBConn>(cct.get());
store.reset(new rgw::sal::SFStore(cct.get(), database_directory));

sqlite::SQLiteUsers users(dbconn);
sqlite::SQLiteUsers users(store->db_conn);
sqlite::DBOPUserInfo user;
user.uinfo.user_id.id = "testuser";
user.uinfo.display_name = "display_name";
users.store_user(user);

sqlite::SQLiteBuckets db_buckets(dbconn);
sqlite::SQLiteBuckets db_buckets(store->db_conn);
sqlite::DBOPBucketInfo db_binfo;
db_binfo.binfo.bucket = rgw_bucket("", "testbucket", "1234");
db_binfo.binfo.owner = rgw_user("testuser");
Expand All @@ -107,7 +105,7 @@ class TestSFSConcurrency

predef_object = bucket->create_version(rgw_obj_key("predef_object"));
predef_object->metadata_finish(store.get(), false);
sqlite::SQLiteVersionedObjects svos(dbconn);
sqlite::SQLiteVersionedObjects svos(store->db_conn);
predef_db_object =
svos.get_versioned_object(predef_object->version_id).value();

Expand All @@ -126,7 +124,6 @@ class TestSFSConcurrency

void TearDown() override {
store.reset();
dbconn.reset();
fs::remove_all(database_directory);
}

Expand Down Expand Up @@ -192,7 +189,7 @@ class TestSFSConcurrency
);
}

sqlite::Storage& storage() { return dbconn->get_storage(); }
sqlite::Storage& storage() { return store->db_conn->get_storage(); }
};

TEST_P(TestSFSConcurrency, parallel_executions_must_not_throw) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rgw/sfs/test_rgw_sfs_object_state_machine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TestSFSObjectStateMachine : public ::testing::Test {
}

fs::path getDBFullPath() const { return getDBFullPath(getTestDir()); }
sqlite::DBConnRef dbconn() { return std::make_shared<sqlite::DBConn>(cct); }
sqlite::DBConnRef dbconn() { return store->db_conn; }
sqlite::Storage& storage() { return dbconn()->get_storage(); }
ObjectState database_object_state(ObjectRef obj) {
return storage()
Expand Down
35 changes: 16 additions & 19 deletions src/test/rgw/sfs/test_rgw_sfs_sqlite_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class TestSFSList : public ::testing::Test {
const fs::path database_directory;

std::unique_ptr<rgw::sal::SFStore> store;
DBConnRef dbconn;

TestSFSList()
: cct(new CephContext(CEPH_ENTITY_TYPE_ANY)),
Expand All @@ -52,16 +51,15 @@ class TestSFSList : public ::testing::Test {
}
void SetUp() override {
ASSERT_TRUE(fs::exists(database_directory)) << database_directory;
dbconn = std::make_shared<DBConn>(cct.get());
store.reset(new rgw::sal::SFStore(cct.get(), database_directory));

SQLiteUsers users(dbconn);
SQLiteUsers users(store->db_conn);
DBOPUserInfo user;
user.uinfo.user_id.id = "testuser";
user.uinfo.display_name = "display_name";
users.store_user(user);

SQLiteBuckets db_buckets(dbconn);
SQLiteBuckets db_buckets(store->db_conn);
DBOPBucketInfo db_binfo;
db_binfo.binfo.bucket = rgw_bucket("", "testbucket", "testbucket");
db_binfo.binfo.owner = rgw_user("testuser");
Expand All @@ -77,7 +75,6 @@ class TestSFSList : public ::testing::Test {
dump_db();
}
store.reset();
dbconn.reset();
fs::remove_all(database_directory);
}

Expand All @@ -95,17 +92,17 @@ class TestSFSList : public ::testing::Test {
std::string name(prefix);
name.append(gen_rand_alphanumeric(cct.get(), 23));
const auto obj = create_test_object("testbucket", name);
SQLiteObjects os(dbconn);
SQLiteObjects os(store->db_conn);
os.store_object(obj);
auto ver = create_test_versionedobject(obj.uuid, "testversion");
ver.object_state = version_state;
SQLiteVersionedObjects vos(dbconn);
SQLiteVersionedObjects vos(store->db_conn);
vos.insert_versioned_object(ver);
return std::make_pair(obj, ver);
}

void dump_db() {
auto& storage = dbconn->get_storage();
auto& storage = store->db_conn->get_storage();
lderr(cct.get()) << "Dumping objects:" << dendl;
for (const auto& row : storage.get_all<DBObject>()) {
lderr(cct.get()) << row << dendl;
Expand All @@ -122,7 +119,7 @@ class TestSFSList : public ::testing::Test {
return e;
}

SQLiteList make_uut() { return SQLiteList(dbconn); }
SQLiteList make_uut() { return SQLiteList(store->db_conn); }
};

class TestSFSListObjectsAndVersions
Expand Down Expand Up @@ -308,7 +305,7 @@ TEST_F(TestSFSList, objects__does_not_return_objects_with_delete_marker) {
auto del = create_test_versionedobject(oov.first.uuid, "deletemarker");
del.object_state = rgw::sal::sfs::ObjectState::COMMITTED;
del.version_type = rgw::sal::sfs::VersionType::DELETE_MARKER;
SQLiteVersionedObjects vos(dbconn);
SQLiteVersionedObjects vos(store->db_conn);
vos.insert_versioned_object(del);

ASSERT_TRUE(uut.objects("testbucket", "", "", 1000, results));
Expand All @@ -333,7 +330,7 @@ TEST_F(TestSFSList, versions__returns_versions_and_delete_markers) {
auto del = create_test_versionedobject(oov.first.uuid, "deletemarker");
del.object_state = rgw::sal::sfs::ObjectState::COMMITTED;
del.version_type = rgw::sal::sfs::VersionType::DELETE_MARKER;
SQLiteVersionedObjects vos(dbconn);
SQLiteVersionedObjects vos(store->db_conn);
vos.insert_versioned_object(del);

ASSERT_TRUE(uut.versions("testbucket", "", "", 1000, results));
Expand All @@ -350,8 +347,8 @@ TEST_F(TestSFSList, versions__correctly_sorts_and_marks_latest_version) {
std::vector<rgw_bucket_dir_entry> results;

const auto obj = create_test_object("testbucket", "obj");
SQLiteObjects os(dbconn);
SQLiteVersionedObjects vos(dbconn);
SQLiteObjects os(store->db_conn);
SQLiteVersionedObjects vos(store->db_conn);
os.store_object(obj);
auto latest = create_test_versionedobject(obj.uuid, "latest");
latest.object_state = rgw::sal::sfs::ObjectState::COMMITTED;
Expand Down Expand Up @@ -385,8 +382,8 @@ TEST_F(TestSFSList, versions__there_is_latest_with_multiple_versions) {

const auto obj1 = create_test_object("testbucket", "test1/a");
const auto obj2 = create_test_object("testbucket", "test2/abc");
SQLiteObjects os(dbconn);
SQLiteVersionedObjects vos(dbconn);
SQLiteObjects os(store->db_conn);
SQLiteVersionedObjects vos(store->db_conn);
os.store_object(obj1);
os.store_object(obj2);
std::array<rgw::sal::sfs::sqlite::DBVersionedObject, 3> vers_obj1 = {
Expand Down Expand Up @@ -434,8 +431,8 @@ TEST_F(TestSFSList, versions__only_one_latest) {
std::vector<rgw_bucket_dir_entry> results;

const auto obj = create_test_object("testbucket", "test1/a");
SQLiteObjects os(dbconn);
SQLiteVersionedObjects vos(dbconn);
SQLiteObjects os(store->db_conn);
SQLiteVersionedObjects vos(store->db_conn);
os.store_object(obj);
auto vo1 = create_test_versionedobject(
obj.uuid, gen_rand_alphanumeric(cct.get(), 23)
Expand Down Expand Up @@ -464,8 +461,8 @@ TEST_F(TestSFSList, versions__delete_marker_latest) {
std::vector<rgw_bucket_dir_entry> results;

const auto obj = create_test_object("testbucket", "test1/a");
SQLiteObjects os(dbconn);
SQLiteVersionedObjects vos(dbconn);
SQLiteObjects os(store->db_conn);
SQLiteVersionedObjects vos(store->db_conn);
os.store_object(obj);
auto vo1 = create_test_versionedobject(
obj.uuid, gen_rand_alphanumeric(cct.get(), 23)
Expand Down

0 comments on commit e133fb0

Please sign in to comment.