Exemplo n.º 1
0
TEST(ObObj,Serialize_int_add)
{
  ObObj t;
  t.set_int(9900);

  int64_t len = t.get_serialize_size();

  ASSERT_EQ(len,3);

  char *buf = (char *)malloc(len);

  int64_t pos = 0;
  ASSERT_EQ(t.serialize(buf,len,pos),OB_SUCCESS);
  ASSERT_EQ(pos,len);

  ObObj f;
  pos = 0;
  ASSERT_EQ(f.deserialize(buf,len,pos),OB_SUCCESS);
  ASSERT_EQ(pos,len);

  int64_t r = 0;
  int64_t l = 0;

  ASSERT_EQ(f.get_type(),t.get_type());
  f.get_int(r);

  t.get_int(l);
  ASSERT_EQ(r,l);

  free(buf);
}
Exemplo n.º 2
0
TEST(ObObj,Serialize_precise_datetime)
{
  ObObj t1;
  t1.set_precise_datetime(221348087492);

  int64_t len = t1.get_serialize_size();

  char *buf = (char *)malloc(len);

  int64_t pos = 0;
  ASSERT_EQ(t1.serialize(buf,len,pos),OB_SUCCESS);

  ObObj f;
  pos = 0;
  ASSERT_EQ(f.deserialize(buf,len,pos),OB_SUCCESS);

  ASSERT_EQ(f.get_type(),t1.get_type());


  ObPreciseDateTime l = 0;
  ObPreciseDateTime r = 0;

  f.get_precise_datetime(l);
  t1.get_precise_datetime(r);

  ASSERT_EQ(l,r);

  free(buf);
}
Exemplo n.º 3
0
TEST(ObObj,Serialize_bool)
{
  ObObj t;
  t.set_bool(true);

  int64_t len = t.get_serialize_size();

  ASSERT_EQ(len,2);

  char *buf = (char *)malloc(len);

  int64_t pos = 0;
  ASSERT_EQ(t.serialize(buf,len,pos),OB_SUCCESS);
  ASSERT_EQ(pos,len);

  ObObj f;
  pos = 0;
  ASSERT_EQ(f.deserialize(buf,len,pos),OB_SUCCESS);
  ASSERT_EQ(pos,len);

  bool r = false;
  bool l = false;

  ASSERT_EQ(f.get_type(),t.get_type());
  f.get_bool(r);

  t.get_bool(l);
  ASSERT_EQ(r,l);
  free(buf);
}
Exemplo n.º 4
0
TEST(ObObj,Serialize_createtime)
{
  ObCreateTime data[] = {1,28,1,static_cast<int64_t>(UINT32_MAX),INT64_MAX,124543900,221348087492};
  int64_t need_len = 0;
  for(uint32_t i=0;i<sizeof(data)/sizeof(data[0]);++i)
  {
    need_len += serialization::encoded_length_createtime(data[i]);
  }
  char *buf = (char *)malloc(need_len);
  ObObj t;
  int64_t pos = 0;

  for(uint32_t i=0;i<sizeof(data)/sizeof(data[0]);++i)
  {
    t.reset();
    t.set_createtime(data[i]);
    ASSERT_EQ(t.serialize(buf,need_len,pos),OB_SUCCESS);
  }

  pos = 0;

  ObCreateTime v = 0;
  for(uint32_t i=0;i<sizeof(data)/sizeof(data[0]);++i)
  {
    t.reset();
    ASSERT_EQ(t.deserialize(buf,need_len,pos),OB_SUCCESS);
    ASSERT_EQ(t.get_createtime(v),OB_SUCCESS);
    ASSERT_EQ(v,data[i]);
  }
  free(buf);
}
Exemplo n.º 5
0
TEST(ObObj,int_boundary)
{
  int64_t need_len = 0;

  int64_t data[] = {1,28,-1,INT32_MIN,static_cast<int64_t>(UINT32_MAX),INT64_MAX,INT64_MIN,UINT64_MAX,124543900};
  for(uint32_t i=0;i<sizeof(data)/sizeof(data[0]);++i)
  {
    need_len += serialization::encoded_length_int(data[i]);
  }
  char *buf = (char *)malloc(need_len);
  ObObj t;
  int64_t pos = 0;

  for(uint32_t i=0;i<sizeof(data)/sizeof(data[0]);++i)
  {
    t.reset();
    t.set_int(data[i]);
    ASSERT_EQ(t.serialize(buf,need_len,pos),OB_SUCCESS);
  }

  pos = 0;

  int64_t v = 0;
  for(uint32_t i=0;i<sizeof(data)/sizeof(data[0]);++i)
  {
    t.reset();
    ASSERT_EQ(t.deserialize(buf,need_len,pos),OB_SUCCESS);
    ASSERT_EQ(t.get_int(v),OB_SUCCESS);
    ASSERT_EQ(v,data[i]);
  }
  free(buf);
}
Exemplo n.º 6
0
    int get_rowkey_compatible(const char* buf, const int64_t buf_len, int64_t & pos,
        const ObRowkeyInfo& info, ObObj* array, int64_t& size, bool& is_binary_rowkey)
    {
      int ret = OB_SUCCESS;
      ObObj obj;
      int64_t obj_count = 0;
      ObString str_value;

      is_binary_rowkey = false;
      if ( OB_SUCCESS == (ret = obj.deserialize(buf, buf_len, pos)) )
      {
        if (ObIntType == obj.get_type() && (OB_SUCCESS == (ret = obj.get_int(obj_count))))
        {
          // new rowkey format.
          for (int64_t i = 0; i < obj_count && OB_SUCCESS == ret; ++i)
          {
            if (i >= size)
            {
              ret = OB_SIZE_OVERFLOW;
            }
            else
            {
              ret = array[i].deserialize(buf, buf_len, pos);
            }
          }

          if (OB_SUCCESS == ret) size = obj_count;
        }
        else if (ObVarcharType == obj.get_type() && OB_SUCCESS == (ret = obj.get_varchar(str_value)))
        {
          is_binary_rowkey = true;
          // old fashion , binary rowkey stream
          if (size < info.get_size())
          {
            TBSYS_LOG(WARN, "input size=%ld not enough, need rowkey obj size=%ld", size, info.get_size());
            ret = OB_SIZE_OVERFLOW;
          }
          else if (str_value.length() == 0)
          {
            // allow empty binary rowkey , incase min, max range.
            size = 0;
          }
          else if (str_value.length() < info.get_binary_rowkey_length())
          {
            TBSYS_LOG(WARN, "binary rowkey length=%d < need rowkey length=%ld",
                str_value.length(), info.get_binary_rowkey_length());
            ret = OB_SIZE_OVERFLOW;
          }
          else
          {
            size = info.get_size();
            ret = ObRowkeyHelper::binary_rowkey_to_obj_array(info, str_value, array, size);
          }
        }
      }

      return ret;
    }
Exemplo n.º 7
0
 int get_str_obj_value(const char* buf, const int64_t buf_len, int64_t & pos, ObString & str_value)
 {
   int ret = OB_SUCCESS;
   ObObj obj;
   if ( OB_SUCCESS == (ret = obj.deserialize(buf, buf_len, pos))
       && ObVarcharType == obj.get_type())
   {
     ret = obj.get_varchar(str_value);
   }
   return ret;
 }
Exemplo n.º 8
0
 int get_int_obj_value(const char* buf, const int64_t buf_len, int64_t & pos, int64_t & int_value)
 {
   int ret = OB_SUCCESS;
   ObObj obj;
   if ( OB_SUCCESS == (ret = obj.deserialize(buf, buf_len, pos))
       && ObIntType == obj.get_type())
   {
     ret = obj.get_int(int_value);
   }
   return ret;
 }
Exemplo n.º 9
0
 int ObReadParam::deserialize_reserve_param(const char * buf, const int64_t data_len, int64_t & pos)
 {
   ObObj obj;
   int64_t int_value = 0;
   int ret = obj.deserialize(buf, data_len, pos);
   if (OB_SUCCESS == ret)
   {
     ret = obj.get_int(int_value);
     if (OB_SUCCESS == ret)
     {
       //is read master
       set_is_read_consistency(int_value);
     }
   }
   return ret;
 }
Exemplo n.º 10
0
TEST(ObObj, test_bug)
{
  ObObj obj;
  obj.set_int(100, false);
  char buf[2048];
  int64_t len = 2048;
  int64_t pos = 0;
  ASSERT_EQ(obj.serialize(buf, len, pos), OB_SUCCESS);

  pos = 0;
  ObObj temp;
  temp.set_int(200, true);
  temp.reset();

  ASSERT_EQ(temp.deserialize(buf, len, pos), OB_SUCCESS);
  ASSERT_EQ(temp == obj, true);

  ObObj test;
  test.set_int(300, true);
  test = temp;
  ASSERT_EQ(test == temp, true);
}
Exemplo n.º 11
0
TEST(ObObj, performance)
{
  // int64_t start_time = tbsys::CTimeUtil::getTime();
  //const int64_t MAX_COUNT = 10 * 1000 * 1000L;
  const int64_t MAX_COUNT = 1000L;
  ObObj obj;
  char buf[2048];
  int64_t len = 2048;
  int64_t pos = 0;
  int64_t data = 0;
  for (int64_t i = 0; i < MAX_COUNT; ++i)
  {
    obj.set_int(i);
    pos = 0;
    ASSERT_EQ(obj.serialize(buf, len, pos), OB_SUCCESS);
    pos = 0;
    ASSERT_EQ(obj.deserialize(buf, len, pos), OB_SUCCESS);
    ASSERT_EQ(obj.get_int(data), OB_SUCCESS);
    ASSERT_EQ(data, i);
  }

  const char *tmp = "Hello12344556666777777777777545352454254254354354565463241242354345345345235345";
  ObObj obj2;
  ObString string;
  ObString string2;
  string.assign_ptr(const_cast<char *>(tmp), 1024);
  obj2.set_varchar(string);
  for (register int64_t i = 0; i < MAX_COUNT; ++i )
  {
    pos = 0;
    ASSERT_EQ(obj2.serialize(buf, len, pos), OB_SUCCESS);
    pos = 0;
    ASSERT_EQ(obj2.deserialize(buf, len, pos), OB_SUCCESS);
    ASSERT_EQ(obj2.get_varchar(string2), OB_SUCCESS);
  }
  // int64_t end_time = tbsys::CTimeUtil::getTime();
  //printf("using time:%ld\n", end_time - start_time);
}
Exemplo n.º 12
0
    int ObSqlGetParam::deserialize_int(const char* buf, const int64_t data_len, int64_t& pos,
        int64_t& value) const
    {
      int ret         = OB_SUCCESS;
      ObObjType type  = ObNullType;
      ObObj obj;

      ret = obj.deserialize(buf, data_len, pos);
      if (OB_SUCCESS == ret)
      {
        type = obj.get_type();
        if (ObIntType == type)
        {
          obj.get_int(value);
        }
        else
        {
          TBSYS_LOG(WARN, "expected deserialize int type, but get type=%d", type);
          ret = OB_ERROR;
        }
      }

      return ret;
    }
Exemplo n.º 13
0
TEST(ObObj,extend_type)
{
  ObObj t1;
  t1.set_ext(90);

  int64_t len = t1.get_serialize_size();

  ASSERT_EQ(len,2);

  char *buf = (char *)malloc(len);

  int64_t pos = 0;
  ASSERT_EQ(t1.serialize(buf,len,pos),OB_SUCCESS);

  ObObj f;
  pos = 0;
  ASSERT_EQ(f.deserialize(buf,len,pos),OB_SUCCESS);

  int64_t e = 0;
  ASSERT_EQ(f.get_ext(e),0);

  ASSERT_EQ(e,90);
  free(buf);
}
Exemplo n.º 14
0
    int ObSqlReadParam::deserialize_basic_param(const char * buf, const int64_t data_len, int64_t & pos)
    {
      ObObj obj;
      int ret = OB_SUCCESS;
      int64_t int_value = 0;
      // read consistency
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            //is read consistency
            set_is_read_consistency(int_value);
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }
      // result cached
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            //is read consistency
            set_is_result_cached(int_value > 0);
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }
      // data_version
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            // data version
            set_data_version(int_value);
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }
      // table id
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            table_id_ = int_value;
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }
      // renamed table id
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            renamed_table_id_ = int_value;
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }

      if (OB_SUCCESS == ret)
      {
        if (OB_SUCCESS != (ret = obj.deserialize(buf, data_len, pos)))
        {
          TBSYS_LOG(WARN, "fail to deserialize obj:ret[%d]", ret);
        }
        else if (OB_SUCCESS != (ret = obj.get_bool(only_static_data_)))
        {
          TBSYS_LOG(WARN, "fail to get bool:ret[%d]", ret);
        }
      }
      return ret;
    }