summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/multi_thread_stripe_access_guard_test.cpp
blob: 8513186d1e130eaa6bb53e584e86a10398c10fd0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "mock_tickable_stripe.h"
#include <vespa/document/bucket/fixed_bucket_spaces.h>
#include <vespa/storage/distributor/distributor_stripe_pool.h>
#include <vespa/storage/distributor/multi_threaded_stripe_access_guard.h>
#include <vespa/vdslib/state/clusterstate.h>
#include <vespa/vespalib/gtest/gtest.h>

using namespace ::testing;

namespace storage::distributor {

struct AggregationTestingMockTickableStripe : MockTickableStripe {
    PotentialDataLossReport report;

    PotentialDataLossReport remove_superfluous_buckets(document::BucketSpace, const lib::ClusterState&, bool) override {
        return report;
    }

    bool tick() override {
        return false;
    }
};

struct MultiThreadedStripeAccessGuardTest : Test {
    DistributorStripePool                _pool;
    MultiThreadedStripeAccessor          _accessor;
    AggregationTestingMockTickableStripe _stripe1;
    AggregationTestingMockTickableStripe _stripe2;
    AggregationTestingMockTickableStripe _stripe3;

    MultiThreadedStripeAccessGuardTest()
        : _pool(),
          _accessor(_pool)
    {}

    ~MultiThreadedStripeAccessGuardTest() {
        _pool.stop_and_join();
    }

    void start_pool_with_stripes() {
        _pool.start({{&_stripe1, &_stripe2, &_stripe3}});
    }
};

TEST_F(MultiThreadedStripeAccessGuardTest, remove_superfluous_buckets_aggregates_reports_across_stripes) {
    _stripe1.report = PotentialDataLossReport(20, 100);
    _stripe2.report = PotentialDataLossReport(5,  200);
    _stripe3.report = PotentialDataLossReport(7,  350);
    start_pool_with_stripes();

    auto guard = _accessor.rendezvous_and_hold_all();
    auto report = guard->remove_superfluous_buckets(document::FixedBucketSpaces::default_space(),
                                                    lib::ClusterState(), false);
    EXPECT_EQ(report.buckets, 32);
    EXPECT_EQ(report.documents, 650);
}

}