@ -42,6 +42,7 @@ static std::string PrintContents(WriteBatch* b) {
int put_count = 0 ;
int put_count = 0 ;
int delete_count = 0 ;
int delete_count = 0 ;
int single_delete_count = 0 ;
int single_delete_count = 0 ;
int delete_range_count = 0 ;
int merge_count = 0 ;
int merge_count = 0 ;
Arena arena ;
Arena arena ;
ScopedArenaIterator iter ( mem - > NewIterator ( ReadOptions ( ) , & arena ) ) ;
ScopedArenaIterator iter ( mem - > NewIterator ( ReadOptions ( ) , & arena ) ) ;
@ -73,6 +74,15 @@ static std::string PrintContents(WriteBatch* b) {
count + + ;
count + + ;
single_delete_count + + ;
single_delete_count + + ;
break ;
break ;
case kTypeRangeDeletion :
state . append ( " DeleteRange( " ) ;
state . append ( ikey . user_key . ToString ( ) ) ;
state . append ( " , " ) ;
state . append ( iter - > value ( ) . ToString ( ) ) ;
state . append ( " ) " ) ;
count + + ;
delete_range_count + + ;
break ;
case kTypeMerge :
case kTypeMerge :
state . append ( " Merge( " ) ;
state . append ( " Merge( " ) ;
state . append ( ikey . user_key . ToString ( ) ) ;
state . append ( ikey . user_key . ToString ( ) ) ;
@ -92,6 +102,7 @@ static std::string PrintContents(WriteBatch* b) {
EXPECT_EQ ( b - > HasPut ( ) , put_count > 0 ) ;
EXPECT_EQ ( b - > HasPut ( ) , put_count > 0 ) ;
EXPECT_EQ ( b - > HasDelete ( ) , delete_count > 0 ) ;
EXPECT_EQ ( b - > HasDelete ( ) , delete_count > 0 ) ;
EXPECT_EQ ( b - > HasSingleDelete ( ) , single_delete_count > 0 ) ;
EXPECT_EQ ( b - > HasSingleDelete ( ) , single_delete_count > 0 ) ;
EXPECT_EQ ( b - > HasDeleteRange ( ) , delete_range_count > 0 ) ;
EXPECT_EQ ( b - > HasMerge ( ) , merge_count > 0 ) ;
EXPECT_EQ ( b - > HasMerge ( ) , merge_count > 0 ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
state . append ( s . ToString ( ) ) ;
state . append ( s . ToString ( ) ) ;
@ -115,15 +126,18 @@ TEST_F(WriteBatchTest, Multiple) {
WriteBatch batch ;
WriteBatch batch ;
batch . Put ( Slice ( " foo " ) , Slice ( " bar " ) ) ;
batch . Put ( Slice ( " foo " ) , Slice ( " bar " ) ) ;
batch . Delete ( Slice ( " box " ) ) ;
batch . Delete ( Slice ( " box " ) ) ;
batch . DeleteRange ( Slice ( " bar " ) , Slice ( " foo " ) ) ;
batch . Put ( Slice ( " baz " ) , Slice ( " boo " ) ) ;
batch . Put ( Slice ( " baz " ) , Slice ( " boo " ) ) ;
WriteBatchInternal : : SetSequence ( & batch , 100 ) ;
WriteBatchInternal : : SetSequence ( & batch , 100 ) ;
ASSERT_EQ ( 100U , WriteBatchInternal : : Sequence ( & batch ) ) ;
ASSERT_EQ ( 100U , WriteBatchInternal : : Sequence ( & batch ) ) ;
ASSERT_EQ ( 3 , WriteBatchInternal : : Count ( & batch ) ) ;
ASSERT_EQ ( 4 , WriteBatchInternal : : Count ( & batch ) ) ;
ASSERT_EQ ( " Put(baz, boo)@102 "
ASSERT_EQ (
" Delete(box)@101 "
" DeleteRange(bar, foo)@102 "
" Put(foo, bar)@100 " ,
" Put(baz, boo)@103 "
PrintContents ( & batch ) ) ;
" Delete(box)@101 "
ASSERT_EQ ( 3 , batch . Count ( ) ) ;
" Put(foo, bar)@100 " ,
PrintContents ( & batch ) ) ;
ASSERT_EQ ( 4 , batch . Count ( ) ) ;
}
}
TEST_F ( WriteBatchTest , Corruption ) {
TEST_F ( WriteBatchTest , Corruption ) {
@ -218,6 +232,18 @@ namespace {
}
}
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
virtual Status DeleteRangeCF ( uint32_t column_family_id ,
const Slice & begin_key ,
const Slice & end_key ) override {
if ( column_family_id = = 0 ) {
seen + = " DeleteRange( " + begin_key . ToString ( ) + " , " +
end_key . ToString ( ) + " ) " ;
} else {
seen + = " DeleteRangeCF( " + ToString ( column_family_id ) + " , " +
begin_key . ToString ( ) + " , " + end_key . ToString ( ) + " ) " ;
}
return Status : : OK ( ) ;
}
virtual Status MergeCF ( uint32_t column_family_id , const Slice & key ,
virtual Status MergeCF ( uint32_t column_family_id , const Slice & key ,
const Slice & value ) override {
const Slice & value ) override {
if ( column_family_id = = 0 ) {
if ( column_family_id = = 0 ) {
@ -563,6 +589,7 @@ TEST_F(WriteBatchTest, ColumnFamiliesBatchTest) {
batch . Put ( & eight , Slice ( " eightfoo " ) , Slice ( " bar8 " ) ) ;
batch . Put ( & eight , Slice ( " eightfoo " ) , Slice ( " bar8 " ) ) ;
batch . Delete ( & eight , Slice ( " eightfoo " ) ) ;
batch . Delete ( & eight , Slice ( " eightfoo " ) ) ;
batch . SingleDelete ( & two , Slice ( " twofoo " ) ) ;
batch . SingleDelete ( & two , Slice ( " twofoo " ) ) ;
batch . DeleteRange ( & two , Slice ( " 3foo " ) , Slice ( " 4foo " ) ) ;
batch . Merge ( & three , Slice ( " threethree " ) , Slice ( " 3three " ) ) ;
batch . Merge ( & three , Slice ( " threethree " ) , Slice ( " 3three " ) ) ;
batch . Put ( & zero , Slice ( " foo " ) , Slice ( " bar " ) ) ;
batch . Put ( & zero , Slice ( " foo " ) , Slice ( " bar " ) ) ;
batch . Merge ( Slice ( " omom " ) , Slice ( " nom " ) ) ;
batch . Merge ( Slice ( " omom " ) , Slice ( " nom " ) ) ;
@ -575,6 +602,7 @@ TEST_F(WriteBatchTest, ColumnFamiliesBatchTest) {
" PutCF(8, eightfoo, bar8) "
" PutCF(8, eightfoo, bar8) "
" DeleteCF(8, eightfoo) "
" DeleteCF(8, eightfoo) "
" SingleDeleteCF(2, twofoo) "
" SingleDeleteCF(2, twofoo) "
" DeleteRangeCF(2, 3foo, 4foo) "
" MergeCF(3, threethree, 3three) "
" MergeCF(3, threethree, 3three) "
" Put(foo, bar) "
" Put(foo, bar) "
" Merge(omom, nom) " ,
" Merge(omom, nom) " ,
@ -590,6 +618,7 @@ TEST_F(WriteBatchTest, ColumnFamiliesBatchWithIndexTest) {
batch . Put ( & eight , Slice ( " eightfoo " ) , Slice ( " bar8 " ) ) ;
batch . Put ( & eight , Slice ( " eightfoo " ) , Slice ( " bar8 " ) ) ;
batch . Delete ( & eight , Slice ( " eightfoo " ) ) ;
batch . Delete ( & eight , Slice ( " eightfoo " ) ) ;
batch . SingleDelete ( & two , Slice ( " twofoo " ) ) ;
batch . SingleDelete ( & two , Slice ( " twofoo " ) ) ;
batch . DeleteRange ( & two , Slice ( " twofoo " ) , Slice ( " threefoo " ) ) ;
batch . Merge ( & three , Slice ( " threethree " ) , Slice ( " 3three " ) ) ;
batch . Merge ( & three , Slice ( " threethree " ) , Slice ( " 3three " ) ) ;
batch . Put ( & zero , Slice ( " foo " ) , Slice ( " bar " ) ) ;
batch . Put ( & zero , Slice ( " foo " ) , Slice ( " bar " ) ) ;
batch . Merge ( Slice ( " omom " ) , Slice ( " nom " ) ) ;
batch . Merge ( Slice ( " omom " ) , Slice ( " nom " ) ) ;
@ -628,6 +657,13 @@ TEST_F(WriteBatchTest, ColumnFamiliesBatchWithIndexTest) {
ASSERT_EQ ( WriteType : : kSingleDeleteRecord , iter - > Entry ( ) . type ) ;
ASSERT_EQ ( WriteType : : kSingleDeleteRecord , iter - > Entry ( ) . type ) ;
ASSERT_EQ ( " twofoo " , iter - > Entry ( ) . key . ToString ( ) ) ;
ASSERT_EQ ( " twofoo " , iter - > Entry ( ) . key . ToString ( ) ) ;
iter - > Next ( ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( iter - > Valid ( ) ) ;
ASSERT_EQ ( WriteType : : kDeleteRangeRecord , iter - > Entry ( ) . type ) ;
ASSERT_EQ ( " twofoo " , iter - > Entry ( ) . key . ToString ( ) ) ;
ASSERT_EQ ( " threefoo " , iter - > Entry ( ) . value . ToString ( ) ) ;
iter - > Next ( ) ;
iter - > Next ( ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_OK ( iter - > status ( ) ) ;
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
ASSERT_TRUE ( ! iter - > Valid ( ) ) ;
@ -678,6 +714,7 @@ TEST_F(WriteBatchTest, ColumnFamiliesBatchWithIndexTest) {
" PutCF(8, eightfoo, bar8) "
" PutCF(8, eightfoo, bar8) "
" DeleteCF(8, eightfoo) "
" DeleteCF(8, eightfoo) "
" SingleDeleteCF(2, twofoo) "
" SingleDeleteCF(2, twofoo) "
" DeleteRangeCF(2, twofoo, threefoo) "
" MergeCF(3, threethree, 3three) "
" MergeCF(3, threethree, 3three) "
" Put(foo, bar) "
" Put(foo, bar) "
" Merge(omom, nom) " ,
" Merge(omom, nom) " ,