test_tasktable.cpp 15.5 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.

W
wxyu 已提交
18
#include <gtest/gtest.h>
W
wxyu 已提交
19
#include "scheduler/TaskTable.h"
W
wxyu 已提交
20
#include "scheduler/task/TestTask.h"
W
wxyu 已提交
21
#include "scheduler/tasklabel/DefaultLabel.h"
W
wxyu 已提交
22

W
wxyu 已提交
23 24
/************ TaskTableBaseTest ************/

W
wxyu 已提交
25
class TaskTableItemTest : public ::testing::Test {
S
starlord 已提交
26
 protected:
W
wxyu 已提交
27 28
    void
    SetUp() override {
S
starlord 已提交
29
        std::vector<milvus::scheduler::TaskTableItemState> states{
W
wxyu 已提交
30 31 32 33 34
            milvus::scheduler::TaskTableItemState::INVALID,   milvus::scheduler::TaskTableItemState::START,
            milvus::scheduler::TaskTableItemState::LOADING,   milvus::scheduler::TaskTableItemState::LOADED,
            milvus::scheduler::TaskTableItemState::EXECUTING, milvus::scheduler::TaskTableItemState::EXECUTED,
            milvus::scheduler::TaskTableItemState::MOVING,    milvus::scheduler::TaskTableItemState::MOVED};
        for (auto& state : states) {
S
starlord 已提交
35
            auto item = std::make_shared<milvus::scheduler::TaskTableItem>();
W
wxyu 已提交
36 37 38
            item->state = state;
            items_.emplace_back(item);
        }
W
wxyu 已提交
39 40
    }

S
starlord 已提交
41 42
    milvus::scheduler::TaskTableItem default_;
    std::vector<milvus::scheduler::TaskTableItemPtr> items_;
W
wxyu 已提交
43 44
};

S
starlord 已提交
45
TEST_F(TaskTableItemTest, CONSTRUCT) {
W
wxyu 已提交
46
    ASSERT_EQ(default_.id, 0);
W
wxyu 已提交
47
    ASSERT_EQ(default_.task, nullptr);
S
starlord 已提交
48
    ASSERT_EQ(default_.state, milvus::scheduler::TaskTableItemState::INVALID);
W
wxyu 已提交
49 50
}

S
starlord 已提交
51
TEST_F(TaskTableItemTest, DESTRUCT) {
S
starlord 已提交
52
    auto p_item = new milvus::scheduler::TaskTableItem();
W
wxyu 已提交
53 54 55
    delete p_item;
}

S
starlord 已提交
56
TEST_F(TaskTableItemTest, IS_FINISH) {
W
wxyu 已提交
57 58 59
    for (auto& item : items_) {
        if (item->state == milvus::scheduler::TaskTableItemState::EXECUTED ||
            item->state == milvus::scheduler::TaskTableItemState::MOVED) {
W
wxyu 已提交
60 61 62 63 64 65 66
            ASSERT_TRUE(item->IsFinish());
        } else {
            ASSERT_FALSE(item->IsFinish());
        }
    }
}

S
starlord 已提交
67
TEST_F(TaskTableItemTest, DUMP) {
W
wxyu 已提交
68
    for (auto& item : items_) {
W
wxyu 已提交
69 70 71 72
        ASSERT_FALSE(item->Dump().empty());
    }
}

S
starlord 已提交
73
TEST_F(TaskTableItemTest, LOAD) {
W
wxyu 已提交
74
    for (auto& item : items_) {
W
wxyu 已提交
75 76
        auto before_state = item->state;
        auto ret = item->Load();
S
starlord 已提交
77
        if (before_state == milvus::scheduler::TaskTableItemState::START) {
W
wxyu 已提交
78
            ASSERT_TRUE(ret);
S
starlord 已提交
79
            ASSERT_EQ(item->state, milvus::scheduler::TaskTableItemState::LOADING);
W
wxyu 已提交
80 81 82 83 84 85 86
        } else {
            ASSERT_FALSE(ret);
            ASSERT_EQ(item->state, before_state);
        }
    }
}

