-
Notifications
You must be signed in to change notification settings - Fork 341
Add NotificationConsumer/Producer unittest #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the difference between the data and FieldValueTuple?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
@@ -264,3 +333,4 @@ TEST(DBConnector, selectableevent) | |
|
|
||
| EXPECT_EQ(value, 2); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added just for flexibility