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/07/07 18:20:07 UTC

[11/11] mesos git commit: Added testcases for `LIST_FILES` call for v1 Operator API.

Added testcases for `LIST_FILES` call for v1 Operator API.

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


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

Branch: refs/heads/master
Commit: bad1cfa7e0684e2be6542fdb7dd8d0b056554940
Parents: d9739f1
Author: Abhishek Dasgupta <a1...@linux.vnet.ibm.com>
Authored: Thu Jul 7 10:52:27 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Thu Jul 7 11:07:15 2016 -0700

----------------------------------------------------------------------
 src/tests/api_tests.cpp | 143 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 143 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bad1cfa7/src/tests/api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/api_tests.cpp b/src/tests/api_tests.cpp
index 7cf716d..4cb7072 100644
--- a/src/tests/api_tests.cpp
+++ b/src/tests/api_tests.cpp
@@ -69,6 +69,7 @@ using process::Future;
 using process::Owned;
 
 using process::http::Accepted;
+using process::http::NotFound;
 using process::http::OK;
 using process::http::Pipe;
 using process::http::Response;
@@ -779,6 +780,68 @@ TEST_P(MasterAPITest, SetLoggingLevel)
 }
 
 
+// This test verifies if we can retrieve the file listing for a directory
+// in the master.
+TEST_P(MasterAPITest, ListFiles)
+{
+  Files files;
+
+  ASSERT_SOME(os::mkdir("1/2"));
+  ASSERT_SOME(os::mkdir("1/3"));
+  ASSERT_SOME(os::write("1/two", "two"));
+
+  AWAIT_EXPECT_READY(files.attach("1", "one"));
+
+  // Get the `FileInfo` for "1/two" file.
+  struct stat s;
+  ASSERT_EQ(0, stat("1/two", &s));
+  FileInfo file = protobuf::createFileInfo("one/two", s);
+
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  v1::master::Call v1Call;
+  v1Call.set_type(v1::master::Call::LIST_FILES);
+  v1Call.mutable_list_files()->set_path("one/");
+
+  ContentType contentType = GetParam();
+
+  Future<v1::master::Response> v1Response =
+    post(master.get()->pid, v1Call, contentType);
+
+  AWAIT_READY(v1Response);
+  ASSERT_TRUE(v1Response.get().IsInitialized());
+  ASSERT_EQ(v1::master::Response::LIST_FILES, v1Response.get().type());
+  ASSERT_EQ(3, v1Response.get().list_files().file_infos().size());
+  ASSERT_EQ(internal::evolve(file),
+            v1Response.get().list_files().file_infos(2));
+}
+
+
+// This test verifies that the client will receive a `NotFound` response when it
+// tries to make a `LIST_FILES` call with an invalid path.
+TEST_P(MasterAPITest, ListFilesInvalidPath)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  v1::master::Call v1Call;
+  v1Call.set_type(v1::master::Call::LIST_FILES);
+  v1Call.mutable_list_files()->set_path("five/");
+
+  ContentType contentType = GetParam();
+
+  Future<Response> response = process::http::post(
+    master.get()->pid,
+    "api/v1",
+    createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+    serialize(contentType, v1Call),
+    stringify(contentType));
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(NotFound().status, response);
+}
+
+
 TEST_P(MasterAPITest, GetRoles)
 {
   master::Flags masterFlags = CreateMasterFlags();
@@ -2154,6 +2217,86 @@ TEST_P(AgentAPITest, SetLoggingLevel)
 }
 
 
+// This test verifies if we can retrieve the file listing for a directory
+// in an agent.
+TEST_P(AgentAPITest, ListFiles)
+{
+  Files files;
+
+  ASSERT_SOME(os::mkdir("1/2"));
+  ASSERT_SOME(os::mkdir("1/3"));
+  ASSERT_SOME(os::write("1/two", "two"));
+
+  AWAIT_EXPECT_READY(files.attach("1", "one"));
+
+  // Get the `FileInfo` for "1/two" file.
+  struct stat s;
+  ASSERT_EQ(0, stat("1/two", &s));
+  FileInfo file = protobuf::createFileInfo("one/two", s);
+
+  Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover);
+
+  StandaloneMasterDetector detector;
+  Try<Owned<cluster::Slave>> slave = StartSlave(&detector);
+  ASSERT_SOME(slave);
+
+  AWAIT_READY(__recover);
+
+  // Wait until the agent has finished recovery.
+  Clock::pause();
+  Clock::settle();
+
+  v1::agent::Call v1Call;
+  v1Call.set_type(v1::agent::Call::LIST_FILES);
+  v1Call.mutable_list_files()->set_path("one/");
+
+  ContentType contentType = GetParam();
+
+  Future<v1::agent::Response> v1Response =
+    post(slave.get()->pid, v1Call, contentType);
+
+  AWAIT_READY(v1Response);
+  ASSERT_TRUE(v1Response.get().IsInitialized());
+  ASSERT_EQ(v1::agent::Response::LIST_FILES, v1Response.get().type());
+  ASSERT_EQ(3, v1Response.get().list_files().file_infos().size());
+  ASSERT_EQ(internal::evolve(file),
+            v1Response.get().list_files().file_infos(2));
+}
+
+
+// This test verifies that the client will receive a `NotFound` response when it
+// tries to make a `LIST_FILES` call with an invalid path.
+TEST_P(AgentAPITest, ListFilesInvalidPath)
+{
+  Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover);
+
+  StandaloneMasterDetector detector;
+  Try<Owned<cluster::Slave>> slave = StartSlave(&detector);
+  ASSERT_SOME(slave);
+
+  AWAIT_READY(__recover);
+
+  // Wait until the agent has finished recovery.
+  Clock::pause();
+  Clock::settle();
+
+  v1::agent::Call v1Call;
+  v1Call.set_type(v1::agent::Call::LIST_FILES);
+  v1Call.mutable_list_files()->set_path("five/");
+
+  ContentType contentType = GetParam();
+
+  Future<Response> response = process::http::post(
+    slave.get()->pid,
+    "api/v1",
+    createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+    serialize(contentType, v1Call),
+    stringify(contentType));
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(NotFound().status, response);
+}
+
+
 TEST_P(AgentAPITest, GetContainers)
 {
   Try<Owned<cluster::Master>> master = StartMaster();