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 2013/10/15 20:20:10 UTC

git commit: Revised replicated log tests to use TemporaryDirectoryTest to ensure temp files are properly cleaned up.

Updated Branches:
  refs/heads/master 38e92332f -> 0b9305799


Revised replicated log tests to use TemporaryDirectoryTest to ensure
temp files are properly cleaned up.

From: Jiang Yan Xu <ya...@jxu.me>
Review: https://reviews.apache.org/r/14544


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

Branch: refs/heads/master
Commit: 0b93057999ebbcd835792d413c7a5844fed6fdc5
Parents: 38e9233
Author: Vinod Kone <vi...@twitter.com>
Authored: Tue Oct 15 11:19:44 2013 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Tue Oct 15 11:19:44 2013 -0700

----------------------------------------------------------------------
 src/tests/log_tests.cpp | 177 +++++++++----------------------------------
 1 file changed, 37 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0b930579/src/tests/log_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/log_tests.cpp b/src/tests/log_tests.cpp
index fbfbf33..ff5f86c 100644
--- a/src/tests/log_tests.cpp
+++ b/src/tests/log_tests.cpp
@@ -54,13 +54,17 @@ using testing::_;
 using testing::Eq;
 using testing::Return;
 
+#include "tests/utils.hpp"
 
-TEST(ReplicaTest, Promise)
+using namespace mesos::internal::tests;
+
+class ReplicaTest : public TemporaryDirectoryTest {};
+
+
+TEST_F(ReplicaTest, Promise)
 {
   const std::string path = os::getcwd() + "/.log";
 
-  os::rmdir(path);
-
   Replica replica(path);
 
   PromiseRequest request;
@@ -104,17 +108,13 @@ TEST(ReplicaTest, Promise)
   EXPECT_TRUE(response.has_position());
   EXPECT_EQ(0u, response.position());
   EXPECT_FALSE(response.has_action());
-
-  os::rmdir(path);
 }
 
 
-TEST(ReplicaTest, Append)
+TEST_F(ReplicaTest, Append)
 {
   const std::string path = os::getcwd() + "/.log";
 
-  os::rmdir(path);
-
   Replica replica(path);
 
   const uint64_t id = 1;
@@ -167,17 +167,13 @@ TEST(ReplicaTest, Append)
   EXPECT_TRUE(action.has_append());
   EXPECT_FALSE(action.has_truncate());
   EXPECT_EQ("hello world", action.append().bytes());
-
-  os::rmdir(path);
 }
 
 
-TEST(ReplicaTest, Recover)
+TEST_F(ReplicaTest, Recover)
 {
   const std::string path = os::getcwd() + "/.log";
 
-  os::rmdir(path);
-
   Replica replica1(path);
 
   const uint64_t id = 1;
@@ -254,19 +250,17 @@ TEST(ReplicaTest, Recover)
     EXPECT_FALSE(action.has_truncate());
     EXPECT_EQ("hello world", action.append().bytes());
   }
-
-  os::rmdir(path);
 }
 
 
-TEST(CoordinatorTest, Elect)
+class CoordinatorTest : public TemporaryDirectoryTest {};
+
+
+TEST_F(CoordinatorTest, Elect)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -291,20 +285,14 @@ TEST(CoordinatorTest, Elect)
     ASSERT_TRUE(actions.get().front().has_type());
     ASSERT_EQ(Action::NOP, actions.get().front().type());
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, AppendRead)
+TEST_F(CoordinatorTest, AppendRead)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -340,20 +328,14 @@ TEST(CoordinatorTest, AppendRead)
     ASSERT_EQ(Action::APPEND, actions.get().front().type());
     EXPECT_EQ("hello world", actions.get().front().append().bytes());
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, AppendReadError)
+TEST_F(CoordinatorTest, AppendReadError)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -386,18 +368,13 @@ TEST(CoordinatorTest, AppendReadError)
     AWAIT_FAILED(actions);
     EXPECT_EQ("Bad read range (past end of log)", actions.failure());
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, ElectNoQuorum)
+TEST_F(CoordinatorTest, ElectNoQuorum)
 {
   const std::string path = os::getcwd() + "/.log";
 
-  os::rmdir(path);
-
   Replica replica(path);
 
   Network network;
@@ -418,20 +395,15 @@ TEST(CoordinatorTest, ElectNoQuorum)
     EXPECT_TRUE(result.isNone());
   }
 
-  os::rmdir(path);
-
   Clock::resume();
 }
 
 
-TEST(CoordinatorTest, AppendNoQuorum)
+TEST_F(CoordinatorTest, AppendNoQuorum)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -463,20 +435,14 @@ TEST(CoordinatorTest, AppendNoQuorum)
   }
 
   Clock::resume();
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, Failover)
+TEST_F(CoordinatorTest, Failover)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -525,20 +491,14 @@ TEST(CoordinatorTest, Failover)
     ASSERT_EQ(Action::APPEND, actions.get().front().type());
     EXPECT_EQ("hello world", actions.get().front().append().bytes());
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, Demoted)
+TEST_F(CoordinatorTest, Demoted)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -602,22 +562,15 @@ TEST(CoordinatorTest, Demoted)
     ASSERT_EQ(Action::APPEND, actions.get().front().type());
     EXPECT_EQ("hello hello", actions.get().front().append().bytes());
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, Fill)
+TEST_F(CoordinatorTest, Fill)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
   const std::string path3 = os::getcwd() + "/.log3";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -670,14 +623,10 @@ TEST(CoordinatorTest, Fill)
     ASSERT_EQ(Action::APPEND, actions.get().front().type());
     EXPECT_EQ("hello world", actions.get().front().append().bytes());
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
 }
 
 
