|
|
|
@ -7,6 +7,7 @@ |
|
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE |
|
|
|
|
|
|
|
|
|
#include <atomic> |
|
|
|
|
#include <functional> |
|
|
|
|
#include <string> |
|
|
|
|
#include <utility> |
|
|
|
@ -65,11 +66,19 @@ class WriteCallbackTestWriteCallback2 : public WriteCallback { |
|
|
|
|
class MockWriteCallback : public WriteCallback { |
|
|
|
|
public: |
|
|
|
|
bool should_fail_ = false; |
|
|
|
|
bool was_called_ = false; |
|
|
|
|
bool allow_batching_ = false; |
|
|
|
|
std::atomic<bool> was_called_{false}; |
|
|
|
|
|
|
|
|
|
MockWriteCallback() {} |
|
|
|
|
|
|
|
|
|
MockWriteCallback(const MockWriteCallback& other) { |
|
|
|
|
should_fail_ = other.should_fail_; |
|
|
|
|
allow_batching_ = other.allow_batching_; |
|
|
|
|
was_called_.store(other.was_called_.load()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status Callback(DB* db) override { |
|
|
|
|
was_called_ = true; |
|
|
|
|
was_called_.store(true); |
|
|
|
|
if (should_fail_) { |
|
|
|
|
return Status::Busy(); |
|
|
|
|
} else { |
|
|
|
@ -92,7 +101,7 @@ TEST_F(WriteCallbackTest, WriteWithCallbackTest) { |
|
|
|
|
void Clear() { |
|
|
|
|
kvs_.clear(); |
|
|
|
|
write_batch_.Clear(); |
|
|
|
|
callback_.was_called_ = false; |
|
|
|
|
callback_.was_called_.store(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MockWriteCallback callback_; |
|
|
|
@ -265,7 +274,7 @@ TEST_F(WriteCallbackTest, WriteWithCallbackTest) { |
|
|
|
|
// check for keys
|
|
|
|
|
string value; |
|
|
|
|
for (auto& w : write_group) { |
|
|
|
|
ASSERT_TRUE(w.callback_.was_called_); |
|
|
|
|
ASSERT_TRUE(w.callback_.was_called_.load()); |
|
|
|
|
for (auto& kvp : w.kvs_) { |
|
|
|
|
if (w.callback_.should_fail_) { |
|
|
|
|
ASSERT_TRUE( |
|
|
|
|