diff options
author | Geir Storli <geirst@verizonmedia.com> | 2019-05-22 09:00:45 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2019-05-22 09:00:45 +0000 |
commit | 81504359b44b379eb0f3c9a45f899171ab862343 (patch) | |
tree | 7731150a931793562aa8551a7e9bd28c860e5055 /vdslib/src/tests | |
parent | 11b0f0b29f816e9208afdc787615b9fe0e8575a1 (diff) |
Rewrite vdslib tests from cppunit to gtest.
Diffstat (limited to 'vdslib/src/tests')
-rw-r--r-- | vdslib/src/tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | vdslib/src/tests/state/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vdslib/src/tests/state/cluster_state_bundle_test.cpp | 40 | ||||
-rw-r--r-- | vdslib/src/tests/state/clusterstatetest.cpp | 204 | ||||
-rw-r--r-- | vdslib/src/tests/state/nodestatetest.cpp | 113 | ||||
-rw-r--r-- | vdslib/src/tests/thread/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vdslib/src/tests/thread/taskschedulertest.cpp | 59 |
7 files changed, 150 insertions, 272 deletions
diff --git a/vdslib/src/tests/CMakeLists.txt b/vdslib/src/tests/CMakeLists.txt index 0c9ae7e0048..084320ee059 100644 --- a/vdslib/src/tests/CMakeLists.txt +++ b/vdslib/src/tests/CMakeLists.txt @@ -8,6 +8,8 @@ vespa_add_executable(vdslib_gtest_runner_app TEST DEPENDS vdslib_bucketdistributiontest vdslib_containertest + vdslib_teststate + vdslib_testthread gtest ) @@ -22,8 +24,6 @@ vespa_add_executable(vdslib_testrunner_app TEST testrunner.cpp DEPENDS vdslib_testdistribution - vdslib_teststate - vdslib_testthread ) # TODO: Test with a larger chunk size to parallelize test suite runs diff --git a/vdslib/src/tests/state/CMakeLists.txt b/vdslib/src/tests/state/CMakeLists.txt index 8b1957a91bb..6308e06e3f1 100644 --- a/vdslib/src/tests/state/CMakeLists.txt +++ b/vdslib/src/tests/state/CMakeLists.txt @@ -6,4 +6,5 @@ vespa_add_library(vdslib_teststate nodestatetest.cpp DEPENDS vdslib + gtest ) diff --git a/vdslib/src/tests/state/cluster_state_bundle_test.cpp b/vdslib/src/tests/state/cluster_state_bundle_test.cpp index 4798fe505f8..bfd83673442 100644 --- a/vdslib/src/tests/state/cluster_state_bundle_test.cpp +++ b/vdslib/src/tests/state/cluster_state_bundle_test.cpp @@ -2,8 +2,7 @@ #include <vespa/vdslib/state/cluster_state_bundle.h> #include <vespa/vdslib/state/clusterstate.h> - -#include <cppunit/extensions/HelperMacros.h> +#include <vespa/vespalib/gtest/gtest.h> using document::BucketSpace; @@ -11,20 +10,6 @@ namespace storage::lib { using ClusterStatePtr = std::shared_ptr<const ClusterState>; -struct ClusterStateBundleTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ClusterStateBundleTest); - CPPUNIT_TEST(derived_state_is_returned_if_bucket_space_is_found); - CPPUNIT_TEST(baseline_state_is_returned_if_bucket_space_is_not_found); - CPPUNIT_TEST(verify_equality_operator); - CPPUNIT_TEST_SUITE_END(); - - void derived_state_is_returned_if_bucket_space_is_found(); - void baseline_state_is_returned_if_bucket_space_is_not_found(); - void verify_equality_operator(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ClusterStateBundleTest); - struct Fixture { ClusterState baselineState; ClusterStatePtr derivedState; @@ -37,18 +22,16 @@ struct Fixture { ~Fixture() {} }; -void -ClusterStateBundleTest::derived_state_is_returned_if_bucket_space_is_found() +TEST(ClusterStateBundleTest, derived_state_is_returned_if_bucket_space_is_found) { Fixture f; - CPPUNIT_ASSERT_EQUAL(*f.derivedState, *f.bundle.getDerivedClusterState(BucketSpace(1))); + EXPECT_EQ(*f.derivedState, *f.bundle.getDerivedClusterState(BucketSpace(1))); } -void -ClusterStateBundleTest::baseline_state_is_returned_if_bucket_space_is_not_found() +TEST(ClusterStateBundleTest, baseline_state_is_returned_if_bucket_space_is_not_found) { Fixture f; - CPPUNIT_ASSERT_EQUAL(f.baselineState, *f.bundle.getDerivedClusterState(BucketSpace(2))); + EXPECT_EQ(f.baselineState, *f.bundle.getDerivedClusterState(BucketSpace(2))); } ClusterStateBundle @@ -61,16 +44,15 @@ makeBundle(const vespalib::string &baselineState, const std::map<BucketSpace, ve return ClusterStateBundle(ClusterState(baselineState), std::move(derivedBucketSpaceStates)); } -void -ClusterStateBundleTest::verify_equality_operator() +TEST(ClusterStateBundleTest, verify_equality_operator) { Fixture f; - CPPUNIT_ASSERT(f.bundle != makeBundle("storage:3", {{BucketSpace(1), "storage:2 .1.s:m"}})); - CPPUNIT_ASSERT(f.bundle != makeBundle("storage:2", {})); - CPPUNIT_ASSERT(f.bundle != makeBundle("storage:2", {{BucketSpace(1), "storage:2 .0.s:m"}})); - CPPUNIT_ASSERT(f.bundle != makeBundle("storage:2", {{BucketSpace(2), "storage:2 .1.s:m"}})); + EXPECT_NE(f.bundle, makeBundle("storage:3", {{BucketSpace(1), "storage:2 .1.s:m"}})); + EXPECT_NE(f.bundle, makeBundle("storage:2", {})); + EXPECT_NE(f.bundle, makeBundle("storage:2", {{BucketSpace(1), "storage:2 .0.s:m"}})); + EXPECT_NE(f.bundle, makeBundle("storage:2", {{BucketSpace(2), "storage:2 .1.s:m"}})); - CPPUNIT_ASSERT_EQUAL(f.bundle, makeBundle("storage:2", {{BucketSpace(1), "storage:2 .1.s:m"}})); + EXPECT_EQ(f.bundle, makeBundle("storage:2", {{BucketSpace(1), "storage:2 .1.s:m"}})); } } diff --git a/vdslib/src/tests/state/clusterstatetest.cpp b/vdslib/src/tests/state/clusterstatetest.cpp index 8cdde1bbc00..143f3aed0e9 100644 --- a/vdslib/src/tests/state/clusterstatetest.cpp +++ b/vdslib/src/tests/state/clusterstatetest.cpp @@ -1,79 +1,37 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/document/bucket/bucketidfactory.h> #include <vespa/vdslib/state/clusterstate.h> -#include <vespa/vespalib/util/exception.h> +#include <vespa/vdslib/state/random.h> +#include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/stllike/asciistream.h> -#include <vespa/document/bucket/bucketidfactory.h> +#include <vespa/vespalib/util/exception.h> #include <cmath> -#include <vespa/vdslib/state/random.h> -#include <vespa/vdstestlib/cppunit/macros.h> +#include <gmock/gmock.h> using vespalib::string; +using ::testing::ContainsRegex; -namespace storage { -namespace lib { - -struct ClusterStateTest : public CppUnit::TestFixture { - - void testBasicFunctionality(); - void testErrorBehaviour(); - void testBackwardsCompability(); - void testDetailed(); - void testParseFailure(); - void testParseFailureGroups(); - - void testDiff(); - - CPPUNIT_TEST_SUITE(ClusterStateTest); - CPPUNIT_TEST(testBasicFunctionality); - CPPUNIT_TEST(testErrorBehaviour); - CPPUNIT_TEST(testBackwardsCompability); - CPPUNIT_TEST(testDetailed); - - // Ideal state tests. - CPPUNIT_TEST(testParseFailure); - CPPUNIT_TEST(testParseFailureGroups); - CPPUNIT_TEST(testDiff); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ClusterStateTest); - -void -ClusterStateTest::testDiff() { - ClusterState state1("distributor:9 storage:4"); - ClusterState state2("distributor:7 storage:6"); - ClusterState state3("distributor:9 storage:2"); - CPPUNIT_ASSERT_EQUAL( - std::string("storage [4: d to u, 5: d to u] " - "distributor [7: u to d, 8: u to d]"), - state1.getTextualDifference(state2)); - CPPUNIT_ASSERT_EQUAL( - std::string("storage [2: u to d, 3: u to d, 4: u to d, 5: u to d] " - "distributor [7: d to u, 8: d to u]"), - state2.getTextualDifference(state3)); -} - +namespace storage::lib { #define VERIFY3(source, result, type, typestr) { \ vespalib::asciistream ost; \ - try{ \ + try { \ state->serialize(ost, type); \ } catch (std::exception& e) { \ - CPPUNIT_FAIL("Failed to serialize system state " \ + FAIL() << ("Failed to serialize system state " \ + state->toString(true) + " in " + std::string(typestr) \ + " format: " + std::string(e.what())); \ } \ - CPPUNIT_ASSERT_EQUAL_MSG(vespalib::string(state->toString(true)), \ - vespalib::string(typestr) + " \"" + vespalib::string(result) + "\"", \ - vespalib::string(typestr) + " \"" + ost.str() + "\""); \ + EXPECT_EQ(vespalib::string(typestr) + " \"" + vespalib::string(result) + "\"", \ + vespalib::string(typestr) + " \"" + ost.str() + "\"") << state->toString(true); \ } #define VERIFY2(serialized, result, testOld, testNew) { \ std::unique_ptr<ClusterState> state; \ - try{ \ + try { \ state.reset(new ClusterState(serialized)); \ } catch (std::exception& e) { \ - CPPUNIT_FAIL("Failed to parse '" + std::string(serialized) \ + FAIL() << ("Failed to parse '" + std::string(serialized) \ + "': " + e.what()); \ } \ if (testOld) VERIFY3(serialized, result, true, "Old") \ @@ -90,15 +48,14 @@ ClusterStateTest::testDiff() { #define VERIFY_FAIL(serialized, error) { \ try{ \ ClusterState state(serialized); \ - CPPUNIT_FAIL("Parsing the state '" + std::string(serialized) \ + FAIL() << ("Parsing the state '" + std::string(serialized) \ + "' is supposed to fail."); \ } catch (vespalib::Exception& e) { \ - CPPUNIT_ASSERT_MATCH_REGEX(error, e.getMessage()); \ + EXPECT_THAT(e.getMessage(), ContainsRegex(error)); \ } \ } -void -ClusterStateTest::testBasicFunctionality() +TEST(ClusterStateTest, test_basic_functionality) { // Version is default and should not be written VERIFYNEW("version:0", ""); @@ -144,31 +101,30 @@ ClusterStateTest::testBasicFunctionality() { ClusterState state("storage:5 .4.s:d .4.m:Foo\\x20bar"); const NodeState& ns(state.getNodeState(Node(NodeType::STORAGE, 4))); - CPPUNIT_ASSERT_EQUAL(string("Foo bar"), ns.getDescription()); + EXPECT_EQ(string("Foo bar"), ns.getDescription()); } ClusterState state; state.setClusterState(State::UP); state.setNodeState(Node(NodeType::DISTRIBUTOR, 3), NodeState(NodeType::DISTRIBUTOR, State::UP)); - CPPUNIT_ASSERT_EQUAL(std::string("distributor:4 .0.s:d .1.s:d .2.s:d"), - state.toString(false)); + EXPECT_EQ(std::string("distributor:4 .0.s:d .1.s:d .2.s:d"), + state.toString(false)); state.setNodeState(Node(NodeType::DISTRIBUTOR, 1), NodeState(NodeType::DISTRIBUTOR, State::UP)); - CPPUNIT_ASSERT_EQUAL(std::string("distributor:4 .0.s:d .2.s:d"), - state.toString(false)); + EXPECT_EQ(std::string("distributor:4 .0.s:d .2.s:d"), + state.toString(false)); state.setNodeState(Node(NodeType::DISTRIBUTOR, 3), NodeState(NodeType::DISTRIBUTOR, State::DOWN)); - CPPUNIT_ASSERT_EQUAL(std::string("distributor:2 .0.s:d"), - state.toString(false)); + EXPECT_EQ(std::string("distributor:2 .0.s:d"), + state.toString(false)); state.setNodeState(Node(NodeType::DISTRIBUTOR, 4), NodeState(NodeType::DISTRIBUTOR, State::UP)); - CPPUNIT_ASSERT_EQUAL(std::string("distributor:5 .0.s:d .2.s:d .3.s:d"), - state.toString(false)); + EXPECT_EQ(std::string("distributor:5 .0.s:d .2.s:d .3.s:d"), + state.toString(false)); } -void -ClusterStateTest::testErrorBehaviour() +TEST(ClusterStateTest, test_error_behaviour) { // Keys with invalid values @@ -215,8 +171,7 @@ ClusterStateTest::testErrorBehaviour() "distributor:4 .2.s:s storage:10 .3.s:s .3.d:4"); } -void -ClusterStateTest::testBackwardsCompability() +TEST(ClusterStateTest, test_backwards_compability) { // 4.1 and older nodes do not support some features, and the java parser // do not allow unknown elements as it was supposed to do, thus we should @@ -243,8 +198,7 @@ ClusterStateTest::testBackwardsCompability() } -void -ClusterStateTest::testDetailed() +TEST(ClusterStateTest, test_detailed) { ClusterState state( "version:314 cluster:i " @@ -252,35 +206,35 @@ ClusterStateTest::testDetailed() "storage:10 .2.d:16 .2.d.3:d .4.s:d .5.c:1.3 .5.r:4" " .6.m:bar\\tfoo .7.s:m .8.d:10 .8.d.4.c:0.6 .8.d.4.m:small" ); - CPPUNIT_ASSERT_EQUAL(314u, state.getVersion()); - CPPUNIT_ASSERT_EQUAL(State::INITIALIZING, state.getClusterState()); - CPPUNIT_ASSERT_EQUAL(uint16_t(8),state.getNodeCount(NodeType::DISTRIBUTOR)); - CPPUNIT_ASSERT_EQUAL(uint16_t(10),state.getNodeCount(NodeType::STORAGE)); + EXPECT_EQ(314u, state.getVersion()); + EXPECT_EQ(State::INITIALIZING, state.getClusterState()); + EXPECT_EQ(uint16_t(8), state.getNodeCount(NodeType::DISTRIBUTOR)); + EXPECT_EQ(uint16_t(10), state.getNodeCount(NodeType::STORAGE)); // Testing distributor node states for (uint16_t i = 0; i <= 20; ++i) { const NodeState& ns(state.getNodeState(Node(NodeType::DISTRIBUTOR, i))); // Test node states if (i == 1 || i == 3) { - CPPUNIT_ASSERT_EQUAL(State::INITIALIZING, ns.getState()); + EXPECT_EQ(State::INITIALIZING, ns.getState()); } else if (i == 5 || i >= 8) { - CPPUNIT_ASSERT_EQUAL(State::DOWN, ns.getState()); + EXPECT_EQ(State::DOWN, ns.getState()); } else { - CPPUNIT_ASSERT_EQUAL(State::UP, ns.getState()); + EXPECT_EQ(State::UP, ns.getState()); } // Test initialize progress if (i == 1) { - CPPUNIT_ASSERT_EQUAL(vespalib::Double(0.0), ns.getInitProgress()); + EXPECT_EQ(vespalib::Double(0.0), ns.getInitProgress()); } else if (i == 3) { - CPPUNIT_ASSERT_EQUAL(vespalib::Double(0.5), ns.getInitProgress()); + EXPECT_EQ(vespalib::Double(0.5), ns.getInitProgress()); } else { - CPPUNIT_ASSERT_EQUAL(vespalib::Double(0.0), ns.getInitProgress()); + EXPECT_EQ(vespalib::Double(0.0), ns.getInitProgress()); } // Test message if (i == 7) { - CPPUNIT_ASSERT_EQUAL(string("foo bar"), ns.getDescription()); + EXPECT_EQ(string("foo bar"), ns.getDescription()); } else { - CPPUNIT_ASSERT_EQUAL(string(""), ns.getDescription()); + EXPECT_EQ(string(""), ns.getDescription()); } } @@ -289,42 +243,41 @@ ClusterStateTest::testDetailed() const NodeState& ns(state.getNodeState(Node(NodeType::STORAGE, i))); // Test node states if (i == 4 || i >= 10) { - CPPUNIT_ASSERT_EQUAL(State::DOWN, ns.getState()); + EXPECT_EQ(State::DOWN, ns.getState()); } else if (i == 7) { - CPPUNIT_ASSERT_EQUAL(State::MAINTENANCE, ns.getState()); + EXPECT_EQ(State::MAINTENANCE, ns.getState()); } else { - CPPUNIT_ASSERT_EQUAL(State::UP, ns.getState()); + EXPECT_EQ(State::UP, ns.getState()); } // Test disk states if (i == 2) { - CPPUNIT_ASSERT_EQUAL(uint16_t(16), ns.getDiskCount()); + EXPECT_EQ(uint16_t(16), ns.getDiskCount()); } else if (i == 8) { - CPPUNIT_ASSERT_EQUAL(uint16_t(10), ns.getDiskCount()); + EXPECT_EQ(uint16_t(10), ns.getDiskCount()); } else { - CPPUNIT_ASSERT_EQUAL(uint16_t(0), ns.getDiskCount()); + EXPECT_EQ(uint16_t(0), ns.getDiskCount()); } if (i == 2) { for (uint16_t j = 0; j < 16; ++j) { if (j == 3) { - CPPUNIT_ASSERT_EQUAL(State::DOWN, - ns.getDiskState(j).getState()); + EXPECT_EQ(State::DOWN, + ns.getDiskState(j).getState()); } else { - CPPUNIT_ASSERT_EQUAL(State::UP, - ns.getDiskState(j).getState()); + EXPECT_EQ(State::UP, + ns.getDiskState(j).getState()); } } } else if (i == 8) { for (uint16_t j = 0; j < 10; ++j) { if (j == 4) { - CPPUNIT_ASSERT_DOUBLES_EQUAL( - 0.6, ns.getDiskState(j).getCapacity().getValue(), 0.0001); - CPPUNIT_ASSERT_EQUAL( + EXPECT_DOUBLE_EQ(0.6, ns.getDiskState(j).getCapacity().getValue()); + EXPECT_EQ( string("small"), ns.getDiskState(j).getDescription()); } else { - CPPUNIT_ASSERT_DOUBLES_EQUAL( - 1.0, ns.getDiskState(j).getCapacity().getValue(), 0.0001); - CPPUNIT_ASSERT_EQUAL( + EXPECT_DOUBLE_EQ( + 1.0, ns.getDiskState(j).getCapacity().getValue()); + EXPECT_EQ( string(""), ns.getDiskState(j).getDescription()); } @@ -332,57 +285,36 @@ ClusterStateTest::testDetailed() } // Test message if (i == 6) { - CPPUNIT_ASSERT_EQUAL(string("bar\tfoo"), ns.getDescription()); + EXPECT_EQ(string("bar\tfoo"), ns.getDescription()); } else { - CPPUNIT_ASSERT_EQUAL(string(""), ns.getDescription()); + EXPECT_EQ(string(""), ns.getDescription()); } // Test reliability if (i == 5) { - CPPUNIT_ASSERT_EQUAL(uint16_t(4), ns.getReliability()); + EXPECT_EQ(uint16_t(4), ns.getReliability()); } else { - CPPUNIT_ASSERT_EQUAL(uint16_t(1), ns.getReliability()); + EXPECT_EQ(uint16_t(1), ns.getReliability()); } // Test capacity if (i == 5) { - CPPUNIT_ASSERT_EQUAL(vespalib::Double(1.3), ns.getCapacity()); + EXPECT_EQ(vespalib::Double(1.3), ns.getCapacity()); } else { - CPPUNIT_ASSERT_EQUAL(vespalib::Double(1.0), ns.getCapacity()); + EXPECT_EQ(vespalib::Double(1.0), ns.getCapacity()); } } } -void -ClusterStateTest::testParseFailure() +TEST(ClusterStateTest, test_parse_failure) { - try { - ClusterState state("storage"); - CPPUNIT_ASSERT(false); - } catch (vespalib::Exception& e) { - } - - try { - ClusterState state(""); - } catch (vespalib::Exception& e) { - CPPUNIT_ASSERT(false); - } - - try { - ClusterState state(".her:tull"); - CPPUNIT_ASSERT(false); - } catch (vespalib::Exception& e) { - } + EXPECT_THROW(ClusterState state("storage"), vespalib::Exception); + EXPECT_NO_THROW(ClusterState state("")); + EXPECT_THROW(ClusterState state(".her:tull"), vespalib::Exception); } -void -ClusterStateTest::testParseFailureGroups() +TEST(ClusterStateTest, test_parse_failure_groups) { - try { - ClusterState state(")"); - CPPUNIT_ASSERT(false); - } catch (vespalib::Exception& e) { - } + EXPECT_THROW(ClusterState state(")"), vespalib::Exception); } -} // lib -} // storage +} diff --git a/vdslib/src/tests/state/nodestatetest.cpp b/vdslib/src/tests/state/nodestatetest.cpp index 67ea7759654..da6faa49779 100644 --- a/vdslib/src/tests/state/nodestatetest.cpp +++ b/vdslib/src/tests/state/nodestatetest.cpp @@ -1,109 +1,88 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vdslib/state/nodestate.h> -#include <cppunit/extensions/HelperMacros.h> +#include <vespa/vespalib/gtest/gtest.h> -namespace storage { -namespace lib { +namespace storage::lib { -class NodeStateTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(NodeStateTest); - CPPUNIT_TEST(testParsing); - CPPUNIT_TEST(testExponential); - CPPUNIT_TEST(stateInstancesProvideDescriptiveNames); - CPPUNIT_TEST_SUITE_END(); - -public: -protected: - void testParsing(); - void testExponential(); // Test exponential notation. - void stateInstancesProvideDescriptiveNames(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION( NodeStateTest ); - -void -NodeStateTest::testParsing() +TEST(NodeStateTest, test_parsing) { { NodeState ns = NodeState("s:u"); - CPPUNIT_ASSERT_EQUAL(std::string("s:u"), ns.toString()); - CPPUNIT_ASSERT_EQUAL(vespalib::Double(1.0), ns.getCapacity()); - CPPUNIT_ASSERT_EQUAL(uint16_t(1), ns.getReliability()); + EXPECT_EQ(std::string("s:u"), ns.toString()); + EXPECT_EQ(vespalib::Double(1.0), ns.getCapacity()); + EXPECT_EQ(uint16_t(1), ns.getReliability()); } { NodeState ns = NodeState("s:m"); - CPPUNIT_ASSERT_EQUAL(std::string("s:m"), ns.toString()); - CPPUNIT_ASSERT_EQUAL(vespalib::Double(1.0), ns.getCapacity()); - CPPUNIT_ASSERT_EQUAL(uint16_t(1), ns.getReliability()); + EXPECT_EQ(std::string("s:m"), ns.toString()); + EXPECT_EQ(vespalib::Double(1.0), ns.getCapacity()); + EXPECT_EQ(uint16_t(1), ns.getReliability()); } { NodeState ns = NodeState("t:4"); - CPPUNIT_ASSERT_EQUAL(std::string("s:u t:4"), ns.toString()); - CPPUNIT_ASSERT_EQUAL(uint64_t(4), ns.getStartTimestamp()); + EXPECT_EQ(std::string("s:u t:4"), ns.toString()); + EXPECT_EQ(uint64_t(4), ns.getStartTimestamp()); } { NodeState ns = NodeState("s:u c:2.4 r:3 b:12"); - CPPUNIT_ASSERT_EQUAL(std::string("s:u c:2.4 r:3 b:12"), ns.toString()); - CPPUNIT_ASSERT_EQUAL(vespalib::Double(2.4), ns.getCapacity()); - CPPUNIT_ASSERT_EQUAL(uint16_t(3), ns.getReliability()); - CPPUNIT_ASSERT_EQUAL(12, (int)ns.getMinUsedBits()); + EXPECT_EQ(std::string("s:u c:2.4 r:3 b:12"), ns.toString()); + EXPECT_EQ(vespalib::Double(2.4), ns.getCapacity()); + EXPECT_EQ(uint16_t(3), ns.getReliability()); + EXPECT_EQ(12, (int)ns.getMinUsedBits()); - CPPUNIT_ASSERT(!(NodeState("s:u b:12") == NodeState("s:u b:13"))); + EXPECT_NE(NodeState("s:u b:12"), NodeState("s:u b:13")); } { NodeState ns = NodeState("c:2.4\ns:u\nr:5"); - CPPUNIT_ASSERT_EQUAL(std::string("s:u c:2.4 r:5"), ns.toString()); - CPPUNIT_ASSERT_EQUAL(vespalib::Double(2.4), ns.getCapacity()); - CPPUNIT_ASSERT_EQUAL(uint16_t(5), ns.getReliability()); + EXPECT_EQ(std::string("s:u c:2.4 r:5"), ns.toString()); + EXPECT_EQ(vespalib::Double(2.4), ns.getCapacity()); + EXPECT_EQ(uint16_t(5), ns.getReliability()); } { NodeState ns = NodeState("c:2.4 r:1"); - CPPUNIT_ASSERT_EQUAL(std::string("s:u c:2.4"), ns.toString()); - CPPUNIT_ASSERT_EQUAL(vespalib::Double(2.4), ns.getCapacity()); - CPPUNIT_ASSERT_EQUAL(uint16_t(1), ns.getReliability()); + EXPECT_EQ(std::string("s:u c:2.4"), ns.toString()); + EXPECT_EQ(vespalib::Double(2.4), ns.getCapacity()); + EXPECT_EQ(uint16_t(1), ns.getReliability()); } { NodeState ns = NodeState("c:2.4 k:2.6"); - CPPUNIT_ASSERT_EQUAL(std::string("s:u c:2.4"), ns.toString()); - CPPUNIT_ASSERT_EQUAL(vespalib::Double(2.4), ns.getCapacity()); - CPPUNIT_ASSERT_EQUAL(uint16_t(1), ns.getReliability()); + EXPECT_EQ(std::string("s:u c:2.4"), ns.toString()); + EXPECT_EQ(vespalib::Double(2.4), ns.getCapacity()); + EXPECT_EQ(uint16_t(1), ns.getReliability()); } } -void -NodeStateTest::testExponential() +TEST(NodeStateTest, test_exponential) { { NodeState ns = NodeState("c:3E-8"); - CPPUNIT_ASSERT_EQUAL( std::string("s:u c:3e-08"), ns.toString() ); - CPPUNIT_ASSERT_EQUAL(vespalib::Double(3E-8), ns.getCapacity()); + EXPECT_EQ(std::string("s:u c:3e-08"), ns.toString() ); + EXPECT_EQ(vespalib::Double(3E-8), ns.getCapacity()); } { NodeState ns = NodeState("c:3e-08"); - CPPUNIT_ASSERT_EQUAL( std::string("s:u c:3e-08"), ns.toString() ); - CPPUNIT_ASSERT_EQUAL(vespalib::Double(3e-08), ns.getCapacity()); + EXPECT_EQ(std::string("s:u c:3e-08"), ns.toString() ); + EXPECT_EQ(vespalib::Double(3e-08), ns.getCapacity()); } } -void -NodeStateTest::stateInstancesProvideDescriptiveNames() +TEST(NodeStateTest, state_instances_provide_descriptive_names) { - CPPUNIT_ASSERT_EQUAL(vespalib::string("Unknown"), - State::UNKNOWN.getName()); - CPPUNIT_ASSERT_EQUAL(vespalib::string("Maintenance"), - State::MAINTENANCE.getName()); - CPPUNIT_ASSERT_EQUAL(vespalib::string("Down"), - State::DOWN.getName()); - CPPUNIT_ASSERT_EQUAL(vespalib::string("Stopping"), - State::STOPPING.getName()); - CPPUNIT_ASSERT_EQUAL(vespalib::string("Initializing"), - State::INITIALIZING.getName()); - CPPUNIT_ASSERT_EQUAL(vespalib::string("Retired"), - State::RETIRED.getName()); - CPPUNIT_ASSERT_EQUAL(vespalib::string("Up"), - State::UP.getName()); + EXPECT_EQ(vespalib::string("Unknown"), + State::UNKNOWN.getName()); + EXPECT_EQ(vespalib::string("Maintenance"), + State::MAINTENANCE.getName()); + EXPECT_EQ(vespalib::string("Down"), + State::DOWN.getName()); + EXPECT_EQ(vespalib::string("Stopping"), + State::STOPPING.getName()); + EXPECT_EQ(vespalib::string("Initializing"), + State::INITIALIZING.getName()); + EXPECT_EQ(vespalib::string("Retired"), + State::RETIRED.getName()); + EXPECT_EQ(vespalib::string("Up"), + State::UP.getName()); } -} // lib -} // storage +} diff --git a/vdslib/src/tests/thread/CMakeLists.txt b/vdslib/src/tests/thread/CMakeLists.txt index 21bcb06b43c..4d1e753a8f6 100644 --- a/vdslib/src/tests/thread/CMakeLists.txt +++ b/vdslib/src/tests/thread/CMakeLists.txt @@ -4,4 +4,5 @@ vespa_add_library(vdslib_testthread taskschedulertest.cpp DEPENDS vdslib + gtest ) diff --git a/vdslib/src/tests/thread/taskschedulertest.cpp b/vdslib/src/tests/thread/taskschedulertest.cpp index 3c056cbb363..540de722137 100644 --- a/vdslib/src/tests/thread/taskschedulertest.cpp +++ b/vdslib/src/tests/thread/taskschedulertest.cpp @@ -1,24 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vdslib/thread/taskscheduler.h> -#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/gtest/gtest.h> namespace vdslib { -struct TaskSchedulerTest : public CppUnit::TestFixture { - void testSimple(); - void testMultipleTasksAtSameTime(); - void testRemoveTask(); - - CPPUNIT_TEST_SUITE(TaskSchedulerTest); - CPPUNIT_TEST(testSimple); - CPPUNIT_TEST(testMultipleTasksAtSameTime); - CPPUNIT_TEST(testRemoveTask); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(TaskSchedulerTest); - namespace { struct TestWatch : public TaskScheduler::Watch { @@ -106,10 +92,9 @@ std::string join(std::vector<std::string>& v) { return ost.str(); } -} // End of anonymous namespace +} -void -TaskSchedulerTest::testSimple() +TEST(TaskSchedulerTest, test_simple) { FastOS_ThreadPool threadPool(128 * 1024); TestWatch watch(0); @@ -127,7 +112,7 @@ TaskSchedulerTest::testSimple() task->registerCallsWithName("", calls); scheduler.add(TestTask::UP(task)); scheduler.waitForTaskCounterOfAtLeast(counter + 1); - CPPUNIT_ASSERT_EQUAL(std::string("0"), join(calls)); + EXPECT_EQ(std::string("0"), join(calls)); scheduler.waitUntilNoTasksRemaining(); // Ensure task is complete } // Test that task is repeated at intervals if wanted. @@ -142,8 +127,8 @@ TaskSchedulerTest::testSimple() scheduler.waitForTaskCounterOfAtLeast(counter + i); watch.increment(100); } - CPPUNIT_ASSERT_EQUAL(std::string("0,110,220,330,440"), - join(calls)); + EXPECT_EQ(std::string("0,110,220,330,440"), + join(calls)); scheduler.waitUntilNoTasksRemaining(); // Ensure task is complete } // Test that task scheduled at specific time works, and that if @@ -158,23 +143,22 @@ TaskSchedulerTest::testSimple() watch.increment(49); // Not yet time to run FastOS_Thread::Sleep(5); // Check that it has not run yet.. - CPPUNIT_ASSERT_EQUAL(counter, scheduler.getTaskCounter()); + EXPECT_EQ(counter, scheduler.getTaskCounter()); watch.increment(10); // Now time is enough for it to run scheduler.waitForTaskCounterOfAtLeast(counter + 1); watch.increment(10); FastOS_Thread::Sleep(5); // Check that it has not run yet.. - CPPUNIT_ASSERT_EQUAL(counter + 1, scheduler.getTaskCounter()); + EXPECT_EQ(counter + 1, scheduler.getTaskCounter()); watch.increment(50); scheduler.waitForTaskCounterOfAtLeast(counter + 2); - CPPUNIT_ASSERT_EQUAL(std::string("59,129,129,129"), - join(calls)); + EXPECT_EQ(std::string("59,129,129,129"), + join(calls)); scheduler.waitUntilNoTasksRemaining(); // Ensure task is complete } } -void -TaskSchedulerTest::testMultipleTasksAtSameTime() +TEST(TaskSchedulerTest, test_multiple_tasks_at_same_time) { FastOS_ThreadPool threadPool(128 * 1024); TestWatch watch(0); @@ -200,19 +184,18 @@ TaskSchedulerTest::testMultipleTasksAtSameTime() std::ostringstream ost; for (size_t i=0; i<calls.size(); ++i) ost << calls[i] << "\n"; - CPPUNIT_ASSERT_EQUAL(std::string( - "10 task1\n" - "10 task2\n" - "10 task1\n" - "10 task2\n" - "10 task1\n" - "10 task2\n" - ), ost.str()); + EXPECT_EQ(std::string( + "10 task1\n" + "10 task2\n" + "10 task1\n" + "10 task2\n" + "10 task1\n" + "10 task2\n" + ), ost.str()); } } -void -TaskSchedulerTest::testRemoveTask() +TEST(TaskSchedulerTest, test_remove_task) { FastOS_ThreadPool threadPool(128 * 1024); TestWatch watch(0); @@ -236,7 +219,7 @@ TaskSchedulerTest::testRemoveTask() scheduler.remove(task); delete task; // Time should not be advanced as task didn't get to run - CPPUNIT_ASSERT_EQUAL(0, (int) watch.getTime()); + EXPECT_EQ(0, (int) watch.getTime()); } } |