Пример #1
0
bool GetNotExistRows::check_result(const uint32_t min_key_include, const uint32_t max_key_include, ObScanner &result,
  void *arg)
{
  bool res = true;
  int err = OB_SUCCESS;
  UNUSED(min_key_include);
  UNUSED(max_key_include);
  ObGetParam *get_param = reinterpret_cast<ObGetParam*>(arg);
  if(result.get_cell_num() != get_param->get_cell_size())
  {
    TBSYS_LOG(WARN,"result cell number error [got:%ld,expcted:%ld]", result.get_cell_num(),  get_param->get_cell_size());
    err = OB_ERR_UNEXPECTED;
  }
  int64_t got_cell_num = 0;
  ObCellInfo *cur_cell = NULL;
  for (got_cell_num = 0; (got_cell_num < get_param->get_cell_size()) && (OB_SUCCESS == err); got_cell_num++)
  {
    if (OB_SUCCESS != (err = result.next_cell()))
    {
      TBSYS_LOG(WARN,"fail to get next cell from result [err:%d]", err);
    }
    if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = result.get_cell(&cur_cell))))
    {
      TBSYS_LOG(WARN,"fail to get next cell from result [err:%d]", err);
    }
    if ((OB_SUCCESS == err) 
      && ((cur_cell->table_name_ != msolap::target_table_name) 
      || (cur_cell->row_key_ != (*get_param)[got_cell_num]->row_key_) 
      || (ObActionFlag::OP_ROW_DOES_NOT_EXIST != cur_cell->value_.get_ext())))
    {
      TBSYS_LOG(WARN,"cell content error");
      err = OB_ERR_UNEXPECTED;
    }
  }
  if ((OB_SUCCESS == err) && (OB_ITER_END != result.next_cell()))
  {
    TBSYS_LOG(WARN,"fail to get enough cells from result");
    err = OB_ERR_UNEXPECTED;
  }
  if (OB_SUCCESS != err)
  {
    res = false;
  }
  return res;
}
bool MultiGetP::check_result(const uint32_t min_key_include, const uint32_t max_key_include, ObScanner &result,
  void *arg)
{
  bool res = true;
  int err = OB_SUCCESS;
  UNUSED(min_key_include);
  UNUSED(max_key_include);
  ObGetParam *get_param = reinterpret_cast<ObGetParam*>(arg);
  ObCellInfo *cur_cell = NULL;

  if ((OB_SUCCESS == err) && (result.get_cell_num() != get_param->get_cell_size()))
  {
    TBSYS_LOG(WARN,"result cell count not correct [got_cell_count:%ld,request_cell_count:%ld]", result.get_cell_num(), 
      get_param->get_cell_size());
    err = OB_ERR_UNEXPECTED;
  }
  for (int64_t i = 0; (i < get_param->get_cell_size()) && (OB_SUCCESS == err); i++)
  {
    if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = result.next_cell())))
    {
      TBSYS_LOG(WARN,"fail to get next cell [err:%d]", err);
    }
    if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = result.get_cell(&cur_cell))))
    {
      TBSYS_LOG(WARN,"fail to get next cell [err:%d]", err);
    }
    if (OB_SUCCESS == err)
    {
      if ((cur_cell->table_name_ != (*get_param)[i]->table_name_)
        || (cur_cell->column_name_ != (*get_param)[i]->column_name_)
        || (cur_cell->row_key_ != (*get_param)[i]->row_key_)
        || !(msolap::olap_check_cell(*cur_cell)))
      {
        TBSYS_LOG(WARN,"cell error");
        err = OB_ERR_UNEXPECTED;
      }
    }
  }
  if ((OB_SUCCESS == err) && (result.next_cell() != OB_ITER_END))
  {
    TBSYS_LOG(WARN,"result not ended as expected");
    err = OB_ERR_UNEXPECTED;
  }
  if (OB_SUCCESS != err)
  {
    res = false;
  }
  return res;
}
Пример #3
0
TEST(TestObScanner, row_num)
{
  ObScanner scanner;
  const int table_num = 3;
  const int row_num = 20;
  const int column_num = 5;
  buffer table_name[table_num];
  buffer row_key[row_num];
  buffer column_name[column_num];
  for (int i = 0; i < table_num; i++)
  {
    table_name[i].assigne("T").appende(i);
  }
  for (int i = 0; i < row_num; i++)
  {
    row_key[i].assigne("R").appende(i);
  }
  for (int i = 0; i < column_num; i++)
  {
    column_name[i].assigne("C").appende(i);
  }

  for (int i = 0; i < table_num; i++)
  {
    for (int j = 0; j < row_num; j++)
    {
      for (int k = 0; k < column_num; k++)
      {
        ObCellInfo cell;
        cell.table_name_ = table_name[i].get_obstring();
        cell.row_key_ = row_key[j].get_obstring();
        cell.column_name_ = column_name[k].get_obstring();
        cell.value_.set_int(1);
        scanner.add_cell(cell);
      }
    }
  }

  ASSERT_EQ(scanner.get_row_num(), table_num * row_num);
  ASSERT_EQ(scanner.get_cell_num(), table_num * row_num * column_num);
  scanner.set_whole_result_row_num(1000);

  buffer buf(1 << 21);
  scanner.serialize(buf.ptre(), buf.capacity(), buf.length());
  printf("%ld\n", buf.length());
  ObScanner dscanner;
  int64_t pos = 0;
  dscanner.deserialize(buf.ptre(), buf.length(), pos);

  EXPECT_EQ(dscanner.get_row_num(), table_num * row_num);
  EXPECT_EQ(dscanner.get_cell_num(), table_num * row_num * column_num);
  EXPECT_EQ(dscanner.get_whole_result_row_num(), 1000);

  scanner.clear();
  scanner.set_mem_size_limit(256);
  int j = 0, k = 0;

  int err = OB_SUCCESS;
  for (; j < row_num; j++)
  {
    k = 0;
    for (; k < column_num; k++)
    {
      ObCellInfo cell;
      cell.table_name_ = table_name[0].get_obstring();
      cell.row_key_ = row_key[j].get_obstring();
      cell.column_name_ = column_name[k].get_obstring();
      cell.value_.set_int(1);
      if (OB_SUCCESS != (err = scanner.add_cell(cell)))
      {
        break;
      }
    }
    if (OB_SUCCESS != err)
    {
      break;
    }
  }
  if (OB_SUCCESS != err)
  {
    scanner.rollback();
  }

  EXPECT_EQ(scanner.get_row_num(), j);
  EXPECT_EQ(scanner.get_cell_num(), j * column_num);

  buf.length() = 0;
  scanner.serialize(buf.ptre(), buf.capacity(), buf.length());
  printf("%ld\n", buf.length());
  dscanner.reset();
  pos = 0;
  dscanner.deserialize(buf.ptre(), buf.length(), pos);

  EXPECT_EQ(dscanner.get_row_num(), j);
  EXPECT_EQ(dscanner.get_cell_num(), j * column_num);
}
Пример #4
0
bool GetSingleRowAllColumn::check_result(const uint32_t min_key_include, const uint32_t max_key_include, ObScanner &result,
  void *arg)
{
  bool res = true;
  int err = OB_SUCCESS;
  UNUSED(min_key_include);
  UNUSED(max_key_include);
  ObGetParam *get_param = reinterpret_cast<ObGetParam*>(arg);
  uint32_t big_endian_rowkey_val = *(uint32_t*)(((*get_param)[0])->row_key_.ptr());
  uint32_t rowkey_val = ntohl(big_endian_rowkey_val);
  ObCellInfo target_cell;
  target_cell.row_key_.assign((char*)&big_endian_rowkey_val, sizeof(big_endian_rowkey_val));
  target_cell.table_name_ = msolap::target_table_name;
  if (result.get_cell_num() != msolap::max_column_id - msolap::min_column_id + 1)
  {
    TBSYS_LOG(WARN,"result cell number error [got:%ld,expcted:%ld]", result.get_cell_num(), 
      msolap::max_column_id - msolap::min_column_id + 1);
    err = OB_ERR_UNEXPECTED;
  }
  int64_t got_cell_num = 0;
  ObCellInfo *cur_cell = NULL;
  int64_t intval = 0;
  for (got_cell_num = 0; (got_cell_num < result.get_cell_num()) && (OB_SUCCESS == err); got_cell_num++)
  {
    if (OB_SUCCESS != (err = result.next_cell()))
    {
      TBSYS_LOG(WARN,"fail to get next cell from result [err:%d]", err);
    }
    if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = result.get_cell(&cur_cell))))
    {
      TBSYS_LOG(WARN,"fail to get next cell from result [err:%d]", err);
    }
    if ((OB_SUCCESS == err) 
      && ((cur_cell->table_name_ != msolap::target_table_name) 
      || (cur_cell->row_key_ != target_cell.row_key_) 
      || (cur_cell->column_name_.length() != 1)
      || (OB_SUCCESS != cur_cell->value_.get_int(intval))))
    {
      TBSYS_LOG(WARN,"cell content error");
      err = OB_ERR_UNEXPECTED;
    }
    if ((OB_SUCCESS == err) && ((cur_cell->column_name_.ptr()[0] < 'a') || (cur_cell->column_name_.ptr()[0] > 'z')))
    {
      TBSYS_LOG(WARN,"cell content error");
      err = OB_ERR_UNEXPECTED;
    }
    if (OB_SUCCESS == err)
    {
      int64_t expect_intval = 0;
      char c_name = cur_cell->column_name_.ptr()[0];
      switch (c_name)
      {
      case 'a':
      case 'b':
      case 'c':
      case 'd':
        expect_intval = ((unsigned char*)&big_endian_rowkey_val)[c_name - 'a'];
        break;
      default:
        expect_intval = rowkey_val;
      }
      if (expect_intval != intval)
      {
        TBSYS_LOG(WARN,"intvalue error [column_name:%c,expect_val:%ld,got_val:%ld,rowkey:%u]", c_name, 
          expect_intval, intval, rowkey_val);
        err = OB_ERR_UNEXPECTED;
      }
    }
  }
  if ((OB_SUCCESS == err) && (got_cell_num != msolap::max_column_id - msolap::min_column_id + 1))
  {
    TBSYS_LOG(WARN,"fail to get enough cells from result");
    err = OB_ERR_UNEXPECTED;
  }
  if ((OB_SUCCESS == err) && (OB_ITER_END != result.next_cell()))
  {
    TBSYS_LOG(WARN,"fail to get enough cells from result");
    err = OB_ERR_UNEXPECTED;
  }
  if (OB_SUCCESS != err)
  {
    res = false;
  }
  return res;
}