Skip to content

Commit

Permalink
Added Batched Overwrite delete test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Fahad Siddiqui authored and Fahad Siddiqui committed Oct 23, 2024
1 parent 427d86c commit a7c0b41
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,5 +763,57 @@ async fn batched_overwrite() {
);
}

database.stop().await.unwrap();
}

#[async_test]
async fn batched_overwrite_delete() {
const COUNT: u64 = 1000;

let (_tmpdir, database) = test_init().await;
let mut batch = WriteBatch::new();

for pos in 0..COUNT {
let key = format!("key_{pos}").into_bytes();
let value = format!("some_string_{pos}").into_bytes();

batch.put(key, value);
}

database.write(batch).await.unwrap();

//Perform overwrite and delete in the same batch
let mut batch_overwrite_delete = WriteBatch::new();

for pos in 0..COUNT {
let key = format!("key_{pos}").into_bytes();

// Delete every tenth key
if pos % 10 == 0 {
batch_overwrite_delete.delete(key.clone());
}
// Overwrite every other key
else {
let new_value = format!("some_other_string_{pos}").into_bytes();
batch_overwrite_delete.put(key.clone(), new_value);
}
}

database.write(batch_overwrite_delete).await.unwrap();

for pos in 0..COUNT {
let key = format!("key_{pos}").into_bytes();

if pos % 10 == 0 {
assert!(database.get(&key).await.unwrap().is_none());
}
else {
let expected_value = format!("some_other_string_{pos}").into_bytes();
assert_eq!(
database.get(&key).await.unwrap().unwrap().get_value(),
expected_value
);
}
}
database.stop().await.unwrap();
}

0 comments on commit a7c0b41

Please sign in to comment.