You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2014/11/19 09:54:09 UTC

[4/9] mesos git commit: A few style fixes for C++ Resources and tests.

A few style fixes for C++ Resources and tests.

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


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

Branch: refs/heads/master
Commit: 05b5ffa43c7e6b5178c1946162cd10d5984acfbe
Parents: bdf2d9d
Author: Jie Yu <yu...@gmail.com>
Authored: Fri Nov 14 11:46:15 2014 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Nov 19 00:14:25 2014 -0800

----------------------------------------------------------------------
 include/mesos/resources.hpp   | 128 +++++++++++++-----------------
 src/common/resources.cpp      |  84 ++++++++++++--------
 src/tests/resources_tests.cpp | 154 ++++++++++++++++++++++---------------
 3 files changed, 194 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/05b5ffa4/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index c2ba597..4ed8cee 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -30,27 +30,16 @@
 #include <stout/try.hpp>
 
 
-/**
- * Resources come in three types: scalar, ranges, and sets. These are
- * represented using protocol buffers. To make manipulation of
- * resources easier within the Mesos core and for scheduler writers,
- * we provide generic overloaded opertors (see below) as well as a
- * general Resources class that encapsulates a collection of protocol
- * buffer Resource objects. The Resources class also provides a few
- * static routines to allow parsing resources (e.g., from the command
- * line), as well as determining whether or not a Resource object is
- * valid or allocatable. Note that many of these operations have not
- * been optimized but instead just written for correct semantics.
- *
- * Note! A resource is described by a tuple (name, type, role). Doing
- * "arithmetic" operations (those defined below) on two resources of
- * the same name but different type, or the same name and type but
- * different roles, doesn't make sense, so it's semantics are as
- * though the second operand was actually just an empty resource
- * (as though you didn't do the operation at all). In addition,
- * doing operations on two resources of the same type but different
- * names is a no-op.
- */
+// Resources come in three types: scalar, ranges, and sets. These are
+// represented using protocol buffers. To make manipulation of
+// resources easier within the Mesos core and for scheduler writers,
+// we provide generic overloaded operators (see below) as well as a
+// general Resources class that encapsulates a collection of protocol
+// buffer Resource objects. The Resources class also provides a few
+// static routines to allow parsing resources (e.g., from the command
+// line), as well as determining whether or not a Resource object is
+// valid. Note that many of these operations have not been optimized
+// but instead just written for correct semantics.
 
 namespace mesos {
 
@@ -76,40 +65,35 @@ bool matches(const Resource& left, const Resource& right);
 class Resources
 {
 public:
-  /**
-   * Parses the value and returns a Resource with the given name and role.
-   */
+  // Parses the text and returns a Resource object with the given name
+  // and role. For example, "Resource r = parse("mem", "1024", "*");".
   static Try<Resource> parse(
       const std::string& name,
       const std::string& value,
       const std::string& role);
 
-  /**
-   * Parses resources in the form "name:value (role);name:value...".
-   * Any name/value pair that doesn't specify a role is assigned to defaultRole.
-   */
+  // Parses Resources from text in the form "name:value(role);
+  // name:value;...". Any name/value pair that doesn't specify a role
+  // is assigned to defaultRole.
   static Try<Resources> parse(
-      const std::string& s,
+      const std::string& text,
       const std::string& defaultRole = "*");
 
-  /**
-   * Returns true iff this resource has a name, a valid type, i.e. scalar,
-   * range, or set, and has the appropriate value set for its type.
-   */
+  // Returns true iff this resource has a name, a valid type, i.e.
+  // scalar, range, or set, and has the appropriate value set for its
+  // type.
   static bool isValid(const Resource& resource);
 
-  /**
-   * Returns true iff this resource is valid and allocatable. In particular,
-   * a scalar is allocatable if it's value is greater than zero, a ranges
-   * is allocatable if there is at least one valid range in it, and a set
-   * is allocatable if it has at least one item.
-   */
+  // Returns true iff this resource is valid and allocatable. In
+  // particular, a scalar is allocatable if it's value is greater than
+  // zero, a ranges is allocatable if there is at least one valid
+  // range in it, and a set is allocatable if it has at least one
+  // item.
   static bool isAllocatable(const Resource& resource);
 
-  /**
-   * Returns true iff this resource is zero valued, i.e. is zero for scalars,
-   * has a range size of zero for ranges, and has no items for sets.
-   */
+  // Returns true iff this resource is zero valued, i.e. is zero for
+  // scalars, has a range size of zero for ranges, and has no items
+  // for sets.
   static bool isZero(const Resource& resource);
 
   Resources() {}
@@ -140,51 +124,40 @@ public:
     return resources.size();
   }
 
-  /**
-   * Returns all resources in this object that are marked with the
-   * specified role.
-   */
+  // Returns all resources in this object that are marked with the
+  // specified role.
   Resources extract(const std::string& role) const;
 
-  /**
-   * Returns a Resources object with the same amount of each resource
-   * type as these Resources, but with only one Resource object per
-   * type and all Resource object marked as the specified role.
-   */
+  // Returns a Resources object with the same amount of each resource
+  // type as these Resources, but with only one Resource object per
+  // type and all Resource object marked as the specified role.
   Resources flatten(const std::string& role = "*") const;
 
-  /**
-   * Finds a number of resources equal to toFind in these Resources
-   * and returns them marked with appropriate roles. For each resource
-   * type, resources are first taken from the specified role, then
-   * from '*', then from any other role.
-   */
+  // Finds a number of resources equal to toFind in these Resources
+  // and returns them marked with appropriate roles. For each resource
+  // type, resources are first taken from the specified role, then
+  // from '*', then from any other role.
   Option<Resources> find(
       const Resources& toFind,
       const std::string& role = "*") const;
 
-  /**
-   * Returns the Resource from these Resources that matches the argument
-   * in name, type, and role, if it exists.
-   */
+  // Returns the Resource from these Resources that matches the
+  // argument in name, type, and role, if it exists.
   Option<Resource> get(const Resource& r) const;
 
-  /**
-   * Returns all Resources from these Resources that match the argument
-   * in name and type, regardless of role.
-   */
+  // Returns all Resources from these Resources that match the
+  // argument in name and type, regardless of role.
   Option<Resources> getAll(const Resource& r) const;
 
   template <typename T>
   T get(const std::string& name, const T& t) const;
 
-  /**
-   * Returns a Resources object with only the allocatable resources.
-   */
+  // Returns a Resources object with only the allocatable resources.
   Resources allocatable() const;
 
   // Helpers to get known resource types.
-  // TODO(vinod): Fix this when we make these types as first class protobufs.
+  // TODO(vinod): Fix this when we make these types as first class
+  // protobufs.
   Option<double> cpus() const;
   Option<Bytes> mem() const;
   Option<Bytes> disk() const;
@@ -192,8 +165,8 @@ public:
   // TODO(vinod): Provide a Ranges abstraction.
   Option<Value::Ranges> ports() const;
 
-  // Helper function to extract the given number of ports
-  // from the "ports" resource.
+  // Helper function to extract the given number of ports from the
+  // "ports" resource.
   Option<Value::Ranges> ports(size_t numPorts) const;
 
   // TODO(jieyu): Consider returning an EphemeralPorts abstraction
@@ -212,10 +185,8 @@ public:
   const_iterator begin() const { return resources.begin(); }
   const_iterator end() const { return resources.end(); }
 
-  /**
-   * Using this operator makes it easy to copy a resources object into
-   * a protocol buffer field.
-   */
+  // Using this operator makes it easy to copy a resources object into
+  // a protocol buffer field.
   operator const google::protobuf::RepeatedPtrField<Resource>& () const;
 
   bool operator == (const Resources& that) const;
@@ -223,6 +194,11 @@ public:
 
   bool operator <= (const Resources& that) const;
 
+  // NOTE: If any error occurs (e.g., input Resource is not valid or
+  // the first operand is not a superset of the second oprand while
+  // doing subtraction), the semantics is as though the second operand
+  // was actually just an empty resource (as though you didn't do the
+  // operation at all).
   Resources operator + (const Resource& that) const;
   Resources operator + (const Resources& that) const;
   Resources& operator += (const Resource& that);

http://git-wip-us.apache.org/repos/asf/mesos/blob/05b5ffa4/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 1ffebbb..810b698 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -157,50 +157,55 @@ bool matches(const Resource& left, const Resource& right)
 }
 
 
