test_rpc.cpp 17.2 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 20 21 22 23 24 25
#include <gtest/gtest.h>
#include <thread>
#include <boost/filesystem.hpp>

#include "server/Server.h"
#include "server/grpc_impl/GrpcRequestHandler.h"
#include "server/grpc_impl/GrpcRequestScheduler.h"
#include "server/grpc_impl/GrpcRequestTask.h"
S
starlord 已提交
26
#include "../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 "server/DBWrapper.h"
S
starlord 已提交
32
#include "server/Config.h"
Y
Yu Kun 已提交
33 34 35 36
#include "scheduler/SchedInst.h"
#include "scheduler/ResourceFactory.h"
#include "utils/CommonUtil.h"

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

static const char *TABLE_NAME = "test_grpc";
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 46 47 48 49
static constexpr int64_t INSERT_LOOP = 10;
constexpr int64_t SECONDS_EACH_HOUR = 3600;

class RpcHandlerTest : public testing::Test {
 protected:
    void
    SetUp() override {
S
starlord 已提交
50
        auto res_mgr = milvus::scheduler::ResMgrInst::GetInstance();
Y
Yu Kun 已提交
51
        res_mgr->Clear();
S
starlord 已提交
52 53 54
        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 已提交
55

S
starlord 已提交
56 57
        auto default_conn = milvus::scheduler::Connection("IO", 500.0);
        auto PCIE = milvus::scheduler::Connection("IO", 11000.0);
Y
Yu Kun 已提交
58 59 60
        res_mgr->Connect("disk", "cpu", default_conn);
        res_mgr->Connect("cpu", "gtx1660", PCIE);
        res_mgr->Start();
S
starlord 已提交
61 62
        milvus::scheduler::SchedInst::GetInstance()->Start();
        milvus::scheduler::JobMgrInst::GetInstance()->Start();
Y
Yu Kun 已提交
63

S
starlord 已提交
64
        milvus::engine::DBOptions opt;
Y
Yu Kun 已提交
65

S
starlord 已提交
66 67 68 69 70 71 72
        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 已提交
73

S
starlord 已提交
74
//        serverConfig.SetValue(server::CONFIG_CLUSTER_MODE, "cluster");
Y
Yu Kun 已提交
75 76 77
//        DBWrapper::GetInstance().GetInstance().StartService();
//        DBWrapper::GetInstance().GetInstance().StopService();
//
S
starlord 已提交
78
//        serverConfig.SetValue(server::CONFIG_CLUSTER_MODE, "read_only");
Y
Yu Kun 已提交
79 80
//        DBWrapper::GetInstance().GetInstance().StartService();
//        DBWrapper::GetInstance().GetInstance().StopService();
Y
Yu Kun 已提交
81

S
starlord 已提交
82 83
        milvus::server::Config::GetInstance().SetResourceConfigMode("single");
        milvus::server::DBWrapper::GetInstance().StartService();
Y
Yu Kun 已提交
84

Y
Yu Kun 已提交
85
        //initialize handler, create table
S
starlord 已提交
86
        handler = std::make_shared<milvus::server::grpc::GrpcRequestHandler>();
Y
Yu Kun 已提交
87 88
        ::grpc::ServerContext context;
        ::milvus::grpc::TableSchema request;
Y
Yu Kun 已提交
89
        ::milvus::grpc::Status status;
Y
Yu Kun 已提交
90
        request.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
91 92 93 94 95 96 97 98
        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 已提交
99 100 101 102
        milvus::server::DBWrapper::GetInstance().StopService();
        milvus::scheduler::JobMgrInst::GetInstance()->Stop();
        milvus::scheduler::ResMgrInst::GetInstance()->Stop();
        milvus::scheduler::SchedInst::GetInstance()->Stop();
Y
Yu Kun 已提交
103 104
        boost::filesystem::remove_all("/tmp/milvus_test");
    }
S
starlord 已提交
105

Y
Yu Kun 已提交
106
 protected:
S
starlord 已提交
107
    std::shared_ptr<milvus::server::grpc::GrpcRequestHandler> handler;
Y
Yu Kun 已提交
108 109
};

S
starlord 已提交
110 111 112
void
BuildVectors(int64_t from, int64_t to,
             std::vector<std::vector<float >> &vector_record_array) {
Y
Yu Kun 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    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++) {
            record[i] = (float) (k % (i + 1));
        }

        vector_record_array.emplace_back(record);
    }
}

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

S
starlord 已提交
138 139
    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 已提交
140 141 142

    return str;
}
S
starlord 已提交
143

S
starlord 已提交
144
} // namespace
Y
Yu Kun 已提交
145

