mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 10:36:24 +05:00
Removed scheduler
This commit is contained in:
committed by
Dan Christian Bogos
parent
48205d689d
commit
2cb978314e
@@ -176,7 +176,7 @@ func (apierSv1 *APIerSv1) LoadDestination(attrs *AttrLoadDestination, reply *str
|
||||
}
|
||||
dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
|
||||
attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone, apierSv1.Config.ApierCfg().CachesConns,
|
||||
apierSv1.Config.ApierCfg().ActionConns,
|
||||
apierSv1.Config.ApierCfg().ActionsConns,
|
||||
apierSv1.Config.DataDbCfg().Type == utils.INTERNAL)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -210,7 +210,7 @@ func (apierSv1 *APIerSv1) LoadTariffPlanFromStorDb(attrs *AttrLoadTpFromStorDb,
|
||||
}
|
||||
dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
|
||||
attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone,
|
||||
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionConns,
|
||||
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionsConns,
|
||||
apierSv1.Config.DataDbCfg().Type == utils.INTERNAL)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -235,7 +235,7 @@ func (apierSv1 *APIerSv1) LoadTariffPlanFromStorDb(attrs *AttrLoadTpFromStorDb,
|
||||
if err := dbReader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if len(apierSv1.Config.ApierCfg().ActionConns) != 0 {
|
||||
if len(apierSv1.Config.ApierCfg().ActionsConns) != 0 {
|
||||
utils.Logger.Info("APIerSv1.LoadTariffPlanFromStorDb, reloading scheduler.")
|
||||
if err := dbReader.ReloadScheduler(true); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -351,7 +351,7 @@ func (apierSv1 *APIerSv1) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFo
|
||||
loader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(),
|
||||
engine.NewFileCSVStorage(utils.CSVSep, attrs.FolderPath),
|
||||
"", apierSv1.Config.GeneralCfg().DefaultTimezone,
|
||||
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionConns,
|
||||
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionsConns,
|
||||
apierSv1.Config.DataDbCfg().Type == utils.INTERNAL)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -379,7 +379,7 @@ func (apierSv1 *APIerSv1) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFo
|
||||
if err := loader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if len(apierSv1.Config.ApierCfg().ActionConns) != 0 {
|
||||
if len(apierSv1.Config.ApierCfg().ActionsConns) != 0 {
|
||||
utils.Logger.Info("APIerSv1.LoadTariffPlanFromFolder, reloading scheduler.")
|
||||
if err := loader.ReloadScheduler(true); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -411,7 +411,7 @@ func (apierSv1 *APIerSv1) RemoveTPFromFolder(attrs *utils.AttrLoadTpFromFolder,
|
||||
// create the TpReader
|
||||
loader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(),
|
||||
engine.NewFileCSVStorage(utils.CSVSep, attrs.FolderPath), "", apierSv1.Config.GeneralCfg().DefaultTimezone,
|
||||
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionConns,
|
||||
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionsConns,
|
||||
apierSv1.Config.DataDbCfg().Type == utils.INTERNAL)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -439,7 +439,7 @@ func (apierSv1 *APIerSv1) RemoveTPFromFolder(attrs *utils.AttrLoadTpFromFolder,
|
||||
if err := loader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if len(apierSv1.Config.ApierCfg().ActionConns) != 0 {
|
||||
if len(apierSv1.Config.ApierCfg().ActionsConns) != 0 {
|
||||
utils.Logger.Info("APIerSv1.RemoveTPFromFolder, reloading scheduler.")
|
||||
if err := loader.ReloadScheduler(true); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -459,7 +459,7 @@ func (apierSv1 *APIerSv1) RemoveTPFromStorDB(attrs *AttrLoadTpFromStorDb, reply
|
||||
}
|
||||
dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
|
||||
attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone,
|
||||
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionConns,
|
||||
apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionsConns,
|
||||
apierSv1.Config.DataDbCfg().Type == utils.INTERNAL)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -485,7 +485,7 @@ func (apierSv1 *APIerSv1) RemoveTPFromStorDB(attrs *AttrLoadTpFromStorDb, reply
|
||||
if err := dbReader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if len(apierSv1.Config.ApierCfg().ActionConns) != 0 {
|
||||
if len(apierSv1.Config.ApierCfg().ActionsConns) != 0 {
|
||||
utils.Logger.Info("APIerSv1.RemoveTPFromStorDB, reloading scheduler.")
|
||||
if err := dbReader.ReloadScheduler(true); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
|
||||
@@ -58,7 +58,7 @@ func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolde
|
||||
}
|
||||
loader, err := engine.NewTpReader(apiv2.DataManager.DataDB(),
|
||||
engine.NewFileCSVStorage(utils.CSVSep, attrs.FolderPath), "", apiv2.Config.GeneralCfg().DefaultTimezone,
|
||||
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().ActionConns,
|
||||
apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().ActionsConns,
|
||||
apiv2.Config.DataDbCfg().Type == utils.INTERNAL)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
@@ -84,7 +84,7 @@ func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolde
|
||||
if err := loader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if len(apiv2.Config.ApierCfg().ActionConns) != 0 {
|
||||
if len(apiv2.Config.ApierCfg().ActionsConns) != 0 {
|
||||
utils.Logger.Info("APIerSv2.LoadTariffPlanFromFolder, reloading scheduler.")
|
||||
if err := loader.ReloadScheduler(true); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
type ApierCfg struct {
|
||||
Enabled bool
|
||||
CachesConns []string // connections towards Cache
|
||||
ActionConns []string // connections towards Scheduler
|
||||
ActionsConns []string // connections towards Scheduler
|
||||
AttributeSConns []string // connections towards AttributeS
|
||||
EEsConns []string // connections towards EEs
|
||||
}
|
||||
@@ -49,12 +49,11 @@ func (aCfg *ApierCfg) loadFromJSONCfg(jsnCfg *ApierJsonCfg) (err error) {
|
||||
}
|
||||
}
|
||||
if jsnCfg.Actions_conns != nil {
|
||||
aCfg.ActionConns = make([]string, len(*jsnCfg.Actions_conns))
|
||||
aCfg.ActionsConns = make([]string, len(*jsnCfg.Actions_conns))
|
||||
for idx, conn := range *jsnCfg.Actions_conns {
|
||||
// if we have the connection internal we change the name so we can have internal rpc for each subsystem
|
||||
aCfg.ActionConns[idx] = conn
|
||||
if conn == utils.MetaInternal {
|
||||
aCfg.ActionConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions)
|
||||
aCfg.ActionsConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,15 +95,15 @@ func (aCfg *ApierCfg) AsMapInterface() (initialMap map[string]interface{}) {
|
||||
}
|
||||
initialMap[utils.CachesConnsCfg] = cachesConns
|
||||
}
|
||||
if aCfg.ActionConns != nil {
|
||||
schedulerConns := make([]string, len(aCfg.ActionConns))
|
||||
for i, item := range aCfg.ActionConns {
|
||||
schedulerConns[i] = item
|
||||
if aCfg.ActionsConns != nil {
|
||||
actionsConns := make([]string, len(aCfg.ActionsConns))
|
||||
for i, item := range aCfg.ActionsConns {
|
||||
actionsConns[i] = item
|
||||
if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions) {
|
||||
schedulerConns[i] = utils.MetaInternal
|
||||
actionsConns[i] = utils.MetaInternal
|
||||
}
|
||||
}
|
||||
initialMap[utils.ActionSConnsCfg] = schedulerConns
|
||||
initialMap[utils.ActionSConnsCfg] = actionsConns
|
||||
}
|
||||
if aCfg.AttributeSConns != nil {
|
||||
attributeSConns := make([]string, len(aCfg.AttributeSConns))
|
||||
@@ -140,10 +139,10 @@ func (aCfg ApierCfg) Clone() (cln *ApierCfg) {
|
||||
cln.CachesConns[i] = k
|
||||
}
|
||||
}
|
||||
if aCfg.ActionConns != nil {
|
||||
cln.ActionConns = make([]string, len(aCfg.ActionConns))
|
||||
for i, k := range aCfg.ActionConns {
|
||||
cln.ActionConns[i] = k
|
||||
if aCfg.ActionsConns != nil {
|
||||
cln.ActionsConns = make([]string, len(aCfg.ActionsConns))
|
||||
for i, k := range aCfg.ActionsConns {
|
||||
cln.ActionsConns[i] = k
|
||||
}
|
||||
}
|
||||
if aCfg.AttributeSConns != nil {
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestApierCfgloadFromJsonCfg(t *testing.T) {
|
||||
expected := &ApierCfg{
|
||||
Enabled: false,
|
||||
CachesConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches), "*conn1"},
|
||||
SchedulerConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler), "*conn1"},
|
||||
ActionsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions), "*conn1"},
|
||||
AttributeSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes), "*conn1"},
|
||||
EEsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs), "*conn1"},
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func TestApierCfgAsMapInterface1(t *testing.T) {
|
||||
eMap := map[string]interface{}{
|
||||
utils.EnabledCfg: false,
|
||||
utils.CachesConnsCfg: sls,
|
||||
utils.ActionSConnsCfg: sls,
|
||||
utils.ActionsConnsCfg: sls,
|
||||
utils.AttributeSConnsCfg: sls,
|
||||
utils.EEsConnsCfg: sls,
|
||||
}
|
||||
@@ -75,13 +75,13 @@ func TestApierCfgAsMapInterface2(t *testing.T) {
|
||||
"attributes_conns": ["*internal:*attributes", "*conn1"],
|
||||
"ees_conns": ["*internal:*ees", "*conn1"],
|
||||
"caches_conns": ["*internal:*caches", "*conn1"],
|
||||
"scheduler_conns": ["*internal:*scheduler", "*conn1"],
|
||||
"actions_conns": ["*internal:*scheduler", "*conn1"],
|
||||
},
|
||||
}`
|
||||
expectedMap := map[string]interface{}{
|
||||
utils.EnabledCfg: true,
|
||||
utils.CachesConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.ActionSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.ActionsConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.AttributeSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.EEsConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func TestApierCfgClone(t *testing.T) {
|
||||
sa := &ApierCfg{
|
||||
Enabled: false,
|
||||
CachesConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches), "*conn1"},
|
||||
SchedulerConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler), "*conn1"},
|
||||
ActionsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions), "*conn1"},
|
||||
AttributeSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes), "*conn1"},
|
||||
EEsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs), "*conn1"},
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func TestApierCfgClone(t *testing.T) {
|
||||
if rcv.CachesConns[1] = ""; sa.CachesConns[1] != "*conn1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.SchedulerConns[1] = ""; sa.SchedulerConns[1] != "*conn1" {
|
||||
if rcv.ActionsConns[1] = ""; sa.ActionsConns[1] != "*conn1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.AttributeSConns[1] = ""; sa.AttributeSConns[1] != "*conn1" {
|
||||
|
||||
@@ -133,6 +133,7 @@ func TestCacheParamCfgloadFromJsonCfg2(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestAddTmpCaches(t *testing.T) {
|
||||
cfgJSON := &CacheJsonCfg{
|
||||
Partitions: &map[string]*CacheParamJsonCfg{
|
||||
@@ -156,6 +157,8 @@ func TestAddTmpCaches(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func TestCachesCfgAsMapInterface1(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
"caches":{
|
||||
|
||||
@@ -34,7 +34,7 @@ type CdrsCfg struct {
|
||||
ThresholdSConns []string
|
||||
StatSConns []string
|
||||
OnlineCDRExports []string // list of CDRE templates to use for real-time CDR exports
|
||||
ActionSConns []string
|
||||
ActionsConns []string
|
||||
EEsConns []string
|
||||
}
|
||||
|
||||
@@ -111,12 +111,12 @@ func (cdrscfg *CdrsCfg) loadFromJSONCfg(jsnCdrsCfg *CdrsJsonCfg) (err error) {
|
||||
cdrscfg.OnlineCDRExports = append(cdrscfg.OnlineCDRExports, *jsnCdrsCfg.Online_cdr_exports...)
|
||||
}
|
||||
if jsnCdrsCfg.Actions_conns != nil {
|
||||
cdrscfg.ActionSConns = make([]string, len(*jsnCdrsCfg.Actions_conns))
|
||||
cdrscfg.ActionsConns = make([]string, len(*jsnCdrsCfg.Actions_conns))
|
||||
for idx, connID := range *jsnCdrsCfg.Actions_conns {
|
||||
// if we have the connection internal we change the name so we can have internal rpc for each subsystem
|
||||
cdrscfg.ActionSConns[idx] = connID
|
||||
cdrscfg.ActionsConns[idx] = connID
|
||||
if connID == utils.MetaInternal {
|
||||
cdrscfg.ActionSConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions)
|
||||
cdrscfg.ActionsConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,15 +204,15 @@ func (cdrscfg *CdrsCfg) AsMapInterface() (initialMP map[string]interface{}) {
|
||||
}
|
||||
initialMP[utils.StatSConnsCfg] = statSConns
|
||||
}
|
||||
if cdrscfg.ActionSConns != nil {
|
||||
schedulerConns := make([]string, len(cdrscfg.ActionSConns))
|
||||
for i, item := range cdrscfg.ActionSConns {
|
||||
schedulerConns[i] = item
|
||||
if cdrscfg.ActionsConns != nil {
|
||||
actionsConns := make([]string, len(cdrscfg.ActionsConns))
|
||||
for i, item := range cdrscfg.ActionsConns {
|
||||
actionsConns[i] = item
|
||||
if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions) {
|
||||
schedulerConns[i] = utils.MetaInternal
|
||||
actionsConns[i] = utils.MetaInternal
|
||||
}
|
||||
}
|
||||
initialMP[utils.ActionSConnsCfg] = schedulerConns
|
||||
initialMP[utils.ActionSConnsCfg] = actionsConns
|
||||
}
|
||||
if cdrscfg.EEsConns != nil {
|
||||
eesConns := make([]string, len(cdrscfg.EEsConns))
|
||||
@@ -271,10 +271,10 @@ func (cdrscfg CdrsCfg) Clone() (cln *CdrsCfg) {
|
||||
cln.OnlineCDRExports[i] = con
|
||||
}
|
||||
}
|
||||
if cdrscfg.ActionSConns != nil {
|
||||
cln.ActionSConns = make([]string, len(cdrscfg.ActionSConns))
|
||||
for i, con := range cdrscfg.ActionSConns {
|
||||
cln.ActionSConns[i] = con
|
||||
if cdrscfg.ActionsConns != nil {
|
||||
cln.ActionsConns = make([]string, len(cdrscfg.ActionsConns))
|
||||
for i, con := range cdrscfg.ActionsConns {
|
||||
cln.ActionsConns[i] = con
|
||||
}
|
||||
}
|
||||
if cdrscfg.EEsConns != nil {
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestCdrsCfgloadFromJsonCfg(t *testing.T) {
|
||||
ThresholdSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds), "*conn1"},
|
||||
StatSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats), "*conn1"},
|
||||
OnlineCDRExports: []string{"randomVal"},
|
||||
ActionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler), "*conn1"},
|
||||
ActionsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions), "*conn1"},
|
||||
EEsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs), "*conn1"},
|
||||
ExtraFields: RSRParsers{},
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func TestCdrsCfgAsMapInterface(t *testing.T) {
|
||||
"thresholds_conns": ["*internal:*thresholds","*conn1"],
|
||||
"stats_conns": ["*internal:*stats","*conn1"],
|
||||
"online_cdr_exports":["http_localhost", "amqp_localhost", "http_test_file"],
|
||||
"scheduler_conns": ["*internal:*scheduler","*conn1"],
|
||||
"actions_conns": ["*internal:*scheduler","*conn1"],
|
||||
"ees_conns": ["*internal:*ees","*conn1"],
|
||||
},
|
||||
}`
|
||||
|
||||
@@ -149,15 +149,7 @@ const CGRATES_CFG_JSON = `
|
||||
"*cdrs": {"remote":false, "replicate":false},
|
||||
"*tp_timings":{"remote":false, "replicate":false},
|
||||
"*tp_destinations": {"remote":false, "replicate":false},
|
||||
"*tp_rates": {"remote":false, "replicate":false},
|
||||
"*tp_destination_rates": {"remote":false, "replicate":false},
|
||||
"*tp_rating_plans":{"remote":false, "replicate":false},
|
||||
"*tp_rating_profiles":{"remote":false, "replicate":false},
|
||||
"*tp_shared_groups": {"remote":false, "replicate":false},
|
||||
"*tp_actions":{"remote":false, "replicate":false},
|
||||
"*tp_action_plans":{"remote":false, "replicate":false},
|
||||
"*tp_action_triggers":{"remote":false, "replicate":false},
|
||||
"*tp_account_actions": {"remote":false, "replicate":false},
|
||||
"*tp_actions":{"remote":false, "replicate":false},
|
||||
"*tp_resources":{"remote":false, "replicate":false},
|
||||
"*tp_stats":{"remote":false, "replicate":false},
|
||||
"*tp_thresholds": {"remote":false, "replicate":false},
|
||||
@@ -228,13 +220,7 @@ const CGRATES_CFG_JSON = `
|
||||
"partitions": {
|
||||
"*destinations": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // destination caching
|
||||
"*reverse_destinations": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // reverse destinations index caching
|
||||
"*rating_plans": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // rating plans caching
|
||||
"*rating_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // rating profiles caching
|
||||
"*actions": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // actions caching
|
||||
"*action_plans": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // action plans caching
|
||||
"*account_action_plans": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // account action plans index caching
|
||||
"*action_triggers": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // action triggers caching
|
||||
"*shared_groups": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // shared groups caching
|
||||
"*timings": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // timings caching
|
||||
"*resource_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // control resource profiles caching
|
||||
"*resources": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false, "replicate": false}, // control resources caching
|
||||
@@ -282,21 +268,13 @@ const CGRATES_CFG_JSON = `
|
||||
|
||||
// only for *internal database
|
||||
"*versions": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false}, // for version storing
|
||||
"*accounts": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false}, // for account storing
|
||||
// internal storDB tabels
|
||||
"*session_costs": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*cdrs": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_timings":{"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_destinations": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_rates": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_destination_rates": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_rating_plans":{"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_rating_profiles":{"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_shared_groups": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_actions":{"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_action_plans":{"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_action_triggers":{"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_account_actions": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
|
||||
"*tp_resources":{"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_stats":{"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
"*tp_thresholds": {"limit": -1, "ttl": "", "static_ttl": false, "replicate": false},
|
||||
@@ -986,7 +964,7 @@ const CGRATES_CFG_JSON = `
|
||||
"apiers": {
|
||||
"enabled": false,
|
||||
"caches_conns":["*internal"],
|
||||
"scheduler_conns": [], // connections to SchedulerS for reloads
|
||||
"actions_conns": [], // connections to ActionS for reloads
|
||||
"attributes_conns": [], // connections to AttributeS for CDRExporter
|
||||
"ees_conns": [], // connections to EEs
|
||||
},
|
||||
|
||||
@@ -91,27 +91,9 @@ func TestCacheJsonCfg(t *testing.T) {
|
||||
utils.CacheReverseDestinations: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheRatingPlans: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheRatingProfiles: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheActions: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheActionPlans: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheAccountActionPlans: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheActionTriggers: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheSharedGroups: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTimings: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Precache: utils.BoolPointer(false), Replicate: utils.BoolPointer(false)},
|
||||
@@ -243,9 +225,6 @@ func TestCacheJsonCfg(t *testing.T) {
|
||||
utils.CacheVersions: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheAccounts: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
|
||||
utils.CacheTBLTPTimings: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
@@ -253,33 +232,9 @@ func TestCacheJsonCfg(t *testing.T) {
|
||||
utils.CacheTBLTPDestinations: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPRates: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPDestinationRates: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPRatingPlans: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPRatingProfiles: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPSharedGroups: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPActions: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPActionPlans: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPActionTriggers: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPAccountActions: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
utils.CacheTBLTPResources: {Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
Replicate: utils.BoolPointer(false)},
|
||||
@@ -540,38 +495,10 @@ func TestDfStorDBJsonCfg(t *testing.T) {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPRates: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPDestinationRates: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPRatingPlans: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPRatingProfiles: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPSharedGroups: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPActions: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPActionTriggers: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPAccountActions: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPResources: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
@@ -592,10 +519,6 @@ func TestDfStorDBJsonCfg(t *testing.T) {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPActionPlans: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
},
|
||||
utils.CacheTBLTPRoutes: {
|
||||
Replicate: utils.BoolPointer(false),
|
||||
Remote: utils.BoolPointer(false),
|
||||
@@ -682,25 +605,6 @@ func TestDfRalsJsonCfg(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDfSchedulerJsonCfg(t *testing.T) {
|
||||
eCfg := &SchedulerJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Cdrs_conns: &[]string{},
|
||||
Thresholds_conns: &[]string{},
|
||||
Stats_conns: &[]string{},
|
||||
Filters: &[]string{},
|
||||
}
|
||||
dfCgrJSONCfg, err := NewCgrJsonCfgFromBytes([]byte(CGRATES_CFG_JSON))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if cfg, err := dfCgrJSONCfg.SchedulerJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eCfg, cfg) {
|
||||
t.Errorf("Expected: %s ,received: %s", utils.ToJSON(eCfg), utils.ToJSON(cfg))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDfCdrsJsonCfg(t *testing.T) {
|
||||
eCfg := &CdrsJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
@@ -762,7 +666,7 @@ func TestSmgJsonCfg(t *testing.T) {
|
||||
Privatekey_path: utils.StringPointer(""),
|
||||
Publickey_path: utils.StringPointer(""),
|
||||
},
|
||||
Scheduler_conns: &[]string{},
|
||||
Actions_conns: &[]string{},
|
||||
}
|
||||
dfCgrJSONCfg, err := NewCgrJsonCfgFromBytes([]byte(CGRATES_CFG_JSON))
|
||||
if err != nil {
|
||||
|
||||
@@ -651,7 +651,7 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.APIerSv1, connID)
|
||||
}
|
||||
}
|
||||
for _, connID := range cfg.apier.ActionConns {
|
||||
for _, connID := range cfg.apier.ActionsConns {
|
||||
if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.actionSCfg.Enabled {
|
||||
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.SchedulerS, utils.APIerSv1)
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ type SessionSJsonCfg struct {
|
||||
Terminate_attempts *int
|
||||
Alterable_fields *[]string
|
||||
Min_dur_low_balance *string
|
||||
Scheduler_conns *[]string
|
||||
Actions_conns *[]string
|
||||
Stir *STIRJsonCfg
|
||||
Default_usage *map[string]string
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ func TestLoaderCgrCfgloadFromJsonCfg(t *testing.T) {
|
||||
Disable_reverse: utils.BoolPointer(true),
|
||||
Field_separator: utils.StringPointer(";"),
|
||||
Caches_conns: &[]string{utils.MetaInternal},
|
||||
Actions_conns: &[]string{utils.MetaInternal},
|
||||
Gapi_credentials: &json.RawMessage{12, 13, 60},
|
||||
Gapi_token: &json.RawMessage{13, 16},
|
||||
}
|
||||
@@ -62,7 +61,7 @@ func TestLoaderCgrCfgAsMapInterface(t *testing.T) {
|
||||
"disable_reverse": false,
|
||||
"field_separator": ",",
|
||||
"caches_conns":["*internal","*localhost"],
|
||||
"scheduler_conns": ["*internal","*localhost"],
|
||||
"actions_conns": ["*internal","*localhost"],
|
||||
"gapi_credentials": ".gapi/credentials.json",
|
||||
"gapi_token": ".gapi/token.json"
|
||||
},
|
||||
|
||||
@@ -112,7 +112,7 @@ type SessionSCfg struct {
|
||||
TerminateAttempts int
|
||||
AlterableFields utils.StringSet
|
||||
MinDurLowBalance time.Duration
|
||||
SchedulerConns []string
|
||||
ActionsConns []string
|
||||
STIRCfg *STIRcfg
|
||||
DefaultUsage map[string]time.Duration
|
||||
}
|
||||
@@ -289,13 +289,13 @@ func (scfg *SessionSCfg) loadFromJSONCfg(jsnCfg *SessionSJsonCfg) (err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if jsnCfg.Scheduler_conns != nil {
|
||||
scfg.SchedulerConns = make([]string, len(*jsnCfg.Scheduler_conns))
|
||||
for idx, connID := range *jsnCfg.Scheduler_conns {
|
||||
if jsnCfg.Actions_conns != nil {
|
||||
scfg.ActionsConns = make([]string, len(*jsnCfg.Actions_conns))
|
||||
for idx, connID := range *jsnCfg.Actions_conns {
|
||||
// if we have the connection internal we change the name so we can have internal rpc for each subsystem
|
||||
scfg.SchedulerConns[idx] = connID
|
||||
scfg.ActionsConns[idx] = connID
|
||||
if connID == utils.MetaInternal {
|
||||
scfg.SchedulerConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions)
|
||||
scfg.ActionsConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -440,15 +440,15 @@ func (scfg *SessionSCfg) AsMapInterface() (initialMP map[string]interface{}) {
|
||||
}
|
||||
initialMP[utils.CDRsConnsCfg] = CDRsConns
|
||||
}
|
||||
if scfg.SchedulerConns != nil {
|
||||
schedulerConns := make([]string, len(scfg.SchedulerConns))
|
||||
for i, item := range scfg.SchedulerConns {
|
||||
schedulerConns[i] = item
|
||||
if scfg.ActionsConns != nil {
|
||||
actionConns := make([]string, len(scfg.ActionsConns))
|
||||
for i, item := range scfg.ActionsConns {
|
||||
actionConns[i] = item
|
||||
if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions) {
|
||||
schedulerConns[i] = utils.MetaInternal
|
||||
actionConns[i] = utils.MetaInternal
|
||||
}
|
||||
}
|
||||
initialMP[utils.ActionSConnsCfg] = schedulerConns
|
||||
initialMP[utils.ActionSConnsCfg] = actionConns
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -541,10 +541,10 @@ func (scfg SessionSCfg) Clone() (cln *SessionSCfg) {
|
||||
cln.ReplicationConns[i] = con
|
||||
}
|
||||
}
|
||||
if scfg.SchedulerConns != nil {
|
||||
cln.SchedulerConns = make([]string, len(scfg.SchedulerConns))
|
||||
for i, con := range scfg.SchedulerConns {
|
||||
cln.SchedulerConns[i] = con
|
||||
if scfg.ActionsConns != nil {
|
||||
cln.ActionsConns = make([]string, len(scfg.ActionsConns))
|
||||
for i, con := range scfg.ActionsConns {
|
||||
cln.ActionsConns[i] = con
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestSessionSCfgloadFromJsonCfgCase1(t *testing.T) {
|
||||
Terminate_attempts: utils.IntPointer(6),
|
||||
Alterable_fields: &[]string{},
|
||||
Min_dur_low_balance: utils.StringPointer("1"),
|
||||
Scheduler_conns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
Actions_conns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
Stir: &STIRJsonCfg{
|
||||
Allowed_attest: &[]string{utils.MetaAny},
|
||||
Payload_maxduration: utils.StringPointer("-1"),
|
||||
@@ -114,7 +114,7 @@ func TestSessionSCfgloadFromJsonCfgCase1(t *testing.T) {
|
||||
TerminateAttempts: 6,
|
||||
AlterableFields: utils.StringSet{},
|
||||
MinDurLowBalance: 1,
|
||||
SchedulerConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler), "*conn1"},
|
||||
ActionsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions), "*conn1"},
|
||||
STIRCfg: &STIRcfg{
|
||||
AllowedAttest: utils.StringSet{utils.MetaAny: {}},
|
||||
PayloadMaxduration: -1,
|
||||
@@ -252,7 +252,7 @@ func TestSessionSCfgloadFromJsonCfgCase10(t *testing.T) {
|
||||
TerminateAttempts: 5,
|
||||
AlterableFields: utils.StringSet{},
|
||||
MinDurLowBalance: 0,
|
||||
SchedulerConns: []string{},
|
||||
ActionsConns: []string{},
|
||||
STIRCfg: &STIRcfg{
|
||||
AllowedAttest: utils.StringSet{utils.MetaAny: {}},
|
||||
PayloadMaxduration: -1,
|
||||
@@ -415,7 +415,7 @@ func TestSessionSCfgAsMapInterfaceCase2(t *testing.T) {
|
||||
"publickey_path": "",
|
||||
"privatekey_path": "",
|
||||
},
|
||||
"scheduler_conns": ["*internal:*scheduler", "*conn1"],
|
||||
"actions_conns": ["*internal:*actions", "*conn1"],
|
||||
},
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
@@ -896,7 +896,7 @@ func TestSessionSCfgClone(t *testing.T) {
|
||||
TerminateAttempts: 6,
|
||||
AlterableFields: utils.StringSet{},
|
||||
MinDurLowBalance: 1,
|
||||
SchedulerConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler), "*conn1"},
|
||||
ActionsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions), "*conn1"},
|
||||
SessionTTLMaxDelay: utils.DurationPointer(time.Second),
|
||||
SessionTTLLastUsed: utils.DurationPointer(time.Second),
|
||||
SessionTTLUsage: utils.DurationPointer(time.Second),
|
||||
|
||||
@@ -1,470 +0,0 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package engine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var rsponder = &Responder{MaxComputedUsage: config.CgrConfig().RalsCfg().MaxComputedUsage}
|
||||
|
||||
func TestResponderGobSMCost(t *testing.T) {
|
||||
cc := &CallCost{
|
||||
Category: "generic",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "1001",
|
||||
Account: "1001",
|
||||
Destination: "data",
|
||||
ToR: "*data",
|
||||
Cost: 0,
|
||||
Timespans: TimeSpans{&TimeSpan{
|
||||
TimeStart: time.Date(2016, 1, 5, 12, 30, 10, 0, time.UTC),
|
||||
TimeEnd: time.Date(2016, 1, 5, 12, 55, 46, 0, time.UTC),
|
||||
Cost: 0,
|
||||
RateInterval: &RateInterval{
|
||||
Timing: nil,
|
||||
Rating: &RIRate{
|
||||
ConnectFee: 0,
|
||||
RoundingMethod: "",
|
||||
RoundingDecimals: 0,
|
||||
MaxCost: 0,
|
||||
MaxCostStrategy: "",
|
||||
Rates: RateGroups{&RGRate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 0,
|
||||
RateIncrement: time.Second,
|
||||
RateUnit: time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
Weight: 0,
|
||||
},
|
||||
DurationIndex: 0,
|
||||
Increments: Increments{&Increment{
|
||||
Duration: time.Second,
|
||||
Cost: 0,
|
||||
BalanceInfo: &DebitInfo{
|
||||
Unit: &UnitInfo{
|
||||
UUID: "fa0aa280-2b76-4b5b-bb06-174f84b8c321",
|
||||
ID: "",
|
||||
Value: 100864,
|
||||
DestinationID: "data",
|
||||
Consumed: 1,
|
||||
ToR: "*data",
|
||||
RateInterval: nil,
|
||||
},
|
||||
Monetary: nil,
|
||||
AccountID: "cgrates.org:1001",
|
||||
},
|
||||
CompressFactor: 1536,
|
||||
},
|
||||
},
|
||||
RoundIncrement: nil,
|
||||
MatchedSubject: "fa0aa280-2b76-4b5b-bb06-174f84b8c321",
|
||||
MatchedPrefix: "data",
|
||||
MatchedDestId: "*any",
|
||||
RatingPlanId: "*none",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
RatedUsage: 1536,
|
||||
}
|
||||
attr := AttrCDRSStoreSMCost{
|
||||
Cost: &SMCost{
|
||||
CGRID: "b783a8bcaa356570436983cd8a0e6de4993f9ba6",
|
||||
RunID: utils.MetaDefault,
|
||||
OriginHost: "",
|
||||
OriginID: "testdatagrp_grp1",
|
||||
CostSource: "SMR",
|
||||
Usage: 1536,
|
||||
CostDetails: NewEventCostFromCallCost(cc, "b783a8bcaa356570436983cd8a0e6de4993f9ba6", utils.MetaDefault),
|
||||
},
|
||||
CheckDuplicate: false,
|
||||
}
|
||||
|
||||
var network bytes.Buffer // Stand-in for a network connection
|
||||
enc := gob.NewEncoder(&network) // Will write to network.
|
||||
dec := gob.NewDecoder(&network) // Will read from network.
|
||||
err := enc.Encode(attr)
|
||||
if err != nil {
|
||||
t.Error("encode error: ", err)
|
||||
}
|
||||
|
||||
// Decode (receive) and print the values.
|
||||
var q AttrCDRSStoreSMCost
|
||||
err = dec.Decode(&q)
|
||||
if err != nil {
|
||||
t.Error("decode error: ", err)
|
||||
}
|
||||
q.Cost.CostDetails.initCache()
|
||||
if !reflect.DeepEqual(attr, q) {
|
||||
t.Error("wrong transmission")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderUsageAllow(t *testing.T) {
|
||||
rsp := &Responder{
|
||||
MaxComputedUsage: map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
},
|
||||
}
|
||||
if allow := rsp.usageAllowed(utils.MetaVoice, 17*time.Second); !allow {
|
||||
t.Errorf("Expected true, received : %+v", allow)
|
||||
}
|
||||
if allow := rsp.usageAllowed(utils.MetaVoice, 22*time.Second); allow {
|
||||
t.Errorf("Expected false, received : %+v", allow)
|
||||
}
|
||||
if allow := rsp.usageAllowed(utils.MetaData, 7*time.Second); !allow {
|
||||
t.Errorf("Expected true, received : %+v", allow)
|
||||
}
|
||||
if allow := rsp.usageAllowed(utils.MetaData, 12*time.Second); allow {
|
||||
t.Errorf("Expected false, received : %+v", allow)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderGetCostMaxUsageANY(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:11Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaAny,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var cc CallCost
|
||||
if err := rsponder.GetCost(cd, &cc); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderGetCostMaxUsageVOICE(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:21Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaVoice,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var cc CallCost
|
||||
if err := rsponder.GetCost(cd, &cc); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderDebitMaxUsageANY(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:11Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaAny,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var cc CallCost
|
||||
if err := rsponder.Debit(cd, &cc); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderDebitMaxUsageVOICE(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:21Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaVoice,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var cc CallCost
|
||||
if err := rsponder.Debit(cd, &cc); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderMaxDebitMaxUsageANY(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:11Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaAny,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var cc CallCost
|
||||
if err := rsponder.MaxDebit(cd, &cc); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderMaxDebitMaxUsageVOICE(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:21Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaVoice,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var cc CallCost
|
||||
if err := rsponder.MaxDebit(cd, &cc); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderRefundIncrementsMaxUsageANY(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:11Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaAny,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var acc Account
|
||||
if err := rsponder.RefundIncrements(cd, &acc); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderRefundIncrementsMaxUsageVOICE(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:21Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaVoice,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var acc Account
|
||||
if err := rsponder.RefundIncrements(cd, &acc); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderRefundRoundingMaxUsageANY(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:11Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaAny,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var reply float64
|
||||
if err := rsponder.RefundRounding(cd, &reply); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderRefundRoundingMaxUsageVOICE(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:21Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaVoice,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var reply float64
|
||||
if err := rsponder.RefundRounding(cd, &reply); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderGetMaxSessionTimeMaxUsageANY(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:11Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaAny,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var reply time.Duration
|
||||
if err := rsponder.GetMaxSessionTime(cd, &reply); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderGetMaxSessionTimeMaxUsageVOICE(t *testing.T) {
|
||||
rsponder.MaxComputedUsage = map[string]time.Duration{
|
||||
utils.MetaAny: 10 * time.Second,
|
||||
utils.MetaVoice: 20 * time.Second,
|
||||
}
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", "")
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:21Z", "")
|
||||
cd := &CallDescriptorWithAPIOpts{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "dan",
|
||||
ToR: utils.MetaVoice,
|
||||
Account: "dan",
|
||||
Destination: "+4917621621391",
|
||||
DurationIndex: 9,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
var reply time.Duration
|
||||
if err := rsponder.GetMaxSessionTime(cd, &reply); err == nil ||
|
||||
err.Error() != utils.ErrMaxUsageExceeded.Error() {
|
||||
t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user