Commit 8d31a6a6 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Add method to calculate number of expected responses to a MultiOp

parent 3e1c82a0
Pipeline #416724 passed with stages
in 28 minutes and 13 seconds
......@@ -82,6 +82,22 @@ public:
void fromRedisRequest(const RedisRequest &req);
std::string toPrintableString() const;
//----------------------------------------------------------------------------
// How many responses is the client to this MultiOp expecting?
// - size() if this is a phantom transaction. The client cannot possibly
// know we're batching the requests in the background, and will be utterly
// confused if we provide fewer responses than actual requests sent.
// - Just one, otherwise. The client issued a real transaction, and knows to
// expect just a single (vector) response.
//----------------------------------------------------------------------------
int64_t expectedResponses() const {
if(phantom) {
return requests.size();
}
return 1;
}
private:
void checkLastCommandForWrites();
......
......@@ -408,6 +408,11 @@ TEST(MultiOp, Parsing) {
ASSERT_TRUE(multiOp.containsWrites());
multiOp.setPhantom(false);
ASSERT_EQ(multiOp.expectedResponses(), 1);
multiOp.setPhantom(true);
ASSERT_EQ(multiOp.expectedResponses(), 2);
std::string serialized = multiOp.serialize();
MultiOp multiOp2;
......@@ -427,5 +432,9 @@ TEST(MultiOp, Parsing) {
multiOp3.emplace_back("SET", "aaa", "bbb");
ASSERT_TRUE(multiOp3.containsWrites());
ASSERT_EQ(multiOp3.expectedResponses(), 1);
multiOp3.setPhantom(true);
ASSERT_EQ(multiOp3.expectedResponses(), 3);
ASSERT_THROW(multiOp3.emplace_back("asdf", "1234"), FatalException);
}
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