You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/02/28 18:55:26 UTC
[08/10] mesos git commit: Introduced a callback interface for testing
the scheduler library.
Introduced a callback interface for testing the scheduler library.
This change adds a new callback based testing interface for the scheduler
library similar to the already existing one for the executor library.
This gets rid of the following hack:
```cpp
// Enqueues all received events into a libprocess queue.
ACTION_P(Enqueue, queue)
{
std::queue<Event> events = arg0;
while (!events.empty()) {
// Note that we currently drop HEARTBEATs because most of these tests
// are not designed to deal with heartbeats.
// TODO(vinod): Implement DROP_HTTP_CALLS that can filter heartbeats.
if (events.front().type() == Event::HEARTBEAT) {
VLOG(1) << "Ignoring HEARTBEAT event";
} else {
queue->put(events.front());
}
events.pop();
}
}
```
New way ( similar to what we do for the driver implementation )
```cpp
EXPECT_CALL(callbacks, heartbeat())
.WillRepeatedly(Return()); // Ignore heartbeats.
```
Review: https://reviews.apache.org/r/39372/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/306cbf5f
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/306cbf5f
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/306cbf5f
Branch: refs/heads/master
Commit: 306cbf5f576c45142b8ee230c60416080717f5be
Parents: 9b0a8ce
Author: Anand Mazumdar <ma...@gmail.com>
Authored: Sun Feb 28 09:52:59 2016 -0800
Committer: Vinod Kone <vi...@gmail.com>
Committed: Sun Feb 28 09:52:59 2016 -0800
----------------------------------------------------------------------
src/tests/mesos.hpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/306cbf5f/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 242a116..e6bd50e 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -29,9 +29,12 @@
#include <mesos/scheduler.hpp>
#include <mesos/v1/executor.hpp>
+#include <mesos/v1/scheduler.hpp>
#include <mesos/v1/executor/executor.hpp>
+#include <mesos/v1/scheduler/scheduler.hpp>
+
#include <mesos/authorizer/authorizer.hpp>
#include <mesos/fetcher/fetcher.hpp>
@@ -888,6 +891,105 @@ public:
}
};
+namespace scheduler {
+
+// A generic mock HTTP scheduler to be used in tests with gmock.
+template <typename Mesos, typename Event>
+class MockHTTPScheduler
+{
+public:
+ MOCK_METHOD1_T(connected, void(Mesos*));
+ MOCK_METHOD1_T(disconnected, void(Mesos*));
+ MOCK_METHOD1_T(heartbeat, void(Mesos*));
+ MOCK_METHOD2_T(subscribed, void(Mesos*, const typename Event::Subscribed&));
+ MOCK_METHOD2_T(offers, void(Mesos*, const typename Event::Offers&));
+ MOCK_METHOD2_T(rescind, void(Mesos*, const typename Event::Rescind&));
+ MOCK_METHOD2_T(update, void(Mesos*, const typename Event::Update&));
+ MOCK_METHOD2_T(message, void(Mesos*, const typename Event::Message&));
+ MOCK_METHOD2_T(failure, void(Mesos*, const typename Event::Failure&));
+ MOCK_METHOD2_T(error, void(Mesos*, const typename Event::Error&));
+
+ void event(Mesos* mesos, const Event& event)
+ {
+ switch(event.type()) {
+ case Event::SUBSCRIBED:
+ subscribed(mesos, event.subscribed());
+ break;
+ case Event::OFFERS:
+ offers(mesos, event.offers());
+ break;
+ case Event::RESCIND:
+ rescind(mesos, event.rescind());
+ break;
+ case Event::UPDATE:
+ update(mesos, event.update());
+ break;
+ case Event::MESSAGE:
+ message(mesos, event.message());
+ break;
+ case Event::FAILURE:
+ failure(mesos, event.failure());
+ break;
+ case Event::ERROR:
+ error(mesos, event.error());
+ break;
+ case Event::HEARTBEAT:
+ heartbeat(mesos);
+ break;
+ }
+ }
+};
+
+
+// A generic testing interface for the scheduler library that can be used to
+// test the library across various versions.
+template <typename Mesos, typename Event>
+class TestMesos : public Mesos
+{
+public:
+ TestMesos(
+ const std::string& master,
+ ContentType contentType,
+ const std::shared_ptr<MockHTTPScheduler<Mesos, Event>>& _scheduler)
+ : Mesos(
+ master,
+ contentType,
+ lambda::bind(&MockHTTPScheduler<Mesos, Event>::connected,
+ _scheduler,
+ this),
+ lambda::bind(&MockHTTPScheduler<Mesos, Event>::disconnected,
+ _scheduler,
+ this),
+ lambda::bind(&TestMesos<Mesos, Event>::events,
+ this,
+ lambda::_1)),
+ scheduler(_scheduler) {}
+
+protected:
+ void events(std::queue<Event> events)
+ {
+ while(!events.empty()) {
+ Event event = std::move(events.front());
+ events.pop();
+ scheduler->event(this, event);
+ }
+ }
+
+private:
+ std::shared_ptr<MockHTTPScheduler<Mesos, Event>> scheduler;
+};
+
+
+using TestV1Mesos =
+ TestMesos<mesos::v1::scheduler::Mesos, mesos::v1::scheduler::Event>;
+
+} // namespace scheduler {
+
+
+using MockV1HTTPScheduler =
+ scheduler::MockHTTPScheduler<
+ mesos::v1::scheduler::Mesos, mesos::v1::scheduler::Event>;
+
namespace executor {