1 | /** |
2 | * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | * |
16 | * \author guonix |
17 | * \date Dec 2020 |
18 | * \brief |
19 | */ |
20 | #pragma once |
21 | |
22 | #include <gmock/gmock.h> |
23 | #include "index/index_service.h" |
24 | |
25 | using namespace proxima::be; |
26 | using namespace proxima::be::index; |
27 | using namespace ::testing; // import ::testing::* |
28 | |
29 | //! Mock IndexService |
30 | class MockIndexService : public IndexService { |
31 | public: |
32 | ~MockIndexService() = default; |
33 | |
34 | public: |
35 | //! Create collection with schema |
36 | MOCK_METHOD(int, create_collection, |
37 | (const std::string &collection_name, |
38 | const meta::CollectionMetaPtr &schema), |
39 | (override)); |
40 | |
41 | //! Drop collection by name |
42 | MOCK_METHOD(int, drop_collection, (const std::string &collection_name), |
43 | (override)); |
44 | |
45 | //! Update collection schema |
46 | MOCK_METHOD(int, update_collection, |
47 | (const std::string &collection_name, |
48 | const meta::CollectionMetaPtr &new_schema), |
49 | (override)); |
50 | |
51 | //! Check if collection exist |
52 | MOCK_METHOD(bool, has_collection, (const std::string &collection_name), |
53 | (override)); |
54 | |
55 | //! Load collections from storage |
56 | MOCK_METHOD(int, load_collections, |
57 | (const std::vector<std::string> &collection_names, |
58 | const std::vector<meta::CollectionMetaPtr> &schemas), |
59 | (override)); |
60 | |
61 | //! List all collection names |
62 | MOCK_METHOD(int, list_collections, |
63 | (std::vector<std::string> * collection_names), (override)); |
64 | |
65 | //! List all collection segments |
66 | MOCK_METHOD(int, list_segments, |
67 | (const std::string &collection_name, |
68 | std::vector<SegmentPtr> *segments), |
69 | (override)); |
70 | |
71 | //! Get collection latest lsn |
72 | MOCK_METHOD(int, get_latest_lsn, |
73 | (const std::string &collection_name, uint64_t *lsn, |
74 | std::string *lsn_context), |
75 | (override)); |
76 | |
77 | //! Write records to some collection |
78 | MOCK_METHOD(int, write_records, |
79 | (const std::string &collection_name, |
80 | const CollectionDatasetPtr &records), |
81 | (override)); |
82 | |
83 | protected: |
84 | //! Initialize inner members |
85 | MOCK_METHOD(int, init_impl, (), (override)); |
86 | |
87 | //! Cleanup and destroy objects |
88 | MOCK_METHOD(int, cleanup_impl, (), (override)); |
89 | |
90 | //! Start worker thread |
91 | MOCK_METHOD(int, start_impl, (), (override)); |
92 | |
93 | //! Stop worker thread |
94 | MOCK_METHOD(int, stop_impl, (), (override)); |
95 | }; |
96 | |
97 | using MockIndexServicePtr = std::shared_ptr<MockIndexService>; |
98 | |