aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/persistence/common/filestortestfixture.h
blob: e4776f393ae05508e726fd9339cd6a495aee15ea (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <tests/common/dummystoragelink.h>
#include <tests/common/testhelper.h>
#include <tests/common/teststorageapp.h>
#include <vespa/storage/persistence/filestorage/filestorhandlerimpl.h>
#include <vespa/storage/persistence/filestorage/filestormanager.h>
#include <vespa/storageapi/message/persistence.h>
#include <vespa/vespalib/gtest/gtest.h>

namespace storage {

class FileStorTestFixture : public ::testing::Test
{
public:
    std::unique_ptr<TestServiceLayerApp> _node;
    std::unique_ptr<vdstestlib::DirConfig> _config;
    const document::DocumentType* _testdoctype1;

    static const uint32_t MSG_WAIT_TIME = 60 * 1000;

    using DocumentIndex = uint32_t;
    using PutTimestamp = uint64_t;

    void SetUp() override;
    void TearDown() override;
    void setupPersistenceThreads(uint32_t threads);
    void createBucket(const document::BucketId& bid);
    bool bucketExistsInDb(const document::BucketId& bucket) const;

    static api::StorageMessageAddress makeSelfAddress();

    api::ReturnCode::Result resultOf(const api::StorageReply& reply) const {
        return reply.getResult().getResult();
    }
    void setClusterState(const std::string&);

    struct StorageLinkInjector
    {
        virtual ~StorageLinkInjector() {}

        virtual void inject(DummyStorageLink&) const = 0;
    };

    struct NoOpStorageLinkInjector : StorageLinkInjector
    {
        void inject(DummyStorageLink&) const override {}
    };

    void
    expectNoReplies(DummyStorageLink& link) {
        EXPECT_EQ(0, link.getNumReplies());
    }

    template <typename ReplyType>
    void
    expectReply(DummyStorageLink& link,
                api::ReturnCode::Result result)
    {
        link.waitForMessages(1, 60*1000);
        api::StorageReply* reply(
                dynamic_cast<ReplyType*>(link.getReply(0).get()));
        if (reply == 0) {
            FAIL() << "got unexpected reply "
                   << link.getReply(0)->toString(true);
        }
        EXPECT_EQ(result, reply->getResult().getResult());
    }

    template <typename ReplyType>
    void
    expectAbortedReply(DummyStorageLink& link) {
        expectReply<ReplyType>(link, api::ReturnCode::ABORTED);
    }

    template <typename ReplyType>
    void
    expectOkReply(DummyStorageLink& link) {
        expectReply<ReplyType>(link, api::ReturnCode::OK);
    }


    struct TestFileStorComponents
    {
    private:
        FileStorTestFixture& _fixture;
    public:
        DummyStorageLink top;
        FileStorManager* manager;

        TestFileStorComponents(FileStorTestFixture& fixture,
                               const StorageLinkInjector& i = NoOpStorageLinkInjector());

        void sendDummyGet(const document::BucketId& bid);
        void sendPut(const document::BucketId& bid,
                     uint32_t docIdx,
                     uint64_t timestamp);
        void sendDummyGetDiff(const document::BucketId& bid);
    };
};

} // ns storage