S
starlord 已提交
87
TEST_F(TaskTableItemTest, LOADED) {
W
wxyu 已提交
88
    for (auto& item : items_) {
W
wxyu 已提交
89 90
        auto before_state = item->state;
        auto ret = item->Loaded();
S
starlord 已提交
91
        if (before_state == milvus::scheduler::TaskTableItemState::LOADING) {
W
wxyu 已提交
92
            ASSERT_TRUE(ret);
S
starlord 已提交
93
            ASSERT_EQ(item->state, milvus::scheduler::TaskTableItemState::LOADED);
W
wxyu 已提交
94 95 96 97 98 99 100
        } else {
            ASSERT_FALSE(ret);
            ASSERT_EQ(item->state, before_state);
        }
    }
}

S
starlord 已提交
101
TEST_F(TaskTableItemTest, EXECUTE) {
W
wxyu 已提交
102
    for (auto& item : items_) {
W
wxyu 已提交
103 104
        auto before_state = item->state;
        auto ret = item->Execute();
S
starlord 已提交
105
        if (before_state == milvus::scheduler::TaskTableItemState::LOADED) {
W
wxyu 已提交
106
            ASSERT_TRUE(ret);
S
starlord 已提交
107
            ASSERT_EQ(item->state, milvus::scheduler::TaskTableItemState::EXECUTING);
W
wxyu 已提交
108 109 110 111 112 113 114
        } else {
            ASSERT_FALSE(ret);
            ASSERT_EQ(item->state, before_state);
        }
    }
}

S
starlord 已提交
115
TEST_F(TaskTableItemTest, EXECUTED) {
W
wxyu 已提交
116
    for (auto& item : items_) {
W
wxyu 已提交
117 118
        auto before_state = item->state;
        auto ret = item->Executed();
S
starlord 已提交
119
        if (before_state == milvus::scheduler::TaskTableItemState::EXECUTING) {
W
wxyu 已提交
120
            ASSERT_TRUE(ret);
S
starlord 已提交
121
            ASSERT_EQ(item->state, milvus::scheduler::TaskTableItemState::EXECUTED);
W
wxyu 已提交
122 123 124 125 126 127 128
        } else {
            ASSERT_FALSE(ret);
            ASSERT_EQ(item->state, before_state);
        }
    }
}

S
starlord 已提交
129
TEST_F(TaskTableItemTest, MOVE) {
W
wxyu 已提交
130
    for (auto& item : items_) {
W
wxyu 已提交
131 132
        auto before_state = item->state;
        auto ret = item->Move();
S
starlord 已提交
133
        if (before_state == milvus::scheduler::TaskTableItemState::LOADED) {
W
wxyu 已提交
134
            ASSERT_TRUE(ret);
S
starlord 已提交
135
            ASSERT_EQ(item->state, milvus::scheduler::TaskTableItemState::MOVING);
W
wxyu 已提交
136 137 138 139 140 141 142
        } else {
            ASSERT_FALSE(ret);
            ASSERT_EQ(item->state, before_state);
        }
    }
}

S
starlord 已提交
143
TEST_F(TaskTableItemTest, MOVED) {
W
wxyu 已提交
144
    for (auto& item : items_) {
W
wxyu 已提交
145 146
        auto before_state = item->state;
        auto ret = item->Moved();
S
starlord 已提交
147
        if (before_state == milvus::scheduler::TaskTableItemState::MOVING) {
W
wxyu 已提交
148
            ASSERT_TRUE(ret);
S
starlord 已提交
149
            ASSERT_EQ(item->state, milvus::scheduler::TaskTableItemState::MOVED);
W
wxyu 已提交
150 151 152 153 154 155
        } else {
            ASSERT_FALSE(ret);
            ASSERT_EQ(item->state, before_state);
        }
    }
}
W
wxyu 已提交
156 157 158 159

/************ TaskTableBaseTest ************/

