aboutsummaryrefslogtreecommitdiff
path: root/db/write_batch_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'db/write_batch_test.cc')
-rw-r--r--db/write_batch_test.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/db/write_batch_test.cc b/db/write_batch_test.cc
index 1ee6d7b..9064e3d 100644
--- a/db/write_batch_test.cc
+++ b/db/write_batch_test.cc
@@ -18,6 +18,7 @@ static std::string PrintContents(WriteBatch* b) {
mem->Ref();
std::string state;
Status s = WriteBatchInternal::InsertInto(b, mem);
+ int count = 0;
Iterator* iter = mem->NewIterator();
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
ParsedInternalKey ikey;
@@ -29,11 +30,13 @@ static std::string PrintContents(WriteBatch* b) {
state.append(", ");
state.append(iter->value().ToString());
state.append(")");
+ count++;
break;
case kTypeDeletion:
state.append("Delete(");
state.append(ikey.user_key.ToString());
state.append(")");
+ count++;
break;
}
state.append("@");
@@ -42,6 +45,8 @@ static std::string PrintContents(WriteBatch* b) {
delete iter;
if (!s.ok()) {
state.append("ParseError()");
+ } else if (count != WriteBatchInternal::Count(b)) {
+ state.append("CountMismatch()");
}
mem->Unref();
return state;
@@ -82,6 +87,32 @@ TEST(WriteBatchTest, Corruption) {
PrintContents(&batch));
}
+TEST(WriteBatchTest, Append) {
+ WriteBatch b1, b2;
+ WriteBatchInternal::SetSequence(&b1, 200);
+ WriteBatchInternal::SetSequence(&b2, 300);
+ WriteBatchInternal::Append(&b1, &b2);
+ ASSERT_EQ("",
+ PrintContents(&b1));
+ b2.Put("a", "va");
+ WriteBatchInternal::Append(&b1, &b2);
+ ASSERT_EQ("Put(a, va)@200",
+ PrintContents(&b1));
+ b2.Clear();
+ b2.Put("b", "vb");
+ WriteBatchInternal::Append(&b1, &b2);
+ ASSERT_EQ("Put(a, va)@200"
+ "Put(b, vb)@201",
+ PrintContents(&b1));
+ b2.Delete("foo");
+ WriteBatchInternal::Append(&b1, &b2);
+ ASSERT_EQ("Put(a, va)@200"
+ "Put(b, vb)@202"
+ "Put(b, vb)@201"
+ "Delete(foo)@203",
+ PrintContents(&b1));
+}
+
} // namespace leveldb
int main(int argc, char** argv) {