MB-20623: Convert MutationLog unit tests to GTest 40/68040/8
authorDave Rigby <daver@couchbase.com>
Tue, 27 Sep 2016 14:00:03 +0000 (15:00 +0100)
committerDave Rigby <daver@couchbase.com>
Fri, 30 Sep 2016 13:29:38 +0000 (13:29 +0000)
Convert to using the GoogleTest framework, and integrate into
ep-engine_ep_unit_tests binary.

Change-Id: I7caff50202abc4ecf55c513f4b6859d5c5d48d40
Reviewed-on: http://review.couchbase.org/68040
Reviewed-by: Daniel Owen <owend@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
CMakeLists.txt
src/mutation_log.cc
src/mutation_log.h
tests/module_tests/mutation_log_test.cc

index b993bf0..4f028cd 100644 (file)
@@ -188,6 +188,7 @@ ADD_EXECUTABLE(ep-engine_ep_unit_tests
   tests/module_tests/evp_engine_test.cc
   tests/module_tests/evp_store_test.cc
   tests/module_tests/evp_store_single_threaded_test.cc
+  tests/module_tests/mutation_log_test.cc
   src/access_scanner.cc
   src/atomic.cc
   src/backfill.cc
@@ -351,7 +352,6 @@ ADD_TEST(ep-engine_hash_table_test ep-engine_hash_table_test)
 ADD_TEST(ep-engine_hrtime_test ep-engine_hrtime_test)
 ADD_TEST(ep-engine_misc_test ep-engine_misc_test)
 ADD_TEST(ep-engine_mutex_test ep-engine_mutex_test)
-ADD_TEST(ep-engine_mutation_log_test ep-engine_mutation_log_test)
 ADD_TEST(ep-engine_ringbuffer_test ep-engine_ringbuffer_test)
 ADD_TEST(ep-engine_kvstore_test ep-engine_kvstore_test)
 ADD_TEST(ep-engine_defragmenter_test ep-engine_defragmenter_test)
@@ -388,63 +388,6 @@ TARGET_LINK_LIBRARIES(ep-engine_defragmenter_test
                       cJSON gtest platform ${MALLOC_LIBRARIES}
                       ${SNAPPY_LIBRARIES})
 
-ADD_EXECUTABLE(ep-engine_mutation_log_test
-               tests/module_tests/mutation_log_test.cc
-               src/access_scanner.cc
-               src/atomic.cc
-               src/backfill.cc
-               src/bgfetcher.cc
-               src/bloomfilter.cc
-               src/checkpoint.cc
-               src/checkpoint_remover.cc
-               src/conflict_resolution.cc
-               src/compress.cc
-               src/connmap.cc
-               src/dcp/backfill.cc
-               src/dcp/backfill-manager.cc
-               src/dcp/consumer.cc
-               src/dcp/flow-control.cc
-               src/dcp/flow-control-manager.cc
-               src/dcp/producer.cc
-               src/dcp/response.cc
-               src/dcp/stream.cc
-               src/defragmenter.cc
-               src/defragmenter_visitor.cc
-               src/ep.cc
-               src/ep_engine.cc
-               src/ep_time.c
-               src/executorpool.cc
-               src/executorthread.cc
-               src/ext_meta_parser.cc
-               src/failover-table.cc
-               src/flusher.cc
-               src/htresizer.cc
-               src/item.cc
-               src/item_pager.cc
-               src/kvshard.cc
-               src/logger.cc
-               src/memory_tracker.cc
-               src/murmurhash3.cc
-               src/mutation_log.cc
-               src/objectregistry.cc
-               src/tapconnection.cc
-               src/replicationthrottle.cc
-               src/stored-value.cc
-               src/string_utils.cc
-               src/tasks.cc
-               src/taskqueue.cc
-               src/vbucket.cc
-               src/vbucketmap.cc
-               src/warmup.cc
-               ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
-               ${OBJECTREGISTRY_SOURCE}
-               ${KVSTORE_SOURCE}
-               ${COUCH_KVSTORE_SOURCE}
-               ${FOREST_KVSTORE_SOURCE}
-               ${CONFIG_SOURCE})
-TARGET_LINK_LIBRARIES(ep-engine_mutation_log_test
-                      couchstore cJSON dirutils forestdb JSON_checker platform ${SNAPPY_LIBRARIES})
-
 ADD_LIBRARY(ep_testsuite SHARED
    tests/ep_testsuite.cc
    src/atomic.cc
index 348c7bc..d96cde2 100644 (file)
@@ -815,7 +815,7 @@ MutationLog::iterator& MutationLog::iterator::operator++() {
     return *this;
 }
 
-bool MutationLog::iterator::operator==(const MutationLog::iterator& rhs) {
+bool MutationLog::iterator::operator==(const MutationLog::iterator& rhs) const {
     return log.fd() == rhs.log.fd()
         && (
             (isEnd == rhs.isEnd)
@@ -823,7 +823,7 @@ bool MutationLog::iterator::operator==(const MutationLog::iterator& rhs) {
                 && items == rhs.items));
 }
 
-bool MutationLog::iterator::operator!=(const MutationLog::iterator& rhs) {
+bool MutationLog::iterator::operator!=(const MutationLog::iterator& rhs) const {
     return ! operator==(rhs);
 }
 
index e7d442a..3da83b2 100644 (file)
@@ -452,9 +452,9 @@ public:
 
         iterator& operator++();
 
-        bool operator==(const iterator& rhs);
+        bool operator==(const iterator& rhs) const;
 
-        bool operator!=(const iterator& rhs);
+        bool operator!=(const iterator& rhs) const;
 
         const MutationLogEntry* operator*();
 
index 7266d90..e909fc5 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <algorithm>
 #include <fcntl.h>
+#include <gtest/gtest.h>
 #include <map>
 #include <platform/strerror.h>
 #include <set>
 #include <sys/stat.h>
 #include <vector>
 
-#include "assert.h"
 #include "mutation_log.h"
 
-#define TMP_LOG_FILE "mlt_test.log"
-
 // Windows doesn't have a truncate() function, implement one.
 #if defined(WIN32)
 int truncate(const char *path, off_t length) {
@@ -65,25 +63,43 @@ namespace FilePerms {
 #endif
 }
 
-/*
- * Sets the read/write permissions on the given file (in a cross-platform way).
- */
-static void set_file_perms(const char* path, /*FilePerms*/int perms) {
+class MutationLogTest : public ::testing::Test {
+protected:
+    void SetUp() override {
+        // Generate a temporary log filename.
+        tmp_log_filename = "mlt_test.XXXXXX";
+        ASSERT_NE(nullptr, cb_mktemp(&tmp_log_filename[0]));
+    }
+
+    void TearDown() override {
+        remove(tmp_log_filename.c_str());
+    }
+
+    /**
+     * Sets the read/write permissions on the tmp log file (in a
+     * cross-platform way).
+     */
+    void set_file_perms(/*FilePerms*/int perms) {
 #if defined(WIN32)
-    if (_chmod(path, perms) != 0) {
+        if (_chmod(tmp_log_filename.c_str(), perms) != 0)
+        {
 #else
-    if (chmod(path, perms) != 0) {
+        if (chmod(tmp_log_filename.c_str(), perms) != 0)
+        {
 #endif
-        std::cerr << "set_file_perms: chmod failed: " << cb_strerror() << std::endl;
-        abort();
+            std::cerr << "set_file_perms: chmod failed: " << cb_strerror() << std::endl;
+            abort();
+        }
     }
-}
 
+    // Storage for temporary log filename
+    std::string tmp_log_filename;
+};
 
-static void testUnconfigured() {
+TEST_F(MutationLogTest, Unconfigured) {
     MutationLog ml("");
     ml.open();
-    cb_assert(!ml.isEnabled());
+    ASSERT_FALSE(ml.isEnabled());
     ml.newItem(3, "somekey", 931);
     ml.delItem(3, "somekey");
     ml.deleteAll(3);
@@ -91,17 +107,21 @@ static void testUnconfigured() {
     ml.commit2();
     ml.flush();
 
-    cb_assert(ml.begin() == ml.end());
+    EXPECT_EQ(ml.begin(), ml.end());
 }
 
-static void testSyncSet() {
+TEST_F(MutationLogTest, SyncSet) {
 
     // Some basics
-    cb_assert((SYNC_COMMIT_1 | SYNC_COMMIT_2) == SYNC_FULL);
-    cb_assert((FLUSH_COMMIT_1 | FLUSH_COMMIT_2) == FLUSH_FULL);
+    static_assert((SYNC_COMMIT_1 | SYNC_COMMIT_2) == SYNC_FULL,
+                  "Incorrect value for SYNC_FULL");
+    static_assert((FLUSH_COMMIT_1 | FLUSH_COMMIT_2) == FLUSH_FULL,
+                  "Incorrect value for FLUSH_FULL");
     // No overlap
-    cb_assert((FLUSH_FULL & ~SYNC_FULL) == FLUSH_FULL);
-    cb_assert((SYNC_FULL & ~FLUSH_FULL) == SYNC_FULL);
+    static_assert((FLUSH_FULL & ~SYNC_FULL) == FLUSH_FULL,
+                  "FLUSH_FULL overlaps with SYNC_FULL");
+    static_assert((SYNC_FULL & ~FLUSH_FULL) == SYNC_FULL,
+                  "SYNC_FULL overlaps with FLUSH_FULL");
 
     //
     // Now the real tests.
@@ -109,58 +129,58 @@ static void testSyncSet() {
     MutationLog ml("");
     ml.open();
 
-    cb_assert(ml.setSyncConfig("off"));
-    cb_assert(ml.getSyncConfig() == 0);
+    EXPECT_TRUE(ml.setSyncConfig("off"));
+    EXPECT_EQ(0, ml.getSyncConfig());
 
-    cb_assert(ml.setSyncConfig("commit1"));
-    cb_assert(ml.getSyncConfig() == SYNC_COMMIT_1);
+    EXPECT_TRUE(ml.setSyncConfig("commit1"));
+    EXPECT_EQ(SYNC_COMMIT_1, ml.getSyncConfig());
 
-    cb_assert(ml.setSyncConfig("commit2"));
-    cb_assert(ml.getSyncConfig() == SYNC_COMMIT_2);
+    EXPECT_TRUE(ml.setSyncConfig("commit2"));
+    EXPECT_EQ(SYNC_COMMIT_2, ml.getSyncConfig());
 
-    cb_assert(ml.setSyncConfig("full"));
-    cb_assert(ml.getSyncConfig() == (SYNC_COMMIT_1|SYNC_COMMIT_2));
+    EXPECT_TRUE(ml.setSyncConfig("full"));
+    EXPECT_EQ(SYNC_COMMIT_1 | SYNC_COMMIT_2, ml.getSyncConfig());
 
-    cb_assert(!ml.setSyncConfig("otherwise"));
+    EXPECT_FALSE(ml.setSyncConfig("otherwise"));
 
     // reset
-    cb_assert(ml.setSyncConfig("off"));
-    cb_assert(ml.getSyncConfig() == 0);
+    EXPECT_TRUE(ml.setSyncConfig("off"));
+    EXPECT_EQ(0, ml.getSyncConfig());
 
     //
     // Flush tests
     //
-    cb_assert(ml.setFlushConfig("commit1"));
-    cb_assert(ml.getFlushConfig() == FLUSH_COMMIT_1);
+    EXPECT_TRUE(ml.setFlushConfig("commit1"));
+    EXPECT_EQ(FLUSH_COMMIT_1, ml.getFlushConfig());
 
-    cb_assert(ml.setFlushConfig("commit2"));
-    cb_assert(ml.getFlushConfig() == FLUSH_COMMIT_2);
+    EXPECT_TRUE(ml.setFlushConfig("commit2"));
+    EXPECT_EQ(FLUSH_COMMIT_2, ml.getFlushConfig());
 
-    cb_assert(ml.setFlushConfig("full"));
-    cb_assert(ml.getFlushConfig() == (FLUSH_COMMIT_1|FLUSH_COMMIT_2));
+    EXPECT_TRUE(ml.setFlushConfig("full"));
+    EXPECT_EQ(FLUSH_COMMIT_1 | FLUSH_COMMIT_2, ml.getFlushConfig());
 
-    cb_assert(!ml.setFlushConfig("otherwise"));
+    EXPECT_FALSE(ml.setFlushConfig("otherwise"));
 
     // reset
-    cb_assert(ml.setSyncConfig("off"));
-    cb_assert(ml.getSyncConfig() == 0);
-    cb_assert(ml.setFlushConfig("off"));
-    cb_assert(ml.getFlushConfig() == 0);
+    EXPECT_TRUE(ml.setSyncConfig("off"));
+    EXPECT_EQ(0, ml.getSyncConfig());
+    EXPECT_TRUE(ml.setFlushConfig("off"));
+    EXPECT_EQ(0, ml.getFlushConfig());
 
     //
     // Try both
     //
 
-    cb_assert(ml.setSyncConfig("commit1"));
-    cb_assert(ml.setFlushConfig("commit2"));
-    cb_assert(ml.getSyncConfig() == SYNC_COMMIT_1);
-    cb_assert(ml.getFlushConfig() == FLUSH_COMMIT_2);
+    EXPECT_TRUE(ml.setSyncConfig("commit1"));
+    EXPECT_TRUE(ml.setFlushConfig("commit2"));
+    EXPECT_EQ(SYNC_COMMIT_1, ml.getSyncConfig());
+    EXPECT_EQ(FLUSH_COMMIT_2, ml.getFlushConfig());
 
     // Swap them and apply in reverse order.
-    cb_assert(ml.setFlushConfig("commit1"));
-    cb_assert(ml.setSyncConfig("commit2"));
-    cb_assert(ml.getSyncConfig() == SYNC_COMMIT_2);
-    cb_assert(ml.getFlushConfig() == FLUSH_COMMIT_1);
+    EXPECT_TRUE(ml.setFlushConfig("commit1"));
+    EXPECT_TRUE(ml.setSyncConfig("commit2"));
+    EXPECT_EQ(SYNC_COMMIT_2, ml.getSyncConfig());
+    EXPECT_EQ(FLUSH_COMMIT_1, ml.getFlushConfig());
 }
 
 static bool loaderFun(void *arg, uint16_t vb,
@@ -170,11 +190,11 @@ static bool loaderFun(void *arg, uint16_t vb,
     return true;
 }
 
-static void testLogging() {
-    remove(TMP_LOG_FILE);
+TEST_F(MutationLogTest, Logging) {
+    remove(tmp_log_filename.c_str());
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
 
         ml.newItem(3, "key1", 1);
@@ -187,56 +207,54 @@ static void testLogging() {
         ml.commit2();
         // Remaining:   3:key2, 2:key1
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 3);
-        cb_assert(ml.itemsLogged[ML_DEL] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 2);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 2);
+        EXPECT_EQ(3, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_DEL]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT2]);
     }
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
         MutationLogHarvester h(ml);
         h.setVBucket(1);
         h.setVBucket(2);
         h.setVBucket(3);
 
-        cb_assert(h.load());
+        EXPECT_TRUE(h.load());
 
-        cb_assert(h.getItemsSeen()[ML_NEW] == 3);
-        cb_assert(h.getItemsSeen()[ML_DEL] == 1);
-        cb_assert(h.getItemsSeen()[ML_COMMIT1] == 2);
-        cb_assert(h.getItemsSeen()[ML_COMMIT2] == 2);
+        EXPECT_EQ(3, h.getItemsSeen()[ML_NEW]);
+        EXPECT_EQ(1, h.getItemsSeen()[ML_DEL]);
+        EXPECT_EQ(2, h.getItemsSeen()[ML_COMMIT1]);
+        EXPECT_EQ(2, h.getItemsSeen()[ML_COMMIT2]);
 
         // Check stat copying
         ml.resetCounts(h.getItemsSeen());
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 3);
-        cb_assert(ml.itemsLogged[ML_DEL] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 2);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 2);
+        EXPECT_EQ(3, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_DEL]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT2]);
 
         // See if we got what we expect.
         std::map<std::string, uint64_t> maps[4];
         h.apply(&maps, loaderFun);
 
-        cb_assert(maps[0].size() == 0);
-        cb_assert(maps[1].size() == 0);
-        cb_assert(maps[2].size() == 1);
-        cb_assert(maps[3].size() == 1);
+        EXPECT_EQ(0, maps[0].size());
+        EXPECT_EQ(0, maps[1].size());
+        EXPECT_EQ(1, maps[2].size());
+        EXPECT_EQ(1, maps[3].size());
 
-        cb_assert(maps[2].find("key1") != maps[2].end());
-        cb_assert(maps[3].find("key2") != maps[3].end());
+        EXPECT_NE(maps[2].end(), maps[2].find("key1"));
+        EXPECT_NE(maps[3].end(), maps[3].find("key2"));
     }
-
-    remove(TMP_LOG_FILE);
 }
 
-static void testDelAll() {
-    remove(TMP_LOG_FILE);
+TEST_F(MutationLogTest, DelAll) {
+    remove(tmp_log_filename.c_str());
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
 
         ml.newItem(3, "key1", 1);
@@ -249,49 +267,47 @@ static void testDelAll() {
         ml.commit2();
         // Remaining:   2:key1
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 3);
-        cb_assert(ml.itemsLogged[ML_DEL] == 0);
-        cb_assert(ml.itemsLogged[ML_DEL_ALL] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 2);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 2);
+        EXPECT_EQ(3, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(0, ml.itemsLogged[ML_DEL]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_DEL_ALL]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT2]);
     }
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
         MutationLogHarvester h(ml);
         h.setVBucket(1);
         h.setVBucket(2);
         h.setVBucket(3);
 
-        cb_assert(h.load());
+        EXPECT_TRUE(h.load());
 
-        cb_assert(h.getItemsSeen()[ML_NEW] == 3);
-        cb_assert(h.getItemsSeen()[ML_DEL_ALL] == 1);
-        cb_assert(h.getItemsSeen()[ML_COMMIT1] == 2);
-        cb_assert(h.getItemsSeen()[ML_COMMIT2] == 2);
+        EXPECT_EQ(3, h.getItemsSeen()[ML_NEW]);
+        EXPECT_EQ(1, h.getItemsSeen()[ML_DEL_ALL]);
+        EXPECT_EQ(2, h.getItemsSeen()[ML_COMMIT1]);
+        EXPECT_EQ(2, h.getItemsSeen()[ML_COMMIT2]);
 
         // Check stat copying
         ml.resetCounts(h.getItemsSeen());
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 3);
-        cb_assert(ml.itemsLogged[ML_DEL_ALL] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 2);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 2);
+        EXPECT_EQ(3, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_DEL_ALL]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT2]);
 
         // See if we got what we expect.
         std::map<std::string, uint64_t> maps[4];
         h.apply(&maps, loaderFun);
 
