diff --git a/engine/caches_test.go b/engine/caches_test.go index 226345c14..352902685 100644 --- a/engine/caches_test.go +++ b/engine/caches_test.go @@ -19,6 +19,7 @@ along with this program. If not, see package engine import ( + "reflect" "testing" "time" @@ -206,3 +207,27 @@ func TestLoadDataDbCache(t *testing.T) { t.Error(nil) } } + +func TestPreCacheStatus(t *testing.T) { + cfg, _ := config.NewDefaultCGRConfig() + db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) + dm := NewDataManager(db, cfg.CacheCfg(), nil) + chS := NewCacheS(cfg, dm) + args := &utils.AttrCacheIDsWithArgDispatcher{ + CacheIDs: []string{utils.CacheChargerProfiles, utils.CacheDispatcherHosts}, + } + go func() { + chS.pcItems[utils.CacheChargerProfiles] <- struct{}{} + }() + time.Sleep(5 * time.Millisecond) + exp := map[string]string{ + utils.CacheChargerProfiles: utils.MetaReady, + utils.CacheDispatcherHosts: utils.MetaPrecaching, + } + var reply map[string]string + if err := chS.V1PrecacheStatus(args, &reply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(exp, reply) { + t.Errorf("Expected %v,Received %v", utils.ToJSON(exp), utils.ToJSON(reply)) + } +} diff --git a/engine/datamanager_test.go b/engine/datamanager_test.go index a6936eb36..8d2778ed5 100644 --- a/engine/datamanager_test.go +++ b/engine/datamanager_test.go @@ -274,6 +274,110 @@ func TestCacheDataFromDBFilterIndexes(t *testing.T) { if err := dm.CacheDataFromDB(utils.AttributeFilterIndexes, nil, false); err != nil { t.Error(err) } + fltr2 := &Filter{ + Tenant: "cgrates.org", + ID: "RS_FLT", + Rules: []*FilterRule{ + { + Type: utils.MetaString, + Element: "~*req.Destination", + Values: []string{"1002", "1003"}, + }, + }, + } + dm.SetFilter(fltr2) + rsc := &ResourceProfile{ + Tenant: "cgrates.org", + ID: "RES1", + FilterIDs: []string{"RS_FLT"}, + ThresholdIDs: []string{utils.META_NONE}, + AllocationMessage: "Approved", + Weight: 10, + Limit: 10, + UsageTTL: time.Minute, + Stored: true, + } + dm.SetResourceProfile(rsc, true) + if err := dm.CacheDataFromDB(utils.ResourceFilterIndexes, nil, false); err != nil { + t.Error(err) + } + statFlt := &Filter{ + Tenant: "cgrates.org", + ID: "FLTR_STATS_1", + Rules: []*FilterRule{ + { + Type: utils.MetaString, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account, + Values: []string{"1001"}, + }, + { + Type: utils.MetaGreaterOrEqual, + Element: "~*req.UsageInterval", + Values: []string{(1 * time.Second).String()}, + }, + { + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage, + Values: []string{(1 * time.Second).String()}, + }, + { + Type: utils.MetaGreaterOrEqual, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight, + Values: []string{"9.0"}, + }, + }, + } + dm.SetFilter(statFlt) + sqP := &StatQueueProfile{ + Tenant: "cgrates.org", + ID: "DistinctMetricProfile", + QueueLength: 10, + FilterIDs: []string{"FLTR_STATS_1"}, + TTL: time.Duration(10) * time.Second, + Metrics: []*MetricWithFilters{ + { + MetricID: utils.MetaDDC, + }, + }, + ThresholdIDs: []string{utils.META_NONE}, + Stored: true, + Weight: 20, + } + dm.SetStatQueueProfile(sqP, true) + + if err := dm.CacheDataFromDB(utils.StatFilterIndexes, nil, false); err != nil { + t.Error(err) + } + thFltr := &Filter{ + Tenant: "cgrates.org", + ID: "FLTR_TH_2", + Rules: []*FilterRule{ + { + Type: utils.MetaString, + Element: "~*req.Threshold", + Values: []string{"TH_2"}, + }, + { + Type: utils.MetaPrefix, + Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination, + Values: []string{"100"}, + }, + }, + } + dm.SetFilter(thFltr) + thP := &ThresholdProfile{ + Tenant: "cgrates.org", + ID: "THD_AccDisableAndLog", + FilterIDs: []string{"FLTR_TH_2"}, + MaxHits: -1, + MinSleep: time.Duration(1 * time.Second), + Weight: 30.0, + ActionIDs: []string{"DISABLE_LOG"}, + } + dm.SetThresholdProfile(thP, true) + if err := dm.CacheDataFromDB(utils.ThresholdFilterIndexes, nil, false); err != nil { + t.Error(err) + } } func TestFilterIndexesRmtRpl(t *testing.T) { diff --git a/engine/responder_test.go b/engine/responder_test.go index d55e1bd47..e96542585 100644 --- a/engine/responder_test.go +++ b/engine/responder_test.go @@ -474,6 +474,112 @@ func TestResponderGetMaxSessionTimeMaxUsageVOICE(t *testing.T) { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } } +func TestResponderGetMaxSessionTimePass(t *testing.T) { + cfg, _ := config.NewDefaultCGRConfig() + db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) + tmpDM := dm + dm := NewDataManager(db, cfg.CacheCfg(), nil) + defer func() { + cfg2, _ := config.NewDefaultCGRConfig() + config.SetCgrConfig(cfg2) + SetDataStorage(tmpDM) + }() + arg := &CallDescriptorWithArgDispatcher{ + CallDescriptor: &CallDescriptor{ + Category: "call", + Tenant: "cgrates.org", + Subject: "1001", + Account: "1001", + Destination: "1002", + TimeStart: time.Date(2023, 3, 4, 15, 54, 00, 0, time.UTC), + TimeEnd: time.Date(2023, 3, 4, 15, 55, 40, 0, time.UTC), + MaxCostSoFar: 0, + ToR: utils.MONETARY, + }, + } + rsponder.MaxComputedUsage[utils.MONETARY] = 2 * time.Minute + dm.SetAccount(&Account{ + ID: "cgrates.org:1001", + BalanceMap: map[string]Balances{ + utils.MONETARY: { + &Balance{ + Weight: 30, + Value: 12, + DestinationIDs: utils.NewStringMap("1002"), + }, + }, + }, + }) + dest := &Destination{ + Id: "DEST", + Prefixes: []string{ + "1002", "1003", "1004", + }, + } + if err := dm.SetReverseDestination(dest, utils.NonTransactional); err != nil { + t.Error(err) + } + rp := &RatingPlan{ + Id: "RP_1001", + Timings: map[string]*RITiming{ + "59a981b9": { + Years: utils.Years{}, + Months: utils.Months{}, + MonthDays: utils.MonthDays{}, + WeekDays: utils.WeekDays{1, 2, 3, 4, 5}, + StartTime: "00:00:00", + }, + }, + Ratings: map[string]*RIRate{ + "efwqpqq32": { + ConnectFee: 0.1, + Rates: RateGroups{ + &Rate{ + GroupIntervalStart: 0, + Value: 0.7, + RateIncrement: time.Second, + RateUnit: time.Minute, + }, + &Rate{ + GroupIntervalStart: 60, + Value: 1, + RateIncrement: time.Second, + RateUnit: time.Second, + }, + }, + RoundingMethod: utils.ROUNDING_MIDDLE, + RoundingDecimals: 4, + }, + }, + DestinationRates: map[string]RPRateList{ + "DEST": { + &RPRate{ + Timing: "59a981b9", + Rating: "efwqpqq32", + Weight: 20, + }, + }, + }, + } + dm.SetRatingPlan(rp, utils.NonTransactional) + rpP := &RatingProfile{ + Id: utils.ConcatenatedKey(utils.META_OUT, "cgrates.org", "call", "1001"), + RatingPlanActivations: RatingPlanActivations{ + &RatingPlanActivation{ + RatingPlanId: "RP_1001", + }, + }, + } + dm.SetRatingProfile(rpP, utils.NonTransactional) + + SetDataStorage(dm) + + var reply time.Duration + if err := rsponder.GetMaxSessionTime(arg, &reply); err == nil { + t.Error(err) + } + //unfinished +} func TestMaxSessionTimeOnAccounts(t *testing.T) { cfg, _ := config.NewDefaultCGRConfig() @@ -799,7 +905,7 @@ func TestResponderMaxDebit11(t *testing.T) { Rates: RateGroups{ { GroupIntervalStart: 0, - Value: 0.01, + Value: 0.1, RateIncrement: time.Second, RateUnit: time.Second, }, @@ -949,7 +1055,9 @@ func TestResponderRounding(t *testing.T) { ID: "cgrates.org:1001", BalanceMap: map[string]Balances{ utils.MONETARY: { - &Balance{Value: 11, Weight: 20, DestinationIDs: utils.NewStringMap("1002")}, + &Balance{ + ID: utils.MetaDefault, + Value: 11, Weight: 20, DestinationIDs: utils.NewStringMap("1002")}, }}, }) rsponder.MaxComputedUsage = map[string]time.Duration{ @@ -958,5 +1066,7 @@ func TestResponderRounding(t *testing.T) { var reply Account if err := rsponder.RefundRounding(arg, &reply); err != nil { t.Error(err) + } else if reply.GetDefaultMoneyBalance().Value != 11 { + t.Error(utils.ToJSON(reply)) } }