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 2016/10/22 00:04:32 UTC

mesos git commit: Factored out the port range helpers into a test header.

Repository: mesos
Updated Branches:
  refs/heads/master 95153ca79 -> 813e4d1be


Factored out the port range helpers into a test header.

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


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

Branch: refs/heads/master
Commit: 813e4d1be8f407a27b5b2f9bdadba23b04f41211
Parents: 95153ca
Author: Guangya Liu <gy...@gmail.com>
Authored: Fri Oct 21 16:53:03 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Oct 21 17:04:20 2016 -0700

----------------------------------------------------------------------
 src/Makefile.am                            |   3 +
 src/tests/CMakeLists.txt                   |   1 +
 src/tests/hierarchical_allocator_tests.cpp |  90 +-------------------
 src/tests/resources_utils.cpp              | 108 ++++++++++++++++++++++++
 src/tests/resources_utils.hpp              |  52 ++++++++++++
 src/tests/sorter_tests.cpp                 |  90 +-------------------
 6 files changed, 166 insertions(+), 178 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/813e4d1b/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 05fe8fa..d06a9fe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -997,6 +997,7 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   tests/mock_slave.hpp							\
   tests/mock_registrar.hpp						\
   tests/module.hpp							\
+  tests/resources_utils.hpp						\
   tests/script.hpp							\
   tests/utils.hpp							\
   tests/zookeeper.hpp							\
@@ -1928,6 +1929,7 @@ check_PROGRAMS += test-helper
 test_helper_SOURCES =						\
   tests/active_user_test_helper.cpp				\
   tests/flags.cpp						\
+  tests/resources_utils.cpp					\
   tests/test_helper_main.cpp					\
   tests/utils.cpp						\
   tests/containerizer/memory_test_helper.cpp
@@ -2132,6 +2134,7 @@ mesos_tests_SOURCES =						\
   tests/reservation_tests.cpp					\
   tests/resource_offers_tests.cpp				\
   tests/resources_tests.cpp					\
+  tests/resources_utils.cpp					\
   tests/role_tests.cpp						\
   tests/scheduler_driver_tests.cpp				\
   tests/scheduler_event_call_tests.cpp				\

http://git-wip-us.apache.org/repos/asf/mesos/blob/813e4d1b/src/tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index f5d66dc..18d6b15 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -21,6 +21,7 @@ set(TEST_HELPER_SRC
   ${TEST_HELPER_SRC}
   active_user_test_helper.cpp
   flags.cpp
+  resources_utils.cpp
   test_helper_main.cpp
   utils.cpp
   containerizer/memory_test_helper.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/813e4d1b/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 2e979d7..edd5cea 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -47,6 +47,7 @@
 
 #include "tests/allocator.hpp"
 #include "tests/mesos.hpp"
+#include "tests/resources_utils.hpp"
 #include "tests/utils.hpp"
 
 using mesos::internal::master::MIN_CPUS;
@@ -83,95 +84,6 @@ struct Allocation
 };
 
 
