TensorFlow Serving C++ API Documentation
mock_request_logger.h
1 /* Copyright 2017 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_REQUEST_LOGGER_H_
17 #define TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_REQUEST_LOGGER_H_
18 
19 #include <vector>
20 
21 #include "google/protobuf/message.h"
22 #include <gmock/gmock.h>
23 #include "tensorflow/core/lib/core/status.h"
24 #include "tensorflow_serving/apis/logging.pb.h"
25 #include "tensorflow_serving/config/logging_config.pb.h"
26 #include "tensorflow_serving/core/log_collector.h"
27 #include "tensorflow_serving/core/request_logger.h"
28 
29 namespace tensorflow {
30 namespace serving {
31 
33  public:
34  // Unfortunately NiceMock doesn't support ctors with move-only types, so we
35  // have to do this workaround.
36  MockRequestLogger(const LoggingConfig& logging_config,
37  const std::vector<string>& saved_model_tags,
38  LogCollector* log_collector,
39  std::function<void(void)> notify_destruction =
40  std::function<void(void)>())
41  : RequestLogger(logging_config, saved_model_tags,
42  std::unique_ptr<LogCollector>(log_collector)),
43  notify_destruction_(std::move(notify_destruction)) {}
44 
45  virtual ~MockRequestLogger() {
46  if (notify_destruction_) {
47  notify_destruction_();
48  }
49  }
50 
51  MOCK_METHOD(Status, CreateLogMessage,
52  (const google::protobuf::Message& request, const google::protobuf::Message& response,
53  const LogMetadata& log_metadata,
54  std::unique_ptr<google::protobuf::Message>* log),
55  (override));
56 
57  MOCK_METHOD(LogMetadata, FillLogMetadata, (const LogMetadata&), (override));
58 
59  private:
60  std::function<void(void)> notify_destruction_;
61 };
62 
63 } // namespace serving
64 } // namespace tensorflow
65 
66 #endif // TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_REQUEST_LOGGER_H_