Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit a11e589

Browse files
Fixed the tests
1 parent 87adece commit a11e589

File tree

1 file changed

+43
-48
lines changed

1 file changed

+43
-48
lines changed

test/brain/query_logger_test.cpp

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,73 +29,68 @@ namespace test {
2929
class QueryLoggerTests : public PelotonTest {
3030
protected:
3131
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();
3734
}
3835

3936
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();
7638
}
7739
};
7840

7941
TEST_F(QueryLoggerTests, SimpleInsertsTest) {
8042
std::vector<std::string> expected_result;
8143
std::string test_query;
8244
std::string test_query_fingerprint;
45+
std::vector<ResultValue> result;
8346
std::string select_query =
84-
"SELECT query_string, fingerprint FROM pg_catalog.pg_query_history;";
47+
"SELECT * FROM pg_catalog.pg_query_history;";
8548
std::string select_query_fingerprint =
8649
pg_query_fingerprint(select_query.c_str()).hexdigest;
8750

88-
test_query = "CREATE TABLE test(a INT PRIMARY KEY, b INT);";
51+
test_query = "CREATE TABLE test(a INT);";
8952
test_query_fingerprint = pg_query_fingerprint(test_query.c_str()).hexdigest;
9053

9154
expected_result.push_back(test_query + "|" + test_query_fingerprint);
9255

9356
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());
9994
}
10095

10196
} // namespace test

0 commit comments

Comments
 (0)