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

getdozer / dozer / 4283961027

pending completion
4283961027

push

github

GitHub
feat: Blue green cache (#1061)

645 of 645 new or added lines in 45 files covered. (100.0%)

27779 of 39307 relevant lines covered (70.67%)

52489.81 hits per line

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

93.75
/dozer-types/src/node.rs
1
use std::{
2
    collections::HashMap,
3
    fmt::{Display, Formatter},
4
    str::from_utf8,
5
};
6

7
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
30,600✔
8
pub struct NodeHandle {
9
    pub ns: Option<u16>,
10
    pub id: String,
11
}
12

13
impl NodeHandle {
14
    pub fn new(ns: Option<u16>, id: String) -> Self {
16,044✔
15
        Self { ns, id }
16,044✔
16
    }
16,044✔
17
}
18

19
impl NodeHandle {
20
    pub fn to_bytes(&self) -> Vec<u8> {
54,622✔
21
        let mut r = Vec::<u8>::with_capacity(5);
54,622✔
22
        match self.ns {
54,622✔
23
            Some(ns) => {
8,531✔
24
                r.push(1_u8);
8,531✔
25
                r.extend(ns.to_le_bytes());
8,531✔
26
            }
8,531✔
27
            None => r.push(0_u8),
46,091✔
28
        }
29
        let id_buf = self.id.as_bytes();
54,622✔
30
        r.extend((id_buf.len() as u16).to_le_bytes());
54,622✔
31
        r.extend(id_buf);
54,622✔
32
        r
54,622✔
33
    }
54,622✔
34

35
    pub fn from_bytes(buffer: &[u8]) -> NodeHandle {
352✔
36
        match buffer[0] {
352✔
37
            1_u8 => {
38
                let ns = u16::from_le_bytes(buffer[1..3].try_into().unwrap());
301✔
39
                let id_len: u16 = u16::from_le_bytes(buffer[3..5].try_into().unwrap());
301✔
40
                let id = from_utf8(&buffer[5..5 + id_len as usize]).unwrap();
301✔
41
                NodeHandle::new(Some(ns), id.to_string())
301✔
42
            }
43
            _ => {
44
                let id_len: u16 = u16::from_le_bytes(buffer[1..3].try_into().unwrap());
51✔
45
                let id = from_utf8(&buffer[3..3 + id_len as usize]).unwrap();
51✔
46
                NodeHandle::new(None, id.to_string())
51✔
47
            }
48
        }
49
    }
352✔
50
}
51

52
impl Display for NodeHandle {
53
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
11,780✔
54
        let ns_str = match self.ns {
11,780✔
55
            Some(ns) => ns.to_string(),
8,670✔
56
            None => "r".to_string(),
3,110✔
57
        };
58
        f.write_str(&format!("{}_{}", ns_str, self.id))
11,780✔
59
    }
11,780✔
60
}
61

62
#[derive(Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
6,055✔
63
pub struct OpIdentifier {
64
    pub txid: u64,
65
    pub seq_in_tx: u64,
66
}
67

68
impl OpIdentifier {
69
    pub fn new(txid: u64, seq_in_tx: u64) -> Self {
15,680✔
70
        Self { txid, seq_in_tx }
15,680✔
71
    }
15,680✔
72

73
    pub fn to_bytes(&self) -> [u8; 16] {
54,600✔
74
        let mut result = [0_u8; 16];
54,600✔
75
        result[0..8].copy_from_slice(&self.txid.to_be_bytes());
54,600✔
76
        result[8..16].copy_from_slice(&self.seq_in_tx.to_be_bytes());
54,600✔
77
        result
54,600✔
78
    }
54,600✔
79

×
80
    pub fn from_bytes(bytes: [u8; 16]) -> Self {
340✔
81
        let txid = u64::from_be_bytes(bytes[0..8].try_into().unwrap());
340✔
82
        let seq_in_tx = u64::from_be_bytes(bytes[8..16].try_into().unwrap());
340✔
83
        Self::new(txid, seq_in_tx)
340✔
84
    }
340✔
85
}
×
86

×
87
pub type SourceStates = HashMap<NodeHandle, OpIdentifier>;
×
88

89
#[test]
1✔
90
fn test_handle_to_from_bytes() {
1✔
91
    let original = NodeHandle::new(Some(10), 100.to_string());
1✔
92
    let sz = original.to_bytes();
1✔
93
    let _decoded = NodeHandle::from_bytes(sz.as_slice());
1✔
94

1✔
95
    let original = NodeHandle::new(None, 100.to_string());
1✔
96
    let sz = original.to_bytes();
1✔
97
    let decoded = NodeHandle::from_bytes(sz.as_slice());
1✔
98

1✔
99
    assert_eq!(original, decoded)
1✔
100
}
1✔
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