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_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(); }
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; }