Repository: mesos
Updated Branches:
  refs/heads/master 4bb0f21eb -> 9c17d8a96


Added a test for JSON MasterInfo detection.

As of Mesos 0.24, we will support JSON format
for the MasterInfo information written out to
ZooKeeper for the Leader election process.

This tests that the JSON can be correctly parsed
and the correct MasterInfo information retrieved.

Jira: MESOS-2898

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


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

Branch: refs/heads/master
Commit: 9c17d8a96ca2f5ad7efd70bc788ebf011609e5fb
Parents: 4bb0f21
Author: Marco Massenzio <[email protected]>
Authored: Thu Jun 25 09:31:31 2015 -0700
Committer: Vinod Kone <[email protected]>
Committed: Thu Jun 25 09:31:31 2015 -0700

----------------------------------------------------------------------
 src/tests/master_contender_detector_tests.cpp | 39 +++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9c17d8a9/src/tests/master_contender_detector_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_contender_detector_tests.cpp 
b/src/tests/master_contender_detector_tests.cpp
index 1b30eeb..d7a3b46 100644
--- a/src/tests/master_contender_detector_tests.cpp
+++ b/src/tests/master_contender_detector_tests.cpp
@@ -37,6 +37,7 @@
 #include <stout/nothing.hpp>
 #include <stout/os.hpp>
 #include <stout/path.hpp>
+#include <stout/protobuf.hpp>
 #include <stout/try.hpp>
 
 #include "common/protobuf_utils.hpp"
@@ -755,7 +756,7 @@ TEST_F(ZooKeeperMasterContenderDetectorTest,
        MasterDetectorExpireSlaveZKSessionNewMaster)
 {
   Try<zookeeper::URL> url = zookeeper::URL::parse(
-        "zk://" + server->connectString() + "/mesos");
+      "zk://" + server->connectString() + "/mesos");
 
   ASSERT_SOME(url);
 
@@ -836,6 +837,42 @@ TEST_F(ZooKeeperMasterContenderDetectorTest,
   EXPECT_SOME_EQ(follower, detected.get());
 }
 
+
+TEST_F(ZooKeeperMasterContenderDetectorTest, MasterDetectorUsesJson)
+{
+  Try<zookeeper::URL> url = zookeeper::URL::parse(
+      "zk://" + server->connectString() + "/mesos");
+
+  ASSERT_SOME(url);
+
+  // Construct a known MasterInfo & convert into JSON.
+  PID<Master> pid;
+  pid.address.ip = net::IP::parse("10.10.1.22", AF_INET).get();
+  pid.address.port = 8080;
+
+  MasterInfo leader = internal::protobuf::createMasterInfo(pid);
+  JSON::Object masterInfo = JSON::Protobuf(leader);
+
+  // Simulate a leading master.
+  Owned<zookeeper::Group> group(
+      new Group(url.get(), MASTER_CONTENDER_ZK_SESSION_TIMEOUT));
+
+  // Simulate a leading contender: we need to force-write JSON
+  // here, as this is still not supported in Mesos 0.23.
+  LeaderContender contender(
+      group.get(), stringify(masterInfo), master::MASTER_INFO_JSON_LABEL);
+  Option<Future<Future<Nothing>>> candidacy = contender.contend();
+  ASSERT_SOME(candidacy);
+
+  // Our detector should now "discover" the JSON, parse it
+  // and derive the correct MasterInfo PB.
+  ZooKeeperMasterDetector leaderDetector(url.get());
+  Future<Option<MasterInfo> > detected = leaderDetector.detect(None());
+  AWAIT_READY(detected);
+
+  ASSERT_SOME_EQ(leader, detected.get());
+}
+
 #endif // MESOS_HAS_JAVA
 
 } // namespace tests {

Reply via email to