|
3 | 3 | //! These tests verify the overall functionality of the Janus engine |
4 | 4 | //! by testing the integration of multiple components together. |
5 | 5 |
|
| 6 | +use janus::api::janus_api::{JanusApi, ResultSource}; |
| 7 | +use janus::parsing::janusql_parser::JanusQLParser; |
| 8 | +use janus::registry::query_registry::QueryRegistry; |
| 9 | +use janus::storage::segmented_storage::StreamingSegmentedStorage; |
| 10 | +use janus::storage::util::StreamingConfig; |
6 | 11 | use janus::{Error, Result}; |
| 12 | +use std::sync::Arc; |
| 13 | +use std::time::Duration; |
| 14 | +use tempfile::TempDir; |
7 | 15 |
|
8 | 16 | #[test] |
9 | 17 | fn test_basic_functionality() { |
10 | | - // TODO: Add integration tests |
11 | | - // assert!(true); // Removed as it's always true |
| 18 | + let temp_dir = TempDir::new().expect("failed to create temporary directory"); |
| 19 | + let mut storage = StreamingSegmentedStorage::new(StreamingConfig { |
| 20 | + segment_base_path: temp_dir.path().to_string_lossy().into_owned(), |
| 21 | + max_batch_events: 10, |
| 22 | + max_batch_age_seconds: 60, |
| 23 | + max_batch_bytes: 1024 * 1024, |
| 24 | + sparse_interval: 10, |
| 25 | + entries_per_index_block: 100, |
| 26 | + }) |
| 27 | + .expect("failed to create storage"); |
| 28 | + storage.start_background_flushing(); |
| 29 | + |
| 30 | + storage |
| 31 | + .write_rdf( |
| 32 | + 1_000, |
| 33 | + "http://example.org/sensor1", |
| 34 | + "http://example.org/temperature", |
| 35 | + "21", |
| 36 | + "http://example.org/sensors", |
| 37 | + ) |
| 38 | + .expect("failed to write first event"); |
| 39 | + storage |
| 40 | + .write_rdf( |
| 41 | + 1_500, |
| 42 | + "http://example.org/sensor2", |
| 43 | + "http://example.org/temperature", |
| 44 | + "22", |
| 45 | + "http://example.org/sensors", |
| 46 | + ) |
| 47 | + .expect("failed to write second event"); |
| 48 | + storage.flush().expect("failed to flush storage"); |
| 49 | + |
| 50 | + let api = JanusApi::new( |
| 51 | + JanusQLParser::new().expect("failed to create parser"), |
| 52 | + Arc::new(QueryRegistry::new()), |
| 53 | + Arc::new(storage), |
| 54 | + ) |
| 55 | + .expect("failed to create JanusApi"); |
| 56 | + |
| 57 | + let janusql = r#" |
| 58 | + PREFIX ex: <http://example.org/> |
| 59 | +
|
| 60 | + SELECT ?sensor ?temp |
| 61 | +
|
| 62 | + FROM NAMED WINDOW ex:hist ON STREAM ex:sensors [START 1000 END 2000] |
| 63 | +
|
| 64 | + WHERE { |
| 65 | + WINDOW ex:hist { ?sensor ex:temperature ?temp } |
| 66 | + } |
| 67 | + "#; |
| 68 | + |
| 69 | + api.register_query("smoke_test".into(), janusql) |
| 70 | + .expect("failed to register query"); |
| 71 | + let handle = api.start_query(&"smoke_test".into()).expect("failed to start query"); |
| 72 | + |
| 73 | + let mut result = None; |
| 74 | + for _ in 0..20 { |
| 75 | + if let Some(next_result) = handle.try_receive() { |
| 76 | + result = Some(next_result); |
| 77 | + break; |
| 78 | + } |
| 79 | + std::thread::sleep(Duration::from_millis(25)); |
| 80 | + } |
| 81 | + |
| 82 | + let result = result.expect("expected a historical query result"); |
| 83 | + assert_eq!(result.query_id, "smoke_test"); |
| 84 | + assert!(matches!(result.source, ResultSource::Historical)); |
| 85 | + assert!(!result.bindings.is_empty(), "expected at least one binding"); |
12 | 86 | } |
13 | 87 |
|
14 | 88 | #[test] |
|
0 commit comments