Repository: mesos
Updated Branches:
  refs/heads/master 6b0a304b5 -> 1c1ee8be2


Introduced an callback interface for testing HTTP based executors.

This change introduces a versioned callback interface for testing HTTP based
executors. The reasoning is similar to `MESOS-3339` , the corresponding issue
for schedulers.

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


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

Branch: refs/heads/master
Commit: 49c8895bd1302a2b98c4a80e6d2050a41715ab20
Parents: 6b0a304
Author: Anand Mazumdar <[email protected]>
Authored: Tue Feb 9 11:16:58 2016 -0800
Committer: Vinod Kone <[email protected]>
Committed: Tue Feb 9 11:16:58 2016 -0800

----------------------------------------------------------------------
 src/tests/mesos.hpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/49c8895b/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index e07d8aa..e382d91 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -28,6 +28,10 @@
 #include <mesos/executor.hpp>
 #include <mesos/scheduler.hpp>
 
+#include <mesos/v1/executor.hpp>
+
+#include <mesos/v1/executor/executor.hpp>
+
 #include <mesos/authorizer/authorizer.hpp>
 
 #include <mesos/fetcher/fetcher.hpp>
@@ -880,6 +884,101 @@ public:
 };
 
 
+namespace executor {
+
+// A generic mock HTTP executor to be used in tests with gmock.
+template <typename Mesos, typename Event>
+class MockHTTPExecutor
+{
+public:
+  MOCK_METHOD1_T(connected, void(Mesos*));
+  MOCK_METHOD1_T(disconnected, void(Mesos*));
+  MOCK_METHOD2_T(subscribed, void(Mesos*, const typename Event::Subscribed&));
+  MOCK_METHOD2_T(launch, void(Mesos*, const typename Event::Launch&));
+  MOCK_METHOD2_T(kill, void(Mesos*, const typename Event::Kill&));
+  MOCK_METHOD2_T(message, void(Mesos*, const typename Event::Message&));
+  MOCK_METHOD2_T(shutdown, void(Mesos*, const typename Event::Shutdown&));
+  MOCK_METHOD2_T(error, void(Mesos*, const typename Event::Error&));
+  MOCK_METHOD2_T(acknowledged,
+                 void(Mesos*, const typename Event::Acknowledged&));
+
+  void event(Mesos* mesos, const Event& event)
+  {
+    switch(event.type()) {
+      case Event::SUBSCRIBED:
+        subscribed(mesos, event.subscribed());
+        break;
+      case Event::LAUNCH:
+        launch(mesos, event.launch());
+        break;
+      case Event::KILL:
+        kill(mesos, event.kill());
+        break;
+      case Event::ACKNOWLEDGED:
+        acknowledged(mesos, event.acknowledged());
+        break;
+      case Event::MESSAGE:
+        message(mesos, event.message());
+        break;
+      case Event::SHUTDOWN:
+        shutdown(mesos, event.shutdown());
+        break;
+      case Event::ERROR:
+        error(mesos, event.error());
+        break;
+    }
+  }
+};
+
+
+// A generic testing interface for the executor library that can be used to
+// test the library across various versions.
+template <typename Mesos, typename Event>
+class TestMesos : public Mesos
+{
+public:
+  TestMesos(
+      ContentType contentType,
+      const std::shared_ptr<MockHTTPExecutor<Mesos, Event>>& _executor)
+    : Mesos(
+        contentType,
+        lambda::bind(&MockHTTPExecutor<Mesos, Event>::connected,
+                     _executor,
+                     this),
+        lambda::bind(&MockHTTPExecutor<Mesos, Event>::disconnected,
+                     _executor,
+                     this),
+        lambda::bind(&TestMesos<Mesos, Event>::events,
+                     this,
+                     lambda::_1)),
+      executor(_executor) {}
+
+protected:
+  void events(std::queue<Event> events)
+  {
+    while(!events.empty()) {
+      Event event = std::move(events.front());
+      events.pop();
+      executor->event(this, event);
+    }
+  }
+
+private:
+  std::shared_ptr<MockHTTPExecutor<Mesos, Event>> executor;
+};
+
+
+using TestV1Mesos =
+  TestMesos<mesos::v1::executor::Mesos, mesos::v1::executor::Event>;
+
+} // namespace executor {
+
+
+using MockV1HTTPExecutor =
+  executor::MockHTTPExecutor<
+    mesos::v1::executor::Mesos, mesos::v1::executor::Event>;
+
+
 class MockGarbageCollector : public slave::GarbageCollector
 {
 public:

Reply via email to