-
Notifications
You must be signed in to change notification settings - Fork 7k
[core] Refactor ActorInfoAccessor in gcs_client so as to be mockable #57241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dcbb476
Refactor ActorInfoAccessor in gcs_client so as to be mockable
ZacAttack c987a87
address robot feedback
ZacAttack 9497b5c
address comments from bots
ZacAttack 637ad1a
Merge branch 'master' into actor_info_accessor
ZacAttack ce54a48
address comments by adding build targets
ZacAttack 3c56db9
address comments
ZacAttack ee69fa4
Merge branch 'master' into actor_info_accessor
ZacAttack 3292d2d
Remove mock (yay!)
ZacAttack 170cbaa
move gcsGcsTimeout
ZacAttack 8903a12
move client_utils
ZacAttack ee9c348
Merge branch 'master' into actor_info_accessor
ZacAttack 5a58760
Merge branch 'master' into actor_info_accessor
ZacAttack f596e2b
fix method declaration
ZacAttack ef6c4de
update mock
ZacAttack fee13b2
break up build targets
ZacAttack 1a5efaf
address comments
ZacAttack 0b0b9ea
Merge branch 'master' into actor_info_accessor
ZacAttack 4c875a7
address comments and remove that parameterless constructor.
ZacAttack d94b831
update 2017->2025
ZacAttack c5ddc1d
appease bot
ZacAttack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/mock/ray/gcs_client/accessors/actor_info_accessor.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // Copyright 2025 The Ray Authors. | ||
| // | ||
| // 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 | ||
|
|
||
| #include "absl/container/flat_hash_map.h" | ||
| #include "ray/common/id.h" | ||
| #include "ray/common/status.h" | ||
| #include "ray/common/task/task_spec.h" | ||
| #include "ray/gcs_rpc_client/accessors/actor_info_accessor_interface.h" | ||
| #include "src/ray/protobuf/gcs.pb.h" | ||
|
|
||
| namespace ray { | ||
| namespace gcs { | ||
|
|
||
| class FakeActorInfoAccessor : public gcs::ActorInfoAccessorInterface { | ||
| public: | ||
| FakeActorInfoAccessor() = default; | ||
|
|
||
| ~FakeActorInfoAccessor() {} | ||
|
|
||
| // Stub implementations for interface methods not used by this test | ||
| void AsyncGet(const ActorID &, | ||
| const gcs::OptionalItemCallback<rpc::ActorTableData> &) override {} | ||
| void AsyncGetAllByFilter(const std::optional<ActorID> &, | ||
| const std::optional<JobID> &, | ||
| const std::optional<std::string> &, | ||
| const gcs::MultiItemCallback<rpc::ActorTableData> &, | ||
| int64_t = -1) override {} | ||
| void AsyncGetByName(const std::string &, | ||
| const std::string &, | ||
| const gcs::OptionalItemCallback<rpc::ActorTableData> &, | ||
| int64_t = -1) override {} | ||
| Status SyncGetByName(const std::string &, | ||
| const std::string &, | ||
| rpc::ActorTableData &, | ||
| rpc::TaskSpec &) override { | ||
| return Status::OK(); | ||
| } | ||
| Status SyncListNamedActors( | ||
| bool, | ||
| const std::string &, | ||
| std::vector<std::pair<std::string, std::string>> &) override { | ||
| return Status::OK(); | ||
| } | ||
| void AsyncReportActorOutOfScope(const ActorID &, | ||
| uint64_t, | ||
| const gcs::StatusCallback &, | ||
| int64_t = -1) override {} | ||
| void AsyncRegisterActor(const TaskSpecification &task_spec, | ||
| const gcs::StatusCallback &callback, | ||
| int64_t = -1) override { | ||
| async_register_actor_callback_ = callback; | ||
| } | ||
| void AsyncRestartActorForLineageReconstruction(const ActorID &, | ||
| uint64_t, | ||
| const gcs::StatusCallback &, | ||
| int64_t = -1) override {} | ||
| Status SyncRegisterActor(const TaskSpecification &) override { return Status::OK(); } | ||
| void AsyncKillActor( | ||
| const ActorID &, bool, bool, const gcs::StatusCallback &, int64_t = -1) override {} | ||
| void AsyncCreateActor( | ||
| const TaskSpecification &task_spec, | ||
| const rpc::ClientCallback<rpc::CreateActorReply> &callback) override { | ||
| async_create_actor_callback_ = callback; | ||
| } | ||
|
|
||
| void AsyncSubscribe( | ||
| const ActorID &actor_id, | ||
| const gcs::SubscribeCallback<ActorID, rpc::ActorTableData> &subscribe, | ||
| const gcs::StatusCallback &done) override { | ||
| auto callback_entry = std::make_pair(actor_id, subscribe); | ||
| callback_map_.emplace(actor_id, subscribe); | ||
| subscribe_finished_callback_map_[actor_id] = done; | ||
| actor_subscribed_times_[actor_id]++; | ||
| } | ||
|
|
||
| void AsyncUnsubscribe(const ActorID &) override {} | ||
| void AsyncResubscribe() override {} | ||
| bool IsActorUnsubscribed(const ActorID &) override { return false; } | ||
|
|
||
| bool ActorStateNotificationPublished(const ActorID &actor_id, | ||
| const rpc::ActorTableData &actor_data) { | ||
| auto it = callback_map_.find(actor_id); | ||
| if (it == callback_map_.end()) return false; | ||
| auto actor_state_notification_callback = it->second; | ||
| auto copied = actor_data; | ||
| actor_state_notification_callback(actor_id, std::move(copied)); | ||
| return true; | ||
| } | ||
|
|
||
| bool CheckSubscriptionRequested(const ActorID &actor_id) { | ||
| return callback_map_.find(actor_id) != callback_map_.end(); | ||
| } | ||
|
|
||
| // Mock the logic of subscribe finished. see `ActorInfoAccessor::AsyncSubscribe` | ||
| bool ActorSubscribeFinished(const ActorID &actor_id, | ||
| const rpc::ActorTableData &actor_data) { | ||
| auto subscribe_finished_callback_it = subscribe_finished_callback_map_.find(actor_id); | ||
| if (subscribe_finished_callback_it == subscribe_finished_callback_map_.end()) { | ||
| return false; | ||
| } | ||
|
|
||
| auto copied = actor_data; | ||
| if (!ActorStateNotificationPublished(actor_id, std::move(copied))) { | ||
| return false; | ||
| } | ||
|
|
||
| auto subscribe_finished_callback = subscribe_finished_callback_it->second; | ||
| subscribe_finished_callback(Status::OK()); | ||
| // Erase callback when actor subscribe is finished. | ||
| subscribe_finished_callback_map_.erase(subscribe_finished_callback_it); | ||
| return true; | ||
| } | ||
|
|
||
| absl::flat_hash_map<ActorID, gcs::SubscribeCallback<ActorID, rpc::ActorTableData>> | ||
| callback_map_; | ||
| absl::flat_hash_map<ActorID, gcs::StatusCallback> subscribe_finished_callback_map_; | ||
| absl::flat_hash_map<ActorID, uint32_t> actor_subscribed_times_; | ||
|
|
||
| // Callbacks for AsyncCreateActor and AsyncRegisterActor | ||
| rpc::ClientCallback<rpc::CreateActorReply> async_create_actor_callback_; | ||
| gcs::StatusCallback async_register_actor_callback_; | ||
| }; | ||
|
|
||
| } // namespace gcs | ||
| } // namespace ray |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.