File: raft.h

package info (click to toggle)
dqlite 1.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,372 kB
  • sloc: ansic: 57,583; makefile: 336; sh: 243
file content (79 lines) | stat: -rw-r--r-- 2,829 bytes parent folder | download | duplicates (2)
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
/**
 * Helpers for setting up a standalone raft instance with a libuv transport.
 */

#ifndef TEST_RAFT_H
#define TEST_RAFT_H

#include <uv.h>

#include "../../src/fsm.h"
#include "../../src/raft.h"
#include "../../src/transport.h"
#include "fs.h"
#include "logger.h"
#include "munit.h"
#include "uv.h"

#include "../../src/lib/threadpool.h"

#define FIXTURE_RAFT                             \
	char *dir;                               \
	struct uv_loop_s loop;                   \
	struct raft_uv_transport raft_transport; \
	struct raft_io raft_io;                  \
	struct raft_fsm fsm;                     \
	struct raft raft

#define SETUP_RAFT                                                       \
	{                                                                \
		int rv2;                                                 \
		f->dir = test_dir_setup();                               \
		test_uv_setup(params, &f->loop);                         \
		rv2 = raftProxyInit(&f->raft_transport, &f->loop);       \
		munit_assert_int(rv2, ==, 0);                            \
		rv2 = raft_uv_init(&f->raft_io, &f->loop, f->dir,        \
				   &f->raft_transport);                  \
		munit_assert_int(rv2, ==, 0);                            \
		rv2 = fsm__init(&f->fsm, &f->config, &f->registry);      \
		munit_assert_int(rv2, ==, 0);                            \
		rv2 = raft_init(&f->raft, &f->raft_io, &f->fsm, 1, "1"); \
		munit_assert_int(rv2, ==, 0);                            \
	}

#define TEAR_DOWN_RAFT                              \
	{                                           \
		raft_close(&f->raft, NULL);         \
		test_uv_stop(&f->loop);             \
		raft_uv_close(&f->raft_io);         \
		fsm__close(&f->fsm);                \
		test_uv_tear_down(&f->loop);        \
		raftProxyClose(&f->raft_transport); \
		test_dir_tear_down(f->dir);         \
	}

/**
 * Bootstrap the fixture raft instance with a configuration containing only
 * itself.
 */
#define RAFT_BOOTSTRAP                                               \
	{                                                            \
		struct raft_configuration configuration;             \
		int rv2;                                             \
		raft_configuration_init(&configuration);             \
		rv2 = raft_configuration_add(&configuration, 1, "1", \
					     RAFT_VOTER);            \
		munit_assert_int(rv2, ==, 0);                        \
		rv2 = raft_bootstrap(&f->raft, &configuration);      \
		munit_assert_int(rv2, ==, 0);                        \
		raft_configuration_close(&configuration);            \
	}

#define RAFT_START                            \
	{                                     \
		int rv2;                      \
		rv2 = raft_start(&f->raft);   \
		munit_assert_int(rv2, ==, 0); \
	}

#endif /* TEST_RAFT_H */