You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2016/09/12 22:18:49 UTC
[5/8] mesos git commit: Added an equality operator for
`TaskGroupInfo`/`TaskInfo`.
Added an equality operator for `TaskGroupInfo`/`TaskInfo`.
This is needed for storing \`TaskGroupInfo\` in a list and then
invoking \`std::find()\`/\`std::remove()\` on it. Also added
a basic test in `src/tests/common/type_utils_tests.cpp`.
Review: https://reviews.apache.org/r/51475/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/94827559
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/94827559
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/94827559
Branch: refs/heads/master
Commit: 94827559f3727ef6dd0058068e7a4c976000a0f9
Parents: 00815ee
Author: Anand Mazumdar <an...@apache.org>
Authored: Mon Sep 12 14:21:09 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Mon Sep 12 15:17:02 2016 -0700
----------------------------------------------------------------------
include/mesos/type_utils.hpp | 2 +
src/Makefile.am | 1 +
src/common/type_utils.cpp | 31 ++++++++++++
src/tests/common/type_utils_tests.cpp | 78 ++++++++++++++++++++++++++++++
4 files changed, 112 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/94827559/include/mesos/type_utils.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/type_utils.hpp b/include/mesos/type_utils.hpp
index d10b663..4f4f46e 100644
--- a/include/mesos/type_utils.hpp
+++ b/include/mesos/type_utils.hpp
@@ -62,6 +62,8 @@ bool operator==(
bool operator==(const SlaveInfo& left, const SlaveInfo& right);
bool operator==(const Task& left, const Task& right);
+bool operator==(const TaskGroupInfo& left, const TaskGroupInfo& right);
+bool operator==(const TaskInfo& left, const TaskInfo& right);
bool operator==(const TaskStatus& left, const TaskStatus& right);
bool operator==(const URL& left, const URL& right);
bool operator==(const Volume& left, const Volume& right);
http://git-wip-us.apache.org/repos/asf/mesos/blob/94827559/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index fa71381..2dd7913 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2141,6 +2141,7 @@ mesos_tests_SOURCES = \
tests/common/command_utils_tests.cpp \
tests/common/http_tests.cpp \
tests/common/recordio_tests.cpp \
+ tests/common/type_utils_tests.cpp \
tests/containerizer/appc_spec_tests.cpp \
tests/containerizer/composing_containerizer_tests.cpp \
tests/containerizer/docker_containerizer_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/94827559/src/common/type_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/type_utils.cpp b/src/common/type_utils.cpp
index c7d5033..9cb6274 100644
--- a/src/common/type_utils.cpp
+++ b/src/common/type_utils.cpp
@@ -388,6 +388,37 @@ bool operator==(const Task& left, const Task& right)
}
+bool operator==(const TaskGroupInfo& left, const TaskGroupInfo& right)
+{
+ // Order of tasks in a task group is not important.
+ if (left.tasks().size() != right.tasks().size()) {
+ return false;
+ }
+
+ for (int i = 0; i < left.tasks().size(); i++) {
+ bool found = false;
+ for (int j = 0; j < right.tasks().size(); j++) {
+ if (left.tasks().Get(i) == right.tasks().Get(j)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+// TODO(anand): Consider doing a field by field comparison instead.
+bool operator==(const TaskInfo& left, const TaskInfo& right)
+{
+ return left.SerializeAsString() == right.SerializeAsString();
+}
+
+
// TODO(bmahler): Use SerializeToString here?
bool operator==(const TaskStatus& left, const TaskStatus& right)
{
http://git-wip-us.apache.org/repos/asf/mesos/blob/94827559/src/tests/common/type_utils_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/common/type_utils_tests.cpp b/src/tests/common/type_utils_tests.cpp
new file mode 100644
index 0000000..a962b39
--- /dev/null
+++ b/src/tests/common/type_utils_tests.cpp
@@ -0,0 +1,78 @@
+// 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 <gtest/gtest.h>
+
+#include <mesos/mesos.hpp>
+#include <mesos/resources.hpp>
+
+#include "tests/mesos.hpp"
+
+using namespace mesos;
+using namespace mesos::internal::tests;
+
+
+TEST(TypeUtilsTest, TaskGroupEquality)
+{
+ SlaveID slaveId;
+ slaveId.set_value("default-agent");
+
+ Resources resources = Resources::parse("cpus:0.1;mem:32;disk:32").get();
+
+ TaskInfo task1 =
+ createTask(slaveId, resources, "default-command1");
+
+ TaskInfo task2 =
+ createTask(slaveId, resources, "default-command2");
+
+ // Compare task groups with identical tasks.
+ {
+ TaskGroupInfo taskGroup1;
+ taskGroup1.add_tasks()->CopyFrom(task1);
+ taskGroup1.add_tasks()->CopyFrom(task2);
+
+ TaskGroupInfo taskGroup2;
+ taskGroup2.add_tasks()->CopyFrom(task1);
+ taskGroup2.add_tasks()->CopyFrom(task2);
+
+ EXPECT_EQ(taskGroup1, taskGroup2);
+ }
+
+ // Compare task groups with identical tasks but ordered differently.
+ {
+ TaskGroupInfo taskGroup1;
+ taskGroup1.add_tasks()->CopyFrom(task1);
+ taskGroup1.add_tasks()->CopyFrom(task2);
+
+ TaskGroupInfo taskGroup2;
+ taskGroup2.add_tasks()->CopyFrom(task2);
+ taskGroup2.add_tasks()->CopyFrom(task1);
+
+ EXPECT_EQ(taskGroup1, taskGroup2);
+ }
+
+ // Compare task groups with unequal tasks.
+ {
+ TaskGroupInfo taskGroup1;
+ taskGroup1.add_tasks()->CopyFrom(task1);
+ taskGroup1.add_tasks()->CopyFrom(task2);
+
+ TaskGroupInfo taskGroup2;
+ taskGroup2.add_tasks()->CopyFrom(task1);
+
+ EXPECT_FALSE(taskGroup1 == taskGroup2);
+ }
+}