16 #include "tensorflow_serving/core/static_source_router.h"
23 #include <gmock/gmock.h>
24 #include <gtest/gtest.h>
25 #include "tensorflow/core/lib/core/status.h"
26 #include "tensorflow/core/lib/core/status_test_util.h"
27 #include "tensorflow/core/lib/core/stringpiece.h"
28 #include "tensorflow/core/platform/types.h"
29 #include "tensorflow_serving/core/servable_data.h"
30 #include "tensorflow_serving/core/source.h"
31 #include "tensorflow_serving/core/storage_path.h"
32 #include "tensorflow_serving/core/target.h"
33 #include "tensorflow_serving/core/test_util/mock_storage_path_target.h"
35 using ::testing::ElementsAre;
37 using ::testing::StrictMock;
39 namespace tensorflow {
43 TEST(StaticSourceRouterTest, Basic) {
44 const std::vector<string> regexps = {
"0th",
"1st"};
45 std::unique_ptr<StaticSourceRouter<StoragePath>> router;
46 TF_ASSERT_OK(StaticSourceRouter<string>::Create(regexps, &router));
47 std::vector<Source<StoragePath>*> output_ports = router->GetOutputPorts();
48 ASSERT_EQ(regexps.size() + 1, output_ports.size());
49 std::vector<std::unique_ptr<test_util::MockStoragePathTarget>> targets;
50 for (
int i = 0; i < output_ports.size(); ++i) {
51 std::unique_ptr<test_util::MockStoragePathTarget> target(
52 new StrictMock<test_util::MockStoragePathTarget>);
53 ConnectSourceToTarget(output_ports[i], target.get());
54 targets.push_back(std::move(target));
60 SetAspiredVersions(Eq(
"0th_foo"), ElementsAre(ServableData<StoragePath>(
61 {
"0th_foo", 7},
"data"))));
62 router->SetAspiredVersions(
63 "0th_foo", {ServableData<StoragePath>({
"0th_foo", 7},
"data")});
66 EXPECT_CALL(*targets[0],
67 SetAspiredVersions(Eq(
"0th_foo_1st"),
68 ElementsAre(ServableData<StoragePath>(
69 {
"0th_foo_1st", 7},
"data"))));
70 router->SetAspiredVersions(
71 "0th_foo_1st", {ServableData<StoragePath>({
"0th_foo_1st", 7},
"data")});
76 SetAspiredVersions(Eq(
"foo_1st"), ElementsAre(ServableData<StoragePath>(
77 {
"foo_1st", 7},
"data"))));
78 router->SetAspiredVersions(
79 "foo_1st", {ServableData<StoragePath>({
"foo_1st", 7},
"data")});
84 SetAspiredVersions(Eq(
"no_match"), ElementsAre(ServableData<StoragePath>(
85 {
"no_match", 7},
"data"))));
86 router->SetAspiredVersions(
87 "no_match", {ServableData<StoragePath>({
"no_match", 7},
"data")});