You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ya...@apache.org on 2014/06/23 20:25:49 UTC

[6/6] git commit: Refactored the querying and parsing of metrics snapshot into a MACRO.

Refactored the querying and parsing of metrics snapshot into a MACRO.

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


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

Branch: refs/heads/master
Commit: a6236a43d19dfd95b665463215db50525375efbc
Parents: 1b2596d
Author: Jiang Yan Xu <ya...@jxu.me>
Authored: Fri Jun 13 19:57:08 2014 -0700
Committer: Jiang Yan Xu <ya...@jxu.me>
Committed: Mon Jun 23 11:19:40 2014 -0700

----------------------------------------------------------------------
 src/tests/rate_limiting_tests.cpp | 136 +++++++--------------------------
 1 file changed, 26 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a6236a43/src/tests/rate_limiting_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/rate_limiting_tests.cpp b/src/tests/rate_limiting_tests.cpp
index 9a54461..2a37fc1 100644
--- a/src/tests/rate_limiting_tests.cpp
+++ b/src/tests/rate_limiting_tests.cpp
@@ -51,6 +51,23 @@ using testing::_;
 using testing::Eq;
 using testing::Return;
 
+// Query Mesos metrics snapshot endpoint and return a JSON::Object
+// result.
+#define METRICS_SNAPSHOT                                                       \
+  ({ Future<process::http::Response> response =                                \
+       process::http::get(MetricsProcess::instance()->self(), "snapshot");     \
+     AWAIT_READY(response);                                                    \
+                                                                               \
+     EXPECT_SOME_EQ(                                                           \
+         "application/json",                                                   \
+         response.get().headers.get("Content-Type"));                          \
+                                                                               \
+     Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body); \
+     ASSERT_SOME(parse);                                                       \
+                                                                               \
+     parse.get(); })
+
+
 // This test case covers tests related to framework API rate limiting
 // which includes metrics exporting for API call rates.
 class RateLimitingTest : public MesosTest {};
@@ -65,20 +82,7 @@ TEST_F(RateLimitingTest, FrameworkMessageCounterMetrics)
 
   // Message counters not present before the framework registers.
   {
-    // TODO(xujyan): It would be nice to refactor out the common
-    // metrics snapshot querying logic into a helper method/MACRO.
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     EXPECT_EQ(
         0u, metrics.values.count("frameworks/"+ DEFAULT_CREDENTIAL.principal() +
@@ -105,18 +109,7 @@ TEST_F(RateLimitingTest, FrameworkMessageCounterMetrics)
 
   // Message counters added after the framework is registered.
   {
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     EXPECT_EQ(
         1u, metrics.values.count("frameworks/"+ DEFAULT_CREDENTIAL.principal() +
@@ -138,18 +131,7 @@ TEST_F(RateLimitingTest, FrameworkMessageCounterMetrics)
 
   // Message counter removed after the framework is unregistered.
   {
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     EXPECT_EQ(
         0u, metrics.values.count("frameworks/"+ DEFAULT_CREDENTIAL.principal() +
@@ -214,18 +196,7 @@ TEST_F(RateLimitingTest, FrameworkMessageCountersMultipleFrameworks)
 
   // 2. Verify that both frameworks have message counters added.
   {
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     EXPECT_EQ(
         1u, metrics.values.count("frameworks/framework1/messages_received"));
@@ -250,18 +221,7 @@ TEST_F(RateLimitingTest, FrameworkMessageCountersMultipleFrameworks)
   // 4. Its message counters are deleted while the other framework's
   //    counters stay.
   {
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     EXPECT_EQ(
         0u, metrics.values.count("frameworks/framework1/messages_received"));
@@ -321,18 +281,7 @@ TEST_F(RateLimitingTest, FrameworkMessageCountersSamePrincipalFrameworks)
 
   // Message counters added after both frameworks are registered.
   {
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     EXPECT_EQ(
         1u, metrics.values.count("frameworks/"+ DEFAULT_CREDENTIAL.principal() +
@@ -354,18 +303,7 @@ TEST_F(RateLimitingTest, FrameworkMessageCountersSamePrincipalFrameworks)
   // Message counters are not removed after the first framework is
   // unregistered.
   {
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     EXPECT_EQ(
         1u, metrics.values.count("frameworks/"+ DEFAULT_CREDENTIAL.principal() +
@@ -436,18 +374,7 @@ TEST_F(RateLimitingTest, SchedulerMessageCounterFailover)
     Clock::resume();
 
     // Verify the message counters.
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     // One message received and processed after the framework is
     // registered.
@@ -517,18 +444,7 @@ TEST_F(RateLimitingTest, SchedulerMessageCounterFailover)
     Clock::settle();
     Clock::resume();
 
-    Future<process::http::Response> response =
-      process::http::get(MetricsProcess::instance()->self(), "snapshot");
-    AWAIT_READY(response);
-
-    EXPECT_SOME_EQ(
-        "application/json",
-        response.get().headers.get("Content-Type"));
-
-    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
-    ASSERT_SOME(parse);
-
-    JSON::Object metrics = parse.get();
+    JSON::Object metrics = METRICS_SNAPSHOT;
 
     // Another message after sched2 is reregistered plus the one from
     // the sched1.