test_rpc.cpp 18.9 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

Y
Yu Kun 已提交
18 19
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
Y
youny626 已提交
20
#include <thread>
Y
Yu Kun 已提交
21 22 23 24

#include "server/Server.h"
#include "server/grpc_impl/GrpcRequestHandler.h"
#include "server/grpc_impl/GrpcRequestScheduler.h"
G
groot 已提交
25
#include "server/grpc_impl/request/GrpcBaseRequest.h"
G
groot 已提交
26
#include "src/version.h"
Y
Yu Kun 已提交
27 28 29 30 31

#include "grpc/gen-milvus/milvus.grpc.pb.h"
#include "grpc/gen-status/status.pb.h"

#include "scheduler/ResourceFactory.h"
Y
youny626 已提交
32 33 34
#include "scheduler/SchedInst.h"
#include "server/Config.h"
#include "server/DBWrapper.h"
Y
Yu Kun 已提交
35 36
#include "utils/CommonUtil.h"

S
starlord 已提交
37
namespace {
Y
Yu Kun 已提交
38

S
starlord 已提交
39
static const char* TABLE_NAME = "test_grpc";
Y
Yu Kun 已提交
40 41
static constexpr int64_t TABLE_DIM = 256;
static constexpr int64_t INDEX_FILE_SIZE = 1024;
Y
Yu Kun 已提交
42
static constexpr int64_t VECTOR_COUNT = 1000;
Y
Yu Kun 已提交
43 44 45
static constexpr int64_t INSERT_LOOP = 10;
constexpr int64_t SECONDS_EACH_HOUR = 3600;

G
groot 已提交
46 47 48 49 50 51
void CopyRowRecord(::milvus::grpc::RowRecord* target, const std::vector<float>& src) {
    auto vector_data = target->mutable_vector_data();
    vector_data->Resize(static_cast<int>(src.size()), 0.0);
    memcpy(vector_data->mutable_data(), src.data(), src.size()* sizeof(float));
}

Y
Yu Kun 已提交
52 53 54 55
class RpcHandlerTest : public testing::Test {
 protected:
    void
    SetUp() override {
S
starlord 已提交
56
        auto res_mgr = milvus::scheduler::ResMgrInst::GetInstance();
Y
Yu Kun 已提交
57
        res_mgr->Clear();
S
starlord 已提交
58 59 60
        res_mgr->Add(milvus::scheduler::ResourceFactory::Create("disk", "DISK", 0, true, false));
        res_mgr->Add(milvus::scheduler::ResourceFactory::Create("cpu", "CPU", 0, true, true));
        res_mgr->Add(milvus::scheduler::ResourceFactory::Create("gtx1660", "GPU", 0, true, true));
Y
Yu Kun 已提交
61

S
starlord 已提交
62 63
        auto default_conn = milvus::scheduler::Connection("IO", 500.0);
        auto PCIE = milvus::scheduler::Connection("IO", 11000.0);
Y
Yu Kun 已提交
64 65 66
        res_mgr->Connect("disk", "cpu", default_conn);
        res_mgr->Connect("cpu", "gtx1660", PCIE);
        res_mgr->Start();
S
starlord 已提交
67 68
        milvus::scheduler::SchedInst::GetInstance()->Start();
        milvus::scheduler::JobMgrInst::GetInstance()->Start();
Y
Yu Kun 已提交
69

S
starlord 已提交
70
        milvus::engine::DBOptions opt;
Y
Yu Kun 已提交
71

S
starlord 已提交
72 73 74 75 76 77 78
        milvus::server::Config::GetInstance().SetDBConfigBackendUrl("sqlite://:@:/");
        milvus::server::Config::GetInstance().SetDBConfigPrimaryPath("/tmp/milvus_test");
        milvus::server::Config::GetInstance().SetDBConfigSecondaryPath("");
        milvus::server::Config::GetInstance().SetDBConfigArchiveDiskThreshold("");
        milvus::server::Config::GetInstance().SetDBConfigArchiveDaysThreshold("");
        milvus::server::Config::GetInstance().SetCacheConfigCacheInsertData("");
        milvus::server::Config::GetInstance().SetEngineConfigOmpThreadNum("");
Y
Yu Kun 已提交
79

Y
youny626 已提交
80 81 82 83 84 85 86
        //        serverConfig.SetValue(server::CONFIG_CLUSTER_MODE, "cluster");
        //        DBWrapper::GetInstance().GetInstance().StartService();
        //        DBWrapper::GetInstance().GetInstance().StopService();
        //
        //        serverConfig.SetValue(server::CONFIG_CLUSTER_MODE, "read_only");
        //        DBWrapper::GetInstance().GetInstance().StartService();
        //        DBWrapper::GetInstance().GetInstance().StopService();
Y
Yu Kun 已提交
87

S
starlord 已提交
88
        milvus::server::DBWrapper::GetInstance().StartService();
Y
Yu Kun 已提交
89

Y
youny626 已提交
90
        // initialize handler, create table
S
starlord 已提交
91
        handler = std::make_shared<milvus::server::grpc::GrpcRequestHandler>();
Y
Yu Kun 已提交
92 93
        ::grpc::ServerContext context;
        ::milvus::grpc::TableSchema request;
Y
Yu Kun 已提交
94
        ::milvus::grpc::Status status;
Y
Yu Kun 已提交
95
        request.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
96 97 98 99 100 101 102 103
        request.set_dimension(TABLE_DIM);
        request.set_index_file_size(INDEX_FILE_SIZE);
        request.set_metric_type(1);
        ::grpc::Status grpc_status = handler->CreateTable(&context, &request, &status);
    }

