@ -120,7 +120,12 @@ TEST(WriteBatchWithIndexTest, TestValueAsSecondaryIndex) {
// Iterator all keys
{
std : : unique_ptr < WBWIIterator > iter ( batch . NewIterator ( & data ) ) ;
for ( int seek_to_first : { 0 , 1 } ) {
if ( seek_to_first ) {
iter - > SeekToFirst ( ) ;
} else {
iter - > Seek ( " " ) ;
}
for ( auto pair : data_map ) {
for ( auto v : pair . second ) {
ASSERT_OK ( iter - > status ( ) ) ;
@ -136,11 +141,32 @@ TEST(WriteBatchWithIndexTest, TestValueAsSecondaryIndex) {
}
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
}
iter - > SeekToLast ( ) ;
for ( auto pair = data_map . rbegin ( ) ; pair ! = data_map . rend ( ) ; + + pair ) {
for ( auto v = pair - > second . rbegin ( ) ; v ! = pair - > second . rend ( ) ; v + + ) {
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
auto & write_entry = iter - > Entry ( ) ;
ASSERT_EQ ( pair - > first , write_entry . key . ToString ( ) ) ;
ASSERT_EQ ( ( * v ) - > type , write_entry . type ) ;
if ( write_entry . type ! = kDeleteRecord ) {
ASSERT_EQ ( ( * v ) - > value , write_entry . value . ToString ( ) ) ;
}
iter - > Prev ( ) ;
}
}
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
}
// Iterator all indexes
{
std : : unique_ptr < WBWIIterator > iter ( batch . NewIterator ( & index ) ) ;
for ( int seek_to_first : { 0 , 1 } ) {
if ( seek_to_first ) {
iter - > SeekToFirst ( ) ;
} else {
iter - > Seek ( " " ) ;
}
for ( auto pair : index_map ) {
for ( auto v : pair . second ) {
ASSERT_OK ( iter - > status ( ) ) ;
@ -157,6 +183,23 @@ TEST(WriteBatchWithIndexTest, TestValueAsSecondaryIndex) {
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
}
iter - > SeekToLast ( ) ;
for ( auto pair = index_map . rbegin ( ) ; pair ! = index_map . rend ( ) ; + + pair ) {
for ( auto v = pair - > second . rbegin ( ) ; v ! = pair - > second . rend ( ) ; v + + ) {
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
auto & write_entry = iter - > Entry ( ) ;
ASSERT_EQ ( pair - > first , write_entry . key . ToString ( ) ) ;
if ( ( * v ) - > type ! = kDeleteRecord ) {
ASSERT_EQ ( ( * v ) - > key , write_entry . value . ToString ( ) ) ;
ASSERT_EQ ( ( * v ) - > value , write_entry . key . ToString ( ) ) ;
}
iter - > Prev ( ) ;
}
}
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
}
// Seek to every key
{
std : : unique_ptr < WBWIIterator > iter ( batch . NewIterator ( & data ) ) ;
@ -357,7 +400,21 @@ TEST(WriteBatchWithIndexTest, TestOverwriteKey) {
{
std : : unique_ptr < WBWIIterator > iter ( batch . NewIterator ( & cf2 ) ) ;
iter - > Seek ( " " ) ;
iter - > SeekToLast ( ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
ASSERT_EQ ( " eee " , iter - > Entry ( ) . key . ToString ( ) ) ;
ASSERT_EQ ( " eee " , iter - > Entry ( ) . value . ToString ( ) ) ;
iter - > Prev ( ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
ASSERT_EQ ( " aaa " , iter - > Entry ( ) . key . ToString ( ) ) ;
ASSERT_EQ ( " aaa " , iter - > Entry ( ) . value . ToString ( ) ) ;
iter - > Prev ( ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
iter - > SeekToFirst ( ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
ASSERT_EQ ( " aaa " , iter - > Entry ( ) . key . ToString ( ) ) ;
@ -391,6 +448,19 @@ TEST(WriteBatchWithIndexTest, TestOverwriteKey) {
iter - > Next ( ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
iter - > SeekToLast ( ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
ASSERT_EQ ( " a11 " , iter - > Entry ( ) . key . ToString ( ) ) ;
ASSERT_EQ ( " a11 " , iter - > Entry ( ) . value . ToString ( ) ) ;
iter - > Prev ( ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
ASSERT_EQ ( " a33 " , iter - > Entry ( ) . key . ToString ( ) ) ;
ASSERT_TRUE ( iter - > Entry ( ) . type = = WriteType : : kDeleteRecord ) ;
iter - > Prev ( ) ;
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
}
}