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 2016/02/12 11:20:11 UTC

[1/5] mesos git commit: Added a strings::tokenize parameter for the maximum number of tokens.

Repository: mesos
Updated Branches:
  refs/heads/master d990a8a99 -> 59fd7e3ec


Added a strings::tokenize parameter for the maximum number of tokens.

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


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

Branch: refs/heads/master
Commit: 69f31e8334d539b63caab792b5ddfde92df62616
Parents: 9d02047
Author: Guangya Liu <gy...@gmail.com>
Authored: Thu Feb 11 11:10:15 2016 +0100
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Feb 12 10:33:28 2016 +0100

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/strings.hpp    | 34 ++++++----
 .../3rdparty/stout/tests/strings_tests.cpp      | 71 ++++++++++++++++++++
 2 files changed, 91 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/69f31e83/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
index ae3b6eb..162bdfb 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
@@ -131,31 +131,37 @@ inline std::string replace(
 
 // Tokenizes the string using the delimiters.
 // Empty tokens will not be included in the result.
-// TODO(ijimenez): Support maximum number of tokens
-// to be returned.
+// Optionally, maximum number of tokens to be returned
+// can be specified.
 inline std::vector<std::string> tokenize(
     const std::string& s,
-    const std::string& delims)
+    const std::string& delims,
+    const Option<size_t>& maxTokens = None())
 {
   size_t offset = 0;
   std::vector<std::string> tokens;
 
-  while (true) {
-    size_t i = s.find_first_not_of(delims, offset);
-    if (std::string::npos == i) {
-      break;
+  while (maxTokens.isNone() || maxTokens.get() > 0) {
+    size_t nonDelim = s.find_first_not_of(delims, offset);
+
+    if (nonDelim == std::string::npos) {
+      break; // Nothing left
     }
 
-    size_t j = s.find_first_of(delims, i);
-    if (std::string::npos == j) {
-      tokens.push_back(s.substr(i));
-      offset = s.length();
-      continue;
+    size_t delim = s.find_first_of(delims, nonDelim);
+
+    // Finish tokenizing if this is the last token,
+    // or we've found enough tokens.
+    if (delim == std::string::npos ||
+        (maxTokens.isSome() && tokens.size() == maxTokens.get() - 1)) {
+      tokens.push_back(s.substr(nonDelim));
+      break;
     }
 
-    tokens.push_back(s.substr(i, j - i));
-    offset = j;
+    tokens.push_back(s.substr(nonDelim, delim - nonDelim));
+    offset = delim;
   }
+
   return tokens;
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/69f31e83/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
index 877dc70..7eed0f3 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
@@ -198,6 +198,77 @@ TEST(StringsTest, TokenizeNullByteDelim)
 }
 
 
+TEST(StringsTest, TokenizeNZero)
+{
+  vector<string> tokens = strings::tokenize("foo,bar,,,", ",", 0);
+  ASSERT_EQ(0u, tokens.size());
+}
+
+
+TEST(StringsTest, TokenizeNOne)
+{
+  vector<string> tokens = strings::tokenize("foo,bar,,,", ",", 1);
+  ASSERT_EQ(1u, tokens.size());
+  EXPECT_EQ("foo,bar,,,", tokens[0]);
+}
+
+
+TEST(StringsTest, TokenizeNDelimOnlyString)
+{
+  vector<string> tokens = strings::tokenize(",,,", ",", 2);
+  ASSERT_EQ(0u, tokens.size());
+}
+
+
+TEST(StringsTest, TokenizeN)
+{
+  vector<string> tokens = strings::tokenize("foo,bar,,baz", ",", 2);
+  ASSERT_EQ(2u, tokens.size());
+  EXPECT_EQ("foo",      tokens[0]);
+  EXPECT_EQ("bar,,baz", tokens[1]);
+}
+
+
+TEST(StringsTest, TokenizeNStringWithDelimsAtStart)
+{
+  vector<string> tokens = strings::tokenize(",,foo,bar,,baz", ",", 5);
+  ASSERT_EQ(3u, tokens.size());
+  EXPECT_EQ("foo", tokens[0]);
+  EXPECT_EQ("bar", tokens[1]);
+  EXPECT_EQ("baz", tokens[2]);
+}
+
+
+TEST(StringsTest, TokenizeNStringWithDelimsAtEnd)
+{
+  vector<string> tokens = strings::tokenize("foo,bar,,baz,,", ",", 4);
+  ASSERT_EQ(3u, tokens.size());
+  EXPECT_EQ("foo", tokens[0]);
+  EXPECT_EQ("bar", tokens[1]);
+  EXPECT_EQ("baz", tokens[2]);
+}
+
+
+TEST(StringsTest, TokenizeNStringWithDelimsAtStartAndEnd)
+{
+  vector<string> tokens = strings::tokenize(",,foo,bar,,", ",", 6);
+  ASSERT_EQ(2u, tokens.size());
+  EXPECT_EQ("foo", tokens[0]);
+  EXPECT_EQ("bar", tokens[1]);
+}
+
+
+TEST(StringsTest, TokenizeNWithMultipleDelims)
+{
+  vector<string> tokens = strings::tokenize("foo.bar,.,.baz.", ",.", 6);
+  ASSERT_EQ(3u, tokens.size());
+  EXPECT_EQ("foo", tokens[0]);
+  EXPECT_EQ("bar", tokens[1]);
+  EXPECT_EQ("baz", tokens[2]);
+}
+
+
+
 TEST(StringsTest, SplitEmptyString)
 {
   vector<string> tokens = strings::split("", ",");


[3/5] mesos git commit: Used size_t for consistency in stout/strings.hpp.

Posted by bm...@apache.org.
Used size_t for consistency in stout/strings.hpp.


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

Branch: refs/heads/master
Commit: 66ddbc7495d923845590e89f423cf16b8e8a2e11
Parents: d990a8a
Author: Benjamin Mahler <be...@gmail.com>
Authored: Thu Feb 11 11:12:21 2016 +0100
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Feb 12 10:33:28 2016 +0100

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/66ddbc74/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
index c20e2ff..1309a18 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
@@ -169,7 +169,7 @@ inline std::vector<std::string> tokenize(
 inline std::vector<std::string> split(
     const std::string& s,
     const std::string& delims,
-    const Option<unsigned int>& n = None())
+    const Option<size_t>& n = None())
 {
   std::vector<std::string> tokens;
   size_t offset = 0;


[2/5] mesos git commit: Fixed a bug in strings::split when n=1.

Posted by bm...@apache.org.
Fixed a bug in strings::split when n=1.


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

Branch: refs/heads/master
Commit: 9d020470f7fefb7b257912e8a0dfddae8e5fbe86
Parents: e6fdd5d
Author: Benjamin Mahler <be...@gmail.com>
Authored: Thu Feb 11 13:46:00 2016 +0100
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Feb 12 10:33:28 2016 +0100

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/strings.hpp          | 14 ++++++--------
 .../libprocess/3rdparty/stout/tests/strings_tests.cpp |  8 ++++++++
 2 files changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9d020470/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
index 015eecd..ae3b6eb 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
@@ -171,24 +171,22 @@ inline std::vector<std::string> split(
     const std::string& delims,
     const Option<size_t>& maxTokens = None())
 {
-  std::vector<std::string> tokens;
   size_t offset = 0;
+  std::vector<std::string> tokens;
 
   while (maxTokens.isNone() || maxTokens.get() > 0) {
     size_t next = s.find_first_of(delims, offset);
-    if (next == std::string::npos) {
+
+    // Finish splitting if this is the last token,
+    // or we've found enough tokens.
+    if (next == std::string::npos ||
+        (maxTokens.isSome() && tokens.size() == maxTokens.get() - 1)) {
       tokens.push_back(s.substr(offset));
       break;
     }
 
     tokens.push_back(s.substr(offset, next - offset));
     offset = next + 1;
-
-    // Finish splitting if we've found enough tokens.
-    if (maxTokens.isSome() && tokens.size() == maxTokens.get() - 1) {
-      tokens.push_back(s.substr(offset));
-      break;
-    }
   }
 
   return tokens;

http://git-wip-us.apache.org/repos/asf/mesos/blob/9d020470/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
index 8e7d3ee..877dc70 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/strings_tests.cpp
@@ -288,6 +288,14 @@ TEST(StringsTest, SplitNZero)
 }
 
 
+TEST(StringsTest, SplitNOne)
+{
+  vector<string> tokens = strings::split("foo,bar,,,", ",", 1);
+  ASSERT_EQ(1u, tokens.size());
+  EXPECT_EQ("foo,bar,,,", tokens[0]);
+}
+
+
 TEST(StringsTest, SplitNDelimOnlyString)
 {
   vector<string> tokens = strings::split(",,,", ",", 2);


[4/5] mesos git commit: Renamed a parameter on strings::split for readability.

Posted by bm...@apache.org.
Renamed a parameter on strings::split for readability.


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

Branch: refs/heads/master
Commit: e6fdd5de76ffdedf61458868484e82e3994450e3
Parents: 66ddbc7
Author: Benjamin Mahler <be...@gmail.com>
Authored: Thu Feb 11 13:39:52 2016 +0100
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Feb 12 10:33:28 2016 +0100

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e6fdd5de/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
index 1309a18..015eecd 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
@@ -169,12 +169,12 @@ inline std::vector<std::string> tokenize(
 inline std::vector<std::string> split(
     const std::string& s,
     const std::string& delims,
-    const Option<size_t>& n = None())
+    const Option<size_t>& maxTokens = None())
 {
   std::vector<std::string> tokens;
   size_t offset = 0;
 
-  while (n.isNone() || n.get() > 0) {
+  while (maxTokens.isNone() || maxTokens.get() > 0) {
     size_t next = s.find_first_of(delims, offset);
     if (next == std::string::npos) {
       tokens.push_back(s.substr(offset));
@@ -185,11 +185,12 @@ inline std::vector<std::string> split(
     offset = next + 1;
 
     // Finish splitting if we've found enough tokens.
-    if (n.isSome() && tokens.size() == n.get() - 1) {
+    if (maxTokens.isSome() && tokens.size() == maxTokens.get() - 1) {
       tokens.push_back(s.substr(offset));
       break;
     }
   }
+
   return tokens;
 }
 


[5/5] mesos git commit: Fixed help endpoint for endpoint names containing slashes.

Posted by bm...@apache.org.
Fixed help endpoint for endpoint names containing slashes.

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


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

Branch: refs/heads/master
Commit: 59fd7e3ec4837072bfe81fa33843efc35eb8ed10
Parents: 69f31e8
Author: Guangya Liu <gy...@gmail.com>
Authored: Fri Feb 12 10:41:16 2016 +0100
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Feb 12 10:41:16 2016 +0100

----------------------------------------------------------------------
 3rdparty/libprocess/src/help.cpp             | 14 +++++++-------
 3rdparty/libprocess/src/tests/http_tests.cpp | 13 +++++++++++++
 2 files changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/59fd7e3e/3rdparty/libprocess/src/help.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/help.cpp b/3rdparty/libprocess/src/help.cpp
index be3f7b7..bac980d 100644
--- a/3rdparty/libprocess/src/help.cpp
+++ b/3rdparty/libprocess/src/help.cpp
@@ -169,19 +169,19 @@ void json(JSON::ObjectWriter* writer, const Help& help)
 
 Future<http::Response> Help::help(const http::Request& request)
 {
-  // Split the path by '/'.
-  vector<string> tokens = strings::tokenize(request.url.path, "/");
+  // Path format of the url: /help/<id>[/<name>].
+  // Note that <name> may contain slashes.
+  vector<string> tokens = strings::tokenize(request.url.path, "/", 3);
 
   Option<string> id = None();
   Option<string> name = None();
 
-  if (tokens.size() > 3) {
-    return http::BadRequest("Malformed URL, expecting '/help/id/name/'\n");
-  } else if (tokens.size() == 3) {
+  if (tokens.size() > 1) {
     id = tokens[1];
+  }
+
+  if (tokens.size() > 2) {
     name = tokens[2];
-  } else if (tokens.size() > 1) {
-    id = tokens[1];
   }
 
   string document;

http://git-wip-us.apache.org/repos/asf/mesos/blob/59fd7e3e/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 410551c..4337e60 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -236,6 +236,19 @@ TEST(HTTPTest, EndpointsHelp)
   AWAIT_READY(response);
   EXPECT_EQ(http::Status::OK, response->code);
   EXPECT_EQ(http::Status::string(http::Status::OK), response->status);
+
+  // Hit '/help/<id>/a/b/c' and wait for a 200 OK response.
+  url = http::URL(
+      "http",
+      http.process->self().address.ip,
+      http.process->self().address.port,
+      "/help/" + pid.id + "/a/b/c");
+
+  response = http::get(url);
+
+  AWAIT_READY(response);
+  EXPECT_EQ(http::Status::OK, response->code);
+  EXPECT_EQ(http::Status::string(http::Status::OK), response->status);
 }