TensorFlow Serving C++ API Documentation
session_bundle_util_test.cc
1 /* Copyright 2019 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/session_bundle/session_bundle_util.h"
17 
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 #include "tensorflow/core/protobuf/meta_graph.pb.h"
21 #include "tensorflow_serving/test_util/test_util.h"
22 
23 namespace tensorflow {
24 namespace serving {
25 namespace session_bundle {
26 namespace {
27 
28 using ::testing::HasSubstr;
29 
30 const char kTestSavedModelPath[] =
31  "cc/saved_model/testdata/half_plus_two/00000123";
32 
33 const char kTestSessionBundleExportPath[] =
34  "session_bundle/testdata/half_plus_two/00000123";
35 
36 TEST(SessionBundleTest, ConvertSignaturesToSignatureDefsTest) {
37  MetaGraphDef meta_graph_def;
38  Status status = ConvertSignaturesToSignatureDefs(&meta_graph_def);
39  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
40  EXPECT_THAT(
41  status.ToString(),
42  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
43 }
44 
45 TEST(SessionBundleTest, ConvertSessionBundleToSavedModelBundleTest) {
46  SessionBundle session_bundle;
47  SavedModelBundle saved_model_bundle;
48  Status status = session_bundle::ConvertSessionBundleToSavedModelBundle(
49  session_bundle, &saved_model_bundle);
50  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
51  EXPECT_THAT(
52  status.ToString(),
53  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
54 }
55 
56 TEST(SessionBundleTest, LoadSessionBundleOrSavedModelBundleTest) {
57  SessionOptions session_options;
58  RunOptions run_options;
59  SavedModelBundle bundle;
60  bool is_session_bundle;
61  const std::unordered_set<string> tags = {"serve"};
62  const string export_dir =
63  test_util::TensorflowTestSrcDirPath(kTestSavedModelPath);
64 
65  Status status = session_bundle::LoadSessionBundleOrSavedModelBundle(
66  session_options, run_options, export_dir, tags, &bundle,
67  &is_session_bundle);
68  EXPECT_TRUE(status.ok());
69 }
70 
71 TEST(SessionBundleTest, LoadSessionBundleOrSavedModelBundleFailureTest) {
72  SessionOptions session_options;
73  RunOptions run_options;
74  SavedModelBundle bundle;
75  bool is_session_bundle;
76  const std::unordered_set<string> tags = {"serve"};
77  const string export_dir =
78  test_util::TestSrcDirPath(kTestSessionBundleExportPath);
79 
80  Status status = session_bundle::LoadSessionBundleOrSavedModelBundle(
81  session_options, run_options, export_dir, tags, &bundle,
82  &is_session_bundle);
83  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
84  EXPECT_THAT(
85  status.ToString(),
86  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
87 }
88 
89 TEST(SessionBundleTest, LoadSessionBundleFromPathUsingRunOptionsTest) {
90  SessionOptions session_options;
91  RunOptions run_options;
92  string export_dir = "/exort_dir";
93  SessionBundle bundle;
94  Status status = session_bundle::LoadSessionBundleFromPathUsingRunOptions(
95  session_options, run_options, export_dir, &bundle);
96  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
97  EXPECT_THAT(
98  status.ToString(),
99  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
100 }
101 
102 TEST(SessionBundleTest, SetSignaturesTest) {
103  Signatures signatures;
104  tensorflow::MetaGraphDef meta_graph_def;
105  Status status = session_bundle::SetSignatures(signatures, &meta_graph_def);
106  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
107  EXPECT_THAT(
108  status.ToString(),
109  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
110 }
111 
112 TEST(SessionBundleTest, GetClassificationSignatureTest) {
113  ClassificationSignature signature;
114  tensorflow::MetaGraphDef meta_graph_def;
115  Status status =
116  session_bundle::GetClassificationSignature(meta_graph_def, &signature);
117  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
118  EXPECT_THAT(
119  status.ToString(),
120  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
121 }
122 
123 TEST(SessionBundleTest, GetRegressionSignatureTest) {
124  RegressionSignature signature;
125  tensorflow::MetaGraphDef meta_graph_def;
126  Status status =
127  session_bundle::GetRegressionSignature(meta_graph_def, &signature);
128  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
129  EXPECT_THAT(
130  status.ToString(),
131  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
132 }
133 
134 TEST(SessionBundleTest, RunClassificationTest) {
135  ClassificationSignature signature;
136  Tensor input;
137  Session* session = nullptr;
138  Tensor classes;
139  Tensor scores;
140  Status status = session_bundle::RunClassification(signature, input, session,
141  &classes, &scores);
142  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
143  EXPECT_THAT(
144  status.ToString(),
145  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
146 }
147 
148 TEST(SessionBundleTest, RunRegressionTest) {
149  RegressionSignature signature;
150  Tensor input, output;
151  Session* session = nullptr;
152  Status status =
153  session_bundle::RunRegression(signature, input, session, &output);
154  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
155  EXPECT_THAT(
156  status.ToString(),
157  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
158 }
159 
160 TEST(SessionBundleTest, GetNamedSignature) {
161  const string name = "name";
162  const tensorflow::MetaGraphDef meta_graph_def;
163  Signature default_signature;
164  Status status = session_bundle::GetNamedSignature(name, meta_graph_def,
165  &default_signature);
166  EXPECT_EQ(::tensorflow::error::UNIMPLEMENTED, status.code());
167  EXPECT_THAT(
168  status.ToString(),
169  ::testing::HasSubstr("Session Bundle is deprecated and removed."));
170 }
171 
172 } // namespace
173 } // namespace session_bundle
174 } // namespace serving
175 } // namespace tensorflow