You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2015/09/15 10:24:45 UTC
[3/4] mesos git commit: Added a test for converting JSON arrays to
Resources.
Added a test for converting JSON arrays to Resources.
Review: https://reviews.apache.org/r/37830
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d4008e1b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d4008e1b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d4008e1b
Branch: refs/heads/master
Commit: d4008e1b24f10112820ad529bf2d752daf40036b
Parents: 6fc4d0f
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Tue Sep 15 03:03:07 2015 -0500
Committer: Michael Park <mp...@apache.org>
Committed: Tue Sep 15 03:24:28 2015 -0500
----------------------------------------------------------------------
src/tests/resources_tests.cpp | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/d4008e1b/src/tests/resources_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index 2ae93a9..0318885 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -24,6 +24,8 @@
#include <stout/bytes.hpp>
#include <stout/gtest.hpp>
+#include <stout/json.hpp>
+#include <stout/protobuf.hpp>
#include "master/master.hpp"
@@ -37,6 +39,8 @@ using std::pair;
using std::set;
using std::string;
+using google::protobuf::RepeatedPtrField;
+
namespace mesos {
namespace internal {
namespace tests {
@@ -142,6 +146,26 @@ TEST(ResourcesTest, ParseError)
}
+TEST(ResourcesTest, ParsingFromJSON)
+{
+ Resources resources = Resources::parse("cpus:2;mem:3").get();
+
+ // Convert to an array of JSON objects.
+ JSON::Array array;
+ foreach (const Resource& resource, resources) {
+ JSON::Object object = JSON::Protobuf(resource);
+ array.values.push_back(object);
+ }
+
+ // Parse JSON array into a collection of Resource messages and convert them
+ // into Resources object.
+ auto parse = ::protobuf::parse<RepeatedPtrField<Resource>>(array);
+ ASSERT_SOME(parse);
+
+ EXPECT_EQ(resources, Resources(parse.get()));
+}
+
+
TEST(ResourcesTest, Resources)
{
Resources r = Resources::parse(