oxirs-stream 0.2.4

Real-time streaming support with Kafka/NATS/MQTT/OPC-UA I/O, RDF Patch, and SPARQL Update delta
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
//! # Enhanced GraphQL Subscription System
//!
//! Advanced GraphQL subscription features for real-time RDF stream updates:
//! - Window-based subscriptions
//! - Advanced filtering and pattern matching
//! - Subscription lifecycle management
//! - Subscription groups and namespaces
//! - Connection pooling and resilience

use anyhow::{anyhow, Result};
use chrono::{DateTime, Duration as ChronoDuration, Utc};
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet, VecDeque};
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::{broadcast, RwLock};
use tokio::time::interval;
use tracing::{debug, info};

use crate::StreamEvent;

/// Enhanced GraphQL subscription manager
pub struct GraphQLSubscriptionManager {
    /// Active subscriptions
    subscriptions: Arc<RwLock<HashMap<String, EnhancedSubscription>>>,
    /// Subscription groups
    groups: Arc<RwLock<HashMap<String, SubscriptionGroup>>>,
    /// Window buffers
    windows: Arc<RwLock<HashMap<String, SubscriptionWindow>>>,
    /// Event broadcaster
    event_tx: broadcast::Sender<SubscriptionEvent>,
    /// Configuration
    config: SubscriptionConfig,
    /// Statistics
    stats: Arc<RwLock<SubscriptionStats>>,
}

/// Subscription configuration
#[derive(Debug, Clone)]
pub struct SubscriptionConfig {
    /// Maximum concurrent subscriptions
    pub max_subscriptions: usize,
    /// Maximum subscriptions per client
    pub max_subscriptions_per_client: usize,
    /// Default window size
    pub default_window_size: Duration,
    /// Enable windowing
    pub enable_windowing: bool,
    /// Enable advanced filtering
    pub enable_advanced_filtering: bool,
    /// Heartbeat interval
    pub heartbeat_interval: Duration,
    /// Subscription timeout
    pub subscription_timeout: Duration,
}

impl Default for SubscriptionConfig {
    fn default() -> Self {
        Self {
            max_subscriptions: 10000,
            max_subscriptions_per_client: 100,
            default_window_size: Duration::from_secs(60),
            enable_windowing: true,
            enable_advanced_filtering: true,
            heartbeat_interval: Duration::from_secs(30),
            subscription_timeout: Duration::from_secs(300),
        }
    }
}

/// Enhanced subscription with lifecycle management
#[derive(Debug, Clone)]
pub struct EnhancedSubscription {
    /// Subscription identifier
    pub id: String,
    /// Client identifier
    pub client_id: String,
    /// GraphQL query
    pub query: String,
    /// Variables
    pub variables: HashMap<String, serde_json::Value>,
    /// Advanced filters
    pub filters: Vec<AdvancedFilter>,
    /// Window specification
    pub window: Option<WindowSpec>,
    /// Lifecycle state
    pub state: SubscriptionState,
    /// Metadata
    pub metadata: SubscriptionMetadata,
    /// Statistics
    pub stats: SubscriptionStatistics,
}

/// Subscription lifecycle state
#[derive(Debug, Clone, PartialEq)]
pub enum SubscriptionState {
    /// Subscription is active
    Active,
    /// Subscription is paused (buffering updates)
    Paused,
    /// Subscription is in reconnection mode
    Reconnecting {
        attempts: u32,
        next_retry: DateTime<Utc>,
    },
    /// Subscription is throttled
    Throttled { until: DateTime<Utc> },
    /// Subscription is terminated
    Terminated {
        reason: String,
        timestamp: DateTime<Utc>,
    },
}

/// Advanced filtering options
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AdvancedFilter {
    /// Time-based filter
    TimeRange {
        start: Option<DateTime<Utc>>,
        end: Option<DateTime<Utc>>,
    },
    /// Value-based filter
    ValueFilter {
        field: String,
        operator: FilterOperator,
        value: serde_json::Value,
    },
    /// Pattern matching filter
    PatternMatch {
        field: String,
        pattern: String,
        case_sensitive: bool,
    },
    /// Geospatial filter
    GeoFilter {
        latitude: f64,
        longitude: f64,
        radius_km: f64,
    },
    /// Semantic filter (RDF-specific)
    SemanticFilter {
        subject_pattern: Option<String>,
        predicate_pattern: Option<String>,
        object_pattern: Option<String>,
    },
    /// Aggregation filter
    AggregationFilter {
        function: AggregationFunction,
        threshold: f64,
    },
    /// Composite filter
    CompositeFilter {
        operator: LogicalOperator,
        filters: Vec<Box<AdvancedFilter>>,
    },
}

