aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/common/testnodestateupdater.h
blob: 5e3001abee4aaf024a9e938966dccda8b5590250 (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
// 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;
    std::shared_ptr<const lib::ClusterStateBundle> _clusterStateBundle;
    std::vector<StateListener*> _listeners;
    size_t _explicit_node_state_reply_send_invocations;

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

    lib::NodeState::CSP getReportedNodeState() const override { return _reported; }
    lib::NodeState::CSP getCurrentNodeState() const override { return _current; }
    std::shared_ptr<const lib::ClusterStateBundle> getClusterStateBundle() const override;
    void addStateListener(StateListener& s) override { _listeners.push_back(&s); }
    void removeStateListener(StateListener&) override {}
    Lock::SP grabStateChangeLock() override { return std::make_shared<Lock>(); }
    void setReportedNodeState(const lib::NodeState& state) override {
        _reported = std::make_shared<lib::NodeState>(state);
    }
    void immediately_send_get_node_state_replies() override {
        ++_explicit_node_state_reply_send_invocations;
    }

    void setCurrentNodeState(const lib::NodeState& state) {
        _current = std::make_shared<lib::NodeState>(state);
    }

    void setClusterState(lib::ClusterState::CSP c);

    size_t explicit_node_state_reply_send_invocations() const noexcept {
        return _explicit_node_state_reply_send_invocations;
    }
};

} // storage