-        cb_assert(maps[0].size() == 0);
-        cb_assert(maps[1].size() == 0);
-        cb_assert(maps[2].size() == 1);
-        cb_assert(maps[3].size() == 0);
+        EXPECT_EQ(0, maps[0].size());
+        EXPECT_EQ(0, maps[1].size());
+        EXPECT_EQ(1, maps[2].size());
+        EXPECT_EQ(0, maps[3].size());
 
-        cb_assert(maps[2].find("key1") != maps[2].end());
+        EXPECT_NE(maps[2].end(), maps[2].find("key1"));
     }
-
-    remove(TMP_LOG_FILE);
 }
 
 static bool leftover_compare(mutation_log_uncommitted_t a,
@@ -311,11 +327,11 @@ static bool leftover_compare(mutation_log_uncommitted_t a,
     return false;
 }
 
-static void testLoggingDirty() {
-    remove(TMP_LOG_FILE);
+TEST_F(MutationLogTest, LoggingDirty) {
+    remove(tmp_log_filename.c_str());
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
 
         ml.newItem(3, "key1", 1);
@@ -328,70 +344,68 @@ static void testLoggingDirty() {
         ml.delItem(3, "key1");
         // Remaining:   3:key1, 2:key1
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 3);
-        cb_assert(ml.itemsLogged[ML_DEL] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 1);
+        EXPECT_EQ(3, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_DEL]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_COMMIT2]);
     }
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
         MutationLogHarvester h(ml);
         h.setVBucket(1);
         h.setVBucket(2);
         h.setVBucket(3);
 
