2
* Copyright (c) 2021 OceanBase
3
* OceanBase CE is licensed under Mulan PubL v2.
4
* You can use this software according to the terms and conditions of the Mulan PubL v2.
5
* You may obtain a copy of Mulan PubL v2 at:
6
* http://license.coscl.org.cn/MulanPubL-2.0
7
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
* See the Mulan PubL v2 for more details.
15
#include "gtest/gtest.h"
16
#include "lib/allocator/ob_malloc.h"
17
#include "lib/allocator/ob_concurrent_fifo_allocator.h"
19
#include "logservice/libobcdc/src/ob_log_task_pool.h"
21
using namespace oceanbase;
22
using namespace common;
23
using namespace libobcdc;
30
class MockTransTask : public TransTaskBase<MockTransTask>
33
void foo() { bar_ += 1; }
35
void set_allocator(int64_t page_size, common::ObIAllocator &large_allocator)
38
UNUSED(large_allocator);
41
void set_prealloc_page(void *page)
46
void revert_prealloc_page(void *page)
51
void set_task_info(const logservice::TenantLSID &tls_id,
52
const char *tls_id_str)
62
TEST(ObLogTransTaskPool, Init)
64
const int64_t part_trans_task_prealloc_count = 300000;
65
const int64_t page_size = 8 * 1024;
66
const int64_t prealloc_page_count = 20000;
68
ObConcurrentFIFOAllocator fifo;
69
int64_t G = 1024 * 1024 * 1024;
70
fifo.init(1 * G, 1 * G, OB_MALLOC_BIG_BLOCK_SIZE);
72
ObLogTransTaskPool<MockTransTask> pool;
74
int ret = pool.init(&fifo, part_trans_task_prealloc_count, true, prealloc_page_count);
75
EXPECT_EQ(OB_SUCCESS, ret);
78
TEST(ObLogTransTaskPool, Function1)
80
const int64_t task_cnt = 1024 * 32;
82
ObConcurrentFIFOAllocator fifo;
83
int64_t G = 1024 * 1024 * 1024;
84
fifo.init(1 * G, 1 * G, OB_MALLOC_BIG_BLOCK_SIZE);
86
ObLogTransTaskPool<MockTransTask> pool;
88
int ret = pool.init(&fifo, 1024 * 8, true, 1024);
89
EXPECT_EQ(OB_SUCCESS, ret);
91
MockTransTask **tasks = new MockTransTask*[task_cnt];
92
const char *tls_info = "tenant_ls_id";
93
logservice::TenantLSID tls_id;
95
for (int64_t idx = 0; idx < task_cnt; ++idx) {
96
tasks[idx] = pool.get(tls_info, tls_id);
97
EXPECT_TRUE(NULL != tasks[idx]);
100
for (int64_t idx = 0; idx < task_cnt; ++idx) {
101
tasks[idx]->revert();
110
// 2 tasks not returned.
111
TEST(ObLogTransTaskPool, Function2)
113
const int64_t task_cnt = 1024 * 32;
115
ObConcurrentFIFOAllocator fifo;
116
int64_t G = 1024 * 1024 * 1024;
117
fifo.init(1 * G, 1 * G, OB_MALLOC_BIG_BLOCK_SIZE);
119
ObLogTransTaskPool<MockTransTask> pool;
121
int ret = pool.init(&fifo, 1024 * 8, true, 1024);
122
EXPECT_EQ(OB_SUCCESS, ret);
124
MockTransTask **tasks = new MockTransTask*[task_cnt];
125
const char *tls_info = "partition";
126
logservice::TenantLSID tls_id;
128
for (int64_t idx = 0; idx < task_cnt; ++idx) {
129
tasks[idx] = pool.get(tls_info, tls_id);
130
EXPECT_TRUE(NULL != tasks[idx]);
133
for (int64_t idx = 0; idx < task_cnt - 2; ++idx) {
134
tasks[idx + 1]->revert();
147
int main(int argc, char **argv)
149
oceanbase::common::ObLogger::get_logger().set_log_level("debug");
150
testing::InitGoogleTest(&argc,argv);
151
// testing::FLAGS_gtest_filter = "DO_NOT_RUN";
152
return RUN_ALL_TESTS();