aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/mergelimitertest.cpp
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@verizonmedia.com>2019-06-21 14:32:05 +0000
committerTor Brede Vekterli <vekterli@verizonmedia.com>2019-06-25 11:08:43 +0000
commit0ec1dddb0e75c235edfc68d72f4471ad186c3399 (patch)
tree254cdda75b06c8453a207933a8d556c1db90b997 /storage/src/tests/distributor/mergelimitertest.cpp
parenta0d854b6a3fab6fe44b1164c071fc994b331c3bc (diff)
Convert remaining CppUnit tests to GTest
Move base message sender stub out to common test module to avoid artificial dependency from persistence tests to the distributor tests.
Diffstat (limited to 'storage/src/tests/distributor/mergelimitertest.cpp')
-rw-r--r--storage/src/tests/distributor/mergelimitertest.cpp159
1 files changed, 60 insertions, 99 deletions
diff --git a/storage/src/tests/distributor/mergelimitertest.cpp b/storage/src/tests/distributor/mergelimitertest.cpp
index 0b40424594b..b06630ea592 100644
--- a/storage/src/tests/distributor/mergelimitertest.cpp
+++ b/storage/src/tests/distributor/mergelimitertest.cpp
@@ -1,94 +1,65 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/storage/distributor/operations/idealstate/mergelimiter.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
+#include <vespa/vespalib/gtest/gtest.h>
+
+using namespace ::testing;
namespace storage::distributor {
-struct MergeLimiterTest : public CppUnit::TestFixture
-{
- void testKeepsAllBelowLimit();
- void testLessThanMaxUntrusted();
- void testMoreThanMaxUntrusted();
- void testAllUntrustedLessThanMaxVariants();
- void testAllUntrustedMoreThanMaxVariants();
- void testSourceOnlyLast();
- void limited_set_cannot_be_just_source_only();
- void non_source_only_replica_chosen_from_in_sync_group();
- void non_source_only_replicas_preferred_when_replicas_not_in_sync();
- void at_least_one_non_source_only_replica_chosen_when_all_trusted();
- void missing_replica_distinct_from_empty_replica();
-
- CPPUNIT_TEST_SUITE(MergeLimiterTest);
- CPPUNIT_TEST(testKeepsAllBelowLimit);
- CPPUNIT_TEST(testLessThanMaxUntrusted);
- CPPUNIT_TEST(testMoreThanMaxUntrusted);
- CPPUNIT_TEST(testAllUntrustedLessThanMaxVariants);
- CPPUNIT_TEST(testAllUntrustedMoreThanMaxVariants);
- CPPUNIT_TEST(testSourceOnlyLast);
- CPPUNIT_TEST(limited_set_cannot_be_just_source_only);
- CPPUNIT_TEST(non_source_only_replica_chosen_from_in_sync_group);
- CPPUNIT_TEST(non_source_only_replicas_preferred_when_replicas_not_in_sync);
- CPPUNIT_TEST(at_least_one_non_source_only_replica_chosen_when_all_trusted);
- CPPUNIT_TEST(missing_replica_distinct_from_empty_replica);
- CPPUNIT_TEST_SUITE_END();
-};
+namespace {
-CPPUNIT_TEST_SUITE_REGISTRATION(MergeLimiterTest);
+using BucketCopyPtr = std::unique_ptr<BucketCopy>;
+std::vector<BucketCopyPtr> _bucketDatabase;
-namespace {
- using BucketCopyPtr = std::unique_ptr<BucketCopy>;
- std::vector<BucketCopyPtr> _bucketDatabase;
-
- struct NodeFactory {
- std::vector<MergeMetaData> _nodes;
-
- NodeFactory& add(int index, int crc) {
- _bucketDatabase.push_back(BucketCopyPtr(
- new BucketCopy(0, index, api::BucketInfo(crc, 5, 10))));
- _nodes.push_back(MergeMetaData(index, *_bucketDatabase.back()));
- return *this;
- }
- NodeFactory& addTrusted(int index, int crc) {
- add(index, crc);
- _bucketDatabase.back()->setTrusted(true);
- return *this;
- }
- NodeFactory& addMissing(int index) {
- add(index, 0x1); // "Magic" checksum value implying invalid/recently created replica
- return *this;
- }
- NodeFactory& addEmpty(int index) {
- add(index, 0x0);
- return *this;
- }
- NodeFactory& setSourceOnly() {
- _nodes.back()._sourceOnly = true;
- return *this;
- }
-
- operator const MergeLimiter::NodeArray&() const { return _nodes; }
- };
-
- #define ASSERT_LIMIT(maxNodes, nodes, result) \
- { \
- MergeLimiter limiter(maxNodes); \
- auto nodesCopy = nodes; \
- limiter.limitMergeToMaxNodes(nodesCopy); \
- std::ostringstream actual; \
- for (uint32_t i = 0; i < nodesCopy.size(); ++i) { \
- if (i != 0) actual << ","; \
- actual << nodesCopy[i]._nodeIndex; \
- if (nodesCopy[i]._sourceOnly) actual << 's'; \
- } \
- CPPUNIT_ASSERT_EQUAL(std::string(result), actual.str()); \
+struct NodeFactory {
+ std::vector<MergeMetaData> _nodes;
+
+ NodeFactory& add(int index, int crc) {
+ _bucketDatabase.emplace_back(
+ std::make_unique<BucketCopy>(0, index, api::BucketInfo(crc, 5, 10)));
+ _nodes.emplace_back(MergeMetaData(index, *_bucketDatabase.back()));
+ return *this;
+ }
+ NodeFactory& addTrusted(int index, int crc) {
+ add(index, crc);
+ _bucketDatabase.back()->setTrusted(true);
+ return *this;
+ }
+ NodeFactory& addMissing(int index) {
+ add(index, 0x1); // "Magic" checksum value implying invalid/recently created replica
+ return *this;
}
+ NodeFactory& addEmpty(int index) {
+ add(index, 0x0);
+ return *this;
+ }
+ NodeFactory& setSourceOnly() {
+ _nodes.back()._sourceOnly = true;
+ return *this;
+ }
+
+ operator const MergeLimiter::NodeArray&() const { return _nodes; }
+};
+
+#define ASSERT_LIMIT(maxNodes, nodes, result) \
+{ \
+ MergeLimiter limiter(maxNodes); \
+ auto nodesCopy = nodes; \
+ limiter.limitMergeToMaxNodes(nodesCopy); \
+ std::ostringstream actual; \
+ for (uint32_t i = 0; i < nodesCopy.size(); ++i) { \
+ if (i != 0) actual << ","; \
+ actual << nodesCopy[i]._nodeIndex; \
+ if (nodesCopy[i]._sourceOnly) actual << 's'; \
+ } \
+ ASSERT_EQ(result, actual.str()); \
+}
+
}
// If there is <= max nodes, then none should be removed.
-void
-MergeLimiterTest::testKeepsAllBelowLimit()
-{
+TEST(MergeLimiterTest, keeps_all_below_limit) {
MergeLimiter::NodeArray nodes(NodeFactory()
.addTrusted(3, 0x4)
.addTrusted(5, 0x4)
@@ -100,9 +71,7 @@ MergeLimiterTest::testKeepsAllBelowLimit()
}
// If less than max nodes is untrusted, merge all untrusted copies with a
// trusted one. (Optionally with extra trusted copies if there is space)
-void
-MergeLimiterTest::testLessThanMaxUntrusted()
-{
+TEST(MergeLimiterTest, less_than_max_untrusted) {
MergeLimiter::NodeArray nodes(NodeFactory()
.addTrusted(3, 0x4)
.addTrusted(5, 0x4)
@@ -113,9 +82,7 @@ MergeLimiterTest::testLessThanMaxUntrusted()
}
// With more than max untrusted, just merge one trusted with as many untrusted
// that fits.
-void
-MergeLimiterTest::testMoreThanMaxUntrusted()
-{
+TEST(MergeLimiterTest, more_than_max_untrusted) {
MergeLimiter::NodeArray nodes(NodeFactory()
.addTrusted(3, 0x4)
.addTrusted(5, 0x4)
@@ -129,9 +96,7 @@ MergeLimiterTest::testMoreThanMaxUntrusted()
// With nothing trusted. If there is <= max different variants (checksums),
// merge one of each variant. After this merge, all these nodes can be set
// trusted. (Except for any source only ones)
-void
-MergeLimiterTest::testAllUntrustedLessThanMaxVariants()
-{
+TEST(MergeLimiterTest, all_untrusted_less_than_max_variants) {
MergeLimiter::NodeArray nodes(NodeFactory()
.add(3, 0x4)
.add(5, 0x4)
@@ -144,9 +109,7 @@ MergeLimiterTest::testAllUntrustedLessThanMaxVariants()
}
// With nothing trusted and more than max variants, we just have to merge one
// of each variant until we end up with less than max variants.
-void
-MergeLimiterTest::testAllUntrustedMoreThanMaxVariants()
-{
+TEST(MergeLimiterTest, all_untrusted_more_than_max_variants) {
MergeLimiter::NodeArray nodes(NodeFactory()
.add(3, 0x4)
.add(5, 0x5)
@@ -160,9 +123,7 @@ MergeLimiterTest::testAllUntrustedMoreThanMaxVariants()
// With more than max untrusted, just merge one trusted with as many untrusted
// that fits.
-void
-MergeLimiterTest::testSourceOnlyLast()
-{
+TEST(MergeLimiterTest, source_only_last) {
MergeLimiter::NodeArray nodes(NodeFactory()
.addTrusted(3, 0x4)
.addTrusted(5, 0x4).setSourceOnly()
@@ -174,7 +135,7 @@ MergeLimiterTest::testSourceOnlyLast()
ASSERT_LIMIT(4, nodes, "9,3,5s,2s");
}
-void MergeLimiterTest::limited_set_cannot_be_just_source_only() {
+TEST(MergeLimiterTest, limited_set_cannot_be_just_source_only) {
MergeLimiter::NodeArray nodes(NodeFactory()
.addTrusted(9, 0x6)
.addTrusted(2, 0x6)
@@ -184,7 +145,7 @@ void MergeLimiterTest::limited_set_cannot_be_just_source_only() {
ASSERT_LIMIT(3, nodes, "2,13s,1s");
}
-void MergeLimiterTest::non_source_only_replica_chosen_from_in_sync_group() {
+TEST(MergeLimiterTest, non_source_only_replica_chosen_from_in_sync_group) {
// nodes 9, 2, 13 are all in sync. Merge limiter will currently by default
// pop the _last_ node of an in-sync replica "group" when outputting a limited
// set. Unless we special-case source-only replicas here, we'd end up with an
@@ -198,7 +159,7 @@ void MergeLimiterTest::non_source_only_replica_chosen_from_in_sync_group() {
ASSERT_LIMIT(3, nodes, "2,13s,1s");
}
-void MergeLimiterTest::non_source_only_replicas_preferred_when_replicas_not_in_sync() {
+TEST(MergeLimiterTest, non_source_only_replicas_preferred_when_replicas_not_in_sync) {
MergeLimiter::NodeArray nodes(NodeFactory()
.add(9, 0x4)
.add(2, 0x5)
@@ -208,7 +169,7 @@ void MergeLimiterTest::non_source_only_replicas_preferred_when_replicas_not_in_s
ASSERT_LIMIT(3, nodes, "9,2,13s");
}
-void MergeLimiterTest::at_least_one_non_source_only_replica_chosen_when_all_trusted() {
+TEST(MergeLimiterTest, at_least_one_non_source_only_replica_chosen_when_all_trusted) {
MergeLimiter::NodeArray nodes(NodeFactory()
.addTrusted(9, 0x6)
.addTrusted(2, 0x6)
@@ -218,7 +179,7 @@ void MergeLimiterTest::at_least_one_non_source_only_replica_chosen_when_all_trus
ASSERT_LIMIT(3, nodes, "2,13s,1s");
}
-void MergeLimiterTest::missing_replica_distinct_from_empty_replica() {
+TEST(MergeLimiterTest, missing_replica_distinct_from_empty_replica) {
MergeLimiter::NodeArray nodes(NodeFactory()
.addEmpty(3)
.addEmpty(5)