Esempio n. 1
0
void touch_file(bool single)
{
  FileUtils file;
  int ret = file.open("test1.txt", O_WRONLY | O_TRUNC | O_CREAT, 0644);
  ASSERT_NE(ret, 0);
  
  vector<string> v;
  gen_file(v, single);

  for (size_t i = 0;i < v.size();i++) {
    file.write(v[i].c_str(), v[i].size());
  }
  file.close();
}
      //test compatible between version2 && version2 compiled without -DCOMPATIBLE
      TEST_F(TestObSSTableTrailer, Compatible)
      {
        ObTrailerOffset trailer_offset;
        ObSSTableTrailer trailer;
        EXPECT_TRUE(default_range == trailer.get_range());
        FileUtils filesys;
        const char *compressor_name = "lzo1x_1_11_compress";
        int64_t file_len = FileDirectoryUtils::get_size(trailer_file_name);
        char *file_buf = reinterpret_cast<char*>(malloc(file_len));
        EXPECT_TRUE(NULL != file_buf);
        int64_t read_size = 0;
        filesys.open(trailer_file_name, O_RDONLY);
        read_size = filesys.read(file_buf, file_len);
        EXPECT_EQ(read_size, file_len);

        int64_t pos = 0;
        pos = trailer.get_serialize_size();
        trailer_offset.trailer_record_offset_ = 0;
        trailer_offset.deserialize(file_buf, file_len, pos);
        EXPECT_EQ(trailer_offset.trailer_record_offset_, 256 * 1024 - 1023);

        pos = 0;
        trailer.deserialize(file_buf, file_len, pos);
        EXPECT_EQ(0x300, trailer.get_trailer_version());
        EXPECT_EQ(1, trailer.get_table_version());
        EXPECT_EQ(0, trailer.get_first_block_data_offset());
        EXPECT_EQ(1, trailer.get_row_value_store_style());
        EXPECT_EQ(1023, trailer.get_block_count());
        EXPECT_EQ(2047, trailer.get_block_index_record_offset());
        EXPECT_EQ(1024, trailer.get_block_index_record_size());
        EXPECT_EQ(8, trailer.get_bloom_filter_hash_count());
        EXPECT_EQ(2047 + 1024, trailer.get_bloom_filter_record_offset());
        EXPECT_EQ(511, trailer.get_bloom_filter_record_size());
        EXPECT_EQ(2047+ 1024 + 511, trailer.get_schema_record_offset());
        EXPECT_EQ(1023, trailer.get_schema_record_size());
        EXPECT_EQ(64 * 1024, trailer.get_block_size());
        EXPECT_EQ(777, trailer.get_row_count());
        EXPECT_EQ(123456789, (int64_t)trailer.get_sstable_checksum());
        EXPECT_EQ(1001, (int64_t)trailer.get_first_table_id());
        EXPECT_EQ(123456789, trailer.get_frozen_time());
        int ret = memcmp(compressor_name, trailer.get_compressor_name(), strlen(compressor_name));
        EXPECT_EQ(0, ret);
        EXPECT_TRUE(default_range == trailer.get_range());
        free(file_buf);
        file_buf = NULL;
        filesys.close();
      }
      TEST_F(TestObSSTableTrailer, write_tariler_to_disk)
      {
        ObSSTableTrailer trailer;
        EXPECT_TRUE(default_range == trailer.get_range());
        FileUtils filesys;
        trailer.set_trailer_version(0x300);
        trailer.set_table_version(1);
        trailer.set_first_block_data_offset(0);
        trailer.set_row_value_store_style(1);
        trailer.set_block_count(1023);
        trailer.set_block_index_record_offset(2047);
        trailer.set_block_index_record_size(1024);
        trailer.set_bloom_filter_hash_count(8);
        trailer.set_bloom_filter_record_offset(2047 + 1024);
        trailer.set_bloom_filter_record_size(511);
        trailer.set_schema_record_offset(2047+ 1024 + 511);
        trailer.set_schema_record_size(1023);
        trailer.set_block_size(64 * 1024);
        trailer.set_row_count(777);
        trailer.set_sstable_checksum(123456789);
        trailer.set_first_table_id(1001);
        trailer.set_frozen_time(123456789);
        trailer.set_range_record_offset(2047+ 1024 + 511 +1023);
        trailer.set_range_record_size(0);
        const char *compressor_name = "lzo1x_1_11_compress";
        trailer.set_compressor_name(compressor_name);

        ObTrailerOffset trailer_offset;
        trailer_offset.trailer_record_offset_= 256 * 1024 - 1023;

        int64_t offset_len = trailer_offset.get_serialize_size();
        int64_t trailer_len = trailer.get_serialize_size();

        int64_t buf_size = offset_len + trailer_len;
        int64_t pos = 0;
        char *serialize_buf = reinterpret_cast<char*>(malloc(buf_size));
        EXPECT_TRUE(NULL != serialize_buf);
        trailer.serialize(serialize_buf, buf_size, pos);
        trailer_offset.serialize(serialize_buf, buf_size, pos);
        filesys.open(trailer_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        int64_t write_size;
        write_size = filesys.write(serialize_buf, buf_size);
        EXPECT_EQ(write_size, buf_size);
        free(serialize_buf);
        serialize_buf = NULL;
        filesys.close();
      }
Esempio n. 4
0
      TEST_F(TestObSSTableSchema, test_compatible)
      {
        ObSSTableSchema schema;
        const ObSSTableSchemaColumnDef *column      = NULL;

        int64_t file_len = FileDirectoryUtils::get_size(schema_file_name);
        char * file_buf = reinterpret_cast<char*>(malloc(file_len));
        int64_t pos = 0;
        FileUtils filesys;
        filesys.open(schema_file_name, O_RDONLY);
        int64_t read_size = filesys.read(file_buf, file_len);
        EXPECT_EQ(read_size, file_len);
        schema.deserialize(file_buf, file_len, pos);
        EXPECT_EQ(schema.get_column_count(), 550);
        int64_t index_find = 0;
        int64_t index = 0;
        int64_t table_schema_size = 0;
        int64_t group_schema_size = 0;
          
        for (uint64_t table_id = 1000; table_id < 1010; ++table_id)
        {
          schema.get_table_schema(table_id, table_schema_size);
          EXPECT_EQ(55, table_schema_size);
          for(uint64_t group_id = 1; group_id < 11; ++group_id)
          {
            schema.get_group_schema(table_id, group_id, group_schema_size);
            EXPECT_EQ(group_schema_size, (int64_t)group_id);
            for(uint64_t column_id = 0; column_id < group_id; ++column_id)
            {
              index_find  = schema.find_column_id(table_id, group_id, column_id);
              column = schema.get_column_def(index_find);
              EXPECT_EQ(index, index_find);
              EXPECT_EQ(column_id, column->column_name_id_);
              EXPECT_EQ(group_id,  column->column_group_id_);
              EXPECT_EQ(table_id,  column->table_id_);
              EXPECT_EQ(ObIntType, column->column_value_type_);
              ++index;
            }
          }
        }
        }
Esempio n. 5
0
      TEST_F(TestObSSTableSchema, write_schema_to_disk)
      {
        ObSSTableSchema schema;
        ObSSTableSchemaColumnDef column_def;
        int ret = OB_SUCCESS;
        column_def.reserved_ = 0;

        for ( int table_id = 1000; table_id < 1010; ++table_id )
        {
          column_def.table_id_ = table_id;
          for ( int group_id = 1 ; group_id <= 10; ++group_id )
          {
            column_def.column_group_id_ = static_cast<uint16_t>(group_id);
            for ( int column_id = 0; column_id < group_id; ++column_id )
            {
              column_def.column_name_id_ = column_id;
              column_def.column_value_type_ = ObIntType;
              ret = schema.add_column_def(column_def);
              EXPECT_TRUE(OB_SUCCESS == ret);
            }
          }
        }

        EXPECT_EQ(550, schema.get_column_count());
        FileUtils filesys;
        filesys.open(schema_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        int64_t buf_size = schema.get_serialize_size();
        char * serialize_buf = reinterpret_cast<char *>(malloc(buf_size));
        EXPECT_TRUE(NULL != serialize_buf);
        int64_t pos = 0;
        schema.serialize(serialize_buf, buf_size, pos);
        
        int64_t write_size = filesys.write(serialize_buf, buf_size);
        EXPECT_EQ(write_size, buf_size);
        free(serialize_buf);
        serialize_buf = NULL;
      }