TensorFlow Serving C++ API Documentation
aspired_version_policy_test.cc
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 #include "tensorflow_serving/core/aspired_version_policy.h"
16 
17 #include <vector>
18 
19 #include <gtest/gtest.h>
20 #include "absl/types/optional.h"
21 #include "tensorflow_serving/core/loader_harness.h"
22 #include "tensorflow_serving/core/servable_id.h"
23 
24 namespace tensorflow {
25 namespace serving {
26 
27 class AspiredVersionPolicyTest : public ::testing::Test {
28  public:
29  // Expose the protected AspiredVersionPolicy::GetHighestAspiredNewServableId()
30  // method.
31  absl::optional<ServableId> GetHighestAspiredNewServableId(
32  const std::vector<AspiredServableStateSnapshot>& all_versions) {
34  }
35 };
36 
37 TEST_F(AspiredVersionPolicyTest, NoHighestAspiredNewServableId) {
38  // No new aspired versions.
39  std::vector<AspiredServableStateSnapshot> versions;
40  versions.push_back({{"test", 10}, LoaderHarness::State::kNew, false});
41  versions.push_back({{"test", 9}, LoaderHarness::State::kUnloading, true});
42  absl::optional<ServableId> highest_aspired_new =
43  GetHighestAspiredNewServableId(versions);
44  ASSERT_FALSE(highest_aspired_new);
45 }
46 
47 TEST_F(AspiredVersionPolicyTest, HighestAspiredNewServableId) {
48  // Three new aspired versions and two other versions.
49  std::vector<AspiredServableStateSnapshot> versions;
50  versions.push_back({{"test", 10}, LoaderHarness::State::kNew, false});
51  versions.push_back({{"test", 9}, LoaderHarness::State::kUnloading, true});
52  versions.push_back({{"test", 1}, LoaderHarness::State::kNew, true});
53  versions.push_back({{"test", 5}, LoaderHarness::State::kNew, true});
54  versions.push_back({{"test", 3}, LoaderHarness::State::kNew, true});
55 
56  absl::optional<ServableId> highest_aspired_new =
57  GetHighestAspiredNewServableId(versions);
58  ASSERT_TRUE(highest_aspired_new);
59  EXPECT_EQ("test", highest_aspired_new.value().name);
60  EXPECT_EQ(5, highest_aspired_new.value().version);
61 }
62 
63 } // namespace serving
64 } // namespace tensorflow
static absl::optional< ServableId > GetHighestAspiredNewServableId(const std::vector< AspiredServableStateSnapshot > &all_versions)
@ kUnloading
'loader_->Unload()' has been called.