Repository: mesos
Updated Branches:
  refs/heads/master cd9543864 -> dc7c4b6d0


Fixed a bug in Resources::contains.

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


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

Branch: refs/heads/master
Commit: dc7c4b6d0bcf778cc0cad57bb108564be734143a
Parents: cd95438
Author: Jie Yu <[email protected]>
Authored: Thu Jan 29 15:07:37 2015 -0800
Committer: Jie Yu <[email protected]>
Committed: Thu Jan 29 15:19:51 2015 -0800

----------------------------------------------------------------------
 src/common/resources.cpp      |  6 +++++-
 src/tests/resources_tests.cpp | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dc7c4b6d/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 68f6421..308b886 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -433,13 +433,17 @@ Resources::Resources(
 
 bool Resources::contains(const Resources& that) const
 {
+  Resources remaining = *this;
+
   foreach (const Resource& resource, that.resources) {
     // NOTE: We use _contains because Resources only contain valid
     // Resource objects, and we don't want the performance hit of the
     // validity check.
-    if (!_contains(resource)) {
+    if (!remaining._contains(resource)) {
       return false;
     }
+
+    remaining -= resource;
   }
 
   return true;

http://git-wip-us.apache.org/repos/asf/mesos/blob/dc7c4b6d/src/tests/resources_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index 9fd2135..4744e87 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -924,6 +924,22 @@ TEST(DiskResourcesTest, Subtraction)
 }
 
 
+TEST(DiskResourcesTest, Contains)
+{
+  Resources r1 = createDiskResource("10", "role", "1", "path");
+  Resources r2 = createDiskResource("10", "role", "1", "path");
+
+  EXPECT_FALSE(r1.contains(r1 + r2));
+  EXPECT_FALSE(r2.contains(r1 + r2));
+  EXPECT_TRUE((r1 + r2).contains(r1 + r2));
+
+  Resources r3 = createDiskResource("20", "role", "2", "path");
+
+  EXPECT_TRUE((r1 + r3).contains(r1));
+  EXPECT_TRUE((r1 + r3).contains(r3));
+}
+
+
 TEST(DiskResourcesTest, FilterPersistentVolumes)
 {
   Resources resources = Resources::parse("cpus:1;mem:512;disk:1000").get();

Reply via email to