/// Filter operators
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum FilterOperator {
    Equal,
    NotEqual,
    LessThan,
    LessThanOrEqual,
    GreaterThan,
    GreaterThanOrEqual,
    Contains,
    StartsWith,
    EndsWith,
    In,
    NotIn,
}

/// Aggregation functions for filtering
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum AggregationFunction {
    Count,
    Sum,
    Average,
    Min,
    Max,
    StdDev,
}

/// Logical operators for composite filters
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum LogicalOperator {
    And,
    Or,
    Not,
    Xor,
}

/// Window specification for subscriptions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WindowSpec {
    /// Window type
    pub window_type: WindowType,
    /// Size (time or count)
    pub size: WindowSize,
    /// Slide interval (for sliding windows)
    pub slide: Option<WindowSize>,
    /// Trigger conditions
    pub triggers: Vec<WindowTrigger>,
}

/// Window types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum WindowType {
    Tumbling,
    Sliding,
    Session,
    Global,
}

/// Window size specification
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum WindowSize {
    Time(Duration),
    Count(usize),
    Bytes(usize),
}

/// Window trigger conditions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum WindowTrigger {
    /// Trigger on time interval
    TimeInterval(Duration),
    /// Trigger on event count
    EventCount(usize),
    /// Trigger on watermark
    Watermark,
    /// Trigger on specific event type
    EventType(String),
    /// Custom trigger condition
    Custom(String),
}

/// Subscription metadata
#[derive(Debug, Clone)]
pub struct SubscriptionMetadata {
    /// Creation timestamp
    pub created_at: DateTime<Utc>,
    /// Last activity timestamp
    pub last_activity: DateTime<Utc>,
    /// Tags for organization
    pub tags: Vec<String>,
    /// Priority level
    pub priority: SubscriptionPriority,
    /// Namespace
    pub namespace: Option<String>,
    /// Group membership
    pub groups: Vec<String>,
}

/// Subscription priority
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum SubscriptionPriority {
    Low = 1,
    Normal = 2,
    High = 3,
    Critical = 4,
}

/// Subscription statistics
#[derive(Debug, Clone, Default)]
pub struct SubscriptionStatistics {
    /// Total events received
    pub events_received: u64,
    /// Total updates sent
    pub updates_sent: u64,
    /// Total bytes sent
    pub bytes_sent: u64,
    /// Average latency (ms)
    pub avg_latency_ms: f64,
    /// Max latency (ms)
    pub max_latency_ms: f64,
    /// Error count
    pub error_count: u64,
    /// Last error
    pub last_error: Option<String>,
}

/// Subscription group for managing related subscriptions
#[derive(Debug, Clone)]
pub struct SubscriptionGroup {
    /// Group identifier
    pub id: String,
    /// Group name
    pub name: String,
    /// Member subscription IDs
    pub members: HashSet<String>,
    /// Group-level filters
    pub filters: Vec<AdvancedFilter>,
    /// Group configuration
    pub config: GroupConfig,
}

/// Group configuration
#[derive(Debug, Clone)]
pub struct GroupConfig {
    /// Enable shared windowing
    pub shared_windowing: bool,
    /// Enable load balancing
    pub load_balancing: bool,
    /// Maximum members
    pub max_members: usize,
}

/// Subscription window buffer
pub struct SubscriptionWindow {
    /// Window identifier
    pub id: String,
    /// Associated subscription ID
    pub subscription_id: String,
    /// Window specification
    pub spec: WindowSpec,
    /// Event buffer
    pub buffer: VecDeque<WindowedEvent>,
    /// Window state
    pub state: WindowState,
}

/// Windowed event
#[derive(Debug, Clone)]
pub struct WindowedEvent {
    pub event: StreamEvent,
    pub timestamp: DateTime<Utc>,
    pub sequence_id: u64,
}

