use crate::tests::{
test_db::TestDB,
util::{random_bytes, random_max_file_size},
};
#[tokio::test]
async fn horizontal_stress() {
let chunk_size = 100;
let max_file_size = 1_000;
let mut test_db = TestDB::open("horizontal_stress", Some(chunk_size), Some(max_file_size))
.await
.unwrap();
let mut block_keys = vec![];
for _ in 0..1_000 {
let bytes = random_bytes(random_max_file_size(max_file_size));
let block_key = test_db.write(&bytes, true).await.unwrap();
block_keys.push((block_key, bytes));
}
let (block_keys_split_one, block_keys_split_two) = block_keys.split_at(block_keys.len() / 2);
for (block_key, bytes) in block_keys_split_one.iter() {
test_db.free(block_key, bytes).await.unwrap();
}
test_db
.compact(
None,
block_keys_split_one
.iter()
.map(|(_, b)| b)
.collect::<Vec<&Vec<u8>>>(),
)
.await
.unwrap();
for (block_key, _) in block_keys_split_one {
test_db.read(block_key, None).await.unwrap();
}
let block_keys_split_two = block_keys_split_two.to_vec();
let mut block_keys_split_two_free_batch = vec![];
for (block_key, bytes) in block_keys_split_two.iter() {
block_keys_split_two_free_batch.push((block_key, bytes));
}
test_db
.batch(vec![], block_keys_split_two_free_batch, 0)
.await
.unwrap();
test_db
.compact(
None,
block_keys_split_two
.iter()
.map(|(_, b)| b)
.collect::<Vec<&Vec<u8>>>(),
)
.await
.unwrap();
for (block_key, _) in block_keys {
test_db.read(&block_key, None).await.unwrap();
}
test_db.cleanup().await.unwrap();
}