Skip to content

Commit

Permalink
Fix UT fail
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Hai <[email protected]>
  • Loading branch information
JinHai-CN committed Oct 15, 2024
1 parent e1f4f34 commit 78f7871
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 99 deletions.
4 changes: 2 additions & 2 deletions src/unit_test/main/infinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ TEST_F(InfinityTest, test1) {

{
QueryResult result = infinity->ListDatabases();
// EXPECT_EQ(result.result_table_->row_count(), 1); // Bug
EXPECT_EQ(result.result_table_->ColumnCount(), 1u);
EXPECT_EQ(result.result_table_->row_count(), 1);
EXPECT_EQ(result.result_table_->ColumnCount(), 3u);
EXPECT_EQ(result.result_table_->GetColumnNameById(0), "database");
EXPECT_EQ(result.result_table_->DataBlockCount(), 1u);
SharedPtr<DataBlock> data_block = result.result_table_->GetDataBlockById(0);
Expand Down
8 changes: 4 additions & 4 deletions src/unit_test/storage/bg_task/cleanup_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ TEST_P(CleanupTaskTest, test_delete_db_simple) {
auto db_name = MakeShared<String>("db1");
{
auto *txn = txn_mgr->BeginTxn(MakeUnique<String>("create db1"));
txn->CreateDatabase(*db_name, ConflictType::kError);
txn->CreateDatabase(db_name, ConflictType::kError, MakeShared<String>());
txn_mgr->CommitTxn(txn);
}
WaitFlushDeltaOp(storage);
Expand Down Expand Up @@ -106,7 +106,7 @@ TEST_P(CleanupTaskTest, test_delete_db_complex) {
auto db_name = MakeShared<String>("db1");
{
auto *txn = txn_mgr->BeginTxn(MakeUnique<String>("create db1"));
txn->CreateDatabase(*db_name, ConflictType::kError);
txn->CreateDatabase(db_name, ConflictType::kError, MakeShared<String>());
txn_mgr->CommitTxn(txn);
}
{
Expand All @@ -117,12 +117,12 @@ TEST_P(CleanupTaskTest, test_delete_db_complex) {
}
{
auto *txn = txn_mgr->BeginTxn(MakeUnique<String>("create db1"));
txn->CreateDatabase(*db_name, ConflictType::kError);
txn->CreateDatabase(db_name, ConflictType::kError, MakeShared<String>());
txn_mgr->RollBackTxn(txn);
}
{
auto *txn = txn_mgr->BeginTxn(MakeUnique<String>("create db1"));
txn->CreateDatabase(*db_name, ConflictType::kError);
txn->CreateDatabase(db_name, ConflictType::kError, MakeShared<String>());
txn_mgr->CommitTxn(txn);
}
{
Expand Down
77 changes: 37 additions & 40 deletions src/unit_test/storage/meta/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TEST_P(CatalogTest, simple_test1) {

// create db in empty catalog should be success
{
auto [base_entry, status] = catalog->CreateDatabase("db1", txn1->TxnID(), txn1->BeginTS(), txn_mgr);
auto [base_entry, status] = catalog->CreateDatabase(MakeShared<String>("db1"), MakeShared<String>(), txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
// store this entry
databases["db1"] = base_entry;
Expand Down Expand Up @@ -127,7 +127,7 @@ TEST_P(CatalogTest, simple_test2) {

// create db in empty catalog should be success
{
Status status = txn1->CreateDatabase("db1", ConflictType::kError);
Status status = txn1->CreateDatabase(MakeShared<String>("db1"), ConflictType::kError, MakeShared<String>());
EXPECT_TRUE(status.ok());
}

Expand Down Expand Up @@ -177,7 +177,7 @@ TEST_P(CatalogTest, concurrent_test) {
auto write_routine = [&](int start, Txn *txn) {
for (int db_id = start; db_id < 1000; db_id += 2) {
String db_name = "db" + std::to_string(db_id);
Status status = txn->CreateDatabase(db_name, ConflictType::kError);
Status status = txn->CreateDatabase(MakeShared<String>(db_name), ConflictType::kError, MakeShared<String>());
EXPECT_TRUE(status.ok());
}
};
Expand Down Expand Up @@ -260,18 +260,17 @@ TEST_P(CatalogTest, get_db_info_test) {
// start txn2
auto *txn2 = txn_mgr->BeginTxn(MakeUnique<String>("get db"));


// create db in empty catalog should be success
{
auto [base_entry, status] = catalog->CreateDatabase("db1", txn1->TxnID(), txn1->BeginTS(), txn_mgr);
auto [base_entry, status] = catalog->CreateDatabase(MakeShared<String>("db1"), MakeShared<String>(), txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
}

{
auto [db_info1, status1] = catalog->GetDatabaseInfo("db1", txn1->TxnID(), txn1->BeginTS());
// should be visible to same txn
EXPECT_TRUE(status1.ok());
std::cout<<*(db_info1->db_name_)<<std::endl;
std::cout << *(db_info1->db_name_) << std::endl;
EXPECT_STREQ("db1", db_info1->db_name_->c_str());

// should not be visible to other txn
Expand Down Expand Up @@ -306,20 +305,20 @@ TEST_P(CatalogTest, get_table_info_test) {
// start txn1
auto *txn1 = txn_mgr->BeginTxn(MakeUnique<String>("create table"));

//create table, get table info, drop table
// create table, get table info, drop table
{
Vector<SharedPtr<ColumnDef>> columns;
{
std::set<ConstraintType> constraints;
constraints.insert(ConstraintType::kNotNull);
i64 column_id = 0;
auto embeddingInfo = MakeShared<EmbeddingInfo>(EmbeddingDataType::kElemFloat, 128);
auto column_def_ptr =
MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
auto column_def_ptr = MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
columns.emplace_back(column_def_ptr);
}
auto tbl1_def = MakeUnique<TableDef>(MakeShared<String>("default_db"), MakeShared<String>("tbl1"), columns);
auto [table_entry, status] = catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
auto [table_entry, status] =
catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
EXPECT_TRUE(status.ok());

auto [table_info, status1] = catalog->GetTableInfo("default_db", "tbl1", txn1);
Expand All @@ -342,20 +341,20 @@ TEST_P(CatalogTest, get_table_index_info_test) {
// start txn1
auto *txn1 = txn_mgr->BeginTxn(MakeUnique<String>("create index"));

//create table
// create table
{
Vector<SharedPtr<ColumnDef>> columns;
{
std::set<ConstraintType> constraints;
constraints.insert(ConstraintType::kNotNull);
i64 column_id = 0;
auto embeddingInfo = MakeShared<EmbeddingInfo>(EmbeddingDataType::kElemFloat, 128);
auto column_def_ptr =
MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
auto column_def_ptr = MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
columns.emplace_back(column_def_ptr);
}
auto tbl1_def = MakeUnique<TableDef>(MakeShared<String>("default_db"), MakeShared<String>("tbl1"), columns);
auto [table_entry, status] = catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
auto [table_entry, status] =
catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
EXPECT_TRUE(status.ok());
}

Expand Down Expand Up @@ -383,20 +382,21 @@ TEST_P(CatalogTest, get_table_index_info_test) {
EXPECT_EQ(index_status.ok(), true);
}

//get index info
// get index info
{
auto [index_info, status] = catalog->GetTableIndexInfo("default_db", "tbl1", "hnsw_index", txn1->TxnID(), txn1->BeginTS());
EXPECT_TRUE(status.ok());
EXPECT_STREQ("hnsw_index", index_info->index_name_->c_str());
}

//drop index
// drop index
{
auto [index_entry, status] = catalog->DropIndex("default_db", "tbl1", "hnsw_index", ConflictType::kError, txn1->TxnID(), txn1->BeginTS(), txn_mgr);
auto [index_entry, status] =
catalog->DropIndex("default_db", "tbl1", "hnsw_index", ConflictType::kError, txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
}

//drop table
// drop table
{
auto [table_entry, status] = catalog->DropTableByName("default_db", "tbl1", ConflictType::kError, txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
Expand All @@ -414,20 +414,20 @@ TEST_P(CatalogTest, remove_index_test) {
// start txn1
auto *txn1 = txn_mgr->BeginTxn(MakeUnique<String>("create index"));

//create table
// create table
{
Vector<SharedPtr<ColumnDef>> columns;
{
std::set<ConstraintType> constraints;
constraints.insert(ConstraintType::kNotNull);
i64 column_id = 0;
auto embeddingInfo = MakeShared<EmbeddingInfo>(EmbeddingDataType::kElemFloat, 128);
auto column_def_ptr =
MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
auto column_def_ptr = MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
columns.emplace_back(column_def_ptr);
}
auto tbl1_def = MakeUnique<TableDef>(MakeShared<String>("default_db"), MakeShared<String>("tbl1"), columns);
auto [table_entry, status] = catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
auto [table_entry, status] =
catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
EXPECT_TRUE(status.ok());
}

Expand Down Expand Up @@ -455,15 +455,15 @@ TEST_P(CatalogTest, remove_index_test) {
EXPECT_EQ(index_status.ok(), true);
}

//remove index
// remove index
{
auto [index_entry, index_status] = catalog->GetIndexByName("default_db", "tbl1", "hnsw_index", txn1->TxnID(), txn1->BeginTS());
EXPECT_TRUE(index_status.ok());
auto status = catalog->RemoveIndexEntry(index_entry, txn1->TxnID());
EXPECT_TRUE(status.ok());
}

//drop table
// drop table
{
auto [table_entry, status] = catalog->DropTableByName("default_db", "tbl1", ConflictType::kError, txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
Expand All @@ -482,36 +482,34 @@ TEST_P(CatalogTest, roll_back_append_test) {
// start txn1
auto *txn1 = txn_mgr->BeginTxn(MakeUnique<String>("create table"));

//create table
// create table
{
Vector<SharedPtr<ColumnDef>> columns;
{
std::set<ConstraintType> constraints;
constraints.insert(ConstraintType::kNotNull);
i64 column_id = 0;
auto embeddingInfo = MakeShared<EmbeddingInfo>(EmbeddingDataType::kElemFloat, 128);
auto column_def_ptr =
MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
auto column_def_ptr = MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
columns.emplace_back(column_def_ptr);
}
auto tbl1_def = MakeUnique<TableDef>(MakeShared<String>("default_db"), MakeShared<String>("tbl1"), columns);
auto [table_entry, status] = catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
auto [table_entry, status] =
catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
EXPECT_TRUE(status.ok());
}

{
auto [table_entry, status] = catalog->GetTableByName("default_db", "tbl1", txn1->TxnID(), txn1->BeginTS());
EXPECT_TRUE(status.ok());


auto txn_store = txn1->GetTxnTableStore(table_entry);
txn_store->SetAppendState(MakeUnique<AppendState>(txn_store->GetBlocks()));
Catalog::Append(table_entry, txn1->TxnID(), (void *)txn_store, txn1->CommitTS(), buffer_mgr);
EXPECT_THROW(Catalog::RollbackAppend(table_entry, txn1->TxnID(), txn1->CommitTS(), (void *)txn_store), UnrecoverableException);
}
}


TEST_P(CatalogTest, roll_back_delete_test) {
using namespace infinity;

Expand All @@ -522,20 +520,20 @@ TEST_P(CatalogTest, roll_back_delete_test) {
// start txn1
auto *txn1 = txn_mgr->BeginTxn(MakeUnique<String>("create table"));

//create table
// create table
{
Vector<SharedPtr<ColumnDef>> columns;
{
std::set<ConstraintType> constraints;
constraints.insert(ConstraintType::kNotNull);
i64 column_id = 0;
auto embeddingInfo = MakeShared<EmbeddingInfo>(EmbeddingDataType::kElemFloat, 128);
auto column_def_ptr =
MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
auto column_def_ptr = MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
columns.emplace_back(column_def_ptr);
}
auto tbl1_def = MakeUnique<TableDef>(MakeShared<String>("default_db"), MakeShared<String>("tbl1"), columns);
auto [table_entry, status] = catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
auto [table_entry, status] =
catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
EXPECT_TRUE(status.ok());
}

Expand All @@ -545,7 +543,7 @@ TEST_P(CatalogTest, roll_back_delete_test) {

auto txn_store = txn1->GetTxnTableStore(table_entry);
Catalog::Delete(table_entry, txn1->TxnID(), (void *)txn_store, txn1->CommitTS(), txn_store->GetDeleteStateRef());
EXPECT_THROW(Catalog::RollbackDelete(table_entry, txn1->TxnID(), txn_store->GetDeleteStateRef(), buffer_mgr),UnrecoverableException);
EXPECT_THROW(Catalog::RollbackDelete(table_entry, txn1->TxnID(), txn_store->GetDeleteStateRef(), buffer_mgr), UnrecoverableException);
}
}

Expand All @@ -559,28 +557,27 @@ TEST_P(CatalogTest, roll_back_write_test) {
// start txn1
auto *txn1 = txn_mgr->BeginTxn(MakeUnique<String>("create table"));

//create table
// create table
{
Vector<SharedPtr<ColumnDef>> columns;
{
std::set<ConstraintType> constraints;
constraints.insert(ConstraintType::kNotNull);
i64 column_id = 0;
auto embeddingInfo = MakeShared<EmbeddingInfo>(EmbeddingDataType::kElemFloat, 128);
auto column_def_ptr =
MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
auto column_def_ptr = MakeShared<ColumnDef>(column_id, MakeShared<DataType>(LogicalType::kEmbedding, embeddingInfo), "col1", constraints);
columns.emplace_back(column_def_ptr);
}
auto tbl1_def = MakeUnique<TableDef>(MakeShared<String>("default_db"), MakeShared<String>("tbl1"), columns);
auto [table_entry, status] = catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
auto [table_entry, status] =
catalog->CreateTable("default_db", txn1->TxnID(), txn1->BeginTS(), std::move(tbl1_def), ConflictType::kError, txn_mgr);
EXPECT_TRUE(status.ok());
}

{
auto [table_entry, status] = catalog->GetTableByName("default_db", "tbl1", txn1->TxnID(), txn1->BeginTS());
EXPECT_TRUE(status.ok());


auto txn_store = txn1->GetTxnTableStore(table_entry);
txn_store->SetAppendState(MakeUnique<AppendState>(txn_store->GetBlocks()));
Catalog::Append(table_entry, txn1->TxnID(), (void *)txn_store, txn1->CommitTS(), buffer_mgr);
Expand Down
18 changes: 9 additions & 9 deletions src/unit_test/storage/meta/db_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ TEST_P(DBMetaTest, to_string_test) {

// create db in empty catalog should be success
{
auto [base_entry, status] = catalog->CreateDatabase("db1", txn1->TxnID(), txn1->BeginTS(), txn_mgr);
auto [base_entry, status] = catalog->CreateDatabase(MakeShared<String>("db1"), MakeShared<String>(), txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
std::cout<<base_entry->db_meta_->ToString()->c_str()<<std::endl;
std::cout << base_entry->db_meta_->ToString()->c_str() << std::endl;
ASSERT_STREQ(base_entry->db_meta_->ToString()->c_str(), "DBMeta, db name: db1, entry count: 1");
}

// drop db should be success
{
auto [base_entry, status] = catalog->DropDatabase("db1", txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
std::cout<<base_entry->db_meta_->ToString()->c_str()<<std::endl;
std::cout << base_entry->db_meta_->ToString()->c_str() << std::endl;
ASSERT_STREQ(base_entry->db_meta_->ToString()->c_str(), "DBMeta, db name: db1, entry count: 0");
}

Expand All @@ -62,17 +62,17 @@ TEST_P(DBMetaTest, empty_db_entry_test) {

// create db in empty catalog should be success
{
auto [base_entry, status] = catalog->CreateDatabase("db1", txn1->TxnID(), txn1->BeginTS(), txn_mgr);
auto [base_entry, status] = catalog->CreateDatabase(MakeShared<String>("db1"), MakeShared<String>(), txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
std::cout<<base_entry->db_meta_->ToString()->c_str()<<std::endl;
std::cout << base_entry->db_meta_->ToString()->c_str() << std::endl;
EXPECT_FALSE(base_entry->db_meta_->Empty());
}

// drop db should be success
{
auto [base_entry, status] = catalog->DropDatabase("db1", txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
std::cout<<base_entry->db_meta_->ToString()->c_str()<<std::endl;
std::cout << base_entry->db_meta_->ToString()->c_str() << std::endl;
EXPECT_TRUE(base_entry->db_meta_->Empty());
}

Expand All @@ -88,17 +88,17 @@ TEST_P(DBMetaTest, get_all_db_entry_test) {

// create db in empty catalog should be success
{
auto [base_entry, status] = catalog->CreateDatabase("db1", txn1->TxnID(), txn1->BeginTS(), txn_mgr);
auto [base_entry, status] = catalog->CreateDatabase(MakeShared<String>("db1"), MakeShared<String>(), txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
std::cout<<base_entry->db_meta_->ToString()->c_str()<<std::endl;
std::cout << base_entry->db_meta_->ToString()->c_str() << std::endl;
EXPECT_EQ(base_entry->db_meta_->GetAllEntries().size(), 1);
}

// drop db should be success
{
auto [base_entry, status] = catalog->DropDatabase("db1", txn1->TxnID(), txn1->BeginTS(), txn_mgr);
EXPECT_TRUE(status.ok());
std::cout<<base_entry->db_meta_->ToString()->c_str()<<std::endl;
std::cout << base_entry->db_meta_->ToString()->c_str() << std::endl;
EXPECT_EQ(base_entry->db_meta_->GetAllEntries().size(), 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TEST_P(TableEntryTest, test2) {
Txn *new_txn = txn_mgr->BeginTxn(MakeUnique<String>("create db1"));

// Txn1: Create db1, OK
Status status = new_txn->CreateDatabase("db1", ConflictType::kError);
Status status = new_txn->CreateDatabase(MakeShared<String>("db1"), ConflictType::kError, MakeShared<String>());
EXPECT_TRUE(status.ok());

// Txn1: Create tbl1, OK
Expand Down
Loading

0 comments on commit 78f7871

Please sign in to comment.