Repository: mesos Updated Branches: refs/heads/master 58e273524 -> c9d51ee6f
Made scheduler tests parameterized. Review: https://reviews.apache.org/r/37489 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c9d51ee6 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c9d51ee6 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c9d51ee6 Branch: refs/heads/master Commit: c9d51ee6f32d5b131381a00e7f84f5c361ca6166 Parents: 58e2735 Author: Anand Mazumdar <[email protected]> Authored: Fri Aug 14 19:18:51 2015 -0700 Committer: Vinod Kone <[email protected]> Committed: Fri Aug 14 19:18:51 2015 -0700 ---------------------------------------------------------------------- include/mesos/http.hpp | 56 +++++++++++++++++++++++++++++++++++++ include/mesos/v1/scheduler.hpp | 10 +++++++ src/Makefile.am | 1 + src/common/http.cpp | 4 --- src/common/http.hpp | 27 +----------------- src/scheduler/scheduler.cpp | 13 +++++++-- src/tests/scheduler_tests.cpp | 41 +++++++++++++++++++-------- 7 files changed, 109 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d51ee6/include/mesos/http.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/http.hpp b/include/mesos/http.hpp new file mode 100644 index 0000000..8b9b748 --- /dev/null +++ b/include/mesos/http.hpp @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MESOS_HTTP_HPP__ +#define __MESOS_HTTP_HPP__ + +#include <ostream> + +#include <stout/unreachable.hpp> + +namespace mesos { + +const char APPLICATION_JSON[] = "application/json"; +const char APPLICATION_PROTOBUF[] = "application/x-protobuf"; + +// Possible content-types that can be used as responses for +// the Mesos HTTP API. +enum class ContentType +{ + PROTOBUF, + JSON +}; + + +inline std::ostream& operator<<(std::ostream& stream, ContentType contentType) +{ + switch (contentType) { + case ContentType::PROTOBUF: { + return stream << APPLICATION_PROTOBUF; + } + case ContentType::JSON: { + return stream << APPLICATION_JSON; + } + } + + UNREACHABLE(); +} + +} // namespace mesos { + +#endif // __MESOS_HTTP_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d51ee6/include/mesos/v1/scheduler.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/v1/scheduler.hpp b/include/mesos/v1/scheduler.hpp index dddc494..8c379a8 100644 --- a/include/mesos/v1/scheduler.hpp +++ b/include/mesos/v1/scheduler.hpp @@ -23,6 +23,8 @@ #include <queue> #include <string> +#include <mesos/http.hpp> + #include <mesos/v1/mesos.hpp> #include <mesos/v1/scheduler/scheduler.hpp> @@ -49,6 +51,14 @@ public: const std::function<void(void)>& disconnected, const std::function<void(const std::queue<Event>&)>& received); + // This constructor is primarily used for testing. + Mesos(const std::string& master, + ContentType contentType, + const std::function<void(void)>& connected, + const std::function<void(void)>& disconnected, + const std::function<void(const std::queue<Event>&)>& received); + + virtual ~Mesos(); // Attempts to send a call to the master. http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d51ee6/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index e990369..457ad26 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -489,6 +489,7 @@ libmesos_no_3rdparty_la_SOURCES = \ pkginclude_HEADERS = \ $(top_srcdir)/include/mesos/executor.hpp \ $(top_srcdir)/include/mesos/hook.hpp \ + $(top_srcdir)/include/mesos/http.hpp \ $(top_srcdir)/include/mesos/mesos.hpp \ $(top_srcdir)/include/mesos/mesos.proto \ $(top_srcdir)/include/mesos/module.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d51ee6/src/common/http.cpp ---------------------------------------------------------------------- diff --git a/src/common/http.cpp b/src/common/http.cpp index e2ff48c..5705365 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -42,10 +42,6 @@ using std::vector; namespace mesos { namespace internal { -const char APPLICATION_JSON[] = "application/json"; -const char APPLICATION_PROTOBUF[] = "application/x-protobuf"; - - string serialize( ContentType contentType, const google::protobuf::Message& message) http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d51ee6/src/common/http.hpp ---------------------------------------------------------------------- diff --git a/src/common/http.hpp b/src/common/http.hpp index 0eab8ba..61ad531 100644 --- a/src/common/http.hpp +++ b/src/common/http.hpp @@ -21,6 +21,7 @@ #include <vector> +#include <mesos/http.hpp> #include <mesos/mesos.hpp> #include <stout/hashmap.hpp> @@ -36,32 +37,6 @@ namespace internal { class Attributes; class Task; -extern const char APPLICATION_JSON[]; -extern const char APPLICATION_PROTOBUF[]; - -// Possible content-types that can be used as responses for -// the mesos Http API. -enum class ContentType -{ - PROTOBUF, - JSON -}; - - -inline std::ostream& operator<<(std::ostream& stream, ContentType contentType) -{ - switch (contentType) { - case ContentType::PROTOBUF: { - return stream << APPLICATION_PROTOBUF; - } - case ContentType::JSON: { - return stream << APPLICATION_JSON; - } - } - - UNREACHABLE(); -} - // Serializes a protobuf message for transmission // based on the HTTP content type. http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d51ee6/src/scheduler/scheduler.cpp ---------------------------------------------------------------------- diff --git a/src/scheduler/scheduler.cpp b/src/scheduler/scheduler.cpp index 2d2bd5e..0aef68e 100644 --- a/src/scheduler/scheduler.cpp +++ b/src/scheduler/scheduler.cpp @@ -505,14 +505,14 @@ private: Mesos::Mesos( const string& master, + ContentType contentType, const lambda::function<void(void)>& connected, const lambda::function<void(void)>& disconnected, const lambda::function<void(const queue<Event>&)>& received) { - // TODO(anand): Make ContentType as a constructor argument. process = new MesosProcess( master, - ContentType::PROTOBUF, + contentType, connected, disconnected, received); @@ -521,6 +521,15 @@ Mesos::Mesos( } +// Default ContentType is protobuf for HTTP requests. +Mesos::Mesos( + const string& master, + const lambda::function<void(void)>& connected, + const lambda::function<void(void)>& disconnected, + const lambda::function<void(const queue<Event>&)>& received) + : Mesos(master, ContentType::PROTOBUF, connected, disconnected, received) {} + + Mesos::~Mesos() { terminate(process); http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d51ee6/src/tests/scheduler_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/scheduler_tests.cpp b/src/tests/scheduler_tests.cpp index 7842f27..77c2635 100644 --- a/src/tests/scheduler_tests.cpp +++ b/src/tests/scheduler_tests.cpp @@ -71,13 +71,14 @@ using testing::_; using testing::AtMost; using testing::DoAll; using testing::Return; +using testing::WithParamInterface; namespace mesos { namespace internal { namespace tests { -class SchedulerTest : public MesosTest +class SchedulerTest : public MesosTest, public WithParamInterface<ContentType> { protected: // Helper class for using EXPECT_CALL since the Mesos scheduler API @@ -92,6 +93,14 @@ protected: }; +// The scheduler library tests are parameterized by the content type +// of the HTTP request. +INSTANTIATE_TEST_CASE_P( + ContentType, + SchedulerTest, + ::testing::Values(ContentType::PROTOBUF, ContentType::JSON)); + + // Enqueues all received events into a libprocess queue. ACTION_P(Enqueue, queue) { @@ -112,7 +121,7 @@ ACTION_P(Enqueue, queue) // This test verifies that when a scheduler resubscribes it receives // SUBSCRIBED event with the previously assigned framework id. -TEST_F(SchedulerTest, Subscribe) +TEST_P(SchedulerTest, Subscribe) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -128,6 +137,7 @@ TEST_F(SchedulerTest, Subscribe) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -179,7 +189,7 @@ TEST_F(SchedulerTest, Subscribe) } -TEST_F(SchedulerTest, TaskRunning) +TEST_P(SchedulerTest, TaskRunning) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -202,6 +212,7 @@ TEST_F(SchedulerTest, TaskRunning) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -289,7 +300,7 @@ TEST_F(SchedulerTest, TaskRunning) } -TEST_F(SchedulerTest, ReconcileTask) +TEST_P(SchedulerTest, ReconcileTask) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -312,6 +323,7 @@ TEST_F(SchedulerTest, ReconcileTask) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -401,7 +413,7 @@ TEST_F(SchedulerTest, ReconcileTask) } -TEST_F(SchedulerTest, KillTask) +TEST_P(SchedulerTest, KillTask) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -424,6 +436,7 @@ TEST_F(SchedulerTest, KillTask) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -528,7 +541,7 @@ TEST_F(SchedulerTest, KillTask) } -TEST_F(SchedulerTest, ShutdownExecutor) +TEST_P(SchedulerTest, ShutdownExecutor) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -551,6 +564,7 @@ TEST_F(SchedulerTest, ShutdownExecutor) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -644,7 +658,7 @@ TEST_F(SchedulerTest, ShutdownExecutor) } -TEST_F(SchedulerTest, Teardown) +TEST_P(SchedulerTest, Teardown) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -667,6 +681,7 @@ TEST_F(SchedulerTest, Teardown) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -748,7 +763,7 @@ TEST_F(SchedulerTest, Teardown) } -TEST_F(SchedulerTest, Decline) +TEST_P(SchedulerTest, Decline) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -767,6 +782,7 @@ TEST_F(SchedulerTest, Decline) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -828,7 +844,7 @@ TEST_F(SchedulerTest, Decline) } -TEST_F(SchedulerTest, Revive) +TEST_P(SchedulerTest, Revive) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -847,6 +863,7 @@ TEST_F(SchedulerTest, Revive) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -924,7 +941,7 @@ TEST_F(SchedulerTest, Revive) } -TEST_F(SchedulerTest, Message) +TEST_P(SchedulerTest, Message) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -947,6 +964,7 @@ TEST_F(SchedulerTest, Message) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1)); @@ -1033,7 +1051,7 @@ TEST_F(SchedulerTest, Message) } -TEST_F(SchedulerTest, Request) +TEST_P(SchedulerTest, Request) { master::Flags flags = CreateMasterFlags(); flags.authenticate_frameworks = false; @@ -1049,6 +1067,7 @@ TEST_F(SchedulerTest, Request) Mesos mesos( master.get(), + GetParam(), lambda::bind(&Callbacks::connected, lambda::ref(callbacks)), lambda::bind(&Callbacks::disconnected, lambda::ref(callbacks)), lambda::bind(&Callbacks::received, lambda::ref(callbacks), lambda::_1));
