use cesiumdb::{Db, DbOptions};

#[test]
fn stress_concurrent_puts_small_memtables() {
    let _ = std::fs::remove_dir_all("/tmp/cesiumdb_stress");
    let mut opts = DbOptions::default();
    opts.data_dir(std::path::PathBuf::from("/tmp/cesiumdb_stress"))
        .memtable_size(1024 * 1024)
        .max_memtables(4);
    
    let db = Db::open(opts).unwrap();
    
    let handles: Vec<_> = (0..8)
        .map(|tid| {
            let db = db.clone();
            std::thread::spawn(move || {
                for i in 0..10_000u64 {
                    let key = format!("key-{}-{}", tid, i);
                    let value = vec![0u8; 400];
                    db.put(key.as_bytes(), &value).unwrap();
                }
            })
        })
        .collect();
    
    for h in handles {
        h.join().unwrap();
    }
}
