Skip to content

Commit

Permalink
Refine getDbId() calling to fix build after swss-common change (sonic…
Browse files Browse the repository at this point in the history
…-net#1245)

* Refine getDbId() calling to fix build after swss-common change

* Fix mock tests with multiDB support and config
  • Loading branch information
qiluo-msft authored Apr 7, 2020
1 parent 7505fe0 commit f5edec7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Consumer : public Executor {

int getDbId() const
{
return getConsumerTable()->getDbId();
return getConsumerTable()->getDbConnector()->getDbId();
}

std::string dumpTuple(const swss::KeyOpFieldsValuesTuple &tuple);
Expand Down
9 changes: 3 additions & 6 deletions tests/mock_tests/consumer_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ namespace consumer_test
ConsumerTest()
{
// FIXME: move out from constructor
m_app_db = make_shared<swss::DBConnector>(
APPL_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
m_config_db = make_shared<swss::DBConnector>(
CONFIG_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
m_state_db = make_shared<swss::DBConnector>(
STATE_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
m_app_db = make_shared<swss::DBConnector>("APPL_DB", 0);
m_config_db = make_shared<swss::DBConnector>("CONFIG_DB", 0);
m_state_db = make_shared<swss::DBConnector>("STATE_DB", 0);
consumer = unique_ptr<Consumer>(new Consumer(
new swss::ConsumerStateTable(m_config_db.get(), "CFG_TEST_TABLE", 1, 1), gPortsOrch, "CFG_TEST_TABLE"));
}
Expand Down
1 change: 1 addition & 0 deletions tests/mock_tests/mock_dbconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace swss
}

DBConnector::DBConnector(const std::string& dbName, unsigned int timeout, bool isTcpConn)
: m_dbName(dbName)
{
if (swss::SonicDBConfig::isInit() == false)
swss::SonicDBConfig::initialize("./database_config.json");
Expand Down
8 changes: 4 additions & 4 deletions tests/mock_tests/mock_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace swss

bool Table::get(const std::string &key, std::vector<FieldValueTuple> &ovalues)
{
auto table = gDB[getDbId()][getTableName()];
auto table = gDB[m_pipe->getDbId()][getTableName()];
if (table.find(key) == table.end())
{
return false;
Expand All @@ -35,7 +35,7 @@ namespace swss

bool Table::hget(const std::string &key, const std::string &field, std::string &value)
{
auto table = gDB[getDbId()][getTableName()];
auto table = gDB[m_pipe->getDbId()][getTableName()];
if (table.find(key) == table.end())
{
return false;
Expand All @@ -58,14 +58,14 @@ namespace swss
const std::string &op,
const std::string &prefix)
{
auto &table = gDB[getDbId()][getTableName()];
auto &table = gDB[m_pipe->getDbId()][getTableName()];
table[key] = values;
}

void Table::getKeys(std::vector<std::string> &keys)
{
keys.clear();
auto table = gDB[getDbId()][getTableName()];
auto table = gDB[m_pipe->getDbId()][getTableName()];
for (const auto &it : table)
{
keys.push_back(it.first);
Expand Down

0 comments on commit f5edec7

Please sign in to comment.