-        cb_assert(!h.load());
+        EXPECT_FALSE(h.load());
 
-        cb_assert(h.getItemsSeen()[ML_NEW] == 3);
-        cb_assert(h.getItemsSeen()[ML_DEL] == 1);
-        cb_assert(h.getItemsSeen()[ML_COMMIT1] == 1);
-        cb_assert(h.getItemsSeen()[ML_COMMIT2] == 1);
+        EXPECT_EQ(3, h.getItemsSeen()[ML_NEW]);
+        EXPECT_EQ(1, h.getItemsSeen()[ML_DEL]);
+        EXPECT_EQ(1, h.getItemsSeen()[ML_COMMIT1]);
+        EXPECT_EQ(1, h.getItemsSeen()[ML_COMMIT2]);
 
         // Check stat copying
         ml.resetCounts(h.getItemsSeen());
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 3);
-        cb_assert(ml.itemsLogged[ML_DEL] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 1);
+        EXPECT_EQ(3, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_DEL]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_COMMIT2]);
 
         // See if we got what we expect.
         std::map<std::string, uint64_t> maps[4];
         h.apply(&maps, loaderFun);
 
-        cb_assert(maps[0].size() == 0);
-        cb_assert(maps[1].size() == 0);
-        cb_assert(maps[2].size() == 1);
-        cb_assert(maps[3].size() == 1);
+        EXPECT_EQ(0, maps[0].size());
+        EXPECT_EQ(0, maps[1].size());
+        EXPECT_EQ(1, maps[2].size());
+        EXPECT_EQ(1, maps[3].size());
 
