From 53571d9be1b7073dd3e135d7878b37ff0f008011 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Wed, 14 Feb 2018 14:44:28 +0000 Subject: Add messageCount() method to help calculate number of expected messages. --- .../src/tests/distributor/bucketdbupdatertest.cpp | 86 +++++++++++----------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/storage/src/tests/distributor/bucketdbupdatertest.cpp b/storage/src/tests/distributor/bucketdbupdatertest.cpp index 92495b37494..77b661c2606 100644 --- a/storage/src/tests/distributor/bucketdbupdatertest.cpp +++ b/storage/src/tests/distributor/bucketdbupdatertest.cpp @@ -200,6 +200,10 @@ protected: std::vector _bucketSpaces; + size_t messageCount(size_t messagesPerBucketSpace) const { + return messagesPerBucketSpace * _bucketSpaces.size(); + } + public: using OutdatedNodesMap = dbtransition::OutdatedNodesMap; void setUp() override { @@ -416,7 +420,7 @@ public: setSystemState(newState); - for (uint32_t i=0; igetType() == MessageType::REQUESTBUCKETINFO); @@ -434,7 +438,7 @@ public: "distributor:1 storage:%d", numStorageNodes)); lib::ClusterState newState(state); - for (uint32_t i=0; iisInRecoveryMode()); - CPPUNIT_ASSERT_EQUAL(6 * _bucketSpaces.size(), _sender.commands.size()); + CPPUNIT_ASSERT_EQUAL(messageCount(6), _sender.commands.size()); uint32_t numBuckets = 10; - for (uint32_t i = 0; i < 6 * _bucketSpaces.size(); ++i) { + for (uint32_t i = 0; i < messageCount(6); ++i) { fakeBucketReply(lib::ClusterState("distributor:6 storage:6"), *_sender.commands[i], numBuckets); } @@ -2268,7 +2272,7 @@ BucketDBUpdaterTest::preemptedDistrChangeCarriesNodeSetOverToNextStateFetch() CPPUNIT_ASSERT_EQUAL( expandNodeVec({0, 1, 2, 3, 4, 5}), getSentNodesWithPreemption("version:1 distributor:6 storage:6", - 6 * _bucketSpaces.size(), + messageCount(6), "version:2 distributor:6 .5.s:d storage:6", "version:3 distributor:6 storage:6")); } @@ -2280,7 +2284,7 @@ BucketDBUpdaterTest::preemptedStorChangeCarriesNodeSetOverToNextStateFetch() expandNodeVec({2, 3}), getSentNodesWithPreemption( "version:1 distributor:6 storage:6 .2.s:d", - 5 * _bucketSpaces.size(), + messageCount(5), "version:2 distributor:6 storage:6 .2.s:d .3.s:d", "version:3 distributor:6 storage:6")); } @@ -2292,7 +2296,7 @@ BucketDBUpdaterTest::preemptedStorageNodeDownMustBeReFetched() expandNodeVec({2}), getSentNodesWithPreemption( "version:1 distributor:6 storage:6", - 6 * _bucketSpaces.size(), + messageCount(6), "version:2 distributor:6 storage:6 .2.s:d", "version:3 distributor:6 storage:6")); } @@ -2304,7 +2308,7 @@ BucketDBUpdaterTest::doNotSendToPreemptedNodeNowInDownState() nodeVec{}, getSentNodesWithPreemption( "version:1 distributor:6 storage:6 .2.s:d", - 5 * _bucketSpaces.size(), + messageCount(5), "version:2 distributor:6 storage:6", // Sends to 2. "version:3 distributor:6 storage:6 .2.s:d")); // 2 down again. } @@ -2318,7 +2322,7 @@ BucketDBUpdaterTest::doNotSendToPreemptedNodeNotPartOfNewState() expandNodeVec({0, 1, 2, 3, 4, 5}), getSentNodesWithPreemption( "version:1 distributor:6 storage:100", - 100 * _bucketSpaces.size(), + messageCount(100), "version:2 distributor:5 .4.s:d storage:100", "version:3 distributor:6 storage:6")); } @@ -2328,7 +2332,7 @@ BucketDBUpdaterTest::outdatedNodeSetClearedAfterSuccessfulStateCompletion() { lib::ClusterState stateBefore( "version:1 distributor:6 storage:6 .1.t:1234"); - uint32_t expectedMsgs = 6 * _bucketSpaces.size(), dummyBucketsToReturn = 10; + uint32_t expectedMsgs = messageCount(6), dummyBucketsToReturn = 10; setAndEnableClusterState(stateBefore, expectedMsgs, dummyBucketsToReturn); _sender.clear(); // New cluster state that should not by itself trigger any new fetches, @@ -2383,7 +2387,7 @@ BucketDBUpdaterTest::changedDiskSetTriggersReFetch() void BucketDBUpdaterTest::nodeMissingFromConfigIsTreatedAsNeedingOwnershipTransfer() { - uint32_t expectedMsgs = 3 * _bucketSpaces.size(), dummyBucketsToReturn = 1; + uint32_t expectedMsgs = messageCount(3), dummyBucketsToReturn = 1; setAndEnableClusterState(lib::ClusterState("distributor:3 storage:3"), expectedMsgs, dummyBucketsToReturn); _sender.clear(); @@ -2411,7 +2415,7 @@ BucketDBUpdaterTest::nodeMissingFromConfigIsTreatedAsNeedingOwnershipTransfer() // Attempt to apply state with {0, 1} set. This will compare the new state // with the previous state, which still has node 2. - expectedMsgs = 2 * _bucketSpaces.size(); + expectedMsgs = messageCount(2); setAndEnableClusterState(lib::ClusterState("distributor:2 storage:2"), expectedMsgs, dummyBucketsToReturn); @@ -2453,7 +2457,7 @@ BucketDBUpdaterTest::changed_distribution_config_implies_ownership_transfer() void BucketDBUpdaterTest::transition_time_tracked_for_single_state_change() { - completeStateTransitionInSeconds("distributor:2 storage:2", 5, 2 * _bucketSpaces.size()); + completeStateTransitionInSeconds("distributor:2 storage:2", 5, messageCount(2)); CPPUNIT_ASSERT_EQUAL(uint64_t(5000), lastTransitionTimeInMillis()); } @@ -2461,8 +2465,8 @@ BucketDBUpdaterTest::transition_time_tracked_for_single_state_change() void BucketDBUpdaterTest::transition_time_reset_across_non_preempting_state_changes() { - completeStateTransitionInSeconds("distributor:2 storage:2", 5, 2 * _bucketSpaces.size()); - completeStateTransitionInSeconds("distributor:2 storage:3", 3, 1 * _bucketSpaces.size()); + completeStateTransitionInSeconds("distributor:2 storage:2", 5, messageCount(2)); + completeStateTransitionInSeconds("distributor:2 storage:3", 3, messageCount(1)); CPPUNIT_ASSERT_EQUAL(uint64_t(3000), lastTransitionTimeInMillis()); } @@ -2471,13 +2475,13 @@ void BucketDBUpdaterTest::transition_time_tracked_for_distribution_config_change() { lib::ClusterState state("distributor:2 storage:2"); - setAndEnableClusterState(state, 2 * _bucketSpaces.size(), 1); + setAndEnableClusterState(state, messageCount(2), 1); _sender.clear(); std::string distConfig(getDistConfig3Nodes1Group()); setDistribution(distConfig); getClock().addSecondsToTime(4); - completeBucketInfoGathering(state, 2 * _bucketSpaces.size()); + completeBucketInfoGathering(state, messageCount(2)); CPPUNIT_ASSERT_EQUAL(uint64_t(4000), lastTransitionTimeInMillis()); } @@ -2491,7 +2495,7 @@ BucketDBUpdaterTest::transition_time_tracked_across_preempted_transitions() // Pre-empted with new state here, which will push out the old pending // state and replace it with a new one. We should still count the time // used processing the old state. - completeStateTransitionInSeconds("distributor:2 storage:3", 3, 3 * _bucketSpaces.size()); + completeStateTransitionInSeconds("distributor:2 storage:3", 3, messageCount(3)); CPPUNIT_ASSERT_EQUAL(uint64_t(8000), lastTransitionTimeInMillis()); } -- cgit v1.2.3