|
|
@ -37,7 +37,7 @@ static std::string PrintContents(WriteBatch* b) { |
|
|
|
ColumnFamilyMemTablesDefault cf_mems_default(mem); |
|
|
|
ColumnFamilyMemTablesDefault cf_mems_default(mem); |
|
|
|
Status s = |
|
|
|
Status s = |
|
|
|
WriteBatchInternal::InsertInto(b, &cf_mems_default, nullptr, nullptr); |
|
|
|
WriteBatchInternal::InsertInto(b, &cf_mems_default, nullptr, nullptr); |
|
|
|
int count = 0; |
|
|
|
uint32_t count = 0; |
|
|
|
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; |
|
|
@ -132,8 +132,8 @@ class WriteBatchTest : public testing::Test {}; |
|
|
|
TEST_F(WriteBatchTest, Empty) { |
|
|
|
TEST_F(WriteBatchTest, Empty) { |
|
|
|
WriteBatch batch; |
|
|
|
WriteBatch batch; |
|
|
|
ASSERT_EQ("", PrintContents(&batch)); |
|
|
|
ASSERT_EQ("", PrintContents(&batch)); |
|
|
|
ASSERT_EQ(0, WriteBatchInternal::Count(&batch)); |
|
|
|
ASSERT_EQ(0u, WriteBatchInternal::Count(&batch)); |
|
|
|
ASSERT_EQ(0, batch.Count()); |
|
|
|
ASSERT_EQ(0u, batch.Count()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchTest, Multiple) { |
|
|
|
TEST_F(WriteBatchTest, Multiple) { |
|
|
@ -144,14 +144,14 @@ TEST_F(WriteBatchTest, Multiple) { |
|
|
|
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(4, WriteBatchInternal::Count(&batch)); |
|
|
|
ASSERT_EQ(4u, WriteBatchInternal::Count(&batch)); |
|
|
|
ASSERT_EQ( |
|
|
|
ASSERT_EQ( |
|
|
|
"Put(baz, boo)@103" |
|
|
|
"Put(baz, boo)@103" |
|
|
|
"Delete(box)@101" |
|
|
|
"Delete(box)@101" |
|
|
|
"Put(foo, bar)@100" |
|
|
|
"Put(foo, bar)@100" |
|
|
|
"DeleteRange(bar, foo)@102", |
|
|
|
"DeleteRange(bar, foo)@102", |
|
|
|
PrintContents(&batch)); |
|
|
|
PrintContents(&batch)); |
|
|
|
ASSERT_EQ(4, batch.Count()); |
|
|
|
ASSERT_EQ(4u, batch.Count()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchTest, Corruption) { |
|
|
|
TEST_F(WriteBatchTest, Corruption) { |
|
|
@ -174,19 +174,19 @@ TEST_F(WriteBatchTest, Append) { |
|
|
|
WriteBatchInternal::Append(&b1, &b2); |
|
|
|
WriteBatchInternal::Append(&b1, &b2); |
|
|
|
ASSERT_EQ("", |
|
|
|
ASSERT_EQ("", |
|
|
|
PrintContents(&b1)); |
|
|
|
PrintContents(&b1)); |
|
|
|
ASSERT_EQ(0, b1.Count()); |
|
|
|
ASSERT_EQ(0u, b1.Count()); |
|
|
|
b2.Put("a", "va"); |
|
|
|
b2.Put("a", "va"); |
|
|
|
WriteBatchInternal::Append(&b1, &b2); |
|
|
|
WriteBatchInternal::Append(&b1, &b2); |
|
|
|
ASSERT_EQ("Put(a, va)@200", |
|
|
|
ASSERT_EQ("Put(a, va)@200", |
|
|
|
PrintContents(&b1)); |
|
|
|
PrintContents(&b1)); |
|
|
|
ASSERT_EQ(1, b1.Count()); |
|
|
|
ASSERT_EQ(1u, b1.Count()); |
|
|
|
b2.Clear(); |
|
|
|
b2.Clear(); |
|
|
|
b2.Put("b", "vb"); |
|
|
|
b2.Put("b", "vb"); |
|
|
|
WriteBatchInternal::Append(&b1, &b2); |
|
|
|
WriteBatchInternal::Append(&b1, &b2); |
|
|
|
ASSERT_EQ("Put(a, va)@200" |
|
|
|
ASSERT_EQ("Put(a, va)@200" |
|
|
|
"Put(b, vb)@201", |
|
|
|
"Put(b, vb)@201", |
|
|
|
PrintContents(&b1)); |
|
|
|
PrintContents(&b1)); |
|
|
|
ASSERT_EQ(2, b1.Count()); |
|
|
|
ASSERT_EQ(2u, b1.Count()); |
|
|
|
b2.Delete("foo"); |
|
|
|
b2.Delete("foo"); |
|
|
|
WriteBatchInternal::Append(&b1, &b2); |
|
|
|
WriteBatchInternal::Append(&b1, &b2); |
|
|
|
ASSERT_EQ("Put(a, va)@200" |
|
|
|
ASSERT_EQ("Put(a, va)@200" |
|
|
@ -194,7 +194,7 @@ TEST_F(WriteBatchTest, Append) { |
|
|
|
"Put(b, vb)@201" |
|
|
|
"Put(b, vb)@201" |
|
|
|
"Delete(foo)@203", |
|
|
|
"Delete(foo)@203", |
|
|
|
PrintContents(&b1)); |
|
|
|
PrintContents(&b1)); |
|
|
|
ASSERT_EQ(4, b1.Count()); |
|
|
|
ASSERT_EQ(4u, b1.Count()); |
|
|
|
b2.Clear(); |
|
|
|
b2.Clear(); |
|
|
|
b2.Put("c", "cc"); |
|
|
|
b2.Put("c", "cc"); |
|
|
|
b2.Put("d", "dd"); |
|
|
|
b2.Put("d", "dd"); |
|
|
@ -209,29 +209,29 @@ TEST_F(WriteBatchTest, Append) { |
|
|
|
"Put(d, dd)@205" |
|
|
|
"Put(d, dd)@205" |
|
|
|
"Delete(foo)@203", |
|
|
|
"Delete(foo)@203", |
|
|
|
PrintContents(&b1)); |
|
|
|
PrintContents(&b1)); |
|
|
|
ASSERT_EQ(6, b1.Count()); |
|
|
|
ASSERT_EQ(6u, b1.Count()); |
|
|
|
ASSERT_EQ( |
|
|
|
ASSERT_EQ( |
|
|
|
"Put(c, cc)@0" |
|
|
|
"Put(c, cc)@0" |
|
|
|
"Put(d, dd)@1" |
|
|
|
"Put(d, dd)@1" |
|
|
|
"Put(e, ee)@2", |
|
|
|
"Put(e, ee)@2", |
|
|
|
PrintContents(&b2)); |
|
|
|
PrintContents(&b2)); |
|
|
|
ASSERT_EQ(3, b2.Count()); |
|
|
|
ASSERT_EQ(3u, b2.Count()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchTest, SingleDeletion) { |
|
|
|
TEST_F(WriteBatchTest, SingleDeletion) { |
|
|
|
WriteBatch batch; |
|
|
|
WriteBatch batch; |
|
|
|
WriteBatchInternal::SetSequence(&batch, 100); |
|
|
|
WriteBatchInternal::SetSequence(&batch, 100); |
|
|
|
ASSERT_EQ("", PrintContents(&batch)); |
|
|
|
ASSERT_EQ("", PrintContents(&batch)); |
|
|
|
ASSERT_EQ(0, batch.Count()); |
|
|
|
ASSERT_EQ(0u, batch.Count()); |
|
|
|
batch.Put("a", "va"); |
|
|
|
batch.Put("a", "va"); |
|
|
|
ASSERT_EQ("Put(a, va)@100", PrintContents(&batch)); |
|
|
|
ASSERT_EQ("Put(a, va)@100", PrintContents(&batch)); |
|
|
|
ASSERT_EQ(1, batch.Count()); |
|
|
|
ASSERT_EQ(1u, batch.Count()); |
|
|
|
batch.SingleDelete("a"); |
|
|
|
batch.SingleDelete("a"); |
|
|
|
ASSERT_EQ( |
|
|
|
ASSERT_EQ( |
|
|
|
"SingleDelete(a)@101" |
|
|
|
"SingleDelete(a)@101" |
|
|
|
"Put(a, va)@100", |
|
|
|
"Put(a, va)@100", |
|
|
|
PrintContents(&batch)); |
|
|
|
PrintContents(&batch)); |
|
|
|
ASSERT_EQ(2, batch.Count()); |
|
|
|
ASSERT_EQ(2u, batch.Count()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
namespace { |
|
|
@ -317,7 +317,7 @@ namespace { |
|
|
|
TEST_F(WriteBatchTest, PutNotImplemented) { |
|
|
|
TEST_F(WriteBatchTest, PutNotImplemented) { |
|
|
|
WriteBatch batch; |
|
|
|
WriteBatch batch; |
|
|
|
batch.Put(Slice("k1"), Slice("v1")); |
|
|
|
batch.Put(Slice("k1"), Slice("v1")); |
|
|
|
ASSERT_EQ(1, batch.Count()); |
|
|
|
ASSERT_EQ(1u, batch.Count()); |
|
|
|
ASSERT_EQ("Put(k1, v1)@0", PrintContents(&batch)); |
|
|
|
ASSERT_EQ("Put(k1, v1)@0", PrintContents(&batch)); |
|
|
|
|
|
|
|
|
|
|
|
WriteBatch::Handler handler; |
|
|
|
WriteBatch::Handler handler; |
|
|
@ -327,7 +327,7 @@ TEST_F(WriteBatchTest, PutNotImplemented) { |
|
|
|
TEST_F(WriteBatchTest, DeleteNotImplemented) { |
|
|
|
TEST_F(WriteBatchTest, DeleteNotImplemented) { |
|
|
|
WriteBatch batch; |
|
|
|
WriteBatch batch; |
|
|
|
batch.Delete(Slice("k2")); |
|
|
|
batch.Delete(Slice("k2")); |
|
|
|
ASSERT_EQ(1, batch.Count()); |
|
|
|
ASSERT_EQ(1u, batch.Count()); |
|
|
|
ASSERT_EQ("Delete(k2)@0", PrintContents(&batch)); |
|
|
|
ASSERT_EQ("Delete(k2)@0", PrintContents(&batch)); |
|
|
|
|
|
|
|
|
|
|
|
WriteBatch::Handler handler; |
|
|
|
WriteBatch::Handler handler; |
|
|
@ -337,7 +337,7 @@ TEST_F(WriteBatchTest, DeleteNotImplemented) { |
|
|
|
TEST_F(WriteBatchTest, SingleDeleteNotImplemented) { |
|
|
|
TEST_F(WriteBatchTest, SingleDeleteNotImplemented) { |
|
|
|
WriteBatch batch; |
|
|
|
WriteBatch batch; |
|
|
|
batch.SingleDelete(Slice("k2")); |
|
|
|
batch.SingleDelete(Slice("k2")); |
|
|
|
ASSERT_EQ(1, batch.Count()); |
|
|
|
ASSERT_EQ(1u, batch.Count()); |
|
|
|
ASSERT_EQ("SingleDelete(k2)@0", PrintContents(&batch)); |
|
|
|
ASSERT_EQ("SingleDelete(k2)@0", PrintContents(&batch)); |
|
|
|
|
|
|
|
|
|
|
|
WriteBatch::Handler handler; |
|
|
|
WriteBatch::Handler handler; |
|
|
@ -347,7 +347,7 @@ TEST_F(WriteBatchTest, SingleDeleteNotImplemented) { |
|
|
|
TEST_F(WriteBatchTest, MergeNotImplemented) { |
|
|
|
TEST_F(WriteBatchTest, MergeNotImplemented) { |
|
|
|
WriteBatch batch; |
|
|
|
WriteBatch batch; |
|
|
|
batch.Merge(Slice("foo"), Slice("bar")); |
|
|
|
batch.Merge(Slice("foo"), Slice("bar")); |
|
|
|
ASSERT_EQ(1, batch.Count()); |
|
|
|
ASSERT_EQ(1u, batch.Count()); |
|
|
|
ASSERT_EQ("Merge(foo, bar)@0", PrintContents(&batch)); |
|
|
|
ASSERT_EQ("Merge(foo, bar)@0", PrintContents(&batch)); |
|
|
|
|
|
|
|
|
|
|
|
WriteBatch::Handler handler; |
|
|
|
WriteBatch::Handler handler; |
|
|
@ -364,7 +364,7 @@ TEST_F(WriteBatchTest, Blob) { |
|
|
|
batch.SingleDelete(Slice("k3")); |
|
|
|
batch.SingleDelete(Slice("k3")); |
|
|
|
batch.PutLogData(Slice("blob2")); |
|
|
|
batch.PutLogData(Slice("blob2")); |
|
|
|
batch.Merge(Slice("foo"), Slice("bar")); |
|
|
|
batch.Merge(Slice("foo"), Slice("bar")); |
|
|
|
ASSERT_EQ(6, batch.Count()); |
|
|
|
ASSERT_EQ(6u, batch.Count()); |
|
|
|
ASSERT_EQ( |
|
|
|
ASSERT_EQ( |
|
|
|
"Merge(foo, bar)@5" |
|
|
|
"Merge(foo, bar)@5" |
|
|
|
"Put(k1, v1)@0" |
|
|
|
"Put(k1, v1)@0" |
|
|
@ -399,7 +399,7 @@ TEST_F(WriteBatchTest, PrepareCommit) { |
|
|
|
ASSERT_EQ(s, Status::NotFound()); |
|
|
|
ASSERT_EQ(s, Status::NotFound()); |
|
|
|
WriteBatchInternal::MarkCommit(&batch, Slice("xid1")); |
|
|
|
WriteBatchInternal::MarkCommit(&batch, Slice("xid1")); |
|
|
|
WriteBatchInternal::MarkRollback(&batch, Slice("xid1")); |
|
|
|
WriteBatchInternal::MarkRollback(&batch, Slice("xid1")); |
|
|
|
ASSERT_EQ(2, batch.Count()); |
|
|
|
ASSERT_EQ(2u, batch.Count()); |
|
|
|
|
|
|
|
|
|
|
|
TestHandler handler; |
|
|
|
TestHandler handler; |
|
|
|
batch.Iterate(&handler); |
|
|
|
batch.Iterate(&handler); |
|
|
@ -489,7 +489,7 @@ TEST_F(WriteBatchTest, DISABLED_LargeKeyValue) { |
|
|
|
batch.Put(raw, raw); |
|
|
|
batch.Put(raw, raw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(2, batch.Count()); |
|
|
|
ASSERT_EQ(2u, batch.Count()); |
|
|
|
|
|
|
|
|
|
|
|
struct NoopHandler : public WriteBatch::Handler { |
|
|
|
struct NoopHandler : public WriteBatch::Handler { |
|
|
|
int num_seen = 0; |
|
|
|
int num_seen = 0; |
|
|
@ -600,7 +600,7 @@ TEST_F(WriteBatchTest, PutGatherSlices) { |
|
|
|
"Put(foo, bar)@100" |
|
|
|
"Put(foo, bar)@100" |
|
|
|
"Put(keypart2part3, value)@102", |
|
|
|
"Put(keypart2part3, value)@102", |
|
|
|
PrintContents(&batch)); |
|
|
|
PrintContents(&batch)); |
|
|
|
ASSERT_EQ(3, batch.Count()); |
|
|
|
ASSERT_EQ(3u, batch.Count()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|