quantrs2_anneal/comprehensive_integration_testing/
config.rs

1//! Configuration types for the comprehensive integration testing framework
2
3use std::collections::HashMap;
4use std::time::Duration;
5
6/// Integration testing framework configuration
7#[derive(Debug, Clone)]
8pub struct IntegrationTestConfig {
9    /// Test execution timeout
10    pub execution_timeout: Duration,
11    /// Maximum concurrent test executions
12    pub max_concurrent_tests: usize,
13    /// Test result storage configuration
14    pub storage_config: TestStorageConfig,
15    /// Performance benchmark settings
16    pub benchmark_config: BenchmarkConfig,
17    /// Stress testing configuration
18    pub stress_config: StressTestConfig,
19    /// Fault injection settings
20    pub fault_injection_config: FaultInjectionConfig,
21    /// Monitoring and reporting settings
22    pub monitoring_config: MonitoringConfig,
23    /// Test environment configuration
24    pub environment_config: TestEnvironmentConfig,
25}
26
27impl Default for IntegrationTestConfig {
28    fn default() -> Self {
29        Self {
30            execution_timeout: Duration::from_secs(300),
31            max_concurrent_tests: 4,
32            storage_config: TestStorageConfig::default(),
33            benchmark_config: BenchmarkConfig::default(),
34            stress_config: StressTestConfig::default(),
35            fault_injection_config: FaultInjectionConfig::default(),
36            monitoring_config: MonitoringConfig::default(),
37            environment_config: TestEnvironmentConfig::default(),
38        }
39    }
40}
41
42/// Test result storage configuration
43#[derive(Debug, Clone)]
44pub struct TestStorageConfig {
45    /// Enable persistent storage
46    pub enable_persistent_storage: bool,
47    /// Storage format
48    pub storage_format: StorageFormat,
49    /// Retention policy
50    pub retention_policy: RetentionPolicy,
51    /// Compression settings
52    pub compression: CompressionConfig,
53}
54
55impl Default for TestStorageConfig {
56    fn default() -> Self {
57        Self {
58            enable_persistent_storage: true,
59            storage_format: StorageFormat::JSON,
60            retention_policy: RetentionPolicy::KeepLast(1000),
61            compression: CompressionConfig::default(),
62        }
63    }
64}
65
66/// Storage formats for test results
67#[derive(Debug, Clone, PartialEq, Eq)]
68pub enum StorageFormat {
69    JSON,
70    Binary,
71    Database,
72    CSV,
73}
74
75/// Retention policies for test data
76#[derive(Debug, Clone)]
77pub enum RetentionPolicy {
78    /// Keep last N test results
79    KeepLast(usize),
80    /// Keep results for duration
81    KeepForDuration(Duration),
82    /// Keep all results
83    KeepAll,
84    /// Custom retention logic
85    Custom(String),
86}
87
88/// Compression configuration
89#[derive(Debug, Clone)]
90pub struct CompressionConfig {
91    /// Enable compression
92    pub enable_compression: bool,
93    /// Compression algorithm
94    pub algorithm: CompressionAlgorithm,
95    /// Compression level
96    pub level: u8,
97}
98
99impl Default for CompressionConfig {
100    fn default() -> Self {
101        Self {
102            enable_compression: true,
103            algorithm: CompressionAlgorithm::Gzip,
104            level: 6,
105        }
106    }
107}
108
109/// Compression algorithms
110#[derive(Debug, Clone, PartialEq, Eq)]
111pub enum CompressionAlgorithm {
112    Gzip,
113    Zstd,
114    Lz4,
115    None,
116}
117
118/// Benchmark configuration
119#[derive(Debug, Clone)]
120pub struct BenchmarkConfig {
121    /// Enable performance benchmarking
122    pub enable_benchmarking: bool,
123    /// Benchmark suite selection
124    pub benchmark_suites: Vec<BenchmarkSuite>,
125    /// Performance baseline configuration
126    pub baseline_config: BaselineConfig,
127    /// Statistical analysis settings
128    pub statistical_config: StatisticalConfig,
129}
130
131impl Default for BenchmarkConfig {
132    fn default() -> Self {
133        Self {
134            enable_benchmarking: true,
135            benchmark_suites: vec![
136                BenchmarkSuite::Performance,
137                BenchmarkSuite::Scalability,
138                BenchmarkSuite::Accuracy,
139            ],
140            baseline_config: BaselineConfig::default(),
141            statistical_config: StatisticalConfig::default(),
142        }
143    }
144}
145
146/// Benchmark suite types
147#[derive(Debug, Clone, PartialEq, Eq)]
148pub enum BenchmarkSuite {
149    /// Performance benchmarks
150    Performance,
151    /// Scalability tests
152    Scalability,
153    /// Accuracy validation
154    Accuracy,
155    /// Resource utilization
156    ResourceUtilization,
157    /// Integration complexity
158    IntegrationComplexity,
159    /// Custom benchmark
160    Custom(String),
161}
162
163/// Baseline configuration for comparisons
164#[derive(Debug, Clone)]
165pub struct BaselineConfig {
166    /// Use historical baselines
167    pub use_historical: bool,
168    /// Baseline update strategy
169    pub update_strategy: BaselineUpdateStrategy,
170    /// Performance thresholds
171    pub performance_thresholds: PerformanceThresholds,
172}
173
174impl Default for BaselineConfig {
175    fn default() -> Self {
176        Self {
177            use_historical: true,
178            update_strategy: BaselineUpdateStrategy::Automatic,
179            performance_thresholds: PerformanceThresholds::default(),
180        }
181    }
182}
183
184/// Baseline update strategies
185#[derive(Debug, Clone, PartialEq, Eq)]
186pub enum BaselineUpdateStrategy {
187    /// Automatic updates based on performance
188    Automatic,
189    /// Manual baseline updates
190    Manual,
191    /// Time-based updates
192    TimeBased(Duration),
193    /// Never update baselines
194    Never,
195}
196
197/// Performance threshold definitions
198#[derive(Debug, Clone)]
199pub struct PerformanceThresholds {
200    /// Maximum acceptable execution time
201    pub max_execution_time: Duration,
202    /// Minimum solution quality
203    pub min_solution_quality: f64,
204    /// Maximum resource usage
205    pub max_resource_usage: f64,
206    /// Maximum error rate
207    pub max_error_rate: f64,
208}
209
210impl Default for PerformanceThresholds {
211    fn default() -> Self {
212        Self {
213            max_execution_time: Duration::from_secs(60),
214            min_solution_quality: 0.8,
215            max_resource_usage: 0.9,
216            max_error_rate: 0.05,
217        }
218    }
219}
220
221/// Statistical analysis configuration
222#[derive(Debug, Clone)]
223pub struct StatisticalConfig {
224    /// Confidence level for analysis
225    pub confidence_level: f64,
226    /// Number of statistical runs
227    pub num_runs: usize,
228    /// Statistical tests to perform
229    pub statistical_tests: Vec<StatisticalTest>,
230    /// Outlier detection method
231    pub outlier_detection: OutlierDetection,
232}
233
234impl Default for StatisticalConfig {
235    fn default() -> Self {
236        Self {
237            confidence_level: 0.95,
238            num_runs: 10,
239            statistical_tests: vec![
240                StatisticalTest::TTest,
241                StatisticalTest::KolmogorovSmirnov,
242                StatisticalTest::MannWhitney,
243            ],
244            outlier_detection: OutlierDetection::IQR,
245        }
246    }
247}
248
249/// Statistical tests for analysis
250#[derive(Debug, Clone, PartialEq, Eq)]
251pub enum StatisticalTest {
252    /// Student's t-test
253    TTest,
254    /// Kolmogorov-Smirnov test
255    KolmogorovSmirnov,
256    /// Mann-Whitney U test
257    MannWhitney,
258    /// Wilcoxon signed-rank test
259    Wilcoxon,
260    /// Chi-squared test
261    ChiSquared,
262}
263
264/// Outlier detection methods
265#[derive(Debug, Clone, PartialEq, Eq)]
266pub enum OutlierDetection {
267    /// Interquartile range method
268    IQR,
269    /// Z-score method
270    ZScore,
271    /// Modified Z-score
272    ModifiedZScore,
273    /// Isolation forest
274    IsolationForest,
275    /// No outlier detection
276    None,
277}
278
279/// Stress testing configuration
280#[derive(Debug, Clone)]
281pub struct StressTestConfig {
282    /// Enable stress testing
283    pub enable_stress_testing: bool,
284    /// Stress test scenarios
285    pub stress_scenarios: Vec<StressScenario>,
286    /// Maximum stress level
287    pub max_stress_level: f64,
288    /// Stress ramp-up strategy
289    pub ramp_up_strategy: RampUpStrategy,
290    /// Failure criteria
291    pub failure_criteria: FailureCriteria,
292}
293
294impl Default for StressTestConfig {
295    fn default() -> Self {
296        Self {
297            enable_stress_testing: true,
298            stress_scenarios: vec![
299                StressScenario::HighLoad,
300                StressScenario::ResourceContention,
301                StressScenario::NetworkLatency,
302            ],
303            max_stress_level: 0.95,
304            ramp_up_strategy: RampUpStrategy::Linear,
305            failure_criteria: FailureCriteria::default(),
306        }
307    }
308}
309
310/// Stress test scenarios
311#[derive(Debug, Clone, PartialEq, Eq)]
312pub enum StressScenario {
313    /// High computational load
314    HighLoad,
315    /// Resource contention
316    ResourceContention,
317    /// Network latency stress
318    NetworkLatency,
319    /// Memory pressure
320    MemoryPressure,
321    /// Concurrent access stress
322    ConcurrentAccess,
323    /// Custom stress scenario
324    Custom(String),
325}
326
327/// Stress ramp-up strategies
328#[derive(Debug, Clone, PartialEq, Eq)]
329pub enum RampUpStrategy {
330    /// Linear ramp-up
331    Linear,
332    /// Exponential ramp-up
333    Exponential,
334    /// Step-wise ramp-up
335    StepWise,
336    /// Random stress levels
337    Random,
338}
339
340/// Failure criteria for stress tests
341#[derive(Debug, Clone)]
342pub struct FailureCriteria {
343    /// Maximum acceptable failures
344    pub max_failures: usize,
345    /// Failure rate threshold
346    pub failure_rate_threshold: f64,
347    /// Response time threshold
348    pub response_time_threshold: Duration,
349    /// Resource exhaustion threshold
350    pub resource_exhaustion_threshold: f64,
351}
352
353impl Default for FailureCriteria {
354    fn default() -> Self {
355        Self {
356            max_failures: 5,
357            failure_rate_threshold: 0.1,
358            response_time_threshold: Duration::from_secs(10),
359            resource_exhaustion_threshold: 0.95,
360        }
361    }
362}
363
364/// Fault injection configuration
365#[derive(Debug, Clone)]
366pub struct FaultInjectionConfig {
367    /// Enable fault injection
368    pub enable_fault_injection: bool,
369    /// Fault types to inject
370    pub fault_types: Vec<FaultType>,
371    /// Injection timing strategy
372    pub timing_strategy: InjectionTiming,
373    /// Fault recovery testing
374    pub test_recovery: bool,
375    /// Chaos engineering settings
376    pub chaos_config: ChaosConfig,
377}
378
379impl Default for FaultInjectionConfig {
380    fn default() -> Self {
381        Self {
382            enable_fault_injection: true,
383            fault_types: vec![
384                FaultType::NetworkFailure,
385                FaultType::ComponentFailure,
386                FaultType::ResourceExhaustion,
387            ],
388            timing_strategy: InjectionTiming::Random,
389            test_recovery: true,
390            chaos_config: ChaosConfig::default(),
391        }
392    }
393}
394
395/// Types of faults to inject
396#[derive(Debug, Clone, PartialEq, Eq)]
397pub enum FaultType {
398    /// Network connectivity failures
399    NetworkFailure,
400    /// Component/service failures
401    ComponentFailure,
402    /// Resource exhaustion
403    ResourceExhaustion,
404    /// Data corruption
405    DataCorruption,
406    /// Timing issues
407    TimingIssues,
408    /// Configuration errors
409    ConfigurationErrors,
410    /// Custom fault type
411    Custom(String),
412}
413
414/// Fault injection timing strategies
415#[derive(Debug, Clone, PartialEq, Eq)]
416pub enum InjectionTiming {
417    /// Random injection times
418    Random,
419    /// Scheduled injection
420    Scheduled(Vec<Duration>),
421    /// Trigger-based injection
422    TriggerBased(Vec<String>),
423    /// Continuous low-level injection
424    Continuous,
425}
426
427/// Chaos engineering configuration
428#[derive(Debug, Clone)]
429pub struct ChaosConfig {
430    /// Enable chaos engineering
431    pub enable_chaos: bool,
432    /// Chaos experiments
433    pub experiments: Vec<ChaosExperiment>,
434    /// Blast radius control
435    pub blast_radius: BlastRadius,
436    /// Safety measures
437    pub safety_measures: SafetyMeasures,
438}
439
440impl Default for ChaosConfig {
441    fn default() -> Self {
442        Self {
443            enable_chaos: false, // Disabled by default for safety
444            experiments: vec![],
445            blast_radius: BlastRadius::Limited,
446            safety_measures: SafetyMeasures::default(),
447        }
448    }
449}
450
451/// Chaos engineering experiments
452#[derive(Debug, Clone)]
453pub struct ChaosExperiment {
454    /// Experiment name
455    pub name: String,
456    /// Experiment type
457    pub experiment_type: ChaosType,
458    /// Target components
459    pub targets: Vec<String>,
460    /// Experiment duration
461    pub duration: Duration,
462    /// Success criteria
463    pub success_criteria: Vec<String>,
464}
465
466/// Types of chaos experiments
467#[derive(Debug, Clone, PartialEq, Eq)]
468pub enum ChaosType {
469    /// Service degradation
470    ServiceDegradation,
471    /// Resource starvation
472    ResourceStarvation,
473    /// Network partitioning
474    NetworkPartitioning,
475    /// Dependency failure
476    DependencyFailure,
477    /// Custom chaos experiment
478    Custom(String),
479}
480
481/// Blast radius control for chaos experiments
482#[derive(Debug, Clone, PartialEq, Eq)]
483pub enum BlastRadius {
484    /// Limited to single components
485    Limited,
486    /// Controlled multi-component impact
487    Controlled,
488    /// System-wide impact allowed
489    SystemWide,
490}
491
492/// Safety measures for chaos engineering
493#[derive(Debug, Clone)]
494pub struct SafetyMeasures {
495    /// Automatic rollback triggers
496    pub auto_rollback_triggers: Vec<String>,
497    /// Maximum impact duration
498    pub max_impact_duration: Duration,
499    /// Emergency stop conditions
500    pub emergency_stop: Vec<String>,
501    /// Health check requirements
502    pub health_checks: Vec<String>,
503}
504
505impl Default for SafetyMeasures {
506    fn default() -> Self {
507        Self {
508            auto_rollback_triggers: vec![
509                "cpu_usage_critical".to_string(),
510                "memory_exhausted".to_string(),
511            ],
512            max_impact_duration: Duration::from_secs(300),
513            emergency_stop: vec!["system_failure".to_string(), "data_corruption".to_string()],
514            health_checks: vec!["system_health".to_string(), "component_status".to_string()],
515        }
516    }
517}
518
519/// Monitoring configuration
520#[derive(Debug, Clone)]
521pub struct MonitoringConfig {
522    /// Enable real-time monitoring
523    pub enable_monitoring: bool,
524    /// Monitoring interval
525    pub monitoring_interval: Duration,
526    /// Metrics to monitor
527    pub monitored_metrics: Vec<MonitoredMetric>,
528    /// Alert configuration
529    pub alert_config: AlertConfig,
530    /// Reporting configuration
531    pub reporting_config: ReportingConfig,
532}
533
534impl Default for MonitoringConfig {
535    fn default() -> Self {
536        Self {
537            enable_monitoring: true,
538            monitoring_interval: Duration::from_secs(1),
539            monitored_metrics: vec![
540                MonitoredMetric::CpuUtilization,
541                MonitoredMetric::MemoryUsage,
542                MonitoredMetric::ErrorRate,
543                MonitoredMetric::ResponseTime,
544            ],
545            alert_config: AlertConfig::default(),
546            reporting_config: ReportingConfig::default(),
547        }
548    }
549}
550
551/// Metrics to monitor during testing
552#[derive(Debug, Clone, PartialEq, Eq, Hash)]
553pub enum MonitoredMetric {
554    /// CPU utilization
555    CpuUtilization,
556    /// Memory usage
557    MemoryUsage,
558    /// Network I/O
559    NetworkIO,
560    /// Disk I/O
561    DiskIO,
562    /// Error rate
563    ErrorRate,
564    /// Response time
565    ResponseTime,
566    /// Throughput
567    Throughput,
568    /// Active connections
569    ActiveConnections,
570    /// Custom metric
571    Custom(String),
572}
573
574/// Alert configuration
575#[derive(Debug, Clone)]
576pub struct AlertConfig {
577    /// Enable alerts
578    pub enable_alerts: bool,
579    /// Alert thresholds
580    pub thresholds: HashMap<MonitoredMetric, f64>,
581    /// Alert channels
582    pub channels: Vec<AlertChannel>,
583    /// Alert frequency limits
584    pub frequency_limits: FrequencyLimits,
585}
586
587impl Default for AlertConfig {
588    fn default() -> Self {
589        let mut thresholds = HashMap::new();
590        thresholds.insert(MonitoredMetric::ErrorRate, 0.1);
591        thresholds.insert(MonitoredMetric::MemoryUsage, 0.9);
592        thresholds.insert(MonitoredMetric::CpuUtilization, 0.95);
593
594        Self {
595            enable_alerts: true,
596            thresholds,
597            channels: vec![AlertChannel::Console],
598            frequency_limits: FrequencyLimits::default(),
599        }
600    }
601}
602
603/// Alert channels
604#[derive(Debug, Clone, PartialEq, Eq)]
605pub enum AlertChannel {
606    /// Console output
607    Console,
608    /// Log files
609    Log,
610    /// Email notifications
611    Email(String),
612    /// Webhook notifications
613    Webhook(String),
614    /// Custom channel
615    Custom(String),
616}
617
618/// Alert frequency limits
619#[derive(Debug, Clone)]
620pub struct FrequencyLimits {
621    /// Maximum alerts per minute
622    pub max_per_minute: usize,
623    /// Cooldown period between similar alerts
624    pub cooldown_period: Duration,
625    /// Enable alert aggregation
626    pub enable_aggregation: bool,
627}
628
629impl Default for FrequencyLimits {
630    fn default() -> Self {
631        Self {
632            max_per_minute: 10,
633            cooldown_period: Duration::from_secs(60),
634            enable_aggregation: true,
635        }
636    }
637}
638
639/// Reporting configuration
640#[derive(Debug, Clone)]
641pub struct ReportingConfig {
642    /// Enable automated reporting
643    pub enable_automated_reporting: bool,
644    /// Report formats
645    pub report_formats: Vec<ReportFormat>,
646    /// Report generation frequency
647    pub generation_frequency: ReportFrequency,
648    /// Report distribution
649    pub distribution: ReportDistribution,
650}
651
652impl Default for ReportingConfig {
653    fn default() -> Self {
654        Self {
655            enable_automated_reporting: true,
656            report_formats: vec![ReportFormat::HTML, ReportFormat::JSON],
657            generation_frequency: ReportFrequency::AfterTestSuite,
658            distribution: ReportDistribution::default(),
659        }
660    }
661}
662
663/// Report formats
664#[derive(Debug, Clone, PartialEq, Eq)]
665pub enum ReportFormat {
666    /// HTML reports
667    HTML,
668    /// JSON data
669    JSON,
670    /// PDF reports
671    PDF,
672    /// CSV data
673    CSV,
674    /// XML format
675    XML,
676}
677
678/// Report generation frequency
679#[derive(Debug, Clone, PartialEq, Eq)]
680pub enum ReportFrequency {
681    /// After each test
682    AfterEachTest,
683    /// After test suite completion
684    AfterTestSuite,
685    /// Scheduled reporting
686    Scheduled(Duration),
687    /// Manual reporting only
688    Manual,
689}
690
691/// Report distribution configuration
692#[derive(Debug, Clone)]
693pub struct ReportDistribution {
694    /// Email recipients
695    pub email_recipients: Vec<String>,
696    /// File system paths
697    pub file_paths: Vec<String>,
698    /// HTTP endpoints
699    pub http_endpoints: Vec<String>,
700    /// Custom distribution targets
701    pub custom_targets: Vec<String>,
702}
703
704impl Default for ReportDistribution {
705    fn default() -> Self {
706        Self {
707            email_recipients: vec![],
708            file_paths: vec!["./test_reports/".to_string()],
709            http_endpoints: vec![],
710            custom_targets: vec![],
711        }
712    }
713}
714
715/// Test environment configuration
716#[derive(Debug, Clone)]
717pub struct TestEnvironmentConfig {
718    /// Environment name
719    pub environment_name: String,
720    /// Environment variables
721    pub environment_variables: HashMap<String, String>,
722    /// Resource allocation
723    pub resource_allocation: ResourceAllocationConfig,
724    /// Cleanup configuration
725    pub cleanup_config: CleanupConfig,
726}
727
728impl Default for TestEnvironmentConfig {
729    fn default() -> Self {
730        Self {
731            environment_name: "default".to_string(),
732            environment_variables: HashMap::new(),
733            resource_allocation: ResourceAllocationConfig::default(),
734            cleanup_config: CleanupConfig::default(),
735        }
736    }
737}
738
739/// Resource allocation configuration
740#[derive(Debug, Clone)]
741pub struct ResourceAllocationConfig {
742    /// Maximum CPU cores
743    pub max_cpu_cores: usize,
744    /// Maximum memory (bytes)
745    pub max_memory: usize,
746    /// Maximum disk space (bytes)
747    pub max_disk_space: usize,
748    /// Network bandwidth limit (bytes/sec)
749    pub network_bandwidth_limit: Option<usize>,
750}
751
752impl Default for ResourceAllocationConfig {
753    fn default() -> Self {
754        Self {
755            max_cpu_cores: num_cpus::get(),
756            max_memory: 8 * 1024 * 1024 * 1024,       // 8 GB
757            max_disk_space: 100 * 1024 * 1024 * 1024, // 100 GB
758            network_bandwidth_limit: None,
759        }
760    }
761}
762
763/// Cleanup configuration
764#[derive(Debug, Clone)]
765pub struct CleanupConfig {
766    /// Auto cleanup after tests
767    pub auto_cleanup: bool,
768    /// Cleanup timeout
769    pub cleanup_timeout: Duration,
770    /// Preserve on failure
771    pub preserve_on_failure: bool,
772    /// Custom cleanup scripts
773    pub custom_scripts: Vec<String>,
774}
775
776impl Default for CleanupConfig {
777    fn default() -> Self {
778        Self {
779            auto_cleanup: true,
780            cleanup_timeout: Duration::from_secs(30),
781            preserve_on_failure: true,
782            custom_scripts: vec![],
783        }
784    }
785}