Skip to content

Commit c47e6c6

Browse files
Merge pull request #9 from SolidLabResearch/codex/main-cleanup
Add real integration smoke test for main
2 parents 9e7af44 + 3d3ef8b commit c47e6c6

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ path = "src/bin/http_server.rs"
4141

4242
[dev-dependencies]
4343
criterion = { version = "0.5", features = ["html_reports"] }
44+
tempfile = "3.8"
4445

4546
[[bench]]
4647
name = "storage_write"

tests/integration_test.rs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,86 @@
33
//! These tests verify the overall functionality of the Janus engine
44
//! by testing the integration of multiple components together.
55
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;
611
use janus::{Error, Result};
12+
use std::sync::Arc;
13+
use std::time::Duration;
14+
use tempfile::TempDir;
715

816
#[test]
917
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");
1286
}
1387

1488
#[test]

0 commit comments

Comments
 (0)