You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2014/10/17 00:07:23 UTC

[3/3] git commit: Added a protobuf::append test.

Added a protobuf::append test.

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


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

Branch: refs/heads/master
Commit: 6553d73c20dae4b866b604b19b4d4f6a072722f1
Parents: 589fdaa
Author: Jie Yu <yu...@gmail.com>
Authored: Wed Oct 15 21:48:26 2014 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Oct 16 14:59:20 2014 -0700

----------------------------------------------------------------------
 src/tests/protobuf_io_tests.cpp | 66 +++++++++++++++++++++++++++++++-----
 1 file changed, 58 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6553d73c/src/tests/protobuf_io_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/protobuf_io_tests.cpp b/src/tests/protobuf_io_tests.cpp
index 5f80c04..c18bc4f 100644
--- a/src/tests/protobuf_io_tests.cpp
+++ b/src/tests/protobuf_io_tests.cpp
@@ -30,29 +30,40 @@
 
 #include "messages/messages.hpp"
 
+#include "tests/utils.hpp"
+
 using namespace mesos;
 using namespace mesos::internal;
+using namespace mesos::internal::tests;
+
+
+class ProtobufIOTest : public TemporaryDirectoryTest {};
 
 
 // TODO(bmahler): Move this file into stout.
-TEST(ProtobufIOTest, Basic)
+TEST_F(ProtobufIOTest, Basic)
 {
   const std::string file = ".protobuf_io_test_basic";
 
-  Try<int> result = os::open(file, O_CREAT | O_WRONLY | O_SYNC,
-                             S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
+  Try<int> result = os::open(
+      file,
+      O_CREAT | O_WRONLY | O_SYNC | O_CLOEXEC,
+      S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
 
   ASSERT_SOME(result);
+
   int fdw = result.get();
 
-  result = os::open(file, O_CREAT | O_RDONLY,
-                    S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
+  result = os::open(
+      file,
+      O_CREAT | O_RDONLY | O_CLOEXEC,
+      S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
 
   ASSERT_SOME(result);
+
   int fdr = result.get();
 
   const size_t writes = 10;
-
   for (size_t i = 0; i < writes; i++) {
     FrameworkID frameworkId;
     frameworkId.set_value(stringify(i));
@@ -71,12 +82,51 @@ TEST(ProtobufIOTest, Basic)
     EXPECT_EQ(read.get().value(), stringify(reads++));
   }
 
-  // Ensure we've hit the end of the file without reading a partial protobuf.
+  // Ensure we've hit the end of the file without reading a partial
+  // protobuf.
   ASSERT_TRUE(read.isNone());
   ASSERT_EQ(writes, reads);
 
   os::close(fdw);
   os::close(fdr);
+}
+
+
+TEST_F(ProtobufIOTest, Append)
+{
+  const std::string file = ".protobuf_io_test_append";
+
+  const size_t writes = 10;
+  for (size_t i = 0; i < writes; i++) {
+    FrameworkID frameworkId;
+    frameworkId.set_value(stringify(i));
+
+    Try<Nothing> result = ::protobuf::append(file, frameworkId);
+    ASSERT_SOME(result);
+  }
+
+  Try<int> fd = os::open(
+      file,
+      O_CREAT | O_RDONLY | O_CLOEXEC,
+      S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
+
+  ASSERT_SOME(fd);
+
+  Result<FrameworkID> read = None();
+  size_t reads = 0;
+  while (true) {
+    read = ::protobuf::read<FrameworkID>(fd.get());
+    if (!read.isSome()) {
+      break;
+    }
+
+    EXPECT_EQ(read.get().value(), stringify(reads++));
+  }
+
+  // Ensure we've hit the end of the file without reading a partial
+  // protobuf.
+  ASSERT_TRUE(read.isNone());
+  ASSERT_EQ(writes, reads);
 
-  os::rm(file);
+  os::close(fd.get());
 }