void build_values(const int64_t row_count, ObRowDesc &row_desc, ObExprValues &values1, ObValues &values2)
{
  for (int64_t i = 0; i < row_count; i++)
  {
    ObRow row;
    row.set_row_desc(row_desc);
    for (int64_t j = 0; j < row_desc.get_column_num(); j++)
    {
      uint64_t table_id = OB_INVALID_ID;
      uint64_t column_id = OB_INVALID_ID;
      row_desc.get_tid_cid(j, table_id, column_id);
      ObObj obj;
      obj.set_int(i + j);
      row.set_cell(table_id, column_id, obj); 

      ObSqlExpression se;
      se.set_tid_cid(table_id, column_id);
      ExprItem ei;
      ei.type_ = T_INT;
      ei.value_.int_ = i + j;
      se.add_expr_item(ei);
      //ei.type_ = T_REF_COLUMN;
      //ei.value_.cell_.tid = table_id;
      //ei.value_.cell_.cid = column_id;
      //se.add_expr_item(ei);
      se.add_expr_item_end();

      values1.add_value(se);
    }
    //values1.add_values(row);
    values2.add_values(row);
  }
}
Ejemplo n.º 2
0
TEST_F(ObRowUtilTest, basic_test1)
{
  char buf[1024];
  ObCompactCellWriter cell_writer;
  OK(cell_writer.init(buf, 1024, SPARSE));

  ObObj value;
  ObRowDesc row_desc;
  for(int64_t i=0;i<10;i++)
  {
    row_desc.add_column_desc(TABLE_ID, i);
    value.set_int(i);
    OK(cell_writer.append(i, value));
  }
  OK(cell_writer.row_finish());

  ObString compact_row;
  compact_row.assign_ptr(cell_writer.get_buf(), (int32_t)cell_writer.size());

  ObRow row;

  row.set_row_desc(row_desc);
  OK(ObRowUtil::convert(compact_row, row));

  const ObObj *cell = NULL;
  uint64_t column_id = OB_INVALID_ID;
  uint64_t table_id = OB_INVALID_ID;
  int64_t int_value = 0;
  for(int64_t i=0;i<10;i++)
  {
    OK(row.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }
}
      TEST_F(ObTabletJoinTest, get_right_table_rowkey)
      {
        ObRowDesc row_desc;
        row_desc.add_column_desc(LEFT_TABLE_ID, 1);

        const char *rowkey_str = "oceanbase";
        ObString row_key_str;
        row_key_str.assign_ptr(const_cast<char *>(rowkey_str), (int32_t)strlen(rowkey_str));

        ObObj row_key_obj;
        row_key_obj.set_varchar(row_key_str);

        ObRowkey row_key;
        row_key.assign(&row_key_obj, 1);

        ObObj value;
        value.set_varchar(row_key_str);

        ObRow row;
        row.set_row_desc(row_desc);
        row.raw_set_cell(0, value);

        ObObj rowkey_obj[OB_MAX_ROWKEY_COLUMN_NUMBER];
        ObRowkey rowkey2;

        ObTabletCacheJoin tablet_join;
        tablet_join.set_table_join_info(tablet_join_info_);

        OK(tablet_join.get_right_table_rowkey(row, rowkey2, rowkey_obj));
        ASSERT_TRUE(row_key == rowkey2);
      }
Ejemplo n.º 4
0
TEST_F(ObRowStoreTest, basic_test)
{
  ObRowStore row_store;
  int64_t cur_size_counter = 0;

  ObRowDesc row_desc;
  row_desc.add_column_desc(TABLE_ID, 1);
  row_desc.add_column_desc(TABLE_ID, 2);
  row_desc.add_column_desc(TABLE_ID, 3);
  row_desc.add_column_desc(TABLE_ID, 4);
  row_desc.add_column_desc(TABLE_ID, 5);

  ObRow row;
  row.set_row_desc(row_desc);

  #define ADD_ROW(num1, num2, num3, num4, num5) \
  row.set_cell(TABLE_ID, 1, gen_int_obj(num1, false)); \
  row.set_cell(TABLE_ID, 2, gen_int_obj(num2, false)); \
  row.set_cell(TABLE_ID, 3, gen_int_obj(num3, false)); \
  row.set_cell(TABLE_ID, 4, gen_int_obj(num4, false)); \
  row.set_cell(TABLE_ID, 5, gen_int_obj(num5, false)); \
  row_store.add_row(row, cur_size_counter);


  ObRow get_row;
  get_row.set_row_desc(row_desc);

  #define CHECK_CELL(column_id, num) \
  { \
    const ObObj *cell = NULL; \
    int64_t int_value = 0; \
    get_row.get_cell(TABLE_ID, column_id, cell); \
    cell->get_int(int_value); \
    ASSERT_EQ(num, int_value); \
  }

  #define CHECK_ROW(num1, num2, num3, num4, num5) \
  row_store.get_next_row(get_row); \
  CHECK_CELL(1, num1); \
  CHECK_CELL(2, num2); \
  CHECK_CELL(3, num3); \
  CHECK_CELL(4, num4); \
  CHECK_CELL(5, num5);

  ADD_ROW(1, 2, 4, 5, 3);
  ADD_ROW(1, 2, 4, 5, 3);
  ADD_ROW(1, 2, 4, 5, 3);
  ADD_ROW(1, 2, 4, 5, 3);
  ADD_ROW(1, 2, 4, 5, 3);

  CHECK_ROW(1, 2, 4, 5, 3);
  CHECK_ROW(1, 2, 4, 5, 3);
  CHECK_ROW(1, 2, 4, 5, 3);
  CHECK_ROW(1, 2, 4, 5, 3);
  CHECK_ROW(1, 2, 4, 5, 3);
}
Ejemplo n.º 5
0
TEST_F(ObRowFuseTest, assign)
{
  uint64_t TABLE_ID = 1000;

  ObRowDesc row_desc;
  for(int i=0;i<8;i++)
  {
    row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + i);
  }

  ObRow row;
  row.set_row_desc(row_desc);
  ObObj value;

  for(int i=0;i<8;i++)
  {
    value.set_int(i);
    OK(row.raw_set_cell(i, value));
  }

  ObRowDesc ups_row_desc;
  for(int i=0;i<4;i++)
  {
    ups_row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + i);
  }

  ObUpsRow ups_row;
  ups_row.set_row_desc(ups_row_desc);

  for(int i=0;i<4;i++)
  {
    value.set_ext(ObActionFlag::OP_NOP);
    OK(ups_row.raw_set_cell(i, value));
  }

  ups_row.set_delete_row(true);
  OK(ObRowFuse::assign(ups_row, row));

  const ObObj *cell = NULL;
  uint64_t table_id = OB_INVALID_ID;
  uint64_t column_id = OB_INVALID_ID;

  for(int i=0;i<4;i++)
  {
    OK(row.raw_get_cell(i, cell, table_id, column_id));
    ASSERT_EQ(ObNullType, cell->get_type());
  }

  ASSERT_TRUE(OB_SUCCESS != row.raw_get_cell(4, cell, table_id, column_id));
}
Ejemplo n.º 6
0
TEST_F(ObRowUtilTest, basic_test)
{
  char buf[1024];
  ObCompactCellWriter cell_writer;
  OK(cell_writer.init(buf, 1024, DENSE_SPARSE));

  ObRowkey rowkey;
  ObObj rowkey_obj[OB_MAX_ROWKEY_COLUMN_NUMBER];
  rowkey_obj[0].set_int(3);
  rowkey_obj[1].set_int(30);

  rowkey.assign(rowkey_obj, 2);
  
  OK(cell_writer.append_rowkey(rowkey));
  
  ObObj value;
  ObRowDesc row_desc;
  for(int64_t i=0;i<10;i++)
  {
    row_desc.add_column_desc(TABLE_ID, i);
    value.set_int(i);
    OK(cell_writer.append(i, value));
  }
  OK(cell_writer.row_finish());

  ObString compact_row;
  compact_row.assign_ptr(cell_writer.get_buf(), (int32_t)cell_writer.size());

  ObRow row;
  ObRowkey rk;
  ObObj rk_obj[OB_MAX_ROWKEY_COLUMN_NUMBER];

  row.set_row_desc(row_desc);
  OK(ObRowUtil::convert(compact_row, row, &rk, rk_obj));

  ASSERT_TRUE( rowkey == rk );

  const ObObj *cell = NULL;
  uint64_t column_id = OB_INVALID_ID;
  uint64_t table_id = OB_INVALID_ID;
  int64_t int_value = 0;
  for(int64_t i=0;i<10;i++)
  {
    OK(row.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }
}
Ejemplo n.º 7
0
TEST_F(ObRowUtilTest, basic_test)
{
  char buf[1024];
  ObCompactCellWriter cell_writer;
  OK(cell_writer.init(buf, 1024, DENSE_SPARSE));

  const char *rowkey = "rowkey_00001";
  ObString rowkey_str;
  rowkey_str.assign_ptr(const_cast<char *>(rowkey), (int32_t)(strlen(rowkey)));
  ObObj rowkey_obj;
  rowkey_obj.set_varchar(rowkey_str);

  OK(cell_writer.append(rowkey_obj));
  OK(cell_writer.rowkey_finish());

  ObObj value;
  ObRowDesc row_desc;
  for(int64_t i=0;i<10;i++)
  {
    row_desc.add_column_desc(TABLE_ID, i);
    value.set_int(i);
    OK(cell_writer.append(i, value));
  }
  OK(cell_writer.row_finish());

  ObString compact_row;
  compact_row.assign_ptr(cell_writer.get_buf(), (int32_t)cell_writer.size());

  ObRow row;
  ObString rk;

  row.set_row_desc(row_desc);
  OK(ObRowUtil::convert(compact_row, row, &rk));

  ASSERT_EQ(0, strncmp(rowkey, rk.ptr(), rk.length()));

  const ObObj *cell = NULL;
  uint64_t column_id = OB_INVALID_ID;
  uint64_t table_id = OB_INVALID_ID;
  int64_t int_value = 0;
  for(int64_t i=0;i<10;i++)
  {
    OK(row.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }
}
void build_values(const int64_t row_count, ObRowDesc &row_desc, ObValues &values1, ObValues &values2)
{
  values1.set_row_desc(row_desc);
  values2.set_row_desc(row_desc);
  for (int64_t i = 0; i < row_count; i++)
  {
    ObRow row;
    row.set_row_desc(row_desc);
    for (int64_t j = 0; j < row_desc.get_column_num(); j++)
    {
      uint64_t table_id = OB_INVALID_ID;
      uint64_t column_id = OB_INVALID_ID;
      row_desc.get_tid_cid(j, table_id, column_id);
      ObObj obj;
      obj.set_int(i + j);
      row.set_cell(table_id, column_id, obj); 
    }
    values1.add_values(row);
    values2.add_values(row);
  }
}
TEST(TestObNewScanner, try_all_the_best_to_add_row_to_scanner_as_much_as_possible)
{
  ObNewScanner sc;
  ObNewRange range, sc_range;
  ObObj start_obj, end_obj;
  start_obj.set_int(0);
  end_obj.set_int(0xffff);
  range.start_key_.assign(&start_obj, 1);
  range.end_key_.assign(&end_obj, 1);
  EXPECT_EQ(OB_SUCCESS, sc.set_range(range));
  
  ObRowDesc row_desc;
  row_desc.add_column_desc(TABLE_ID, 1);
  row_desc.add_column_desc(TABLE_ID, 2);
  row_desc.add_column_desc(TABLE_ID, 3);
  row_desc.add_column_desc(TABLE_ID, 4);
  row_desc.add_column_desc(TABLE_ID, 5);

  ObRow row;
  ObRow get_row;
  row.set_row_desc(row_desc);
  get_row.set_row_desc(row_desc);


  int ret;
  int n = 1024*1024;
  while(n-- > 0)
  {
    ret =  ADD_ROW(sc, 1, 2, 4, 5, 3);
    ASSERT_TRUE(OB_SUCCESS == ret || OB_SIZE_OVERFLOW == ret);
    if (ret == OB_SIZE_OVERFLOW)
    {
      TBSYS_LOG(INFO, "total %d rows inserted", n);
      break;
    }
  }
 
  CLEAN(sc);
}
TEST(TestObNewScanner, set_mem_limit)
{
  ObNewScanner sc;
  ObNewRange range, sc_range;
  ObObj start_obj, end_obj;
  start_obj.set_int(0);
  end_obj.set_int(0xffff);
  range.start_key_.assign(&start_obj, 1);
  range.end_key_.assign(&end_obj, 1);
  EXPECT_EQ(OB_SUCCESS, sc.set_range(range));
  
  sc.set_mem_size_limit(40);
  ObRowDesc row_desc;
  row_desc.add_column_desc(TABLE_ID, 1);
  row_desc.add_column_desc(TABLE_ID, 2);
  row_desc.add_column_desc(TABLE_ID, 3);
  row_desc.add_column_desc(TABLE_ID, 4);
  row_desc.add_column_desc(TABLE_ID, 5);

  ObRow row;
  ObRow get_row;
  row.set_row_desc(row_desc);
  get_row.set_row_desc(row_desc);


  int ret;
  ret =  ADD_ROW(sc, 1, 2, 4, 5, 3);
  EXPECT_EQ(OB_SUCCESS,ret);
  
  ret =  ADD_ROW(sc, 1, 2, 4, 5, 3);
  EXPECT_EQ(OB_SIZE_OVERFLOW, ret);
  
  ret =  ADD_ROW(sc, 1, 2, 4, 5, 3);
  EXPECT_EQ(OB_SIZE_OVERFLOW, ret);


  CLEAN(sc);
}
Ejemplo n.º 11
0
    int ObStatManager::get_scanner(ObNewScanner &scanner) const
    {
      int ret = OB_SUCCESS;
      int64_t last_used_mod = OB_INVALID_ID;
      char ipbuf[OB_IP_STR_BUFF] = {0};
      server_.ip_to_string(ipbuf, sizeof (ipbuf));
      ObString ipstr = ObString::make_string(ipbuf);
      const int32_t port = server_.get_port();
      ObString server_name = ObString::make_string(print_role(get_server_type()));
      int64_t total_stat_cnt = 0;
      /* create row_desc */
      ObRowDesc row_desc;
      int32_t column_id = OB_APP_MIN_COLUMN_ID;
      row_desc.add_column_desc(OB_ALL_SERVER_STAT_TID, column_id++);
      row_desc.add_column_desc(OB_ALL_SERVER_STAT_TID, column_id++);
      row_desc.add_column_desc(OB_ALL_SERVER_STAT_TID, column_id++);
      row_desc.add_column_desc(OB_ALL_SERVER_STAT_TID, column_id++);
      row_desc.add_column_desc(OB_ALL_SERVER_STAT_TID, column_id++);
      row_desc.set_rowkey_cell_count(4);
      ObRow row;
      ObObj obj;

      // drop mod id info
      for (int32_t mod = 0; mod < OB_MAX_MOD_NUMBER; mod++)
      {
        ObStat stat;
        total_stat_cnt += stat_cnt_[mod];
        // drop table id info
        for (int32_t i = 0; i < table_stats_[mod].get_array_index(); i++)
        {
          for (int32_t j = 0; j < stat_cnt_[mod]; j++)
          {
            stat.inc(j, table_stats_[mod].at(i)->get_value(j));
          }
        }
        for (int32_t i = 0; i < stat_cnt_[mod]; i++)
        {
          column_id = OB_APP_MIN_COLUMN_ID;
          row.set_row_desc(row_desc);
          row.reset(false, ObRow::DEFAULT_NULL);
          /* server type */
          obj.set_type(ObVarcharType);
          obj.set_varchar(server_name);
          row.set_cell(OB_ALL_SERVER_STAT_TID, column_id++, obj);
          /* server ip */
          obj.set_type(ObVarcharType);
          obj.set_varchar(ipstr);
          row.set_cell(OB_ALL_SERVER_STAT_TID, column_id++, obj);
          /* port */
          obj.set_type(ObIntType);
          obj.set_int(port);
          row.set_cell(OB_ALL_SERVER_STAT_TID, column_id++, obj);
          /* key */
          obj.set_type(ObVarcharType);
          obj.set_varchar(ObString::make_string(get_name(mod, i)));
          row.set_cell(OB_ALL_SERVER_STAT_TID, column_id++, obj);
          /* value */
          obj.set_type(ObIntType);
          obj.set_int(stat.get_value(i));
          row.set_cell(OB_ALL_SERVER_STAT_TID, column_id++, obj);

          scanner.add_row(row);
          // for last rowkey
          last_used_mod = mod;
        }
      }
      /* last rowkey */
      if (total_stat_cnt > 0)
      {
        static ObObj rk_objs[4];
        rk_objs[0].set_type(ObVarcharType);
        rk_objs[0].set_varchar(server_name);
        rk_objs[1].set_type(ObVarcharType);
        rk_objs[1].set_varchar(ipstr);
        rk_objs[2].set_type(ObIntType);
        rk_objs[2].set_int(port);
        rk_objs[3].set_type(ObVarcharType);
        rk_objs[3].set_varchar(ObString::make_string(get_name(last_used_mod, stat_cnt_[last_used_mod] - 1)));
        ObRowkey rowkey(rk_objs, 4);
        scanner.set_last_row_key(rowkey);
      }

      /* fullfilled */
      scanner.set_is_req_fullfilled(true, total_stat_cnt);

      return ret;
    }
TEST(TestObNewScanner, add_row_serialize)
{
  char buffer[2048];
  int64_t pos = 0;
  int64_t pos_dest = 0;
  ObNewScanner sc, sc_dest;
  ObNewRange range, sc_range, sc_dest_range;
  ObObj start_obj, end_obj;
  start_obj.set_int(0);
  end_obj.set_int(0xffff);
  range.start_key_.assign(&start_obj, 1);
  range.end_key_.assign(&end_obj, 1);
  EXPECT_EQ(OB_SUCCESS, sc.set_range(range));
  
  ObRowDesc row_desc;
  row_desc.add_column_desc(TABLE_ID, 1);
  row_desc.add_column_desc(TABLE_ID, 2);
  row_desc.add_column_desc(TABLE_ID, 3);
  row_desc.add_column_desc(TABLE_ID, 4);
  row_desc.add_column_desc(TABLE_ID, 5);

  ObRow row;
  ObRow get_row;
  row.set_row_desc(row_desc);
  get_row.set_row_desc(row_desc);

  ADD_ROW(sc, 1, 2, 4, 5, 3);
  ADD_ROW(sc, 1, 2, 4, 5, 3);
  ADD_ROW(sc, 1, 2, 4, 5, 3);
  ADD_ROW(sc, 1, 2, 4, 5, 3);
  ADD_ROW(sc, 1, 2, 4, 5, 3);

  CHECK_ROW(sc, 1, 2, 4, 5, 3);
  CHECK_ROW(sc, 1, 2, 4, 5, 3);
  CHECK_ROW(sc, 1, 2, 4, 5, 3);
  CHECK_ROW(sc, 1, 2, 4, 5, 3);
  CHECK_ROW(sc, 1, 2, 4, 5, 3);


  bool tmp_is_fulfilled = true;
  EXPECT_EQ(OB_SUCCESS, sc.set_is_req_fullfilled(tmp_is_fulfilled, 0));
  EXPECT_EQ(OB_SUCCESS, sc.serialize(buffer, 2048, pos));
  EXPECT_EQ(OB_SUCCESS, sc_dest.deserialize(buffer, 2048, pos_dest));
  EXPECT_EQ(pos, pos_dest);
  EXPECT_EQ(OB_SUCCESS, sc.get_range(sc_range));
  EXPECT_EQ(OB_SUCCESS, sc.get_range(sc_dest_range));
  EXPECT_EQ(0, sc_range.compare_with_startkey2(sc_dest_range));
  EXPECT_EQ(0, sc_range.compare_with_endkey2(sc_dest_range));

  CHECK_ROW(sc_dest, 1, 2, 4, 5, 3);
  CHECK_ROW(sc_dest, 1, 2, 4, 5, 3);
  CHECK_ROW(sc_dest, 1, 2, 4, 5, 3);
  CHECK_ROW(sc_dest, 1, 2, 4, 5, 3);
  CHECK_ROW(sc_dest, 1, 2, 4, 5, 3);

  bool is_fulfilled = false;
  int64_t fulfilled_item_num = -1;
  EXPECT_EQ(OB_SUCCESS, sc.get_is_req_fullfilled(is_fulfilled, fulfilled_item_num));
  EXPECT_TRUE(true == is_fulfilled);
  EXPECT_TRUE(0 == fulfilled_item_num);

  EXPECT_EQ(OB_SUCCESS, sc.get_is_req_fullfilled(is_fulfilled, fulfilled_item_num));
  EXPECT_TRUE(true == is_fulfilled);
  EXPECT_TRUE(0 == fulfilled_item_num);
  
  CLEAN(sc);
  CLEAN(sc_dest);
}
TEST_F(ObSqlQueryServiceTest, basic_test)
{
  ObSqlQueryService query_service;

  ObOperatorFactoryImpl op_factory;
  OK(query_service.set_operator_factory(&op_factory));

  ObFakeUpsRpcStub2 rpc_stub;
  rpc_stub.set_ups_scan("./tablet_scan_test_data/ups_table1.ini");
  rpc_stub.set_ups_multi_get("./tablet_scan_test_data/ups_table2.ini");

  OK(query_service.set_ups_rpc_stub(&rpc_stub));

  ObSchemaManagerV2 schema_mgr;
  tbsys::CConfig cfg;
  ASSERT_TRUE(schema_mgr.parse_from_file("./tablet_scan_test_data/schema.ini", cfg));

  OK(query_service.set_schema_manager(&schema_mgr));
  query_service.set_join_batch_count(3);

  ObSqlExpression expr1, expr2, expr3;
  ObSqlScanParam sql_scan_param;

  expr1.set_tid_cid(TABLE_ID, 4);
  ExprItem item_a;
  item_a.type_ = T_REF_COLUMN;
  item_a.value_.cell_.tid = TABLE_ID;
  item_a.value_.cell_.cid = 4;
  expr1.add_expr_item(item_a);
  expr1.add_expr_item_end();
  OK(sql_scan_param.add_output_column(expr1));

  expr2.set_tid_cid(TABLE_ID, 5);
  ExprItem item_b;
  item_b.type_ = T_REF_COLUMN;
  item_b.value_.cell_.tid = TABLE_ID;
  item_b.value_.cell_.cid = 5;
  expr2.add_expr_item(item_b);
  expr2.add_expr_item_end();
  OK(sql_scan_param.add_output_column(expr2));

  int64_t start = 100;
  int64_t end = 1000;
  
  ObNewRange range;
  range.table_id_ = TABLE_ID;
  CharArena arena;
  gen_new_range(start, end, arena, range);

  OK(sql_scan_param.set_range(range));

  ObRowDesc row_desc;
  row_desc.add_column_desc(TABLE_ID, 4);
  row_desc.add_column_desc(TABLE_ID, 5);


  ObFileTable result("./tablet_scan_test_data/result.ini");

  int err = OB_SUCCESS;
  int64_t count = 0;
  ObRow row;
  const ObRow *result_row = NULL;
  const ObObj *value = NULL;
  const ObObj *result_value = NULL;
  uint64_t table_id = 0;
  uint64_t column_id = 0;
  ObNewScanner new_scanner;
  new_scanner.set_mem_size_limit(1024);

  bool is_fullfilled = false;
  int64_t fullfilled_item_num = 0;

  row.set_row_desc(row_desc);

  OK(query_service.open(sql_scan_param));
  OK(result.open());

  int run_times = 0;
  while(OB_SUCCESS == err)
  {
    OK(query_service.fill_scan_data(new_scanner));
    OK(new_scanner.get_is_req_fullfilled(is_fullfilled, fullfilled_item_num));

    run_times ++;

    while(OB_SUCCESS == err)
    {
      err = new_scanner.get_next_row(row);
      if(OB_SUCCESS != err)
      {
        ASSERT_TRUE(OB_ITER_END == err);
        err = OB_SUCCESS;
        break;
      }

      OK(result.get_next_row(result_row));
      count ++;

      ASSERT_TRUE(row.get_column_num() > 0);

      for(int64_t i=0;i<row.get_column_num();i++)
      {
        OK(row.raw_get_cell(i, value, table_id, column_id));
        OK(result_row->get_cell(table_id, column_id, result_value));

        if( *value != *result_value )
        {
          printf("row:[%ld], column[%ld]===========\n", count, i);
          printf("row: %s\n", print_obj(*value));
          printf("result: %s\n", print_obj(*result_value));
        }

        ASSERT_TRUE((*value) == (*result_value));
      }
    }

    if(is_fullfilled)
    {
      break;
    }
  }

  printf("I am runinng %d\n", run_times);
  printf("fullfilled_item_num %ld\n", fullfilled_item_num);
}
Ejemplo n.º 14
0
TEST_F(ObRowFuseTest, basic_test)
{
  ObRowDesc row_desc;
  uint64_t table_id = 1000;
  for(int i=0;i<8;i++)
  {
    row_desc.add_column_desc(table_id, OB_APP_MIN_COLUMN_ID + i);
  }

  ObUpsRow ups_row;
  ups_row.set_row_desc(row_desc);
  ups_row.set_delete_row(false);

  ObObj cell;
  for(int i=0;i<8;i++)
  {
    cell.set_int(i, true);
    ups_row.raw_set_cell(i, cell);
  }

  ObRow row;
  row.set_row_desc(row_desc);
  
  for(int i=0;i<8;i++)
  {
    cell.set_int(i);
    row.raw_set_cell(i, cell);
  }

  ObRow result;

  ObRowFuse::fuse_row(&ups_row, &row, &result);

  const ObObj *result_cell = NULL;
  uint64_t result_table_id = 0;
  uint64_t result_column_id = 0;
  int64_t int_value = 0;
  for(int i=0;i<8;i++)
  {
    result.raw_get_cell(i, result_cell, result_table_id, result_column_id);
    result_cell->get_int(int_value);
    ASSERT_EQ(i * 2, int_value);
  }

  ups_row.set_delete_row(true);

  ObRowFuse::fuse_row(&ups_row, &row, &result);

  for(int i=0;i<8;i++)
  {
    result.raw_get_cell(i, result_cell, result_table_id, result_column_id);
    result_cell->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }

  for(int i=0;i<8;i++)
  {
    cell.set_int(i, false);
    ups_row.raw_set_cell(i, cell);
  }

  ups_row.set_delete_row(false);
  ObRowFuse::fuse_row(&ups_row, &row, &result);

  for(int i=0;i<8;i++)
  {
    result.raw_get_cell(i, result_cell, result_table_id, result_column_id);
    result_cell->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }
}
Ejemplo n.º 15
0
TEST_F(ObRowFuseTest, test2)
{
  uint64_t TABLE_ID = 1000;

  ObRowDesc row_desc;
  for(int i=0;i<8;i++)
  {
    row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + i);
  }

  ObRow row;
  row.set_row_desc(row_desc);
  ObObj value;

  for(int i=0;i<8;i++)
  {
    value.set_int(i);
    row.raw_set_cell(i, value);
  }

  ObRowDesc ups_row_desc;
  for(int i=0;i<4;i++)
  {
    ups_row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + i);
  }

  ObUpsRow ups_row;
  ups_row.set_row_desc(ups_row_desc);

  ups_row.set_delete_row(true);

  for(int i=0;i<4;i++)
  {
    value.set_ext(ObActionFlag::OP_NOP);
    ups_row.raw_set_cell(i, value); 
  }

  ObRow result;
  OK(ObRowFuse::fuse_row(&ups_row, &row, &result));

  uint64_t table_id = OB_INVALID_ID;
  uint64_t column_id = OB_INVALID_ID;
  
  const ObObj *cell = NULL;

  for(int i=0;i<4;i++)
  {
    OK(result.raw_get_cell(i, cell, table_id, column_id));
    ASSERT_EQ(ObNullType, cell->get_type());
  }

  for(int i=4;i<8;i++)
  {
    int64_t int_value = 0;
    OK(result.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(int_value, i);
  }


  for(int i=0;i<4;i++)
  {
    value.set_int(i+100);
    ups_row.raw_set_cell(i, value);
  }

  OK(ObRowFuse::fuse_row(&ups_row, &row, &result));
  for(int i=0;i<4;i++)
  {
    int64_t int_value = 0;
    OK(result.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(int_value, i+100);
  }

  for(int i=4;i<8;i++)
  {
    int64_t int_value = 0;
    OK(result.raw_get_cell(i, cell, table_id, column_id));
    cell->get_int(int_value);
    ASSERT_EQ(int_value, i);
  }

  ups_row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + 10);
  ASSERT_TRUE(OB_SUCCESS != ObRowFuse::fuse_row(&ups_row, &row, &result));
}
Ejemplo n.º 16
0
TEST_F(ObRowStoreTest, rowkey)
{
  ObRowStore row_store;

  char rowkey_buf[100];
  ObString rowkey;

  ObRowDesc row_desc;
  for(int64_t i=0;i<10;i++)
  {
    row_desc.add_column_desc(TABLE_ID, i + OB_APP_MIN_COLUMN_ID);
  }

  ObRow row;
  row.set_row_desc(row_desc);

  ObObj cell;
  const ObRowStore::StoredRow *stored_row = NULL;
  const ObObj *value = NULL;
  uint64_t table_id = OB_INVALID_ID;
  uint64_t column_id = OB_INVALID_ID;
  int64_t int_value = 0;

  ObCompactCellIterator cell_reader;


  for(int64_t j=0;j<9;j++)
  {
    sprintf(rowkey_buf, "rowkey_%05ld", j);
    rowkey.assign_ptr(rowkey_buf, (int32_t)strlen(rowkey_buf));
    for(int64_t i=0;i<10;i++)
    {
      cell.set_int(j * 1000 + i);
      OK(row.raw_set_cell(i, cell));
    }
    OK(row_store.add_row(rowkey, row, stored_row));

    OK(cell_reader.init(stored_row->get_compact_row(), DENSE_SPARSE));

    OK(cell_reader.next_cell());
    OK(cell_reader.get_cell(value));
    value->get_varchar(rowkey);
    ASSERT_EQ(0, strncmp(rowkey_buf, rowkey.ptr(), rowkey.length()));

    for(int64_t i=0;i<10;i++)
    {
      OK(cell_reader.next_cell());
      OK(cell_reader.get_cell(column_id, value));
      value->get_int(int_value);
      ASSERT_EQ(j * 1000 + i, int_value);
    }
  }

  
  for(int64_t j=0;j<9;j++)
  {
    OK(row_store.get_next_row(&rowkey, row));
    sprintf(rowkey_buf, "rowkey_%05ld", j);
    ASSERT_EQ(0, strncmp(rowkey_buf, rowkey.ptr(), rowkey.length()));

    for(int64_t i=0;i<10;i++)
    {
      OK(row.raw_get_cell(i, value, table_id, column_id));
      value->get_int(int_value);
      ASSERT_EQ( j * 1000 + i, int_value);
    }
  }
}
Ejemplo n.º 17
0
TEST(ObPrivilege, test)
{
  ObPrivilege privilege;
  int ret = OB_SUCCESS;
  ret = privilege.init();
  ASSERT_EQ(OB_SUCCESS, ret);
  // add_user_table_privilege_per
  ObRow row;
  ObRowDesc row_desc;
  ObRow row2;
  ObRowDesc row_desc2;
  const uint64_t OB_USERS_TID = 20;
  const uint64_t OB_USERS_USERNAME_CID = 30;
  const uint64_t OB_USERS_USERID_CID = 31;
  const uint64_t OB_USERS_PASSWORD_CID = 32;
  const uint64_t OB_USERS_COMMENT_CID = 34;
  const uint64_t OB_USERS_PRIV_ALL_CID = 35;
  const uint64_t OB_USERS_PRIV_ALTER_CID = 36;
  const uint64_t OB_USERS_PRIV_CREATE_CID = 37;
  const uint64_t OB_USERS_PRIV_CREATE_USER_CID = 38;
  const uint64_t OB_USERS_PRIV_DELETE_CID = 39;
  const uint64_t OB_USERS_PRIV_DROP_CID = 40;
  const uint64_t OB_USERS_PRIV_GRANT_OPTION_CID = 41;
  const uint64_t OB_USERS_PRIV_INSERT_CID = 42;
  const uint64_t OB_USERS_PRIV_UPDATE_CID = 43;
  const uint64_t OB_USERS_PRIV_SELECT_CID = 44;
  const uint64_t OB_USERS_LOCKED_CID = 45;

  const uint64_t OB_TABLE_PRIVILEGES_TID = 40;
  const uint64_t OB_TABLE_PRIVILEGES_USERID_CID = 50;
  const uint64_t OB_TABLE_PRIVILEGES_TABLEID_CID = 51;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_ALL_CID = 52;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_ALTER_CID = 53;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_CREATE_CID = 54;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_CREATE_USER_CID = 55;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_DELETE_CID = 56;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_DROP_CID = 57;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_GRANT_OPTION_CID = 58;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_INSERT_CID = 59;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_UPDATE_CID = 60;
  const uint64_t OB_TABLE_PRIVILEGES_PRIV_SELECT_CID = 61;

  // set row desc, set table __users
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_USERNAME_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_USERID_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PASSWORD_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_COMMENT_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_ALL_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_ALTER_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_CREATE_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_CREATE_USER_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_DELETE_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_DROP_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_GRANT_OPTION_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_INSERT_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_UPDATE_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_PRIV_SELECT_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc.add_column_desc(OB_USERS_TID, OB_USERS_LOCKED_CID));
  //set row desc , set table __table_privileges
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_USERID_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_TABLEID_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_ALL_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_ALTER_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_CREATE_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_CREATE_USER_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_DELETE_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_DROP_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_GRANT_OPTION_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_INSERT_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_UPDATE_CID));
  ASSERT_EQ(OB_SUCCESS, row_desc2.add_column_desc(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_SELECT_CID));
  row.set_row_desc(row_desc);
  row2.set_row_desc(row_desc2);
  //=======================================================================================
  // set row data
  ObObj username;
  ObString str;
  str.assign_ptr(const_cast<char*>("zhangsan"), static_cast<int32_t>(strlen("zhangsan")));
  username.set_varchar(str);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_USERNAME_CID, username));
  ObObj userid;
  userid.set_int(10);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_USERID_CID, userid));

  ObObj password;
  str.assign_ptr(const_cast<char*>("encryptedpass"), static_cast<int32_t>(strlen("encryptedpass")));
  password.set_varchar(str);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PASSWORD_CID, password));

  ObObj comment;
  str.assign_ptr(const_cast<char*>("comment content"), static_cast<int32_t>(strlen("comment content")));
  comment.set_varchar(str);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_COMMENT_CID, comment));
  /*  PRIV_ALL  PRIV_ALTER  PRIV_CREATE   PRIV_CREATE_USER    PRIV_DELETE   PRIV_DROP   PRIV_GRANT_OPTION   PRIV_INSERT   PRIV_UPDATE   PRIV_SELECT
   *    1           1            0               0                1           0               0                 1             0             0
   *
   *
   *
   */
  /* set privilege-related cell*/
  ObObj priv_all;
  priv_all.set_int(1);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_ALL_CID, priv_all));
  ObObj priv_alter;
  priv_alter.set_int(1);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_ALTER_CID, priv_alter));
  ObObj priv_create;
  priv_create.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_CREATE_CID, priv_create));
  ObObj priv_create_user;
  priv_create_user.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_CREATE_USER_CID, priv_create_user));
  ObObj priv_delete;
  priv_delete.set_int(1);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_DELETE_CID, priv_delete));
  ObObj priv_drop;
  priv_drop.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_DROP_CID, priv_drop));
  ObObj priv_grant_option;
  priv_grant_option.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_GRANT_OPTION_CID, priv_grant_option));
  ObObj priv_insert;
  priv_insert.set_int(1);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_INSERT_CID, priv_insert));
  ObObj priv_update;
  priv_update.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_UPDATE_CID, priv_update));
  ObObj priv_select;
  priv_select.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_PRIV_SELECT_CID, priv_select));
  /* finish set privilege-related cell */
  ObObj locked;
  locked.set_int(0);//locked
  ASSERT_EQ(OB_SUCCESS, row.set_cell(OB_USERS_TID, OB_USERS_LOCKED_CID, locked));
  //=====================================================================================
  ObObj table_user_id;
  table_user_id.set_int(10);//user id
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_USERID_CID, table_user_id));
  ObObj table_table_id;
  table_table_id.set_int(100);//table id
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_TABLEID_CID, table_table_id));
  //start set privilege-related cell for table __table_privileges
  // user:       1100100100
  // user_table: 0000010100
  ObObj table_priv_all;
  table_priv_all.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_ALL_CID, table_priv_all));
  ObObj table_priv_alter;
  table_priv_alter.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_ALTER_CID, table_priv_alter));
  ObObj table_priv_create;
  table_priv_create.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_CREATE_CID, table_priv_create));
  ObObj table_priv_create_user;
  table_priv_create_user.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_CREATE_USER_CID, table_priv_create_user));
  ObObj table_priv_delete;
  table_priv_delete.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_DELETE_CID, table_priv_delete));
  ObObj table_priv_drop;
  table_priv_drop.set_int(1);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_DROP_CID, table_priv_drop));
  ObObj table_priv_grant_option;
  table_priv_grant_option.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_GRANT_OPTION_CID, table_priv_grant_option));
  ObObj table_priv_insert;
  table_priv_insert.set_int(1);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_INSERT_CID, table_priv_insert));
  ObObj table_priv_update;
  table_priv_update.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_UPDATE_CID, table_priv_update));
  ObObj table_priv_select;
  table_priv_select.set_int(0);
  ASSERT_EQ(OB_SUCCESS, row2.set_cell(OB_TABLE_PRIVILEGES_TID, OB_TABLE_PRIVILEGES_PRIV_SELECT_CID, table_priv_select));
  /* finished set privilege-related cell for table __table_privileges */
  //============================================================================================================
  //start testing
  ASSERT_EQ(OB_SUCCESS, privilege.add_users_entry(row));
  ASSERT_EQ(OB_SUCCESS, privilege.add_table_privileges_entry(row2));

  ObString user1;
  ObString pass1;
  user1.assign_ptr(const_cast<char*>("zhangsan"), static_cast<int32_t>(strlen("zhangsan")));
  pass1.assign_ptr(const_cast<char*>("encryptedpass"), static_cast<int32_t>(strlen("encryptedpass")));
  ASSERT_EQ(OB_SUCCESS, privilege.user_is_valid(user1, pass1));

  ObString user2;
  ObString pass2;
  user2.assign_ptr(const_cast<char*>("lisi"), static_cast<int32_t>(strlen("lisi")));
  pass2.assign_ptr(const_cast<char*>("lisipass"), static_cast<int32_t>(strlen("lisipass")));
  ASSERT_EQ(OB_ERR_USER_NOT_EXIST, privilege.user_is_valid(user2, pass2));

  ObString user3;
  ObString pass3;
  user3.assign_ptr(const_cast<char*>("zhangsan"), static_cast<int32_t>(strlen("zhangsan")));
  pass3.assign_ptr(const_cast<char*>("xxxx"), static_cast<int32_t>(strlen("xxxx")));
  ASSERT_EQ(OB_ERR_WRONG_PASSWORD, privilege.user_is_valid(user3, pass3));
  //=========================================================================================================
  // OB_PRIV_ALL从第一个bit开始
  // user:       1100100100
  // user_table: 0000010100
  ObPrivilege::TablePrivilege table_privilege;
  // on table_id=100, user zhangsan have:
  // user:       1100100100
  // user_table: 0000010100
  //
  // we test:    0111010000 , result should be true
  table_privilege.table_id_ = 100;
  EXPECT_TRUE(table_privilege.privileges_.add_member(OB_PRIV_ALTER));
  EXPECT_TRUE(table_privilege.privileges_.add_member(OB_PRIV_CREATE));
  EXPECT_TRUE(table_privilege.privileges_.add_member(OB_PRIV_CREATE_USER));
  EXPECT_TRUE(table_privilege.privileges_.add_member(OB_PRIV_DROP));
  ObArray<ObPrivilege::TablePrivilege> arr;
  ASSERT_EQ(OB_SUCCESS, arr.push_back(table_privilege));
  ASSERT_EQ(OB_SUCCESS, privilege.has_needed_privileges(user1, arr));
  arr.pop_back();

  // we test:    1100001100 result should be false
  /*  PRIV_ALL  PRIV_ALTER  PRIV_CREATE   PRIV_CREATE_USER    PRIV_DELETE   PRIV_DROP   PRIV_GRANT_OPTION   PRIV_INSERT   PRIV_UPDATE   PRIV_SELECT*/
  EXPECT_TRUE(table_privilege.privileges_.add_member(OB_PRIV_ALL));
  EXPECT_TRUE(table_privilege.privileges_.add_member(OB_PRIV_ALTER));
  EXPECT_TRUE(table_privilege.privileges_.add_member(OB_PRIV_GRANT_OPTION));
  EXPECT_TRUE(table_privilege.privileges_.add_member(OB_PRIV_INSERT));
  ASSERT_EQ(OB_SUCCESS, arr.push_back(table_privilege));
  ASSERT_EQ(OB_ERR_NO_PRIVILEGE, privilege.has_needed_privileges(user1, arr));
  arr.pop_back();

}
Ejemplo n.º 18
0
// ObRow.reset
TEST_F(ObRowTest, reset_test)
{
  ObRow row;
  ObRowDesc row_desc;
  const uint64_t TABLE_ID = 1001;
  const int64_t COLUMN_NUM = 8;
  ObObj cell;
  const ObObj *value = NULL;
  uint64_t table_id = 0;
  uint64_t column_id = 0;
  int64_t int_value = 0;

  row_desc.set_rowkey_cell_count(2);

  for (int i = 0; i < COLUMN_NUM; i ++)
  {
    row_desc.add_column_desc(TABLE_ID, OB_APP_MIN_COLUMN_ID + i);
  }
  row.set_row_desc(row_desc);

  for (int i = 0; i < COLUMN_NUM; i ++)
  {
    cell.set_int(i);
    row.raw_set_cell(i, cell);
  }

  row.reset(true, ObRow::DEFAULT_NULL);
  for (int i = 0; i < row_desc.get_rowkey_cell_count(); i ++)
  {
    row.raw_get_cell(i, value, table_id, column_id);
    value->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }

  for (int64_t i = row_desc.get_rowkey_cell_count(); i < COLUMN_NUM; i ++)
  {
    row.raw_get_cell(i, value, table_id, column_id);
    ASSERT_TRUE( ObNullType == value->get_type() );
  }

  row_desc.add_column_desc(OB_INVALID_ID, OB_ACTION_FLAG_COLUMN_ID);
  cell.set_ext(ObActionFlag::OP_DEL_ROW);
  row.set_cell(OB_INVALID_ID, OB_ACTION_FLAG_COLUMN_ID, cell);

  row.reset(true, ObRow::DEFAULT_NOP);

  for (int i = 0; i < row_desc.get_rowkey_cell_count(); i ++)
  {
    row.raw_get_cell(i, value, table_id, column_id);
    value->get_int(int_value);
    ASSERT_EQ(i, int_value);
  }

  for (int64_t i = row_desc.get_rowkey_cell_count(); i < COLUMN_NUM; i ++)
  {
    row.raw_get_cell(i, value, table_id, column_id);
    ASSERT_TRUE( ObActionFlag::OP_NOP == value->get_ext() ) << "ext value: " << value->get_ext();
  }

  row.get_cell(OB_INVALID_ID, OB_ACTION_FLAG_COLUMN_ID, value);
  ASSERT_TRUE( ObActionFlag::OP_ROW_DOES_NOT_EXIST == value->get_ext() );
}
Ejemplo n.º 19
0
TEST_F(ObRunFileTest, test_all)
{
  static const int64_t BUFFER_SIZE = 1024;
  char compact_row_buff_[BUFFER_SIZE];
  ObRunFile run_file;
  char* fname = (char*)"ob_run_file_test.run";
  ObString filename;
  ASSERT_EQ(false, run_file.is_opened());
  ASSERT_NE(OB_SUCCESS, run_file.open(filename));
  filename.assign(fname, strlen(fname));
  ASSERT_EQ(OB_SUCCESS, run_file.open(filename));
  ASSERT_EQ(true, run_file.is_opened());
  const int64_t bucket_count = 4;
  const int64_t run_count_per_bucket = 8;
  for (int64_t j = 0; j < run_count_per_bucket; ++j)
  {
    for (int64_t i = 0; i < bucket_count; ++i)
    {
      ASSERT_EQ(OB_SUCCESS, run_file.begin_append_run(i));
      const ObRow *row = NULL;
      ObString compact_row;
      compact_row.assign_buffer(compact_row_buff_, BUFFER_SIZE);
      ASSERT_EQ(OB_SUCCESS, input_data_.open());
      while (OB_SUCCESS == input_data_.get_next_row(row))
      {
        compact_row.assign_buffer(compact_row_buff_, BUFFER_SIZE);
        ASSERT_EQ(OB_SUCCESS, ObRowUtil::convert(*row, compact_row));
        ASSERT_EQ(OB_SUCCESS, run_file.append_row(compact_row));
      } // end for
      ASSERT_EQ(OB_SUCCESS, input_data_.close());
      ASSERT_EQ(OB_SUCCESS, run_file.end_append_run());
    } // end for
  }
  // read and check
  ObRow row;
  const ObObj *cell = NULL;
  uint64_t table_id;
  uint64_t column_id;
  ASSERT_EQ(OB_SUCCESS, input_data_.open());
  row.set_row_desc(input_data_.get_row_desc());
  for (int64_t i = 0; i < bucket_count; ++i)
  {
    int64_t run_count = 0;
    ASSERT_EQ(OB_SUCCESS, run_file.begin_read_bucket(i, run_count));
    ASSERT_EQ(run_count, run_count_per_bucket);
    for (int64_t j = 0; j < ROW_COUNT; ++j)
    {
      for (int64_t k = 0; k < run_count; ++k)
      {
        ASSERT_EQ(OB_SUCCESS, run_file.get_next_row(k, row));
        ASSERT_EQ(OB_SUCCESS, row.raw_get_cell(1, cell, table_id, column_id));
        int64_t int_value;
        ASSERT_EQ(OB_SUCCESS, cell->get_int(int_value));
        ASSERT_EQ(j, int_value);
      }
    } // end for
    for (int64_t k = 0; k < run_count; ++k)
    {
      ASSERT_EQ(OB_ITER_END, run_file.get_next_row(k, row));
    }
    ASSERT_EQ(OB_SUCCESS, run_file.end_read_bucket());
  }
  ASSERT_EQ(OB_SUCCESS, run_file.close());
  ASSERT_EQ(false, run_file.is_opened());
  ASSERT_EQ(OB_SUCCESS, input_data_.close());
}