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

#include <tests/testhelper.h>
#include <tests/common/storage_config_set.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<StorageConfigSet> dist_config;
    std::unique_ptr<StorageConfigSet> stor_config;

    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 final : public Node {
    DistributorProcess _process;

    explicit Distributor(const config::ConfigUri& config_uri);
    ~Distributor() override;

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

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

    explicit Storage(const config::ConfigUri& config_uri);
    ~Storage() override;

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

Distributor::Distributor(const config::ConfigUri& config_uri)
    : _process(config_uri)
{
    _process.setupConfig(60000ms);
    _process.createNode();
}

Distributor::~Distributor() = default;

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

Storage::~Storage() = default;

}

void
StorageServerTest::SetUp()
{
    slobrok = std::make_unique<mbus::Slobrok>();
    dist_config = StorageConfigSet::make_distributor_node_config();
    stor_config = StorageConfigSet::make_storage_node_config();
    dist_config->set_slobrok_config_port(slobrok->port());
    stor_config->set_slobrok_config_port(slobrok->port());
}

void
StorageServerTest::TearDown()
{
    stor_config.reset();
    dist_config.reset();
    slobrok.reset();
}

TEST_F(StorageServerTest, distributor_server_can_be_instantiated)
{
    Distributor distServer(dist_config->config_uri());
}

TEST_F(StorageServerTest, storage_server_can_be_instantiated)
{
    Storage storServer(stor_config->config_uri());
}

}