S
starlord 已提交
146
TEST_F(RpcHandlerTest, HAS_TABLE_TEST) {
Y
Yu Kun 已提交
147 148 149 150
    ::grpc::ServerContext context;
    ::milvus::grpc::TableName request;
    ::milvus::grpc::BoolReply reply;
    ::grpc::Status status = handler->HasTable(&context, &request, &reply);
Y
Yu Kun 已提交
151 152
    request.set_table_name(TABLE_NAME);
    status = handler->HasTable(&context, &request, &reply);
Y
Yu Kun 已提交
153 154 155 156 157
    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 已提交
158
TEST_F(RpcHandlerTest, INDEX_TEST) {
Y
Yu Kun 已提交
159 160 161
    ::grpc::ServerContext context;
    ::milvus::grpc::IndexParam request;
    ::milvus::grpc::Status response;
Y
Yu Kun 已提交
162
    ::grpc::Status grpc_status = handler->CreateIndex(&context, &request, &response);
Y
Yu Kun 已提交
163
    request.set_table_name("test1");
Y
Yu Kun 已提交
164 165
    handler->CreateIndex(&context, &request, &response);

Y
Yu Kun 已提交
166
    request.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
167 168
    handler->CreateIndex(&context, &request, &response);

Y
Yu Kun 已提交
169
    request.mutable_index()->set_index_type(1);
Y
Yu Kun 已提交
170 171
    handler->CreateIndex(&context, &request, &response);

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

    ::milvus::grpc::TableName table_name;
    ::milvus::grpc::IndexParam index_param;
    handler->DescribeIndex(&context, &table_name, &index_param);
Y
Yu Kun 已提交
181 182 183 184
    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 已提交
185
    ::milvus::grpc::Status status;
Y
Yu Kun 已提交
186 187 188 189 190
    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 已提交
191 192 193
    handler->DropIndex(&context, &table_name, &status);
}

S
starlord 已提交
194
TEST_F(RpcHandlerTest, INSERT_TEST) {
Y
Yu Kun 已提交
195 196 197
    ::grpc::ServerContext context;
    ::milvus::grpc::InsertParam request;
    ::milvus::grpc::Status response;
Y
Yu Kun 已提交
198

Y
Yu Kun 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212
    request.set_table_name(TABLE_NAME);
    std::vector<std::vector<float>> record_array;
    BuildVectors(0, VECTOR_COUNT, record_array);
    ::milvus::grpc::VectorIds vector_ids;
    for (auto &record : record_array) {
        ::milvus::grpc::RowRecord *grpc_record = request.add_row_record_array();
        for (size_t i = 0; i < record.size(); i++) {
            grpc_record->add_vector_data(record[i]);
        }
    }
    handler->Insert(&context, &request, &vector_ids);
    ASSERT_EQ(vector_ids.vector_id_array_size(), VECTOR_COUNT);
}

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

    //test invalid table name
    handler->Search(&context, &request, &response);

    //test table not exist
    request.set_table_name("test3");
    handler->Search(&context, &request, &response);

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

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

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

Y
Yu Kun 已提交
239
    std::vector<std::vector<float>> record_array;
Y
Yu Kun 已提交
240
    BuildVectors(0, VECTOR_COUNT, record_array);
Y
Yu Kun 已提交
241 242 243 244 245 246 247 248 249 250 251
    ::milvus::grpc::InsertParam insert_param;
    for (auto &record : record_array) {
        ::milvus::grpc::RowRecord *grpc_record = insert_param.add_row_record_array();
        for (size_t i = 0; i < record.size(); i++) {
            grpc_record->add_vector_data(record[i]);
        }
    }
    //insert vectors
    insert_param.set_table_name(TABLE_NAME);
    ::milvus::grpc::VectorIds vector_ids;
    handler->Insert(&context, &insert_param, &vector_ids);
Y
Yu Kun 已提交
252
    sleep(7);
Y
Yu Kun 已提交
253 254

    BuildVectors(0, 10, record_array);
Y
Yu Kun 已提交
255 256 257 258 259 260
    for (auto &record : record_array) {
        ::milvus::grpc::RowRecord *row_record = request.add_query_record_array();
        for (auto &rec : record) {
            row_record->add_vector_data(rec);
        }
    }
Y
Yu Kun 已提交
261 262
    handler->Search(&context, &request, &response);

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

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

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

S
starlord 已提交
281
TEST_F(RpcHandlerTest, TABLES_TEST) {
Y
Yu Kun 已提交
282
    ::grpc::ServerContext context;
Y
Yu Kun 已提交
283
    ::milvus::grpc::TableSchema tableschema;
Y
Yu Kun 已提交
284
    ::milvus::grpc::Status response;
Y
Yu Kun 已提交
285 286 287 288 289 290 291 292
    std::string tablename = "tbl";

    //create table test
    //test null input
    handler->CreateTable(&context, nullptr, &response);
    //test invalid table name
    handler->CreateTable(&context, &tableschema, &response);
    //test invalid table dimension
Y
Yu Kun 已提交
293
    tableschema.set_table_name(tablename);
Y
Yu Kun 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
    handler->CreateTable(&context, &tableschema, &response);
    //test invalid index file size
    tableschema.set_dimension(TABLE_DIM);
//    handler->CreateTable(&context, &tableschema, &response);
    //test invalid index metric type
    tableschema.set_index_file_size(INDEX_FILE_SIZE);
    handler->CreateTable(&context, &tableschema, &response);
    //test table already exist
    tableschema.set_metric_type(1);
    handler->CreateTable(&context, &tableschema, &response);

    //describe table test
    //test invalid table name
    ::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 已提交
316 317 318
    std::vector<std::vector<float>> record_array;
    BuildVectors(0, VECTOR_COUNT, record_array);
    ::milvus::grpc::VectorIds vector_ids;
Y
Yu Kun 已提交
319 320 321 322 323 324 325
    //Insert vectors
    //test invalid table name
    handler->Insert(&context, &request, &vector_ids);
    request.set_table_name(tablename);
    //test empty row record
    handler->Insert(&context, &request, &vector_ids);

Y
Yu Kun 已提交
326 327 328 329 330 331
    for (auto &record : record_array) {
        ::milvus::grpc::RowRecord *grpc_record = request.add_row_record_array();
        for (size_t i = 0; i < record.size(); i++) {
            grpc_record->add_vector_data(record[i]);
        }
    }
Y
Yu Kun 已提交
332
    //test vector_id size not equal to row record size
Y
Yu Kun 已提交
333 334
    vector_ids.clear_vector_id_array();
    vector_ids.add_vector_id_array(1);
Y
Yu Kun 已提交
335
    handler->Insert(&context, &request, &vector_ids);
Y
Yu Kun 已提交
336

Y
Yu Kun 已提交
337 338
    //normally test
    vector_ids.clear_vector_id_array();
Y
Yu Kun 已提交
339 340
    handler->Insert(&context, &request, &vector_ids);

Y
Yu Kun 已提交
341 342 343 344 345 346 347 348 349 350
    request.clear_row_record_array();
    vector_ids.clear_vector_id_array();
    for (uint64_t i = 0; i < 10; ++i) {
        ::milvus::grpc::RowRecord *grpc_record = request.add_row_record_array();
        for (size_t j = 0; j < 10; j++) {
            grpc_record->add_vector_data(record_array[i][j]);
        }
    }
    handler->Insert(&context, &request, &vector_ids);

Y
Yu Kun 已提交
351

Y
Yu Kun 已提交
352 353 354 355 356
    //show tables
    ::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 已提交
357

Y
Yu Kun 已提交
358 359
    //Count Table
    ::milvus::grpc::TableRowCount count;
Y
Yu Kun 已提交
360 361
    table_name.Clear();
    status = handler->CountTable(&context, &table_name, &count);
Y
Yu Kun 已提交
362
    table_name.set_table_name(tablename);
Y
Yu Kun 已提交
363
    status = handler->CountTable(&context, &table_name, &count);
Y
Yu Kun 已提交
364
    ASSERT_EQ(status.error_code(), ::grpc::Status::OK.error_code());
Y
Yu Kun 已提交
365
//    ASSERT_EQ(count.table_row_count(), vector_ids.vector_id_array_size());
Y
Yu Kun 已提交
366 367 368


    //Preload Table
Y
Yu Kun 已提交
369 370 371
    table_name.Clear();
    status = handler->PreloadTable(&context, &table_name, &response);
    table_name.set_table_name(TABLE_NAME);
Y
Yu Kun 已提交
372 373 374 375
    status = handler->PreloadTable(&context, &table_name, &response);
    ASSERT_EQ(status.error_code(), ::grpc::Status::OK.error_code());

    //Drop table
Y
Yu Kun 已提交
376 377
    table_name.set_table_name("");
    //test invalid table name
Y
Yu Kun 已提交
378
    ::grpc::Status grpc_status = handler->DropTable(&context, &table_name, &response);
Y
Yu Kun 已提交
379 380
    table_name.set_table_name(tablename);
    grpc_status = handler->DropTable(&context, &table_name, &response);
Y
Yu Kun 已提交
381 382 383 384 385
    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);
}

