You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/02/19 02:07:48 UTC

[2/3] git commit: 'Try' cleanups in libprocess, and other housekeeping.

'Try' cleanups in libprocess, and other housekeeping.

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


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

Branch: refs/heads/master
Commit: befe859f5d60c51177921287d1e959dd157533eb
Parents: 7bc9931
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Sun Feb 16 14:52:20 2014 -0800
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Tue Feb 18 16:53:47 2014 -0800

----------------------------------------------------------------------
 .../3rdparty/stout/tests/error_tests.cpp        | 13 +++----
 3rdparty/libprocess/src/process.cpp             |  4 +--
 3rdparty/libprocess/src/tests/http_tests.cpp    | 36 +++++++++++---------
 3 files changed, 28 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/befe859f/3rdparty/libprocess/3rdparty/stout/tests/error_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/error_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/error_tests.cpp
index 75e365e..d86b0ea 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/error_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/error_tests.cpp
@@ -5,6 +5,7 @@
 #include <string>
 
 #include <stout/error.hpp>
+#include <stout/gtest.hpp>
 #include <stout/option.hpp>
 #include <stout/result.hpp>
 #include <stout/try.hpp>
@@ -45,16 +46,16 @@ Result<string> error5(const Result<string>& r)
 TEST(ErrorTest, Test)
 {
   Try<string> t = error1();
-  EXPECT_TRUE(t.isError());
+  EXPECT_ERROR(t);
   t = error2();
-  EXPECT_TRUE(t.isError());
+  EXPECT_ERROR(t);
   t = error3(error1());
-  EXPECT_TRUE(t.isError());
+  EXPECT_ERROR(t);
 
   Result<string> r = error1();
-  EXPECT_TRUE(r.isError());
+  EXPECT_ERROR(r);
   r = error4();
-  EXPECT_TRUE(r.isError());
+  EXPECT_ERROR(r);
   r = error5(error1());
-  EXPECT_TRUE(r.isError());
+  EXPECT_ERROR(r);
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/befe859f/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 7bf2d70..6cf4bfb 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -3622,7 +3622,7 @@ Future<size_t> read(int fd, void* data, size_t size)
     // The file descriptor is not valid (e.g., has been closed).
     promise->fail(
         "Failed to check if file descriptor was non-blocking: " +
-        string(strerror(errno)));
+        nonblock.error());
     return promise->future();
   } else if (!nonblock.get()) {
     // The file descriptor is not non-blocking.
@@ -3655,7 +3655,7 @@ Future<size_t> write(int fd, void* data, size_t size)
     // The file descriptor is not valid (e.g., has been closed).
     promise->fail(
         "Failed to check if file descriptor was non-blocking: " +
-        string(strerror(errno)));
+        nonblock.error());
     return promise->future();
   } else if (!nonblock.get()) {
     // The file descriptor is not non-blocking.

http://git-wip-us.apache.org/repos/asf/mesos/blob/befe859f/3rdparty/libprocess/src/tests/http_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index 15e72a1..94934dd 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -22,6 +22,8 @@
 
 using namespace process;
 
+using std::string;
+
 using testing::_;
 using testing::Assign;
 using testing::DoAll;
@@ -75,18 +77,18 @@ TEST(HTTP, Endpoints)
       << "Connection: Keep-Alive\r\n"
       << "\r\n";
 
-  const std::string& data = out.str();
+  const string& data = out.str();
 
   EXPECT_CALL(process, body(_))
     .WillOnce(Return(http::OK()));
 
    ASSERT_SOME(os::write(s, data));
 
-  std::string response = "HTTP/1.1 200 OK";
+  string response = "HTTP/1.1 200 OK";
 
   char temp[response.size()];
   ASSERT_LT(0, ::read(s, temp, response.size()));
-  ASSERT_EQ(response, std::string(temp, response.size()));
+  ASSERT_EQ(response, string(temp, response.size()));
 
   ASSERT_EQ(0, close(s));
 
@@ -122,10 +124,10 @@ TEST(HTTP, Endpoints)
 
 TEST(HTTP, Encode)
 {
-  std::string unencoded = "a$&+,/:;=?@ \"<>#%{}|\\^~[]`\x19\x80\xFF";
-  unencoded += std::string("\x00", 1); // Add a null byte to the end.
+  string unencoded = "a$&+,/:;=?@ \"<>#%{}|\\^~[]`\x19\x80\xFF";
+  unencoded += string("\x00", 1); // Add a null byte to the end.
 
-  std::string encoded = http::encode(unencoded);
+  string encoded = http::encode(unencoded);
 
   EXPECT_EQ("a%24%26%2B%2C%2F%3A%3B%3D%3F%40%20%22%3C%3E%23"
             "%25%7B%7D%7C%5C%5E%7E%5B%5D%60%19%80%FF%00",
@@ -142,32 +144,32 @@ TEST(HTTP, Encode)
 
 TEST(HTTP, PathParse)
 {
-  const std::string pattern = "/books/{isbn}/chapters/{chapter}";
+  const string pattern = "/books/{isbn}/chapters/{chapter}";
 
-  Try<hashmap<std::string, std::string> > parse =
+  Try<hashmap<string, string> > parse =
     http::path::parse(pattern, "/books/0304827484/chapters/3");
 
   ASSERT_SOME(parse);
   EXPECT_EQ(4, parse.get().size());
-  EXPECT_EQ("books", parse.get()["books"]);
-  EXPECT_EQ("0304827484", parse.get()["isbn"]);
-  EXPECT_EQ("chapters", parse.get()["chapters"]);
-  EXPECT_EQ("3", parse.get()["chapter"]);
+  EXPECT_SOME_EQ("books", parse.get().get("books"));
+  EXPECT_SOME_EQ("0304827484", parse.get().get("isbn"));
+  EXPECT_SOME_EQ("chapters", parse.get().get("chapters"));
+  EXPECT_SOME_EQ("3", parse.get().get("chapter"));
 
   parse = http::path::parse(pattern, "/books/0304827484");
 
   ASSERT_SOME(parse);
   EXPECT_EQ(2, parse.get().size());
-  EXPECT_EQ("books", parse.get()["books"]);
-  EXPECT_EQ("0304827484", parse.get()["isbn"]);
+  EXPECT_SOME_EQ("books", parse.get().get("books"));
+  EXPECT_SOME_EQ("0304827484", parse.get().get("isbn"));
 
   parse = http::path::parse(pattern, "/books/0304827484/chapters");
 
   ASSERT_SOME(parse);
   EXPECT_EQ(3, parse.get().size());
-  EXPECT_EQ("books", parse.get()["books"]);
-  EXPECT_EQ("0304827484", parse.get()["isbn"]);
-  EXPECT_EQ("chapters", parse.get()["chapters"]);
+  EXPECT_SOME_EQ("books", parse.get().get("books"));
+  EXPECT_SOME_EQ("0304827484", parse.get().get("isbn"));
+  EXPECT_SOME_EQ("chapters", parse.get().get("chapters"));
 
   parse = http::path::parse(pattern, "/foo/0304827484/chapters");