Moves CacheHashData test-only methods into tests module (#33170)
This commit is contained in:
parent
377b6003a8
commit
f4816dc0cf
|
@ -254,23 +254,6 @@ impl CacheHashData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
/// load from 'file_name' into 'accumulator'
|
|
||||||
pub(crate) fn load(
|
|
||||||
&self,
|
|
||||||
file_name: impl AsRef<Path>,
|
|
||||||
accumulator: &mut SavedType,
|
|
||||||
start_bin_index: usize,
|
|
||||||
bin_calculator: &PubkeyBinCalculator24,
|
|
||||||
) -> Result<(), std::io::Error> {
|
|
||||||
let mut m = Measure::start("overall");
|
|
||||||
let cache_file = self.load_map(file_name)?;
|
|
||||||
cache_file.load_all(accumulator, start_bin_index, bin_calculator);
|
|
||||||
m.stop();
|
|
||||||
self.stats.load_us.fetch_add(m.as_us(), Ordering::Relaxed);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// open a cache hash file, but don't map it.
|
/// open a cache hash file, but don't map it.
|
||||||
/// This allows callers to know a file exists, but preserves the # mmapped files.
|
/// This allows callers to know a file exists, but preserves the # mmapped files.
|
||||||
pub(crate) fn get_file_reference_to_map_later(
|
pub(crate) fn get_file_reference_to_map_later(
|
||||||
|
@ -298,13 +281,6 @@ impl CacheHashData {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
/// map 'file_name' into memory
|
|
||||||
fn load_map(&self, file_name: impl AsRef<Path>) -> Result<CacheHashDataFile, std::io::Error> {
|
|
||||||
let reference = self.get_file_reference_to_map_later(file_name)?;
|
|
||||||
reference.map()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn pre_existing_cache_file_will_be_used(&self, file_name: impl AsRef<Path>) {
|
pub(crate) fn pre_existing_cache_file_will_be_used(&self, file_name: impl AsRef<Path>) {
|
||||||
self.pre_existing_cache_files
|
self.pre_existing_cache_files
|
||||||
.lock()
|
.lock()
|
||||||
|
@ -382,9 +358,36 @@ impl CacheHashData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
mod tests {
|
||||||
use {super::*, rand::Rng};
|
use {super::*, rand::Rng};
|
||||||
|
|
||||||
|
impl CacheHashData {
|
||||||
|
/// load from 'file_name' into 'accumulator'
|
||||||
|
fn load(
|
||||||
|
&self,
|
||||||
|
file_name: impl AsRef<Path>,
|
||||||
|
accumulator: &mut SavedType,
|
||||||
|
start_bin_index: usize,
|
||||||
|
bin_calculator: &PubkeyBinCalculator24,
|
||||||
|
) -> Result<(), std::io::Error> {
|
||||||
|
let mut m = Measure::start("overall");
|
||||||
|
let cache_file = self.load_map(file_name)?;
|
||||||
|
cache_file.load_all(accumulator, start_bin_index, bin_calculator);
|
||||||
|
m.stop();
|
||||||
|
self.stats.load_us.fetch_add(m.as_us(), Ordering::Relaxed);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// map 'file_name' into memory
|
||||||
|
fn load_map(
|
||||||
|
&self,
|
||||||
|
file_name: impl AsRef<Path>,
|
||||||
|
) -> Result<CacheHashDataFile, std::io::Error> {
|
||||||
|
let reference = self.get_file_reference_to_map_later(file_name)?;
|
||||||
|
reference.map()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_read_write() {
|
fn test_read_write() {
|
||||||
// generate sample data
|
// generate sample data
|
||||||
|
|
Loading…
Reference in New Issue