17 #ifndef TENSORFLOW_SERVING_MODEL_SERVERS_TEST_UTIL_MOCK_SERVER_CORE_H_
18 #define TENSORFLOW_SERVING_MODEL_SERVERS_TEST_UTIL_MOCK_SERVER_CORE_H_
24 #include "google/protobuf/any.pb.h"
25 #include "google/protobuf/map.h"
26 #include <gmock/gmock.h>
27 #include "absl/status/status.h"
28 #include "tensorflow/core/lib/core/status.h"
29 #include "tensorflow/core/platform/logging.h"
30 #include "tensorflow_serving/apis/logging.proto.h"
31 #include "tensorflow_serving/apis/model.pb.h"
32 #include "tensorflow_serving/config/model_server_config.pb.h"
33 #include "tensorflow_serving/config/platform_config.pb.h"
34 #include "tensorflow_serving/core/aspired_versions_manager.h"
35 #include "tensorflow_serving/core/servable_handle.h"
36 #include "tensorflow_serving/core/servable_id.h"
37 #include "tensorflow_serving/core/servable_state.h"
38 #include "tensorflow_serving/core/servable_state_monitor.h"
39 #include "tensorflow_serving/core/server_request_logger.h"
40 #include "tensorflow_serving/core/test_util/fake_loader_source_adapter.pb.h"
41 #include "tensorflow_serving/core/test_util/servable_handle_test_util.h"
42 #include "tensorflow_serving/model_servers/server_core.h"
43 #include "tensorflow_serving/servables/tensorflow/servable.h"
44 #include "tensorflow_serving/util/event_bus.h"
45 #include "tensorflow_serving/util/unique_ptr_with_deps.h"
47 namespace tensorflow {
54 static PlatformConfigMap CreateFakeLoaderPlatformConfigMap() {
55 ::google::protobuf::Any source_adapter_config;
56 source_adapter_config.PackFrom(test_util::FakeLoaderSourceAdapterConfig());
57 PlatformConfigMap platform_config_map;
58 (*(*platform_config_map.mutable_platform_configs())[
"fake_servable"]
59 .mutable_source_adapter_config()) = source_adapter_config;
60 return platform_config_map;
64 const PlatformConfigMap& platform_config_map,
65 std::unique_ptr<ServerRequestLogger> server_request_logger) {
67 options.platform_config_map = platform_config_map;
68 options.servable_state_monitor_creator =
70 std::unique_ptr<ServableStateMonitor>* monitor) -> Status {
74 options.custom_model_config_loader =
75 [](const ::google::protobuf::Any& any,
80 if (server_request_logger !=
nullptr) {
81 options.server_request_logger = std::move(server_request_logger);
84 ServerRequestLogger::Create(
nullptr, &options.server_request_logger));
89 explicit MockServerCore(
const PlatformConfigMap& platform_config_map)
93 std::unique_ptr<ServerRequestLogger> server_request_logger)
95 std::move(server_request_logger))) {}
99 MOCK_METHOD(Status,
ReloadConfig, (
const ModelServerConfig&), (
override));
100 MOCK_METHOD(Status,
Log,
101 (
const google::protobuf::Message& request,
const google::protobuf::Message& response,
102 const LogMetadata& log_metadata),
106 void SetServable(std::unique_ptr<Servable> servable) {
107 servable_ = std::move(servable);
110 template <
typename T>
111 Status GetServableHandle(
const ModelSpec& model_spec,
113 LOG(FATAL) <<
"Not implemented.";
118 virtual Status GetServableHandle(
119 const ModelSpec& model_spec,
123 *handle = WrapAsHandle<Servable>(
id, servable_.get());
124 return absl::OkStatus();
126 return ServerCore::GetServableHandle<Servable>(model_spec, handle);
130 std::unique_ptr<Servable> servable_;
virtual Status Log(const google::protobuf::Message &request, const google::protobuf::Message &response, const LogMetadata &log_metadata)
virtual Status ReloadConfig(const ModelServerConfig &config) TF_LOCKS_EXCLUDED(config_mu_)
virtual ServableStateMonitor * servable_state_monitor() const
Returns ServableStateMonitor that can be used to query servable states.
Options for configuring a ServerCore object.