class TaskTableBaseTest : public ::testing::Test {
S
starlord 已提交
160
 protected:
W
wxyu 已提交
161 162
    void
    SetUp() override {
S
starlord 已提交
163
        milvus::scheduler::TableFileSchemaPtr dummy = nullptr;
W
wxyu 已提交
164
        invalid_task_ = nullptr;
S
starlord 已提交
165 166 167
        auto label = std::make_shared<milvus::scheduler::DefaultLabel>();
        task1_ = std::make_shared<milvus::scheduler::TestTask>(dummy, label);
        task2_ = std::make_shared<milvus::scheduler::TestTask>(dummy, label);
W
wxyu 已提交
168 169
    }

S
starlord 已提交
170 171 172 173
    milvus::scheduler::TaskPtr invalid_task_;
    milvus::scheduler::TaskPtr task1_;
    milvus::scheduler::TaskPtr task2_;
    milvus::scheduler::TaskTable empty_table_;
W
wxyu 已提交
174 175
};

S
starlord 已提交
176
TEST_F(TaskTableBaseTest, SUBSCRIBER) {
W
wxyu 已提交
177
    bool flag = false;
W
wxyu 已提交
178
    auto callback = [&]() { flag = true; };
W
wxyu 已提交
179 180 181 182 183
    empty_table_.RegisterSubscriber(callback);
    empty_table_.Put(task1_);
    ASSERT_TRUE(flag);
}

S
starlord 已提交
184
TEST_F(TaskTableBaseTest, PUT_TASK) {
W
wxyu 已提交
185
    empty_table_.Put(task1_);
186
    ASSERT_EQ(empty_table_.at(0)->task, task1_);
W
wxyu 已提交
187 188
}

S
starlord 已提交
189
TEST_F(TaskTableBaseTest, PUT_INVALID_TEST) {
W
wxyu 已提交
190
    empty_table_.Put(invalid_task_);
191
    ASSERT_EQ(empty_table_.at(0)->task, invalid_task_);
W
wxyu 已提交
192 193
}

S
starlord 已提交
194
TEST_F(TaskTableBaseTest, PUT_BATCH) {
S
starlord 已提交
195
    std::vector<milvus::scheduler::TaskPtr> tasks{task1_, task2_};
W
wxyu 已提交
196
    empty_table_.Put(tasks);
197 198
    ASSERT_EQ(empty_table_.at(0)->task, task1_);
    ASSERT_EQ(empty_table_.at(1)->task, task2_);
W
wxyu 已提交
199 200
}

S
starlord 已提交
201
TEST_F(TaskTableBaseTest, PUT_EMPTY_BATCH) {
S
starlord 已提交
202
    std::vector<milvus::scheduler::TaskPtr> tasks{};
W
wxyu 已提交
203 204 205
    empty_table_.Put(tasks);
}

S
starlord 已提交
206
TEST_F(TaskTableBaseTest, SIZE) {
207
    ASSERT_EQ(empty_table_.size(), 0);
W
wxyu 已提交
208
    empty_table_.Put(task1_);
209
    ASSERT_EQ(empty_table_.size(), 1);
W
wxyu 已提交
210 211
}

S
starlord 已提交
212
TEST_F(TaskTableBaseTest, OPERATOR) {
W
wxyu 已提交
213
    empty_table_.Put(task1_);
214
    ASSERT_EQ(empty_table_.at(0), empty_table_[0]);
W
wxyu 已提交
215 216
}

S
starlord 已提交
217
TEST_F(TaskTableBaseTest, PICK_TO_LOAD) {
W
wxyu 已提交
218 219 220 221
    const size_t NUM_TASKS = 10;
    for (size_t i = 0; i < NUM_TASKS; ++i) {
        empty_table_.Put(task1_);
    }
S
starlord 已提交
222 223
    empty_table_[0]->state = milvus::scheduler::TaskTableItemState::MOVED;
    empty_table_[1]->state = milvus::scheduler::TaskTableItemState::EXECUTED;
W
wxyu 已提交
224 225 226

    auto indexes = empty_table_.PickToLoad(1);
    ASSERT_EQ(indexes.size(), 1);
227
    ASSERT_EQ(indexes[0] % empty_table_.capacity(), 2);
W
wxyu 已提交
228 229
}

S
starlord 已提交
230
TEST_F(TaskTableBaseTest, PICK_TO_LOAD_LIMIT) {
W
wxyu 已提交
231 232 233 234
    const size_t NUM_TASKS = 10;
    for (size_t i = 0; i < NUM_TASKS; ++i) {
        empty_table_.Put(task1_);
    }
S
starlord 已提交
235 236
    empty_table_[0]->state = milvus::scheduler::TaskTableItemState::MOVED;
    empty_table_[1]->state = milvus::scheduler::TaskTableItemState::EXECUTED;
W
wxyu 已提交
237 238 239

    auto indexes = empty_table_.PickToLoad(3);
    ASSERT_EQ(indexes.size(), 3);
240 241 242
    ASSERT_EQ(indexes[0] % empty_table_.capacity(), 2);
    ASSERT_EQ(indexes[1] % empty_table_.capacity(), 3);
    ASSERT_EQ(indexes[2] % empty_table_.capacity(), 4);
W
wxyu 已提交
243 244
}

S
starlord 已提交
245
TEST_F(TaskTableBaseTest, PICK_TO_LOAD_CACHE) {
W
wxyu 已提交
246 247 248 249
    const size_t NUM_TASKS = 10;
    for (size_t i = 0; i < NUM_TASKS; ++i) {
        empty_table_.Put(task1_);
    }
S
starlord 已提交
250 251
    empty_table_[0]->state = milvus::scheduler::TaskTableItemState::MOVED;
    empty_table_[1]->state = milvus::scheduler::TaskTableItemState::EXECUTED;
W
wxyu 已提交
252 253 254 255

    // first pick, non-cache
    auto indexes = empty_table_.PickToLoad(1);
    ASSERT_EQ(indexes.size(), 1);
256
    ASSERT_EQ(indexes[0] % empty_table_.capacity(), 2);
W
wxyu 已提交
257 258 259

    // second pick, iterate from 2
    // invalid state change
S
starlord 已提交
260
    empty_table_[1]->state = milvus::scheduler::TaskTableItemState::START;
W
wxyu 已提交
261 262
    indexes = empty_table_.PickToLoad(1);
    ASSERT_EQ(indexes.size(), 1);
263
    ASSERT_EQ(indexes[0] % empty_table_.capacity(), 2);
W
wxyu 已提交
264 265
}

S
starlord 已提交
266
TEST_F(TaskTableBaseTest, PICK_TO_EXECUTE) {
W
wxyu 已提交
267 268 269 270
    const size_t NUM_TASKS = 10;
    for (size_t i = 0; i < NUM_TASKS; ++i) {
        empty_table_.Put(task1_);
    }
S
starlord 已提交
271 272 273
    empty_table_[0]->state = milvus::scheduler::TaskTableItemState::MOVED;
    empty_table_[1]->state = milvus::scheduler::TaskTableItemState::EXECUTED;
    empty_table_[2]->state = milvus::scheduler::TaskTableItemState::LOADED;
W
wxyu 已提交
274 275 276

    auto indexes = empty_table_.PickToExecute(1);
    ASSERT_EQ(indexes.size(), 1);
277
    ASSERT_EQ(indexes[0] % empty_table_.capacity(), 2);
W
wxyu 已提交
278 279
}

S
starlord 已提交
280
TEST_F(TaskTableBaseTest, PICK_TO_EXECUTE_LIMIT) {
W
wxyu 已提交
281 282 283 284
    const size_t NUM_TASKS = 10;
    for (size_t i = 0; i < NUM_TASKS; ++i) {
        empty_table_.Put(task1_);
    }
S
starlord 已提交
285 286 287 288
    empty_table_[0]->state = milvus::scheduler::TaskTableItemState::MOVED;
    empty_table_[1]->state = milvus::scheduler::TaskTableItemState::EXECUTED;
    empty_table_[2]->state = milvus::scheduler::TaskTableItemState::LOADED;
    empty_table_[3]->state = milvus::scheduler::TaskTableItemState::LOADED;
W
wxyu 已提交
289 290 291

    auto indexes = empty_table_.PickToExecute(3);
    ASSERT_EQ(indexes.size(), 2);
292 293
    ASSERT_EQ(indexes[0] % empty_table_.capacity(), 2);
    ASSERT_EQ(indexes[1] % empty_table_.capacity(), 3);
W
wxyu 已提交
294 295
}

