Commit d01be9d9 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Add tests for qclient callbacks

parent 95afc854
Pipeline #302694 passed with stages
in 22 minutes and 33 seconds
Subproject commit f931e87570d1add6e2a8f4f6a3c05ace86a42e8f
Subproject commit ef6aea48fa089ba4032df368a37931952b7d4461
......@@ -36,6 +36,7 @@ public:
using container = std::vector<std::string>;
using iterator = container::iterator;
using const_iterator = container::const_iterator;
using size_type = container::size_type;
RedisRequest(std::initializer_list<std::string> list) {
for(auto it = list.begin(); it != list.end(); it++) {
......
......@@ -38,6 +38,7 @@ add_executable(quarkdb-tests
link.cc
main.cc
poller.cc
qclient.cc
raft-journal.cc
raft-lease.cc
raft-parser.cc
......@@ -48,7 +49,6 @@ add_executable(quarkdb-tests
redis-parser.cc
state-machine.cc
${COMMON_TEST_SOURCES}
tunnel.cc
utils.cc
)
......
......@@ -501,6 +501,39 @@ TEST_F(Raft_e2e, test_many_redis_commands) {
ASSERT_REPLY(futures[i++], "i6");
ASSERT_REPLY(futures[i++], "OK");
ASSERT_REPLY(futures[i++], "ERR Invalid argument: WRONGTYPE Operation against a key holding the wrong kind of value");
// Now test qclient callbacks, ensure things stay reasonable when we mix them
// with futures.
TrivialQCallback c1;
tunnel(leaderID)->execCB(&c1, "set", "qcl-counter", "1");
TrivialQCallback c2;
tunnel(leaderID)->execCB(&c2, "get", "qcl-counter");
std::future<redisReplyPtr> fut1 = tunnel(leaderID)->exec("get", "qcl-counter");
std::future<redisReplyPtr> fut2 = tunnel(leaderID)->exec("set", "qcl-counter", "2");
std::future<redisReplyPtr> fut3 = tunnel(leaderID)->exec("get", "qcl-counter");
TrivialQCallback c3;
tunnel(leaderID)->execCB(&c3, "get", "qcl-counter");
TrivialQCallback c4;
tunnel(leaderID)->execCB(&c4, "set", "qcl-counter", "3");
TrivialQCallback c5;
tunnel(leaderID)->execCB(&c5, "get", "qcl-counter");
std::future<redisReplyPtr> fut4 = tunnel(leaderID)->exec("get", "qcl-counter");
ASSERT_REPLY(c1.getFuture(), "OK");
ASSERT_REPLY(c2.getFuture(), "1");
ASSERT_REPLY(fut1, "1");
ASSERT_REPLY(fut2, "OK");
ASSERT_REPLY(fut3, "2");
ASSERT_REPLY(c3.getFuture(), "2");
ASSERT_REPLY(c4.getFuture(), "OK");
ASSERT_REPLY(c5.getFuture(), "3");
ASSERT_REPLY(fut4, "3");
}
TEST_F(Raft_e2e, replication_with_trimmed_journal) {
......
// ----------------------------------------------------------------------
// File: tunnel.cc
// File: qclient.cc
// Author: Georgios Bitzes - CERN
// ----------------------------------------------------------------------
......
......@@ -89,6 +89,26 @@ std::vector<std::string> make_vec(Args... args) {
return std::vector<std::string> { args... };
}
// Yes, passing a callback to QClient to convert it into a future is really
// stupid, since QClient supports futures natively. This is used to test that
// qclient callbacks work as they should..
class TrivialQCallback : public qclient::QCallback {
public:
TrivialQCallback() {}
virtual ~TrivialQCallback() {}
virtual void handleResponse(qclient::redisReplyPtr &&reply) override {
promise.set_value(std::move(reply));
}
std::future<qclient::redisReplyPtr> getFuture() {
return promise.get_future();
}
private:
std::promise<qclient::redisReplyPtr> promise;
};
class GlobalEnv : public testing::Environment {
public:
virtual void SetUp() override;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment