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
21
22#include "query/query_factory.h"
23#include <gtest/gtest.h>
24
25
26using namespace proxima::be::query;
27
28using QueryRequest = proxima::be::proto::QueryRequest;
29using QueryResponse = proxima::be::proto::QueryResponse;
30using GetDocumentRequest = proxima::be::proto::GetDocumentRequest;
31using GetDocumentResponse = proxima::be::proto::GetDocumentResponse;
32
33TEST(QueryBuilerTest, TestDummyQuery) {
34 QueryRequest request;
35 request.set_query_type(
36 proxima::be::proto::
37 QueryRequest_QueryType_QueryRequest_QueryType_INT_MIN_SENTINEL_DO_NOT_USE_);
38
39 // Dummy query
40 auto query = QueryFactory::Create(&request, nullptr, nullptr, nullptr,
41 nullptr, nullptr);
42
43 EXPECT_EQ(query->mode(), IOMode::READONLY);
44 EXPECT_EQ(query->type(), QueryType::UNDEFINED);
45
46 EXPECT_TRUE(query->validate() != 0);
47 EXPECT_TRUE(query->prepare() != 0);
48 EXPECT_TRUE(query->evaluate() != 0);
49 EXPECT_TRUE(query->finalize() != 0);
50}
51
52TEST(QueryBuilerTest, TestValidQuery) {
53 {
54 QueryRequest request;
55 request.set_query_type(proxima::be::proto::QueryRequest_QueryType_QT_KNN);
56 // KNN query
57 auto query = QueryFactory::Create(&request, nullptr, nullptr, nullptr,
58 nullptr, nullptr);
59 EXPECT_EQ(query->mode(), IOMode::READONLY);
60 EXPECT_EQ(query->type(), QueryType::KNN);
61 EXPECT_EQ(query->id(), 1);
62 }
63
64 {
65 GetDocumentRequest request;
66 // Equal query
67 auto query = QueryFactory::Create(&request, nullptr, nullptr, nullptr,
68 nullptr, nullptr);
69 EXPECT_EQ(query->mode(), IOMode::READONLY);
70 EXPECT_EQ(query->type(), QueryType::EQUAL);
71 EXPECT_EQ(query->id(), 2);
72 }
73}