/// Window state
#[derive(Debug, Clone)]
pub struct WindowState {
    /// Window start time
    pub start_time: DateTime<Utc>,
    /// Window end time
    pub end_time: Option<DateTime<Utc>>,
    /// Event count
    pub event_count: usize,
    /// Total bytes
    pub total_bytes: usize,
    /// Is window closed
    pub is_closed: bool,
}

/// Subscription event
#[derive(Debug, Clone)]
pub enum SubscriptionEvent {
    /// New update available
    Update {
        subscription_id: String,
        data: serde_json::Value,
        timestamp: DateTime<Utc>,
    },
    /// Subscription state changed
    StateChanged {
        subscription_id: String,
        old_state: SubscriptionState,
        new_state: SubscriptionState,
    },
    /// Heartbeat
    Heartbeat {
        subscription_id: String,
        timestamp: DateTime<Utc>,
    },
    /// Error occurred
    Error {
        subscription_id: String,
        error: String,
        timestamp: DateTime<Utc>,
    },
}

/// Overall statistics
#[derive(Debug, Clone, Default)]
pub struct SubscriptionStats {
    pub total_subscriptions: usize,
    pub active_subscriptions: usize,
    pub paused_subscriptions: usize,
    pub reconnecting_subscriptions: usize,
    pub total_events_processed: u64,
    pub total_updates_sent: u64,
    pub avg_processing_time_ms: f64,
}

impl GraphQLSubscriptionManager {
    /// Create a new subscription manager
    pub fn new(config: SubscriptionConfig) -> Self {
        let (event_tx, _) = broadcast::channel(10000);

        let manager = Self {
            subscriptions: Arc::new(RwLock::new(HashMap::new())),
            groups: Arc::new(RwLock::new(HashMap::new())),
            windows: Arc::new(RwLock::new(HashMap::new())),
            event_tx,
            config,
            stats: Arc::new(RwLock::new(SubscriptionStats::default())),
        };

        // Start background tasks
        manager.start_heartbeat_task();
        manager.start_cleanup_task();

        manager
    }

    /// Register a new subscription
    pub async fn register_subscription(
        &self,
        subscription: EnhancedSubscription,
    ) -> Result<String> {
        let mut subscriptions = self.subscriptions.write().await;

        // Check limits
        if subscriptions.len() >= self.config.max_subscriptions {
            return Err(anyhow!("Maximum subscriptions limit reached"));
        }

        // Check per-client limit
        let client_count = subscriptions
            .values()
            .filter(|s| s.client_id == subscription.client_id)
            .count();

        if client_count >= self.config.max_subscriptions_per_client {
            return Err(anyhow!("Client subscription limit reached"));
        }

        let id = subscription.id.clone();

        // Create window if needed
        if self.config.enable_windowing {
            if let Some(window_spec) = &subscription.window {
                self.create_window(&id, window_spec.clone()).await?;
            }
        }

        subscriptions.insert(id.clone(), subscription);

        // Update stats
        let mut stats = self.stats.write().await;
        stats.total_subscriptions = subscriptions.len();
        stats.active_subscriptions = subscriptions
            .values()
            .filter(|s| s.state == SubscriptionState::Active)
            .count();

        info!("Registered GraphQL subscription: {}", id);
        Ok(id)
    }

    /// Unregister a subscription
    pub async fn unregister_subscription(&self, subscription_id: &str) -> Result<()> {
        let mut subscriptions = self.subscriptions.write().await;
        subscriptions
            .remove(subscription_id)
            .ok_or_else(|| anyhow!("Subscription not found"))?;

        // Remove window
        self.windows.write().await.remove(subscription_id);

        // Update stats
        let mut stats = self.stats.write().await;
        stats.total_subscriptions = subscriptions.len();
        stats.active_subscriptions = subscriptions
            .values()
            .filter(|s| s.state == SubscriptionState::Active)
            .count();

        info!("Unregistered GraphQL subscription: {}", subscription_id);
        Ok(())
    }

    /// Pause a subscription
    pub async fn pause_subscription(&self, subscription_id: &str) -> Result<()> {
        let mut subscriptions = self.subscriptions.write().await;
        let subscription = subscriptions
            .get_mut(subscription_id)
            .ok_or_else(|| anyhow!("Subscription not found"))?;

        let old_state = subscription.state.clone();
        subscription.state = SubscriptionState::Paused;

        // Emit state change event
        let _ = self.event_tx.send(SubscriptionEvent::StateChanged {
            subscription_id: subscription_id.to_string(),
            old_state,
            new_state: SubscriptionState::Paused,
        });

        info!("Paused subscription: {}", subscription_id);
        Ok(())
    }

