Skip to content

Commit ef2702f

Browse files
fix update snapshot count function.
Fixes #192
1 parent 69356de commit ef2702f

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/cpp/src/kvs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ score::Result<size_t> Kvs::snapshot_count() const
589589
score::Result<size_t> result = score::MakeUnexpected(ErrorCode::UnmappedError);
590590
size_t count = 0;
591591
bool error = false;
592-
for (size_t idx = 1; idx <= KVS_MAX_SNAPSHOTS; ++idx)
592+
for (size_t idx = 0; idx < KVS_MAX_SNAPSHOTS; ++idx)
593593
{
594594
const score::filesystem::Path fname = filename_prefix.Native() + "_" + to_string(idx) + ".json";
595595
const auto fname_exists_res = filesystem->standard->Exists(fname);
@@ -605,7 +605,7 @@ score::Result<size_t> Kvs::snapshot_count() const
605605
error = true;
606606
break;
607607
}
608-
count = idx;
608+
count = idx+1;
609609
}
610610
if (error)
611611
{

src/cpp/tests/test_kvs.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,11 @@ TEST(kvs_snapshot_rotate, snapshot_rotate_success)
714714
ASSERT_TRUE(result);
715715

716716
/* Create empty Test-Snapshot Files */
717-
for (size_t i = 1; i < KVS_MAX_SNAPSHOTS; i++)
717+
for (size_t i = 0; i < KVS_MAX_SNAPSHOTS; i++)
718718
{
719719
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".json") << "{}";
720720
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".hash") << "{}";
721-
EXPECT_EQ(result.value().snapshot_count().value(), i);
721+
EXPECT_EQ(result.value().snapshot_count().value(), i+1);
722722
}
723723
ASSERT_FALSE(std::filesystem::exists(filename_prefix + "_" + std::to_string(KVS_MAX_SNAPSHOTS) + ".json"));
724724
ASSERT_FALSE(std::filesystem::exists(filename_prefix + "_" + std::to_string(KVS_MAX_SNAPSHOTS) + ".hash"));
@@ -744,11 +744,11 @@ TEST(kvs_snapshot_rotate, snapshot_rotate_max_snapshots)
744744
ASSERT_TRUE(result);
745745

746746
/* Create empty Test-Snapshot Files */
747-
for (size_t i = 1; i < KVS_MAX_SNAPSHOTS; i++)
747+
for (size_t i = 0; i < KVS_MAX_SNAPSHOTS; i++)
748748
{
749749
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".json") << "{}";
750750
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".hash") << "{}";
751-
EXPECT_EQ(result.value().snapshot_count().value(), i);
751+
EXPECT_EQ(result.value().snapshot_count().value(), i+1);
752752
}
753753
ASSERT_FALSE(std::filesystem::exists(filename_prefix + "_" + std::to_string(KVS_MAX_SNAPSHOTS) + ".json"));
754754
ASSERT_FALSE(std::filesystem::exists(filename_prefix + "_" + std::to_string(KVS_MAX_SNAPSHOTS) + ".hash"));
@@ -770,11 +770,11 @@ TEST(kvs_snapshot_rotate, snapshot_rotate_failure_renaming_json)
770770
ASSERT_TRUE(result);
771771

772772
/* Create empty Test-Snapshot Files */
773-
for (size_t i = 1; i < KVS_MAX_SNAPSHOTS; i++)
773+
for (size_t i = 0; i < KVS_MAX_SNAPSHOTS; i++)
774774
{
775775
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".json") << "{}";
776776
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".hash") << "{}";
777-
EXPECT_EQ(result.value().snapshot_count().value(), i);
777+
EXPECT_EQ(result.value().snapshot_count().value(), i+1);
778778
}
779779

780780
/* Snapshot (JSON) Renaming failed (Create directorys instead of json files to trigger rename
@@ -795,11 +795,11 @@ TEST(kvs_snapshot_rotate, snapshot_rotate_failure_renaming_hash)
795795
ASSERT_TRUE(result);
796796

797797
/* Create empty Test-Snapshot Files */
798-
for (size_t i = 1; i < KVS_MAX_SNAPSHOTS; i++)
798+
for (size_t i = 0; i < KVS_MAX_SNAPSHOTS; i++)
799799
{
800800
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".json") << "{}";
801801
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".hash") << "{}";
802-
EXPECT_EQ(result.value().snapshot_count().value(), i);
802+
EXPECT_EQ(result.value().snapshot_count().value(), i+1);
803803
}
804804

805805
/* Hash Renaming failed (Create directorys instead of json files to trigger rename error)*/
@@ -957,12 +957,12 @@ TEST(kvs_snapshot_count, snapshot_count_success)
957957
ASSERT_TRUE(result);
958958

959959
/* Create empty Test-Snapshot Files */
960-
for (size_t i = 1; i <= KVS_MAX_SNAPSHOTS; i++)
960+
for (size_t i = 0; i < KVS_MAX_SNAPSHOTS; i++)
961961
{
962962
std::ofstream(filename_prefix + "_" + std::to_string(i) + ".json") << "{}";
963963
auto count = result.value().snapshot_count();
964964
EXPECT_TRUE(count);
965-
EXPECT_EQ(count.value(), i);
965+
EXPECT_EQ(count.value(), i+1);
966966
}
967967
/* Test maximum capacity */
968968
std::ofstream(filename_prefix + "_" + std::to_string(KVS_MAX_SNAPSHOTS + 1) + ".json") << "{}";

tests/test_cases/tests/test_cit_snapshots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def test_ok(
7171
snapshot_max_count: int,
7272
version: str,
7373
):
74-
if version == "cpp" and snapshot_max_count in [1, 3, 10]:
74+
if version == "cpp" and snapshot_max_count in [0, 1, 3, 10]:
7575
pytest.xfail(
76-
reason="https://github.com/eclipse-score/persistency/issues/192 , https://github.com/eclipse-score/persistency/issues/108",
76+
reason="https://github.com/eclipse-score/persistency/issues/108",
7777
)
7878
assert results.return_code == ResultCode.SUCCESS
7979

tests/test_scenarios/cpp/src/cit/snapshots.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class SnapshotCount : public Scenario
8585
* only after flush when MAX<3.
8686
*
8787
* Raised bugs: https://github.com/eclipse-score/persistency/issues/108
88-
* https://github.com/eclipse-score/persistency/issues/192
8988
*/
9089
void run(const std::string& input) const final
9190
{

0 commit comments

Comments
 (0)