summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/common/testnodestateupdater.h
blob: 3e5dfed560d5619cec0c4d85c0890af28aead4b5 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * \class storage::TestNodeStateUpdater
 * \ingroup common
 *
 * \brief Test implementation of the node state updater.
 */

#pragma once

#include <vespa/storage/common/nodestateupdater.h>

namespace storage {

struct TestNodeStateUpdater : public NodeStateUpdater
{
    lib::NodeState::CSP _reported;
    lib::NodeState::CSP _current;
    lib::ClusterState::CSP _cluster;
    std::vector<StateListener*> _listeners;

public:
    TestNodeStateUpdater(const lib::NodeType& type);
    ~TestNodeStateUpdater();

    lib::NodeState::CSP getReportedNodeState() const override { return _reported; }
    lib::NodeState::CSP getCurrentNodeState() const override { return _current; }
    lib::ClusterState::CSP getSystemState() const override { return _cluster; }
    void addStateListener(StateListener& s) override { _listeners.push_back(&s); }
    void removeStateListener(StateListener&) override {}
    Lock::SP grabStateChangeLock() override { return Lock::SP(new Lock); }
    void setReportedNodeState(const lib::NodeState& state) override { _reported.reset(new lib::NodeState(state)); }

    void setCurrentNodeState(const lib::NodeState& state) { _current.reset(new lib::NodeState(state)); }

    void setClusterState(lib::ClusterState::CSP c)  {
        _cluster = c;
        for (uint32_t i = 0; i < _listeners.size(); ++i) {
            _listeners[i]->handleNewState();
        }
    }
};

} // storage