| 532 | } |
| 533 | |
| 534 | void ValidateCellValueTest() { |
| 535 | tera::ErrorCode err; |
| 536 | std::unique_ptr<tera::Client> client(tera::Client::NewClient(FLAGS_flagfile, &err)); |
| 537 | // for ut test |
| 538 | EXPECT_EQ(tera::ErrorCode::kOK, err.GetType()); |
| 539 | // for no core |
| 540 | if (tera::ErrorCode::kOK != err.GetType()) { |
| 541 | LOG(ERROR) << "new client failed"; |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | common::ThreadPool thread_pool(5); |
| 546 | ScannerImpl* scanner = new ScannerImpl(); |
| 547 | scanner->key_selector_.reset(new RandomKeySelector()); |
| 548 | std::unique_ptr<Table> table(client->OpenTable("observer_test_table", &err)); |
| 549 | |
| 550 | Observer* observer = new TestWorker(); |
| 551 | bool ret = scanner->Init(); |
| 552 | EXPECT_EQ(true, ret); |
| 553 | if (!ret) { |
| 554 | LOG(ERROR) << "fail to init scanner_impl"; |
| 555 | return; |
| 556 | } |
| 557 | err = scanner->Observe("observer_test_table", "Data", "Page", observer); |
| 558 | EXPECT_EQ(err.GetType(), tera::ErrorCode::kOK); |
| 559 | |
| 560 | ScannerImpl::NotificationContext* context = new ScannerImpl::NotificationContext(); |
| 561 | common::Semaphore s(1); |
| 562 | s.Acquire(); |
| 563 | std::shared_ptr<NotifyCell> notify_cell(new NotifyCell(s)); |
| 564 | context->notify_cell = notify_cell; |
| 565 | Column column = {"observer_test_table", "Data", "qu"}; |
| 566 | notify_cell->row = "row"; |
| 567 | notify_cell->observed_column = column; |
| 568 | notify_cell->table = table.get(); |
| 569 | |
| 570 | // no value |
| 571 | RowReader* row_reader(table->NewRowReader("no_row")); |
| 572 | row_reader->SetContext(context); |
| 573 | row_reader->AddColumn("Data", "qu"); |
| 574 | table->Get(row_reader); |
| 575 | scanner->ValidateCellValue(row_reader); |
| 576 | sleep(1); |
| 577 | EXPECT_FALSE(static_cast<TestWorker*>(observer)->notified_); |
| 578 | |
| 579 | // no table |
| 580 | table->Put("row1", "Data", "qu", "value", &err); |
| 581 | if (err.GetType() != tera::ErrorCode::kOK) { |
| 582 | LOG(ERROR) << "put error: " << err.GetReason(); |
| 583 | return; |
| 584 | } |
| 585 | row_reader = table->NewRowReader("row1"); |
| 586 | context = new ScannerImpl::NotificationContext(); |
| 587 | context->notify_cell = notify_cell; |
| 588 | notify_cell->row = "row 1"; |
| 589 | |
| 590 | row_reader->SetContext(context); |
| 591 | table->Get(row_reader); |
nothing calls this directly
no test coverage detected