示例#1
0
TEST(DataStore, updateData) {
  ResultCode status;

  shared_ptr<CustomerKey> customerKey1(new CustomerKey);
  customerKey1->set_c_custkey(11000);

  shared_ptr<Customer> customer1(new Customer);
  customer1->set_c_name("Kate");
  customer1->set_c_nationkey(50);
  customer1->set_c_phone("13800138000");

  StoreKey<Message> key1(customerKey1);
  StoreValue<Message> value1(customer1);

  status = ::idgs::util::singleton<DataStore>::getInstance().updateData("Customer", key1, value1);
  ASSERT_TRUE(status == RC_SUCCESS);

  shared_ptr<CustomerKey> customerKey2(new CustomerKey);
  customerKey2->set_c_custkey(11000);

  shared_ptr<Customer> customer2(new Customer);

  StoreKey<Message> key2(customerKey2);
  StoreValue<Message> value2(customer2);

  status = ::idgs::util::singleton<DataStore>::getInstance().getData("Customer", key2, value2);
  ASSERT_TRUE(status == RC_SUCCESS);

  ASSERT_TRUE(value2.get() != NULL);

  Customer* result = (Customer *) value2.get().get();
  ASSERT_EQ("Kate", result->c_name());
  ASSERT_EQ(50, result->c_nationkey());
  ASSERT_EQ("13800138000", result->c_phone());
}
TEST(DataStore, get) {
  ResultCode status;
  StoreOption ps;
  hashcode_t hash;

  shared_ptr<CustomerKey> customerKey1 = make_shared<CustomerKey>();
  customerKey1->set_c_custkey(11000);

  shared_ptr<Customer> customer1 = make_shared<Customer>();

  StoreKey<Message> key1(customerKey1);
  StoreValue<Message> value1(customer1);

  auto store = idgs::store_test::datastore.getStore("Customer");

  hash = protobuf::HashCode::hashcode(key1.get());
  ps.partitionId = (hash % idgs::store_test::partSize);
  status = store->get(key1, value1, &ps);
  ASSERT_EQ(RC_SUCCESS, status);

  Customer* result = (Customer *) value1.get().get();
  ASSERT_EQ("Tom1", result->c_name());
  ASSERT_EQ(20, result->c_nationkey());
  ASSERT_EQ("13800138000", result->c_phone());

  shared_ptr<CustomerKey> customerKey2 = make_shared<CustomerKey>();
  customerKey2->set_c_custkey(12010);

  shared_ptr<Customer> customer2 = make_shared<Customer>();

  StoreKey<Message> key2(customerKey2);
  StoreValue<Message> value2(customer2);

  hash = protobuf::HashCode::hashcode(key2.get());
  ps.partitionId = (hash % idgs::store_test::partSize);
  status = store->get(key2, value2, &ps);
  ASSERT_EQ(RC_SUCCESS, status);

  shared_ptr<CustomerKey> customerKey3 = make_shared<CustomerKey>();
  customerKey3->set_c_custkey(20000);

  StoreKey<Message> key3(customerKey3);
  StoreValue<Message> value3(make_shared<Customer>());

  hash = protobuf::HashCode::hashcode(key3.get());
  ps.partitionId = (hash % idgs::store_test::partSize);
  status = store->get(key3, value3, &ps);
  ASSERT_EQ(RC_DATA_NOT_FOUND, status);
}
TEST(DataStore, updateData) {
  ResultCode status;
  StoreOption ps;
  hashcode_t hash;

  shared_ptr<CustomerKey> customerKey1 = make_shared<CustomerKey>();
  customerKey1->set_c_custkey(11000);

  shared_ptr<Customer> customer1 = make_shared<Customer>();
  customer1->set_c_name("Kate");
  customer1->set_c_nationkey(50);
  customer1->set_c_phone("13800138000");

  StoreKey<Message> key1(customerKey1);
  StoreValue<Message> value1(customer1);

  auto store = idgs::store_test::datastore.getStore("Customer");

  hash = protobuf::HashCode::hashcode(key1.get());
  ps.partitionId = (hash % idgs::store_test::partSize);
  status = store->put(key1, value1, &ps);
  ASSERT_EQ(RC_SUCCESS, status);

  shared_ptr<CustomerKey> customerKey2 = make_shared<CustomerKey>();
  customerKey2->set_c_custkey(11000);

  shared_ptr<Customer> customer2 = make_shared<Customer>();

  StoreKey<Message> key2(customerKey2);
  StoreValue<Message> value2(customer2);

  hash = protobuf::HashCode::hashcode(key2.get());
  ps.partitionId = (hash % idgs::store_test::partSize);
  status = store->put(key2, value2, &ps);
  ASSERT_EQ(RC_SUCCESS, status);

  ASSERT_TRUE(value2.get() != NULL);

  Customer* result = (Customer *) value2.get().get();
  ASSERT_EQ("Kate", result->c_name());
  ASSERT_EQ(50, result->c_nationkey());
  ASSERT_EQ("13800138000", result->c_phone());
}
示例#4
0
TEST(DataStore, getData) {
  ResultCode status;

  shared_ptr<CustomerKey> customerKey1(new CustomerKey);
  customerKey1->set_c_custkey(11000);

  shared_ptr<Customer> customer1(new Customer);

  StoreKey<Message> key1(customerKey1);
  StoreValue<Message> value1(customer1);

  status = ::idgs::util::singleton<DataStore>::getInstance().getData("Customer", key1, value1);
  ASSERT_TRUE(status == RC_SUCCESS);

  Customer* result = (Customer *) value1.get().get();
  ASSERT_EQ("Tom1", result->c_name());
  ASSERT_EQ(20, result->c_nationkey());
  ASSERT_EQ("13800138000", result->c_phone());

  shared_ptr<CustomerKey> customerKey2(new CustomerKey);
  customerKey2->set_c_custkey(12010);

  shared_ptr<Customer> customer2(new Customer);

  StoreKey<Message> key2(customerKey2);
  StoreValue<Message> value2(customer2);

  status = ::idgs::util::singleton<DataStore>::getInstance().getData("Customer", key2, value2);
  ASSERT_TRUE(status == RC_SUCCESS);

  shared_ptr<CustomerKey> customerKey3(new CustomerKey);
  customerKey3->set_c_custkey(20000);

  StoreKey<Message> key3(customerKey3);
  StoreValue<Message> value3(shared_ptr<Customer>(new Customer));

  status = ::idgs::util::singleton<DataStore>::getInstance().getData("Customer", key3, value3);
  ASSERT_TRUE(status == RC_DATA_NOT_FOUND);
}