oceanbase

Форк
0
/
test_log_task_pool.cpp 
153 строки · 3.5 Кб
1
/**
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.
11
 */
12

13
#include <cstdlib>
14

15
#include "gtest/gtest.h"
16
#include "lib/allocator/ob_malloc.h"
17
#include "lib/allocator/ob_concurrent_fifo_allocator.h"
18

19
#include "logservice/libobcdc/src/ob_log_task_pool.h"
20

21
using namespace oceanbase;
22
using namespace common;
23
using namespace libobcdc;
24

25
namespace oceanbase
26
{
27
namespace unittest
28
{
29

30
class MockTransTask : public TransTaskBase<MockTransTask>
31
{
32
public:
33
  void foo() { bar_ += 1; }
34

35
  void set_allocator(int64_t page_size, common::ObIAllocator &large_allocator)
36
  {
37
    UNUSED(page_size);
38
    UNUSED(large_allocator);
39
  }
40

41
  void set_prealloc_page(void *page)
42
  {
43
    UNUSED(page);
44
  }
45

46
  void revert_prealloc_page(void *page)
47
  {
48
    UNUSED(page);
49
  }
50

51
  void set_task_info(const logservice::TenantLSID &tls_id,
52
      const char *tls_id_str)
53
  {
54
    UNUSED(tls_id);
55
    UNUSED(tls_id_str);
56
  }
57

58
private:
59
  int64_t bar_;
60
};
61

62
TEST(ObLogTransTaskPool, Init)
63
{
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;
67

68
  ObConcurrentFIFOAllocator fifo;
69
  int64_t G = 1024 * 1024 * 1024;
70
  fifo.init(1 * G, 1 * G, OB_MALLOC_BIG_BLOCK_SIZE);
71

72
  ObLogTransTaskPool<MockTransTask> pool;
73

74
  int ret = pool.init(&fifo, part_trans_task_prealloc_count, true, prealloc_page_count);
75
  EXPECT_EQ(OB_SUCCESS, ret);
76
}
77

78
TEST(ObLogTransTaskPool, Function1)
79
{
80
  const int64_t task_cnt = 1024 * 32;
81

82
  ObConcurrentFIFOAllocator fifo;
83
  int64_t G = 1024 * 1024 * 1024;
84
  fifo.init(1 * G, 1 * G, OB_MALLOC_BIG_BLOCK_SIZE);
85

86
  ObLogTransTaskPool<MockTransTask> pool;
87

88
  int ret = pool.init(&fifo, 1024 * 8, true, 1024);
89
  EXPECT_EQ(OB_SUCCESS, ret);
90

91
  MockTransTask **tasks = new MockTransTask*[task_cnt];
92
  const char *tls_info = "tenant_ls_id";
93
  logservice::TenantLSID tls_id;
94

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]);
98
  }
99

100
  for (int64_t idx = 0; idx < task_cnt; ++idx) {
101
    tasks[idx]->revert();
102
  }
103

104
  pool.destroy();
105

106
  delete []tasks;
107
  fifo.destroy();
108
}
109

110
// 2 tasks not returned.
111
TEST(ObLogTransTaskPool, Function2)
112
{
113
  const int64_t task_cnt = 1024 * 32;
114

115
  ObConcurrentFIFOAllocator fifo;
116
  int64_t G = 1024 * 1024 * 1024;
117
  fifo.init(1 * G, 1 * G, OB_MALLOC_BIG_BLOCK_SIZE);
118

119
  ObLogTransTaskPool<MockTransTask> pool;
120

121
  int ret = pool.init(&fifo, 1024 * 8, true, 1024);
122
  EXPECT_EQ(OB_SUCCESS, ret);
123

124
  MockTransTask **tasks = new MockTransTask*[task_cnt];
125
  const char *tls_info = "partition";
126
  logservice::TenantLSID tls_id;
127

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]);
131
  }
132

133
  for (int64_t idx = 0; idx < task_cnt - 2; ++idx) {
134
    tasks[idx + 1]->revert();
135
  }
136

137
  pool.destroy();
138

139
  delete []tasks;
140
  fifo.destroy();
141
}
142

143

144
}
145
}
146

147
int main(int argc, char **argv)
148
{
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();
153
}
154

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.