    void
    TearDown() override {
S
starlord 已提交
104 105 106 107
        milvus::server::DBWrapper::GetInstance().StopService();
        milvus::scheduler::JobMgrInst::GetInstance()->Stop();
        milvus::scheduler::ResMgrInst::GetInstance()->Stop();
        milvus::scheduler::SchedInst::GetInstance()->Stop();
Y
Yu Kun 已提交
108 109
        boost::filesystem::remove_all("/tmp/milvus_test");
    }
S
starlord 已提交
110

Y
Yu Kun 已提交
111
 protected:
S
starlord 已提交
112
    std::shared_ptr<milvus::server::grpc::GrpcRequestHandler> handler;
Y
Yu Kun 已提交
113 114
};

S
starlord 已提交
115
void
Y
youny626 已提交
116
BuildVectors(int64_t from, int64_t to, std::vector<std::vector<float>>& vector_record_array) {
Y
Yu Kun 已提交
117 118 119 120 121 122 123 124 125
    if (to <= from) {
        return;
    }

    vector_record_array.clear();
    for (int64_t k = from; k < to; k++) {
        std::vector<float> record;
        record.resize(TABLE_DIM);
        for (int64_t i = 0; i < TABLE_DIM; i++) {
S
starlord 已提交
126
            record[i] = (float)(k % (i + 1));
Y
Yu Kun 已提交
127 128 129 130 131 132
        }

        vector_record_array.emplace_back(record);
    }
}

S
starlord 已提交
133 134
std::string
CurrentTmDate(int64_t offset_day = 0) {
Y
Yu Kun 已提交
135 136 137 138
    time_t tt;
    time(&tt);
    tt = tt + 8 * SECONDS_EACH_HOUR;
    tt = tt + 24 * SECONDS_EACH_HOUR * offset_day;
S
starlord 已提交
139 140
    tm t;
    gmtime_r(&tt, &t);
Y
Yu Kun 已提交
141

Y
youny626 已提交
142 143
    std::string str =
        std::to_string(t.tm_year + 1900) + "-" + std::to_string(t.tm_mon + 1) + "-" + std::to_string(t.tm_mday);
Y
Yu Kun 已提交
144 145 146

    return str;
}
S
starlord 已提交
147

Y
youny626 已提交
148
}  // namespace
Y
Yu Kun 已提交
149

S
starlord 已提交
150
TEST_F(RpcHandlerTest, HAS_TABLE_TEST) {
Y
Yu Kun 已提交
151 152 153 154
    ::grpc::ServerContext context;
    ::milvus::grpc::TableName request;
    ::milvus::grpc::BoolReply reply;
    ::grpc::Status status = handler->HasTable(&context, &request, &reply);
Y
Yu Kun 已提交
155 156
    request.set_table_name(TABLE_NAME);
    status = handler->HasTable(&context, &request, &reply);
Y
Yu Kun 已提交
157 158 159 160 161
    ASSERT_TRUE(status.error_code() == ::grpc::Status::OK.error_code());
    int error_code = reply.status().error_code();
    ASSERT_EQ(error_code, ::milvus::grpc::ErrorCode::SUCCESS);
}

