use lsm_tree::{
    AbstractTree, Config, SequenceNumberCounter, config::BlockSizePolicy, get_tmp_folder,
};
use test_log::test;

#[test]
fn table_reader_mvcc_slab() -> lsm_tree::Result<()> {
    const ITEM_COUNT: usize = 10_000;

    let folder = get_tmp_folder();

    let seqno = SequenceNumberCounter::default();

    let tree = Config::new(&folder, seqno.clone(), SequenceNumberCounter::default())
        .data_block_size_policy(BlockSizePolicy::all(1_024))
        // .index_block_size_policy(BlockSizePolicy::all(1_024))
        .open()?;

    for _ in 0..ITEM_COUNT {
        tree.insert("a", "", seqno.next());
    }
    tree.insert("b", "", 0);

    tree.flush_active_memtable(0)?;

    let version = tree.current_version();

    let table = version
        .level(0)
        .expect("level should exist")
        .first()
        .expect("run should exist")
        .first()
        .expect("table should exist");

    let reader = table.iter();
    assert_eq!(reader.count(), ITEM_COUNT + 1);

    Ok(())
}
