Skip to content

Commit 0828908

Browse files
committed
cpp impl: remove write_json_data buffer
remove write_json_data buffer argument
1 parent d41e12e commit 0828908

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/cpp/inc/kvs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ class Kvs final {
556556

557557
score::Result<std::unordered_map<std::string, KvsValue>> parse_json_data(const std::string& data);
558558
score::Result<std::unordered_map<std::string, KvsValue>> open_json(const std::string& prefix, OpenJsonNeedFile need_file);
559-
score::ResultBlank write_json_data(const std::string& filename_prefix, const std::string& buf);
559+
score::ResultBlank write_json_data(const std::string& buf);
560560
};
561561

562562

src/cpp/src/kvs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ score::ResultBlank Kvs::remove_key(const string_view key) {
823823
}
824824

825825
/* Helper Function to write JSON data to a file for flush process (also adds Hash file)*/
826-
score::ResultBlank Kvs::write_json_data(const std::string& filename_prefix, const std::string& buf)
826+
score::ResultBlank Kvs::write_json_data(const std::string& buf)
827827
{
828828
score::ResultBlank result = score::MakeUnexpected(MyErrorCode::UnmappedError);
829829
const std::string fn_json = filename_prefix + "_0.json";
@@ -899,7 +899,7 @@ score::ResultBlank Kvs::flush() {
899899
}else{
900900
/* Write JSON Data */
901901
std::string buf = std::move(buf_res.value());
902-
result = write_json_data(filename_prefix, buf);
902+
result = write_json_data(buf);
903903
}
904904
}
905905
}

src/cpp/tests/test_kvs.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,8 @@ TEST(kvs_write_json_data, write_json_data_success){
13741374
auto kvs = Kvs::open(InstanceId(instance_id), OpenNeedDefaults::Optional, OpenNeedKvs::Optional, std::string(data_dir));
13751375
ASSERT_TRUE(kvs);
13761376

1377-
auto result = kvs->write_json_data(filename_prefix, json_test_data);
1377+
kvs->filename_prefix = filename_prefix; /* Set the filename prefix to the test prefix */
1378+
auto result = kvs->write_json_data(json_test_data);
13781379
EXPECT_TRUE(result);
13791380
EXPECT_TRUE(std::filesystem::exists(kvs_prefix + ".json"));
13801381
EXPECT_TRUE(std::filesystem::exists(kvs_prefix + ".hash"));
@@ -1410,8 +1411,8 @@ TEST(kvs_write_json_data, write_json_data_failure){
14101411

14111412
auto kvs = Kvs::open(InstanceId(instance_id), OpenNeedDefaults::Optional, OpenNeedKvs::Optional, std::string(data_dir));
14121413
ASSERT_TRUE(kvs);
1413-
1414-
auto result = kvs->write_json_data(unwritable_dir + "/kvs_" + std::to_string(instance), kvs_json);
1414+
kvs->filename_prefix = unwritable_dir + "/kvs_" + std::to_string(instance); /* Set the filename prefix to the test prefix */
1415+
auto result = kvs->write_json_data(kvs_json);
14151416
EXPECT_FALSE(result);
14161417
EXPECT_EQ(result.error(), MyErrorCode::PhysicalStorageFailure);
14171418

@@ -1420,7 +1421,8 @@ TEST(kvs_write_json_data, write_json_data_failure){
14201421
out_hash << "data";
14211422
out_hash.close();
14221423
std::filesystem::permissions(kvs_prefix + ".hash", std::filesystem::perms::owner_read, std::filesystem::perm_options::replace);
1423-
result = kvs->write_json_data(filename_prefix, kvs_json);
1424+
kvs->filename_prefix = filename_prefix; /* Reset the filename prefix to the test prefix */
1425+
result = kvs->write_json_data(kvs_json);
14241426
EXPECT_FALSE(result);
14251427
EXPECT_EQ(result.error(), MyErrorCode::PhysicalStorageFailure);
14261428

@@ -1429,13 +1431,14 @@ TEST(kvs_write_json_data, write_json_data_failure){
14291431
out_json << "data";
14301432
out_json.close();
14311433
std::filesystem::permissions(kvs_prefix + ".json", std::filesystem::perms::owner_read, std::filesystem::perm_options::replace);
1432-
result = kvs->write_json_data(filename_prefix, kvs_json);
1434+
kvs->filename_prefix = filename_prefix; /* Reset the filename prefix to the test prefix */
1435+
result = kvs->write_json_data(kvs_json);
14331436
EXPECT_FALSE(result);
14341437
EXPECT_EQ(result.error(), MyErrorCode::PhysicalStorageFailure);
14351438

14361439
/* Test if path argument is missing parent path (will only occur if semantic errors will be done in flush() )*/
1437-
const std::string prefix = "no_parent_path";
1438-
result = kvs->write_json_data(prefix, kvs_json);
1440+
kvs->filename_prefix = "no_parent_path"; /* Set the filename prefix to the test prefix */
1441+
result = kvs->write_json_data(kvs_json);
14391442
EXPECT_FALSE(result);
14401443
EXPECT_EQ(result.error(), MyErrorCode::UnmappedError);
14411444

0 commit comments

Comments
 (0)