• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ivanallen / pain / 17189463775

24 Aug 2025 01:41PM UTC coverage: 57.529% (-25.6%) from 83.114%
17189463775

push

github

ivanallen
add mock deva

Signed-off-by: allen <1007729991@qq.com>

842 of 2633 branches covered (31.98%)

98 of 128 new or added lines in 5 files covered. (76.56%)

14 existing lines in 2 files now uncovered.

1001 of 1740 relevant lines covered (57.53%)

256.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.84
/src/deva/mock/deva_machine.h
1
#include <brpc/server.h>
2
#include <butil/debug/leak_annotations.h>
3
#include <pain/base/types.h>
4
#include "deva/deva.h"
5
#include "deva/deva_service_impl.h"
6
#include "deva/rsm.h"
7

8
namespace pain::deva::mock {
9

10
class DevaMachine {
11
public:
12
    DevaMachine(const char* data_path, const char* group, const char* address, const char* node_conf) :
5✔
13
        _address(address),
15!
14
        _node_conf(node_conf) {
15!
15
        braft::NodeOptions node_options;
5!
16
        if (node_options.initial_conf.parse_from(node_conf) != 0) {
5!
NEW
17
            BOOST_ASSERT_MSG(false, "Fail to parse configuration");
×
18
        }
19
        butil::EndPoint addr;
5✔
20
        if (butil::str2endpoint(_address.c_str(), &addr) != 0) {
5!
NEW
21
            BOOST_ASSERT_MSG(false, "Fail to parse address");
×
22
        }
23

24
        node_options.election_timeout_ms = 5000; // NOLINT
5✔
25
        node_options.node_owns_fsm = false;
5✔
26
        node_options.snapshot_interval_s = 30; // NOLINT
5✔
27
        std::string prefix = fmt::format("local://{}", data_path);
5✔
28
        node_options.log_uri = fmt::format("{}/{}/log", prefix, group);
10✔
29
        node_options.raft_meta_uri = fmt::format("{}/{}/raft_meta", prefix, group);
10✔
30
        node_options.snapshot_uri = fmt::format("{}/{}/snapshot", prefix, group);
10✔
31

32
        _rsm = new Rsm(addr, group, node_options, new Deva());
15!
33
    }
10✔
34

35
    Status start() {
5✔
36
        auto deva_service_impl = new pain::deva::DevaServiceImpl;
5!
37
        if (_server.AddService(deva_service_impl, brpc::SERVER_OWNS_SERVICE) != 0) {
5!
NEW
38
            return Status(EINVAL, "Fail to add service");
×
39
        }
40

41
        if (braft::add_service(&_server, _address.c_str()) != 0) {
5!
NEW
42
            return Status(EINVAL, "Fail to add raft service");
×
43
        }
44

45
        brpc::ServerOptions options;
5!
46
        options.idle_timeout_sec = -1;
5✔
47
        ANNOTATE_SCOPED_MEMORY_LEAK;
5!
48
        if (_server.Start(_address.c_str(), &options) != 0) {
5!
NEW
49
            return Status(EINVAL, "Fail to start EchoServer");
×
50
        }
51

52
        _rsm->start();
5!
53
        return Status::OK();
5✔
54
    }
5✔
55

56
    void stop() {
5✔
57
        _server.Stop(0);
5✔
58
        _server.Join();
5✔
59
        _rsm->shutdown();
5✔
60
        _rsm->join();
5✔
61
    }
5✔
62

63
private:
64
    std::string _address;
65
    std::string _node_conf;
66
    brpc::Server _server;
67
    RsmPtr _rsm;
68
};
69

70
} // namespace pain::deva::mock
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc