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

Method OnNotifyTest

src/observer/test/observer_test.cc:205–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203class ObserverImplTest : public ::testing::Test {
204 public:
205 void OnNotifyTest() {
206 tera::ErrorCode err;
207 LOG(ERROR) << "FALG FILE: " << FLAGS_flagfile;
208 tera::Client* client = tera::Client::NewClient(FLAGS_flagfile, &err);
209 // for ut test
210 EXPECT_EQ(tera::ErrorCode::kOK, err.GetType());
211 // for no core
212 if (tera::ErrorCode::kOK != err.GetType()) {
213 LOG(ERROR) << "new client failed";
214 return;
215 }
216
217 // create table
218 tera::TableDescriptor table_desc("observer_test_table");
219 table_desc.EnableTxn();
220
221 table_desc.AddLocalityGroup("lg1");
222 tera::ColumnFamilyDescriptor* cf1 = table_desc.AddColumnFamily("cf", "lg1");
223 cf1->EnableGlobalTransaction();
224 cf1->EnableNotify();
225 ExtendNotifyLgToDescriptor(&table_desc);
226
227 client->CreateTable(table_desc, &err);
228 if (err.GetType() != tera::ErrorCode::kOK) {
229 LOG(ERROR) << "Create table fail";
230 return;
231 }
232
233 std::unique_ptr<Table> table(client->OpenTable("observer_test_table", &err));
234 EXPECT_EQ(tera::ErrorCode::kOK, err.GetType());
235 if (tera::ErrorCode::kOK != err.GetType()) {
236 LOG(ERROR) << "open table failed";
237 return;
238 }
239
240 sleep(1);
241 std::unique_ptr<tera::Transaction> t(table->StartRowTransaction("www.baidu.com"));
242
243 assert(t != NULL);
244 std::unique_ptr<tera::RowMutation> mu0(table->NewRowMutation("www.baidu.com"));
245 mu0->Put("_N_", "cf:Page", "I am not important");
246 t->ApplyMutation(mu0.get());
247 t->Commit();
248
249 std::unique_ptr<tera::Transaction> g_txn(client->NewGlobalTransaction());
250 assert(g_txn != NULL);
251 std::unique_ptr<tera::RowMutation> mu1(table->NewRowMutation("www.baidu.com"));
252
253 mu1->Put("cf", "Page", "hello world", -1);
254 g_txn->ApplyMutation(mu1.get());
255 g_txn->Commit();
256
257 if (g_txn->GetError().GetType() != tera::ErrorCode::kOK) {
258 std::cout << g_txn->GetError().ToString() << std::endl;
259 } else {
260 std::cout << "commit success" << std::endl;
261 }
262

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

Tested by

no test coverage detected