Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/consumertable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ void ConsumerTable::pop(KeyOpFieldsValuesTuple &kco)
vector<FieldValueTuple> fieldsValues;
string key = pop_front(m_results);
string op = pop_front(m_results);

string dbop = op.at(0) == 'D' ? DEL_COMMAND : SET_COMMAND;

op = op.substr(1);

JSon::readJson(pop_front(m_results), fieldsValues);

kco = std::make_tuple(key, op, fieldsValues);
Expand All @@ -93,7 +98,7 @@ void ConsumerTable::pop(KeyOpFieldsValuesTuple &kco)

multi();

if (op == DEL_COMMAND)
if (dbop == DEL_COMMAND)
{

std::string del("DEL ");
Expand Down
4 changes: 2 additions & 2 deletions common/producertable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void ProducerTable::set(string key, vector<FieldValueTuple> &values, string op)
{
multi();

enqueueDbChange(key, JSon::buildJson(values), op);
enqueueDbChange(key, JSon::buildJson(values), "S" + op);
exec();
}

Expand All @@ -57,7 +57,7 @@ void ProducerTable::del(string key, string op)

multi();

enqueueDbChange(key, "{}", op);
enqueueDbChange(key, "{}", "D" + op);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the use case for this passing arbitrary DEL command?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added just for flexibility


exec();
}
Expand Down
70 changes: 70 additions & 0 deletions tests/redis_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "common/dbconnector.h"
#include "common/producertable.h"
#include "common/consumertable.h"
#include "common/notificationconsumer.h"
#include "common/notificationproducer.h"
#include "common/select.h"
#include "common/selectableevent.h"
#include <iostream>
Expand Down Expand Up @@ -222,6 +224,73 @@ TEST(DBConnector, multitable)
cout << endl << "Done." << endl;
}


void notificationProducer()
{
sleep(1);

DBConnector db(TEST_VIEW, "localhost", 6379, 0);

swss::NotificationProducer np(&db, "fooChannel");

std::vector<swss::FieldValueTuple> values;

swss::FieldValueTuple e("foo", "bar");

values.push_back(e);

std::cout << "sending ntf" << std::endl;

np.send("a", "b", values);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between the data and FieldValueTuple?

Copy link
Copy Markdown
Contributor Author

@kcudnik kcudnik Apr 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the question, data is string since api takes "key" "op" as strings and values as vector of FieldValues, data is just a name here which was intendedas "data" send inside notification

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void send(std::string op, std::string data, std::vector &values);

here is the send api for notificationproducer. there is no key. The second arg is data. The question is to explain the difference between the data and values for the API.

Copy link
Copy Markdown
Contributor Author

@kcudnik kcudnik Apr 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data is just arbitrary string that is passed by user, values is just for convenience, will be used for attribute id/attribute value vector so user will not have to split it manually. Same concept as in consumer and producer table

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should put your description to notificationproducer.h to explain how to use this API.

}

TEST(DBConnector, notifications)
{
clearDB();

DBConnector db(TEST_VIEW, "localhost", 6379, 0);

swss::NotificationConsumer nc(&db, "fooChannel");

std::thread np(notificationProducer);

swss::Select s;

s.addSelectable(&nc);

swss::Selectable *sel;

int fd;

int value = 1;

int result = s.select(&sel, &fd, 2000);

if (result == swss::Select::OBJECT)
{
std::cout << "Got notification " << std::endl;

value = 2;

std::string op, data;
std::vector<swss::FieldValueTuple> values;

nc.pop(op, data, values);

EXPECT_EQ(op, "a");
EXPECT_EQ(data, "b");

auto v = values.at(0);

EXPECT_EQ(fvField(v), "foo");
EXPECT_EQ(fvValue(v), "bar");
}

np.join();

EXPECT_EQ(value, 2);
}

void selectableEventThread(swss::Selectable *ev, int *value)
{
swss::Select s;
Expand Down Expand Up @@ -264,3 +333,4 @@ TEST(DBConnector, selectableevent)

EXPECT_EQ(value, 2);
}