S
starlord 已提交
296
TEST_F(TaskTableBaseTest, PICK_TO_EXECUTE_CACHE) {
W
wxyu 已提交
297 298 299 300
    const size_t NUM_TASKS = 10;
    for (size_t i = 0; i < NUM_TASKS; ++i) {
        empty_table_.Put(task1_);
    }
S
starlord 已提交
301 302 303
    empty_table_[0]->state = milvus::scheduler::TaskTableItemState::MOVED;
    empty_table_[1]->state = milvus::scheduler::TaskTableItemState::EXECUTED;
    empty_table_[2]->state = milvus::scheduler::TaskTableItemState::LOADED;
W
wxyu 已提交
304 305 306 307

    // first pick, non-cache
    auto indexes = empty_table_.PickToExecute(1);
    ASSERT_EQ(indexes.size(), 1);
308
    ASSERT_EQ(indexes[0] % empty_table_.capacity(), 2);
W
wxyu 已提交
309 310 311

    // second pick, iterate from 2
    // invalid state change
S
starlord 已提交
312
    empty_table_[1]->state = milvus::scheduler::TaskTableItemState::START;
W
wxyu 已提交
313 314
    indexes = empty_table_.PickToExecute(1);
    ASSERT_EQ(indexes.size(), 1);
315
    ASSERT_EQ(indexes[0] % empty_table_.capacity(), 2);
W
wxyu 已提交
316 317
}

W
wxyu 已提交
318 319 320
/************ TaskTableAdvanceTest ************/

class TaskTableAdvanceTest : public ::testing::Test {
S
starlord 已提交
321
 protected:
W
wxyu 已提交
322 323
    void
    SetUp() override {
S
starlord 已提交
324
        milvus::scheduler::TableFileSchemaPtr dummy = nullptr;
W
wxyu 已提交
325
        for (uint64_t i = 0; i < 8; ++i) {
S
starlord 已提交
326 327
            auto label = std::make_shared<milvus::scheduler::DefaultLabel>();
            auto task = std::make_shared<milvus::scheduler::TestTask>(dummy, label);
W
wxyu 已提交
328 329 330
            table1_.Put(task);
        }

331 332 333 334 335 336 337 338
        table1_.at(0)->state = milvus::scheduler::TaskTableItemState::INVALID;
        table1_.at(1)->state = milvus::scheduler::TaskTableItemState::START;
        table1_.at(2)->state = milvus::scheduler::TaskTableItemState::LOADING;
        table1_.at(3)->state = milvus::scheduler::TaskTableItemState::LOADED;
        table1_.at(4)->state = milvus::scheduler::TaskTableItemState::EXECUTING;
        table1_.at(5)->state = milvus::scheduler::TaskTableItemState::EXECUTED;
        table1_.at(6)->state = milvus::scheduler::TaskTableItemState::MOVING;
        table1_.at(7)->state = milvus::scheduler::TaskTableItemState::MOVED;
W
wxyu 已提交
339 340
    }

S
starlord 已提交
341
    milvus::scheduler::TaskTable table1_;
W
wxyu 已提交
342 343
};

S
starlord 已提交
344
TEST_F(TaskTableAdvanceTest, LOAD) {
S
starlord 已提交
345
    std::vector<milvus::scheduler::TaskTableItemState> before_state;
346
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
347
        before_state.push_back(table1_[i]->state);
W
wxyu 已提交
348 349
    }

350
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
351 352 353
        table1_.Load(i);
    }

354
    for (size_t i = 0; i < table1_.size(); ++i) {
S
starlord 已提交
355
        if (before_state[i] == milvus::scheduler::TaskTableItemState::START) {
356
            ASSERT_EQ(table1_.at(i)->state, milvus::scheduler::TaskTableItemState::LOADING);
W
wxyu 已提交
357
        } else {
358
            ASSERT_EQ(table1_.at(i)->state, before_state[i]);
W
wxyu 已提交
359 360 361 362
        }
    }
}

S
starlord 已提交
363
TEST_F(TaskTableAdvanceTest, LOADED) {
S
starlord 已提交
364
    std::vector<milvus::scheduler::TaskTableItemState> before_state;
365
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
366
        before_state.push_back(table1_[i]->state);
W
wxyu 已提交
367 368
    }

369
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
370 371
        table1_.Loaded(i);
    }
W
wxyu 已提交
372