-// Creates a "ports(*)" resource for the given ranges.
-static Resource createPorts(const ::mesos::Value::Ranges& ranges)
-{
-  Value value;
-  value.set_type(Value::RANGES);
-  value.mutable_ranges()->CopyFrom(ranges);
-
-  Resource resource;
-  resource.set_role("*");
-  resource.set_name("ports");
-  resource.set_type(Value::RANGES);
-  resource.mutable_ranges()->CopyFrom(value.ranges());
-
-  return resource;
-}
-
-
-// Fragments the given range bounds into a number of subranges.
-// Returns an Error if 'numRanges' is too large. E.g.
-//
-//   [1-10], 1 -> [1-10]
-//   [1-10], 2 -> [1-1,3-10]
-//   [1-10], 3 -> [1-1,3-3,5-10]
-//   [1-10], 4 -> [1-1,3-3,5-5,7-10]
-//   [1-10], 5 -> [1-1,3-3,5-5,7-7,9-10]
-//   [1-10], 6 -> Error
-//
-static Try<::mesos::Value::Ranges> fragment(
-    const ::mesos::Value::Range& bounds,
-    size_t numRanges)
-{
-  uint64_t numValues = bounds.end() - bounds.begin() + 1;
-
-  // Compute the max number of ranges.
-  //
-  // If `numValues` is even, then the maximum number of ranges is
-  // `numValues / 2`:
-  //   [1-2] -> 2 values, maximum 1 range:  [1-2]
-  //   [1-4] -> 4 values, maximum 2 ranges: [1-1,3-4]
-  //   [1-6] -> 6 values, maximum 3 ranges: [1-1,3-3,5-6]
-  //
-  // If `numValues` is odd, then the maximum number of ranges is
-  // `(numValues + 1) / 2`:
-  //   [1-1] -> 1 values, maximum 1 range:  [1-1]
-  //   [1-3] -> 3 values, maximum 2 ranges: [1-1,3-3]
-  //   [1-5] -> 5 values, maximum 3 ranges: [1-1,3-3,5-5]
-  //
-  uint64_t maxRanges;
-  if (numValues % 2 == 0) {
-    maxRanges = numValues / 2;
-  } else {
-    maxRanges = (numValues + 1) / 2;
-  }
-
-  if (numRanges > maxRanges) {
-    return Error("Requested more distinct ranges than possible");
-  }
-
-  // See the documentation above for the fragmentation technique.
-  // We fragment from the front of the bounds until we have the
-  // desired number of ranges.
-  ::mesos::Value::Ranges ranges;
-  ranges.mutable_range()->Reserve(numRanges);
-
-  for (size_t i = 0; i < numRanges; ++i) {
-    Value::Range* range = ranges.add_range();
-
-    range->set_begin(bounds.begin() + (i * 2));
-    range->set_end(range->begin());
-  }
-
-  // Make sure the last range covers the end of the bounds.
-  if (!ranges.range().empty()) {
-    ranges.mutable_range()->rbegin()->set_end(bounds.end());
-  }
-
-  return ranges;
-}
-
-
-static ::mesos::Value::Range createRange(uint64_t begin, uint64_t end)
-{
-  ::mesos::Value::Range range;
-  range.set_begin(begin);
-  range.set_end(end);
-  return range;
-}
-
-
 struct Deallocation
 {
   FrameworkID frameworkId;

http://git-wip-us.apache.org/repos/asf/mesos/blob/813e4d1b/src/tests/resources_utils.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_utils.cpp b/src/tests/resources_utils.cpp
new file mode 100644
index 0000000..be1feb9
--- /dev/null
+++ b/src/tests/resources_utils.cpp
@@ -0,0 +1,108 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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 <mesos/mesos.hpp>
+#include <mesos/resources.hpp>
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
+#include "tests/resources_utils.hpp"
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+Resource createPorts(const ::mesos::Value::Ranges& ranges)
+{
+  Value value;
+  value.set_type(Value::RANGES);
+  value.mutable_ranges()->CopyFrom(ranges);
+
+  Resource resource;
+  resource.set_role("*");
+  resource.set_name("ports");
+  resource.set_type(Value::RANGES);
+  resource.mutable_ranges()->CopyFrom(value.ranges());
+
+  return resource;
+}
+
+
+Try<::mesos::Value::Ranges> fragment(
+    const ::mesos::Value::Range& bounds,
+    size_t numRanges)
+{
+  uint64_t numValues = bounds.end() - bounds.begin() + 1;
+
+  // Compute the max number of ranges.
+  //
+  // If `numValues` is even, then the maximum number of ranges is
+  // `numValues / 2`:
+  //   [1-2] -> 2 values, maximum 1 range:  [1-2]
+  //   [1-4] -> 4 values, maximum 2 ranges: [1-1,3-4]
+  //   [1-6] -> 6 values, maximum 3 ranges: [1-1,3-3,5-6]
+  //
+  // If `numValues` is odd, then the maximum number of ranges is
+  // `(numValues + 1) / 2`:
+  //   [1-1] -> 1 values, maximum 1 range:  [1-1]
+  //   [1-3] -> 3 values, maximum 2 ranges: [1-1,3-3]
+  //   [1-5] -> 5 values, maximum 3 ranges: [1-1,3-3,5-5]
+  //
+  uint64_t maxRanges;
+  if (numValues % 2 == 0) {
+    maxRanges = numValues / 2;
+  } else {
+    maxRanges = (numValues + 1) / 2;
+  }
+
+  if (numRanges > maxRanges) {
+    return Error("Requested more distinct ranges than possible");
+  }
+
+  // See the documentation above for the fragmentation technique.
+  // We fragment from the front of the bounds until we have the
+  // desired number of ranges.
+  ::mesos::Value::Ranges ranges;
+  ranges.mutable_range()->Reserve(numRanges);
+
+  for (size_t i = 0; i < numRanges; ++i) {
+    Value::Range* range = ranges.add_range();
+
+    range->set_begin(bounds.begin() + (i * 2));
+    range->set_end(range->begin());
+  }
+
+  // Make sure the last range covers the end of the bounds.
+  if (!ranges.range().empty()) {
+    ranges.mutable_range()->rbegin()->set_end(bounds.end());
+  }
+
+  return ranges;
+}
+
+
+::mesos::Value::Range createRange(uint64_t begin, uint64_t end)
+{
+  ::mesos::Value::Range range;
+  range.set_begin(begin);
+  range.set_end(end);
+  return range;
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/813e4d1b/src/tests/resources_utils.hpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_utils.hpp b/src/tests/resources_utils.hpp
new file mode 100644
index 0000000..18dcca7
--- /dev/null
+++ b/src/tests/resources_utils.hpp
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+#ifndef __TESTS_RESOURCES_UTILS_HPP__
+#define __TESTS_RESOURCES_UTILS_HPP__
+
+#include <mesos/mesos.hpp>
+#include <mesos/resources.hpp>
+
+#include <stout/try.hpp>
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+// Creates a "ports(*)" resource for the given ranges.
+Resource createPorts(const ::mesos::Value::Ranges& ranges);
+
+// Fragments the given range bounds into a number of subranges.
+// Returns an Error if 'numRanges' is too large. E.g.
+//
+//   [1-10], 1 -> [1-10]
+//   [1-10], 2 -> [1-1,3-10]
+//   [1-10], 3 -> [1-1,3-3,5-10]
+//   [1-10], 4 -> [1-1,3-3,5-5,7-10]
+//   [1-10], 5 -> [1-1,3-3,5-5,7-7,9-10]
+//   [1-10], 6 -> Error
+//
+Try<::mesos::Value::Ranges> fragment(
+    const ::mesos::Value::Range& bounds,
+    size_t numRanges);
+
+::mesos::Value::Range createRange(uint64_t begin, uint64_t end);
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __TESTS_RESOURCES_UTILS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/813e4d1b/src/tests/sorter_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/sorter_tests.cpp b/src/tests/sorter_tests.cpp
index 1f17c01..9f48abe 100644
--- a/src/tests/sorter_tests.cpp
+++ b/src/tests/sorter_tests.cpp
@@ -30,6 +30,7 @@
 #include "master/allocator/sorter/drf/sorter.hpp"
 
 #include "tests/mesos.hpp"
+#include "tests/resources_utils.hpp"
 
 using mesos::internal::master::allocator::DRFSorter;
 
@@ -501,95 +502,6 @@ INSTANTIATE_TEST_CASE_P(
     );
 
 
-// Creates a "ports(*)" resource for the given ranges.
-static Resource createPorts(const ::mesos::Value::Ranges& ranges)
-{
-  Value value;
-  value.set_type(Value::RANGES);
-  value.mutable_ranges()->CopyFrom(ranges);
-
-  Resource resource;
-  resource.set_role("*");
-  resource.set_name("ports");
-  resource.set_type(Value::RANGES);
-  resource.mutable_ranges()->CopyFrom(value.ranges());
-
-  return resource;
-}
-
-
-// Fragments the given range bounds into a number of subranges.
-// Returns an Error if 'numRanges' is too large. E.g.
-//
-//   [1-10], 1 -> [1-10]
-//   [1-10], 2 -> [1-1,3-10]
-//   [1-10], 3 -> [1-1,3-3,5-10]
-//   [1-10], 4 -> [1-1,3-3,5-5,7-10]
-//   [1-10], 5 -> [1-1,3-3,5-5,7-7,9-10]
-//   [1-10], 6 -> Error
-//
-static Try<::mesos::Value::Ranges> fragment(
-    const ::mesos::Value::Range& bounds,
-    size_t numRanges)
-{
-  uint64_t numValues = bounds.end() - bounds.begin() + 1;
-
-  // Compute the max number of ranges.
-  //
-  // If `numValues` is even, then the maximum number of ranges is
-  // `numValues / 2`:
-  //   [1-2] -> 2 values, maximum 1 range:  [1-2]
-  //   [1-4] -> 4 values, maximum 2 ranges: [1-1,3-4]
-  //   [1-6] -> 6 values, maximum 3 ranges: [1-1,3-3,5-6]
-  //
-  // If `numValues` is odd, then the maximum number of ranges is
-  // `(numValues + 1) / 2`:
-  //   [1-1] -> 1 values, maximum 1 range:  [1-1]
-  //   [1-3] -> 3 values, maximum 2 ranges: [1-1,3-3]
-  //   [1-5] -> 5 values, maximum 3 ranges: [1-1,3-3,5-5]
-  //
-  uint64_t maxRanges;
-  if (numValues % 2 == 0) {
-    maxRanges = numValues / 2;
-  } else {
-    maxRanges = (numValues + 1) / 2;
-  }
-
-  if (numRanges > maxRanges) {
-    return Error("Requested more distinct ranges than possible");
-  }
-
-  // See the documentation above for the fragmentation technique.
-  // We fragment from the front of the bounds until we have the
-  // desired number of ranges.
-  ::mesos::Value::Ranges ranges;
-  ranges.mutable_range()->Reserve(numRanges);
-
-  for (size_t i = 0; i < numRanges; ++i) {
-    Value::Range* range = ranges.add_range();
-
-    range->set_begin(bounds.begin() + (i * 2));
-    range->set_end(range->begin());
-  }
-
-  // Make sure the last range covers the end of the bounds.
-  if (!ranges.range().empty()) {
-    ranges.mutable_range()->rbegin()->set_end(bounds.end());
-  }
-
-  return ranges;
-}
-
-
-static ::mesos::Value::Range createRange(uint64_t begin, uint64_t end)
-{
-  ::mesos::Value::Range range;
-  range.set_begin(begin);
-  range.set_end(end);
-  return range;
-}
-
-
 // This benchmark simulates sorting a number of clients that have
 // different amount of allocations.
 TEST_P(Sorter_BENCHMARK_Test, FullSort)