Skip to content

Commit 20b9788

Browse files
committed
WIP
1 parent d6979af commit 20b9788

12 files changed

Lines changed: 228 additions & 25 deletions
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#include "backend_shared_impl.h"
2-
32
namespace limestone::grpc::service {
43

4+
using limestone::internal::wal_history;
5+
56

67
backend_shared_impl::backend_shared_impl(const boost::filesystem::path& log_dir)
78
: log_dir_(log_dir) {}
89

9-
std::vector<limestone::internal::wal_history::record> backend_shared_impl::list_wal_history() {
10-
// stub implementation
11-
return {};
10+
std::vector<wal_history::record> backend_shared_impl::list_wal_history() {
11+
wal_history wal_history_(log_dir_);
12+
return wal_history_.list();
1213
}
1314

1415
} // namespace limestone::grpc::service

src/limestone/grpc/backend/grpc_service_backend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace limestone::grpc::service {
2323

2424
using limestone::api::datastore;
2525

26-
std::unique_ptr<grpc_service_backend> grpc_service_backend::create_inproc(datastore& store) {
27-
return std::make_unique<inproc_backend>(store);
26+
std::unique_ptr<grpc_service_backend> grpc_service_backend::create_inproc(datastore& store, const boost::filesystem::path& log_dir) {
27+
return std::make_unique<inproc_backend>(store, log_dir);
2828
}
2929

3030
std::unique_ptr<grpc_service_backend> grpc_service_backend::create_standalone(const boost::filesystem::path& data_dir) {

src/limestone/grpc/backend/grpc_service_backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class grpc_service_backend {
3131
virtual ~grpc_service_backend() = default;
3232

3333
// Factory helpers (unchanged)
34-
static std::unique_ptr<grpc_service_backend> create_inproc(limestone::api::datastore& store);
34+
static std::unique_ptr<grpc_service_backend> create_inproc(limestone::api::datastore& store, const boost::filesystem::path& log_dir);
3535
static std::unique_ptr<grpc_service_backend> create_standalone(const boost::filesystem::path& log_dir);
3636

3737
// Returns the list of WAL history records.

src/limestone/grpc/backend/inproc_backend.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
namespace limestone::grpc::service {
1919

2020

21-
inproc_backend::inproc_backend(limestone::api::datastore& store)
22-
: store_(store)
21+
inproc_backend::inproc_backend(limestone::api::datastore& ds, const boost::filesystem::path& log_dir)
22+
: datastore_(ds), log_dir_(log_dir), backend_shared_impl_(log_dir)
2323
{
24-
// store_ already initialized by member initializer list
2524
}
2625

2726
std::vector<wal_history::record> inproc_backend::list_wal_history() {
28-
// stub implementation
29-
return {};
27+
return backend_shared_impl_.list_wal_history();
3028
}
3129

3230

src/limestone/grpc/backend/inproc_backend.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717

1818
#include <vector>
1919
#include "grpc_service_backend.h"
20-
20+
#include "backend_shared_impl.h"
2121
namespace limestone::grpc::service {
2222

2323
class inproc_backend : public grpc_service_backend {
2424
public:
25-
explicit inproc_backend(limestone::api::datastore& store);
25+
inproc_backend(limestone::api::datastore& ds, const boost::filesystem::path& log_dir);
2626
~inproc_backend() override = default;
2727

2828
std::vector<wal_history::record> list_wal_history() override;
2929
private:
30-
limestone::api::datastore& store_;
30+
limestone::api::datastore& datastore_;
31+
boost::filesystem::path log_dir_;
32+
backend_shared_impl backend_shared_impl_;
3133
};
3234

3335
} // namespace limestone::grpc::service

src/limestone/grpc/backend/standalone_backend.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Copyright 2022-2025 Project Tsurugi.
43
*
@@ -19,15 +18,12 @@
1918
namespace limestone::grpc::service {
2019

2120
standalone_backend::standalone_backend(const boost::filesystem::path& log_dir)
22-
: log_dir_(log_dir)
21+
: log_dir_(log_dir), backend_shared_impl_(log_dir)
2322
{
24-
// log_dir_ already initialized by member initializer list
2523
}
2624

2725
std::vector<wal_history::record> standalone_backend::list_wal_history() {
28-
// stub implementation
29-
return {};
26+
return backend_shared_impl_.list_wal_history();
3027
}
3128

32-
} // namespace limestone::grpc::service
33-
29+
}

src/limestone/grpc/backend/standalone_backend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <vector>
1919
#include "grpc_service_backend.h"
20-
20+
#include "backend_shared_impl.h"
2121
namespace limestone::grpc::service {
2222

2323
class standalone_backend : public grpc_service_backend {
@@ -28,6 +28,7 @@ class standalone_backend : public grpc_service_backend {
2828
std::vector<wal_history::record> list_wal_history() override;
2929
private:
3030
boost::filesystem::path log_dir_;
31+
backend_shared_impl backend_shared_impl_;
3132
};
3233

3334
} // namespace limestone::grpc::service
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2022-2025 Project Tsurugi.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "limestone/grpc/backend/backend_shared_impl.h"
18+
#include <gtest/gtest.h>
19+
#include <boost/filesystem.hpp>
20+
#include <fstream>
21+
#include <vector>
22+
23+
namespace limestone::testing {
24+
25+
using namespace limestone::grpc::service;
26+
using namespace limestone::internal;
27+
28+
class backend_shared_impl_test : public ::testing::Test {
29+
protected:
30+
boost::filesystem::path temp_dir;
31+
32+
void SetUp() override {
33+
temp_dir = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
34+
boost::filesystem::create_directories(temp_dir);
35+
}
36+
void TearDown() override {
37+
boost::filesystem::remove_all(temp_dir);
38+
}
39+
};
40+
41+
42+
TEST_F(backend_shared_impl_test, list_wal_history_returns_empty_when_dir_is_empty) {
43+
backend_shared_impl backend(temp_dir);
44+
auto result = backend.list_wal_history();
45+
EXPECT_TRUE(result.empty());
46+
}
47+
48+
TEST_F(backend_shared_impl_test, list_wal_history_matches_wal_history_class) {
49+
wal_history wh(temp_dir);
50+
wh.append(123);
51+
wh.append(456);
52+
auto expected = wh.list();
53+
54+
backend_shared_impl backend(temp_dir);
55+
auto actual = backend.list_wal_history();
56+
57+
ASSERT_EQ(expected.size(), actual.size());
58+
for (size_t i = 0; i < expected.size(); ++i) {
59+
EXPECT_EQ(expected[i].epoch, actual[i].epoch);
60+
EXPECT_EQ(expected[i].unique_id, actual[i].unique_id);
61+
EXPECT_EQ(expected[i].timestamp, actual[i].timestamp);
62+
}
63+
}
64+
65+
} // namespace limestone::testing

test/limestone/grpc/grpc_service_backend_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ class grpc_service_backend_test : public ::testing::Test {
5050

5151
protected:
5252
std::unique_ptr<limestone::api::datastore_test> datastore_{};
53-
boost::filesystem::path log_dir_ = "/tmp/test_log_dir";
53+
boost::filesystem::path log_dir_ = "/tmp/grpc_service_backend_test";
5454
};
5555

5656
TEST_F(grpc_service_backend_test, create_inproc_returns_instance) {
5757
gen_datastore();
58-
auto backend = grpc_service_backend::create_inproc(*datastore_);
58+
auto backend = grpc_service_backend::create_inproc(*datastore_, log_dir_);
5959
EXPECT_NE(backend, nullptr);
6060
}
6161

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2022-2025 Project Tsurugi.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
#include "limestone/grpc/backend/inproc_backend.h"
19+
#include "wal_sync/wal_history.h"
20+
#include "limestone/api/datastore.h"
21+
#include "limestone/api/configuration.h"
22+
#include "test_root.h"
23+
#include <gtest/gtest.h>
24+
#include <boost/filesystem.hpp>
25+
#include <vector>
26+
27+
using namespace limestone::grpc::service;
28+
using namespace limestone::internal;
29+
30+
namespace {
31+
32+
class inproc_backend_test : public ::testing::Test {
33+
protected:
34+
std::unique_ptr<limestone::api::datastore_test> datastore_{};
35+
boost::filesystem::path log_dir = "/tmp/inproc_backend_test";
36+
37+
void gen_datastore() {
38+
std::vector<boost::filesystem::path> data_locations{};
39+
data_locations.emplace_back(log_dir);
40+
boost::filesystem::path metadata_location{log_dir};
41+
limestone::api::configuration conf(data_locations, metadata_location);
42+
datastore_ = std::make_unique<limestone::api::datastore_test>(conf);
43+
}
44+
45+
void SetUp() override {
46+
boost::filesystem::remove_all(log_dir);
47+
boost::filesystem::create_directories(log_dir);
48+
}
49+
void TearDown() override {
50+
datastore_ = nullptr;
51+
boost::filesystem::remove_all(log_dir);
52+
}
53+
};
54+
55+
TEST_F(inproc_backend_test, list_wal_history_empty) {
56+
gen_datastore();
57+
inproc_backend backend(*datastore_, log_dir);
58+
auto result = backend.list_wal_history();
59+
EXPECT_TRUE(result.empty());
60+
}
61+
62+
TEST_F(inproc_backend_test, list_wal_history_with_records) {
63+
gen_datastore();
64+
wal_history wh(log_dir);
65+
wh.append(300);
66+
wh.append(400);
67+
auto expected = wh.list();
68+
inproc_backend backend(*datastore_, log_dir);
69+
auto actual = backend.list_wal_history();
70+
ASSERT_EQ(expected.size(), actual.size());
71+
for (size_t i = 0; i < expected.size(); ++i) {
72+
EXPECT_EQ(expected[i].epoch, actual[i].epoch);
73+
EXPECT_EQ(expected[i].unique_id, actual[i].unique_id);
74+
EXPECT_EQ(expected[i].timestamp, actual[i].timestamp);
75+
}
76+
}
77+
78+
} // anonymous namespace

0 commit comments

Comments
 (0)