You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2014/10/21 01:53:42 UTC
git commit: Created a Result(Try&) constructor for Result.
Repository: mesos
Updated Branches:
refs/heads/master 64862a70c -> acb94b203
Created a Result(Try&) constructor for Result<T>.
Try<T> doesn't have a default constructor and so it's not possible to
have a Try<T> class member variable unless we initialize it with
Error().
With this patch, we can instead have a Result<T> class member variable
which is initialized to None() and can be assigned a Try<T> type.
Review: https://reviews.apache.org/r/26955
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/acb94b20
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/acb94b20
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/acb94b20
Branch: refs/heads/master
Commit: acb94b203581f1c0e1adcac7b5dc39d6eb880586
Parents: 64862a7
Author: Kapil Arya <ka...@mesosphere.io>
Authored: Mon Oct 20 16:32:46 2014 -0700
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Mon Oct 20 16:32:46 2014 -0700
----------------------------------------------------------------------
3rdparty/libprocess/3rdparty/Makefile.am | 1 +
3rdparty/libprocess/3rdparty/stout/Makefile.am | 1 +
.../3rdparty/stout/include/stout/result.hpp | 14 +++---
.../3rdparty/stout/tests/result_tests.cpp | 47 ++++++++++++++++++++
4 files changed, 58 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/acb94b20/3rdparty/libprocess/3rdparty/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/Makefile.am b/3rdparty/libprocess/3rdparty/Makefile.am
index 256df0b..895ac6b 100644
--- a/3rdparty/libprocess/3rdparty/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/Makefile.am
@@ -167,6 +167,7 @@ stout_tests_SOURCES = \
$(STOUT)/tests/protobuf_tests.pb.cc \
$(STOUT)/tests/protobuf_tests.pb.h \
$(STOUT)/tests/protobuf_tests.proto \
+ $(STOUT)/tests/result_tests.cpp \
$(STOUT)/tests/os/sendfile_tests.cpp \
$(STOUT)/tests/os/signals_tests.cpp \
$(STOUT)/tests/set_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/acb94b20/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index 125b3fa..16cab5a 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -39,6 +39,7 @@ EXTRA_DIST = \
tests/protobuf_tests.pb.cc \
tests/protobuf_tests.pb.h \
tests/protobuf_tests.proto \
+ tests/result_tests.cpp \
tests/set_tests.cpp \
tests/some_tests.cpp \
tests/strings_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/acb94b20/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp
index 631f126..96b0f36 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp
@@ -24,6 +24,7 @@
#include <stout/none.hpp>
#include <stout/option.hpp>
#include <stout/some.hpp>
+#include <stout/try.hpp>
template <typename T>
class Result
@@ -69,11 +70,14 @@ public:
: state(ERROR), t(NULL), message(error.message) {}
Result(const Result<T>& that)
- {
- state = that.state;
- t = (that.t == NULL ? NULL : new T(*that.t));
- message = that.message;
- }
+ : state(that.state),
+ t(that.t == NULL ? NULL : new T(*that.t)),
+ message(that.message) {}
+
+ Result(const Try<T>& _try)
+ : state(_try.isSome() ? SOME : ERROR),
+ t(_try.isSome() ? new T(_try.get()) : NULL),
+ message(_try.isSome() ? "" : _try.error()) {}
~Result()
{
http://git-wip-us.apache.org/repos/asf/mesos/blob/acb94b20/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp
new file mode 100644
index 0000000..0a38106
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp
@@ -0,0 +1,47 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gmock/gmock.h>
+
+#include <stout/error.hpp>
+#include <stout/gtest.hpp>
+#include <stout/result.hpp>
+#include <stout/try.hpp>
+
+// Verify Try to Result conversion.
+TEST(ResultTest, TryToResultConversion)
+{
+ // Test with implicit Result(Try&) contructor.
+ Try<int> foo = 5;
+ Result<int> bar = foo;
+ EXPECT_SOME(bar);
+ EXPECT_EQ(bar.get(), foo.get());
+
+ // Test with explicit constructor.
+ Result<int> result = None();
+ result = Result<int>(foo);
+ EXPECT_SOME(result);
+ EXPECT_EQ(result.get(), foo.get());
+
+ // Test Try with error state.
+ Try<int> tryError(Error("Invalid Try"));
+ Result<int> resultError = tryError;
+ EXPECT_ERROR(resultError);
+ EXPECT_EQ(tryError.error(), resultError.error());
+
+ // Test Try with error state with explicit constructor.
+ result = Result<int>(tryError);
+ EXPECT_ERROR(result);
+ EXPECT_EQ(result.error(), tryError.error());
+}