test_normal.cpp 2.4 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
youny626 已提交
18
#include <gtest/gtest.h>
W
wxyu 已提交
19 20
#include "scheduler/ResourceFactory.h"
#include "scheduler/ResourceMgr.h"
Y
youny626 已提交
21
#include "scheduler/SchedInst.h"
W
wxyu 已提交
22
#include "scheduler/Scheduler.h"
23
#include "scheduler/task/TestTask.h"
W
wxyu 已提交
24
#include "scheduler/tasklabel/DefaultLabel.h"
25
#include "utils/Log.h"
W
wxyu 已提交
26

S
starlord 已提交
27
namespace {
W
wxyu 已提交
28

S
starlord 已提交
29
namespace ms = milvus::scheduler;
W
wxyu 已提交
30

Y
youny626 已提交
31
}  // namespace
W
wxyu 已提交
32

S
starlord 已提交
33
TEST(NormalTest, INST_TEST) {
W
wxyu 已提交
34
    // ResourceMgr only compose resources, provide unified event
S
starlord 已提交
35
    auto res_mgr = ms::ResMgrInst::GetInstance();
W
wxyu 已提交
36

S
starlord 已提交
37 38
    res_mgr->Add(ms::ResourceFactory::Create("disk", "DISK", 0, true, false));
    res_mgr->Add(ms::ResourceFactory::Create("cpu", "CPU", 0, true, true));
W
wxyu 已提交
39

S
starlord 已提交
40
    auto IO = ms::Connection("IO", 500.0);
W
wxyu 已提交
41
    res_mgr->Connect("disk", "cpu", IO);
W
wxyu 已提交
42

S
starlord 已提交
43
    auto scheduler = ms::SchedInst::GetInstance();
W
wxyu 已提交
44 45

    res_mgr->Start();
46 47
    scheduler->Start();

48
    const uint64_t NUM_TASK = 2;
S
starlord 已提交
49 50
    std::vector<std::shared_ptr<ms::TestTask>> tasks;
    ms::TableFileSchemaPtr dummy = nullptr;
51

W
wxyu 已提交
52 53 54 55
    auto disks = res_mgr->GetDiskResources();
    ASSERT_FALSE(disks.empty());
    if (auto observe = disks[0].lock()) {
        for (uint64_t i = 0; i < NUM_TASK; ++i) {
W
wxyu 已提交
56 57
            auto label = std::make_shared<ms::DefaultLabel>();
            auto task = std::make_shared<ms::TestTask>(dummy, label);
S
starlord 已提交
58
            task->label() = std::make_shared<ms::DefaultLabel>();
59 60 61
            tasks.push_back(task);
            observe->task_table().Put(task);
        }
W
wxyu 已提交
62 63
    }

Y
youny626 已提交
64
    for (auto& task : tasks) {
W
wxyu 已提交
65 66 67 68
        task->Wait();
        ASSERT_EQ(task->load_count_, 1);
        ASSERT_EQ(task->exec_count_, 1);
    }
69 70 71

    scheduler->Stop();
    res_mgr->Stop();
W
wxyu 已提交
72
}