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

Commit a72f2e9

Browse files
schedutronapavlo
authored andcommitted
Add test for bad insert
1 parent 6465c91 commit a72f2e9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/include/common/exception.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class Exception : public std::runtime_error {
130130
}
131131
}
132132

133+
ExceptionType GetType() { return type; }
134+
133135
// Based on :: http://panthema.net/2008/0901-stacktrace-demangled/
134136
static void PrintStackTrace(FILE *out = ::stderr,
135137
unsigned int max_frames = 63) {

test/sql/insert_sql_test.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,5 +570,34 @@ TEST_F(InsertSQLTests, UniqueColumn) {
570570
txn_manager.CommitTransaction(txn);
571571
}
572572

573+
TEST_F(InsertSQLTests, NonExistentTable){
574+
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
575+
auto txn = txn_manager.BeginTransaction();
576+
catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, txn);
577+
txn_manager.CommitTransaction(txn);
578+
std::string error_message;
579+
int rows_changed;
580+
std::unique_ptr<optimizer::AbstractOptimizer> optimizer(
581+
new optimizer::Optimizer());
582+
583+
rows_changed = 0;
584+
EXPECT_THROW({
585+
try {
586+
// Insert an int into a non-existent table.
587+
std::string query("INSERT INTO NotExistTestTable VALUES(3);");
588+
txn = txn_manager.BeginTransaction();
589+
auto plan = TestingSQLUtil::GeneratePlanWithOptimizer(optimizer, query, txn);
590+
EXPECT_EQ(plan->GetPlanNodeType(), PlanNodeType::INSERT);
591+
txn_manager.CommitTransaction(txn);
592+
} catch (peloton::Exception &ex) {
593+
EXPECT_EQ(ExceptionType::CATALOG, ex.GetType());
594+
EXPECT_STREQ("Table NotExistTestTable is not found",
595+
ex.what());
596+
throw peloton::CatalogException(ex.what());
597+
}
598+
}, peloton::CatalogException);
599+
EXPECT_EQ(0, rows_changed);
600+
}
601+
573602
} // namespace test
574603
} // namespace peloton

0 commit comments

Comments
 (0)