@@ -29,73 +29,68 @@ namespace test {
29
29
class QueryLoggerTests : public PelotonTest {
30
30
protected:
31
31
virtual void SetUp () override {
32
- // Call parent virtual function first
33
- PelotonTest::SetUp ();
34
-
35
- // Create test database
36
- CreateAndLoadTable ();
32
+ settings::SettingsManager::SetBool (settings::SettingId::brain, true );
33
+ PelotonInit::Initialize ();
37
34
}
38
35
39
36
virtual void TearDown () override {
40
- // Destroy test database
41
- auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
42
- auto txn = txn_manager.BeginTransaction ();
43
- catalog::Catalog::GetInstance ()->DropDatabaseWithName (DEFAULT_DB_NAME, txn);
44
- txn_manager.CommitTransaction (txn);
45
-
46
- // Call parent virtual function
47
- PelotonTest::TearDown ();
48
- }
49
-
50
- /* ** Helper functions **/
51
- void CreateAndLoadTable () {
52
- // Create database
53
- // auto &txn_manager =
54
- // concurrency::TransactionManagerFactory::GetInstance();
55
- // auto txn = txn_manager.BeginTransaction();
56
- // catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, txn);
57
- // txn_manager.CommitTransaction(txn);
58
-
59
- PelotonInit::Initialize ();
60
- // TODO (Priyatham and Siva): Figure out why this is not working
61
- // settings::SettingsManager::SetBool(settings::SettingId::brain, true);
62
- // threadpool::BrainThreadPool::GetInstance().Startup();
63
-
64
- // auto catalog = catalog::Catalog::GetInstance();
65
- // catalog->Bootstrap();
66
- // // set max thread number.
67
- // thread_pool.Initialize(0, std::thread::hardware_concurrency() + 3);
68
-
69
- // threadpool::BrainThreadPool::GetInstance().Startup();
70
-
71
- // // start epoch.
72
- // concurrency::EpochManagerFactory::GetInstance().StartEpoch();
73
-
74
- // // start GC.
75
- // gc::GCManagerFactory::GetInstance().StartGC();
37
+ PelotonInit::Shutdown ();
76
38
}
77
39
};
78
40
79
41
TEST_F (QueryLoggerTests, SimpleInsertsTest) {
80
42
std::vector<std::string> expected_result;
81
43
std::string test_query;
82
44
std::string test_query_fingerprint;
45
+ std::vector<ResultValue> result;
83
46
std::string select_query =
84
- " SELECT query_string, fingerprint FROM pg_catalog.pg_query_history;" ;
47
+ " SELECT * FROM pg_catalog.pg_query_history;" ;
85
48
std::string select_query_fingerprint =
86
49
pg_query_fingerprint (select_query.c_str ()).hexdigest ;
87
50
88
- test_query = " CREATE TABLE test(a INT PRIMARY KEY, b INT );" ;
51
+ test_query = " CREATE TABLE test(a INT);" ;
89
52
test_query_fingerprint = pg_query_fingerprint (test_query.c_str ()).hexdigest ;
90
53
91
54
expected_result.push_back (test_query + " |" + test_query_fingerprint);
92
55
93
56
TestingSQLUtil::ExecuteSQLQuery (test_query.c_str ());
94
- bool check = settings::SettingsManager::GetBool (settings::SettingId::brain);
95
- LOG_INFO (" Boolean: %d" , check);
96
- sleep (5 );
97
- TestingSQLUtil::ExecuteSQLQueryAndCheckResult (select_query.c_str (),
98
- expected_result, false );
57
+ // bool check = settings::SettingsManager::GetBool(settings::SettingId::brain);
58
+
59
+ test_query = " INSERT INTO test VALUES (11);" ;
60
+ test_query_fingerprint = pg_query_fingerprint (test_query.c_str ()).hexdigest ;
61
+
62
+ expected_result.push_back (test_query + " |" + test_query_fingerprint);
63
+
64
+ TestingSQLUtil::ExecuteSQLQuery (test_query.c_str ());
65
+ // check = settings::SettingsManager::GetBool(settings::SettingId::brain);
66
+
67
+ test_query = " SELECT * FROM test;" ;
68
+ test_query_fingerprint = pg_query_fingerprint (test_query.c_str ()).hexdigest ;
69
+
70
+ expected_result.push_back (test_query + " |" + test_query_fingerprint);
71
+
72
+ TestingSQLUtil::ExecuteSQLQuery (test_query.c_str (), result);
73
+ LOG_INFO (" SELECT RESULT SIZE: %lu" , result.size ());
74
+ LOG_INFO (" SELECT RESULT VALUE: %s" , TestingSQLUtil::GetResultValueAsString (result, 0 ).c_str ());
75
+ // check = settings::SettingsManager::GetBool(settings::SettingId::brain);
76
+
77
+
78
+ test_query = " SELECT * FROM pg_catalog.pg_table WHERE table_name = 'pg_query_history';" ;
79
+ test_query_fingerprint = pg_query_fingerprint (test_query.c_str ()).hexdigest ;
80
+
81
+ expected_result.push_back (test_query + " |" + test_query_fingerprint);
82
+
83
+ TestingSQLUtil::ExecuteSQLQuery (test_query.c_str (), result);
84
+ LOG_INFO (" SELECT CATALOG RESULT SIZE: %lu" , result.size ());
85
+ LOG_INFO (" SELECT CATALOG RESULT VALUE: %s" , TestingSQLUtil::GetResultValueAsString (result, 1 ).c_str ());
86
+
87
+ sleep (2 );
88
+
89
+ result.clear ();
90
+
91
+ TestingSQLUtil::ExecuteSQLQuery (select_query.c_str (), result);
92
+
93
+ LOG_INFO (" RESULT SIZE: %lu" , result.size ());
99
94
}
100
95
101
96
} // namespace test
0 commit comments