You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2014/10/26 02:38:38 UTC

git commit: Introduced a FutureResult action.

Repository: mesos
Updated Branches:
  refs/heads/master d9381b018 -> 6a045e98f


Introduced a FutureResult action.

The FutureResult action enables capturing the result from an inner
action, e.g., an Invoke* action.

Review: https://reviews.apache.org/r/27199


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6a045e98
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6a045e98
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6a045e98

Branch: refs/heads/master
Commit: 6a045e98f868c286c13a813f53073bddc249e670
Parents: d9381b0
Author: Benjamin Hindman <be...@gmail.com>
Authored: Wed Oct 22 07:56:53 2014 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sat Oct 25 18:38:32 2014 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/gmock.hpp | 63 ++++++++++++++++++++++
 1 file changed, 63 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6a045e98/3rdparty/libprocess/include/process/gmock.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/gmock.hpp b/3rdparty/libprocess/include/process/gmock.hpp
index 6330ea6..d6f2fc8 100644
--- a/3rdparty/libprocess/include/process/gmock.hpp
+++ b/3rdparty/libprocess/include/process/gmock.hpp
@@ -131,6 +131,69 @@ FutureSatisfy(process::Future<Nothing>* future)
 }
 
 
+// This action invokes an "inner" action but captures the result and
+// stores a copy of it in a future. Note that this is implemented
+// similarly to the IgnoreResult action, which relies on the cast
+// operator to Action<F> which must occur (implicitly) before the
+// expression has completed, hence we can pass the Future<R>* all the
+// way through to our action "implementation".
+template <typename R, typename A>
+class FutureResultAction
+{
+public:
+  explicit FutureResultAction(process::Future<R>* future, const A& action)
+    : future(future),
+      action(action) {}
+
+  template <typename F>
+  operator ::testing::Action<F>() const
+  {
+    return ::testing::Action<F>(new Implementation<F>(future, action));
+  }
+
+private:
+  template <typename F>
+  class Implementation : public ::testing::ActionInterface<F>
+  {
+  public:
+    explicit Implementation(process::Future<R>* future, const A& action)
+      : action(action)
+    {
+      *future = promise.future();
+    }
+
+    virtual typename ::testing::ActionInterface<F>::Result Perform(
+        const typename ::testing::ActionInterface<F>::ArgumentTuple& args)
+    {
+      const typename ::testing::ActionInterface<F>::Result& result =
+        action.Perform(args);
+      promise.set(result);
+      return result;
+    }
+
+  private:
+    // Not copyable, not assignable.
+    Implementation(const Implementation&);
+    Implementation& operator = (const Implementation&);
+
+    process::Promise<R> promise;
+    const ::testing::Action<F> action;
+  };
+
+  process::Future<R>* future;
+  const A action;
+};
+
+
+template <typename R, typename A>
+FutureResultAction<R, A> FutureResult(
+    process::Future<R>* future,
+    const A& action)
+{
+  return FutureResultAction<R, A>(future, action);
+}
+
+
 namespace process {
 
 class MockFilter : public Filter