S
starlord 已提交
162
TEST_F(RpcHandlerTest, INDEX_TEST) {
Y
Yu Kun 已提交
163 164 165
    ::grpc::ServerContext context;
    ::milvus::grpc::IndexParam request;
    ::milvus::grpc::Status response;
Y
Yu Kun 已提交
166
    ::grpc::Status grpc_status = handler->CreateIndex(&context, &request, &response);
Y
Yu Kun 已提交
167
    request.set_table_name("test1");
Y
Yu Kun 已提交
168 169
    handler->CreateIndex(&context, &request, &response);

Y
Yu Kun 已提交
170
    request.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
171 172
    handler->CreateIndex(&context, &request, &response);

Y
Yu Kun 已提交
173
    request.mutable_index()->set_index_type(1);
Y
Yu Kun 已提交
174 175
    handler->CreateIndex(&context, &request, &response);

Y
Yu Kun 已提交
176
    request.mutable_index()->set_nlist(16384);
Y
Yu Kun 已提交
177
    grpc_status = handler->CreateIndex(&context, &request, &response);
Y
Yu Kun 已提交
178 179
    ASSERT_EQ(grpc_status.error_code(), ::grpc::Status::OK.error_code());
    int error_code = response.error_code();
Y
youny626 已提交
180
    //    ASSERT_EQ(error_code, ::milvus::grpc::ErrorCode::SUCCESS);
Y
Yu Kun 已提交
181 182 183 184

    ::milvus::grpc::TableName table_name;
    ::milvus::grpc::IndexParam index_param;
    handler->DescribeIndex(&context, &table_name, &index_param);
Y
Yu Kun 已提交
185 186 187 188
    table_name.set_table_name("test4");
    handler->DescribeIndex(&context, &table_name, &index_param);
    table_name.set_table_name(TABLE_NAME);
    handler->DescribeIndex(&context, &table_name, &index_param);
Y
Yu Kun 已提交
189
    ::milvus::grpc::Status status;
Y
Yu Kun 已提交
190 191 192 193 194
    table_name.Clear();
    handler->DropIndex(&context, &table_name, &status);
    table_name.set_table_name("test5");
    handler->DropIndex(&context, &table_name, &status);
    table_name.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
195 196 197
    handler->DropIndex(&context, &table_name, &status);
}

S
starlord 已提交
198
TEST_F(RpcHandlerTest, INSERT_TEST) {
Y
Yu Kun 已提交
199 200 201
    ::grpc::ServerContext context;
    ::milvus::grpc::InsertParam request;
    ::milvus::grpc::Status response;
Y
Yu Kun 已提交
202

Y
Yu Kun 已提交
203 204 205 206
    request.set_table_name(TABLE_NAME);
    std::vector<std::vector<float>> record_array;
    BuildVectors(0, VECTOR_COUNT, record_array);
    ::milvus::grpc::VectorIds vector_ids;
S
starlord 已提交
207 208
    for (auto& record : record_array) {
        ::milvus::grpc::RowRecord* grpc_record = request.add_row_record_array();
G
groot 已提交
209
        CopyRowRecord(grpc_record, record);
Y
Yu Kun 已提交
210 211 212 213 214
    }
    handler->Insert(&context, &request, &vector_ids);
    ASSERT_EQ(vector_ids.vector_id_array_size(), VECTOR_COUNT);
}

