| 460 | } |
| 461 | |
| 462 | void ObserveTest() { |
| 463 | tera::ErrorCode err; |
| 464 | tera::Client* client = tera::Client::NewClient(FLAGS_flagfile, &err); |
| 465 | // for ut test |
| 466 | EXPECT_EQ(tera::ErrorCode::kOK, err.GetType()); |
| 467 | // for no core |
| 468 | if (tera::ErrorCode::kOK != err.GetType()) { |
| 469 | LOG(ERROR) << "new client failed"; |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | // create table |
| 474 | tera::TableDescriptor table_desc("observer_table"); |
| 475 | table_desc.EnableTxn(); |
| 476 | table_desc.AddLocalityGroup("notify"); |
| 477 | tera::ColumnFamilyDescriptor* cf_t = table_desc.AddColumnFamily(kNotifyColumnFamily, "notify"); |
| 478 | cf_t->EnableGlobalTransaction(); |
| 479 | |
| 480 | table_desc.AddLocalityGroup("lg1"); |
| 481 | tera::ColumnFamilyDescriptor* cf1 = table_desc.AddColumnFamily("cf", "lg1"); |
| 482 | cf1->EnableGlobalTransaction(); |
| 483 | cf1->EnableNotify(); |
| 484 | tera::ColumnFamilyDescriptor* cf2 = table_desc.AddColumnFamily("cf_1", "lg1"); |
| 485 | cf2->EnableGlobalTransaction(); |
| 486 | cf2->EnableNotify(); |
| 487 | |
| 488 | ExtendNotifyLgToDescriptor(&table_desc); |
| 489 | |
| 490 | client->CreateTable(table_desc, &err); |
| 491 | if (err.GetType() != tera::ErrorCode::kOK) { |
| 492 | LOG(ERROR) << "Create table fail"; |
| 493 | } |
| 494 | |
| 495 | FLAGS_tera_sdk_client_for_gtxn = true; |
| 496 | FLAGS_tera_coord_type = "ins"; |
| 497 | common::ThreadPool thread_pool(5); |
| 498 | ScannerImpl* scanner = new ScannerImpl(); |
| 499 | Observer* observer = new DemoObserver(); |
| 500 | scanner->key_selector_.reset(new RandomKeySelector()); |
| 501 | |
| 502 | // single thread |
| 503 | |
| 504 | err = scanner->Observe("observer_table", "cf", "qualifier", observer); |
| 505 | EXPECT_TRUE(err.GetType() != tera::ErrorCode::kOK); |
| 506 | |
| 507 | scanner->tera_client_.reset(tera::Client::NewClient(FLAGS_flagfile, &err)); |
| 508 | EXPECT_EQ(scanner->table_observe_info_->size(), 0); |
| 509 | |
| 510 | err = scanner->Observe("observer_table", "cf", "qualifier", observer); |
| 511 | EXPECT_TRUE(err.GetType() == tera::ErrorCode::kOK); |
| 512 | |
| 513 | err = scanner->Observe("observer_table", "cf", "qualifier", observer); |
| 514 | EXPECT_FALSE(err.GetType() == tera::ErrorCode::kOK); |
| 515 | |
| 516 | err = scanner->Observe("observer_table", "cf_1", "qualifier", observer); |
| 517 | EXPECT_TRUE(err.GetType() == tera::ErrorCode::kOK); |
| 518 | |
| 519 | // multi thread |
nothing calls this directly
no test coverage detected