-        cb_assert(maps[2].find("key1") != maps[2].end());
-        cb_assert(maps[3].find("key1") != maps[3].end());
-        cb_assert(maps[3].find("key2") == maps[3].end());
+        EXPECT_NE(maps[2].end(), maps[2].find("key1"));
+        EXPECT_NE(maps[3].end(), maps[3].find("key1"));
+        EXPECT_EQ(maps[3].end(), maps[3].find("key2"));
 
         // Check the leftovers
         std::vector<mutation_log_uncommitted_t> leftovers;
         h.getUncommitted(leftovers);
         std::sort(leftovers.begin(), leftovers.end(), leftover_compare);
-        cb_assert(leftovers.size() == 2);
-        cb_assert(leftovers[0].vbucket == 3);
-        cb_assert(leftovers[0].key == "key1");
-        cb_assert(leftovers[0].type == ML_DEL);
-        cb_assert(leftovers[1].vbucket == 3);
-        cb_assert(leftovers[1].key == "key2");
-        cb_assert(leftovers[1].type == ML_NEW);
-        cb_assert(leftovers[1].rowid == 3);
+        EXPECT_EQ(2, leftovers.size());
+        EXPECT_EQ(3, leftovers[0].vbucket);
+        EXPECT_EQ("key1", leftovers[0].key);
+        EXPECT_EQ(ML_DEL, leftovers[0].type);
+        EXPECT_EQ(3, leftovers[1].vbucket);
+        EXPECT_EQ("key2", leftovers[1].key);
+        EXPECT_EQ(ML_NEW, leftovers[1].type);
+        EXPECT_EQ(3, leftovers[1].rowid);
     }
