rust-rocksdb-zaidoon1/tests/test_sst_file_manager.rs
Zaidoon Abd Al Hadi 9521bc4879
sync with upstream & upgrade to Rust edition 2024 and MSRV 1.89.0 (#187)
* ci: use actions/checkout@v5l (#1043)

* feat: allow user to set checkpoint log size for flush (#1055)

* upgrade to Rust edition 2024 and MSRV 1.89.0

---------

Co-authored-by: Coder <161350311+MamunC0der@users.noreply.github.com>
Co-authored-by: QuantumExplorer <quantum@dash.org>
2025-12-29 13:24:47 -05:00

50 lines
1.7 KiB
Rust

mod util;
use rust_rocksdb::sst_file_manager::SstFileManager;
use rust_rocksdb::{DB, FlushOptions, Options};
use util::DBPath;
#[test]
fn test_sst_file_manager_config_and_sizes() {
let path = DBPath::new("_rust_rocksdb_test_sst_file_manager_config_and_sizes");
let sfm = SstFileManager::new();
// Set compaction buffer size (no direct getter, just ensure it doesn't panic).
sfm.set_compaction_buffer_size(64 * 1024);
// Delete rate and max trash/db ratio should round-trip.
sfm.set_delete_rate_bytes_per_second(1024);
assert_eq!(sfm.get_delete_rate_bytes_per_second(), 1024);
sfm.set_max_trash_db_ratio(0.25);
assert_eq!(sfm.get_max_trash_db_ratio(), 0.25);
// Hook into Options and open a DB.
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_sst_file_manager(&sfm);
let db = DB::open(&opts, &path).unwrap();
// Write enough data and flush to create at least one SST file.
for i in 0..1000u32 {
db.put(format!("k{:04}", i).as_bytes(), b"value").unwrap();
}
let mut fopts = FlushOptions::default();
fopts.set_wait(true);
db.flush_opt(&fopts).unwrap();
// After flush we should have some SST size accounted for.
let total_size = sfm.get_total_size();
assert!(total_size > 0, "expected some SST size; got {}", total_size);
// Now set the space limit just below current usage and ensure flags flip.
let limit = total_size.saturating_sub(1);
sfm.set_max_allowed_space_usage(limit);
assert!(sfm.is_max_allowed_space_reached());
assert!(sfm.is_max_allowed_space_reached_including_compactions());
// Trash size is non-negative; may be zero depending on environment.
let _trash = sfm.get_total_trash_size();
}