2021-12-16 13:17:27 +00:00
|
|
|
use ps_core::{
|
2021-11-18 12:10:54 +00:00
|
|
|
self,
|
2021-12-16 13:17:27 +00:00
|
|
|
model::{self, Engine, Rect},
|
|
|
|
Config, DatabaseLike, Field, Filter, FormatType, Importerlike, ValueField,
|
2021-11-18 12:10:54 +00:00
|
|
|
};
|
2021-12-16 13:17:27 +00:00
|
|
|
use ps_database::Database;
|
|
|
|
use ps_importer::mbox_importer;
|
2021-11-18 12:10:54 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2021-12-12 09:18:45 +00:00
|
|
|
use std::sync::Once;
|
|
|
|
|
|
|
|
static INIT: Once = Once::new();
|
|
|
|
|
|
|
|
pub fn initialize() {
|
|
|
|
INIT.call_once(|| {
|
|
|
|
if std::env::var("RUST_LOG").is_err() {
|
|
|
|
std::env::set_var("RUST_LOG", "trace");
|
|
|
|
}
|
2021-12-16 13:17:27 +00:00
|
|
|
ps_core::setup_tracing();
|
2021-12-12 09:18:45 +00:00
|
|
|
});
|
|
|
|
}
|
2021-11-18 12:10:54 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_engine_all() {
|
2021-12-12 09:18:45 +00:00
|
|
|
initialize();
|
2021-11-18 12:10:54 +00:00
|
|
|
let config = create_database();
|
2021-12-16 13:17:27 +00:00
|
|
|
let mut engine = Engine::new::<Database>(&config).expect("Expected Engine");
|
2021-11-18 12:10:54 +00:00
|
|
|
engine.start().expect("Expect to start engine");
|
|
|
|
engine.wait().expect("Expected working wait");
|
|
|
|
let segment = {
|
|
|
|
let segments =
|
|
|
|
model::segmentations::layouted_segments(&mut engine, default_rect()).unwrap();
|
|
|
|
assert_eq!(segments.len(), 5);
|
|
|
|
segments[0].clone()
|
|
|
|
};
|
|
|
|
|
|
|
|
// add another aggregation level
|
|
|
|
engine
|
|
|
|
.push(segment)
|
|
|
|
.expect("Expect being able to push another segment");
|
|
|
|
engine.wait().expect("Expected working wait");
|
|
|
|
|
|
|
|
// Validate
|
|
|
|
let segments =
|
|
|
|
model::segmentations::layouted_segments(&mut engine, default_rect()).unwrap();
|
|
|
|
assert_eq!(segments.len(), 2);
|
|
|
|
|
2021-12-08 07:32:24 +00:00
|
|
|
// Limit to only one segment
|
2021-11-18 12:10:54 +00:00
|
|
|
model::segmentations::set_segments_range(&mut engine, Some(0..=1));
|
|
|
|
// Validate
|
|
|
|
let segments =
|
|
|
|
model::segmentations::layouted_segments(&mut engine, default_rect()).unwrap();
|
|
|
|
assert_eq!(segments.len(), 1);
|
|
|
|
|
|
|
|
// Add a filter
|
|
|
|
let filter = Filter::Is(ValueField::bool(&Field::IsSend, true));
|
2021-12-11 09:14:45 +00:00
|
|
|
model::segmentations::set_filters(&mut engine, &[filter]).expect("Expect setting filters");
|
2021-11-18 12:10:54 +00:00
|
|
|
engine.wait().expect("");
|
|
|
|
|
|
|
|
let segments =
|
|
|
|
model::segmentations::layouted_segments(&mut engine, default_rect()).unwrap();
|
|
|
|
assert_eq!(segments.len(), 0);
|
2021-12-10 20:11:30 +00:00
|
|
|
|
|
|
|
// Remove filter
|
|
|
|
model::segmentations::set_filters(&mut engine, &[]).expect("");
|
|
|
|
engine.wait().expect("");
|
|
|
|
|
|
|
|
let segments =
|
|
|
|
model::segmentations::layouted_segments(&mut engine, default_rect()).unwrap();
|
|
|
|
assert_eq!(segments.len(), 2);
|
|
|
|
|
|
|
|
// Push a new segment
|
|
|
|
let segment = segments[0].clone();
|
|
|
|
engine.push(segment).unwrap();
|
|
|
|
engine.wait().expect("");
|
|
|
|
|
|
|
|
// Check the new segments
|
|
|
|
let segments =
|
|
|
|
model::segmentations::layouted_segments(&mut engine, default_rect()).unwrap();
|
|
|
|
assert_eq!(segments.len(), 1);
|
2021-11-18 12:10:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 13:17:27 +00:00
|
|
|
fn default_rect() -> Rect {
|
|
|
|
Rect {
|
|
|
|
left: 50.0,
|
|
|
|
top: 50.0,
|
|
|
|
width: 500.0,
|
|
|
|
height: 500.0,
|
|
|
|
}
|
2021-11-18 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create_database() -> Config {
|
|
|
|
let path = "tests/resources/mbox";
|
2021-12-16 13:17:27 +00:00
|
|
|
let config = Config::new(None, path, vec!["".to_string()], FormatType::Mbox).expect("Config");
|
|
|
|
let importer = mbox_importer(config.clone());
|
|
|
|
let database = Database::new(&config.database_path).unwrap();
|
|
|
|
let (_receiver, handle) = importer.import(database).unwrap();
|
2021-11-18 12:10:54 +00:00
|
|
|
handle.join().expect("").expect("");
|
|
|
|
config
|
|
|
|
}
|