From c3cea2d52dcbb71c5918c784b482b54b45903d06 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 27 Apr 2020 16:19:15 +0300 Subject: [PATCH] Updated *gob integration tests --- agents/diam_it_test.go | 2 +- apier/v1/accounts_it_test.go | 3 - apier/v1/chargers_it_test.go | 32 +++--- apier/v1/config_it_test.go | 8 +- apier/v1/filter_indexes_it_test.go | 4 +- apier/v1/filterindexecache_it_test.go | 6 +- apier/v1/remote_it_test.go | 5 +- apier/v1/replicate_it_test.go | 12 ++- apier/v1/stats.go | 7 +- apier/v1/stats_it_test.go | 10 +- config/datadbcfg.go | 1 - config/datadbcfg_test.go | 1 + config/ralscfg.go | 2 - config/ralscfg_test.go | 2 + config/stordbcfg.go | 1 - config/stordbcfg_test.go | 1 + console/statqueue_set.go | 7 +- .../samples/radagent_mysql_gob/cgrates.json | 100 ------------------ engine/actions_it_test.go | 22 ++-- engine/libstats.go | 5 + general_tests/cacherpl_it_test.go | 74 +++++++------ general_tests/cdrs_it_test.go | 12 +-- general_tests/cdrs_processevent_it_test.go | 31 ++++-- general_tests/doubleremove_it_test.go | 2 +- general_tests/export_it_test.go | 14 ++- gob_integration_test.sh | 12 +-- sessions/sessions_data_it_test.go | 19 ++-- sessions/sessions_it_test.go | 3 - sessions/sessions_voice_it_test.go | 3 - 29 files changed, 172 insertions(+), 229 deletions(-) diff --git a/agents/diam_it_test.go b/agents/diam_it_test.go index c6a929d07..59cd4b789 100644 --- a/agents/diam_it_test.go +++ b/agents/diam_it_test.go @@ -1193,7 +1193,7 @@ func testDiamItRAR(t *testing.T) { wait.Add(1) go func() { var reply string - if err := apierRpc.Call(utils.SessionSv1ReAuthorize, nil, &reply); err != nil { + if err := apierRpc.Call(utils.SessionSv1ReAuthorize, &utils.SessionFilter{}, &reply); err != nil { t.Error(err) } wait.Done() diff --git a/apier/v1/accounts_it_test.go b/apier/v1/accounts_it_test.go index e0f78b775..4d88f3286 100644 --- a/apier/v1/accounts_it_test.go +++ b/apier/v1/accounts_it_test.go @@ -78,9 +78,6 @@ func TestAccITWithRemove(t *testing.T) { default: t.Fatal("Unknown Database type") } - if *encoding == utils.MetaGOB { - accTestsConfig += "_gob" - } accCfgPath = path.Join(*dataDir, "conf", "samples", accTestsConfig) for _, stest := range accTests { diff --git a/apier/v1/chargers_it_test.go b/apier/v1/chargers_it_test.go index 3eb6359b9..fc4855c05 100755 --- a/apier/v1/chargers_it_test.go +++ b/apier/v1/chargers_it_test.go @@ -39,23 +39,27 @@ var ( chargerProfile *ChargerWithCache chargerConfigDIR string //run tests for specific configuration - chargerEvent = []*utils.CGREventWithArgDispatcher{ + chargerEvent = []*utils.CGREventWithOpts{ { - CGREvent: &utils.CGREvent{ // matching Charger1 - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.Account: "1001", + CGREventWithArgDispatcher: &utils.CGREventWithArgDispatcher{ + CGREvent: &utils.CGREvent{ // matching Charger1 + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.Account: "1001", + }, }, }, }, { - CGREvent: &utils.CGREvent{ // no matching - Tenant: "cgrates.org", - ID: "event1", - Event: map[string]interface{}{ - utils.Account: "1010", - "DistinctMatch": "cgrates", + CGREventWithArgDispatcher: &utils.CGREventWithArgDispatcher{ + CGREvent: &utils.CGREvent{ // no matching + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.Account: "1010", + "DistinctMatch": "cgrates", + }, }, }, }, @@ -201,11 +205,11 @@ func testChargerSGetChargersForEvent(t *testing.T) { }, } var result *engine.ChargerProfiles - if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent, chargerEvent[1], &result); err == nil || + if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent, chargerEvent[1].CGREventWithArgDispatcher, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent, chargerEvent[0], &result); err != nil { + if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent, chargerEvent[0].CGREventWithArgDispatcher, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(result, chargerProfiles) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(chargerProfiles), utils.ToJSON(result)) diff --git a/apier/v1/config_it_test.go b/apier/v1/config_it_test.go index 3bb0e9d4d..425196881 100644 --- a/apier/v1/config_it_test.go +++ b/apier/v1/config_it_test.go @@ -163,7 +163,13 @@ func testConfigSReloadConfigFromJSONSessionS(t *testing.T) { }, "SchedulerConns": []interface{}{}, } - + if *encoding == utils.MetaGOB { + var empty []interface{} + exp["ReplicationConns"] = empty + exp["SchedulerConns"] = empty + exp["StatSConns"] = empty + exp["ThreshSConns"] = empty + } var rpl map[string]interface{} if err := configRPC.Call(utils.ConfigSv1GetJSONSection, &config.StringWithArgDispatcher{ Section: config.SessionSJson, diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index e704e7b88..3dfa81adb 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -438,7 +438,7 @@ func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: tenant, ID: "TEST_PROFILE1", @@ -541,7 +541,7 @@ func testV1FIdxSetSecondStatQueueProfileIndexes(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: tenant, ID: "TEST_PROFILE2", diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index 240735232..008ff2b6b 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -522,7 +522,7 @@ func testV1FIdxCaSetStatQueueProfile(t *testing.T) { } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: "cgrates.org", ID: "TEST_PROFILE1", @@ -675,7 +675,7 @@ func testV1FIdxCaUpdateStatQueueProfile(t *testing.T) { } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: "cgrates.org", ID: "TEST_PROFILE1", @@ -758,7 +758,7 @@ func testV1FIdxCaUpdateStatQueueProfileFromTP(t *testing.T) { reply.FilterIDs = []string{"FLTR_3"} reply.ActivationInterval = &utils.ActivationInterval{ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)} if err := tFIdxCaRpc.Call(utils.APIerSv1SetStatQueueProfile, - &StatQueueWithCache{StatQueueProfile: &reply}, &result); err != nil { + &engine.StatQueueWithCache{StatQueueProfile: &reply}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) diff --git a/apier/v1/remote_it_test.go b/apier/v1/remote_it_test.go index d6f971679..460676a27 100644 --- a/apier/v1/remote_it_test.go +++ b/apier/v1/remote_it_test.go @@ -612,6 +612,9 @@ func testInternalRemoteITGetChargerProfile(t *testing.T) { AttributeIDs: []string{utils.META_NONE}, Weight: 0, } + if *encoding == utils.MetaGOB { + chargerProfile.FilterIDs = nil + } var reply *engine.ChargerProfile if err := internalRPC.Call(utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}, &reply); err != nil { @@ -1032,7 +1035,7 @@ func testInternalSetAccount(t *testing.T) { func testInternalReplicateStats(t *testing.T) { var reply string - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: "cgrates.org", ID: "StatsToReplicate", diff --git a/apier/v1/replicate_it_test.go b/apier/v1/replicate_it_test.go index 24dc4e0da..6fb5b75df 100644 --- a/apier/v1/replicate_it_test.go +++ b/apier/v1/replicate_it_test.go @@ -430,7 +430,7 @@ func testInternalReplicateITStatQueueProfile(t *testing.T) { t.Error(err) } // set - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: tenant, ID: "TEST_PROFILE1", @@ -441,10 +441,10 @@ func testInternalReplicateITStatQueueProfile(t *testing.T) { QueueLength: 10, TTL: time.Duration(10) * time.Second, Metrics: []*engine.MetricWithFilters{ - &engine.MetricWithFilters{ + { MetricID: "*sum", }, - &engine.MetricWithFilters{ + { MetricID: "*acd", }, }, @@ -1073,6 +1073,12 @@ func testInternalReplicateITThresholdProfile(t *testing.T) { } func testInternalReplicateITSetAccount(t *testing.T) { + if *encoding == utils.MetaGOB { + t.SkipNow() // skip this function because + // APIerSv1GetAccount returns the old format of Account + // and it can not register that interface because is duplicate + // of the real Account + } //check var reply string if err := engineOneRPC.Call(utils.APIerSv1GetAccount, diff --git a/apier/v1/stats.go b/apier/v1/stats.go index 7d7535f19..07ca5e13e 100644 --- a/apier/v1/stats.go +++ b/apier/v1/stats.go @@ -60,13 +60,8 @@ func (APIerSv1 *APIerSv1) GetStatQueueProfileIDs(args utils.TenantArgWithPaginat return nil } -type StatQueueWithCache struct { - *engine.StatQueueProfile - Cache *string -} - // SetStatQueueProfile alters/creates a StatQueueProfile -func (APIerSv1 *APIerSv1) SetStatQueueProfile(arg *StatQueueWithCache, reply *string) error { +func (APIerSv1 *APIerSv1) SetStatQueueProfile(arg *engine.StatQueueWithCache, reply *string) error { if missing := utils.MissingStructFields(arg.StatQueueProfile, []string{"Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/stats_it_test.go b/apier/v1/stats_it_test.go index c0904ad04..276434289 100644 --- a/apier/v1/stats_it_test.go +++ b/apier/v1/stats_it_test.go @@ -36,7 +36,7 @@ var ( stsV1CfgPath string stsV1Cfg *config.CGRConfig stsV1Rpc *rpc.Client - statConfig *StatQueueWithCache + statConfig *engine.StatQueueWithCache stsV1ConfDIR string //run tests for specific configuration evs = []*utils.CGREvent{ @@ -362,7 +362,7 @@ func testV1STSSetStatQueueProfile(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: "cgrates.org", ID: "TEST_PROFILE1", @@ -471,7 +471,7 @@ func testV1STSRemoveStatQueueProfile(t *testing.T) { } func testV1STSProcessMetricsWithFilter(t *testing.T) { - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: "cgrates.org", ID: "CustomStatProfile", @@ -590,7 +590,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) { } func testV1STSProcessStaticMetrics(t *testing.T) { - statConfig = &StatQueueWithCache{ + statConfig = &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: "cgrates.org", ID: "StaticStatQueue", @@ -695,7 +695,7 @@ func testV1STSStatsPing(t *testing.T) { } func testV1STSProcessStatWithThreshold(t *testing.T) { - stTh := &StatQueueWithCache{ + stTh := &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: "cgrates.org", ID: "StatWithThreshold", diff --git a/config/datadbcfg.go b/config/datadbcfg.go index 049c0577e..f4dad7ee4 100644 --- a/config/datadbcfg.go +++ b/config/datadbcfg.go @@ -100,7 +100,6 @@ func (dbcfg *DataDbCfg) loadFromJsonCfg(jsnDbCfg *DbJsonCfg) (err error) { } } if jsnDbCfg.Items != nil { - dbcfg.Items = make(map[string]*ItemOpt) for kJsn, vJsn := range *jsnDbCfg.Items { val, has := dbcfg.Items[kJsn] if val == nil || !has { diff --git a/config/datadbcfg_test.go b/config/datadbcfg_test.go index 3d9c4a638..2c2084c32 100644 --- a/config/datadbcfg_test.go +++ b/config/datadbcfg_test.go @@ -398,6 +398,7 @@ func TestDataDbCfgloadFromJsonCfgItems(t *testing.T) { func TestDataDbCfgAsMapInterface(t *testing.T) { var dbcfg DataDbCfg + dbcfg.Items = make(map[string]*ItemOpt) cfgJSONStr := `{ "data_db": { "db_type": "*redis", diff --git a/config/ralscfg.go b/config/ralscfg.go index a4f473105..8b445037a 100644 --- a/config/ralscfg.go +++ b/config/ralscfg.go @@ -88,7 +88,6 @@ func (ralsCfg *RalsCfg) loadFromJsonCfg(jsnRALsCfg *RalsJsonCfg) (err error) { ralsCfg.RemoveExpired = *jsnRALsCfg.Remove_expired } if jsnRALsCfg.Max_computed_usage != nil { - ralsCfg.MaxComputedUsage = make(map[string]time.Duration, len(*jsnRALsCfg.Max_computed_usage)) for k, v := range *jsnRALsCfg.Max_computed_usage { if ralsCfg.MaxComputedUsage[k], err = utils.ParseDurationWithNanosecs(v); err != nil { return @@ -99,7 +98,6 @@ func (ralsCfg *RalsCfg) loadFromJsonCfg(jsnRALsCfg *RalsJsonCfg) (err error) { ralsCfg.MaxIncrements = *jsnRALsCfg.Max_increments } if jsnRALsCfg.Balance_rating_subject != nil { - ralsCfg.BalanceRatingSubject = make(map[string]string, len(*jsnRALsCfg.Balance_rating_subject)) for k, v := range *jsnRALsCfg.Balance_rating_subject { ralsCfg.BalanceRatingSubject[k] = v } diff --git a/config/ralscfg_test.go b/config/ralscfg_test.go index 835fbc2c1..d705f1317 100644 --- a/config/ralscfg_test.go +++ b/config/ralscfg_test.go @@ -78,6 +78,8 @@ func TestRalsCfgFromJsonCfg(t *testing.T) { func TestRalsCfgAsMapInterface(t *testing.T) { var ralscfg RalsCfg + ralscfg.MaxComputedUsage = make(map[string]time.Duration) + ralscfg.BalanceRatingSubject = make(map[string]string) cfgJSONStr := `{ "rals": { "enabled": false, diff --git a/config/stordbcfg.go b/config/stordbcfg.go index 1295d5ebe..54410785b 100644 --- a/config/stordbcfg.go +++ b/config/stordbcfg.go @@ -95,7 +95,6 @@ func (dbcfg *StorDbCfg) loadFromJsonCfg(jsnDbCfg *DbJsonCfg) (err error) { dbcfg.SSLMode = *jsnDbCfg.Sslmode } if jsnDbCfg.Items != nil { - dbcfg.Items = make(map[string]*ItemOpt) for kJsn, vJsn := range *jsnDbCfg.Items { val := new(ItemOpt) if err := val.loadFromJsonCfg(vJsn); err != nil { diff --git a/config/stordbcfg_test.go b/config/stordbcfg_test.go index 1ef7e654d..816e04dd7 100644 --- a/config/stordbcfg_test.go +++ b/config/stordbcfg_test.go @@ -135,6 +135,7 @@ func TestStoreDbCfgloadFromJsonCfgPort(t *testing.T) { func TestStorDbCfgAsMapInterface(t *testing.T) { var dbcfg StorDbCfg + dbcfg.Items = make(map[string]*ItemOpt) cfgJSONStr := `{ "stor_db": { "db_type": "*mysql", diff --git a/console/statqueue_set.go b/console/statqueue_set.go index 2d7ed65b5..7fc97db36 100644 --- a/console/statqueue_set.go +++ b/console/statqueue_set.go @@ -19,7 +19,6 @@ along with this program. If not, see package console import ( - v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -28,7 +27,7 @@ func init() { c := &CmdSetStatQueue{ name: "statqueue_set", rpcMethod: utils.APIerSv1SetStatQueueProfile, - rpcParams: &v1.StatQueueWithCache{}, + rpcParams: &engine.StatQueueWithCache{}, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -38,7 +37,7 @@ func init() { type CmdSetStatQueue struct { name string rpcMethod string - rpcParams *v1.StatQueueWithCache + rpcParams *engine.StatQueueWithCache *CommandExecuter } @@ -52,7 +51,7 @@ func (self *CmdSetStatQueue) RpcMethod() string { func (self *CmdSetStatQueue) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = &v1.StatQueueWithCache{StatQueueProfile: new(engine.StatQueueProfile)} + self.rpcParams = &engine.StatQueueWithCache{StatQueueProfile: new(engine.StatQueueProfile)} } return self.rpcParams } diff --git a/data/conf/samples/radagent_mysql_gob/cgrates.json b/data/conf/samples/radagent_mysql_gob/cgrates.json index b89009134..25ddf5ae0 100644 --- a/data/conf/samples/radagent_mysql_gob/cgrates.json +++ b/data/conf/samples/radagent_mysql_gob/cgrates.json @@ -72,106 +72,6 @@ "radius_agent": { "enabled": true, "sessions_conns": ["conn1"], - "request_processors": [ - { - "id": "KamailioAuth", - "filters": ["*string:~*vars.*radReqType:*radAuth"], - "flags": ["*authorize", "*attributes", "*accounts", "*continue"], - "request_fields":[ - {"tag": "Category", "path": "*cgreq.Category", "type": "*constant", "value": "call"}, - {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", - "value": "*prepaid", "mandatory": true}, - {"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", - "value": "~*req.Acct-Session-Id;-;~*req.Sip-From-Tag", "mandatory": true}, - {"tag": "Account", "path": "*cgreq.Account", "type": "*variable", - "value": "~*req.User-Name", "mandatory": true}, - {"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", - "value": "~*req.User-Name", "mandatory": true}, - {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", - "value": "~*req.Called-Station-Id", "mandatory": true}, - {"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", - "value": "~*req.Event-Timestamp", "mandatory": true}, - {"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", - "value": "~*req.Event-Timestamp", "mandatory": true}, - {"tag": "PasswordFromAttributes", "path": "*cgreq.PasswordFromAttributes", "type": "*constant", - "value": "*attributes"} - ], - "reply_fields":[ - {"tag": "MaxUsage", "path": "*rep.SIP-AVP", "type": "*variable", - "value": "session_max_time#;~*cgrep.MaxUsage{*duration_seconds}", "mandatory": true}, - ], - }, - { - "id": "RadiusAuthProcessor", - "filters": ["*string:~*vars.*radReqType:*radAuth"], - "flags": ["*radauth", "*log"], - "request_fields":[ - {"tag": "UserPassword", "path": "*vars.UserPassword", "type": "*variable", - "value": "~*cgrep.Attributes.PasswordFromAttributes"}, - ], - "reply_fields":[ - {"tag":"RemoveAddedFields", "filters": ["*notempty:~*cgrep.Error:"], "type": "*removeall", "path": "*rep"}, - {"tag": "Code", "path": "*rep.*radReplyCode", "filters": ["*notempty:~*cgrep.Error:"], - "type": "*constant", "value": "AccessReject"}, - {"tag": "ReplyMessage", "path": "*rep.Reply-Message", "filters": ["*notempty:~*cgrep.Error:"], - "type": "*variable", "value": "~*cgrep.Error"} - ] - }, - { - "id": "KamailioAccountingStart", - "filters": ["*string:~*req.Acct-Status-Type:Start"], - "flags": ["*initiate", "*attributes", "*resources", "*accounts"], - "request_fields":[ - {"tag": "Category", "path": "*cgreq.Category", "type": "*constant", "value": "call"}, - {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", - "value": "*prepaid", "mandatory": true}, - {"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", - "value": "~*req.Acct-Session-Id;-;~*req.Sip-From-Tag;-;~*req.Sip-To-Tag", "mandatory": true}, - {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*variable", - "value": "~*req.NAS-IP-Address", "mandatory": true}, - {"tag": "Account", "path": "*cgreq.Account", "type": "*variable", - "value": "~*req.User-Name", "mandatory": true}, - {"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", - "value": "~*req.User-Name", "mandatory": true}, - {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", - "value": "~*req.Called-Station-Id", "mandatory": true}, - {"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", - "value": "~*req.Ascend-User-Acct-Time", "mandatory": true}, - {"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", - "value": "~*req.Ascend-User-Acct-Time", "mandatory": true}, - {"tag": "RemoteAddr" , "path": "*cgreq.RemoteAddr", "type": "*remote_host"}, - ], - "reply_fields":[], - }, - { - "id": "KamailioAccountingStop", - "filters": ["*string:~*req.Acct-Status-Type:Stop"], - "flags": ["*terminate", "*resources", "*accounts", "*cdrs"], - "request_fields":[ - {"tag": "Category", "path": "*cgreq.Category", "type": "*constant", "value": "call"}, - {"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*constant", - "value": "*prepaid", "mandatory": true}, - {"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", - "value": "~*req.Acct-Session-Id;-;~*req.Sip-From-Tag;-;~*req.Sip-To-Tag", "mandatory": true}, - {"tag": "OriginHost", "path": "*cgreq.OriginHost", "type": "*variable", - "value": "~*req.NAS-IP-Address", "mandatory": true}, - {"tag": "Account", "path": "*cgreq.Account", "type": "*variable", - "value": "~*req.User-Name", "mandatory": true}, - {"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", - "value": "~*req.User-Name", "mandatory": true}, - {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", - "value": "~*req.Called-Station-Id", "mandatory": true}, - {"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", - "value": "~*req.Ascend-User-Acct-Time", "mandatory": true}, - {"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", - "value": "~*req.Ascend-User-Acct-Time", "mandatory": true}, - {"tag": "Usage", "path": "*cgreq.Usage", "type": "*usage_difference", - "value": "~*req.Event-Timestamp;~*req.Ascend-User-Acct-Time", "mandatory": true}, - {"tag": "RemoteAddr" , "path": "*cgreq.RemoteAddr", "type": "*remote_host"}, - ], - "reply_fields":[], - } - ] }, diff --git a/engine/actions_it_test.go b/engine/actions_it_test.go index 89d88875c..e2ab22b69 100644 --- a/engine/actions_it_test.go +++ b/engine/actions_it_test.go @@ -694,19 +694,19 @@ func testActionsitSetSDestinations(t *testing.T) { } // set a StatQueueProfile and simulate process event - statConfig := &StatQueueProfile{ - Tenant: "cgrates.org", - ID: "DistinctMetricProfile", - QueueLength: 10, - TTL: time.Duration(10) * time.Second, - Metrics: []*MetricWithFilters{ - &MetricWithFilters{ + statConfig := &StatQueueWithCache{ + StatQueueProfile: &StatQueueProfile{ + Tenant: "cgrates.org", + ID: "DistinctMetricProfile", + QueueLength: 10, + TTL: time.Duration(10) * time.Second, + Metrics: []*MetricWithFilters{{ MetricID: utils.MetaDDC, - }, + }}, + ThresholdIDs: []string{utils.META_NONE}, + Stored: true, + Weight: 20, }, - ThresholdIDs: []string{utils.META_NONE}, - Stored: true, - Weight: 20, } if err := actsLclRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &reply); err != nil { diff --git a/engine/libstats.go b/engine/libstats.go index cb24529e7..d1c89db00 100644 --- a/engine/libstats.go +++ b/engine/libstats.go @@ -50,6 +50,11 @@ type StatQueueProfileWithArgDispatcher struct { *utils.ArgDispatcher } +type StatQueueWithCache struct { + *StatQueueProfile + Cache *string +} + func (sqp *StatQueueProfile) TenantID() string { return utils.ConcatenatedKey(sqp.Tenant, sqp.ID) } diff --git a/general_tests/cacherpl_it_test.go b/general_tests/cacherpl_it_test.go index 157736d6a..2ac95676c 100644 --- a/general_tests/cacherpl_it_test.go +++ b/general_tests/cacherpl_it_test.go @@ -177,7 +177,7 @@ func testCacheRplRpcConn(t *testing.T) { if err != nil { t.Fatal(err) } - dspEngine2RPC, err = rpc.Dial(utils.TCP, dspEngine2Cfg.ListenCfg().RPCGOBListen) + dspEngine2RPC, err = newRPCClient(dspEngine2Cfg.ListenCfg()) if err != nil { t.Fatal(err) } @@ -476,18 +476,20 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { wgDisp1.Add(1) wgDisp2.Add(1) go func() { - if err := dspEngine1RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREventWithArgDispatcher{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testCacheRplAACheckLoadReplication", - Event: map[string]interface{}{ - utils.Account: "1007", - utils.Destination: "+491511231234", - "EventName": "TestLoad", + if err := dspEngine1RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREventWithOpts{ + CGREventWithArgDispatcher: &utils.CGREventWithArgDispatcher{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testCacheRplAACheckLoadReplication", + Event: map[string]interface{}{ + utils.Account: "1007", + utils.Destination: "+491511231234", + "EventName": "TestLoad", + }, + }, + ArgDispatcher: &utils.ArgDispatcher{ + RouteID: utils.StringPointer("testRouteFromDispatcher1"), }, - }, - ArgDispatcher: &utils.ArgDispatcher{ - RouteID: utils.StringPointer("testRouteFromDispatcher1"), }, }, &rpl); err != nil { t.Error(err) @@ -497,18 +499,20 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { wgDisp1.Done() }() go func() { - if err := dspEngine2RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREventWithArgDispatcher{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testCacheRplAACheckLoadReplication", - Event: map[string]interface{}{ - utils.Account: "1007", - utils.Destination: "+491511231234", - "EventName": "TestLoad", + if err := dspEngine2RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREventWithOpts{ + CGREventWithArgDispatcher: &utils.CGREventWithArgDispatcher{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testCacheRplAACheckLoadReplication", + Event: map[string]interface{}{ + utils.Account: "1007", + utils.Destination: "+491511231234", + "EventName": "TestLoad", + }, + }, + ArgDispatcher: &utils.ArgDispatcher{ + RouteID: utils.StringPointer("testRouteFromDispatcher2"), }, - }, - ArgDispatcher: &utils.ArgDispatcher{ - RouteID: utils.StringPointer("testRouteFromDispatcher2"), }, }, &rpl); err != nil { t.Error(err) @@ -594,18 +598,20 @@ func testCacheRplCheckLoadReplication(t *testing.T) { for i := 0; i < 10; i++ { wg.Add(1) go func() { - if err := dspEngine1RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREventWithArgDispatcher{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testCacheRplCheckLoadReplication", - Event: map[string]interface{}{ - utils.Account: "1007", - utils.Destination: "+491511231234", - "EventName": "TestLoad", + if err := dspEngine1RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREventWithOpts{ + CGREventWithArgDispatcher: &utils.CGREventWithArgDispatcher{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testCacheRplCheckLoadReplication", + Event: map[string]interface{}{ + utils.Account: "1007", + utils.Destination: "+491511231234", + "EventName": "TestLoad", + }, + }, + ArgDispatcher: &utils.ArgDispatcher{ + RouteID: utils.StringPointer("testRoute123"), }, - }, - ArgDispatcher: &utils.ArgDispatcher{ - RouteID: utils.StringPointer("testRoute123"), }, }, &rpl); err != nil { t.Error(err) diff --git a/general_tests/cdrs_it_test.go b/general_tests/cdrs_it_test.go index 944c2fd25..e262a423d 100644 --- a/general_tests/cdrs_it_test.go +++ b/general_tests/cdrs_it_test.go @@ -27,8 +27,6 @@ import ( "testing" "time" - v1 "github.com/cgrates/cgrates/apier/v1" - "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -473,17 +471,15 @@ func testV2CDRsSetStats(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - statConfig := &v1.StatQueueWithCache{ + statConfig := &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: "cgrates.org", ID: "STS_PoccessCDR", FilterIDs: []string{"*string:~*req.OriginID:testV2CDRsProcessCDR5"}, // QueueLength: 10, - Metrics: []*engine.MetricWithFilters{ - &engine.MetricWithFilters{ - MetricID: "*sum:~*req.Usage", - }, - }, + Metrics: []*engine.MetricWithFilters{{ + MetricID: "*sum:~*req.Usage", + }}, ThresholdIDs: []string{utils.META_NONE}, Blocker: true, Stored: true, diff --git a/general_tests/cdrs_processevent_it_test.go b/general_tests/cdrs_processevent_it_test.go index c696274a7..ee3352271 100644 --- a/general_tests/cdrs_processevent_it_test.go +++ b/general_tests/cdrs_processevent_it_test.go @@ -654,8 +654,15 @@ func testV1CDRsV2ProcessEventRalS(t *testing.T) { } reply[0].Event["CostDetails"] = nil expRply[0].Event["CGRID"] = reply[0].Event["CGRID"] - if !reflect.DeepEqual(reply[0], expRply[0]) { - t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + if *encoding == utils.MetaGOB { // gob encoding encodes 0 values of pointers to nil + expRply[0].Flags = nil + if utils.ToJSON(expRply) != utils.ToJSON(reply) { + t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + } + } else { + if !reflect.DeepEqual(reply[0], expRply[0]) { + t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + } } var cdrs []*engine.CDR if err := pecdrsRpc.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithArgDispatcher{ @@ -678,8 +685,14 @@ func testV1CDRsV2ProcessEventRalS(t *testing.T) { expRply[0].Event["Usage"] = 60000000000. expRply[0].Event["Cost"] = 0.0102 reply[0].Event["CostDetails"] = nil - if !reflect.DeepEqual(reply[0], expRply[0]) { - t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + if *encoding == utils.MetaGOB { // gob encoding encodes 0 values of pointers to nil + if utils.ToJSON(expRply) != utils.ToJSON(reply) { + t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + } + } else { + if !reflect.DeepEqual(reply[0], expRply[0]) { + t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + } } argsEv.CGREvent.Event[utils.Usage] = 30 * time.Second @@ -687,8 +700,14 @@ func testV1CDRsV2ProcessEventRalS(t *testing.T) { t.Error(err) } reply[0].Event["CostDetails"] = nil - if !reflect.DeepEqual(reply[0], expRply[0]) { - t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + if *encoding == utils.MetaGOB { // gob encoding encodes 0 values of pointers to nil + if utils.ToJSON(expRply) != utils.ToJSON(reply) { + t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + } + } else { + if !reflect.DeepEqual(reply[0], expRply[0]) { + t.Errorf("Expected %s, received: %s ", utils.ToJSON(expRply), utils.ToJSON(reply)) + } } } diff --git a/general_tests/doubleremove_it_test.go b/general_tests/doubleremove_it_test.go index 4ab53e8ee..754537f04 100644 --- a/general_tests/doubleremove_it_test.go +++ b/general_tests/doubleremove_it_test.go @@ -110,7 +110,7 @@ func testdoubleRemoveStatQueueProfile(t *testing.T) { t.Error(err) } // set - statConfig := &v1.StatQueueWithCache{ + statConfig := &engine.StatQueueWithCache{ StatQueueProfile: &engine.StatQueueProfile{ Tenant: doubleRemoveTenant, ID: "TEST_PROFILE1", diff --git a/general_tests/export_it_test.go b/general_tests/export_it_test.go index 503b2ca9c..5224f135e 100644 --- a/general_tests/export_it_test.go +++ b/general_tests/export_it_test.go @@ -188,6 +188,11 @@ func testExpVerifyAttributes(t *testing.T) { t.Fatal(err) } reply.Compile() + if *encoding == utils.MetaGOB { + for _, v := range exp.Attributes { + v.FilterIDs = nil + } + } if !reflect.DeepEqual(exp, reply) { t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(exp), utils.ToJSON(reply)) } @@ -397,8 +402,13 @@ func testExpVerifySuppliers(t *testing.T) { } if err := expRpc.Call(utils.APIerSv1GetSupplierProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "SPL_ACNT_1002"}, &reply); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(splPrf, reply) && !reflect.DeepEqual(splPrf2, reply) { + t.Fatal(err) + } + if *encoding == utils.MetaGOB { + splPrf.SortingParameters = nil + splPrf2.SortingParameters = nil + } + if !reflect.DeepEqual(splPrf, reply) && !reflect.DeepEqual(splPrf2, reply) { t.Errorf("Expecting: %+v \n or %+v \n,\n received: %+v", utils.ToJSON(splPrf), utils.ToJSON(splPrf2), utils.ToJSON(reply)) } diff --git a/gob_integration_test.sh b/gob_integration_test.sh index cba4ff336..87d365339 100755 --- a/gob_integration_test.sh +++ b/gob_integration_test.sh @@ -128,14 +128,14 @@ echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*postgre go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*postgres -rpc=*gob offline_postgres=$? -echo 'go test github.com/cgrates/cgrates/config -tags=integration -rpc=*gob' -go test github.com/cgrates/cgrates/config -tags=integration -rpc=*gob +echo 'go test github.com/cgrates/cgrates/config -tags=integration' +go test github.com/cgrates/cgrates/config -tags=integration cfg=$? -echo 'go test github.com/cgrates/cgrates/migrator -tags=integration -rpc=*gob' -go test github.com/cgrates/cgrates/migrator -tags=integration -rpc=*gob +echo 'go test github.com/cgrates/cgrates/migrator -tags=integration' +go test github.com/cgrates/cgrates/migrator -tags=integration mgr=$? -echo 'go test github.com/cgrates/cgrates/services -tags=integration -rpc=*gob' -go test github.com/cgrates/cgrates/services -tags=integration -rpc=*gob +echo 'go test github.com/cgrates/cgrates/services -tags=integration' +go test github.com/cgrates/cgrates/services -tags=integration srv=$? exit $gen && $ap1_internal && $ap2_internal && $en_internal && $ers_internal && $lds_internal && diff --git a/sessions/sessions_data_it_test.go b/sessions/sessions_data_it_test.go index a268f66d9..68e484023 100644 --- a/sessions/sessions_data_it_test.go +++ b/sessions/sessions_data_it_test.go @@ -67,9 +67,6 @@ func TestSessionsData(t *testing.T) { default: t.Fatal("Unknown Database type") } - if *encoding == utils.MetaGOB { - dataCfgDIR += "_gob" - } for _, stest := range SessionsDataTests { t.Run(dataCfgDIR, stest) } @@ -673,7 +670,7 @@ func testSessionsDataTTLExpMultiUpdates(t *testing.T) { var initRpl *V1InitSessionReply if err := sDataRPC.Call(utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { - t.Error(err) + t.Fatal(err) } time.Sleep(10 * time.Millisecond) // give some time to allow the session to be created if initRpl.MaxUsage.Nanoseconds() != usage { @@ -801,7 +798,7 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { var initRpl *V1InitSessionReply if err := sDataRPC.Call(utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { - t.Error(err) + t.Fatal(err) } if initRpl.MaxUsage.Nanoseconds() != usage { t.Errorf("Expecting : %+v, received: %+v", usage, initRpl.MaxUsage.Nanoseconds()) @@ -899,10 +896,16 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { updateRpl = new(V1UpdateSessionReply) // because gob doesn't overwrite 0 value fields if err := sDataRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { - t.Error(err) + t.Fatal(err) } - if updateRpl.MaxUsage.Nanoseconds() != usage { - t.Errorf("Expected: %+v, received: %+v", usage, updateRpl.MaxUsage.Nanoseconds()) + if *encoding != utils.MetaGOB { + if updateRpl.MaxUsage.Nanoseconds() != usage { + t.Errorf("Expected: %+v, received: %+v", usage, updateRpl.MaxUsage.Nanoseconds()) + } + } else { + if updateRpl.MaxUsage != nil { // gob returns 0 values as nil + t.Errorf("Expected: nil, received: %+v", updateRpl.MaxUsage) + } } eAcntVal = 100352.000000 diff --git a/sessions/sessions_it_test.go b/sessions/sessions_it_test.go index ee04c810a..8f2aec2cd 100644 --- a/sessions/sessions_it_test.go +++ b/sessions/sessions_it_test.go @@ -65,9 +65,6 @@ func TestSessionsIt(t *testing.T) { default: t.Fatal("Unknown Database type") } - if *encoding == utils.MetaGOB { - sItCfgDIR += "_gob" - } for _, stest := range sessionsITtests { t.Run(sItCfgDIR, stest) } diff --git a/sessions/sessions_voice_it_test.go b/sessions/sessions_voice_it_test.go index 6d7e60ed9..e670ee79e 100644 --- a/sessions/sessions_voice_it_test.go +++ b/sessions/sessions_voice_it_test.go @@ -70,9 +70,6 @@ func TestSessionsVoice(t *testing.T) { default: t.Fatal("Unknown Database type") } - if *encoding == utils.MetaGOB { - voiceCfgDIR += "_gob" - } for _, stest := range sessionsVoiceTests { t.Run(voiceCfgDIR, stest) }