forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_task_info.cpp
More file actions
133 lines (115 loc) · 3.33 KB
/
Copy pathtest_task_info.cpp
File metadata and controls
133 lines (115 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* 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 <gtest/gtest.h>
#include "sql/executor/ob_task_info.h"
#include "sql/executor/ob_fifo_receive.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;
class ObTaskInfoTest : public ::testing::Test
{
public:
ObTaskInfoTest();
virtual ~ObTaskInfoTest();
virtual void SetUp();
virtual void TearDown();
void MakeSliceID(ObSliceID &slice_id) {
int64_t valid_id_a = 1012;
int64_t valid_id_b = 13012;
int64_t valid_id_c = 130120;
int64_t valid_id_d = 1;
ObAddr server(ObAddr::IPV4, "127.0.0.1", 8080);
slice_id.set_execution_id(valid_id_a);
slice_id.set_job_id(valid_id_b);
slice_id.set_task_id(valid_id_c);
slice_id.set_slice_id(valid_id_d);
slice_id.set_server(server);
}
void MakeTaskID(ObTaskID &task_id, int64_t a, int64_t b=1001, int64_t c=1002, int64_t d=1) {
task_id.set_execution_id(a);
task_id.set_job_id(b);
task_id.set_task_id(c);
task_id.set_task_id(d);
}
void MakeServer(ObAddr &svr) {
ObAddr server(ObAddr::IPV4, "127.0.0.1", 8080);
svr = server;
}
void MakeTaskID(ObTaskID &task_id) {
int64_t valid_id_a = 1012;
int64_t valid_id_b = 13012;
int64_t valid_id_c = 130120;
int64_t valid_id_d = 1;
task_id.set_execution_id(valid_id_a);
task_id.set_job_id(valid_id_b);
task_id.set_task_id(valid_id_c);
task_id.set_task_id(valid_id_d);
}
private:
// disallow copy
ObTaskInfoTest(const ObTaskInfoTest &other);
ObTaskInfoTest& operator=(const ObTaskInfoTest &other);
private:
// data members
};
ObTaskInfoTest::ObTaskInfoTest()
{
}
ObTaskInfoTest::~ObTaskInfoTest()
{
}
void ObTaskInfoTest::SetUp()
{
}
void ObTaskInfoTest::TearDown()
{
}
TEST_F(ObTaskInfoTest, all_test)
{
ObArenaAllocator allocator(ObModIds::TEST);
ObTaskInfo ti(allocator);
// state test
ASSERT_TRUE(OB_TASK_STATE_NOT_INIT == ti.get_state());
ti.set_state(OB_TASK_STATE_INITED);
ASSERT_TRUE(OB_TASK_STATE_INITED == ti.get_state());
ObArenaAllocator alloc;
// root op test
ObPhyOperator *op = new ObFifoReceive(alloc);
ASSERT_TRUE(NULL == ti.get_root_op());
ti.set_root_op(op);
ASSERT_TRUE(op == ti.get_root_op());
// range test
// TODO
//
// location test
ObTaskLocation loc;
ObAddr server;
ObTaskID task_id;
ObTaskLocation loc_tmp;
ObAddr server_tmp;
ObTaskID task_id_tmp;
this->MakeTaskID(task_id);
this->MakeServer(server);
loc.set_ob_task_id(task_id);
loc.set_server(server);
ti.set_task_location(loc);
loc_tmp = ti.get_task_location();
task_id_tmp = loc_tmp.get_ob_task_id();
server_tmp = loc_tmp.get_server();
ASSERT_TRUE(task_id_tmp.equal(task_id));
ASSERT_TRUE(server.hash() == server_tmp.hash());
}
int main(int argc, char **argv)
{
oceanbase::common::ObLogger::get_logger().set_log_level("INFO");
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}