@ -4538,6 +4538,37 @@ TEST_F(DBTest2, TraceAndManualReplay) {
single_iter = db_ - > NewIterator ( ro ) ;
single_iter = db_ - > NewIterator ( ro ) ;
single_iter - > Seek ( " f " ) ;
single_iter - > Seek ( " f " ) ;
single_iter - > SeekForPrev ( " g " ) ;
single_iter - > SeekForPrev ( " g " ) ;
ASSERT_OK ( single_iter - > status ( ) ) ;
delete single_iter ;
// Write some sequenced keys for testing lower/upper bounds of iterator.
batch . Clear ( ) ;
ASSERT_OK ( batch . Put ( " iter-0 " , " iter-0 " ) ) ;
ASSERT_OK ( batch . Put ( " iter-1 " , " iter-1 " ) ) ;
ASSERT_OK ( batch . Put ( " iter-2 " , " iter-2 " ) ) ;
ASSERT_OK ( batch . Put ( " iter-3 " , " iter-3 " ) ) ;
ASSERT_OK ( batch . Put ( " iter-4 " , " iter-4 " ) ) ;
ASSERT_OK ( db_ - > Write ( wo , & batch ) ) ;
ReadOptions bounded_ro = ro ;
Slice lower_bound ( " iter-1 " ) ;
Slice upper_bound ( " iter-3 " ) ;
bounded_ro . iterate_lower_bound = & lower_bound ;
bounded_ro . iterate_upper_bound = & upper_bound ;
single_iter = db_ - > NewIterator ( bounded_ro ) ;
single_iter - > Seek ( " iter-0 " ) ;
ASSERT_EQ ( single_iter - > key ( ) . ToString ( ) , " iter-1 " ) ;
single_iter - > Seek ( " iter-2 " ) ;
ASSERT_EQ ( single_iter - > key ( ) . ToString ( ) , " iter-2 " ) ;
single_iter - > Seek ( " iter-4 " ) ;
ASSERT_FALSE ( single_iter - > Valid ( ) ) ;
single_iter - > SeekForPrev ( " iter-0 " ) ;
ASSERT_FALSE ( single_iter - > Valid ( ) ) ;
single_iter - > SeekForPrev ( " iter-2 " ) ;
ASSERT_EQ ( single_iter - > key ( ) . ToString ( ) , " iter-2 " ) ;
single_iter - > SeekForPrev ( " iter-4 " ) ;
ASSERT_EQ ( single_iter - > key ( ) . ToString ( ) , " iter-2 " ) ;
ASSERT_OK ( single_iter - > status ( ) ) ;
delete single_iter ;
delete single_iter ;
ASSERT_EQ ( " 1 " , Get ( 0 , " a " ) ) ;
ASSERT_EQ ( " 1 " , Get ( 0 , " a " ) ) ;
@ -4548,6 +4579,9 @@ TEST_F(DBTest2, TraceAndManualReplay) {
ASSERT_EQ ( " NOT_FOUND " , Get ( 1 , " leveldb " ) ) ;
ASSERT_EQ ( " NOT_FOUND " , Get ( 1 , " leveldb " ) ) ;
// Same as TraceAndReplay, Write x 8, Get x 3, Seek x 2.
// Same as TraceAndReplay, Write x 8, Get x 3, Seek x 2.
// Plus 1 WriteBatch for iterator with lower/upper bounds, and 6
// Seek(ForPrev)s.
// Total Write x 9, Get x 3, Seek x 8
ASSERT_OK ( db_ - > EndTrace ( ) ) ;
ASSERT_OK ( db_ - > EndTrace ( ) ) ;
// These should not get into the trace file as it is after EndTrace.
// These should not get into the trace file as it is after EndTrace.
ASSERT_OK ( Put ( " hello " , " world " ) ) ;
ASSERT_OK ( Put ( " hello " , " world " ) ) ;
@ -4610,6 +4644,20 @@ TEST_F(DBTest2, TraceAndManualReplay) {
continue ;
continue ;
}
}
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
if ( record - > GetTraceType ( ) = = kTraceIteratorSeek | |
record - > GetTraceType ( ) = = kTraceIteratorSeekForPrev ) {
IteratorSeekQueryTraceRecord * iter_r =
dynamic_cast < IteratorSeekQueryTraceRecord * > ( record . get ( ) ) ;
// Check if lower/upper bounds are correctly saved and decoded.
lower_bound = iter_r - > GetLowerBound ( ) ;
if ( ! lower_bound . empty ( ) ) {
ASSERT_EQ ( lower_bound . ToString ( ) , " iter-1 " ) ;
}
upper_bound = iter_r - > GetUpperBound ( ) ;
if ( ! upper_bound . empty ( ) ) {
ASSERT_EQ ( upper_bound . ToString ( ) , " iter-3 " ) ;
}
}
ASSERT_OK ( replayer - > Execute ( record , & result ) ) ;
ASSERT_OK ( replayer - > Execute ( record , & result ) ) ;
if ( result ! = nullptr ) {
if ( result ! = nullptr ) {
ASSERT_OK ( result - > Accept ( & res_handler ) ) ;
ASSERT_OK ( result - > Accept ( & res_handler ) ) ;
@ -4622,9 +4670,9 @@ TEST_F(DBTest2, TraceAndManualReplay) {
ASSERT_TRUE ( s . IsIncomplete ( ) ) ;
ASSERT_TRUE ( s . IsIncomplete ( ) ) ;
ASSERT_TRUE ( replayer - > Next ( nullptr ) . IsIncomplete ( ) ) ;
ASSERT_TRUE ( replayer - > Next ( nullptr ) . IsIncomplete ( ) ) ;
ASSERT_GT ( res_handler . GetAvgLatency ( ) , 0.0 ) ;
ASSERT_GT ( res_handler . GetAvgLatency ( ) , 0.0 ) ;
ASSERT_EQ ( res_handler . GetNumWrites ( ) , 8 ) ;
ASSERT_EQ ( res_handler . GetNumWrites ( ) , 9 ) ;
ASSERT_EQ ( res_handler . GetNumGets ( ) , 3 ) ;
ASSERT_EQ ( res_handler . GetNumGets ( ) , 3 ) ;
ASSERT_EQ ( res_handler . GetNumIterSeeks ( ) , 2 ) ;
ASSERT_EQ ( res_handler . GetNumIterSeeks ( ) , 8 ) ;
ASSERT_EQ ( res_handler . GetNumMultiGets ( ) , 0 ) ;
ASSERT_EQ ( res_handler . GetNumMultiGets ( ) , 0 ) ;
res_handler . Reset ( ) ;
res_handler . Reset ( ) ;
}
}