#[cfg(test)]
mod tests {
use crate::streams::*;
use std::time::Duration;
#[test]
fn test_stream_info_creation_and_fields() {
let stream_info = StreamInfo {
name: "TEST_STREAM".to_string(),
subjects: vec![
"smith.intents.raw.*".to_string(),
"smith.intents.vetted.*".to_string(),
],
messages: 12500,
bytes: 45 * 1024 * 1024, first_seq: 1,
last_seq: 12500,
consumer_count: 3,
exists: true,
};
assert_eq!(stream_info.name, "TEST_STREAM");
assert_eq!(stream_info.subjects.len(), 2);
assert_eq!(stream_info.subjects[0], "smith.intents.raw.*");
assert_eq!(stream_info.subjects[1], "smith.intents.vetted.*");
assert_eq!(stream_info.messages, 12500);
assert_eq!(stream_info.bytes, 45 * 1024 * 1024);
assert_eq!(stream_info.first_seq, 1);
assert_eq!(stream_info.last_seq, 12500);
assert_eq!(stream_info.consumer_count, 3);
assert!(stream_info.exists);
}
#[test]
fn test_stream_info_health_status_comprehensive() {
let healthy_stream = StreamInfo {
name: "HEALTHY_STREAM".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 5000, bytes: 40 * 1024 * 1024, first_seq: 1,
last_seq: 5000,
consumer_count: 2,
exists: true,
};
assert!(healthy_stream.is_healthy());
let too_many_messages = StreamInfo {
name: "TOO_MANY_MSG".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 8500, bytes: 30 * 1024 * 1024, first_seq: 1,
last_seq: 8500,
consumer_count: 1,
exists: true,
};
assert!(!too_many_messages.is_healthy());
let too_many_bytes = StreamInfo {
name: "TOO_MANY_BYTES".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 5000, bytes: 85 * 1024 * 1024, first_seq: 1,
last_seq: 5000,
consumer_count: 1,
exists: true,
};
assert!(!too_many_bytes.is_healthy());
let both_exceeded = StreamInfo {
name: "BOTH_EXCEEDED".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 9000, bytes: 90 * 1024 * 1024, first_seq: 1,
last_seq: 9000,
consumer_count: 1,
exists: true,
};
assert!(!both_exceeded.is_healthy());
let non_existent = StreamInfo {
name: "NON_EXISTENT".to_string(),
subjects: vec![],
messages: 0,
bytes: 0,
first_seq: 0,
last_seq: 0,
consumer_count: 0,
exists: false,
};
assert!(!non_existent.is_healthy());
}
#[test]
fn test_stream_info_health_edge_cases() {
let at_message_threshold = StreamInfo {
name: "AT_MSG_THRESHOLD".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 8000, bytes: 40 * 1024 * 1024,
first_seq: 1,
last_seq: 8000,
consumer_count: 1,
exists: true,
};
assert!(!at_message_threshold.is_healthy());
let at_byte_threshold = StreamInfo {
name: "AT_BYTE_THRESHOLD".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 5000,
bytes: 80 * 1024 * 1024, first_seq: 1,
last_seq: 5000,
consumer_count: 1,
exists: true,
};
assert!(!at_byte_threshold.is_healthy());
let zero_stream = StreamInfo {
name: "ZERO_STREAM".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 0,
bytes: 0,
first_seq: 0,
last_seq: 0,
consumer_count: 0,
exists: true,
};
assert!(zero_stream.is_healthy()); }
#[test]
fn test_stream_utilization_percentage_comprehensive() {
let msg_50_percent = StreamInfo {
name: "MSG_50_PCT".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 5000, bytes: 25 * 1024 * 1024, first_seq: 1,
last_seq: 5000,
consumer_count: 1,
exists: true,
};
let utilization = msg_50_percent.utilization_percent();
assert!((49.0..=51.0).contains(&utilization));
let bytes_75_percent = StreamInfo {
name: "BYTES_75_PCT".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 2500, bytes: 75 * 1024 * 1024, first_seq: 1,
last_seq: 2500,
consumer_count: 1,
exists: true,
};
let utilization = bytes_75_percent.utilization_percent();
assert!((74.0..=76.0).contains(&utilization));
let over_100_percent = StreamInfo {
name: "OVER_100_PCT".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 15000, bytes: 200 * 1024 * 1024, first_seq: 1,
last_seq: 15000,
consumer_count: 1,
exists: true,
};
let utilization = over_100_percent.utilization_percent();
assert_eq!(utilization, 100.0);
let non_existent = StreamInfo {
name: "NON_EXISTENT".to_string(),
subjects: vec![],
messages: 0,
bytes: 0,
first_seq: 0,
last_seq: 0,
consumer_count: 0,
exists: false,
};
assert_eq!(non_existent.utilization_percent(), 0.0);
}
#[test]
fn test_stream_utilization_edge_cases() {
let zero_utilization = StreamInfo {
name: "ZERO_UTIL".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 0,
bytes: 0,
first_seq: 0,
last_seq: 0,
consumer_count: 0,
exists: true,
};
assert_eq!(zero_utilization.utilization_percent(), 0.0);
let tiny_utilization = StreamInfo {
name: "TINY_UTIL".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 1,
bytes: 1024, first_seq: 1,
last_seq: 1,
consumer_count: 1,
exists: true,
};
let utilization = tiny_utilization.utilization_percent();
assert!((0.0..=0.1).contains(&utilization));
let extreme_values = StreamInfo {
name: "EXTREME_VALUES".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: u64::MAX,
bytes: u64::MAX,
first_seq: 1,
last_seq: u64::MAX,
consumer_count: usize::MAX,
exists: true,
};
let utilization = extreme_values.utilization_percent();
assert_eq!(utilization, 100.0); }
#[test]
fn test_stream_info_debug_trait() {
let stream_info = StreamInfo {
name: "DEBUG_TEST".to_string(),
subjects: vec!["smith.debug.*".to_string()],
messages: 1234,
bytes: 567890,
first_seq: 1,
last_seq: 1234,
consumer_count: 2,
exists: true,
};
let debug_string = format!("{:?}", stream_info);
assert!(debug_string.contains("DEBUG_TEST"));
assert!(debug_string.contains("smith.debug.*"));
assert!(debug_string.contains("1234"));
assert!(debug_string.contains("567890"));
assert!(debug_string.contains("true"));
}
#[test]
fn test_stream_info_clone_trait() {
let original = StreamInfo {
name: "CLONE_TEST".to_string(),
subjects: vec!["smith.clone.*".to_string()],
messages: 9999,
bytes: 888777,
first_seq: 100,
last_seq: 9999,
consumer_count: 5,
exists: true,
};
let cloned = original.clone();
assert_eq!(original.name, cloned.name);
assert_eq!(original.subjects, cloned.subjects);
assert_eq!(original.messages, cloned.messages);
assert_eq!(original.bytes, cloned.bytes);
assert_eq!(original.first_seq, cloned.first_seq);
assert_eq!(original.last_seq, cloned.last_seq);
assert_eq!(original.consumer_count, cloned.consumer_count);
assert_eq!(original.exists, cloned.exists);
}
#[test]
fn test_stream_info_empty_subjects() {
let empty_subjects = StreamInfo {
name: "EMPTY_SUBJECTS".to_string(),
subjects: vec![],
messages: 500,
bytes: 1024,
first_seq: 1,
last_seq: 500,
consumer_count: 0,
exists: true,
};
assert!(empty_subjects.subjects.is_empty());
assert_eq!(empty_subjects.consumer_count, 0);
assert!(empty_subjects.is_healthy()); }
#[test]
fn test_stream_info_multiple_subjects() {
let multi_subjects = StreamInfo {
name: "MULTI_SUBJECTS".to_string(),
subjects: vec![
"smith.intents.raw.*".to_string(),
"smith.intents.vetted.*".to_string(),
"smith.results.*".to_string(),
"smith.audit.*".to_string(),
"smith.system.*".to_string(),
],
messages: 2500,
bytes: 15 * 1024 * 1024, first_seq: 1,
last_seq: 2500,
consumer_count: 8,
exists: true,
};
assert_eq!(multi_subjects.subjects.len(), 5);
assert!(multi_subjects
.subjects
.contains(&"smith.intents.raw.*".to_string()));
assert!(multi_subjects
.subjects
.contains(&"smith.intents.vetted.*".to_string()));
assert!(multi_subjects
.subjects
.contains(&"smith.results.*".to_string()));
assert!(multi_subjects
.subjects
.contains(&"smith.audit.*".to_string()));
assert!(multi_subjects
.subjects
.contains(&"smith.system.*".to_string()));
assert_eq!(multi_subjects.consumer_count, 8);
assert!(multi_subjects.is_healthy());
}
#[test]
fn test_stream_info_sequence_numbers() {
let normal_seq = StreamInfo {
name: "NORMAL_SEQ".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 100,
bytes: 1024,
first_seq: 1,
last_seq: 100,
consumer_count: 1,
exists: true,
};
assert_eq!(normal_seq.first_seq, 1);
assert_eq!(normal_seq.last_seq, 100);
assert_eq!(
normal_seq.last_seq - normal_seq.first_seq + 1,
normal_seq.messages
);
let gap_seq = StreamInfo {
name: "GAP_SEQ".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 50,
bytes: 1024,
first_seq: 51, last_seq: 100,
consumer_count: 1,
exists: true,
};
assert_eq!(gap_seq.first_seq, 51);
assert_eq!(gap_seq.last_seq, 100);
assert_eq!(gap_seq.last_seq - gap_seq.first_seq + 1, gap_seq.messages);
let zero_seq = StreamInfo {
name: "ZERO_SEQ".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 0,
bytes: 0,
first_seq: 0,
last_seq: 0,
consumer_count: 0,
exists: true,
};
assert_eq!(zero_seq.first_seq, 0);
assert_eq!(zero_seq.last_seq, 0);
assert_eq!(zero_seq.messages, 0);
}
#[test]
fn test_stream_info_consumer_count_scenarios() {
let no_consumers = StreamInfo {
name: "NO_CONSUMERS".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 1000,
bytes: 1024 * 1024,
first_seq: 1,
last_seq: 1000,
consumer_count: 0,
exists: true,
};
assert_eq!(no_consumers.consumer_count, 0);
assert!(no_consumers.is_healthy());
let single_consumer = StreamInfo {
name: "SINGLE_CONSUMER".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 1000,
bytes: 1024 * 1024,
first_seq: 1,
last_seq: 1000,
consumer_count: 1,
exists: true,
};
assert_eq!(single_consumer.consumer_count, 1);
assert!(single_consumer.is_healthy());
let many_consumers = StreamInfo {
name: "MANY_CONSUMERS".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 1000,
bytes: 1024 * 1024,
first_seq: 1,
last_seq: 1000,
consumer_count: 20,
exists: true,
};
assert_eq!(many_consumers.consumer_count, 20);
assert!(many_consumers.is_healthy());
}
#[test]
fn test_stream_info_bytes_calculations() {
let kb_stream = StreamInfo {
name: "KB_STREAM".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 100,
bytes: 64 * 1024, first_seq: 1,
last_seq: 100,
consumer_count: 1,
exists: true,
};
assert_eq!(kb_stream.bytes, 64 * 1024);
assert!(kb_stream.is_healthy());
let mb_stream = StreamInfo {
name: "MB_STREAM".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 1000,
bytes: 32 * 1024 * 1024, first_seq: 1,
last_seq: 1000,
consumer_count: 1,
exists: true,
};
assert_eq!(mb_stream.bytes, 32 * 1024 * 1024);
assert!(mb_stream.is_healthy());
let gb_stream = StreamInfo {
name: "GB_STREAM".to_string(),
subjects: vec!["smith.test.*".to_string()],
messages: 10000,
bytes: 1024 * 1024 * 1024, first_seq: 1,
last_seq: 10000,
consumer_count: 1,
exists: true,
};
assert_eq!(gb_stream.bytes, 1024 * 1024 * 1024);
assert!(!gb_stream.is_healthy()); }
#[test]
fn test_stream_manager_creation() {
let stream_names = vec![
"SDLC_RAW",
"ATOMS_VETTED",
"ATOMS_RESULTS",
"AUDIT_SECURITY",
"SDLC_QUARANTINE_BACKPRESSURE",
"INTENT_RESULTS",
"AUDIT_LOGS",
"SYSTEM_EVENTS",
];
for name in stream_names {
assert!(!name.is_empty());
assert!(name.chars().all(|c| c.is_ascii_uppercase() || c == '_'));
assert!(!name.contains(' '));
}
}
#[test]
fn test_stream_config_comparison_logic() {
let subjects1 = vec!["smith.test1.*".to_string()];
let subjects2 = vec!["smith.test2.*".to_string()];
assert_ne!(subjects1, subjects2);
let same_subjects1 = vec!["smith.test.*".to_string()];
let same_subjects2 = vec!["smith.test.*".to_string()];
assert_eq!(same_subjects1, same_subjects2);
let duration1 = Duration::from_secs(60);
let duration2 = Duration::from_secs(120);
let duration3 = Duration::from_secs(60);
assert_ne!(duration1, duration2); assert_eq!(duration1, duration3);
let bytes1: u64 = 1024 * 1024; let bytes2: u64 = 2 * 1024 * 1024; let bytes3: u64 = 1024 * 1024;
assert_ne!(bytes1, bytes2); assert_eq!(bytes1, bytes3);
let messages1: i64 = 1000;
let messages2: i64 = 2000;
let messages3: i64 = 1000;
assert_ne!(messages1, messages2); assert_eq!(messages1, messages3); }
#[test]
fn test_stream_bootstrap_workflow_structure() {
let expected_bootstrap_order = vec![
"SDLC_RAW",
"ATOMS_VETTED",
"ATOMS_RESULTS",
"AUDIT_SECURITY",
"SDLC_QUARANTINE_BACKPRESSURE",
];
for stream_name in expected_bootstrap_order {
assert!(!stream_name.is_empty());
assert!(!stream_name.contains(' '));
assert!(stream_name
.chars()
.all(|c| c.is_ascii_uppercase() || c == '_'));
}
let legacy_streams = vec!["INTENT_RESULTS", "AUDIT_LOGS", "SYSTEM_EVENTS"];
for stream_name in legacy_streams {
assert!(!stream_name.is_empty());
assert!(!stream_name.contains(' '));
assert!(stream_name
.chars()
.all(|c| c.is_ascii_uppercase() || c == '_'));
}
}
#[test]
fn test_stream_info_get_streams_logic() {
let expected_streams = vec!["INTENTS", "INTENT_RESULTS", "AUDIT_LOGS", "SYSTEM_EVENTS"];
let mut stream_infos = Vec::new();
for stream_name in expected_streams {
stream_infos.push(StreamInfo {
name: stream_name.to_string(),
subjects: vec![],
messages: 0,
bytes: 0,
first_seq: 0,
last_seq: 0,
consumer_count: 0,
exists: false, });
}
assert_eq!(stream_infos.len(), 4);
for stream_info in stream_infos {
assert!(!stream_info.name.is_empty());
assert_eq!(stream_info.messages, 0);
assert_eq!(stream_info.bytes, 0);
assert!(!stream_info.exists);
assert!(!stream_info.is_healthy()); }
}
#[test]
fn test_stream_deletion_workflow() {
let stream_names_to_delete = vec!["TEST_STREAM_1", "TEST_STREAM_2", "TEMPORARY_STREAM"];
for stream_name in stream_names_to_delete {
assert!(!stream_name.is_empty());
assert!(!stream_name.contains(' '));
assert!(stream_name.len() <= 64);
assert!(stream_name.chars().all(|c| c.is_alphanumeric() || c == '_'));
}
}
#[test]
fn test_stream_configuration_constants() {
let sdlc_raw_max_age = Duration::from_secs(6 * 60 * 60); let sdlc_raw_max_bytes = 500 * 1024 * 1024; let sdlc_raw_max_messages = 50_000;
let sdlc_raw_max_message_size = 2 * 1024 * 1024; let sdlc_raw_duplicate_window = Duration::from_secs(60);
assert_eq!(sdlc_raw_max_age, Duration::from_secs(21600));
assert_eq!(sdlc_raw_max_bytes, 524288000);
assert_eq!(sdlc_raw_max_messages, 50000);
assert_eq!(sdlc_raw_max_message_size, 2097152);
assert_eq!(sdlc_raw_duplicate_window, Duration::from_secs(60));
let atoms_vetted_max_age = Duration::from_secs(12 * 60 * 60); let atoms_vetted_max_bytes = 1024 * 1024 * 1024; let atoms_vetted_max_messages = 100_000;
let atoms_vetted_duplicate_window = Duration::from_secs(2 * 60);
assert_eq!(atoms_vetted_max_age, Duration::from_secs(43200));
assert_eq!(atoms_vetted_max_bytes, 1073741824);
assert_eq!(atoms_vetted_max_messages, 100000);
assert_eq!(atoms_vetted_duplicate_window, Duration::from_secs(120));
let atoms_results_max_age = Duration::from_secs(48 * 60 * 60); let atoms_results_max_bytes = 2048u64 * 1024 * 1024; let atoms_results_max_messages = 200_000;
let atoms_results_max_message_size = 4 * 1024 * 1024; let atoms_results_duplicate_window = Duration::from_secs(5 * 60);
assert_eq!(atoms_results_max_age, Duration::from_secs(172800));
assert_eq!(atoms_results_max_bytes, 2147483648);
assert_eq!(atoms_results_max_messages, 200000);
assert_eq!(atoms_results_max_message_size, 4194304);
assert_eq!(atoms_results_duplicate_window, Duration::from_secs(300));
}
#[test]
fn test_audit_stream_configuration() {
let audit_max_age = Duration::from_secs(365 * 24 * 60 * 60); let audit_max_bytes = 10u64 * 1024 * 1024 * 1024; let audit_max_messages = 1_000_000;
let audit_max_message_size = 1024 * 1024; let audit_duplicate_window = Duration::from_secs(60);
assert_eq!(audit_max_age, Duration::from_secs(31536000)); assert_eq!(audit_max_bytes, 10737418240); assert_eq!(audit_max_messages, 1000000);
assert_eq!(audit_max_message_size, 1048576); assert_eq!(audit_duplicate_window, Duration::from_secs(60));
}
#[test]
fn test_backpressure_stream_configuration() {
let backpressure_max_age = Duration::from_secs(2 * 60 * 60); let backpressure_max_bytes = 100 * 1024 * 1024; let backpressure_max_messages = 10_000;
let backpressure_max_message_size = 1024 * 1024; let backpressure_duplicate_window = Duration::from_secs(30);
assert_eq!(backpressure_max_age, Duration::from_secs(7200)); assert_eq!(backpressure_max_bytes, 104857600); assert_eq!(backpressure_max_messages, 10000);
assert_eq!(backpressure_max_message_size, 1048576); assert_eq!(backpressure_duplicate_window, Duration::from_secs(30));
}
#[test]
fn test_system_events_stream_configuration() {
let system_max_age = Duration::from_secs(12 * 60 * 60); let system_max_bytes = 50 * 1024 * 1024; let system_max_messages = 10_000;
let system_max_message_size = 64 * 1024; let system_duplicate_window = Duration::from_secs(30);
assert_eq!(system_max_age, Duration::from_secs(43200)); assert_eq!(system_max_bytes, 52428800); assert_eq!(system_max_messages, 10000);
assert_eq!(system_max_message_size, 65536); assert_eq!(system_duplicate_window, Duration::from_secs(30));
}
#[test]
fn test_subject_patterns() {
let raw_subjects = vec!["smith.intents.raw.*"];
let vetted_subjects = vec!["smith.intents.vetted.*"];
let results_subjects = vec!["smith.results.*"];
let audit_subjects = vec!["smith.audit.*"];
let quarantine_subjects = vec!["smith.intents.quarantine.*"];
let system_subjects = vec!["smith.system.*"];
for subject in raw_subjects {
assert!(subject.starts_with("smith."));
assert!(subject.ends_with(".*"));
assert!(subject.contains("intents.raw"));
}
for subject in vetted_subjects {
assert!(subject.starts_with("smith."));
assert!(subject.ends_with(".*"));
assert!(subject.contains("intents.vetted"));
}
for subject in results_subjects {
assert!(subject.starts_with("smith."));
assert!(subject.ends_with(".*"));
assert!(subject.contains("results"));
}
for subject in audit_subjects {
assert!(subject.starts_with("smith."));
assert!(subject.ends_with(".*"));
assert!(subject.contains("audit"));
}
for subject in quarantine_subjects {
assert!(subject.starts_with("smith."));
assert!(subject.ends_with(".*"));
assert!(subject.contains("quarantine"));
}
for subject in system_subjects {
assert!(subject.starts_with("smith."));
assert!(subject.ends_with(".*"));
assert!(subject.contains("system"));
}
}
#[test]
fn test_retention_policy_configurations() {
let work_queue_streams = vec!["SDLC_RAW", "SDLC_QUARANTINE_BACKPRESSURE"];
for stream in work_queue_streams {
assert!(stream.contains("SDLC") || stream.contains("QUARANTINE"));
}
let interest_streams = vec!["ATOMS_VETTED", "AUDIT_SECURITY"];
for stream in interest_streams {
assert!(stream.contains("ATOMS") || stream.contains("AUDIT"));
}
let limits_streams = vec![
"ATOMS_RESULTS",
"INTENT_RESULTS",
"AUDIT_LOGS",
"SYSTEM_EVENTS",
];
for stream in limits_streams {
assert!(
stream.contains("RESULTS") || stream.contains("AUDIT") || stream.contains("SYSTEM")
);
}
}
#[test]
fn test_message_size_configurations() {
let small_message_size = 64 * 1024;
assert_eq!(small_message_size, 65536);
let medium_message_size = 512 * 1024;
assert_eq!(medium_message_size, 524288);
let standard_message_size = 1024 * 1024;
assert_eq!(standard_message_size, 1048576);
let large_message_size = 2 * 1024 * 1024;
assert_eq!(large_message_size, 2097152);
let xl_message_size = 4 * 1024 * 1024;
assert_eq!(xl_message_size, 4194304);
assert!(small_message_size < medium_message_size);
assert!(medium_message_size < standard_message_size);
assert!(standard_message_size < large_message_size);
assert!(large_message_size < xl_message_size);
}
#[test]
fn test_duplicate_window_configurations() {
let short_dedup_window = Duration::from_secs(30);
assert_eq!(short_dedup_window.as_secs(), 30);
let standard_dedup_window = Duration::from_secs(60);
assert_eq!(standard_dedup_window.as_secs(), 60);
let medium_dedup_window = Duration::from_secs(2 * 60);
assert_eq!(medium_dedup_window.as_secs(), 120);
let long_dedup_window = Duration::from_secs(5 * 60);
assert_eq!(long_dedup_window.as_secs(), 300);
assert!(short_dedup_window < standard_dedup_window);
assert!(standard_dedup_window < medium_dedup_window);
assert!(medium_dedup_window < long_dedup_window);
}
#[test]
fn test_stream_capacity_relationships() {
let small_capacity = 10_000u64; let medium_capacity = 50_000u64; let large_capacity = 100_000u64; let xl_capacity = 200_000u64; let audit_capacity = 1_000_000u64;
assert!(small_capacity < medium_capacity);
assert!(medium_capacity < large_capacity);
assert!(large_capacity < xl_capacity);
assert!(xl_capacity < audit_capacity);
let small_bytes = 50u64 * 1024 * 1024; let medium_bytes = 100u64 * 1024 * 1024; let standard_bytes = 500u64 * 1024 * 1024; let large_bytes = 1024u64 * 1024 * 1024; let xl_bytes = 2048u64 * 1024 * 1024; let audit_bytes = 10u64 * 1024 * 1024 * 1024;
assert!(small_bytes < medium_bytes);
assert!(medium_bytes < standard_bytes);
assert!(standard_bytes < large_bytes);
assert!(large_bytes < xl_bytes);
assert!(xl_bytes < audit_bytes);
}
#[test]
fn test_stream_age_retention_periods() {
let backpressure_retention = Duration::from_secs(2 * 60 * 60);
assert_eq!(backpressure_retention.as_secs(), 7200);
let raw_retention = Duration::from_secs(6 * 60 * 60);
assert_eq!(raw_retention.as_secs(), 21600);
let standard_retention = Duration::from_secs(12 * 60 * 60);
assert_eq!(standard_retention.as_secs(), 43200);
let audit_retention = Duration::from_secs(30 * 24 * 60 * 60);
assert_eq!(audit_retention.as_secs(), 2592000);
let results_retention = Duration::from_secs(48 * 60 * 60);
assert_eq!(results_retention.as_secs(), 172800);
let security_retention = Duration::from_secs(365 * 24 * 60 * 60);
assert_eq!(security_retention.as_secs(), 31536000);
assert!(backpressure_retention < raw_retention);
assert!(raw_retention < standard_retention);
assert!(results_retention > standard_retention);
assert!(audit_retention > results_retention);
assert!(security_retention > audit_retention);
}
#[test]
fn test_stream_description_formats() {
let descriptions = vec![
"Phase 2: Raw intent ingestion with high-throughput optimization",
"Phase 2: Policy-approved intents with ordering guarantees",
"Phase 2: Execution results with performance tracking",
"Phase 2: Security and compliance audit events",
"Phase 2: Backpressure and quarantine handling",
"Results from intent execution",
"Audit logs for compliance and debugging",
"System-level events and health monitoring",
];
for description in descriptions {
assert!(!description.is_empty());
assert!(description.len() > 10); assert!(description.len() < 200);
assert!(description.chars().next().unwrap().is_uppercase());
assert!(!description.ends_with('.'));
}
}
#[test]
fn test_storage_and_replica_configuration() {
let expected_replicas = 1;
assert_eq!(expected_replicas, 1);
let storage_types = ["File", "Memory"];
let expected_storage = "File";
assert!(storage_types.contains(&expected_storage));
assert_ne!(expected_storage, "Memory"); }
#[test]
fn test_discard_policy_configuration() {
let discard_policies = ["Old", "New"];
let expected_policy = "Old";
assert!(discard_policies.contains(&expected_policy));
assert_eq!(expected_policy, "Old"); }
#[test]
fn test_phase_2_architecture_concepts() {
let processing_flow = vec!["SDLC_RAW", "ATOMS_VETTED", "ATOMS_RESULTS"];
assert_eq!(processing_flow[0], "SDLC_RAW"); assert_eq!(processing_flow[1], "ATOMS_VETTED"); assert_eq!(processing_flow[2], "ATOMS_RESULTS");
let audit_streams = vec!["AUDIT_SECURITY"];
assert_eq!(audit_streams.len(), 1);
let backpressure_streams = vec!["SDLC_QUARANTINE_BACKPRESSURE"];
assert_eq!(backpressure_streams.len(), 1);
let all_phase2_streams = [processing_flow, audit_streams, backpressure_streams].concat();
assert_eq!(all_phase2_streams.len(), 5);
}
}