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 2013/08/06 21:27:08 UTC

[1/2] git commit: Fixed process::collect to preserve ordering of results.

Updated Branches:
  refs/heads/master 733a078ea -> edc436a7c


Fixed process::collect to preserve ordering of results.

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


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

Branch: refs/heads/master
Commit: edc436a7c3be3d44736fdf8475947dac6afd2fa0
Parents: 2eb23c0
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Thu Jul 25 15:00:41 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Tue Aug 6 12:13:07 2013 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/collect.hpp | 19 ++++++++++++-------
 3rdparty/libprocess/src/tests/process_tests.cpp |  7 +++++--
 2 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/edc436a7/3rdparty/libprocess/include/process/collect.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/collect.hpp b/3rdparty/libprocess/include/process/collect.hpp
index 8050351..a08fb20 100644
--- a/3rdparty/libprocess/include/process/collect.hpp
+++ b/3rdparty/libprocess/include/process/collect.hpp
@@ -16,10 +16,10 @@
 
 namespace process {
 
-// Waits on each future in the specified set and returns the set of
-// resulting values. If any future is discarded then the result will
-// be a failure. Likewise, if any future fails than the result future
-// will be a failure.
+// Waits on each future in the specified list and returns the list of
+// resulting values in the same order. If any future is discarded then
+// the result will be a failure. Likewise, if any future fails then
+// the result future will be a failure.
 template <typename T>
 Future<std::list<T> > collect(
     std::list<Future<T> >& futures,
@@ -38,7 +38,8 @@ public:
       Promise<std::list<T> >* _promise)
     : futures(_futures),
       timeout(_timeout),
-      promise(_promise) {}
+      promise(_promise),
+      ready(0) {}
 
   virtual ~CollectProcess()
   {
@@ -92,8 +93,11 @@ private:
       terminate(this);
     } else {
       assert(future.isReady());
-      values.push_back(future.get());
-      if (futures.size() == values.size()) {
+      ready += 1;
+      if (futures.size() == ready) {
+        foreach (const Future<T>& future, futures) {
+          values.push_back(future.get());
+        }
         promise->set(values);
         terminate(this);
       }
@@ -104,6 +108,7 @@ private:
   const Option<Timeout> timeout;
   Promise<std::list<T> >* promise;
   std::list<T> values;
+  size_t ready;
 };
 
 } // namespace internal {

http://git-wip-us.apache.org/repos/asf/mesos/blob/edc436a7/3rdparty/libprocess/src/tests/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/process_tests.cpp b/3rdparty/libprocess/src/tests/process_tests.cpp
index c89d99e..1d49c87 100644
--- a/3rdparty/libprocess/src/tests/process_tests.cpp
+++ b/3rdparty/libprocess/src/tests/process_tests.cpp
@@ -849,10 +849,11 @@ TEST(Process, collect)
   futures.push_back(promise3.future());
   futures.push_back(promise4.future());
 
-  promise1.set(1);
+  // Set them out-of-order.
+  promise4.set(4);
   promise2.set(2);
+  promise1.set(1);
   promise3.set(3);
-  promise4.set(4);
 
   Future<std::list<int> > future = collect(futures);
 
@@ -865,6 +866,8 @@ TEST(Process, collect)
   values.push_back(3);
   values.push_back(4);
 
+  // We expect them to be returned in the same order as the
+  // future list that was passed in.
   EXPECT_EQ(values, future.get());
 }
 


[2/2] git commit: Fixed JSON::Number output precision, and added a test.

Posted by bm...@apache.org.
Fixed JSON::Number output precision, and added a test.

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


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

Branch: refs/heads/master
Commit: 2eb23c01b8d17cb75b4c5512393f66e178306870
Parents: 733a078
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Wed Jul 24 16:03:35 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Tue Aug 6 12:13:07 2013 -0700

----------------------------------------------------------------------
 .../libprocess/3rdparty/stout/include/stout/json.hpp  |  9 ++++++---
 .../3rdparty/stout/include/stout/protobuf.hpp         |  2 ++
 .../libprocess/3rdparty/stout/tests/json_tests.cpp    | 14 ++++++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2eb23c01/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
index e2ef0d3..4406d07 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
@@ -3,6 +3,7 @@
 
 #include <iomanip>
 #include <iostream>
+#include <limits>
 #include <list>
 #include <map>
 #include <string>
@@ -13,7 +14,7 @@
 
 // TODO(jsirois): Implement parsing that constructs JSON objects.
 
-
+// TODO(bmahler): Evaluate picojson / JSON_Spirit.
 namespace JSON {
 
 // Implementation of the JavaScript Object Notation (JSON) grammar
@@ -132,8 +133,10 @@ struct Renderer : boost::static_visitor<>
 
   void operator () (const Number& number) const
   {
-    out.precision(10);
-    out << number.value;
+    // Use the guaranteed accurate precision, see:
+    // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2005.pdf
+    out << std::setprecision(std::numeric_limits<double>::digits10)
+        << number.value;
   }
 
   void operator () (const Object& object) const

http://git-wip-us.apache.org/repos/asf/mesos/blob/2eb23c01/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
index bd5bc73..0355416 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
@@ -162,6 +162,8 @@ namespace JSON {
 
 struct Protobuf
 {
+  // TODO(bmahler): This currently uses the default value for optional
+  // fields but we may want to revisit this decision.
   Protobuf(const google::protobuf::Message& message)
   {
     const google::protobuf::Reflection* reflection = message.GetReflection();

http://git-wip-us.apache.org/repos/asf/mesos/blob/2eb23c01/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
index c582d70..29ada8a 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
@@ -17,3 +17,17 @@ TEST(JsonTest, BinaryData)
   EXPECT_EQ("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007F\\u00FF\"",
             stringify(s));
 }
+
+
+TEST(JsonTest, NumberFormat)
+{
+  // Test whole numbers.
+  EXPECT_EQ("0", stringify(JSON::Number(0.0)));
+  EXPECT_EQ("1", stringify(JSON::Number(1.0)));
+
+  // Negative.
+  EXPECT_EQ("-1", stringify(JSON::Number(-1.0)));
+
+  // Expect at least 15 digits of precision.
+  EXPECT_EQ("1234567890.12345", stringify(JSON::Number(1234567890.12345)));
+}