summaryrefslogtreecommitdiffstats
path: root/storageserver/src/tests/storageservertest.cpp
blob: b18b241acaae1e2e9c4e2c1930012a11bcc8a506 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <tests/testhelper.h>
#include <vespa/storage/storageserver/distributornode.h>
#include <vespa/storage/storageserver/servicelayernode.h>
#include <vespa/storageserver/app/distributorprocess.h>
#include <vespa/storageserver/app/dummyservicelayerprocess.h>
#include <vespa/messagebus/message.h>
#include <vespa/vespalib/gtest/gtest.h>

#include <vespa/log/log.h>

LOG_SETUP(".storageservertest");

using namespace std::chrono_literals;

namespace storage {

struct StorageServerTest : public ::testing::Test {
    std::unique_ptr<mbus::Slobrok> slobrok;
    std::unique_ptr<vdstestlib::DirConfig> distConfig;
    std::unique_ptr<vdstestlib::DirConfig> storConfig;

    StorageServerTest();
    ~StorageServerTest() override;

    void SetUp() override;
    void TearDown() override;

};

StorageServerTest::StorageServerTest() = default;
StorageServerTest::~StorageServerTest() = default;

namespace {

struct Node {
    virtual ~Node() = default;
    virtual StorageNode& getNode() = 0;
    virtual StorageNodeContext& getContext() = 0;
};

struct Distributor : public Node {
    DistributorProcess _process;

    explicit Distributor(vdstestlib::DirConfig& config);
    ~Distributor() override;

    StorageNode& getNode() override { return _process.getNode(); }
    StorageNodeContext& getContext() override { return _process.getContext(); }
};

struct Storage : public Node {
    DummyServiceLayerProcess _process;
    StorageComponent::UP _component;

    explicit Storage(vdstestlib::DirConfig& config);
    ~Storage() override;

    StorageNode& getNode() override { return _process.getNode(); }
    StorageNodeContext& getContext() override { return _process.getContext(); }
};

Distributor::Distributor(vdstestlib::DirConfig& config)
    : _process(config::ConfigUri(config.getConfigId()))
{
    _process.setupConfig(60000ms);
    _process.createNode();
}

Distributor::~Distributor() = default;

Storage::Storage(vdstestlib::DirConfig& config)
    : _process(config::ConfigUri(config.getConfigId()))
{
    _process.setupConfig(60000ms);
    _process.createNode();
    _component = std::make_unique<StorageComponent>(getContext().getComponentRegister(), "test");
}

Storage::~Storage() = default;

}

void
StorageServerTest::SetUp()
{
    [[maybe_unused]] int systemResult = system("chmod -R 755 vdsroot");
    systemResult = system("rm -rf vdsroot*");
    slobrok = std::make_unique<mbus::Slobrok>();
    distConfig = std::make_unique<vdstestlib::DirConfig>(getStandardConfig(false));
    storConfig = std::make_unique<vdstestlib::DirConfig>(getStandardConfig(true));
    addSlobrokConfig(*distConfig, *slobrok);
    addSlobrokConfig(*storConfig, *slobrok);
    systemResult = system("mkdir -p vdsroot/disks/d0");
    systemResult = system("mkdir -p vdsroot.distributor");
}

void
StorageServerTest::TearDown()
{
    // TODO wipe temp dirs
    storConfig.reset(nullptr);
    distConfig.reset(nullptr);
    slobrok.reset(nullptr);
}

TEST_F(StorageServerTest, distributor_server_can_be_instantiated)
{
    Distributor distServer(*distConfig);
}

TEST_F(StorageServerTest, storage_server_can_be_instantiated)
{
    Storage storServer(*storConfig);
}

}