mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-06 20:02:18 +00:00
* refactor: Rename handler package to handlers in carrier-connector - Rename internal/handler directory to internal/handlers - Update handler import path in main.go and routes.go * feat: Add SM-DP+ handler with multi-carrier management and profile operations - Add SMDPHandler struct with manager field and NewSMDPHandler constructor - Add AddCarrier endpoint with JSON binding and carrier configuration support - Add RemoveCarrier endpoint with carrier ID parameter validation - Add DownloadProfile endpoint with 30-second timeout and context cancellation - Add GetCarrierStatus endpoint returning all carriers with timestamp - Add GetProfileStatus endpoint with EID/ICCID validation * feat: Add SM-DP+ integration layer with multi-carrier system initialization and route registration - Add SMDPIntegration struct with service, handler, repository, and logger fields - Add NewSMDPIntegration constructor with default carrier initialization - Add InitializeSystem method with carrier health logging and status tracking - Add RegisterRoutes method with profile, carrier, health, and metrics endpoints - Add healthHandler with carrier health status aggregation and degraded state detection - Add metricsHandler * feat: Add SM-DP+ service layer with multi-carrier management and profile download operations - Add SMDPService struct with manager, repository, and logger fields - Add NewSMDPService constructor with default config and background health checking - Add InitializeDefaultCarriers with AT&T, Verizon, and T-Mobile DE configurations - Add DownloadProfile method with context support and request logging - Add GetOptimalCarrier wrapping SelectCarrier for best carrier selection - Add GetCarrierHealth returning * feat: Add SM-DP+ manager with multi-carrier load balancing, health checking, and profile operations - Add DefaultManagerConfig with 30s health checks, 3 retries, and circuit breaker configuration - Add CarrierConfig struct with ES2 settings, MCC/MNC, priority, and feature support - Add ToCarrier method converting CarrierConfig to Carrier with metrics and capabilities - Add HealthChecker with periodic carrier health monitoring and status evaluation - Add LoadBalancer with weighted round-robin, least * feat: Add intelligent carrier selection service with scoring, recommendations, and analytics - Add SelectionService struct with manager, handler, and logger fields - Add NewSelectionService constructor with info-level logging - Add IntelligentCarrierSelection method with comprehensive criteria evaluation - Add IntelligentSelectionRequest with region, profile type, urgency, and cost sensitivity - Add UserPreferences and BusinessContext structs for selection customization - Add IntelligentSelectionResponse with selected * feat: Add carrier selection handler with optimal selection, analytics, and performance monitoring endpoints - Add SelectionHandler struct with manager and logger fields - Add NewSelectionHandler constructor with info-level logging - Add SelectOptimalCarrier endpoint with criteria validation and scoring - Add SelectCarrier endpoint using default selection criteria - Add GetSelectionHistory endpoint with carrier ID path parameter - Add UpdateLearning endpoint with performance feedback validation - Add GetSelectionAnalytics endpoint with carrier stats * feat: Add carrier selection integration layer with multi-carrier setup, HTTP server, and demo capabilities - Add SelectionIntegration struct with manager, selection service, handler, and SMDP service fields - Add NewSelectionIntegration constructor with default manager config and 30s health checks - Add SetupCarriers with AT&T, Verizon, T-Mobile DE, and Orange FR configurations - Add StartServer method with health endpoint and 30s read/write timeouts - Add StartHealthChecking wrapper for background * feat: Refactor profile handlers into modular core components with simplified operations - Split profile_handlers.go into profile_handlers_core.go, profile_handlers_management_core.go, and profile_handlers_management_delete.go - Simplify OrderProfileHandlerWithRepo with ICCID/IMSI-only validation and "downloaded" state - Remove webhook and message queue notifications from order handler - Add UpdateProfileHandler with state validation for downloaded/activated/deactivated/expired - Add DeleteProfileHandler with existence * refactor: Extract carrier setup logic into separate file and remove unnecessary comments - Move SetupCarriers method from selection_integration.go to new setup_carriers.go file - Remove redundant comments from SelectionIntegration struct and methods - Clean up inline comments in RunDemo method while preserving functionality * feat: Add intelligent carrier selection algorithm with machine learning optimization and performance tracking - Add SelectionAlgorithm with scoring, weighting, and ML-based carrier selection - Add SelectionCriteria struct with region, profile type, urgency, and cost/performance weights - Add CarrierScore with performance, reliability, cost, region, and capability scores - Add calculateWeightedScore combining all scores with ML-optimized weights - Add getWeights with urgency-based adjustments * feat: Integrate SelectionAlgorithm into SMDPManager with optimal carrier selection and learning capabilities - Add selector field to SMDPManager struct with SelectionAlgorithm type - Initialize selector in NewSMDPManager constructor - Add SelectOptimalCarrier method filtering healthy carriers and delegating to selection algorithm - Add SelectCarrier wrapper with default criteria (operational profile, medium urgency, balanced weights) - Add GetSelectionHistory method returning carrier selection history - Add UpdateLearning
167 lines
4.5 KiB
Go
167 lines
4.5 KiB
Go
package smdp
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
// TestEdgeCases tests edge cases and boundary conditions
|
|
func TestEdgeCases(t *testing.T) {
|
|
selector := NewSelectionAlgorithm()
|
|
|
|
// Test empty carrier list
|
|
t.Run("EmptyCarrierList", func(t *testing.T) {
|
|
criteria := &SelectionCriteria{
|
|
Region: "US",
|
|
ProfileType: "operational",
|
|
Urgency: "medium",
|
|
CostSensitivity: 0.5,
|
|
PerformanceWeight: 0.4,
|
|
ReliabilityWeight: 0.4,
|
|
}
|
|
|
|
_, err := selector.SelectOptimalCarrier(context.Background(), []*Carrier{}, criteria)
|
|
if err == nil {
|
|
t.Error("Expected error for empty carrier list")
|
|
}
|
|
})
|
|
|
|
// Test all unhealthy carriers
|
|
t.Run("AllUnhealthyCarriers", func(t *testing.T) {
|
|
unhealthyCarriers := []*Carrier{
|
|
createUnhealthyCarrier("broken1", "Broken 1", "US"),
|
|
createUnhealthyCarrier("broken2", "Broken 2", "US"),
|
|
}
|
|
|
|
criteria := &SelectionCriteria{
|
|
Region: "US",
|
|
ProfileType: "operational",
|
|
Urgency: "medium",
|
|
CostSensitivity: 0.5,
|
|
PerformanceWeight: 0.4,
|
|
ReliabilityWeight: 0.4,
|
|
}
|
|
|
|
_, err := selector.SelectOptimalCarrier(context.Background(), unhealthyCarriers, criteria)
|
|
if err == nil {
|
|
t.Error("Expected error when all carriers are unhealthy")
|
|
}
|
|
})
|
|
|
|
// Test inactive carriers
|
|
t.Run("InactiveCarriers", func(t *testing.T) {
|
|
inactiveCarriers := []*Carrier{
|
|
createInactiveCarrier("inactive1", "Inactive 1", "US"),
|
|
createInactiveCarrier("inactive2", "Inactive 2", "US"),
|
|
}
|
|
|
|
criteria := &SelectionCriteria{
|
|
Region: "US",
|
|
ProfileType: "operational",
|
|
Urgency: "medium",
|
|
CostSensitivity: 0.5,
|
|
PerformanceWeight: 0.4,
|
|
ReliabilityWeight: 0.4,
|
|
}
|
|
|
|
_, err := selector.SelectOptimalCarrier(context.Background(), inactiveCarriers, criteria)
|
|
if err == nil {
|
|
t.Error("Expected error when all carriers are inactive")
|
|
}
|
|
})
|
|
}
|
|
|
|
// TestMultipleSelections tests behavior with multiple selections
|
|
func TestMultipleSelections(t *testing.T) {
|
|
selector := NewSelectionAlgorithm()
|
|
|
|
carriers := []*Carrier{
|
|
createTestCarrier("carrier1", "Carrier 1", "US", 90, 95, 100, 5.0),
|
|
createTestCarrier("carrier2", "Carrier 2", "US", 85, 98, 120, 4.0),
|
|
createTestCarrier("carrier3", "Carrier 3", "US", 80, 97, 110, 6.0),
|
|
}
|
|
|
|
criteria := &SelectionCriteria{
|
|
Region: "US",
|
|
ProfileType: "operational",
|
|
Urgency: "medium",
|
|
CostSensitivity: 0.5,
|
|
PerformanceWeight: 0.4,
|
|
ReliabilityWeight: 0.4,
|
|
}
|
|
|
|
// Perform multiple selections
|
|
selections := make(map[string]int)
|
|
for i := range 20 {
|
|
score, err := selector.SelectOptimalCarrier(context.Background(), carriers, criteria)
|
|
if err != nil {
|
|
t.Fatalf("Selection %d failed: %v", i, err)
|
|
}
|
|
selections[score.CarrierID]++
|
|
}
|
|
|
|
// Check that we have some distribution
|
|
totalSelections := 0
|
|
for _, count := range selections {
|
|
totalSelections += count
|
|
}
|
|
if totalSelections != 20 {
|
|
t.Errorf("Expected 20 total selections, got %d", totalSelections)
|
|
}
|
|
|
|
t.Logf("Selection distribution: %+v", selections)
|
|
}
|
|
|
|
// TestLearningFeedback tests the learning feedback mechanism
|
|
func TestLearningFeedback(t *testing.T) {
|
|
selector := NewSelectionAlgorithm()
|
|
|
|
carriers := []*Carrier{
|
|
createTestCarrier("learning-carrier", "Learning Carrier", "US", 80, 90, 150, 5.0),
|
|
}
|
|
|
|
criteria := &SelectionCriteria{
|
|
Region: "US",
|
|
ProfileType: "operational",
|
|
Urgency: "medium",
|
|
CostSensitivity: 0.5,
|
|
PerformanceWeight: 0.4,
|
|
ReliabilityWeight: 0.4,
|
|
}
|
|
|
|
// Initial selection
|
|
_, err := selector.SelectOptimalCarrier(context.Background(), carriers, criteria)
|
|
if err != nil {
|
|
t.Fatalf("Initial selection failed: %v", err)
|
|
}
|
|
|
|
initialLearningRate := selector.learningRate
|
|
|
|
// Update with poor performance
|
|
selector.UpdateLearning("learning-carrier", 30.0)
|
|
learningRateAfterPoor := selector.learningRate
|
|
|
|
// Update with good performance
|
|
selector.UpdateLearning("learning-carrier", 90.0)
|
|
learningRateAfterGood := selector.learningRate
|
|
|
|
// Verify learning rate changes
|
|
if learningRateAfterPoor >= initialLearningRate {
|
|
t.Error("Learning rate should decrease after poor performance")
|
|
}
|
|
|
|
if learningRateAfterGood <= learningRateAfterPoor {
|
|
t.Error("Learning rate should increase after good performance")
|
|
}
|
|
|
|
t.Logf("Learning rate progression: %.4f -> %.4f -> %.4f",
|
|
initialLearningRate, learningRateAfterPoor, learningRateAfterGood)
|
|
}
|
|
|
|
// Helper function to create inactive carrier
|
|
func createInactiveCarrier(id, name, country string) *Carrier {
|
|
carrier := createTestCarrier(id, name, country, 50, 50, 500, 1.0)
|
|
carrier.IsActive = false
|
|
return carrier
|
|
}
|