use cesiumdb::{Db, DbOptions};

fn main() {
    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(512 * 1024)
        .max_memtables(4);
    
    let db = Db::open(opts).unwrap();
    
    let handles: Vec<_> = (0..16)
        .map(|tid| {
            let db = db.clone();
            std::thread::spawn(move || {
                for i in 0..50_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();
    }
    
    println!("Done. Checking disk...");
    let output = std::process::Command::new("sh")
        .arg("-c")
        .arg("find /tmp/cesiumdb_stress -type d | wc -l && find /tmp/cesiumdb_stress -type f | wc -l")
        .output()
        .unwrap();
    println!("{}", String::from_utf8_lossy(&output.stdout));
}
