diff --git a/config/configsanity_test.go b/config/configsanity_test.go index 195de929b..bb59a3115 100644 --- a/config/configsanity_test.go +++ b/config/configsanity_test.go @@ -688,3 +688,80 @@ func TestConfigSanityStorDB(t *testing.T) { t.Errorf("Expecting: %+q received: %+q", expected, err) } } + +func TestConfigSanityDataDB(t *testing.T) { + cfg, _ = NewDefaultCGRConfig() + cfg.dataDbCfg.DataDbType = utils.INTERNAL + cfg.cacheCfg = CacheCfg{ + utils.CacheDiameterMessages: &CacheParamCfg{ + Limit: 0, + }, + } + expected := " *diameter_messages needs to be != 0 when DataBD is *internal, found 0." + if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { + t.Errorf("Expecting: %+q received: %+q", expected, err) + } + + cfg.cacheCfg = CacheCfg{ + utils.CacheDiameterMessages: &CacheParamCfg{ + Limit: 1, + }, + } + if err := cfg.checkConfigSanity(); err != nil { + t.Errorf("Expecting: nil received: %+q", err) + } + + cfg.cacheCfg = CacheCfg{ + "test": &CacheParamCfg{ + Limit: 1, + }, + } + expected = " test needs to be 0 when DataBD is *internal, received : 1" + if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { + t.Errorf("Expecting: %+q received: %+q", expected, err) + } + cfg.cacheCfg["test"].Limit = 0 + + cfg.resourceSCfg.Enabled = true + expected = " StoreInterval needs to be -1 when DataBD is *internal, received : 0" + if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { + t.Errorf("Expecting: %+q received: %+q", expected, err) + } + cfg.resourceSCfg.Enabled = false + + cfg.statsCfg.Enabled = true + expected = " StoreInterval needs to be -1 when DataBD is *internal, received : 0" + if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { + t.Errorf("Expecting: %+q received: %+q", expected, err) + } + cfg.statsCfg.Enabled = false + + cfg.thresholdSCfg.Enabled = true + expected = " StoreInterval needs to be -1 when DataBD is *internal, received : 0" + if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { + t.Errorf("Expecting: %+q received: %+q", expected, err) + } + cfg.thresholdSCfg.Enabled = false + + cfg.dataDbCfg.Items = map[string]*ItemRmtRplOpt{ + "test1": &ItemRmtRplOpt{ + Remote: true, + }, + } + expected = "Remote connections required by: " + if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { + t.Errorf("Expecting: %+q received: %+q", expected, err) + } + + cfg.dataDbCfg.Items = map[string]*ItemRmtRplOpt{ + "test2": &ItemRmtRplOpt{ + Remote: false, + Replicate: true, + }, + } + expected = "Replicate connections required by: " + if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { + t.Errorf("Expecting: %+q received: %+q", expected, err) + } + +} diff --git a/engine/action_plan.go b/engine/action_plan.go index 51d7efca3..3da3b2f2b 100644 --- a/engine/action_plan.go +++ b/engine/action_plan.go @@ -80,14 +80,36 @@ func (apl *ActionPlan) RemoveAccountID(accID string) (found bool) { return } +// Clone clones *ActionPlan func (apl *ActionPlan) Clone() (interface{}, error) { - cln := new(ActionPlan) - if err := utils.Clone(*apl, cln); err != nil { - return nil, err + cln := &ActionPlan{ + Id: apl.Id, + AccountIDs: apl.AccountIDs.Clone(), + } + if apl.ActionTimings != nil { + cln.ActionTimings = make([]*ActionTiming, len(apl.ActionTimings)) + for i, act := range apl.ActionTimings { + cln.ActionTimings[i] = act.Clone() + } } return cln, nil } +// Clone clones ActionTiming +func (at *ActionTiming) Clone() (cln *ActionTiming) { + if at == nil { + return + } + cln = &ActionTiming{ + Uuid: at.Uuid, + ActionsID: at.ActionsID, + Weight: at.Weight, + ExtraData: at.ExtraData, + Timing: at.Timing.Clone(), + } + return +} + func (at *ActionTiming) GetNextStartTime(now time.Time) (t time.Time) { if !at.stCache.IsZero() { return at.stCache diff --git a/engine/action_plan_test.go b/engine/action_plan_test.go index cec5bcb4f..abb451685 100644 --- a/engine/action_plan_test.go +++ b/engine/action_plan_test.go @@ -91,7 +91,16 @@ func TestActionPlanClone(t *testing.T) { at1 := &ActionPlan{ Id: "test", AccountIDs: utils.StringMap{"one": true, "two": true, "three": true}, - //ActionTimings: []*ActionTiming{}, + ActionTimings: []*ActionTiming{ + &ActionTiming{ + Uuid: "Uuid_test1", + ActionsID: "ActionsID_test1", + Weight: 0.8, + Timing: &RateInterval{ + Weight: 0.7, + }, + }, + }, } clned, err := at1.Clone() if err != nil { @@ -99,7 +108,7 @@ func TestActionPlanClone(t *testing.T) { } at1Cloned := clned.(*ActionPlan) if !reflect.DeepEqual(at1, at1Cloned) { - t.Errorf("Expecting: %+v, received: %+v", at1, at1Cloned) + t.Errorf("\nExpecting: %+v,\n received: %+v", at1, at1Cloned) } } func TestActionTimindSetActions(t *testing.T) { diff --git a/engine/rateinterval.go b/engine/rateinterval.go index 49d85fc02..b9bc3f8de 100644 --- a/engine/rateinterval.go +++ b/engine/rateinterval.go @@ -425,3 +425,48 @@ func (il *RateIntervalTimeSorter) Sort() []*RateInterval { sort.Sort(il) return il.ris } + +// Clone clones RateInterval +func (i *RateInterval) Clone() (cln *RateInterval) { + if i == nil { + return + } + cln = &RateInterval{ + Timing: i.Timing.Clone(), + Rating: i.Rating.Clone(), + Weight: i.Weight, + } + return +} + +// Clone clones RITiming +func (rit *RITiming) Clone() (cln *RITiming) { + if rit == nil { + return + } + cln = &RITiming{ + Years: rit.Years, + Months: rit.Months, + MonthDays: rit.MonthDays, + WeekDays: rit.WeekDays, + StartTime: rit.StartTime, + EndTime: rit.EndTime, + } + return +} + +// Clone clones RIRate +func (rit *RIRate) Clone() (cln *RIRate) { + if rit == nil { + return + } + cln = &RIRate{ + ConnectFee: rit.ConnectFee, + RoundingMethod: rit.RoundingMethod, + RoundingDecimals: rit.RoundingDecimals, + MaxCost: rit.MaxCost, + MaxCostStrategy: rit.MaxCostStrategy, + Rates: rit.Rates, + } + return cln +}