-TEST(CoordinatorTest, NotLearnedFill)
+TEST_F(CoordinatorTest, NotLearnedFill)
 {
   DROP_MESSAGES(Eq(LearnedMessage().GetTypeName()), _, _);
 
@@ -685,10 +634,6 @@ TEST(CoordinatorTest, NotLearnedFill)
   const std::string path2 = os::getcwd() + "/.log2";
   const std::string path3 = os::getcwd() + "/.log3";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -741,21 +686,14 @@ TEST(CoordinatorTest, NotLearnedFill)
     ASSERT_EQ(Action::APPEND, actions.get().front().type());
     EXPECT_EQ("hello world", actions.get().front().append().bytes());
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
 }
 
 
-TEST(CoordinatorTest, MultipleAppends)
+TEST_F(CoordinatorTest, MultipleAppends)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -789,13 +727,10 @@ TEST(CoordinatorTest, MultipleAppends)
       EXPECT_EQ(stringify(action.position()), action.append().bytes());
     }
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, MultipleAppendsNotLearnedFill)
+TEST_F(CoordinatorTest, MultipleAppendsNotLearnedFill)
 {
   DROP_MESSAGES(Eq(LearnedMessage().GetTypeName()), _, _);
 
@@ -803,10 +738,6 @@ TEST(CoordinatorTest, MultipleAppendsNotLearnedFill)
   const std::string path2 = os::getcwd() + "/.log2";
   const std::string path3 = os::getcwd() + "/.log3";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -857,21 +788,14 @@ TEST(CoordinatorTest, MultipleAppendsNotLearnedFill)
       EXPECT_EQ(stringify(action.position()), action.append().bytes());
     }
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
 }
 
 
-TEST(CoordinatorTest, Truncate)
+TEST_F(CoordinatorTest, Truncate)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -917,13 +841,10 @@ TEST(CoordinatorTest, Truncate)
       EXPECT_EQ(stringify(action.position()), action.append().bytes());
     }
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, TruncateNotLearnedFill)
+TEST_F(CoordinatorTest, TruncateNotLearnedFill)
 {
   DROP_MESSAGES(Eq(LearnedMessage().GetTypeName()), _, _);
 
@@ -931,10 +852,6 @@ TEST(CoordinatorTest, TruncateNotLearnedFill)
   const std::string path2 = os::getcwd() + "/.log2";
   const std::string path3 = os::getcwd() + "/.log3";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -997,23 +914,15 @@ TEST(CoordinatorTest, TruncateNotLearnedFill)
       EXPECT_EQ(stringify(action.position()), action.append().bytes());
     }
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
 }
 
 
-TEST(CoordinatorTest, TruncateLearnedFill)
+TEST_F(CoordinatorTest, TruncateLearnedFill)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
   const std::string path3 = os::getcwd() + "/.log3";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
-
   Replica replica1(path1);
   Replica replica2(path2);
 
@@ -1076,21 +985,17 @@ TEST(CoordinatorTest, TruncateLearnedFill)
       EXPECT_EQ(stringify(action.position()), action.append().bytes());
     }
   }
-
-  os::rmdir(path1);
-  os::rmdir(path2);
-  os::rmdir(path3);
 }
 
 
-TEST(LogTest, WriteRead)
+class LogTest : public TemporaryDirectoryTest {};
+
+
+TEST_F(LogTest, WriteRead)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
 
   std::set<UPID> pids;
@@ -1114,20 +1019,14 @@ TEST(LogTest, WriteRead)
   ASSERT_EQ(1u, entries.get().size());
   EXPECT_EQ(position.get(), entries.get().front().position);
   EXPECT_EQ("hello world", entries.get().front().data);
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(LogTest, Position)
+TEST_F(LogTest, Position)
 {
   const std::string path1 = os::getcwd() + "/.log1";
   const std::string path2 = os::getcwd() + "/.log2";
 
-  os::rmdir(path1);
-  os::rmdir(path2);
-
   Replica replica1(path1);
 
   std::set<UPID> pids;
@@ -1143,18 +1042,16 @@ TEST(LogTest, Position)
   ASSERT_SOME(position);
 
   ASSERT_EQ(position.get(), log.position(position.get().identity()));
-
-  os::rmdir(path1);
-  os::rmdir(path2);
 }
 
 
-TEST(CoordinatorTest, RacingElect) {}
+TEST_F(CoordinatorTest, RacingElect) {}
 
-TEST(CoordinatorTest, FillNoQuorum) {}
+TEST_F(CoordinatorTest, FillNoQuorum) {}
 
-TEST(CoordinatorTest, FillInconsistent) {}
+TEST_F(CoordinatorTest, FillInconsistent) {}
 
-TEST(CoordinatorTest, LearnedOnOneReplica_NotLearnedOnAnother) {}
+TEST_F(CoordinatorTest, LearnedOnOneReplica_NotLearnedOnAnother) {}
 
-TEST(CoordinatorTest, LearnedOnOneReplica_NotLearnedOnAnother_AnotherFailsAndRecovers) {}
+TEST_F(CoordinatorTest,
+       LearnedOnOneReplica_NotLearnedOnAnother_AnotherFailsAndRecovers) {}