mod lifecycle;
mod live_reload;
mod payload_storage_read;
use crate::blobstore::BlobstoreReader;
use crate::common::universal_io::UniversalRead;
use crate::segment::types::Payload;
pub struct ReadOnlyPayloadStorage<S: UniversalRead> {
storage: BlobstoreReader<Payload, S>,
}
#[cfg(test)]
mod tests {
use crate::common::counter::hardware_counter::HardwareCounterCell;
use crate::common::universal_io::{MmapFile, Populate, ReadOnly, UniversalRead, UniversalReadFileOps};
use rstest::rstest;
use tempfile::TempDir;
use super::ReadOnlyPayloadStorage;
use crate::segment::payload_json;
use crate::segment::payload_storage::payload_storage_impl::PayloadStorageImpl;
use crate::segment::payload_storage::{PayloadStorage, PayloadStorageRead};
#[rstest]
fn read_only_payload_storage_round_trip(
#[values(Populate::No, Populate::PreferBackground)] populate: Populate,
) {
let dir = TempDir::with_prefix("read_only_payload").unwrap();
let hw_counter = HardwareCounterCell::new();
let payload = payload_json! {
"a": "some text",
"n": 42,
};
{
let mut storage: PayloadStorageImpl =
PayloadStorageImpl::open_or_create(dir.path().to_path_buf(), false).unwrap();
for i in 0..5 {
storage.set(i, &payload, &hw_counter).unwrap();
}
storage.flusher()().unwrap();
}
type RoFs = <ReadOnly<MmapFile> as UniversalRead>::Fs;
let fs = RoFs::from_context(Default::default()).unwrap();
let storage: ReadOnlyPayloadStorage<ReadOnly<MmapFile>> =
ReadOnlyPayloadStorage::open(&fs, dir.path().to_path_buf(), populate).unwrap();
assert_eq!(storage.is_on_disk(), !populate.to_bool::<MmapFile>());
for i in 0..5 {
assert_eq!(storage.get(i, &hw_counter).unwrap(), payload);
}
assert_eq!(storage.get(99, &hw_counter).unwrap(), payload_json! {});
}
}