-
-    remove(TMP_LOG_FILE);
 }
 
-static void testLoggingBadCRC() {
-    remove(TMP_LOG_FILE);
+TEST_F(MutationLogTest, LoggingBadCRC) {
+    remove(tmp_log_filename.c_str());
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
 
         ml.newItem(3, "key1", 1);
@@ -404,71 +418,64 @@ static void testLoggingBadCRC() {
         ml.commit2();
         // Remaining:   3:key2, 2:key1
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 3);
-        cb_assert(ml.itemsLogged[ML_DEL] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 2);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 2);
+        EXPECT_EQ(3, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_DEL]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT2]);
     }
 
     // Break the log
-    int file = open(TMP_LOG_FILE, O_RDWR, FilePerms::Read | FilePerms::Write);
-    cb_assert(lseek(file, 5000, SEEK_SET) == 5000);
+    int file = open(tmp_log_filename.c_str(), O_RDWR, FilePerms::Read | FilePerms::Write);
+    EXPECT_EQ(5000, lseek(file, 5000, SEEK_SET));
     uint8_t b;
-    cb_assert(read(file, &b, sizeof(b)) == 1);
-    cb_assert(lseek(file, 5000, SEEK_SET) == 5000);
+    EXPECT_EQ(1, read(file, &b, sizeof(b)));
+    EXPECT_EQ(5000, lseek(file, 5000, SEEK_SET));
     b = ~b;
