aboutsummaryrefslogtreecommitdiffstats
path: root/persistence/src/vespa/persistence/conformancetest/conformancetest.h
blob: da779e1587bcf9c1c7d8be163e6bea74a061c4e9 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * This conformance test class has been created in order to run the same tests
 * on multiple implementations of the persistence SPI.
 *
 * To run conformance tests on a given implementation, just add a little wrapper
 * such as the dummy persistence implementation does. (See dummyimpltest.cpp)
 */
#pragma once

#include <vespa/document/config/documenttypes_config_fwd.h>
#include <vespa/persistence/spi/persistenceprovider.h>
#include <gtest/gtest.h>

namespace document
{

class DocumentTypeRepo;
class TestDocMan;

}

namespace storage::spi {

class ConformanceTest : public ::testing::Test {

public:
    using PersistenceProviderUP = std::unique_ptr<PersistenceProvider>;
    struct PersistenceFactory {
        using UP = std::unique_ptr<PersistenceFactory>;

        virtual ~PersistenceFactory() = default;
        virtual PersistenceProviderUP getPersistenceImplementation(
                const std::shared_ptr<const document::DocumentTypeRepo> &repo,
                const DocumenttypesConfig &typesCfg) = 0;

        virtual void
        clear(void)
        {
            // clear persistent state, i.e. remove files/directories
        }

        virtual bool
        hasPersistence(void) const
        {
            return false;
        }
        virtual bool
        supportsActiveState() const
        {
            return false;
        }
        virtual bool
        supportsRemoveEntry() const
        {
            return false;
        }
        // If bucket spaces are supported then testdoctype2 is in bucket space 1
        virtual bool supportsBucketSpaces() const { return false; }
    };

    // Set by test runner.
    static std::unique_ptr<PersistenceFactory>(*_factoryFactory)(const std::string &docType);

protected:
    PersistenceFactory::UP _factory;

    void populateBucket(const Bucket& b,
                        PersistenceProvider& spi,
                        uint32_t from,
                        uint32_t to,
                        document::TestDocMan& testDocMan);

    void
    testDeleteBucketPostCondition(const PersistenceProvider &spi,
                                  const Bucket &bucket,
                                  const Document &doc1);

    void
    testSplitNormalCasePostCondition(const PersistenceProvider &spi,
                                     const Bucket &bucketA,
                                     const Bucket &bucketB,
                                     const Bucket &bucketC,
                                     document::TestDocMan &testDocMan);

    void
    testSplitTargetExistsPostCondition(const PersistenceProvider &spi,
                                       const Bucket &bucketA,
                                       const Bucket &bucketB,
                                       const Bucket &bucketC,
                                       document::TestDocMan &testDocMan);

    void
    testSplitSingleDocumentInSourcePostCondition(
            const PersistenceProvider& spi,
            const Bucket& source,
            const Bucket& target1,
            const Bucket& target2,
            document::TestDocMan& testDocMan);

    void
    createAndPopulateJoinSourceBuckets(
            PersistenceProvider& spi,
            const Bucket& source1,
            const Bucket& source2,
            document::TestDocMan& testDocMan);

    void
    doTestJoinNormalCase(const Bucket& source1,
                         const Bucket& source2,
                         const Bucket& target);

    void
    testJoinNormalCasePostCondition(const PersistenceProvider &spi,
                                    const Bucket &bucketA,
                                    const Bucket &bucketB,
                                    const Bucket &bucketC,
                                    document::TestDocMan &testDocMan);

    void
    testJoinTargetExistsPostCondition(const PersistenceProvider &spi,
                                      const Bucket &bucketA,
                                      const Bucket &bucketB,
                                      const Bucket &bucketC,
                                      document::TestDocMan &testDocMan);

    void
    testJoinOneBucketPostCondition(const PersistenceProvider &spi,
                                   const Bucket &bucketA,
                                   const Bucket &bucketC,
                                   document::TestDocMan &testDocMan);

    void
    doTestJoinSameSourceBuckets(const Bucket& source,
                                const Bucket& target);

    void
    testJoinSameSourceBucketsPostCondition(
            const PersistenceProvider& spi,
            const Bucket& source,
            const Bucket& target,
            document::TestDocMan& testDocMan);

    void
    testJoinSameSourceBucketsTargetExistsPostCondition(
            const PersistenceProvider& spi,
            const Bucket& source,
            const Bucket& target,
            document::TestDocMan& testDocMan);

    void test_iterate_empty_or_missing_bucket(bool bucket_exists);

    void test_empty_bucket_info(bool bucket_exists, bool active);

    ConformanceTest();
    ConformanceTest(const std::string &docType);
};

class SingleDocTypeConformanceTest : public ConformanceTest
{
protected:
    SingleDocTypeConformanceTest();
};

}