/** * Copyright (c) 2021 OceanBase * OceanBase CE is licensed under Mulan PubL v2. * You can use this software according to the terms and conditions of the Mulan PubL v2. * You may obtain a copy of Mulan PubL v2 at: * http://license.coscl.org.cn/MulanPubL-2.0 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PubL v2 for more details. */ #include #define private public #include "lib/task/ob_timer.h" #undef private using namespace oceanbase::lib; namespace oceanbase { namespace common { class TestTimerTask : public ObTimerTask { public: TestTimerTask() : running_(false), task_run_count_(0) {} void runTimerTask() { running_ = true; ++task_run_count_; ::usleep(50000);//50ms running_ = false; } volatile bool running_; int64_t task_run_count_; }; TEST(TestTimer, timer_task) { TestTimerTask task[ObTimer::MAX_TASK_NUM + 1]; ObTimer timer; ASSERT_EQ(OB_SUCCESS, timer.init()); ASSERT_EQ(OB_SUCCESS, timer.start()); const bool is_repeat = true; ASSERT_EQ(OB_SUCCESS, timer.schedule(task[0], 100, is_repeat)); for(int i=1; i