d_engine_core/test_utils/
entry_builder.rs1use bytes::Bytes;
2use d_engine_proto::common::Entry;
3use d_engine_proto::common::EntryPayload;
4use d_engine_proto::common::membership_change::Change;
5
6pub struct EntryBuilder {
7 index: u64,
8 term: u64,
9}
10
11impl EntryBuilder {
12 pub fn new(
13 start_index: u64,
14 term: u64,
15 ) -> Self {
16 Self {
17 index: start_index,
18 term,
19 }
20 }
21
22 pub fn command(
23 mut self,
24 data: &[u8],
25 ) -> (Self, Entry) {
26 let entry = Entry {
27 index: self.index,
28 term: self.term,
29 payload: Some(EntryPayload::command(Bytes::from(data.to_vec()))),
30 };
31 self.index += 1;
32 (self, entry)
33 }
34
35 pub fn config(
36 mut self,
37 change: Change,
38 ) -> (Self, Entry) {
39 let entry = Entry {
40 index: self.index,
41 term: self.term,
42 payload: Some(EntryPayload::config(change)),
43 };
44 self.index += 1;
45 (self, entry)
46 }
47
48 pub fn noop(mut self) -> (Self, Entry) {
49 let entry = Entry {
50 index: self.index,
51 term: self.term,
52 payload: Some(EntryPayload::noop()),
53 };
54 self.index += 1;
55 (self, entry)
56 }
57}