Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
Add more storage incoming unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Sep 7, 2017
1 parent cedbafe commit 95bce5d
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/test/native/cpp/StorageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ TEST_P(StorageTestEmpty, ProcessIncomingEntryAssign) {
auto conn = std::make_shared<MockNetworkConnection>();
auto value = Value::MakeDouble(1.0);
if (GetParam()) {
// id assign message reply generated on the server
// id assign message reply generated on the server; sent to everyone
EXPECT_CALL(
dispatcher,
QueueOutgoing(MessageEq(Message::EntryAssign("foo", 0, 0, value, 0)),
Expand All @@ -890,6 +890,57 @@ TEST_P(StorageTestEmpty, ProcessIncomingEntryAssign) {
conn.get(), conn);
}

TEST_P(StorageTestPopulateOne, ProcessIncomingEntryAssign) {
auto conn = std::make_shared<MockNetworkConnection>();
auto value = Value::MakeDouble(1.0);
EXPECT_CALL(*conn, proto_rev()).WillRepeatedly(Return(0x0300u));
if (GetParam()) {
// server broadcasts new value to all *other* connections
EXPECT_CALL(
dispatcher,
QueueOutgoing(MessageEq(Message::EntryAssign("foo", 0, 1, value, 0)),
IsNull(), conn.get()));
}
EXPECT_CALL(notifier, NotifyEntry(0, StringRef("foo"), ValueEq(value),
NT_NOTIFY_UPDATE, UINT_MAX));

storage.ProcessIncoming(Message::EntryAssign("foo", 0, 1, value, 0),
conn.get(), conn);
}

TEST_P(StorageTestPopulateOne, ProcessIncomingEntryAssignIgnore) {
auto conn = std::make_shared<MockNetworkConnection>();
auto value = Value::MakeDouble(1.0);
storage.ProcessIncoming(Message::EntryAssign("foo", 0xffff, 1, value, 0),
conn.get(), conn);
}

TEST_P(StorageTestPopulateOne, ProcessIncomingEntryAssignWithFlags) {
auto conn = std::make_shared<MockNetworkConnection>();
auto value = Value::MakeDouble(1.0);
EXPECT_CALL(*conn, proto_rev()).WillRepeatedly(Return(0x0300u));
if (GetParam()) {
// server broadcasts new value/flags to all *other* connections
EXPECT_CALL(
dispatcher,
QueueOutgoing(MessageEq(Message::EntryAssign("foo", 0, 1, value, 0x2)),
IsNull(), conn.get()));
EXPECT_CALL(notifier,
NotifyEntry(0, StringRef("foo"), ValueEq(value),
NT_NOTIFY_UPDATE | NT_NOTIFY_FLAGS, UINT_MAX));
} else {
// client forces flags back when an assign message is received for an
// existing entry with different flags
EXPECT_CALL(dispatcher, QueueOutgoing(MessageEq(Message::FlagsUpdate(0, 0)),
IsNull(), IsNull()));
EXPECT_CALL(notifier, NotifyEntry(0, StringRef("foo"), ValueEq(value),
NT_NOTIFY_UPDATE, UINT_MAX));
}

storage.ProcessIncoming(Message::EntryAssign("foo", 0, 1, value, 0x2),
conn.get(), conn);
}

INSTANTIATE_TEST_CASE_P(StorageTestsEmpty, StorageTestEmpty,
::testing::Bool(), );
INSTANTIATE_TEST_CASE_P(StorageTestsPopulateOne, StorageTestPopulateOne,
Expand Down

0 comments on commit 95bce5d

Please sign in to comment.