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 smoke() {
    let mut test_db = TestDB::open("smoke", Some(100), Some(10_000))
        .await
        .unwrap();

    let bytes_one = b"Hello".to_vec();
    let bytes_two = b"World!".to_vec();
    let bytes_three = b"Salve".to_vec();
    let bytes_four = b"Mundus!".to_vec();
    let bytes_five = vec![6; 10_000];
    let bytes_six = vec![7; 10_000];

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

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

    let block_key_three = test_db.write(&bytes_three, false).await.unwrap();

    test_db.free(&block_key_two, &bytes_two).await.unwrap();

    test_db
        .compact(Some(vec![&block_key_two.data_file_id]), vec![&bytes_two])
        .await
        .unwrap();

    test_db
        .compact::<Vec<u8>>(Some(vec![&block_key_two.data_file_id]), vec![])
        .await
        .unwrap();

    let block_key_four = test_db.write(&bytes_four, false).await.unwrap();

    test_db
        .batch(
            vec![&bytes_five, &bytes_six],
            vec![
                (&block_key_three, &bytes_three),
                (&block_key_four, &bytes_four),
            ],
            1,
        )
        .await
        .unwrap();

    test_db.cleanup().await.unwrap();
}