You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2015/10/27 20:30:11 UTC

[3/3] mesos git commit: Added unit tests for Call validation in Agent.

Added unit tests for Call validation in Agent.

Unit tests for Call validation in Agent.

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


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

Branch: refs/heads/master
Commit: 59b09b3be22f658eb96bba91f347c86c1d41ef18
Parents: ea31fd0
Author: Isabel Jimenez <co...@isabeljimenez.com>
Authored: Tue Oct 27 12:28:33 2015 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Tue Oct 27 12:29:51 2015 -0700

----------------------------------------------------------------------
 src/tests/executor_http_api_tests.cpp | 192 +++++++++++++++++++++++++++++
 1 file changed, 192 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/59b09b3b/src/tests/executor_http_api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/executor_http_api_tests.cpp b/src/tests/executor_http_api_tests.cpp
index 13a903b..4863092 100644
--- a/src/tests/executor_http_api_tests.cpp
+++ b/src/tests/executor_http_api_tests.cpp
@@ -513,6 +513,198 @@ TEST_P(ExecutorHttpApiTest, NotAcceptable)
   Shutdown();
 }
 
+
+TEST_P(ExecutorHttpApiTest, ValidProtobufInvalidCall)
+{
+  Try<PID<Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover);
+
+  Try<PID<Slave>> slave = StartSlave();
+  ASSERT_SOME(slave);
+
+  AWAIT_READY(__recover);
+
+  // Wait for recovery to be complete.
+  Clock::pause();
+  Clock::settle();
+
+  // We send a Call protobuf message with missing
+  // required message per type.
+  {
+    Call call;
+    call.set_type(Call::SUBSCRIBE);
+    call.mutable_framework_id()->set_value("dummy_framework_id");
+    call.mutable_executor_id()->set_value("dummy_executor_id");
+
+    process::http::Headers headers;
+    headers["Accept"] = APPLICATION_JSON;
+
+    Future<Response> response = process::http::post(
+        slave.get(),
+        "api/v1/executor",
+        headers,
+        serialize(ContentType::PROTOBUF, call),
+        APPLICATION_PROTOBUF);
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response);
+  }
+
+  {
+    Call call;
+    call.set_type(Call::UPDATE);
+    call.mutable_framework_id()->set_value("dummy_framework_id");
+    call.mutable_executor_id()->set_value("dummy_executor_id");
+
+    process::http::Headers headers;
+    headers["Accept"] = APPLICATION_JSON;
+
+    Future<Response> response = process::http::post(
+        slave.get(),
+        "api/v1/executor",
+        headers,
+        serialize(ContentType::PROTOBUF, call),
+        APPLICATION_PROTOBUF);
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response);
+  }
+
+  {
+    Call call;
+    call.set_type(Call::MESSAGE);
+    call.mutable_framework_id()->set_value("dummy_framework_id");
+    call.mutable_executor_id()->set_value("dummy_executor_id");
+
+    process::http::Headers headers;
+    headers["Accept"] = APPLICATION_JSON;
+
+    Future<Response> response = process::http::post(
+        slave.get(),
+        "api/v1/executor",
+        headers,
+        serialize(ContentType::PROTOBUF, call),
+        APPLICATION_PROTOBUF);
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response);
+  }
+
+  Shutdown();
+}
+
+
+TEST_P(ExecutorHttpApiTest, StatusUpdateCallFailedValidation)
+{
+  Try<PID<Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover);
+
+  Try<PID<Slave>> slave = StartSlave();
+  ASSERT_SOME(slave);
+
+  AWAIT_READY(__recover);
+
+  // Wait for recovery to be complete.
+  Clock::pause();
+  Clock::settle();
+
+  // We send a Call::Update message with inconsistent executor id between
+  // Call::executor_id and Call::Update::TaskInfo::executor_id.
+  // This should result in failed validation.
+  {
+    Call call;
+    call.set_type(Call::UPDATE);
+    call.mutable_framework_id()->set_value("dummy_framework_id");
+    call.mutable_executor_id()->set_value("call_level_executor_id");
+
+    call.mutable_update()->set_uuid(UUID::random().toBytes());
+    call.mutable_update()->set_timestamp(0);
+
+    v1::TaskStatus* status = call.mutable_update()->mutable_status();
+
+    status->mutable_executor_id()->set_value("update_level_executor_id");
+    status->set_state(mesos::v1::TaskState::TASK_STARTING);
+    status->mutable_task_id()->set_value("dummy_task_id");
+
+    process::http::Headers headers;
+    headers["Accept"] = APPLICATION_JSON;
+
+    Future<Response> response = process::http::post(
+        slave.get(),
+        "api/v1/executor",
+        headers,
+        serialize(ContentType::PROTOBUF, call),
+        APPLICATION_PROTOBUF);
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response);
+  }
+
+  // We send a Call Update message with a TASK_STAGING
+  // status update. This should fail validation.
+  {
+    Call call;
+    call.set_type(Call::UPDATE);
+    call.mutable_framework_id()->set_value("dummy_framework_id");
+    call.mutable_executor_id()->set_value("call_level_executor_id");
+
+    call.mutable_update()->set_uuid(UUID::random().toBytes());
+    call.mutable_update()->set_timestamp(0);
+
+    v1::TaskStatus* status = call.mutable_update()->mutable_status();
+
+    status->mutable_executor_id()->set_value("call_level_executor_id");
+    status->mutable_task_id()->set_value("dummy_task_id");
+    status->set_state(mesos::v1::TaskState::TASK_STAGING);
+
+    process::http::Headers headers;
+    headers["Accept"] = APPLICATION_JSON;
+
+    Future<Response> responseStatusUpdate = process::http::post(
+        slave.get(),
+        "api/v1/executor",
+        headers,
+        serialize(ContentType::PROTOBUF, call),
+        APPLICATION_PROTOBUF);
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, responseStatusUpdate);
+  }
+
+  // We send a Call Update message with a different source than
+  // SOURCE_EXECUTOR in the status update. This should fail validation.
+  {
+    Call call;
+    call.set_type(Call::UPDATE);
+    call.mutable_framework_id()->set_value("dummy_framework_id");
+    call.mutable_executor_id()->set_value("call_level_executor_id");
+
+    call.mutable_update()->set_uuid(UUID::random().toBytes());
+    call.mutable_update()->set_timestamp(0);
+
+    v1::TaskStatus* status = call.mutable_update()->mutable_status();
+
+    status->mutable_executor_id()->set_value("call_level_executor_id");
+    status->mutable_task_id()->set_value("dummy_task_id");
+    status->set_state(mesos::v1::TaskState::TASK_STARTING);
+    status->set_source(mesos::v1::TaskStatus::SOURCE_MASTER);
+
+    process::http::Headers headers;
+    headers["Accept"] = APPLICATION_JSON;
+
+    Future<Response> responseStatusUpdate = process::http::post(
+        slave.get(),
+        "api/v1/executor",
+        headers,
+        serialize(ContentType::PROTOBUF, call),
+        APPLICATION_PROTOBUF);
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, responseStatusUpdate);
+  }
+
+  Shutdown();
+}
+
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {