oxirs-stream 0.3.1

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
//! # Visual Designer — Tests

#[cfg(test)]
mod tests {
    use crate::visual_designer_engine::VisualStreamDesigner;
    use crate::visual_designer_types::{
        DebuggerConfig, ExportFormat, NodeType, Position, SinkType, SourceType,
        VisualDesignerConfig,
    };

    #[tokio::test]
    async fn test_create_pipeline() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline(
                "Test Pipeline".to_string(),
                Some("Test description".to_string()),
            )
            .await
            .unwrap();

        assert!(!pipeline_id.is_empty());

        let pipelines = designer.list_pipelines().await;
        assert_eq!(pipelines.len(), 1);
        assert_eq!(pipelines[0].name, "Test Pipeline");
    }

    #[tokio::test]
    async fn test_add_nodes() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        let source_id = designer
            .add_node(
                &pipeline_id,
                "Source".to_string(),
                NodeType::Source(SourceType::Memory),
                Position {
                    x: 0.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        let sink_id = designer
            .add_node(
                &pipeline_id,
                "Sink".to_string(),
                NodeType::Sink(SinkType::Memory),
                Position {
                    x: 100.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        assert!(!source_id.is_empty());
        assert!(!sink_id.is_empty());

        let pipeline = designer.get_pipeline(&pipeline_id).await.unwrap();
        assert_eq!(pipeline.nodes.len(), 2);
    }

    #[tokio::test]
    async fn test_add_edge() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        let source_id = designer
            .add_node(
                &pipeline_id,
                "Source".to_string(),
                NodeType::Source(SourceType::Memory),
                Position {
                    x: 0.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        let sink_id = designer
            .add_node(
                &pipeline_id,
                "Sink".to_string(),
                NodeType::Sink(SinkType::Memory),
                Position {
                    x: 100.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        let edge_id = designer
            .add_edge(
                &pipeline_id,
                source_id,
                "output".to_string(),
                sink_id,
                "input".to_string(),
            )
            .await
            .unwrap();

        assert!(!edge_id.is_empty());

        let pipeline = designer.get_pipeline(&pipeline_id).await.unwrap();
        assert_eq!(pipeline.edges.len(), 1);
    }

    #[tokio::test]
    async fn test_validate_pipeline() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        let source_id = designer
            .add_node(
                &pipeline_id,
                "Source".to_string(),
                NodeType::Source(SourceType::Memory),
                Position {
                    x: 0.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        let sink_id = designer
            .add_node(
                &pipeline_id,
                "Sink".to_string(),
                NodeType::Sink(SinkType::Memory),
                Position {
                    x: 100.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        designer
            .add_edge(
                &pipeline_id,
                source_id,
                "output".to_string(),
                sink_id,
                "input".to_string(),
            )
            .await
            .unwrap();

        let validation = designer.validate_pipeline(&pipeline_id).await.unwrap();
        assert!(validation.is_valid);
        assert!(validation.errors.is_empty());
    }

    #[tokio::test]
    async fn test_export_import_json() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        designer
            .add_node(
                &pipeline_id,
                "Source".to_string(),
                NodeType::Source(SourceType::Memory),
                Position {
                    x: 0.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        let json = designer
            .export_pipeline(&pipeline_id, ExportFormat::Json)
            .await
            .unwrap();

        assert!(!json.is_empty());

        let new_id = designer
            .import_pipeline(&json, ExportFormat::Json)
            .await
            .unwrap();

        assert!(!new_id.is_empty());

        let imported = designer.get_pipeline(&new_id).await.unwrap();
        assert_eq!(imported.nodes.len(), 1);
    }

    #[tokio::test]
    async fn test_export_dot() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        let source_id = designer
            .add_node(
                &pipeline_id,
                "Source".to_string(),
                NodeType::Source(SourceType::Memory),
                Position {
                    x: 0.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        let sink_id = designer
            .add_node(
                &pipeline_id,
                "Sink".to_string(),
                NodeType::Sink(SinkType::Memory),
                Position {
                    x: 100.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        designer
            .add_edge(
                &pipeline_id,
                source_id,
                "output".to_string(),
                sink_id,
                "input".to_string(),
            )
            .await
            .unwrap();

        let dot = designer
            .export_pipeline(&pipeline_id, ExportFormat::Dot)
            .await
            .unwrap();

        assert!(dot.contains("digraph"));
        assert!(dot.contains("Source"));
        assert!(dot.contains("Sink"));
        assert!(dot.contains("->"));
    }

    #[tokio::test]
    async fn test_create_debugger() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        let debugger_id = designer
            .create_debugger(&pipeline_id, DebuggerConfig::default())
            .await
            .unwrap();

        assert!(!debugger_id.is_empty());

        let state = designer.get_debugger_state(&debugger_id).await.unwrap();
        assert!(!state.is_running);
        assert!(!state.is_paused);
    }

    #[tokio::test]
    async fn test_add_breakpoint() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        let node_id = designer
            .add_node(
                &pipeline_id,
                "Filter".to_string(),
                NodeType::Filter,
                Position {
                    x: 0.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        let debugger_id = designer
            .create_debugger(&pipeline_id, DebuggerConfig::default())
            .await
            .unwrap();

        let breakpoint_id = designer
            .add_breakpoint(&debugger_id, node_id, None)
            .await
            .unwrap();

        assert!(!breakpoint_id.is_empty());
    }

    #[tokio::test]
    async fn test_optimize_pipeline() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        // Create a chain of nodes
        let mut prev_id = None;
        for i in 0..12 {
            let node_id = designer
                .add_node(
                    &pipeline_id,
                    format!("Node{}", i),
                    NodeType::Map,
                    Position {
                        x: i as f64 * 100.0,
                        y: 0.0,
                        z: None,
                    },
                )
                .await
                .unwrap();

            if let Some(prev) = prev_id {
                designer
                    .add_edge(
                        &pipeline_id,
                        prev,
                        "output".to_string(),
                        node_id.clone(),
                        "input".to_string(),
                    )
                    .await
                    .unwrap();
            }

            prev_id = Some(node_id);
        }

        let optimization = designer.optimize_pipeline(&pipeline_id).await.unwrap();
        assert!(!optimization.suggestions.is_empty());
    }

    #[tokio::test]
    async fn test_delete_pipeline() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("Test".to_string(), None)
            .await
            .unwrap();

        assert_eq!(designer.list_pipelines().await.len(), 1);

        designer.delete_pipeline(&pipeline_id).await.unwrap();
        assert_eq!(designer.list_pipelines().await.len(), 0);
    }

    #[tokio::test]
    async fn test_export_svg_contains_svg_tag() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("SVG Test Pipeline".to_string(), None)
            .await
            .unwrap();

        let source_id = designer
            .add_node(
                &pipeline_id,
                "Source".to_string(),
                NodeType::Source(SourceType::Memory),
                Position {
                    x: 0.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        let sink_id = designer
            .add_node(
                &pipeline_id,
                "Sink".to_string(),
                NodeType::Sink(SinkType::Memory),
                Position {
                    x: 200.0,
                    y: 0.0,
                    z: None,
                },
            )
            .await
            .unwrap();

        designer
            .add_edge(
                &pipeline_id,
                source_id,
                "output".to_string(),
                sink_id,
                "input".to_string(),
            )
            .await
            .unwrap();

        let svg = designer
            .export_pipeline(&pipeline_id, ExportFormat::Svg)
            .await
            .expect("SVG export should succeed");

        assert!(
            svg.contains("<svg"),
            "SVG output must start with <svg element"
        );
        assert!(svg.contains("</svg>"), "SVG output must be closed");
        assert!(
            svg.contains("Source"),
            "SVG must contain node label 'Source'"
        );
        assert!(svg.contains("Sink"), "SVG must contain node label 'Sink'");
    }

    #[tokio::test]
    async fn test_export_png_returns_descriptive_error() {
        let designer = VisualStreamDesigner::new(VisualDesignerConfig::default());
        let pipeline_id = designer
            .create_pipeline("PNG Test".to_string(), None)
            .await
            .unwrap();

        let result = designer
            .export_pipeline(&pipeline_id, ExportFormat::Png)
            .await;

        assert!(
            result.is_err(),
            "PNG export should return an error per policy"
        );
        let err_msg = result.unwrap_err().to_string();
        assert!(
            err_msg.contains("PNG"),
            "Error message should mention PNG: {err_msg}"
        );
    }
}