S
starlord 已提交
215
TEST_F(RpcHandlerTest, SEARCH_TEST) {
Y
Yu Kun 已提交
216 217
    ::grpc::ServerContext context;
    ::milvus::grpc::SearchParam request;
218
    ::milvus::grpc::TopKQueryResult response;
Y
Yu Kun 已提交
219 220 221
    //test null input
    handler->Search(&context, nullptr, &response);

Y
youny626 已提交
222
    // test invalid table name
Y
Yu Kun 已提交
223 224
    handler->Search(&context, &request, &response);

Y
youny626 已提交
225
    // test table not exist
Y
Yu Kun 已提交
226 227 228
    request.set_table_name("test3");
    handler->Search(&context, &request, &response);

Y
youny626 已提交
229
    // test invalid topk
Y
Yu Kun 已提交
230
    request.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
231 232
    handler->Search(&context, &request, &response);

Y
youny626 已提交
233
    // test invalid nprobe
Y
Yu Kun 已提交
234
    request.set_topk(10);
Y
Yu Kun 已提交
235 236
    handler->Search(&context, &request, &response);

Y
youny626 已提交
237
    // test empty query record array
Y
Yu Kun 已提交
238
    request.set_nprobe(32);
Y
Yu Kun 已提交
239 240
    handler->Search(&context, &request, &response);

Y
Yu Kun 已提交
241
    std::vector<std::vector<float>> record_array;
Y
Yu Kun 已提交
242
    BuildVectors(0, VECTOR_COUNT, record_array);
Y
Yu Kun 已提交
243
    ::milvus::grpc::InsertParam insert_param;
S
starlord 已提交
244 245
    for (auto& record : record_array) {
        ::milvus::grpc::RowRecord* grpc_record = insert_param.add_row_record_array();
G
groot 已提交
246
        CopyRowRecord(grpc_record, record);
Y
Yu Kun 已提交
247
    }
Y
youny626 已提交
248
    // insert vectors
Y
Yu Kun 已提交
249 250 251 252 253
    insert_param.set_table_name(TABLE_NAME);
    ::milvus::grpc::VectorIds vector_ids;
    handler->Insert(&context, &insert_param, &vector_ids);

    BuildVectors(0, 10, record_array);
S
starlord 已提交
254 255
    for (auto& record : record_array) {
        ::milvus::grpc::RowRecord* row_record = request.add_query_record_array();
G
groot 已提交
256
        CopyRowRecord(row_record, record);
Y
Yu Kun 已提交
257
    }
Y
Yu Kun 已提交
258 259
    handler->Search(&context, &request, &response);

Y
youny626 已提交
260
    // test search with range
S
starlord 已提交
261
    ::milvus::grpc::Range* range = request.mutable_query_range_array()->Add();
Y
Yu Kun 已提交
262 263
    range->set_start_value(CurrentTmDate(-2));
    range->set_end_value(CurrentTmDate(-3));
Y
Yu Kun 已提交
264
    handler->Search(&context, &request, &response);
Y
Yu Kun 已提交
265
    request.mutable_query_range_array()->Clear();
Y
Yu Kun 已提交
266 267 268 269

    request.set_table_name("test2");
    handler->Search(&context, &request, &response);
    request.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
270 271
    handler->Search(&context, &request, &response);

Y
Yu Kun 已提交
272
    ::milvus::grpc::SearchInFilesParam search_in_files_param;
S
starlord 已提交
273
    std::string* file_id = search_in_files_param.add_file_id_array();
Y
Yu Kun 已提交
274
    *file_id = "test_tbl";
Y
Yu Kun 已提交
275 276 277
    handler->SearchInFiles(&context, &search_in_files_param, &response);
}

