diff --git a/engine/tpreader.go b/engine/tpreader.go index 767ad1a44..d00efd9f6 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -1971,6 +1971,14 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) { i++ } return keys, nil + case utils.TimingsPrefix: + keys := make([]string, len(tpr.timings)) + i := 0 + for k := range tpr.timings { + keys[i] = k + i++ + } + return keys, nil case utils.ResourceProfilesPrefix: keys := make([]string, len(tpr.resProfiles)) i := 0 @@ -2395,6 +2403,7 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]i // take IDs for each type dstIds, _ := tpr.GetLoadedIds(utils.DestinationPrefix) revDstIDs, _ := tpr.GetLoadedIds(utils.ReverseDestinationPrefix) + tmgIds, _ := tpr.GetLoadedIds(utils.TimingsPrefix) rplIds, _ := tpr.GetLoadedIds(utils.RatingPlanPrefix) rpfIds, _ := tpr.GetLoadedIds(utils.RatingProfilePrefix) actIds, _ := tpr.GetLoadedIds(utils.ActionPrefix) @@ -2419,6 +2428,7 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]i cacheArgs := map[string][]string{ utils.DestinationIDs: dstIds, utils.ReverseDestinationIDs: revDstIDs, + utils.TimingIDs: tmgIds, utils.RatingPlanIDs: rplIds, utils.RatingProfileIDs: rpfIds, utils.ActionIDs: actIds, diff --git a/engine/tpreader_test.go b/engine/tpreader_test.go index dccaef11a..a5f2201a6 100644 --- a/engine/tpreader_test.go +++ b/engine/tpreader_test.go @@ -965,6 +965,18 @@ func TestGetLoadedIdsDispatcherProfiles(t *testing.T) { } } +func TestGetLoadedIdsEmptyObject(t *testing.T) { + tpr := &TpReader{} + rcv, err := tpr.GetLoadedIds(utils.DispatcherProfilePrefix) + if err != nil { + t.Error(err) + } + expRcv := make([]string, 0) + if !reflect.DeepEqual(expRcv, rcv) { + t.Errorf("\nExpected %v but received \n%v", expRcv, rcv) + } +} + func TestGetLoadedIdsDispatcherHosts(t *testing.T) { tpr := &TpReader{ dispatcherHosts: map[utils.TenantID]*utils.TPDispatcherHost{ @@ -992,3 +1004,132 @@ func TestGetLoadedIdsError(t *testing.T) { t.Errorf("\nExpected error %v but received \n%v", errExpect, err) } } + +func TestReloadCache(t *testing.T) { + data := NewInternalDB(nil, nil, false) + cfg := config.NewDefaultCGRConfig() + argExpect := utils.AttrReloadCacheWithAPIOpts{ + APIOpts: map[string]interface{}{}, + Tenant: "", + ArgsCache: map[string][]string{ + "ActionIDs": {"ActionsID"}, + "ActionPlanIDs": {"ActionPlansID"}, + "ActionTriggerIDs": {"ActionTriggersID"}, + "DestinationIDs": {"DestinationsID"}, + "TimingIDs": {"TimingsID"}, + "RatingPlanIDs": {"RatingPlansID"}, + "RatingProfileIDs": {"RatingProfilesID"}, + "SharedGroupIDs": {"SharedGroupsID"}, + "ResourceProfileIDs": {"cgrates.org:resourceProfilesID"}, + "StatsQueueProfileIDs": {"cgrates.org:statProfilesID"}, + "ThresholdProfileIDs": {"cgrates.org:thresholdProfilesID"}, + "FilterIDs": {"cgrates.org:filtersID"}, + "RouteProfileIDs": {"cgrates.org:routeProfilesID"}, + "AttributeProfileIDs": {"cgrates.org:attributeProfilesID"}, + "ChargerProfileIDs": {"cgrates.org:chargerProfilesID"}, + "DispatcherProfileIDs": {"cgrates.org:dispatcherProfilesID"}, + "DispatcherHostIDs": {"cgrates.org:dispatcherHostsID"}, + "ResourceIDs": {"cgrates.org:resourcesID"}, + "StatsQueueIDs": {"cgrates.org:statQueuesID"}, + "ThresholdIDs": {"cgrates.org:thresholdsID"}, + "AccountActionPlanIDs": {"AccountActionPlansID"}, + }, + } + cM := &ccMock{ + calls: map[string]func(args interface{}, reply interface{}) error{ + utils.CacheSv1ReloadCache: func(args interface{}, reply interface{}) error { + if !reflect.DeepEqual(args, argExpect) { + t.Errorf("Expected %v \nbut received %v", utils.ToJSON(argExpect), utils.ToJSON(args)) + } + return nil + }, + utils.CacheSv1Clear: func(args interface{}, reply interface{}) error { + return nil + }, + }, + } + rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal <- cM + cnMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, + }) + tpr := &TpReader{ + actions: map[string][]*Action{ + "ActionsID": {}, + }, + actionPlans: map[string]*ActionPlan{ + "ActionPlansID": {}, + }, + actionsTriggers: map[string]ActionTriggers{ + "ActionTriggersID": {}, + }, + destinations: map[string]*Destination{ + "DestinationsID": {}, + }, + timings: map[string]*utils.TPTiming{ + "TimingsID": {}, + }, + ratingPlans: map[string]*RatingPlan{ + "RatingPlansID": {}, + }, + ratingProfiles: map[string]*RatingProfile{ + "RatingProfilesID": {}, + }, + sharedGroups: map[string]*SharedGroup{ + "SharedGroupsID": {}, + }, + resProfiles: map[utils.TenantID]*utils.TPResourceProfile{ + {Tenant: "cgrates.org", ID: "resourceProfilesID"}: {}, + }, + sqProfiles: map[utils.TenantID]*utils.TPStatProfile{ + {Tenant: "cgrates.org", ID: "statProfilesID"}: {}, + }, + thProfiles: map[utils.TenantID]*utils.TPThresholdProfile{ + {Tenant: "cgrates.org", ID: "thresholdProfilesID"}: {}, + }, + filters: map[utils.TenantID]*utils.TPFilterProfile{ + {Tenant: "cgrates.org", ID: "filtersID"}: {}, + }, + routeProfiles: map[utils.TenantID]*utils.TPRouteProfile{ + {Tenant: "cgrates.org", ID: "routeProfilesID"}: {}, + }, + attributeProfiles: map[utils.TenantID]*utils.TPAttributeProfile{ + {Tenant: "cgrates.org", ID: "attributeProfilesID"}: {}, + }, + chargerProfiles: map[utils.TenantID]*utils.TPChargerProfile{ + {Tenant: "cgrates.org", ID: "chargerProfilesID"}: {}, + }, + dispatcherProfiles: map[utils.TenantID]*utils.TPDispatcherProfile{ + {Tenant: "cgrates.org", ID: "dispatcherProfilesID"}: {}, + }, + dispatcherHosts: map[utils.TenantID]*utils.TPDispatcherHost{ + {Tenant: "cgrates.org", ID: "dispatcherHostsID"}: {}, + }, + resources: []*utils.TenantID{ + { + Tenant: "cgrates.org", + ID: "resourcesID", + }, + }, + statQueues: []*utils.TenantID{ + { + Tenant: "cgrates.org", + ID: "statQueuesID", + }, + }, + thresholds: []*utils.TenantID{ + { + Tenant: "cgrates.org", + ID: "thresholdsID", + }, + }, + acntActionPlans: map[string][]string{ + "AccountActionPlansID": {}, + }, + dm: NewDataManager(data, config.CgrConfig().CacheCfg(), cnMgr), + } + tpr.cacheConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)} + if err := tpr.ReloadCache(utils.MetaReload, false, make(map[string]interface{})); err != nil { + t.Error(err) + } +}