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

Refactor MultiOp toPrintableString

parent bddfa441
......@@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#ifndef __QUARKDB_DISPATCHER_H__
#define __QUARKDB_DISPATCHER_H__
#ifndef QUARKDB_DISPATCHER_H
#define QUARKDB_DISPATCHER_H
#include "Common.hh"
#include "Link.hh"
......
......@@ -47,17 +47,8 @@ void RedisRequest::parseCommand() {
std::string RedisRequest::toPrintableString() const {
if(this->getCommand() == RedisCommand::MULTIOP_READ || this->getCommand() == RedisCommand::MULTIOP_READWRITE) {
MultiOp multiOp;
qdb_assert(this->size() == 3);
qdb_assert(multiOp.deserialize((*this)[1]));
std::stringstream ss;
ss << (*this)[0] << " (" << (*this)[2] << "), size " << multiOp.size() << std::endl;
for(size_t i = 0; i < multiOp.size(); i++) {
ss << " --- " << i+1 << ") " << multiOp[i].toPrintableString();
if(i != multiOp.size()-1) ss << std::endl;
}
return ss.str();
multiOp.fromRedisRequest(*this);
return multiOp.toPrintableString();
}
std::stringstream ss;
......
......@@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#ifndef __QUARKDB_REDIS_REQUEST_H__
#define __QUARKDB_REDIS_REQUEST_H__
#ifndef QUARKDB_REDIS_REQUEST_H
#define QUARKDB_REDIS_REQUEST_H
#include "Commands.hh"
#include <string>
......
......@@ -120,3 +120,38 @@ RedisRequest MultiOp::toRedisRequest() const {
return req;
}
void MultiOp::fromRedisRequest(const RedisRequest &req) {
qdb_assert(req.getCommand() == RedisCommand::MULTIOP_READ || req.getCommand() == RedisCommand::MULTIOP_READWRITE);
qdb_assert(req.size() == 3);
qdb_assert(deserialize(req[1]));
if(req[2] == "phantom") {
setPhantom(true);
}
else if(req[2] == "real") {
setPhantom(false);
}
else {
qdb_throw("should never happen");
}
}
std::string MultiOp::multiOpTypeInString() const {
if(phantom) {
return "phantom";
}
return "real";
}
std::string MultiOp::toPrintableString() const {
std::stringstream ss;
ss << getFusedCommand() << " (" << multiOpTypeInString() << "), size " << requests.size() << std::endl;
for(size_t i = 0; i < requests.size(); i++) {
ss << " --- " << i+1 << ") " << requests[i].toPrintableString();
if(i != requests.size()-1) ss << std::endl;
}
return ss.str();
}
......@@ -79,6 +79,8 @@ public:
RedisRequest toRedisRequest() const;
std::string getFusedCommand() const;
void fromRedisRequest(const RedisRequest &req);
std::string toPrintableString() const;
private:
void checkLastCommandForWrites();
......@@ -86,6 +88,7 @@ private:
bool hasWrites = false;
bool phantom = false;
std::vector<RedisRequest> requests;
std::string multiOpTypeInString() const;
};
}
......
......@@ -108,7 +108,7 @@ TEST(RedisRequest, MultiOpPrintableString) {
RedisRequest req { "multiop_readwrite", multiOp.serialize(), "phantom" };
ASSERT_EQ(req.toPrintableString(),
"multiop_readwrite (phantom), size 2\n"
"MULTIOP_READWRITE (phantom), size 2\n"
" --- 1) \"set\" \"aaa\" \"bbb\"\n"
" --- 2) \"get\" \"qwe\" \"rty\""
);
......
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