aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/persistence/common/filestortestfixture.h
blob: c8158d0122419334b290bad157269426a88dabf9 (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
104
105
106
107
108
109
110
111
112
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vdstestlib/cppunit/macros.h>
#include <tests/common/testhelper.h>
#include <vespa/persistence/spi/persistenceprovider.h>
#include <vespa/storage/persistence/filestorage/filestormanager.h>
#include <vespa/storageapi/message/persistence.h>
#include <tests/common/dummystoragelink.h>
#include <tests/common/teststorageapp.h>
#include <tests/common/testhelper.h>

namespace storage {

class FileStorTestFixture : public CppUnit::TestFixture
{
public:
    static spi::LoadType defaultLoadType;

    std::unique_ptr<TestServiceLayerApp> _node;
    std::unique_ptr<vdstestlib::DirConfig> _config;
    std::unique_ptr<vdstestlib::DirConfig> _config2;
    std::unique_ptr<vdstestlib::DirConfig> _smallConfig;
    const document::DocumentType* _testdoctype1;

    static const uint32_t MSG_WAIT_TIME = 60 * 1000;

    typedef uint32_t DocumentIndex;
    typedef uint64_t PutTimestamp;

    void setUp() override;
    void tearDown() override;
    void setupDisks(uint32_t diskCount);
    void createBucket(const document::BucketId& bid);
    bool bucketExistsInDb(const document::BucketId& bucket) const;

    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) {
        CPPUNIT_ASSERT_EQUAL(size_t(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) {
            std::ostringstream ss;
            ss << "got unexpected reply "
            << link.getReply(0)->toString(true);
            CPPUNIT_FAIL(ss.str());
        }
        CPPUNIT_ASSERT_EQUAL(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:
        TestName _testName;
        FileStorTestFixture& _fixture;
    public:
        DummyStorageLink top;
        FileStorManager* manager;

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

        api::StorageMessageAddress makeSelfAddress() const;

        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