// Copyright 2023 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #ifndef NDEBUG #include #include namespace DB::PS::V2::tests { class MockEntries { private: std::map entries; public: void put(PageId page_id, PageEntry entry) { entries[page_id] = entry; } std::set validNormalPageIds() const { std::set ids; for (auto it = entries.begin(); it != entries.end(); ++it) ids.insert(it->first); return ids; } std::optional findNormalPageEntry(PageId page_id) const { if (auto it = entries.find(page_id); it != entries.end()) return it->second; else return std::nullopt; } }; class MockSnapshot; using MockSnapshotPtr = std::shared_ptr; class MockSnapshot { private: std::shared_ptr entries; public: MockSnapshot() : entries(std::make_shared()) {} std::shared_ptr version() { return entries; } static MockSnapshotPtr createFrom(std::vector> && entries) { auto snap = std::make_shared(); for (const auto & [pid, entry] : entries) { snap->entries->put(pid, entry); } return snap; } }; } // namespace DB::PS::V2::tests #endif // NDEBUG