aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/common/message_sender_stub.h
blob: 5aaf275c71980cbb486dde59ef5d9513b7c7b074 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/storage/common/messagesender.h>
#include <vector>

namespace storage {

struct MessageSenderStub : MessageSender {
    std::vector<std::shared_ptr<api::StorageCommand>> commands;
    std::vector<std::shared_ptr<api::StorageReply>> replies;

    MessageSenderStub();
    ~MessageSenderStub() override;

    void clear() {
        commands.clear();
        replies.clear();
    }

    void sendCommand(const std::shared_ptr<api::StorageCommand>& cmd) override {
        commands.push_back(cmd);
    }

    void sendReply(const std::shared_ptr<api::StorageReply>& reply) override {
        replies.push_back(reply);
    }

    std::string getLastCommand(bool verbose = true) const;

    std::string getCommands(bool includeAddress = false,
                            bool verbose = false,
                            uint32_t fromIndex = 0) const;

    std::string getLastReply(bool verbose = true) const;

    std::string getReplies(bool includeAddress = false,
                           bool verbose = false) const;

    static std::string dumpMessage(const api::StorageMessage& msg,
                                   bool includeAddress,
                                   bool verbose);
};


}