aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/removelocationtest.cpp
blob: be688e64a8b6955c29f0a5ddca4fe1470aede506 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <tests/distributor/distributor_stripe_test_util.h>
#include <vespa/document/test/make_document_bucket.h>
#include <vespa/storage/distributor/top_level_distributor.h>
#include <vespa/storage/distributor/distributor_stripe.h>
#include <vespa/storage/distributor/operations/external/removelocationoperation.h>
#include <vespa/storageapi/message/removelocation.h>
#include <vespa/vespalib/gtest/gtest.h>

using document::test::makeDocumentBucket;
using namespace ::testing;

namespace storage::distributor {

struct RemoveLocationOperationTest : Test, DistributorStripeTestUtil {
    std::unique_ptr<RemoveLocationOperation> op;

    void SetUp() override {
        createLinks();
    };

    void TearDown() override {
        close();
    }

    void sendRemoveLocation(const std::string& selection) {
        auto msg = std::make_shared<api::RemoveLocationCommand>(selection, makeDocumentBucket(document::BucketId(0)));

        op = std::make_unique<RemoveLocationOperation>(
                node_context(),
                operation_context(),
                doc_selection_parser(),
                getDistributorBucketSpace(),
                msg,
                metrics().removelocations);

        op->start(_sender);
    }
};

TEST_F(RemoveLocationOperationTest, simple) {
    enable_cluster_state("distributor:1 storage:3");

    addNodesToBucketDB(document::BucketId(34, 0x000001234), "0=1,1=1");
    addNodesToBucketDB(document::BucketId(34, 0x100001234), "0=1,2=1");
    addNodesToBucketDB(document::BucketId(34, 0x200001234), "0=1,2=1");
    addNodesToBucketDB(document::BucketId(34, 0x300001234), "1=1,2=1");

    sendRemoveLocation("id.user=4660");

    ASSERT_EQ("Remove selection(id.user=4660): BucketInfoCommand() => 0,"
              "Remove selection(id.user=4660): BucketInfoCommand() => 1,"
              "Remove selection(id.user=4660): BucketInfoCommand() => 0,"
              "Remove selection(id.user=4660): BucketInfoCommand() => 2,"
              "Remove selection(id.user=4660): BucketInfoCommand() => 0,"
              "Remove selection(id.user=4660): BucketInfoCommand() => 2,"
              "Remove selection(id.user=4660): BucketInfoCommand() => 1,"
              "Remove selection(id.user=4660): BucketInfoCommand() => 2",
              _sender.getCommands(true, true));

    for (uint32_t i = 0; i < 8; ++i) {
        sendReply(*op, i);
    }

    ASSERT_EQ("BucketInfoReply(BucketInfo(invalid)) ReturnCode(NONE)",
              _sender.getLastReply());
}

// TODO test cancellation (implicitly covered via operation PersistenceMessageTracker)

} // storage::distributor