in below/src/test.rs [116:176]
fn advance_forward_and_reverse() {
let logger = get_logger();
let dir = TempDir::new("below_record_replay_test").expect("tempdir failed");
let mut store = store::StoreWriter::new(
logger.clone(),
&dir,
CompressionMode::ZstdDictionary(ChunkSizePo2(2)),
store::Format::Cbor,
)
.expect("Failed to create store");
// Collect and store the same sample 3 times
let timestamp = 554433;
let unix_ts = UNIX_EPOCH + Duration::from_secs(timestamp);
let sample = Collector::new(
logger.clone(),
/* collector_options */ Default::default(),
)
.collect_sample()
.expect("failed to collect sample");
for i in 0..3 {
let df = DataFrame {
sample: sample.clone(),
};
store
.put(unix_ts + Duration::from_secs(i), &df)
.expect("failed to store sample");
}
let mut advance = new_advance_local(logger, dir.as_ref().to_path_buf(), unix_ts);
advance.initialize();
// Basic sanity check that backstep then forward step time works
for i in 1..3 {
let sample = advance
.advance(store::Direction::Forward)
.expect("failed to get forward data");
assert_eq!(
sample
.timestamp
.duration_since(UNIX_EPOCH)
.expect("time before UNIX EPOCH")
.as_secs(),
timestamp + i
);
}
let direction_sample = advance
.advance(store::Direction::Reverse)
.expect("failed to get reverse data");
// We advanced forward 3 times and reversed once. That means we should
// expect to see the 2nd sample (at timestamp + 1).
assert_eq!(
direction_sample
.timestamp
.duration_since(UNIX_EPOCH)
.expect("time went backwards")
.as_secs(),
timestamp + 1
);
}