1#![allow(clippy::all)]
12
13tonic::include_proto!("reddb.v1");
14
15pub use reddb_wire::topology as topology_schema;
21pub use reddb_wire::{
22 decode_topology, encode_topology, Endpoint as TopologyEndpoint, ReplicaInfo as TopologyReplica,
23 Topology, TopologyError, MAX_KNOWN_TOPOLOGY_VERSION, TOPOLOGY_HEADER_SIZE,
24 TOPOLOGY_WIRE_VERSION_V1,
25};
26
27#[cfg(test)]
28mod topology_tests {
29 use super::*;
30
31 fn fixture() -> Topology {
32 Topology {
33 epoch: 7,
34 primary: TopologyEndpoint {
35 addr: "primary:5050".into(),
36 region: "eu-west-1".into(),
37 },
38 replicas: vec![TopologyReplica {
39 addr: "r1:5050".into(),
40 region: "eu-west-1".into(),
41 healthy: true,
42 lag_ms: 4,
43 last_applied_lsn: 99,
44 }],
45 }
46 }
47
48 #[test]
49 fn topology_round_trip_through_grpc_message() {
50 let t = fixture();
55 let canonical = encode_topology(&t);
56 let reply = TopologyReply {
57 topology_bytes: canonical.clone(),
58 };
59 assert_eq!(reply.topology_bytes, canonical);
61 let decoded = decode_topology(&reply.topology_bytes)
62 .expect("decode")
63 .expect("v1 known");
64 assert_eq!(decoded, t);
65 }
66
67 #[test]
68 fn topology_unknown_version_drops_cleanly() {
69 let t = fixture();
70 let mut bytes = encode_topology(&t);
71 bytes[0] = 0x80;
72 let reply = TopologyReply {
73 topology_bytes: bytes,
74 };
75 let decoded = decode_topology(&reply.topology_bytes).expect("decode");
76 assert!(decoded.is_none());
77 }
78}