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