block-db 0.2.0

Local, multi-threaded, durable byte DB.
Documentation
// Authors: Robert Lopez

use crate::tests::test_db::TestDB;

#[tokio::test]
async fn re_open_smoke() {
    let chunk_size = 4_096;
    let max_file_size = 4_096_000_000;

    let bytes_one = b"Hello".to_vec();
    let bytes_two = b"World!".to_vec();
    let bytes_three = b"Hallo".to_vec();
    let bytes_four = b"Welt!".to_vec();

    let mut test_db = TestDB::open("re_open_smoke", Some(chunk_size), Some(max_file_size))
        .await
        .unwrap();

    let block_key_one = test_db.write(&bytes_one, true).await.unwrap();

    test_db.free(&block_key_one, &bytes_one).await.unwrap();

    let block_key_two = test_db.write(&bytes_two, false).await.unwrap();

    let new_block_keys = test_db
        .batch(
            vec![&bytes_three, &bytes_four],
            vec![(&block_key_two, &bytes_two)],
            0,
        )
        .await
        .unwrap();

    test_db.read(&block_key_one, None).await.unwrap();
    test_db.read(&block_key_two, None).await.unwrap();

    test_db
        .read(&new_block_keys[0], Some(b"Hallo"))
        .await
        .unwrap();
    test_db
        .read(&new_block_keys[1], Some(b"Welt!"))
        .await
        .unwrap();

    test_db.compact(None, vec![&bytes_two]).await.unwrap();

    let test_state = test_db.test_state.clone();

    drop(test_db);

    let test_db = TestDB::re_open("re_open_smoke", test_state).await.unwrap();

    test_db.read(&block_key_one, None).await.unwrap();
    test_db.read(&block_key_two, None).await.unwrap();

    test_db
        .read(&new_block_keys[0], Some(b"Hallo"))
        .await
        .unwrap();
    test_db
        .read(&new_block_keys[1], Some(b"Welt!"))
        .await
        .unwrap();
}