S
starlord 已提交
278
TEST_F(RpcHandlerTest, TABLES_TEST) {
Y
Yu Kun 已提交
279
    ::grpc::ServerContext context;
Y
Yu Kun 已提交
280
    ::milvus::grpc::TableSchema tableschema;
Y
Yu Kun 已提交
281
    ::milvus::grpc::Status response;
Y
Yu Kun 已提交
282 283
    std::string tablename = "tbl";

Y
youny626 已提交
284 285
    // create table test
    // test null input
Y
Yu Kun 已提交
286
    handler->CreateTable(&context, nullptr, &response);
Y
youny626 已提交
287
    // test invalid table name
Y
Yu Kun 已提交
288
    handler->CreateTable(&context, &tableschema, &response);
Y
youny626 已提交
289
    // test invalid table dimension
Y
Yu Kun 已提交
290
    tableschema.set_table_name(tablename);
Y
Yu Kun 已提交
291
    handler->CreateTable(&context, &tableschema, &response);
Y
youny626 已提交
292
    // test invalid index file size
Y
Yu Kun 已提交
293
    tableschema.set_dimension(TABLE_DIM);
Y
youny626 已提交
294 295
    //    handler->CreateTable(&context, &tableschema, &response);
    // test invalid index metric type
Y
Yu Kun 已提交
296 297
    tableschema.set_index_file_size(INDEX_FILE_SIZE);
    handler->CreateTable(&context, &tableschema, &response);
Y
youny626 已提交
298
    // test table already exist
Y
Yu Kun 已提交
299 300 301
    tableschema.set_metric_type(1);
    handler->CreateTable(&context, &tableschema, &response);

Y
youny626 已提交
302 303
    // describe table test
    // test invalid table name
Y
Yu Kun 已提交
304 305 306 307 308 309 310 311 312
    ::milvus::grpc::TableName table_name;
    ::milvus::grpc::TableSchema table_schema;
    handler->DescribeTable(&context, &table_name, &table_schema);

    table_name.set_table_name(TABLE_NAME);
    ::grpc::Status status = handler->DescribeTable(&context, &table_name, &table_schema);
    ASSERT_EQ(status.error_code(), ::grpc::Status::OK.error_code());

    ::milvus::grpc::InsertParam request;
Y
Yu Kun 已提交
313 314 315
    std::vector<std::vector<float>> record_array;
    BuildVectors(0, VECTOR_COUNT, record_array);
    ::milvus::grpc::VectorIds vector_ids;
Y
youny626 已提交
316 317
    // Insert vectors
    // test invalid table name
Y
Yu Kun 已提交
318 319
    handler->Insert(&context, &request, &vector_ids);
    request.set_table_name(tablename);
Y
youny626 已提交
320
    // test empty row record
Y
Yu Kun 已提交
321 322
    handler->Insert(&context, &request, &vector_ids);

S
starlord 已提交
323 324
    for (auto& record : record_array) {
        ::milvus::grpc::RowRecord* grpc_record = request.add_row_record_array();
G
groot 已提交
325
        CopyRowRecord(grpc_record, record);
Y
Yu Kun 已提交
326
    }
Y
youny626 已提交
327
    // test vector_id size not equal to row record size
Y
Yu Kun 已提交
328 329
    vector_ids.clear_vector_id_array();
    vector_ids.add_vector_id_array(1);
Y
Yu Kun 已提交
330
    handler->Insert(&context, &request, &vector_ids);
Y
Yu Kun 已提交
331

Y
youny626 已提交
332
    // normally test
Y
Yu Kun 已提交
333
    vector_ids.clear_vector_id_array();
Y
Yu Kun 已提交
334 335
    handler->Insert(&context, &request, &vector_ids);

Y
Yu Kun 已提交
336 337 338
    request.clear_row_record_array();
    vector_ids.clear_vector_id_array();
    for (uint64_t i = 0; i < 10; ++i) {
S
starlord 已提交
339
        ::milvus::grpc::RowRecord* grpc_record = request.add_row_record_array();
G
groot 已提交
340
        CopyRowRecord(grpc_record, record_array[i]);
Y
Yu Kun 已提交
341 342 343
    }
    handler->Insert(&context, &request, &vector_ids);

Y
youny626 已提交
344
    // show tables
Y
Yu Kun 已提交
345 346 347 348
    ::milvus::grpc::Command cmd;
    ::milvus::grpc::TableNameList table_name_list;
    status = handler->ShowTables(&context, &cmd, &table_name_list);
    ASSERT_EQ(status.error_code(), ::grpc::Status::OK.error_code());
Y
Yu Kun 已提交
349

Y
youny626 已提交
350
    // Count Table
Y
Yu Kun 已提交
351
    ::milvus::grpc::TableRowCount count;
Y
Yu Kun 已提交
352 353
    table_name.Clear();
    status = handler->CountTable(&context, &table_name, &count);
Y
Yu Kun 已提交
354
    table_name.set_table_name(tablename);
Y
Yu Kun 已提交
355
    status = handler->CountTable(&context, &table_name, &count);
Y
Yu Kun 已提交
356
    ASSERT_EQ(status.error_code(), ::grpc::Status::OK.error_code());
Y
youny626 已提交
357
    //    ASSERT_EQ(count.table_row_count(), vector_ids.vector_id_array_size());
Y
Yu Kun 已提交
358

Y
youny626 已提交
359
    // Preload Table
Y
Yu Kun 已提交
360 361 362
    table_name.Clear();
    status = handler->PreloadTable(&context, &table_name, &response);
    table_name.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
363 364 365
    status = handler->PreloadTable(&context, &table_name, &response);
    ASSERT_EQ(status.error_code(), ::grpc::Status::OK.error_code());

Y
youny626 已提交
366
    // Drop table
Y
Yu Kun 已提交
367
    table_name.set_table_name("");
Y
youny626 已提交
368
    // test invalid table name
Y
Yu Kun 已提交
369
    ::grpc::Status grpc_status = handler->DropTable(&context, &table_name, &response);
Y
Yu Kun 已提交
370 371
    table_name.set_table_name(tablename);
    grpc_status = handler->DropTable(&context, &table_name, &response);
Y
Yu Kun 已提交
372 373 374 375 376
    ASSERT_EQ(grpc_status.error_code(), ::grpc::Status::OK.error_code());
    int error_code = status.error_code();
    ASSERT_EQ(error_code, ::milvus::grpc::ErrorCode::SUCCESS);
}

