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/parallel_executor.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 = -1; |
30 | const int kMillSeconds = 100; |
31 | |
32 | TEST(SchedulerTest, TestScheduler) { |
33 | SchedulerPtr scheduler = Scheduler::Default(); |
34 | uint32_t concurrency = Scheduler::HostConcurrency(); |
35 | ASSERT_EQ(scheduler->concurrency(concurrency), concurrency); |
36 | |
37 | ExecutorPtr executor = ExecutorPtr(new ParallelExecutor(scheduler)); |
38 | |
39 | TaskPtr task = CreateTask(kName, kCode, kMillSeconds); |
40 | TaskPtr task2 = CreateTask(kName, kCode, kMillSeconds); |
41 | |
42 | // invoke task->run in current routine |
43 | ASSERT_EQ(executor->execute_task(task), kCode); |
44 | |
45 | ASSERT_TRUE(task->finished()); |
46 | |
47 | TaskPtrList tasks = {task2, CreateTask(kName, kCode, kMillSeconds), |
48 | CreateTask(kName, kCode, kMillSeconds)}; |
49 | |
50 | executor->execute_tasks(tasks); |
51 | |
52 | ASSERT_TRUE(task2->finished()); |
53 | } |
54 | |