-    cb_assert(write(file, &b, sizeof(b)) == 1);
+    EXPECT_EQ(1, write(file, &b, sizeof(b)));
     close(file);
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
         MutationLogHarvester h(ml);
         h.setVBucket(1);
         h.setVBucket(2);
         h.setVBucket(3);
 
-        try {
-            h.load();
-            abort();
-        } catch(MutationLog::CRCReadException &e) {
-            // expected
-        }
+        EXPECT_THROW(h.load(), MutationLog::CRCReadException);
 
-        cb_assert(h.getItemsSeen()[ML_NEW] == 0);
-        cb_assert(h.getItemsSeen()[ML_DEL] == 0);
-        cb_assert(h.getItemsSeen()[ML_COMMIT1] == 0);
-        cb_assert(h.getItemsSeen()[ML_COMMIT2] == 0);
+        EXPECT_EQ(0, h.getItemsSeen()[ML_NEW]);
+        EXPECT_EQ(0, h.getItemsSeen()[ML_DEL]);
+        EXPECT_EQ(0, h.getItemsSeen()[ML_COMMIT1]);
+        EXPECT_EQ(0, h.getItemsSeen()[ML_COMMIT2]);
 
         // Check stat copying
         ml.resetCounts(h.getItemsSeen());
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 0);
-        cb_assert(ml.itemsLogged[ML_DEL] == 0);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 0);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 0);
+        EXPECT_EQ(0, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(0, ml.itemsLogged[ML_DEL]);
+        EXPECT_EQ(0, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(0, ml.itemsLogged[ML_COMMIT2]);
 
         // See if we got what we expect.
         std::map<std::string, uint64_t> maps[4];
         h.apply(&maps, loaderFun);
 
-        cb_assert(maps[0].size() == 0);
-        cb_assert(maps[1].size() == 0);
-        cb_assert(maps[2].size() == 0);
-        cb_assert(maps[3].size() == 0);
+        EXPECT_EQ(0, maps[0].size());
+        EXPECT_EQ(0, maps[1].size());
+        EXPECT_EQ(0, maps[2].size());
+        EXPECT_EQ(0, maps[3].size());
 
-        cb_assert(maps[2].find("key1") == maps[2].end());
-        cb_assert(maps[3].find("key2") == maps[3].end());
+        EXPECT_EQ(maps[2].end(), maps[2].find("key1"));
+        EXPECT_EQ(maps[3].end(), maps[3].find("key2"));
     }
-
-    remove(TMP_LOG_FILE);
 }
 