+/////////////////////////////////////////////////
+// Public static functions.
+/////////////////////////////////////////////////
+
+
 Try<Resource> Resources::parse(
     const string& name,
-    const string& text,
+    const string& value,
     const string& role)
 {
+  Try<Value> result = internal::values::parse(value);
+  if (result.isError()) {
+    return Error(
+        "Failed to parse resource " + name +
+        " value " + value + " error " + result.error());
+  }
+
   Resource resource;
-  Try<Value> result = internal::values::parse(text);
 
-  if (result.isError()) {
-    return Error("Failed to parse resource " + name +
-                 " text " + text +
-                 " error " + result.error());
-  } else{
-    Value value = result.get();
-    resource.set_name(name);
-    resource.set_role(role);
-
-    if (value.type() == Value::RANGES) {
-      resource.set_type(Value::RANGES);
-      resource.mutable_ranges()->MergeFrom(value.ranges());
-    } else if (value.type() == Value::SET) {
-      resource.set_type(Value::SET);
-      resource.mutable_set()->MergeFrom(value.set());
-    } else if (value.type() == Value::SCALAR) {
-      resource.set_type(Value::SCALAR);
-      resource.mutable_scalar()->MergeFrom(value.scalar());
-    } else {
-      return Error("Bad type for resource " + name +
-                   " text " + text +
-                   " type " + Value::Type_Name(value.type()));
-    }
+  Value _value = result.get();
+  resource.set_name(name);
+  resource.set_role(role);
+
+  if (_value.type() == Value::SCALAR) {
+    resource.set_type(Value::SCALAR);
+    resource.mutable_scalar()->CopyFrom(_value.scalar());
+  } else if (_value.type() == Value::RANGES) {
+    resource.set_type(Value::RANGES);
+    resource.mutable_ranges()->CopyFrom(_value.ranges());
+  } else if (_value.type() == Value::SET) {
+    resource.set_type(Value::SET);
+    resource.mutable_set()->CopyFrom(_value.set());
+  } else {
+    return Error(
+        "Bad type for resource " + name + " value " + value +
+        " type " + Value::Type_Name(_value.type()));
   }
 
   return resource;
 }
 
 
-Try<Resources> Resources::parse(const string& s, const string& defaultRole)
+Try<Resources> Resources::parse(
+    const string& text,
+    const string& defaultRole)
 {
   Resources resources;
 
-  vector<string> tokens = strings::tokenize(s, ";");
-
-  foreach (const string& token, tokens) {
+  foreach (const string& token, strings::tokenize(text, ";")) {
     vector<string> pair = strings::tokenize(token, ":");
     if (pair.size() != 2) {
       return Error("Bad value for resources, missing or extra ':' in " + token);
@@ -215,19 +220,22 @@ Try<Resources> Resources::parse(const string& s, const string& defaultRole)
     } else {
       size_t closeParen = pair[0].find(")");
       if (closeParen == string::npos || closeParen < openParen) {
-        return Error("Bad value for resources, mismatched parentheses in " +
-                     token);
+        return Error(
+            "Bad value for resources, mismatched parentheses in " + token);
       }
 
       name = strings::trim(pair[0].substr(0, openParen));
-      role = strings::trim(pair[0].substr(openParen + 1,
-                                          closeParen - openParen - 1));
+
+      role = strings::trim(pair[0].substr(
+          openParen + 1,
+          closeParen - openParen - 1));
     }
 
     Try<Resource> resource = Resources::parse(name, pair[1], role);
     if (resource.isError()) {
       return Error(resource.error());
     }
+
     resources += resource.get();
   }
 
@@ -325,6 +333,11 @@ bool Resources::isZero(const Resource& resource)
 }
 
 
+/////////////////////////////////////////////////
+// Public member functions.
+/////////////////////////////////////////////////
+
+
 Resources Resources::extract(const string& role) const
 {
   Resources r;
@@ -668,6 +681,11 @@ Option<Value::Ranges> Resources::ephemeral_ports() const
 }
 
 
+/////////////////////////////////////////////////
+// Overloaded operators.
+/////////////////////////////////////////////////
+
+
 Resources::operator const google::protobuf::RepeatedPtrField<Resource>& () const
 {
   return resources;

http://git-wip-us.apache.org/repos/asf/mesos/blob/05b5ffa4/src/tests/resources_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index 3e50889..9fe3c3a 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -38,24 +38,24 @@ using std::string;
 TEST(ResourcesTest, Parsing)
 {
   Resource cpus = Resources::parse("cpus", "45.55", "*").get();
+
   ASSERT_EQ(Value::SCALAR, cpus.type());
   EXPECT_EQ(45.55, cpus.scalar().value());
 
-  Resource ports = Resources::parse("ports",
-                                    "[10000-20000, 30000-50000]",
-                                    "*").get();
+  Resource ports = Resources::parse(
+      "ports", "[10000-20000, 30000-50000]", "*").get();
 
   ASSERT_EQ(Value::RANGES, ports.type());
   EXPECT_EQ(2, ports.ranges().range_size());
 
   Resource disks = Resources::parse("disks", "{sda1}", "*").get();
+
   ASSERT_EQ(Value::SET, disks.type());
   ASSERT_EQ(1, disks.set().item_size());
   EXPECT_EQ("sda1", disks.set().item(0));
 
-  Resources r1 = Resources::parse("cpus:45.55;"
-                                  "ports:[10000-20000, 30000-50000];"
-                                  "disks:{sda1}").get();
+  Resources r1 = Resources::parse(
+      "cpus:45.55;ports:[10000-20000, 30000-50000];disks:{sda1}").get();
 
   Resources r2;
   r2 += cpus;
@@ -87,11 +87,10 @@ TEST(ResourcesTest, ParsingWithRoles)
   resources1 += mem;
 
   EXPECT_EQ(parse1, resources1);
-
   EXPECT_EQ(resources1, Resources::parse(stringify(resources1)).get());
 
-  Resources parse2 =
-    Resources::parse("cpus(role1):2.5;ports(role2):[0-100]").get();
+  Resources parse2 = Resources::parse(
+      "cpus(role1):2.5;ports(role2):[0-100]").get();
 
   Resource cpus2;
   cpus2.set_name("cpus");
@@ -112,11 +111,10 @@ TEST(ResourcesTest, ParsingWithRoles)
   resources2 += cpus2;
 
   EXPECT_EQ(parse2, resources2);
-
   EXPECT_EQ(resources2, Resources::parse(stringify(resources2)).get());
 
-  Resources parse3 =
-    Resources::parse("cpus:2.5;ports(role2):[0-100]", "role1").get();
+  Resources parse3 = Resources::parse(
+      "cpus:2.5;ports(role2):[0-100]", "role1").get();
 
   EXPECT_EQ(parse2, parse3);
 }
@@ -129,29 +127,28 @@ TEST(ResourcesTest, ParseError)
 
   // Mismatched parentheses.
   EXPECT_ERROR(Resources::parse("cpus(role1:1"));
-
   EXPECT_ERROR(Resources::parse("cpus)(role1:1"));
 }
 
 
 TEST(ResourcesTest, Resources)
 {
-  Resources r = Resources::parse("cpus:45.55;"
-                                 "mem:1024;"
-                                 "ports:[10000-20000, 30000-50000];"
-                                 "disk:512").get();
+  Resources r = Resources::parse(
+      "cpus:45.55;mem:1024;ports:[10000-20000, 30000-50000];disk:512").get();
 
   EXPECT_SOME_EQ(45.55, r.cpus());
   EXPECT_SOME_EQ(Megabytes(1024), r.mem());
   EXPECT_SOME_EQ(Megabytes(512), r.disk());
 
-  EXPECT_SOME(r.ports());
+  ASSERT_SOME(r.ports());
+
   ostringstream ports;
   ports << r.ports().get();
 
   EXPECT_EQ("[10000-20000, 30000-50000]", ports.str());
 
   r = Resources::parse("cpus:45.55;disk:512").get();
+
   EXPECT_SOME_EQ(45.55, r.cpus());
   EXPECT_SOME_EQ(Megabytes(512), r.disk());
   EXPECT_TRUE(r.mem().isNone());
@@ -189,9 +186,8 @@ TEST(ResourcesTest, Ports)
 
 TEST(ResourcesTest, Printing)
 {
-  Resources r = Resources::parse("cpus:45.55;"
-                                 "ports:[10000-20000, 30000-50000];"
-                                 "disks:{sda1}").get();
+  Resources r = Resources::parse(
+      "cpus:45.55;ports:[10000-20000, 30000-50000];disks:{sda1}").get();
 
   string output =
     "cpus(*):45.55; ports(*):[10000-20000, 30000-50000]; disks(*):{sda1}";
@@ -220,12 +216,17 @@ TEST(ResourcesTest, BadResourcesNotAllocatable)
   Resource cpus;
   cpus.set_type(Value::SCALAR);
   cpus.mutable_scalar()->set_value(1);
+
   Resources r;
   r += cpus;
+
   EXPECT_EQ(0u, r.allocatable().size());
+
   cpus.set_name("cpus");
   cpus.mutable_scalar()->set_value(0);
+
   r += cpus;
+
   EXPECT_EQ(0u, r.allocatable().size());
 }
 
@@ -249,6 +250,7 @@ TEST(ResourcesTest, ScalarEquals)
 
   Resource cpus1 = Resources::parse("cpus", "3", "role1").get();
   Resource cpus2 = Resources::parse("cpus", "3", "role2").get();
+
   EXPECT_NE(cpus1, cpus2);
 }
 
@@ -317,12 +319,14 @@ TEST(ResourcesTest, ScalarAddition)
   r2 += mem2;
 
   Resources sum = r1 + r2;
+
   EXPECT_EQ(2u, sum.size());
   EXPECT_EQ(3, sum.get("cpus", Value::Scalar()).value());
   EXPECT_EQ(15, sum.get("mem", Value::Scalar()).value());
 
   Resources r = r1;
   r += r2;
+
   EXPECT_EQ(2u, r.size());
   EXPECT_EQ(3, r.get("cpus", Value::Scalar()).value());
   EXPECT_EQ(15, r.get("mem", Value::Scalar()).value());
@@ -343,6 +347,7 @@ TEST(ResourcesTest, ScalarAddition2)
   r2 += cpus3;
 
   Resources sum = r1 + r2;
+
   EXPECT_EQ(2u, sum.size());
   EXPECT_EQ(9, sum.cpus().get());
   EXPECT_EQ(sum, Resources::parse("cpus(role1):6;cpus(role2):3").get());
@@ -366,12 +371,14 @@ TEST(ResourcesTest, ScalarSubtraction)
   r2 += mem2;
 
   Resources diff = r1 - r2;
+
   EXPECT_EQ(2u, diff.size());
   EXPECT_EQ(49.5, diff.get("cpus", Value::Scalar()).value());
   EXPECT_EQ(3072, diff.get("mem", Value::Scalar()).value());
 
   Resources r = r1;
   r -= r2;
+
   EXPECT_EQ(49.5, diff.get("cpus", Value::Scalar()).value());
   EXPECT_EQ(3072, diff.get("mem", Value::Scalar()).value());
 
@@ -395,6 +402,7 @@ TEST(ResourcesTest, ScalarSubtraction2)
   r2 += cpus3;
 
   Resources diff = r1 - r2;
+
   EXPECT_EQ(2u, diff.size());
   EXPECT_EQ(7, diff.cpus().get());
   EXPECT_EQ(diff, Resources::parse("cpus(role1):4;cpus(role2):3").get());
@@ -403,9 +411,11 @@ TEST(ResourcesTest, ScalarSubtraction2)
 
 TEST(ResourcesTest, RangesEquals)
 {
-  Resource ports1 = Resources::parse("ports", "[20-40]", "*").get();
-  Resource ports2 =
-    Resources::parse("ports", "[20-30, 31-39, 40-40]", "*").get();
+  Resource ports1 = Resources::parse(
+      "ports", "[20-40]", "*").get();
+
+  Resource ports2 = Resources::parse(
+      "ports", "[20-30, 31-39, 40-40]", "*").get();
 
   Resources r1;
   r1 += ports1;
@@ -461,10 +471,11 @@ TEST(ResourcesTest, RangesSubset)
 
 TEST(ResourcesTest, RangesAddition)
 {
-  Resource ports1 =
-    Resources::parse("ports", "[20000-40000, 21000-38000]", "*").get();
-  Resource ports2 =
-    Resources::parse("ports", "[30000-50000, 10000-20000]", "*").get();
+  Resource ports1 = Resources::parse(
+      "ports", "[20000-40000, 21000-38000]", "*").get();
+
+  Resource ports2 = Resources::parse(
+      "ports", "[30000-50000, 10000-20000]", "*").get();
 
   Resources r;
   r += ports1;
@@ -534,9 +545,11 @@ TEST(ResourcesTest, RangesAdditon3)
 
 TEST(ResourcesTest, RangesAddition4)
 {
-  Resource ports1 =
-    Resources::parse("ports", "[1-4, 9-10, 20-22, 26-30]", "*").get();
-  Resource ports2 = Resources::parse("ports", "[5-8, 23-25]", "*").get();
+  Resource ports1 = Resources::parse(
+      "ports", "[1-4, 9-10, 20-22, 26-30]", "*").get();
+
+  Resource ports2 = Resources::parse(
+      "ports", "[5-8, 23-25]", "*").get();
 
   Resources r;
   r += ports1;
@@ -552,9 +565,11 @@ TEST(ResourcesTest, RangesAddition4)
 
 TEST(ResourcesTest, RangesSubtraction)
 {
-  Resource ports1 = Resources::parse("ports", "[20000-40000]", "*").get();
-  Resource ports2 =
-    Resources::parse("ports", "[10000-20000, 30000-50000]", "*").get();
+  Resource ports1 = Resources::parse(
+      "ports", "[20000-40000]", "*").get();
+
+  Resource ports2 = Resources::parse(
+      "ports", "[10000-20000, 30000-50000]", "*").get();
 
   Resources r;
   r += ports1;
@@ -610,7 +625,6 @@ TEST(ResourcesTest, RangesSubtraction3)
   Resources resourcesInUse = Resources::parse("ports:[50000-50001]").get();
 
   Resources resourcesFree = resources - (resourcesOffered + resourcesInUse);
-
   resourcesFree = resourcesFree.allocatable();
 
   EXPECT_EQ(1u, resourcesFree.size());
@@ -626,9 +640,7 @@ TEST(ResourcesTest, RangesSubtraction4)
   Resources resources = Resources::parse("ports:[50000-60000]").get();
 
   Resources resourcesOffered;
-
   resourcesOffered += resources;
-
   resourcesOffered -= resources;
 
   EXPECT_EQ(0u, resourcesOffered.size());
@@ -641,9 +653,11 @@ TEST(ResourcesTest, RangesSubtraction4)
 
 TEST(ResourcesTest, RangesSubtraction5)
 {
-  Resource ports1 =
-    Resources::parse("ports", "[1-10, 20-30, 40-50]", "*").get();
-  Resource ports2 = Resources::parse("ports", "[2-9, 15-45, 48-50]", "*").get();
+  Resource ports1 = Resources::parse(
+      "ports", "[1-10, 20-30, 40-50]", "*").get();
+
+  Resource ports2 = Resources::parse(
+      "ports", "[2-9, 15-45, 48-50]", "*").get();
 
   Resources r;
   r += ports1;
@@ -690,9 +704,11 @@ TEST(ResourcesTest, SetEquals)
 
 TEST(ResourcesTest, SetSubset)
 {
-  Resource disks1 = Resources::parse("disks", "{sda1,sda2}", "*").get();
-  Resource disks2 =
-    Resources::parse("disks", "{sda1,sda3,sda4,sda2}", "*").get();
+  Resource disks1 = Resources::parse(
+      "disks", "{sda1,sda2}", "*").get();
+
+  Resource disks2 = Resources::parse(
+      "disks", "{sda1,sda3,sda4,sda2}", "*").get();
 
   Resources r1;
   r1 += disks1;
@@ -709,9 +725,11 @@ TEST(ResourcesTest, SetSubset)
 
 TEST(ResourcesTest, SetAddition)
 {
-  Resource disks1 = Resources::parse("disks", "{sda1,sda2,sda3}", "*").get();
-  Resource disks2 =
-    Resources::parse("disks", "{sda1,sda2,sda3,sda4}", "*").get();
+  Resource disks1 = Resources::parse(
+      "disks", "{sda1,sda2,sda3}", "*").get();
+
+  Resource disks2 = Resources::parse(
+      "disks", "{sda1,sda2,sda3,sda4}", "*").get();
 
   Resources r;
   r += disks1;
@@ -727,9 +745,11 @@ TEST(ResourcesTest, SetAddition)
 
 TEST(ResourcesTest, SetSubtraction)
 {
-  Resource disks1 =
-    Resources::parse("disks", "{sda1,sda2,sda3,sda4}", "*").get();
-  Resource disks2 = Resources::parse("disks", "{sda2,sda3,sda4}", "*").get();
+  Resource disks1 = Resources::parse(
+      "disks", "{sda1,sda2,sda3,sda4}", "*").get();
+
+  Resource disks2 = Resources::parse(
+      "disks", "{sda2,sda3,sda4}", "*").get();
 
   Resources r;
   r += disks1;
@@ -770,33 +790,41 @@ TEST(ResourcesTest, FlattenRoles)
 
 TEST(ResourcesTest, Find)
 {
-  Resources resources1 =
-    Resources::parse("cpus(role1):2;mem(role1):10;cpus:4;mem:20").get();
+  Resources resources1 = Resources::parse(
+      "cpus(role1):2;mem(role1):10;cpus:4;mem:20").get();
+
   Resources toFind1 = Resources::parse("cpus:3;mem:15").get();
 
   Resources found1 = resources1.find(toFind1, "role1").get();
-  Resources expected1 =
-    Resources::parse("cpus(role1):2;mem(role1):10;cpus:1;mem:5").get();
+
+  Resources expected1 = Resources::parse(
+      "cpus(role1):2;mem(role1):10;cpus:1;mem:5").get();
+
   EXPECT_EQ(found1, expected1);
 
-  Resources resources2 =
-    Resources::parse("cpus(role1):1;mem(role1):5;cpus(role2):2;"
-                     "mem(role2):8;cpus:1;mem:7").get();
+  Resources resources2 = Resources::parse(
+      "cpus(role1):1;mem(role1):5;cpus(role2):2;"
+      "mem(role2):8;cpus:1;mem:7").get();
+
   Resources toFind2 = Resources::parse("cpus:3;mem:15").get();
 
   Resources found2 = resources2.find(toFind2, "role1").get();
-  Resources expected2 =
-    Resources::parse("cpus(role1):1;mem(role1):5;cpus:1;mem:7;"
-                     "cpus(role2):1;mem(role2):3").get();
+
+  Resources expected2 = Resources::parse(
+      "cpus(role1):1;mem(role1):5;cpus:1;mem:7;"
+      "cpus(role2):1;mem(role2):3").get();
+
   EXPECT_EQ(found2, expected2);
 
-  Resources resources3 =
-    Resources::parse("cpus(role1):5;mem(role1):5;cpus:5;mem:5").get();
+  Resources resources3 = Resources::parse(
+      "cpus(role1):5;mem(role1):5;cpus:5;mem:5").get();
+
   Resources toFind3 = Resources::parse("cpus:6;mem:6").get();
 
   Resources found3 = resources3.find(toFind3).get();
-  Resources expected3 =
-    Resources::parse("cpus:5;mem:5;cpus(role1):1;mem(role1):1").get();
+
+  Resources expected3 = Resources::parse(
+      "cpus:5;mem:5;cpus(role1):1;mem(role1):1").get();
 
   EXPECT_EQ(found3, expected3);