forked from cmu-db/peloton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
append_test.cpp
110 lines (81 loc) · 3.06 KB
/
append_test.cpp
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
//===----------------------------------------------------------------------===//
//
// Peloton
//
// append_test.cpp
//
// Identification: test/executor/append_test.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//
#include <vector>
#include "executor/testing_executor_util.h"
#include "common/harness.h"
#include "planner/append_plan.h"
#include "common/internal_types.h"
#include "executor/logical_tile.h"
#include "executor/logical_tile_factory.h"
#include "executor/append_executor.h"
#include "storage/data_table.h"
#include "concurrency/transaction_manager_factory.h"
#include "executor/mock_executor.h"
using ::testing::NotNull;
using ::testing::Return;
namespace peloton {
namespace test {
namespace {
class AppendTests : public PelotonTest {};
void RunTest(executor::AppendExecutor &executor, size_t expected_num_tuples) {
EXPECT_TRUE(executor.Init());
std::vector<std::unique_ptr<executor::LogicalTile>> result_tiles;
while (executor.Execute()) {
result_tiles.emplace_back(executor.GetOutput());
}
size_t actual_num_tuples_returned = 0;
for (auto &tile : result_tiles) {
actual_num_tuples_returned += tile->GetTupleCount();
}
EXPECT_EQ(expected_num_tuples, actual_num_tuples_returned);
}
TEST_F(AppendTests, AppendTwoTest) {
// Create the plan node
planner::AppendPlan node;
// Create and set up executor
executor::AppendExecutor executor(&node, nullptr);
MockExecutor child_executor1;
MockExecutor child_executor2;
executor.AddChild(&child_executor1);
executor.AddChild(&child_executor2);
EXPECT_CALL(child_executor1, DInit()).WillOnce(Return(true));
EXPECT_CALL(child_executor2, DInit()).WillOnce(Return(true));
EXPECT_CALL(child_executor1, DExecute())
.WillOnce(Return(true))
.WillOnce(Return(false));
EXPECT_CALL(child_executor2, DExecute())
.WillOnce(Return(true))
.WillOnce(Return(true))
.WillOnce(Return(false));
size_t tile_size = 10;
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
auto txn = txn_manager.BeginTransaction();
std::unique_ptr<storage::DataTable> data_table(
TestingExecutorUtil::CreateTable(tile_size));
TestingExecutorUtil::PopulateTable(data_table.get(), tile_size * 10, false,
false, false, txn);
txn_manager.CommitTransaction(txn);
std::unique_ptr<executor::LogicalTile> ltile0(
executor::LogicalTileFactory::WrapTileGroup(data_table->GetTileGroup(0)));
std::unique_ptr<executor::LogicalTile> ltile1(
executor::LogicalTileFactory::WrapTileGroup(data_table->GetTileGroup(1)));
std::unique_ptr<executor::LogicalTile> ltile2(
executor::LogicalTileFactory::WrapTileGroup(data_table->GetTileGroup(2)));
EXPECT_CALL(child_executor1, GetOutput()).WillOnce(Return(ltile0.release()));
EXPECT_CALL(child_executor2, GetOutput())
.WillOnce(Return(ltile1.release()))
.WillOnce(Return(ltile2.release()));
RunTest(executor, tile_size * 3);
}
}
}
}