-static void testLoggingShortRead() {
-    remove(TMP_LOG_FILE);
+TEST_F(MutationLogTest, LoggingShortRead) {
+    remove(tmp_log_filename.c_str());
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
 
         ml.newItem(3, "key1", 1);
@@ -481,67 +488,45 @@ static void testLoggingShortRead() {
         ml.commit2();
         // Remaining:   3:key2, 2:key1
 
-        cb_assert(ml.itemsLogged[ML_NEW] == 3);
-        cb_assert(ml.itemsLogged[ML_DEL] == 1);
-        cb_assert(ml.itemsLogged[ML_COMMIT1] == 2);
-        cb_assert(ml.itemsLogged[ML_COMMIT2] == 2);
+        EXPECT_EQ(3, ml.itemsLogged[ML_NEW]);
+        EXPECT_EQ(1, ml.itemsLogged[ML_DEL]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT1]);
+        EXPECT_EQ(2, ml.itemsLogged[ML_COMMIT2]);
     }
 
     // Break the log
-    cb_assert(truncate(TMP_LOG_FILE, 5000) == 0);
+    EXPECT_EQ(0, truncate(tmp_log_filename.c_str(), 5000));
 
     {
-        MutationLog ml(TMP_LOG_FILE);
-        try {
-            ml.open();
-            MutationLogHarvester h(ml);
-            h.setVBucket(1);
-            h.setVBucket(2);
-            h.setVBucket(3);
-
-            h.load();
-            abort();
-        } catch(MutationLog::ShortReadException &e) {
-            // expected
-        }
+        MutationLog ml(tmp_log_filename.c_str());
+
+        ml.open();
+        MutationLogHarvester h(ml);
+        h.setVBucket(1);
+        h.setVBucket(2);
+        h.setVBucket(3);
+
+        EXPECT_THROW(h.load(), MutationLog::ShortReadException);
     }
 
     // Break the log harder (can't read even the initial block)
     // This should succeed as open() will call reset() to give us a usable
     // mutation log.
-    cb_assert(truncate(TMP_LOG_FILE, 4000) == 0);
+    EXPECT_EQ(0, truncate(tmp_log_filename.c_str(), 4000));
 
     {
-        MutationLog ml(TMP_LOG_FILE);
+        MutationLog ml(tmp_log_filename.c_str());
         ml.open();
     }
-
-    remove(TMP_LOG_FILE);
 }
 