    /// Resume a paused subscription
    pub async fn resume_subscription(&self, subscription_id: &str) -> Result<()> {
        let mut subscriptions = self.subscriptions.write().await;
        let subscription = subscriptions
            .get_mut(subscription_id)
            .ok_or_else(|| anyhow!("Subscription not found"))?;

        let old_state = subscription.state.clone();
        subscription.state = SubscriptionState::Active;
        subscription.metadata.last_activity = Utc::now();

        // Emit state change event
        let _ = self.event_tx.send(SubscriptionEvent::StateChanged {
            subscription_id: subscription_id.to_string(),
            old_state,
            new_state: SubscriptionState::Active,
        });

        info!("Resumed subscription: {}", subscription_id);
        Ok(())
    }

    /// Process stream event
    pub async fn process_event(&self, event: &StreamEvent) -> Result<()> {
        let subscriptions = self.subscriptions.read().await;

        for (sub_id, subscription) in subscriptions.iter() {
            // Only process for active subscriptions
            if subscription.state != SubscriptionState::Active {
                continue;
            }

            // Apply filters
            if !self.apply_filters(event, &subscription.filters).await? {
                continue;
            }

            // Handle windowing
            if self.config.enable_windowing && subscription.window.is_some() {
                self.add_to_window(sub_id, event).await?;
            } else {
                // Send immediate update
                self.send_update(sub_id, event).await?;
            }
        }

        let mut stats = self.stats.write().await;
        stats.total_events_processed += 1;

        Ok(())
    }

    /// Apply filters to event
    async fn apply_filters(
        &self,
        _event: &StreamEvent,
        filters: &[AdvancedFilter],
    ) -> Result<bool> {
        if !self.config.enable_advanced_filtering || filters.is_empty() {
            return Ok(true);
        }

        // Simplified filter logic - in production, implement full filter evaluation
        for filter in filters {
            match filter {
                AdvancedFilter::TimeRange { start, end } => {
                    let now = Utc::now();
                    if let Some(start) = start {
                        if &now < start {
                            return Ok(false);
                        }
                    }
                    if let Some(end) = end {
                        if &now > end {
                            return Ok(false);
                        }
                    }
                }
                _ => {
                    // Other filter types would be evaluated here
                }
            }
        }

        Ok(true)
    }

    /// Create window for subscription
    async fn create_window(&self, subscription_id: &str, spec: WindowSpec) -> Result<()> {
        let window = SubscriptionWindow {
            id: uuid::Uuid::new_v4().to_string(),
            subscription_id: subscription_id.to_string(),
            spec,
            buffer: VecDeque::new(),
            state: WindowState {
                start_time: Utc::now(),
                end_time: None,
                event_count: 0,
                total_bytes: 0,
                is_closed: false,
            },
        };

        self.windows
            .write()
            .await
            .insert(subscription_id.to_string(), window);

        Ok(())
    }

    /// Add event to window
    async fn add_to_window(&self, subscription_id: &str, event: &StreamEvent) -> Result<()> {
        let mut windows = self.windows.write().await;
        if let Some(window) = windows.get_mut(subscription_id) {
            let windowed_event = WindowedEvent {
                event: event.clone(),
                timestamp: Utc::now(),
                sequence_id: window.state.event_count as u64,
            };

            window.buffer.push_back(windowed_event);
            window.state.event_count += 1;

            // Check triggers
            self.check_window_triggers(window).await?;
        }

        Ok(())
    }

    /// Check if window triggers should fire
    async fn check_window_triggers(&self, window: &mut SubscriptionWindow) -> Result<()> {
        for trigger in &window.spec.triggers {
            match trigger {
                WindowTrigger::EventCount(count) if window.state.event_count >= *count => {
                    // Trigger window emission
                    debug!("Window trigger fired: event count {}", count);
                }
                WindowTrigger::TimeInterval(duration) => {
                    let elapsed = Utc::now() - window.state.start_time;
                    if elapsed > ChronoDuration::from_std(*duration)? {
                        debug!("Window trigger fired: time interval {:?}", duration);
                    }
                }
                _ => {}
            }
        }

        Ok(())
    }