S
starlord 已提交
386
TEST_F(RpcHandlerTest, CMD_TEST) {
Y
Yu Kun 已提交
387 388 389 390 391
    ::grpc::ServerContext context;
    ::milvus::grpc::Command command;
    command.set_cmd("version");
    ::milvus::grpc::StringReply reply;
    handler->Cmd(&context, &command, &reply);
Y
Yu Kun 已提交
392 393
    ASSERT_EQ(reply.string_reply(), MILVUS_VERSION);

Y
Yu Kun 已提交
394 395 396 397
    command.set_cmd("tasktable");
    handler->Cmd(&context, &command, &reply);
    command.set_cmd("test");
    handler->Cmd(&context, &command, &reply);
Y
Yu Kun 已提交
398 399
}

S
starlord 已提交
400
TEST_F(RpcHandlerTest, DELETE_BY_RANGE_TEST) {
Y
Yu Kun 已提交
401 402 403
    ::grpc::ServerContext context;
    ::milvus::grpc::DeleteByRangeParam request;
    ::milvus::grpc::Status status;
Y
Yu Kun 已提交
404 405 406
    handler->DeleteByRange(&context, nullptr, &status);
    handler->DeleteByRange(&context, &request, &status);

Y
Yu Kun 已提交
407
    request.set_table_name(TABLE_NAME);
S
starlord 已提交
408 409
    request.mutable_range()->set_start_value(CurrentTmDate(-3));
    request.mutable_range()->set_end_value(CurrentTmDate(-2));
Y
Yu Kun 已提交
410 411 412

    ::grpc::Status grpc_status = handler->DeleteByRange(&context, &request, &status);
    int error_code = status.error_code();
Y
Yu Kun 已提交
413
//    ASSERT_EQ(error_code, ::milvus::grpc::ErrorCode::SUCCESS);
Y
Yu Kun 已提交
414

Y
Yu Kun 已提交
415
    request.mutable_range()->set_start_value("test6");
Y
Yu Kun 已提交
416 417
    grpc_status = handler->DeleteByRange(&context, &request, &status);
    request.mutable_range()->set_start_value(CurrentTmDate(-2));
Y
Yu Kun 已提交
418
    request.mutable_range()->set_end_value("test6");
Y
Yu Kun 已提交
419 420 421
    grpc_status = handler->DeleteByRange(&context, &request, &status);
    request.mutable_range()->set_end_value(CurrentTmDate(-2));
    grpc_status = handler->DeleteByRange(&context, &request, &status);
Y
Yu Kun 已提交
422 423 424
}

