diff options
author | Sanjay Ghemawat <sanjay@google.com> | 2012-03-08 16:23:21 -0800 |
---|---|---|
committer | Sanjay Ghemawat <sanjay@google.com> | 2012-03-08 16:23:21 -0800 |
commit | d79762e27369365a7ffe1f2e3a5c64b0632079e1 (patch) | |
tree | beacf85da681b45003f9149562c4c6b85e893eba /db/write_batch_test.cc | |
parent | 015d26f8be6e27d96c536eb9f1ef7275898e3603 (diff) | |
download | leveldb-d79762e27369365a7ffe1f2e3a5c64b0632079e1.tar.gz |
added group commit; drastically speeds up mult-threaded synchronous write workloads
Diffstat (limited to 'db/write_batch_test.cc')
-rw-r--r-- | db/write_batch_test.cc | 31 |
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) { |