    /// Send update to subscription
    async fn send_update(&self, subscription_id: &str, event: &StreamEvent) -> Result<()> {
        // Convert event to GraphQL data
        let data = self.convert_event_to_graphql(event)?;

        // Emit update event
        let _ = self.event_tx.send(SubscriptionEvent::Update {
            subscription_id: subscription_id.to_string(),
            data,
            timestamp: Utc::now(),
        });

        // Update subscription statistics
        let mut subscriptions = self.subscriptions.write().await;
        if let Some(subscription) = subscriptions.get_mut(subscription_id) {
            subscription.stats.updates_sent += 1;
            subscription.metadata.last_activity = Utc::now();
        }

        Ok(())
    }

    /// Convert stream event to GraphQL data
    fn convert_event_to_graphql(&self, event: &StreamEvent) -> Result<serde_json::Value> {
        // Simplified conversion - in production, implement full event mapping
        Ok(serde_json::json!({
            "type": format!("{:?}", event),
            "timestamp": Utc::now().to_rfc3339(),
        }))
    }

    /// Start heartbeat task
    fn start_heartbeat_task(&self) {
        let subscriptions = self.subscriptions.clone();
        let event_tx = self.event_tx.clone();
        let interval_duration = self.config.heartbeat_interval;

        tokio::spawn(async move {
            let mut interval_timer = interval(interval_duration);

            loop {
                interval_timer.tick().await;

                let subs = subscriptions.read().await;
                for (sub_id, subscription) in subs.iter() {
                    if subscription.state == SubscriptionState::Active {
                        let _ = event_tx.send(SubscriptionEvent::Heartbeat {
                            subscription_id: sub_id.clone(),
                            timestamp: Utc::now(),
                        });
                    }
                }
            }
        });
    }

    /// Start cleanup task
    fn start_cleanup_task(&self) {
        let subscriptions = self.subscriptions.clone();
        let timeout = self.config.subscription_timeout;

        tokio::spawn(async move {
            let mut interval_timer = interval(Duration::from_secs(60));

            loop {
                interval_timer.tick().await;

                let mut subs = subscriptions.write().await;
                let now = Utc::now();

                // Remove timed-out subscriptions
                subs.retain(|_, subscription| {
                    let inactive_duration = now - subscription.metadata.last_activity;
                    inactive_duration
                        < ChronoDuration::from_std(timeout)
                            .expect("timeout should be valid chrono Duration")
                });
            }
        });
    }

    /// Get statistics
    pub async fn get_stats(&self) -> SubscriptionStats {
        self.stats.read().await.clone()
    }

    /// Subscribe to events
    pub fn subscribe(&self) -> broadcast::Receiver<SubscriptionEvent> {
        self.event_tx.subscribe()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[tokio::test]
    async fn test_subscription_config_defaults() {
        let config = SubscriptionConfig::default();
        assert_eq!(config.max_subscriptions, 10000);
        assert!(config.enable_windowing);
    }

    #[tokio::test]
    async fn test_subscription_states() {
        let state = SubscriptionState::Active;
        assert_eq!(state, SubscriptionState::Active);

        let state = SubscriptionState::Paused;
        assert_eq!(state, SubscriptionState::Paused);
    }

    #[tokio::test]
    async fn test_filter_operators() {
        assert_eq!(FilterOperator::Equal, FilterOperator::Equal);
        assert_ne!(FilterOperator::Equal, FilterOperator::NotEqual);
    }

    #[tokio::test]
    async fn test_window_types() {
        let window = WindowSpec {
            window_type: WindowType::Tumbling,
            size: WindowSize::Time(Duration::from_secs(60)),
            slide: None,
            triggers: vec![WindowTrigger::EventCount(100)],
        };

        assert_eq!(window.window_type, WindowType::Tumbling);
    }

    #[tokio::test]
    async fn test_subscription_priority() {
        assert!(SubscriptionPriority::Critical > SubscriptionPriority::High);
        assert!(SubscriptionPriority::High > SubscriptionPriority::Normal);
        assert!(SubscriptionPriority::Normal > SubscriptionPriority::Low);
    }
}