@ -163,8 +163,8 @@ class LogTest : public ::testing::TestWithParam<int> {
source_holder_ ( test : : GetSequentialFileReader (
new StringSource ( reader_contents_ ) , " " /* file name */ ) ) ,
writer_ ( std : : move ( dest_holder_ ) , 123 , GetParam ( ) ) ,
reader_ ( nullptr , std : : move ( source_holder_ ) , & report_ , true /*checksum*/ ,
0 /*initial_offset */, 123 ) {
reader_ ( nullptr , std : : move ( source_holder_ ) , & report_ ,
true /* checksum */, 123 /* log_number */ ) {
int header_size = GetParam ( ) ? kRecyclableHeaderSize : kHeaderSize ;
initial_offset_last_record_offsets_ [ 0 ] = 0 ;
initial_offset_last_record_offsets_ [ 1 ] = header_size + 10000 ;
@ -266,36 +266,6 @@ class LogTest : public ::testing::TestWithParam<int> {
}
}
void CheckOffsetPastEndReturnsNoRecords ( uint64_t offset_past_end ) {
WriteInitialOffsetLog ( ) ;
unique_ptr < SequentialFileReader > file_reader ( test : : GetSequentialFileReader (
new StringSource ( reader_contents_ ) , " " /* fname */ ) ) ;
unique_ptr < Reader > offset_reader (
new Reader ( nullptr , std : : move ( file_reader ) , & report_ ,
true /*checksum*/ , WrittenBytes ( ) + offset_past_end , 123 ) ) ;
Slice record ;
std : : string scratch ;
ASSERT_TRUE ( ! offset_reader - > ReadRecord ( & record , & scratch ) ) ;
}
void CheckInitialOffsetRecord ( uint64_t initial_offset ,
int expected_record_offset ) {
WriteInitialOffsetLog ( ) ;
unique_ptr < SequentialFileReader > file_reader ( test : : GetSequentialFileReader (
new StringSource ( reader_contents_ ) , " " /* fname */ ) ) ;
unique_ptr < Reader > offset_reader (
new Reader ( nullptr , std : : move ( file_reader ) , & report_ ,
true /*checksum*/ , initial_offset , 123 ) ) ;
Slice record ;
std : : string scratch ;
ASSERT_TRUE ( offset_reader - > ReadRecord ( & record , & scratch ) ) ;
ASSERT_EQ ( initial_offset_record_sizes_ [ expected_record_offset ] ,
record . size ( ) ) ;
ASSERT_EQ ( initial_offset_last_record_offsets_ [ expected_record_offset ] ,
offset_reader - > LastRecordOffset ( ) ) ;
ASSERT_EQ ( ( char ) ( ' a ' + expected_record_offset ) , record . data ( ) [ 0 ] ) ;
}
} ;
size_t LogTest : : initial_offset_record_sizes_ [ ] =
@ -590,55 +560,6 @@ TEST_P(LogTest, ErrorJoinsRecords) {
}
}
TEST_P ( LogTest , ReadStart ) { CheckInitialOffsetRecord ( 0 , 0 ) ; }
TEST_P ( LogTest , ReadSecondOneOff ) { CheckInitialOffsetRecord ( 1 , 1 ) ; }
TEST_P ( LogTest , ReadSecondTenThousand ) { CheckInitialOffsetRecord ( 10000 , 1 ) ; }
TEST_P ( LogTest , ReadSecondStart ) {
int header_size = GetParam ( ) ? kRecyclableHeaderSize : kHeaderSize ;
CheckInitialOffsetRecord ( 10000 + header_size , 1 ) ;
}
TEST_P ( LogTest , ReadThirdOneOff ) {
int header_size = GetParam ( ) ? kRecyclableHeaderSize : kHeaderSize ;
CheckInitialOffsetRecord ( 10000 + header_size + 1 , 2 ) ;
}
TEST_P ( LogTest , ReadThirdStart ) {
int header_size = GetParam ( ) ? kRecyclableHeaderSize : kHeaderSize ;
CheckInitialOffsetRecord ( 20000 + 2 * header_size , 2 ) ;
}
TEST_P ( LogTest , ReadFourthOneOff ) {
int header_size = GetParam ( ) ? kRecyclableHeaderSize : kHeaderSize ;
CheckInitialOffsetRecord ( 20000 + 2 * header_size + 1 , 3 ) ;
}
TEST_P ( LogTest , ReadFourthFirstBlockTrailer ) {
CheckInitialOffsetRecord ( log : : kBlockSize - 4 , 3 ) ;
}
TEST_P ( LogTest , ReadFourthMiddleBlock ) {
CheckInitialOffsetRecord ( log : : kBlockSize + 1 , 3 ) ;
}
TEST_P ( LogTest , ReadFourthLastBlock ) {
CheckInitialOffsetRecord ( 2 * log : : kBlockSize + 1 , 3 ) ;
}
TEST_P ( LogTest , ReadFourthStart ) {
int header_size = GetParam ( ) ? kRecyclableHeaderSize : kHeaderSize ;
CheckInitialOffsetRecord (
2 * ( header_size + 1000 ) + ( 2 * log : : kBlockSize - 1000 ) + 3 * header_size ,
3 ) ;
}
TEST_P ( LogTest , ReadEnd ) { CheckOffsetPastEndReturnsNoRecords ( 0 ) ; }
TEST_P ( LogTest , ReadPastEnd ) { CheckOffsetPastEndReturnsNoRecords ( 5 ) ; }
TEST_P ( LogTest , ClearEofSingleBlock ) {
Write ( " foo " ) ;
Write ( " bar " ) ;