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 Nov 2020 |
18 | * \brief |
19 | */ |
20 | |
21 | #include "query/executor/scheduler.h" |
22 | #include <gtest/gtest.h> |
23 | #include "task-inl.h" |
24 | |
25 | using namespace proxima::be::query; |
26 | using namespace proxima::be::query::test; |
27 | |
28 | const std::string kName("task name" ); |
29 | const int kCode = 0; |
30 | const int kMillSeconds = 100; |
31 | |
32 | TEST(SchedulerTest, TestScheduler) { |
33 | SchedulerPtr scheduler = Scheduler::Default(); |
34 | TaskPtr task = CreateTask(kName, kCode, kMillSeconds); |
35 | |
36 | ASSERT_EQ(scheduler->concurrency(), 0); |
37 | |
38 | // Can't schedule an task before set concurrency |
39 | ASSERT_TRUE(scheduler->schedule(task) != 0); |
40 | |
41 | uint32_t concurrency = Scheduler::HostConcurrency(); |
42 | ASSERT_EQ(scheduler->concurrency(concurrency), concurrency); |
43 | |
44 | ASSERT_EQ(scheduler->schedule(task), 0); |
45 | |
46 | ASSERT_TRUE(task->wait_finish()); |
47 | } |
48 | |