|
23 | 23 | #include "concurrency/transaction_manager_factory.h"
|
24 | 24 | #include "storage/storage_manager.h"
|
25 | 25 | #include "type/ephemeral_pool.h"
|
| 26 | +#include "sql/testing_sql_util.h" |
26 | 27 |
|
27 | 28 | namespace peloton {
|
28 | 29 | namespace test {
|
@@ -116,40 +117,6 @@ TEST_F(CatalogTests, CreatingTable) {
|
116 | 117 | ->GetColumnObject(1)
|
117 | 118 | ->GetColumnName());
|
118 | 119 | txn_manager.CommitTransaction(txn);
|
119 |
| - // EXPECT_EQ(5, time_stamp); |
120 |
| - |
121 |
| - // We remove these tests so people can add new catalogs without breaking this |
122 |
| - // test... |
123 |
| - // 3 + 4 |
124 |
| - // EXPECT_EQ(catalog::Catalog::GetInstance() |
125 |
| - // ->GetDatabaseWithName("pg_catalog") |
126 |
| - // ->GetTableWithName("pg_table") |
127 |
| - // ->GetTupleCount(), |
128 |
| - // 11); |
129 |
| - // // 6 + pg_database(2) + pg_table(3) + pg_attribute(7) + pg_index(6) |
130 |
| - // EXPECT_EQ(catalog::Catalog::GetInstance() |
131 |
| - // ->GetDatabaseWithName("pg_catalog") |
132 |
| - // ->GetTableWithName("pg_attribute") |
133 |
| - // ->GetTupleCount(), |
134 |
| - // 57); |
135 |
| - // // pg_catalog + emp_db |
136 |
| - // EXPECT_EQ(catalog::Catalog::GetInstance() |
137 |
| - // ->GetDatabaseWithName("pg_catalog") |
138 |
| - // ->GetTableWithName("pg_database") |
139 |
| - // ->GetTupleCount(), |
140 |
| - // 2); |
141 |
| - // // 3 + pg_index(3) + pg_attribute(3) + pg_table(3) + pg_database(2) |
142 |
| - // EXPECT_EQ(catalog::Catalog::GetInstance() |
143 |
| - // ->GetDatabaseWithName("pg_catalog") |
144 |
| - // ->GetTableWithName("pg_index") |
145 |
| - // ->GetTupleCount(), |
146 |
| - // 18); |
147 |
| - // EXPECT_EQ(catalog::Catalog::GetInstance() |
148 |
| - // ->GetDatabaseWithName("pg_catalog") |
149 |
| - // ->GetTableWithName("pg_table") |
150 |
| - // ->GetSchema() |
151 |
| - // ->GetLength(), |
152 |
| - // 72); |
153 | 120 | }
|
154 | 121 |
|
155 | 122 | TEST_F(CatalogTests, TableObject) {
|
@@ -200,6 +167,69 @@ TEST_F(CatalogTests, TableObject) {
|
200 | 167 | txn_manager.CommitTransaction(txn);
|
201 | 168 | }
|
202 | 169 |
|
| 170 | +TEST_F(CatalogTests, TestingNamespace) { |
| 171 | + EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("begin;")); |
| 172 | + // create namespaces emp_ns0 and emp_ns1 |
| 173 | + EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery( |
| 174 | + "create database default_database;")); |
| 175 | + EXPECT_EQ(ResultType::SUCCESS, |
| 176 | + TestingSQLUtil::ExecuteSQLQuery("create schema emp_ns0;")); |
| 177 | + EXPECT_EQ(ResultType::SUCCESS, |
| 178 | + TestingSQLUtil::ExecuteSQLQuery("create schema emp_ns1;")); |
| 179 | + |
| 180 | + // create emp_table0 and emp_table1 in namespaces |
| 181 | + EXPECT_EQ(ResultType::SUCCESS, |
| 182 | + TestingSQLUtil::ExecuteSQLQuery( |
| 183 | + "create table emp_ns0.emp_table0 (a int, b varchar);")); |
| 184 | + EXPECT_EQ(ResultType::SUCCESS, |
| 185 | + TestingSQLUtil::ExecuteSQLQuery( |
| 186 | + "create table emp_ns0.emp_table1 (a int, b varchar);")); |
| 187 | + EXPECT_EQ(ResultType::SUCCESS, |
| 188 | + TestingSQLUtil::ExecuteSQLQuery( |
| 189 | + "create table emp_ns1.emp_table0 (a int, b varchar);")); |
| 190 | + EXPECT_EQ(ResultType::FAILURE, |
| 191 | + TestingSQLUtil::ExecuteSQLQuery( |
| 192 | + "create table emp_ns1.emp_table0 (a int, b varchar);")); |
| 193 | + |
| 194 | + // insert values into emp_table0 |
| 195 | + EXPECT_EQ(ResultType::SUCCESS, |
| 196 | + TestingSQLUtil::ExecuteSQLQuery( |
| 197 | + "insert into emp_ns0.emp_table0 values (1, 'abc');")); |
| 198 | + EXPECT_EQ(ResultType::SUCCESS, |
| 199 | + TestingSQLUtil::ExecuteSQLQuery( |
| 200 | + "insert into emp_ns0.emp_table0 values (2, 'abc');")); |
| 201 | + EXPECT_EQ(ResultType::SUCCESS, |
| 202 | + TestingSQLUtil::ExecuteSQLQuery( |
| 203 | + "insert into emp_ns1.emp_table0 values (1, 'abc');")); |
| 204 | + |
| 205 | + // select values from emp_table0 and emp_table1 |
| 206 | + TestingSQLUtil::ExecuteSQLQueryAndCheckResult( |
| 207 | + "select * from emp_ns0.emp_table1;", {}); |
| 208 | + TestingSQLUtil::ExecuteSQLQueryAndCheckResult( |
| 209 | + "select * from emp_ns0.emp_table0;", {"1|abc", "2|abc"}); |
| 210 | + TestingSQLUtil::ExecuteSQLQueryAndCheckResult( |
| 211 | + "select * from emp_ns1.emp_table0;", {"1|abc"}); |
| 212 | + EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("commit;")); |
| 213 | + EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("begin;")); |
| 214 | + EXPECT_EQ(ResultType::FAILURE, TestingSQLUtil::ExecuteSQLQuery( |
| 215 | + "select * from emp_ns1.emp_table1;")); |
| 216 | + EXPECT_EQ(ResultType::ABORTED, TestingSQLUtil::ExecuteSQLQuery("commit;")); |
| 217 | + |
| 218 | + // drop namespace emp_ns0 and emp_ns1 |
| 219 | + EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("begin;")); |
| 220 | + EXPECT_EQ(ResultType::SUCCESS, |
| 221 | + TestingSQLUtil::ExecuteSQLQuery("drop schema emp_ns0;")); |
| 222 | + TestingSQLUtil::ExecuteSQLQueryAndCheckResult( |
| 223 | + "select * from emp_ns1.emp_table0;", {"1|abc"}); |
| 224 | + EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("commit;")); |
| 225 | + EXPECT_EQ(ResultType::SUCCESS, TestingSQLUtil::ExecuteSQLQuery("begin;")); |
| 226 | + EXPECT_EQ(ResultType::FAILURE, |
| 227 | + TestingSQLUtil::ExecuteSQLQuery("drop schema emp_ns0;")); |
| 228 | + EXPECT_EQ(ResultType::FAILURE, TestingSQLUtil::ExecuteSQLQuery( |
| 229 | + "select * from emp_ns0.emp_table1;")); |
| 230 | + EXPECT_EQ(ResultType::ABORTED, TestingSQLUtil::ExecuteSQLQuery("commit;")); |
| 231 | +} |
| 232 | + |
203 | 233 | TEST_F(CatalogTests, DroppingTable) {
|
204 | 234 | auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
|
205 | 235 | auto txn = txn_manager.BeginTransaction();
|
|
0 commit comments