diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-04 12:25:20 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-05 13:32:39 +0200 |
commit | 5140befaa10f65145fe041b416b7764127efc379 (patch) | |
tree | 9bb8d66c31455d275e5870e69c10d31789fb6c0a /test/buildtool/storage | |
parent | e8992e622278d093165b3a0d8271a14424b61775 (diff) | |
download | justbuild-5140befaa10f65145fe041b416b7764127efc379.tar.gz |
Convert Storage to a general class
Diffstat (limited to 'test/buildtool/storage')
-rw-r--r-- | test/buildtool/storage/large_object_cas.test.cpp | 50 | ||||
-rw-r--r-- | test/buildtool/storage/local_ac.test.cpp | 25 | ||||
-rw-r--r-- | test/buildtool/storage/local_cas.test.cpp | 14 |
3 files changed, 57 insertions, 32 deletions
diff --git a/test/buildtool/storage/large_object_cas.test.cpp b/test/buildtool/storage/large_object_cas.test.cpp index f7713d45..fda1449a 100644 --- a/test/buildtool/storage/large_object_cas.test.cpp +++ b/test/buildtool/storage/large_object_cas.test.cpp @@ -100,7 +100,8 @@ class Tree final { TEST_CASE_METHOD(HermeticLocalTestFixture, "LargeObjectCAS: split a small tree", "[storage]") { - auto const& cas = Storage::Instance().CAS(); + auto const storage = Storage::Create(&StorageConfig::Instance()); + auto const& cas = storage.CAS(); // Create a small tree: using LargeTestUtils::Tree; @@ -125,6 +126,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, template <ObjectType kType> static void TestLarge() noexcept { SECTION("Large") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -132,7 +135,7 @@ static void TestLarge() noexcept { LargeTestUtils::Tree, LargeTestUtils::Blob<kIsExec>>; - auto const& cas = Storage::Instance().CAS(); + auto const& cas = storage.CAS(); // Create a large object: auto object = TestType::Create( @@ -188,9 +191,8 @@ static void TestLarge() noexcept { CHECK_FALSE(FileSystemManager::IsFile(path)); // Call split with disabled uplinking: - auto gen_config = - StorageConfig::Instance().CreateGenerationConfig(0); - ::Generation youngest_storage{gen_config}; + auto const youngest_storage = + ::Generation::Create(&StorageConfig::Instance()); auto pack_3 = kIsTree ? youngest_storage.CAS().SplitTree(digest) : youngest_storage.CAS().SplitBlob(digest); REQUIRE(pack_3); @@ -200,9 +202,8 @@ static void TestLarge() noexcept { for (std::size_t i = 0; i < StorageConfig::Instance().NumGenerations(); ++i) { - auto gen_config1 = - StorageConfig::Instance().CreateGenerationConfig(i); - ::Generation storage{gen_config1}; + auto const storage = ::Generation::Create( + &StorageConfig::Instance(), /*generation=*/i); auto generation_path = kIsTree ? storage.CAS().TreePath(digest) : storage.CAS().BlobPath(digest, kIsExec); @@ -219,6 +220,8 @@ static void TestLarge() noexcept { template <ObjectType kType> static void TestSmall() noexcept { SECTION("Small") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -226,7 +229,7 @@ static void TestSmall() noexcept { LargeTestUtils::Tree, LargeTestUtils::Blob<kIsExec>>; - auto const& cas = Storage::Instance().CAS(); + auto const& cas = storage.CAS(); // Create a small object: auto object = TestType::Create( @@ -275,6 +278,8 @@ static void TestSmall() noexcept { template <ObjectType kType> static void TestEmpty() noexcept { SECTION("Empty") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -282,7 +287,7 @@ static void TestEmpty() noexcept { LargeTestUtils::Tree, LargeTestUtils::Blob<kIsExec>>; - auto const& cas = Storage::Instance().CAS(); + auto const& cas = storage.CAS(); // Create an empty object: auto object = TestType::Create( @@ -324,6 +329,8 @@ static void TestEmpty() noexcept { template <ObjectType kType> static void TestExternal() noexcept { SECTION("External") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -331,7 +338,7 @@ static void TestExternal() noexcept { LargeTestUtils::Tree, LargeTestUtils::Blob<kIsExec>>; - auto const& cas = Storage::Instance().CAS(); + auto const& cas = storage.CAS(); // Create a large object: auto object = TestType::Create( @@ -354,8 +361,7 @@ static void TestExternal() noexcept { REQUIRE(cas.BlobPath(part, is_executable)); } - auto gen_config = StorageConfig::Instance().CreateGenerationConfig(0); - ::Generation const youngest{gen_config}; + auto const youngest = ::Generation::Create(&StorageConfig::Instance()); SECTION("Proper request") { if constexpr (kIsTree) { @@ -424,6 +430,8 @@ static void TestExternal() noexcept { template <ObjectType kType> static void TestCompactification() { SECTION("Compactify") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -431,7 +439,7 @@ static void TestCompactification() { LargeTestUtils::Tree, LargeTestUtils::Blob<kIsExec>>; - auto const& cas = Storage::Instance().CAS(); + auto const& cas = storage.CAS(); // Create a large object and split it: auto object = TestType::Create( @@ -470,8 +478,7 @@ static void TestCompactification() { : cas.BlobPath(digest, kIsExec); }; - auto gen_config = StorageConfig::Instance().CreateGenerationConfig(0); - ::Generation const latest{gen_config}; + auto const latest = ::Generation::Create(&StorageConfig::Instance()); REQUIRE(get_path(latest.CAS(), digest).has_value()); REQUIRE(get_path(latest.CAS(), digest_2).has_value()); @@ -536,7 +543,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, TEST_CASE_METHOD(HermeticLocalTestFixture, "LargeObjectCAS: uplink nested large objects", "[storage]") { - auto const& cas = Storage::Instance().CAS(); + auto const storage = Storage::Create(&StorageConfig::Instance()); + + auto const& cas = storage.CAS(); // Randomize a large directory: auto tree_path = LargeTestUtils::Tree::Generate( @@ -601,8 +610,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, CHECK_FALSE(FileSystemManager::IsFile(*nested_tree_path)); CHECK_FALSE(FileSystemManager::IsFile(*nested_blob_path)); - auto gen_config = StorageConfig::Instance().CreateGenerationConfig(0); - ::Generation const latest{gen_config}; + auto const latest = ::Generation::Create(&StorageConfig::Instance()); // However, they might be reconstructed on request because there entries are // in the latest generation: @@ -615,8 +623,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, // Check there are no spliced results in old generations: for (std::size_t i = 1; i < StorageConfig::Instance().NumGenerations(); ++i) { - auto gen_config1 = StorageConfig::Instance().CreateGenerationConfig(i); - ::Generation storage{gen_config1}; + auto const storage = + ::Generation::Create(&StorageConfig::Instance(), /*generation=*/i); auto const& generation_cas = storage.CAS(); REQUIRE_FALSE(generation_cas.TreePath(*nested_tree_digest)); REQUIRE_FALSE(generation_cas.TreePath(*large_tree_digest)); diff --git a/test/buildtool/storage/local_ac.test.cpp b/test/buildtool/storage/local_ac.test.cpp index 4092ca1d..f2ca3a15 100644 --- a/test/buildtool/storage/local_ac.test.cpp +++ b/test/buildtool/storage/local_ac.test.cpp @@ -20,6 +20,7 @@ #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" #include "test/utils/hermeticity/local.hpp" @@ -32,8 +33,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAC: Single action, single result", "[storage]") { - auto const& ac = Storage::Instance().ActionCache(); - auto const& cas = Storage::Instance().CAS(); + auto const storage = Storage::Create(&StorageConfig::Instance()); + + auto const& ac = storage.ActionCache(); + auto const& cas = storage.CAS(); auto action_id = ArtifactDigest::Create<ObjectType::File>("action"); CHECK(not ac.CachedResult(action_id)); @@ -45,8 +48,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAC: Two different actions, two different results", "[storage]") { - auto const& ac = Storage::Instance().ActionCache(); - auto const& cas = Storage::Instance().CAS(); + auto const storage = Storage::Create(&StorageConfig::Instance()); + + auto const& ac = storage.ActionCache(); + auto const& cas = storage.CAS(); auto action_id1 = ArtifactDigest::Create<ObjectType::File>("action1"); auto action_id2 = ArtifactDigest::Create<ObjectType::File>("action2"); @@ -74,8 +79,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAC: Two different actions, same two results", "[storage]") { - auto const& ac = Storage::Instance().ActionCache(); - auto const& cas = Storage::Instance().CAS(); + auto const storage = Storage::Create(&StorageConfig::Instance()); + + auto const& ac = storage.ActionCache(); + auto const& cas = storage.CAS(); auto action_id1 = ArtifactDigest::Create<ObjectType::File>("action1"); auto action_id2 = ArtifactDigest::Create<ObjectType::File>("action2"); @@ -103,8 +110,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAC: Same two actions, two different results", "[storage]") { - auto const& ac = Storage::Instance().ActionCache(); - auto const& cas = Storage::Instance().CAS(); + auto const storage = Storage::Create(&StorageConfig::Instance()); + + auto const& ac = storage.ActionCache(); + auto const& cas = storage.CAS(); auto action_id = ArtifactDigest::Create<ObjectType::File>("same action"); CHECK(not ac.CachedResult(action_id)); diff --git a/test/buildtool/storage/local_cas.test.cpp b/test/buildtool/storage/local_cas.test.cpp index 55a8d946..b64ee780 100644 --- a/test/buildtool/storage/local_cas.test.cpp +++ b/test/buildtool/storage/local_cas.test.cpp @@ -20,15 +20,19 @@ #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "src/buildtool/storage/config.hpp" +#include "src/buildtool/storage/storage.hpp" #include "test/utils/blob_creator.hpp" #include "test/utils/hermeticity/local.hpp" TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalCAS: Add blob to storage from bytes", "[storage]") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + std::string test_bytes("test"); - auto const& cas = Storage::Instance().CAS(); + auto const& cas = storage.CAS(); auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_bytes); // check blob not in storage @@ -73,10 +77,12 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalCAS: Add blob to storage from non-executable file", "[storage]") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + std::filesystem::path non_exec_file{ "test/buildtool/storage/data/non_executable_file"}; - auto const& cas = Storage::Instance().CAS(); + auto const& cas = storage.CAS(); auto test_blob = CreateBlobFromPath(non_exec_file); REQUIRE(test_blob); @@ -122,10 +128,12 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalCAS: Add blob to storage from executable file", "[storage]") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + std::filesystem::path exec_file{ "test/buildtool/storage/data/executable_file"}; - auto const& cas = Storage::Instance().CAS(); + auto const& cas = storage.CAS(); auto test_blob = CreateBlobFromPath(exec_file); REQUIRE(test_blob); |