#![cfg(all(feature = "armour", feature = "typed-tree", feature = "rapira-codec"))]
use armdb::armour::Db;
use armdb::{CollectionMeta, Config, NoHook, RapiraCodec, TtlPolicy};
use armour_core::GetType;
use rapira::Rapira;
use tempfile::tempdir;
#[derive(Clone, Debug, PartialEq, Rapira, GetType)]
struct Row {
expires_at_ms: u64,
}
impl CollectionMeta for Row {
type SelfId = [u8; 8];
const NAME: &'static str = "ttl_t5_commit_rows";
const TTL: Option<TtlPolicy<Self>> = Some(TtlPolicy {
revision: 1,
deadline: |row, _| Some(row.expires_at_ms),
});
}
fn key(id: u64) -> [u8; 8] {
id.to_be_bytes()
}
#[test]
#[ignore = "waits for T5 merge"]
fn row_in_committed_multi_collection_tx_expires() {
let dir = tempdir().unwrap();
let db = Db::open_test(dir.path()).unwrap();
let tree = db
.open_typed_tree::<Row, RapiraCodec, NoHook>(Config::test(), NoHook, &[])
.unwrap();
tree.build_ttl_index().unwrap();
let k = key(1);
tree.put(&k, Row { expires_at_ms: 1 }).unwrap();
tree.sweep_expired(2, usize::MAX).unwrap();
assert!(
!tree.contains(&k),
"row written inside committed tx must be physically removed after deadline"
);
}