mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
Factor out client connections module into a separate library called facade
This commit is contained in:
parent
28a2db1044
commit
3f0fcbf99f
64 changed files with 946 additions and 666 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021, Roman Gershman. All rights reserved.
|
||||
// Copyright 2022, Roman Gershman. All rights reserved.
|
||||
// See LICENSE for licensing terms.
|
||||
//
|
||||
|
||||
|
@ -9,15 +9,14 @@
|
|||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "server/dragonfly_connection.h"
|
||||
#include "facade/dragonfly_connection.h"
|
||||
#include "util/uring/uring_pool.h"
|
||||
|
||||
namespace dfly {
|
||||
|
||||
using namespace testing;
|
||||
using namespace util;
|
||||
using namespace std;
|
||||
using MP = MemcacheParser;
|
||||
using namespace std;
|
||||
using namespace util;
|
||||
using namespace testing;
|
||||
|
||||
static vector<string> SplitLines(const std::string& src) {
|
||||
vector<string> res = absl::StrSplit(src, "\r\n");
|
||||
|
@ -29,90 +28,6 @@ static vector<string> SplitLines(const std::string& src) {
|
|||
return res;
|
||||
}
|
||||
|
||||
bool RespMatcher::MatchAndExplain(const RespExpr& e, MatchResultListener* listener) const {
|
||||
if (e.type != type_) {
|
||||
*listener << "\nWrong type: " << RespExpr::TypeName(e.type);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type_ == RespExpr::STRING || type_ == RespExpr::ERROR) {
|
||||
RespExpr::Buffer ebuf = e.GetBuf();
|
||||
std::string_view actual{reinterpret_cast<char*>(ebuf.data()), ebuf.size()};
|
||||
|
||||
if (type_ == RespExpr::ERROR && !absl::StrContains(actual, exp_str_)) {
|
||||
*listener << "Actual does not contain '" << exp_str_ << "'";
|
||||
return false;
|
||||
}
|
||||
if (type_ == RespExpr::STRING && exp_str_ != actual) {
|
||||
*listener << "\nActual string: " << actual;
|
||||
return false;
|
||||
}
|
||||
} else if (type_ == RespExpr::INT64) {
|
||||
auto actual = get<int64_t>(e.u);
|
||||
if (exp_int_ != actual) {
|
||||
*listener << "\nActual : " << actual << " expected: " << exp_int_;
|
||||
return false;
|
||||
}
|
||||
} else if (type_ == RespExpr::ARRAY) {
|
||||
size_t len = get<RespVec*>(e.u)->size();
|
||||
if (len != size_t(exp_int_)) {
|
||||
*listener << "Actual length " << len << ", expected: " << exp_int_;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RespMatcher::DescribeTo(std::ostream* os) const {
|
||||
*os << "is ";
|
||||
switch (type_) {
|
||||
case RespExpr::STRING:
|
||||
case RespExpr::ERROR:
|
||||
*os << exp_str_;
|
||||
break;
|
||||
|
||||
case RespExpr::INT64:
|
||||
*os << exp_str_;
|
||||
break;
|
||||
default:
|
||||
*os << "TBD";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RespMatcher::DescribeNegationTo(std::ostream* os) const {
|
||||
*os << "is not ";
|
||||
}
|
||||
|
||||
bool RespTypeMatcher::MatchAndExplain(const RespExpr& e, MatchResultListener* listener) const {
|
||||
if (e.type != type_) {
|
||||
*listener << "\nWrong type: " << RespExpr::TypeName(e.type);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RespTypeMatcher::DescribeTo(std::ostream* os) const {
|
||||
*os << "is " << RespExpr::TypeName(type_);
|
||||
}
|
||||
|
||||
void RespTypeMatcher::DescribeNegationTo(std::ostream* os) const {
|
||||
*os << "is not " << RespExpr::TypeName(type_);
|
||||
}
|
||||
|
||||
void PrintTo(const RespExpr::Vec& vec, std::ostream* os) {
|
||||
*os << "Vec: [";
|
||||
if (!vec.empty()) {
|
||||
for (size_t i = 0; i < vec.size() - 1; ++i) {
|
||||
*os << vec[i] << ",";
|
||||
}
|
||||
*os << vec.back();
|
||||
}
|
||||
*os << "]\n";
|
||||
}
|
||||
|
||||
vector<int64_t> ToIntArr(const RespVec& vec) {
|
||||
vector<int64_t> res;
|
||||
for (auto a : vec) {
|
||||
|
@ -126,7 +41,8 @@ vector<int64_t> ToIntArr(const RespVec& vec) {
|
|||
}
|
||||
|
||||
BaseFamilyTest::TestConnWrapper::TestConnWrapper(Protocol proto)
|
||||
: dummy_conn(new Connection(proto, nullptr, nullptr)), cmd_cntx(&sink, dummy_conn.get()) {
|
||||
: dummy_conn(new facade::Connection(proto, nullptr, nullptr, nullptr)),
|
||||
cmd_cntx(&sink, dummy_conn.get()) {
|
||||
}
|
||||
|
||||
BaseFamilyTest::TestConnWrapper::~TestConnWrapper() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue