Added FutureUnionMessage, DropUnionMessages and ExpectNoFutureUnionMessages.
Review: https://reviews.apache.org/r/36461 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/53298516 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/53298516 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/53298516 Branch: refs/heads/master Commit: 53298516d88fa2060990de5254f4c5ad3ca1ada0 Parents: 6b1b66d Author: Vinod Kone <[email protected]> Authored: Fri Jul 10 16:10:25 2015 -0700 Committer: Vinod Kone <[email protected]> Committed: Fri Jul 17 10:43:58 2015 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/include/process/gmock.hpp | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/53298516/3rdparty/libprocess/include/process/gmock.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/gmock.hpp b/3rdparty/libprocess/include/process/gmock.hpp index e878161..d449952 100644 --- a/3rdparty/libprocess/include/process/gmock.hpp +++ b/3rdparty/libprocess/include/process/gmock.hpp @@ -330,6 +330,23 @@ MATCHER_P3(MessageMatcher, name, from, to, "") } +// This matches protobuf messages that are described using the +// standard protocol buffer "union" trick, see: +// https://developers.google.com/protocol-buffers/docs/techniques#union. +MATCHER_P4(UnionMessageMatcher, message, unionType, from, to, "") +{ + const process::MessageEvent& event = ::std::tr1::get<0>(arg); + message_type message; + + return (testing::Matcher<std::string>(message.GetTypeName()).Matches( + event.message->name) && + message.ParseFromString(event.message->body) && + testing::Matcher<unionType_type>(unionType).Matches(message.type()) && + testing::Matcher<process::UPID>(from).Matches(event.message->from) && + testing::Matcher<process::UPID>(to).Matches(event.message->to)); +} + + MATCHER_P2(DispatchMatcher, pid, method, "") { const DispatchEvent& event = ::std::tr1::get<0>(arg); @@ -358,6 +375,28 @@ Future<Message> FutureMessage(Name name, From from, To to, bool drop = false) } +template <typename Message, typename UnionType, typename From, typename To> +Future<process::Message> FutureUnionMessage( + Message message, UnionType unionType, From from, To to, bool drop = false) +{ + TestsFilter* filter = + FilterTestEventListener::instance()->install(); + + Future<process::Message> future; + synchronized (filter->mutex) { + EXPECT_CALL(filter->mock, filter(testing::A<const MessageEvent&>())) + .With(UnionMessageMatcher(message, unionType, from, to)) + .WillOnce(testing::DoAll(FutureArgField<0>( + &MessageEvent::message, + &future), + testing::Return(drop))) + .RetiresOnSaturation(); // Don't impose any subsequent expectations. + } + + return future; +} + + template <typename PID, typename Method> Future<Nothing> FutureDispatch(PID pid, Method method, bool drop = false) { @@ -387,6 +426,18 @@ void DropMessages(Name name, From from, To to) } +template <typename Message, typename UnionType, typename From, typename To> +void DropUnionMessages(Message message, UnionType unionType, From from, To to) +{ + TestsFilter* filter = FilterTestEventListener::instance()->install(); + synchronized (filter->mutex) { + EXPECT_CALL(filter->mock, filter(testing::A<const MessageEvent&>())) + .With(UnionMessageMatcher(message, unionType, from, to)) + .WillRepeatedly(testing::Return(true)); + } +} + + template <typename Name, typename From, typename To> void ExpectNoFutureMessages(Name name, From from, To to) { @@ -399,6 +450,19 @@ void ExpectNoFutureMessages(Name name, From from, To to) } +template <typename Message, typename UnionType, typename From, typename To> +void ExpectNoFutureUnionMessages( + Message message, UnionType unionType, From from, To to) +{ + TestsFilter* filter = FilterTestEventListener::instance()->install(); + synchronized (filter->mutex) { + EXPECT_CALL(filter->mock, filter(testing::A<const MessageEvent&>())) + .With(UnionMessageMatcher(message, unionType, from, to)) + .Times(0); + } +} + + template <typename PID, typename Method> void DropDispatches(PID pid, Method method) {
