You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2016/10/29 02:50:48 UTC
[1/2] mesos git commit: Updated UUID::fromString to not throw an
exception on error.
Repository: mesos
Updated Branches:
refs/heads/1.0.x 162f31bb5 -> 9e0f9505b
Updated UUID::fromString to not throw an exception on error.
The exception from the string_generator needs to be caught so
that we can surface a Try to the caller.
Review: https://reviews.apache.org/r/52098
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4e4d058e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4e4d058e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4e4d058e
Branch: refs/heads/1.0.x
Commit: 4e4d058ea3c012b2e6d4bbed58ef7fbaea5b60fb
Parents: 162f31b
Author: Benjamin Mahler <bm...@apache.org>
Authored: Tue Sep 20 14:14:39 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Fri Oct 28 19:27:53 2016 -0700
----------------------------------------------------------------------
3rdparty/stout/include/stout/uuid.hpp | 17 ++++++++++++-----
3rdparty/stout/tests/uuid_tests.cpp | 8 +++++---
2 files changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4e4d058e/3rdparty/stout/include/stout/uuid.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/uuid.hpp b/3rdparty/stout/include/stout/uuid.hpp
index a57896c..c3932e2 100644
--- a/3rdparty/stout/include/stout/uuid.hpp
+++ b/3rdparty/stout/include/stout/uuid.hpp
@@ -16,6 +16,7 @@
#include <assert.h>
#include <sstream>
+#include <stdexcept>
#include <string>
#include <boost/uuid/uuid.hpp>
@@ -69,12 +70,18 @@ public:
return UUID(uuid);
}
- static UUID fromString(const std::string& s)
+ static Try<UUID> fromString(const std::string& s)
{
- boost::uuids::uuid uuid;
- std::istringstream in(s);
- in >> uuid;
- return UUID(uuid);
+ try {
+ // NOTE: We don't use THREAD_LOCAL for the `string_generator`
+ // (unlike for the `random_generator` above), because it is cheap
+ // to construct one each time.
+ boost::uuids::string_generator gen;
+ boost::uuids::uuid uuid = gen(s);
+ return UUID(uuid);
+ } catch (const std::runtime_error& e) {
+ return Error(e.what());
+ }
}
std::string toBytes() const
http://git-wip-us.apache.org/repos/asf/mesos/blob/4e4d058e/3rdparty/stout/tests/uuid_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/uuid_tests.cpp b/3rdparty/stout/tests/uuid_tests.cpp
index b061b82..ce25faa 100644
--- a/3rdparty/stout/tests/uuid_tests.cpp
+++ b/3rdparty/stout/tests/uuid_tests.cpp
@@ -45,9 +45,9 @@ TEST(UUIDTest, Test)
string string2 = uuid2.toString();
string string3 = uuid3.toString();
- EXPECT_EQ(string1, string2);
- EXPECT_EQ(string2, string3);
- EXPECT_EQ(string1, string3);
+ EXPECT_SOME_EQ(uuid1, UUID::fromString(string1));
+ EXPECT_SOME_EQ(uuid2, UUID::fromString(string2));
+ EXPECT_SOME_EQ(uuid3, UUID::fromString(string3));
}
@@ -56,4 +56,6 @@ TEST(UUIDTest, MalformedUUID)
EXPECT_SOME(UUID::fromBytes(UUID::random().toBytes()));
EXPECT_ERROR(UUID::fromBytes("malformed-uuid"));
EXPECT_ERROR(UUID::fromBytes("invalidstringmsg"));
+
+ EXPECT_ERROR(UUID::fromString("malformed-uuid"));
}
[2/2] mesos git commit: Updated scheduler library to handle UUID
parsing error.
Posted by an...@apache.org.
Updated scheduler library to handle UUID parsing error.
Previously this would have thrown an exception.
Review: https://reviews.apache.org/r/52099
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9e0f9505
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9e0f9505
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9e0f9505
Branch: refs/heads/1.0.x
Commit: 9e0f9505bae40a5f803d9a3eebfebe62287fbe91
Parents: 4e4d058
Author: Benjamin Mahler <bm...@apache.org>
Authored: Tue Sep 20 14:17:30 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Fri Oct 28 19:30:20 2016 -0700
----------------------------------------------------------------------
src/scheduler/scheduler.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9e0f9505/src/scheduler/scheduler.cpp
----------------------------------------------------------------------
diff --git a/src/scheduler/scheduler.cpp b/src/scheduler/scheduler.cpp
index 276ed10..d807540 100644
--- a/src/scheduler/scheduler.cpp
+++ b/src/scheduler/scheduler.cpp
@@ -548,7 +548,12 @@ protected:
// Responses to SUBSCRIBE calls should always include a stream ID.
CHECK(response->headers.contains("Mesos-Stream-Id"));
- streamId = UUID::fromString(response->headers.at("Mesos-Stream-Id"));
+ Try<UUID> uuid =
+ UUID::fromString(response->headers.at("Mesos-Stream-Id"));
+
+ CHECK_SOME(uuid);
+
+ streamId = uuid.get();
read();