//////////////////////////////////////////////////////////////////////
S
starlord 已提交
425
namespace {
S
starlord 已提交
426
class DummyTask : public milvus::server::grpc::GrpcBaseTask {
S
starlord 已提交
427
 public:
S
starlord 已提交
428
    milvus::Status
Y
Yu Kun 已提交
429
    OnExecute() override {
S
starlord 已提交
430
        return milvus::Status::OK();
Y
Yu Kun 已提交
431 432
    }

S
starlord 已提交
433
    static milvus::server::grpc::BaseTaskPtr
S
starlord 已提交
434
    Create(std::string &dummy) {
S
starlord 已提交
435
        return std::shared_ptr<milvus::server::grpc::GrpcBaseTask>(new DummyTask(dummy));
Y
Yu Kun 已提交
436 437
    }

S
starlord 已提交
438
 public:
Y
Yu Kun 已提交
439 440 441 442 443
    explicit DummyTask(std::string &dummy) : GrpcBaseTask(dummy) {
    }
};

class RpcSchedulerTest : public testing::Test {
S
starlord 已提交
444
 protected:
Y
Yu Kun 已提交
445 446 447 448 449 450 451 452 453
    void
    SetUp() override {
        std::string dummy = "dql";
        task_ptr = std::make_shared<DummyTask>(dummy);
    }

    std::shared_ptr<DummyTask> task_ptr;
};

S
starlord 已提交
454
} // namespace
S
starlord 已提交
455

S
starlord 已提交
456
TEST_F(RpcSchedulerTest, BASE_TASK_TEST) {
S
starlord 已提交
457 458
    auto status = task_ptr->Execute();
    ASSERT_TRUE(status.ok());
Y
Yu Kun 已提交
459

S
starlord 已提交
460
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().Start();
Y
Yu Kun 已提交
461 462
    ::milvus::grpc::Status grpc_status;
    std::string dummy = "dql";
S
starlord 已提交
463 464
    milvus::server::grpc::BaseTaskPtr base_task_ptr = DummyTask::Create(dummy);
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().ExecTask(base_task_ptr, &grpc_status);
Y
Yu Kun 已提交
465

S
starlord 已提交
466
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().ExecuteTask(task_ptr);
Y
Yu Kun 已提交
467
    task_ptr = nullptr;
S
starlord 已提交
468
    milvus::server::grpc::GrpcRequestScheduler::GetInstance().ExecuteTask(task_ptr);
Y
Yu Kun 已提交
469

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