373
    for (size_t i = 0; i < table1_.size(); ++i) {
S
starlord 已提交
374
        if (before_state[i] == milvus::scheduler::TaskTableItemState::LOADING) {
375
            ASSERT_EQ(table1_.at(i)->state, milvus::scheduler::TaskTableItemState::LOADED);
W
wxyu 已提交
376
        } else {
377
            ASSERT_EQ(table1_.at(i)->state, before_state[i]);
W
wxyu 已提交
378 379
        }
    }
W
wxyu 已提交
380 381
}

S
starlord 已提交
382
TEST_F(TaskTableAdvanceTest, EXECUTE) {
S
starlord 已提交
383
    std::vector<milvus::scheduler::TaskTableItemState> before_state;
384
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
385
        before_state.push_back(table1_[i]->state);
W
wxyu 已提交
386 387
    }

388
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
389 390
        table1_.Execute(i);
    }
W
wxyu 已提交
391

392
    for (size_t i = 0; i < table1_.size(); ++i) {
S
starlord 已提交
393
        if (before_state[i] == milvus::scheduler::TaskTableItemState::LOADED) {
394
            ASSERT_EQ(table1_.at(i)->state, milvus::scheduler::TaskTableItemState::EXECUTING);
W
wxyu 已提交
395
        } else {
396
            ASSERT_EQ(table1_.at(i)->state, before_state[i]);
W
wxyu 已提交
397 398 399 400
        }
    }
}

S
starlord 已提交
401
TEST_F(TaskTableAdvanceTest, EXECUTED) {
S
starlord 已提交
402
    std::vector<milvus::scheduler::TaskTableItemState> before_state;
403
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
404
        before_state.push_back(table1_[i]->state);
W
wxyu 已提交
405 406
    }

407
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
408 409 410
        table1_.Executed(i);
    }

411
    for (size_t i = 0; i < table1_.size(); ++i) {
S
starlord 已提交
412
        if (before_state[i] == milvus::scheduler::TaskTableItemState::EXECUTING) {
413
            ASSERT_EQ(table1_.at(i)->state, milvus::scheduler::TaskTableItemState::EXECUTED);
W
wxyu 已提交
414
        } else {
415
            ASSERT_EQ(table1_.at(i)->state, before_state[i]);
W
wxyu 已提交
416 417
        }
    }
W
wxyu 已提交
418 419
}

S
starlord 已提交
420
TEST_F(TaskTableAdvanceTest, MOVE) {
S
starlord 已提交
421
    std::vector<milvus::scheduler::TaskTableItemState> before_state;
422
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
423
        before_state.push_back(table1_[i]->state);
W
wxyu 已提交
424 425
    }

426
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
427 428 429
        table1_.Move(i);
    }

430
    for (size_t i = 0; i < table1_.size(); ++i) {
S
starlord 已提交
431
        if (before_state[i] == milvus::scheduler::TaskTableItemState::LOADED) {
432
            ASSERT_EQ(table1_.at(i)->state, milvus::scheduler::TaskTableItemState::MOVING);
W
wxyu 已提交
433
        } else {
434
            ASSERT_EQ(table1_.at(i)->state, before_state[i]);
W
wxyu 已提交
435 436 437
        }
    }
}
W
wxyu 已提交
438

S
starlord 已提交
439
TEST_F(TaskTableAdvanceTest, MOVED) {
S
starlord 已提交
440
    std::vector<milvus::scheduler::TaskTableItemState> before_state;
441
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
442
        before_state.push_back(table1_[i]->state);
W
wxyu 已提交
443 444
    }

445
    for (size_t i = 0; i < table1_.size(); ++i) {
W
wxyu 已提交
446 447 448
        table1_.Moved(i);
    }

449
    for (size_t i = 0; i < table1_.size(); ++i) {
S
starlord 已提交
450
        if (before_state[i] == milvus::scheduler::TaskTableItemState::MOVING) {
451
            ASSERT_EQ(table1_.at(i)->state, milvus::scheduler::TaskTableItemState::MOVED);
W
wxyu 已提交
452
        } else {
453
            ASSERT_EQ(table1_.at(i)->state, before_state[i]);
W
wxyu 已提交
454 455
        }
    }
W
wxyu 已提交
456
}