G
groot 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
TEST_F(RpcHandlerTest, PARTITION_TEST) {
    ::grpc::ServerContext context;
    ::milvus::grpc::TableSchema table_schema;
    ::milvus::grpc::Status response;
    std::string str_table_name = "tbl_partition";
    table_schema.set_table_name(str_table_name);
    table_schema.set_dimension(TABLE_DIM);
    table_schema.set_index_file_size(INDEX_FILE_SIZE);
    table_schema.set_metric_type(1);
    handler->CreateTable(&context, &table_schema, &response);

    ::milvus::grpc::PartitionParam partition_param;
    partition_param.set_table_name(str_table_name);
    std::string partition_name = "tbl_partition_0";
    partition_param.set_partition_name(partition_name);
    std::string partition_tag = "0";
    partition_param.set_tag(partition_tag);
    handler->CreatePartition(&context, &partition_param, &response);
    ASSERT_EQ(response.error_code(), ::grpc::Status::OK.error_code());

    ::milvus::grpc::TableName table_name;
    table_name.set_table_name(str_table_name);
    ::milvus::grpc::PartitionList partition_list;
    handler->ShowPartitions(&context, &table_name, &partition_list);
    ASSERT_EQ(response.error_code(), ::grpc::Status::OK.error_code());
    ASSERT_EQ(partition_list.partition_array_size(), 1);

    ::milvus::grpc::PartitionParam partition_parm;
    partition_parm.set_table_name(str_table_name);
    partition_parm.set_tag(partition_tag);
    handler->DropPartition(&context, &partition_parm, &response);
    ASSERT_EQ(response.error_code(), ::grpc::Status::OK.error_code());

    partition_parm.set_partition_name(partition_name);
    handler->DropPartition(&context, &partition_parm, &response);
G
groot 已提交
412
    ASSERT_NE(response.error_code(), ::grpc::Status::OK.error_code());
G
groot 已提交
413 414
}

S
starlord 已提交
415
TEST_F(RpcHandlerTest, CMD_TEST) {
Y
Yu Kun 已提交
416 417 418 419 420
    ::grpc::ServerContext context;
    ::milvus::grpc::Command command;
    command.set_cmd("version");
    ::milvus::grpc::StringReply reply;
    handler->Cmd(&context, &command, &reply);
Y
Yu Kun 已提交
421 422
    ASSERT_EQ(reply.string_reply(), MILVUS_VERSION);

Y
Yu Kun 已提交
423 424 425 426
    command.set_cmd("tasktable");
    handler->Cmd(&context, &command, &reply);
    command.set_cmd("test");
    handler->Cmd(&context, &command, &reply);
Y
Yu Kun 已提交
427 428
}

