|
| 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