summaryrefslogtreecommitdiffstats
path: root/memfilepersistence/src/tests/spi/providerconformancetest.cpp
blob: 8bc2237265b601053287fcda985cd5d57f791cba (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/fastos/fastos.h>
#include <vespa/log/log.h>
#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/persistence/conformancetest/conformancetest.h>
#include <vespa/storageframework/defaultimplementation/component/componentregisterimpl.h>
#include <vespa/storageframework/defaultimplementation/clock/realclock.h>
#include <vespa/storageframework/defaultimplementation/memory/memorymanager.h>
#include <vespa/storageframework/defaultimplementation/memory/simplememorylogic.h>
#include <vespa/storageframework/generic/memory/memorymanagerinterface.h>
#include <vespa/memfilepersistence/memfile/memfilecache.h>
#include <vespa/memfilepersistence/spi/memfilepersistenceprovider.h>
#include <tests/spi/memfiletestutils.h>

LOG_SETUP(".test.dummyimpl");

namespace storage {
namespace memfile {

struct ProviderConformanceTest : public spi::ConformanceTest {
    struct Factory : public PersistenceFactory {
        framework::defaultimplementation::ComponentRegisterImpl _compRegister;
        framework::defaultimplementation::RealClock _clock;
        framework::defaultimplementation::MemoryManager _memoryManager;
        std::unique_ptr<MemFileCache> cache;

        Factory()
            : _compRegister(),
              _clock(),
              _memoryManager(
                    framework::defaultimplementation::AllocationLogic::UP(
                        new framework::defaultimplementation::SimpleMemoryLogic(
                            _clock, 1024 * 1024 * 1024)))
        {
            _compRegister.setClock(_clock);
            _compRegister.setMemoryManager(_memoryManager);
        }

        spi::PersistenceProvider::UP
        getPersistenceImplementation(const document::DocumentTypeRepo::SP& repo,
                                     const document::DocumenttypesConfig&) override
        {
            system("rm -rf vdsroot");
            system("mkdir -p vdsroot/disks/d0");
            vdstestlib::DirConfig config(getStandardConfig(true));

            MemFilePersistenceProvider::UP result(
                    new MemFilePersistenceProvider(
                            _compRegister,
                            config.getConfigId()));
            result->setDocumentRepo(*repo);
            return spi::PersistenceProvider::UP(result.release());
        }

        bool
        supportsRevert() const
        {
            return true;
        }
    };

    ProviderConformanceTest()
        : spi::ConformanceTest(PersistenceFactory::UP(new Factory)) {}

    CPPUNIT_TEST_SUITE(ProviderConformanceTest);
    DEFINE_CONFORMANCE_TESTS();
    CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(ProviderConformanceTest);

} // memfile
} // storage