From 95bce5d6560260afa2322bd89fd0a25b4f599b7f Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 4 Sep 2017 23:26:32 -0700 Subject: [PATCH] Add more storage incoming unit tests. --- src/test/native/cpp/StorageTest.cpp | 53 ++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/test/native/cpp/StorageTest.cpp b/src/test/native/cpp/StorageTest.cpp index f61b973..44bad81 100644 --- a/src/test/native/cpp/StorageTest.cpp +++ b/src/test/native/cpp/StorageTest.cpp @@ -876,7 +876,7 @@ TEST_P(StorageTestEmpty, ProcessIncomingEntryAssign) { auto conn = std::make_shared(); 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)), @@ -890,6 +890,57 @@ TEST_P(StorageTestEmpty, ProcessIncomingEntryAssign) { conn.get(), conn); } +TEST_P(StorageTestPopulateOne, ProcessIncomingEntryAssign) { + auto conn = std::make_shared(); + 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(); + 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(); + 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,