diff options
author | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2019-06-13 16:25:25 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2019-06-14 10:42:18 +0000 |
commit | 71947d62ce117cd5803ca03c1e63e8e9db9e8a86 (patch) | |
tree | 98981c0b067e9eab9696bc29ffc8c5d0e7556d82 /storage/src/tests/visiting/commandqueuetest.cpp | |
parent | 98187c9181c2acc140e8556a5a9cfd8b8bda1764 (diff) |
Convert storageserver and visiting tests from CppUnit to GTest
Diffstat (limited to 'storage/src/tests/visiting/commandqueuetest.cpp')
-rw-r--r-- | storage/src/tests/visiting/commandqueuetest.cpp | 199 |
1 files changed, 93 insertions, 106 deletions
diff --git a/storage/src/tests/visiting/commandqueuetest.cpp b/storage/src/tests/visiting/commandqueuetest.cpp index e335df353f6..c152e4c5191 100644 --- a/storage/src/tests/visiting/commandqueuetest.cpp +++ b/storage/src/tests/visiting/commandqueuetest.cpp @@ -3,62 +3,44 @@ #include <vespa/storageframework/defaultimplementation/clock/fakeclock.h> #include <vespa/storage/visiting/commandqueue.h> #include <vespa/storageapi/message/visitor.h> -#include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/document/test/make_bucket_space.h> - +#include <vespa/vespalib/gtest/gtest.h> using vespalib::string; using document::test::makeBucketSpace; +using namespace ::testing; namespace storage { -struct CommandQueueTest : public CppUnit::TestFixture -{ - void testFIFO(); - void testFIFOWithPriorities(); - void testReleaseOldest(); - void testReleaseLowestPriority(); - void testDeleteIterator(); - - CPPUNIT_TEST_SUITE(CommandQueueTest); - CPPUNIT_TEST(testFIFO); - CPPUNIT_TEST(testFIFOWithPriorities); - CPPUNIT_TEST(testReleaseOldest); - CPPUNIT_TEST(testReleaseLowestPriority); - CPPUNIT_TEST(testDeleteIterator); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(CommandQueueTest); - namespace { - std::shared_ptr<api::CreateVisitorCommand> getCommand( - vespalib::stringref name, int timeout, - uint8_t priority = 0) - { - vespalib::asciistream ost; - ost << name << " t=" << timeout << " p=" << static_cast<unsigned int>(priority); - // Piggyback name in document selection - std::shared_ptr<api::CreateVisitorCommand> cmd( - new api::CreateVisitorCommand(makeBucketSpace(), "", "", ost.str())); - cmd->setQueueTimeout(timeout); - cmd->setPriority(priority); - return cmd; - } - const vespalib::string & - getCommandString(const std::shared_ptr<api::CreateVisitorCommand>& cmd) - { - return cmd->getDocumentSelection(); - } +std::shared_ptr<api::CreateVisitorCommand> getCommand( + vespalib::stringref name, int timeout, + uint8_t priority = 0) +{ + vespalib::asciistream ost; + ost << name << " t=" << timeout << " p=" << static_cast<unsigned int>(priority); + // Piggyback name in document selection + std::shared_ptr<api::CreateVisitorCommand> cmd( + new api::CreateVisitorCommand(makeBucketSpace(), "", "", ost.str())); + cmd->setQueueTimeout(timeout); + cmd->setPriority(priority); + return cmd; +} +const vespalib::string & +getCommandString(const std::shared_ptr<api::CreateVisitorCommand>& cmd) +{ + return cmd->getDocumentSelection(); } -void CommandQueueTest::testFIFO() { +} + +TEST(CommandQueueTest, fifo) { framework::defaultimplementation::FakeClock clock; CommandQueue<api::CreateVisitorCommand> queue(clock); - CPPUNIT_ASSERT(queue.empty()); + ASSERT_TRUE(queue.empty()); // Use all default priorities, meaning what comes out should be in the same order // as what went in queue.add(getCommand("first", 1)); @@ -69,64 +51,66 @@ void CommandQueueTest::testFIFO() { queue.add(getCommand("sixth", 14)); queue.add(getCommand("seventh", 7)); - CPPUNIT_ASSERT(!queue.empty()); - std::vector<std::shared_ptr<api::CreateVisitorCommand> > commands; + ASSERT_FALSE(queue.empty()); + std::vector<std::shared_ptr<api::CreateVisitorCommand>> commands; for (;;) { std::shared_ptr<api::CreateVisitorCommand> cmd( queue.releaseNextCommand().first); if (cmd.get() == 0) break; commands.push_back(cmd); } - CPPUNIT_ASSERT_EQUAL(size_t(7), commands.size()); - CPPUNIT_ASSERT_EQUAL(string("first t=1 p=0"), getCommandString(commands[0])); - CPPUNIT_ASSERT_EQUAL(string("second t=10 p=0"), getCommandString(commands[1])); - CPPUNIT_ASSERT_EQUAL(string("third t=5 p=0"), getCommandString(commands[2])); - CPPUNIT_ASSERT_EQUAL(string("fourth t=0 p=0"), getCommandString(commands[3])); - CPPUNIT_ASSERT_EQUAL(string("fifth t=3 p=0"), getCommandString(commands[4])); - CPPUNIT_ASSERT_EQUAL(string("sixth t=14 p=0"), getCommandString(commands[5])); - CPPUNIT_ASSERT_EQUAL(string("seventh t=7 p=0"), getCommandString(commands[6])); + ASSERT_EQ(7, commands.size()); + EXPECT_EQ("first t=1 p=0", getCommandString(commands[0])); + EXPECT_EQ("second t=10 p=0", getCommandString(commands[1])); + EXPECT_EQ("third t=5 p=0", getCommandString(commands[2])); + EXPECT_EQ("fourth t=0 p=0", getCommandString(commands[3])); + EXPECT_EQ("fifth t=3 p=0", getCommandString(commands[4])); + EXPECT_EQ("sixth t=14 p=0", getCommandString(commands[5])); + EXPECT_EQ("seventh t=7 p=0", getCommandString(commands[6])); } -void CommandQueueTest::testFIFOWithPriorities() { +TEST(CommandQueueTest, fifo_with_priorities) { framework::defaultimplementation::FakeClock clock; CommandQueue<api::CreateVisitorCommand> queue(clock); - CPPUNIT_ASSERT(queue.empty()); + ASSERT_TRUE(queue.empty()); queue.add(getCommand("first", 1, 10)); - CPPUNIT_ASSERT_EQUAL(string("first t=1 p=10"), getCommandString(queue.peekLowestPriorityCommand())); + EXPECT_EQ("first t=1 p=10", getCommandString(queue.peekLowestPriorityCommand())); queue.add(getCommand("second", 10, 22)); queue.add(getCommand("third", 5, 9)); - CPPUNIT_ASSERT_EQUAL(string("second t=10 p=22"), getCommandString(queue.peekLowestPriorityCommand())); + EXPECT_EQ("second t=10 p=22", getCommandString(queue.peekLowestPriorityCommand())); queue.add(getCommand("fourth", 0, 22)); queue.add(getCommand("fifth", 3, 22)); - CPPUNIT_ASSERT_EQUAL(string("fifth t=3 p=22"), getCommandString(queue.peekLowestPriorityCommand())); + EXPECT_EQ("fifth t=3 p=22", getCommandString(queue.peekLowestPriorityCommand())); queue.add(getCommand("sixth", 14, 50)); queue.add(getCommand("seventh", 7, 0)); - CPPUNIT_ASSERT_EQUAL(string("sixth t=14 p=50"), getCommandString(queue.peekLowestPriorityCommand())); + EXPECT_EQ("sixth t=14 p=50", getCommandString(queue.peekLowestPriorityCommand())); - CPPUNIT_ASSERT(!queue.empty()); - std::vector<std::shared_ptr<api::CreateVisitorCommand> > commands; + ASSERT_FALSE(queue.empty()); + std::vector<std::shared_ptr<api::CreateVisitorCommand>> commands; for (;;) { std::shared_ptr<api::CreateVisitorCommand> cmdPeek(queue.peekNextCommand()); std::shared_ptr<api::CreateVisitorCommand> cmd(queue.releaseNextCommand().first); - if (cmd.get() == 0 || cmdPeek != cmd) break; + if (cmd.get() == 0 || cmdPeek != cmd) { + break; + } commands.push_back(cmd); } - CPPUNIT_ASSERT_EQUAL(size_t(7), commands.size()); - CPPUNIT_ASSERT_EQUAL(string("seventh t=7 p=0"), getCommandString(commands[0])); - CPPUNIT_ASSERT_EQUAL(string("third t=5 p=9"), getCommandString(commands[1])); - CPPUNIT_ASSERT_EQUAL(string("first t=1 p=10"), getCommandString(commands[2])); - CPPUNIT_ASSERT_EQUAL(string("second t=10 p=22"), getCommandString(commands[3])); - CPPUNIT_ASSERT_EQUAL(string("fourth t=0 p=22"), getCommandString(commands[4])); - CPPUNIT_ASSERT_EQUAL(string("fifth t=3 p=22"), getCommandString(commands[5])); - CPPUNIT_ASSERT_EQUAL(string("sixth t=14 p=50"), getCommandString(commands[6])); + ASSERT_EQ(7, commands.size()); + EXPECT_EQ("seventh t=7 p=0", getCommandString(commands[0])); + EXPECT_EQ("third t=5 p=9", getCommandString(commands[1])); + EXPECT_EQ("first t=1 p=10", getCommandString(commands[2])); + EXPECT_EQ("second t=10 p=22", getCommandString(commands[3])); + EXPECT_EQ("fourth t=0 p=22", getCommandString(commands[4])); + EXPECT_EQ("fifth t=3 p=22", getCommandString(commands[5])); + EXPECT_EQ("sixth t=14 p=50", getCommandString(commands[6])); } -void CommandQueueTest::testReleaseOldest() { +TEST(CommandQueueTest, release_oldest) { framework::defaultimplementation::FakeClock clock(framework::defaultimplementation::FakeClock::FAKE_ABSOLUTE); CommandQueue<api::CreateVisitorCommand> queue(clock); - CPPUNIT_ASSERT(queue.empty()); + ASSERT_TRUE(queue.empty()); queue.add(getCommand("first", 10)); queue.add(getCommand("second", 100)); queue.add(getCommand("third", 1000)); @@ -134,32 +118,31 @@ void CommandQueueTest::testReleaseOldest() { queue.add(getCommand("fifth", 3000)); queue.add(getCommand("sixth", 400)); queue.add(getCommand("seventh", 700)); - CPPUNIT_ASSERT_EQUAL(7u, queue.size()); + ASSERT_EQ(7u, queue.size()); - typedef CommandQueue<api::CreateVisitorCommand>::CommandEntry CommandEntry; + using CommandEntry = CommandQueue<api::CreateVisitorCommand>::CommandEntry; std::list<CommandEntry> timedOut(queue.releaseTimedOut()); - CPPUNIT_ASSERT(timedOut.empty()); + ASSERT_TRUE(timedOut.empty()); clock.addMilliSecondsToTime(400 * 1000); timedOut = queue.releaseTimedOut(); - CPPUNIT_ASSERT_EQUAL(size_t(4), timedOut.size()); + ASSERT_EQ(4, timedOut.size()); std::ostringstream ost; for (std::list<CommandEntry>::const_iterator it = timedOut.begin(); it != timedOut.end(); ++it) { ost << getCommandString(it->_command) << "\n"; } - CPPUNIT_ASSERT_EQUAL(std::string( - "fourth t=5 p=0\n" - "first t=10 p=0\n" - "second t=100 p=0\n" - "sixth t=400 p=0\n"), ost.str()); - CPPUNIT_ASSERT_EQUAL(3u, queue.size()); + EXPECT_EQ("fourth t=5 p=0\n" + "first t=10 p=0\n" + "second t=100 p=0\n" + "sixth t=400 p=0\n", ost.str()); + EXPECT_EQ(3u, queue.size()); } -void CommandQueueTest::testReleaseLowestPriority() { +TEST(CommandQueueTest, release_lowest_priority) { framework::defaultimplementation::FakeClock clock; CommandQueue<api::CreateVisitorCommand> queue(clock); - CPPUNIT_ASSERT(queue.empty()); + ASSERT_TRUE(queue.empty()); queue.add(getCommand("first", 1, 10)); queue.add(getCommand("second", 10, 22)); @@ -168,30 +151,32 @@ void CommandQueueTest::testReleaseLowestPriority() { queue.add(getCommand("fifth", 3, 22)); queue.add(getCommand("sixth", 14, 50)); queue.add(getCommand("seventh", 7, 0)); - CPPUNIT_ASSERT_EQUAL(7u, queue.size()); + ASSERT_EQ(7u, queue.size()); - std::vector<std::shared_ptr<api::CreateVisitorCommand> > commands; + std::vector<std::shared_ptr<api::CreateVisitorCommand>> commands; for (;;) { std::shared_ptr<api::CreateVisitorCommand> cmdPeek(queue.peekLowestPriorityCommand()); std::pair<std::shared_ptr<api::CreateVisitorCommand>, uint64_t> cmd( queue.releaseLowestPriorityCommand()); - if (cmd.first.get() == 0 || cmdPeek != cmd.first) break; + if (cmd.first.get() == 0 || cmdPeek != cmd.first) { + break; + } commands.push_back(cmd.first); } - CPPUNIT_ASSERT_EQUAL(size_t(7), commands.size()); - CPPUNIT_ASSERT_EQUAL(string("sixth t=14 p=50"), getCommandString(commands[0])); - CPPUNIT_ASSERT_EQUAL(string("fifth t=3 p=22"), getCommandString(commands[1])); - CPPUNIT_ASSERT_EQUAL(string("fourth t=0 p=22"), getCommandString(commands[2])); - CPPUNIT_ASSERT_EQUAL(string("second t=10 p=22"), getCommandString(commands[3])); - CPPUNIT_ASSERT_EQUAL(string("first t=1 p=10"), getCommandString(commands[4])); - CPPUNIT_ASSERT_EQUAL(string("third t=5 p=9"), getCommandString(commands[5])); - CPPUNIT_ASSERT_EQUAL(string("seventh t=7 p=0"), getCommandString(commands[6])); + ASSERT_EQ(7, commands.size()); + EXPECT_EQ("sixth t=14 p=50", getCommandString(commands[0])); + EXPECT_EQ("fifth t=3 p=22", getCommandString(commands[1])); + EXPECT_EQ("fourth t=0 p=22", getCommandString(commands[2])); + EXPECT_EQ("second t=10 p=22", getCommandString(commands[3])); + EXPECT_EQ("first t=1 p=10", getCommandString(commands[4])); + EXPECT_EQ("third t=5 p=9", getCommandString(commands[5])); + EXPECT_EQ("seventh t=7 p=0", getCommandString(commands[6])); } -void CommandQueueTest::testDeleteIterator() { +TEST(CommandQueueTest, delete_iterator) { framework::defaultimplementation::FakeClock clock; CommandQueue<api::CreateVisitorCommand> queue(clock); - CPPUNIT_ASSERT(queue.empty()); + ASSERT_TRUE(queue.empty()); queue.add(getCommand("first", 10)); queue.add(getCommand("second", 100)); queue.add(getCommand("third", 1000)); @@ -199,28 +184,30 @@ void CommandQueueTest::testDeleteIterator() { queue.add(getCommand("fifth", 3000)); queue.add(getCommand("sixth", 400)); queue.add(getCommand("seventh", 700)); - CPPUNIT_ASSERT_EQUAL(7u, queue.size()); + ASSERT_EQ(7u, queue.size()); CommandQueue<api::CreateVisitorCommand>::iterator it = queue.begin(); ++it; ++it; queue.erase(it); - CPPUNIT_ASSERT_EQUAL(6u, queue.size()); + ASSERT_EQ(6u, queue.size()); - std::vector<std::shared_ptr<api::CreateVisitorCommand> > cmds; + std::vector<std::shared_ptr<api::CreateVisitorCommand>> cmds; for (;;) { std::shared_ptr<api::CreateVisitorCommand> cmd( std::dynamic_pointer_cast<api::CreateVisitorCommand>( queue.releaseNextCommand().first)); - if (cmd.get() == 0) break; + if (cmd.get() == 0) { + break; + } cmds.push_back(cmd); } - CPPUNIT_ASSERT_EQUAL(size_t(6), cmds.size()); - CPPUNIT_ASSERT_EQUAL(string("first t=10 p=0"), getCommandString(cmds[0])); - CPPUNIT_ASSERT_EQUAL(string("second t=100 p=0"), getCommandString(cmds[1])); - CPPUNIT_ASSERT_EQUAL(string("fourth t=5 p=0"), getCommandString(cmds[2])); - CPPUNIT_ASSERT_EQUAL(string("fifth t=3000 p=0"), getCommandString(cmds[3])); - CPPUNIT_ASSERT_EQUAL(string("sixth t=400 p=0"), getCommandString(cmds[4])); - CPPUNIT_ASSERT_EQUAL(string("seventh t=700 p=0"), getCommandString(cmds[5])); + ASSERT_EQ(6, cmds.size()); + EXPECT_EQ("first t=10 p=0", getCommandString(cmds[0])); + EXPECT_EQ("second t=100 p=0", getCommandString(cmds[1])); + EXPECT_EQ("fourth t=5 p=0", getCommandString(cmds[2])); + EXPECT_EQ("fifth t=3000 p=0", getCommandString(cmds[3])); + EXPECT_EQ("sixth t=400 p=0", getCommandString(cmds[4])); + EXPECT_EQ("seventh t=700 p=0", getCommandString(cmds[5])); } } |