From 3dc230bfc1854d211c44eab318831513d127a71c Mon Sep 17 00:00:00 2001 From: Eric Hughes Date: Thu, 5 Sep 2024 06:58:21 -0600 Subject: [PATCH] Changed resources() to a const accessor --- tiledb/sm/consolidator/consolidator.h | 2 +- .../array_dimension_label_queries.h | 2 +- tiledb/sm/query/query.h | 2 +- tiledb/sm/storage_manager/context.h | 2 +- tiledb/sm/storage_manager/job.h | 2 +- tiledb/sm/storage_manager/test/unit_job.cc | 27 +++++++++++++------ 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/tiledb/sm/consolidator/consolidator.h b/tiledb/sm/consolidator/consolidator.h index 76c8cc3288f..9773709e57f 100644 --- a/tiledb/sm/consolidator/consolidator.h +++ b/tiledb/sm/consolidator/consolidator.h @@ -235,7 +235,7 @@ class Consolidator : public JobBranch { /** * Derived from `JobBranch` */ - ContextResources& resources() override { + ContextResources& resources() const override { return resources_; } diff --git a/tiledb/sm/query/dimension_label/array_dimension_label_queries.h b/tiledb/sm/query/dimension_label/array_dimension_label_queries.h index a5f8c59aece..d9d6008be92 100644 --- a/tiledb/sm/query/dimension_label/array_dimension_label_queries.h +++ b/tiledb/sm/query/dimension_label/array_dimension_label_queries.h @@ -250,7 +250,7 @@ class ArrayDimensionLabelQueries : public JobBranch { /** * Derived from `JobBranch` */ - ContextResources& resources() override { + ContextResources& resources() const override { return resources_; } }; diff --git a/tiledb/sm/query/query.h b/tiledb/sm/query/query.h index b4547bb3c88..a44ecc1e758 100644 --- a/tiledb/sm/query/query.h +++ b/tiledb/sm/query/query.h @@ -1197,7 +1197,7 @@ class Query : public JobBranch { /** * Derived from `JobBranch` */ - ContextResources& resources() override { + ContextResources& resources() const override { return resources_; } }; diff --git a/tiledb/sm/storage_manager/context.h b/tiledb/sm/storage_manager/context.h index efb61adf6b3..539926ea1c6 100644 --- a/tiledb/sm/storage_manager/context.h +++ b/tiledb/sm/storage_manager/context.h @@ -165,7 +165,7 @@ class Context : public ContextBase, public JobRoot { /** * Derived from `JobRoot` */ - [[nodiscard]] ContextResources& resources() override { + [[nodiscard]] ContextResources& resources() const override { return resources_; } diff --git a/tiledb/sm/storage_manager/job.h b/tiledb/sm/storage_manager/job.h index b95ca216b68..05e87d2e5dd 100644 --- a/tiledb/sm/storage_manager/job.h +++ b/tiledb/sm/storage_manager/job.h @@ -157,7 +157,7 @@ struct JobResourceMixin { * Each class derived from `Parent` implements its own resources accessor. * Typically this accessor will simply return its own member variable. */ - [[nodiscard]] virtual ContextResources& resources() = 0; + [[nodiscard]] virtual ContextResources& resources() const = 0; /** * Factory for cancellation source objects that are tied to the cancellation diff --git a/tiledb/sm/storage_manager/test/unit_job.cc b/tiledb/sm/storage_manager/test/unit_job.cc index 27a24b9ebce..8f5b1925f6c 100644 --- a/tiledb/sm/storage_manager/test/unit_job.cc +++ b/tiledb/sm/storage_manager/test/unit_job.cc @@ -232,18 +232,24 @@ TEST_CASE("job::Child - construct and size") { CHECK(jf.context_.number_of_jobs() == 0); } -class TestJobRoot : public JobRoot { + +class TestJobRootBase { + protected: Config config_{}; - ContextResources resources_{ + mutable ContextResources resources_{ config_, std::make_shared("log"), 1, 1, ""}; StorageManager sm_{resources_, config_}; + TestJobRootBase() = default; +}; +class TestJobRoot : protected TestJobRootBase, public JobRoot { + using Base = TestJobRootBase; public: TestJobRoot() - : JobRoot(sm_) { + : TestJobRootBase(), JobRoot(Base::sm_) { } - ContextResources& resources() override { - return resources_; + ContextResources& resources() const override { + return Base::resources_; } }; static_assert(TestJobRoot::is_parent); @@ -258,7 +264,7 @@ class TestJobBranch : public JobBranch { TestJobBranch(JobParent& parent) : JobBranch(parent) { } - ContextResources& resources() override { + ContextResources& resources() const override { return parent().resources(); } }; @@ -297,15 +303,20 @@ TEST_CASE("TestJobLeaf - construct from branch") { TestJobLeaf leaf{branch}; } -class TestJobIsolate : public JobIsolate { +class TestJobIsolateBase { + protected: Config config_{}; ContextResources resources_{ config_, std::make_shared("log"), 1, 1, ""}; StorageManager sm_{resources_, config_}; + TestJobIsolateBase() = default; +}; +class TestJobIsolate : protected TestJobIsolateBase, public JobIsolate { + using Base = TestJobIsolateBase; public: TestJobIsolate() - : JobIsolate(sm_) { + : TestJobIsolateBase(), JobIsolate(Base::sm_) { } }; static_assert(!TestJobIsolate::is_parent);