10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
- #include < memory>
14
-
15
- #include " catalog/catalog.h"
16
13
#include " common/harness.h"
17
- #include " concurrency/transaction_manager_factory.h"
18
14
#include " sql/testing_sql_util.h"
19
15
#include " settings/settings_manager.h"
20
16
#include " parser/pg_query.h"
21
- #include " threadpool/brain_thread_pool.h"
22
17
23
18
using std::vector;
24
19
using std::string;
@@ -33,11 +28,11 @@ class QueryLoggerTests : public PelotonTest {
33
28
PelotonInit::Initialize ();
34
29
35
30
// query to check that logging is done
36
- select_query =
31
+ select_query_ =
37
32
" SELECT query_string, fingerprint FROM pg_catalog.pg_query_history;" ;
38
- select_query_fingerprint =
39
- pg_query_fingerprint (select_query .c_str ()).hexdigest ;
40
- wait_time = 2 ;
33
+ select_query_fingerprint_ =
34
+ pg_query_fingerprint (select_query_ .c_str ()).hexdigest ;
35
+ wait_time_ = 2 ;
41
36
}
42
37
43
38
virtual void TearDown () override { PelotonInit::Shutdown (); }
@@ -52,13 +47,13 @@ class QueryLoggerTests : public PelotonTest {
52
47
TestingSQLUtil::ExecuteSQLQuery (test_query.c_str ());
53
48
54
49
// give some time to actually log this query
55
- sleep (wait_time );
50
+ sleep (wait_time_ );
56
51
57
- TestingSQLUtil::ExecuteSQLQueryAndCheckResult (select_query .c_str (),
52
+ TestingSQLUtil::ExecuteSQLQueryAndCheckResult (select_query_ .c_str (),
58
53
expected_result, true );
59
54
60
55
// the select query we used will also be logged for next time
61
- expected_result.push_back (select_query + " |" + select_query_fingerprint );
56
+ expected_result.push_back (select_query_ + " |" + select_query_fingerprint_ );
62
57
}
63
58
64
59
// Executes the given query and then checks if the queries that are executed
@@ -75,37 +70,40 @@ class QueryLoggerTests : public PelotonTest {
75
70
TestingSQLUtil::ExecuteSQLQuery (test_query.c_str ());
76
71
77
72
// give some time to actually log this query
78
- sleep (wait_time );
73
+ sleep (wait_time_ );
79
74
80
75
// only check once the the transaction has committed
81
76
if (committed) {
82
- // accounting for the select_query that happened before this txn
83
- expected_result.push_back (select_query + " |" + select_query_fingerprint);
77
+ // accounting for the select_query_ that happened before this txn
78
+ expected_result.push_back (select_query_ + " |" +
79
+ select_query_fingerprint_);
84
80
85
81
expected_result.insert (expected_result.end (),
86
82
temporary_expected_result.begin (),
87
83
temporary_expected_result.end ());
88
84
temporary_expected_result.clear ();
89
- TestingSQLUtil::ExecuteSQLQueryAndCheckResult (select_query .c_str (),
85
+ TestingSQLUtil::ExecuteSQLQueryAndCheckResult (select_query_ .c_str (),
90
86
expected_result, true );
91
87
92
88
// the select query we used will also be logged for next time
93
- expected_result.push_back (select_query + " |" + select_query_fingerprint);
89
+ expected_result.push_back (select_query_ + " |" +
90
+ select_query_fingerprint_);
94
91
95
92
} else {
96
93
// verify that the logging does not happen before the txn commit
97
- TestingSQLUtil::ExecuteSQLQueryAndCheckResult (select_query .c_str (),
94
+ TestingSQLUtil::ExecuteSQLQueryAndCheckResult (select_query_ .c_str (),
98
95
expected_result, true );
99
96
// the select query we used will also be logged for next time
100
- temporary_expected_result.push_back (select_query + " |" +
101
- select_query_fingerprint );
97
+ temporary_expected_result.push_back (select_query_ + " |" +
98
+ select_query_fingerprint_ );
102
99
}
103
100
}
104
101
105
102
protected:
106
- string select_query; // fixed query to check the queries logged in the table
107
- string select_query_fingerprint; // fingerprint for the fixed query
108
- int wait_time; // time to wait in seconds for the query to log into the table
103
+ string select_query_; // fixed query to check the queries logged in the table
104
+ string select_query_fingerprint_; // fingerprint for the fixed query
105
+ int wait_time_; // time to wait in seconds for the query to log into the
106
+ // table
109
107
};
110
108
111
109
// Testing the functionality of query logging
@@ -117,16 +115,17 @@ TEST_F(QueryLoggerTests, QueriesTest) {
117
115
TestSimpleUtil (" INSERT INTO test VALUES (1);" , expected_result);
118
116
TestSimpleUtil (" INSERT INTO test VALUES (2);" , expected_result);
119
117
120
- expected_result.pop_back (); // the select_query done at the end of above test
121
- // won't be logged till the txn below commits
118
+ expected_result
119
+ .pop_back (); // the select_query_ done at the end of above test
120
+ // won't be logged till the txn below commits
122
121
123
122
// check if the queries are logged only when the transaction actually commits
124
123
TestTransactionUtil (" BEGIN;" , expected_result, false );
125
124
TestTransactionUtil (" INSERT INTO test VALUES (1);" , expected_result, false );
126
125
TestTransactionUtil (" COMMIT;" , expected_result, true );
127
126
128
127
// final check to see if everything is ok
129
- TestSimpleUtil (select_query , expected_result);
128
+ TestSimpleUtil (select_query_ , expected_result);
130
129
}
131
130
132
131
} // namespace test
0 commit comments