TensorFlow Serving C++ API Documentation
fake_storage_path_source_adapter.cc
1 /* Copyright 2016 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 #include "tensorflow_serving/core/test_util/fake_storage_path_source_adapter.h"
17 
18 #include <functional>
19 
20 #include "tensorflow/core/lib/core/errors.h"
21 
22 namespace tensorflow {
23 namespace serving {
24 namespace test_util {
25 
26 FakeStoragePathSourceAdapter::FakeStoragePathSourceAdapter(
27  const string& suffix, std::function<void(const string&)> call_on_destruct)
28  : suffix_(suffix), call_on_destruct_(call_on_destruct) {}
29 
30 FakeStoragePathSourceAdapter::~FakeStoragePathSourceAdapter() {
31  Detach();
32  if (call_on_destruct_) {
33  call_on_destruct_(suffix_);
34  }
35 }
36 
37 Status FakeStoragePathSourceAdapter::Convert(
38  const StoragePath& data, StoragePath* const converted_data) {
39  if (data == "invalid") {
40  return errors::InvalidArgument(
41  "FakeStoragePathSourceAdapter Convert() dutifully failing on "
42  "\"invalid\" "
43  "data");
44  }
45  *converted_data =
46  suffix_.empty() ? data : strings::StrCat(data, "/", suffix_);
47  return Status();
48 }
49 
50 } // namespace test_util
51 } // namespace serving
52 } // namespace tensorflow