MCPcopy Create free account
hub / github.com/baidu/tera / SingleRowTransactionTest

Method SingleRowTransactionTest

src/observer/test/observer_test.cc:306–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304 }
305
306 void SingleRowTransactionTest() {
307 tera::ErrorCode err;
308 tera::Client* client = tera::Client::NewClient(FLAGS_flagfile, &err);
309 // for ut test
310 EXPECT_EQ(tera::ErrorCode::kOK, err.GetType());
311 // for no core
312 if (tera::ErrorCode::kOK != err.GetType()) {
313 LOG(ERROR) << "new client failed";
314 return;
315 }
316
317 // create table
318 tera::TableDescriptor table_desc("observer_table_gtx");
319 table_desc.EnableTxn();
320
321 table_desc.AddLocalityGroup("lg1");
322 tera::ColumnFamilyDescriptor* cf1 = table_desc.AddColumnFamily("cf", "lg1");
323 cf1->EnableNotify();
324 ExtendNotifyLgToDescriptor(&table_desc);
325
326 client->CreateTable(table_desc, &err);
327 if (err.GetType() != tera::ErrorCode::kOK) {
328 LOG(ERROR) << "Create table fail";
329 return;
330 }
331
332 std::unique_ptr<Table> table(client->OpenTable("observer_table_gtx", &err));
333 EXPECT_EQ(tera::ErrorCode::kOK, err.GetType());
334 if (tera::ErrorCode::kOK != err.GetType()) {
335 LOG(ERROR) << "open table failed";
336 return;
337 }
338
339 std::unique_ptr<tera::Transaction> t(table->StartRowTransaction("www.baidu.com"));
340
341 assert(t != NULL);
342 std::unique_ptr<tera::RowMutation> mu0(table->NewRowMutation("www.baidu.com"));
343 mu0->Put("_N_", "cf:Page", "I am not important");
344 mu0->Put("cf", "Page", "hello world", -1);
345 t->ApplyMutation(mu0.get());
346 t->Commit();
347
348 if (t->GetError().GetType() != tera::ErrorCode::kOK) {
349 std::cout << t->GetError().ToString() << std::endl;
350 } else {
351 std::cout << "commit success" << std::endl;
352 }
353
354 Observer* observer = new TestWorkerGTX();
355
356 Scanner* scanner = new ScannerImpl();
357 bool ret = scanner->Init();
358
359 EXPECT_EQ(true, ret);
360 if (!ret) {
361 LOG(ERROR) << "fail to init scanner_impl";
362 return;
363 }

Callers

nothing calls this directly

Calls 15

EnableNotifyMethod · 0.80
GetTypeMethod · 0.45
EnableTxnMethod · 0.45
AddLocalityGroupMethod · 0.45
AddColumnFamilyMethod · 0.45
CreateTableMethod · 0.45
OpenTableMethod · 0.45
StartRowTransactionMethod · 0.45
NewRowMutationMethod · 0.45
PutMethod · 0.45
ApplyMutationMethod · 0.45

Tested by

no test coverage detected