-static void testYUNOOPEN() {
-    int file = open(TMP_LOG_FILE, O_CREAT|O_RDWR, 0);
-    set_file_perms(TMP_LOG_FILE, FilePerms::None);
-    cb_assert(file >= 0);
-    close(file);
-    MutationLog ml(TMP_LOG_FILE);
-    try {
-        ml.open();
-        abort();
-    } catch(MutationLog::ReadException &e) {
-        const std::string exp("Unable to open log file:");
-        // This is kind of a soft assertion.  The actual text may vary.
-        if (exp.compare(0, exp.size(), e.what(), exp.size()) != 0) {
-            std::cerr << "Expected ``" << exp << "'', got: " << e.what() << std::endl;
-        }
-    }
-
+TEST_F(MutationLogTest, YUNOOPEN) {
+    // Make file unreadable
+    set_file_perms(FilePerms::None);
+    MutationLog ml(tmp_log_filename.c_str());
+    EXPECT_THROW(ml.open(), MutationLog::ReadException);
     // Restore permissions to be able to delete file.
-    set_file_perms(TMP_LOG_FILE, FilePerms::Read | FilePerms::Write);
-    if (remove(TMP_LOG_FILE) != 0)
-    {
-        std::cerr << "testYUNOOPEN: remove failed: " << cb_strerror() << std::endl;
-    }
+    set_file_perms(FilePerms::Read | FilePerms::Write);
 }
 
 // @todo
@@ -550,15 +535,12 @@ static void testYUNOOPEN() {
 //   Fix copy constructor bug
 //
 
-static void testReadOnly() {
-    MutationLog ml(TMP_LOG_FILE);
-    try {
-        ml.open(true);
-        abort();
-    } catch (MutationLog::FileNotFoundException &e) {
-    }
+TEST_F(MutationLogTest, ReadOnly) {
+    remove(tmp_log_filename.c_str());
+    MutationLog ml(tmp_log_filename.c_str());
+    EXPECT_THROW(ml.open(true), MutationLog::FileNotFoundException);
 
-    MutationLog m2(TMP_LOG_FILE);
+    MutationLog m2(tmp_log_filename);
     m2.open();
     m2.newItem(3, "key1", 1);
     m2.close();
@@ -567,25 +549,5 @@ static void testReadOnly() {
     ml.open(true);
 
     // But we should not be able to add items to a read only stream
-    try {
-        ml.newItem(4, "key2", 1);
-        abort();
-    } catch (MutationLog::WriteException &e) {
-    }
-}
-
-int main(int, char **) {
-    remove(TMP_LOG_FILE);
-    testReadOnly();
-    testUnconfigured();
-    testSyncSet();
-    testLogging();
-    testDelAll();
-    testLoggingDirty();
-    testLoggingBadCRC();
-    testLoggingShortRead();
-    testYUNOOPEN();
-
-    remove(TMP_LOG_FILE);
-    return 0;
+    EXPECT_THROW(ml.newItem(4, "key2", 1), MutationLog::WriteException);
 }