Skip to content

Commit

Permalink
[mock tests] Update MockDBConnector to match new swsscommon interface (
Browse files Browse the repository at this point in the history
…#1465)

Signed-off-by: Danny Allen <[email protected]>
  • Loading branch information
daall authored Oct 13, 2020
1 parent 7880c7e commit 793f9bd
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions tests/mock_tests/mock_dbconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,25 @@

namespace swss
{
DBConnector::~DBConnector()
{
close(m_conn->fd);
if (m_conn->connection_type == REDIS_CONN_TCP)
free(m_conn->tcp.host);
else
free(m_conn->unix_sock.path);
free(m_conn);
}

DBConnector::DBConnector(int dbId, const std::string &hostname, int port, unsigned int timeout) :
m_dbId(dbId)
{
m_conn = (redisContext *)calloc(1, sizeof(redisContext));
m_conn->connection_type = REDIS_CONN_TCP;
m_conn->tcp.host = strdup(hostname.c_str());
m_conn->tcp.port = port;
m_conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0);
auto conn = (redisContext *)calloc(1, sizeof(redisContext));
conn->connection_type = REDIS_CONN_TCP;
conn->tcp.host = strdup(hostname.c_str());
conn->tcp.port = port;
conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0);
setContext(conn);
}

DBConnector::DBConnector(int dbId, const std::string &unixPath, unsigned int timeout) :
m_dbId(dbId)
{
m_conn = (redisContext *)calloc(1, sizeof(redisContext));
m_conn->connection_type = REDIS_CONN_UNIX;
m_conn->unix_sock.path = strdup(unixPath.c_str());
m_conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0);
auto conn = (redisContext *)calloc(1, sizeof(redisContext));
conn->connection_type = REDIS_CONN_UNIX;
conn->unix_sock.path = strdup(unixPath.c_str());
conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0);
setContext(conn);
}

DBConnector::DBConnector(const std::string& dbName, unsigned int timeout, bool isTcpConn)
Expand All @@ -46,18 +38,20 @@ namespace swss
m_dbId = swss::SonicDBConfig::getDbId(dbName);
if (isTcpConn)
{
m_conn = (redisContext *)calloc(1, sizeof(redisContext));
m_conn->connection_type = REDIS_CONN_TCP;
m_conn->tcp.host = strdup(swss::SonicDBConfig::getDbHostname(dbName).c_str());
m_conn->tcp.port = swss::SonicDBConfig::getDbPort(dbName);
m_conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0);
auto conn = (redisContext *)calloc(1, sizeof(redisContext));
conn->connection_type = REDIS_CONN_TCP;
conn->tcp.host = strdup(swss::SonicDBConfig::getDbHostname(dbName).c_str());
conn->tcp.port = swss::SonicDBConfig::getDbPort(dbName);
conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0);
setContext(conn);
}
else
{
m_conn = (redisContext *)calloc(1, sizeof(redisContext));
m_conn->connection_type = REDIS_CONN_UNIX;
m_conn->unix_sock.path = strdup(swss::SonicDBConfig::getDbSock(dbName).c_str());
m_conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0);
auto conn = (redisContext *)calloc(1, sizeof(redisContext));
conn->connection_type = REDIS_CONN_UNIX;
conn->unix_sock.path = strdup(swss::SonicDBConfig::getDbSock(dbName).c_str());
conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0);
setContext(conn);
}
}

Expand Down

0 comments on commit 793f9bd

Please sign in to comment.