MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / write_then_read_roundtrip

Function write_then_read_roundtrip

nodedb-wal/src/reader.rs:221–257  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

219
220 #[test]
221 fn write_then_read_roundtrip() {
222 let dir = tempfile::tempdir().unwrap();
223 let path = dir.path().join("test.wal");
224
225 // Write records.
226 {
227 let mut writer = WalWriter::open_without_direct_io(&path).unwrap();
228 writer
229 .append(RecordType::Put as u32, 1, 0, 0, b"first")
230 .unwrap();
231 writer
232 .append(RecordType::Put as u32, 2, 1, 0, b"second")
233 .unwrap();
234 writer
235 .append(RecordType::Delete as u32, 1, 0, 0, b"third")
236 .unwrap();
237 writer.sync().unwrap();
238 }
239
240 // Read them back.
241 let reader = WalReader::open(&path).unwrap();
242 let records: Vec<_> = reader.records().collect::<Result<_>>().unwrap();
243
244 assert_eq!(records.len(), 3);
245 assert_eq!(records[0].header.lsn, 1);
246 assert_eq!(records[0].header.tenant_id, 1);
247 assert_eq!(records[0].payload, b"first");
248
249 assert_eq!(records[1].header.lsn, 2);
250 assert_eq!(records[1].header.tenant_id, 2);
251 assert_eq!(records[1].header.vshard_id, 1);
252 assert_eq!(records[1].payload, b"second");
253
254 assert_eq!(records[2].header.lsn, 3);
255 assert_eq!(records[2].header.record_type, RecordType::Delete as u32);
256 assert_eq!(records[2].payload, b"third");
257 }
258
259 #[test]
260 fn empty_wal_yields_no_records() {

Callers

nothing calls this directly

Calls 6

joinMethod · 0.80
openFunction · 0.50
pathMethod · 0.45
appendMethod · 0.45
syncMethod · 0.45
recordsMethod · 0.45

Tested by

no test coverage detected