S
starlord 已提交
429
TEST_F(RpcHandlerTest, DELETE_BY_RANGE_TEST) {
Y
Yu Kun 已提交
430
    ::grpc::ServerContext context;
G
groot 已提交
431
    ::milvus::grpc::DeleteByDateParam request;
Y
Yu Kun 已提交
432
    ::milvus::grpc::Status status;
G
groot 已提交
433 434
    handler->DeleteByDate(&context, nullptr, &status);
    handler->DeleteByDate(&context, &request, &status);
Y
Yu Kun 已提交
435

Y
Yu Kun 已提交
436
    request.set_table_name(TABLE_NAME);
S
starlord 已提交
437 438
    request.mutable_range()->set_start_value(CurrentTmDate(-3));
    request.mutable_range()->set_end_value(CurrentTmDate(-2));
Y
Yu Kun 已提交
439

G
groot 已提交
440
    ::grpc::Status grpc_status = handler->DeleteByDate(&context, &request, &status);
Y
Yu Kun 已提交
441
    int error_code = status.error_code();
Y
youny626 已提交
442
    //    ASSERT_EQ(error_code, ::milvus::grpc::ErrorCode::SUCCESS);
Y
Yu Kun 已提交
443

Y
Yu Kun 已提交
444
    request.mutable_range()->set_start_value("test6");
G
groot 已提交
445
    grpc_status = handler->DeleteByDate(&context, &request, &status);
Y
Yu Kun 已提交
446
    request.mutable_range()->set_start_value(CurrentTmDate(-2));
Y
Yu Kun 已提交
447
    request.mutable_range()->set_end_value("test6");
G
groot 已提交
448
    grpc_status = handler->DeleteByDate(&context, &request, &status);
Y
Yu Kun 已提交
449
    request.mutable_range()->set_end_value(CurrentTmDate(-2));
G
groot 已提交
450
    grpc_status = handler->DeleteByDate(&context, &request, &status);
Y
Yu Kun 已提交
451 452 453
}

//////////////////////////////////////////////////////////////////////
S
starlord 已提交
454
namespace {
G
groot 已提交
455
class DummyRequest : public milvus::server::grpc::GrpcBaseRequest {
S
starlord 已提交
456
 public:
S
starlord 已提交
457
    milvus::Status
Y
Yu Kun 已提交
458
    OnExecute() override {
S
starlord 已提交
459
        return milvus::Status::OK();
Y
Yu Kun 已提交
460 461
    }

G
groot 已提交
462
    static milvus::server::grpc::BaseRequestPtr
S
starlord 已提交
463
    Create(std::string& dummy) {
G
groot 已提交
464
        return std::shared_ptr<milvus::server::grpc::GrpcBaseRequest>(new DummyRequest(dummy));
Y
Yu Kun 已提交
465 466
    }

S
starlord 已提交
467
 public:
G
groot 已提交
468
    explicit DummyRequest(std::string& dummy) : GrpcBaseRequest(dummy) {
Y
Yu Kun 已提交
469 470 471 472
    }
};

class RpcSchedulerTest : public testing::Test {
S
starlord 已提交
473
 protected:
Y
Yu Kun 已提交
474 475 476
    void
    SetUp() override {
        std::string dummy = "dql";
G
groot 已提交
477
        request_ptr = std::make_shared<DummyRequest>(dummy);
Y
Yu Kun 已提交
478 479
    }

G
groot 已提交
480
    std::shared_ptr<DummyRequest> request_ptr;
Y
Yu Kun 已提交
481 482
};

Y
youny626 已提交
483
}  // namespace
S
starlord 已提交
484

S
starlord 已提交
485
TEST_F(RpcSchedulerTest, BASE_TASK_TEST) {
G
groot 已提交
486
    auto status = request_ptr->Execute();
S
starlord 已提交
487
    ASSERT_TRUE(status.ok());
Y
Yu Kun 已提交
488

S
starlord 已提交
489
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().Start();
Y
Yu Kun 已提交
490 491
    ::milvus::grpc::Status grpc_status;
    std::string dummy = "dql";
G
groot 已提交
492 493
    milvus::server::grpc::BaseRequestPtr base_task_ptr = DummyRequest::Create(dummy);
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().ExecRequest(base_task_ptr, &grpc_status);
Y
Yu Kun 已提交
494

G
groot 已提交
495 496 497
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().ExecuteRequest(request_ptr);
    request_ptr = nullptr;
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().ExecuteRequest(request_ptr);
Y
Yu Kun 已提交
498

S
starlord 已提交
499
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().Stop();
Y
Yu Kun 已提交
500
}