From 49489be7a2cc199c28195601dc422ca50ff02f32 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 11 Dec 2019 16:56:54 +0200 Subject: [PATCH] Updated integration tests --- agents/diam_it_test.go | 6 +- apier/v1/attributes_it_test.go | 6 +- apier/v1/caches_it_test.go | 36 +---------- apier/v1/precache_it_test.go | 4 ++ apier/v1/sessions_process_event_it_test.go | 4 +- apier/v1/sessions_thresholds_it_test.go | 4 +- apier/v1/sessionsv1_it_test.go | 50 ++++++++------- config/config_defaults.go | 14 ++--- config/config_json_test.go | 21 ++++--- data/conf/cgrates/cgrates.json | 59 +++++++++--------- data/conf/samples/diamagent/cgrates.json | 3 + .../samples/diamagentmaxconn/cgrates.json | 3 + data/conf/samples/diamsctpagent/cgrates.json | 3 + data/conf/samples/ers/cgrates.json | 2 +- .../samples/precache/tutmongo/cgrates.json | 2 +- .../samples/precache/tutmysql/cgrates.json | 2 +- data/conf/samples/rpccaching/cgrates.json | 1 + data/tariffplans/tutorial/Attributes.csv | 1 + data/tariffplans/tutorial/Chargers.csv | 3 +- dispatchers/caches_it_test.go | 8 ++- dispatchers/chargers_it_test.go | 62 ++++++++++++++++--- engine/caches.go | 5 +- engine/cdrs.go | 4 +- general_tests/session2_it_test.go | 4 +- sessions/sessions.go | 17 +++++ 25 files changed, 195 insertions(+), 129 deletions(-) diff --git a/agents/diam_it_test.go b/agents/diam_it_test.go index 1a4bcd199..b63788d6a 100644 --- a/agents/diam_it_test.go +++ b/agents/diam_it_test.go @@ -867,10 +867,8 @@ func testDiamItCCRSMS(t *testing.T) { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) - } else { - if cdrs[0].Usage != 1 { - t.Errorf("Unexpected Usage CDR: %+v", cdrs[0]) - } + } else if cdrs[0].Usage != 1 { + t.Errorf("Unexpected Usage CDR: %+v", cdrs[0]) } } diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index c040045e6..bf2888964 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -447,7 +447,7 @@ func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { }, { FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile(utils.META_NONE, true, utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile(utils.MetaRemove, true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -514,7 +514,7 @@ func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { }, { FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile(utils.META_NONE, true, utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile(utils.MetaRemove, true, utils.INFIELD_SEP), }, }, Weight: 20, @@ -593,7 +593,7 @@ func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) { { FilterIDs: []string{"*string:~*req.Subject:1008"}, FieldName: utils.Subject, - Value: config.NewRSRParsersMustCompile(utils.META_NONE, true, utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile(utils.MetaRemove, true, utils.INFIELD_SEP), }, }, Weight: 20, diff --git a/apier/v1/caches_it_test.go b/apier/v1/caches_it_test.go index bc7d24f70..40f74c68d 100644 --- a/apier/v1/caches_it_test.go +++ b/apier/v1/caches_it_test.go @@ -340,40 +340,10 @@ func testCacheSClear(t *testing.T) { func testCacheSPrecacheStatus(t *testing.T) { var reply map[string]string - expected := map[string]string{ - utils.CacheDestinations: utils.MetaReady, - utils.CacheReverseDestinations: utils.MetaReady, - utils.CacheRatingPlans: utils.MetaReady, - utils.CacheRatingProfiles: utils.MetaReady, - utils.CacheActions: utils.MetaReady, - utils.CacheActionPlans: utils.MetaReady, - utils.CacheAccountActionPlans: utils.MetaReady, - utils.CacheActionTriggers: utils.MetaReady, - utils.CacheSharedGroups: utils.MetaReady, - utils.CacheResourceProfiles: utils.MetaReady, - utils.CacheResources: utils.MetaReady, - utils.CacheTimings: utils.MetaReady, - utils.CacheStatQueueProfiles: utils.MetaReady, - utils.CacheStatQueues: utils.MetaReady, - utils.CacheThresholdProfiles: utils.MetaReady, - utils.CacheThresholds: utils.MetaReady, - utils.CacheFilters: utils.MetaReady, - utils.CacheSupplierProfiles: utils.MetaReady, - utils.CacheAttributeProfiles: utils.MetaReady, - utils.CacheChargerProfiles: utils.MetaReady, - utils.CacheDispatcherProfiles: utils.MetaReady, - utils.CacheDispatcherHosts: utils.MetaReady, - utils.CacheDiameterMessages: utils.MetaReady, - utils.CacheAttributeFilterIndexes: utils.MetaReady, - utils.CacheResourceFilterIndexes: utils.MetaReady, - utils.CacheStatFilterIndexes: utils.MetaReady, - utils.CacheThresholdFilterIndexes: utils.MetaReady, - utils.CacheSupplierFilterIndexes: utils.MetaReady, - utils.CacheChargerFilterIndexes: utils.MetaReady, - utils.CacheDispatcherFilterIndexes: utils.MetaReady, - utils.CacheLoadIDs: utils.MetaReady, + expected := make(map[string]string) + for k := range utils.CachePartitions { + expected[k] = utils.MetaReady } - if err := chcRPC.Call(utils.CacheSv1PrecacheStatus, &utils.AttrCacheIDsWithArgDispatcher{}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, reply) { diff --git a/apier/v1/precache_it_test.go b/apier/v1/precache_it_test.go index 78eaa1600..018b3437b 100644 --- a/apier/v1/precache_it_test.go +++ b/apier/v1/precache_it_test.go @@ -298,6 +298,10 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) { Items: 0, Groups: 0, }, + utils.CacheCDRIDs: { + Items: 0, + Groups: 0, + }, } if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil { t.Error(err.Error()) diff --git a/apier/v1/sessions_process_event_it_test.go b/apier/v1/sessions_process_event_it_test.go index 109610179..f730b8430 100644 --- a/apier/v1/sessions_process_event_it_test.go +++ b/apier/v1/sessions_process_event_it_test.go @@ -225,7 +225,7 @@ func testSSv1ItProcessEventInitiateSession(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) } } @@ -291,7 +291,7 @@ func testSSv1ItProcessEventUpdateSession(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) } } diff --git a/apier/v1/sessions_thresholds_it_test.go b/apier/v1/sessions_thresholds_it_test.go index 44ce8cdee..99f8417a2 100755 --- a/apier/v1/sessions_thresholds_it_test.go +++ b/apier/v1/sessions_thresholds_it_test.go @@ -422,7 +422,7 @@ func TestSessionSv1ItInitNotFoundThreshold(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) } } @@ -556,7 +556,7 @@ func TestSessionSv1ItInitNotFoundThresholdAndStats(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) } } diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index 9a0059c7d..f0cbf3f3d 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -371,7 +371,7 @@ func testSSv1ItInitiateSession(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) } } @@ -421,7 +421,7 @@ func testSSv1ItInitiateSessionWithDigest(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) } } @@ -488,7 +488,7 @@ func testSSv1ItUpdateSession(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) } } @@ -530,20 +530,22 @@ func testSSv1ItTerminateSession(t *testing.T) { } func testSSv1ItProcessCDR(t *testing.T) { - args := utils.CGREvent{ - Tenant: "cgrates.org", - ID: "TestSSv1ItProcessCDR", - Event: map[string]interface{}{ - utils.Tenant: "cgrates.org", - utils.ToR: utils.VOICE, - utils.OriginID: "TestSSv1It1", - utils.RequestType: sSV1RequestType, - utils.Account: "1001", - utils.Subject: "ANY2CNT", - utils.Destination: "1002", - utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC), - utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC), - utils.Usage: 10 * time.Minute, + args := &utils.CGREventWithArgDispatcher{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "TestSSv1ItProcessCDR", + Event: map[string]interface{}{ + utils.Tenant: "cgrates.org", + utils.ToR: utils.VOICE, + utils.OriginID: "TestSSv1It1", + utils.RequestType: sSV1RequestType, + utils.Account: "1001", + utils.Subject: "ANY2CNT", + utils.Destination: "1002", + utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC), + utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC), + utils.Usage: 10 * time.Minute, + }, }, } var rply string @@ -571,6 +573,7 @@ func testSSv1ItProcessEvent(t *testing.T) { utils.Tenant: "cgrates.org", utils.ToR: utils.VOICE, utils.OriginID: "TestSSv1It2", + utils.OriginHost: "TestSSv1It3", utils.RequestType: sSV1RequestType, utils.Account: "1001", utils.Subject: "ANY2CNT", @@ -602,7 +605,7 @@ func testSSv1ItProcessEvent(t *testing.T) { Tenant: "cgrates.org", ID: "TestSSv1ItProcessEvent", Event: map[string]interface{}{ - utils.CGRID: "c87609aa1cb6e9529ab1836cfeeeb0ab7aa7ebaf", + utils.CGRID: "f7f5cf1029905f9b98be1a608e4bd975b8e51413", utils.Tenant: "cgrates.org", utils.ToR: utils.VOICE, utils.Account: "1001", @@ -610,6 +613,7 @@ func testSSv1ItProcessEvent(t *testing.T) { utils.Destination: "1002", "OfficeGroup": "Marketing", utils.OriginID: "TestSSv1It2", + utils.OriginHost: "TestSSv1It3", utils.RequestType: sSV1RequestType, utils.SetupTime: "2018-01-07T17:00:00Z", utils.AnswerTime: "2018-01-07T17:00:10Z", @@ -782,7 +786,7 @@ func testSSv1ItForceUpdateSession(t *testing.T) { aSessions = make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active ssesions: %s", utils.ToJSON(aSessions)) } @@ -911,7 +915,7 @@ func testSSv1ItDynamicDebit(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) } time.Sleep(time.Millisecond) @@ -941,7 +945,7 @@ func testSSv1ItDynamicDebit(t *testing.T) { if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) } @@ -998,7 +1002,7 @@ func testSSv1ItDeactivateSessions(t *testing.T) { } if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) - } else if len(aSessions) != 2 { + } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) } if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil && err.Error() != utils.NotFoundCaps { @@ -1016,7 +1020,7 @@ func testSSv1ItDeactivateSessions(t *testing.T) { } if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil { t.Error(err) - } else if len(pSessions) != 2 { + } else if len(pSessions) != 3 { t.Errorf("Expecting: 2, received: %+v", len(pSessions)) } } diff --git a/config/config_defaults.go b/config/config_defaults.go index 5c8283b47..daeea6cd1 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -165,7 +165,7 @@ const CGRATES_CFG_JSON = ` "*timings": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // timings caching "*resource_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control resource profiles caching "*resources": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control resources caching - "*event_resources": {"limit": -1, "ttl": "", "static_ttl": false}, // matching resources to events + "*event_resources": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // matching resources to events "*statqueue_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // statqueue profiles "*statqueues": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // statqueues with metrics "*threshold_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control threshold profiles caching @@ -183,13 +183,13 @@ const CGRATES_CFG_JSON = ` "*attribute_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control attribute filter indexes caching "*charger_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control charger filter indexes caching "*dispatcher_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control dispatcher filter indexes caching - "*dispatcher_routes": {"limit": -1, "ttl": "", "static_ttl": false}, // control dispatcher routes caching - "*diameter_messages": {"limit": -1, "ttl": "3h", "static_ttl": false}, // diameter messages caching - "*rpc_responses": {"limit": 0, "ttl": "2s", "static_ttl": false}, // RPC responses caching - "*closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false}, // closed sessions cached for CDRs - "*cdr_ids": {"limit": -1, "ttl": "", "static_ttl": false}, // protects CDRs against double-charging + "*dispatcher_routes": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control dispatcher routes caching + "*diameter_messages": {"limit": -1, "ttl": "3h", "static_ttl": false, "precache": false}, // diameter messages caching + "*rpc_responses": {"limit": 0, "ttl": "2s", "static_ttl": false, "precache": false}, // RPC responses caching + "*closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false, "precache": false}, // closed sessions cached for CDRs + "*cdr_ids": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // protects CDRs against double-charging "*load_ids": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control the load_ids for items - "*rpc_connections": {"limit": -1, "ttl": "", "static_ttl": false}, // RPC connections caching + "*rpc_connections": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // RPC connections caching }, diff --git a/config/config_json_test.go b/config/config_json_test.go index d2d4b01e8..49eccab9a 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -106,7 +106,8 @@ func TestCacheJsonCfg(t *testing.T) { Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false), Precache: utils.BoolPointer(false)}, utils.CacheEventResources: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, + Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false), + Precache: utils.BoolPointer(false)}, utils.CacheStatQueueProfiles: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false), Precache: utils.BoolPointer(false)}, @@ -152,20 +153,26 @@ func TestCacheJsonCfg(t *testing.T) { utils.CacheDispatcherFilterIndexes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, utils.CacheDispatcherRoutes: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, + Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false), + Precache: utils.BoolPointer(false)}, utils.CacheDiameterMessages: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer("3h"), Static_ttl: utils.BoolPointer(false)}, + Ttl: utils.StringPointer("3h"), Static_ttl: utils.BoolPointer(false), + Precache: utils.BoolPointer(false)}, utils.CacheRPCResponses: &CacheParamJsonCfg{Limit: utils.IntPointer(0), - Ttl: utils.StringPointer("2s"), Static_ttl: utils.BoolPointer(false)}, + Ttl: utils.StringPointer("2s"), Static_ttl: utils.BoolPointer(false), + Precache: utils.BoolPointer(false)}, utils.CacheClosedSessions: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer("10s"), Static_ttl: utils.BoolPointer(false)}, + Ttl: utils.StringPointer("10s"), Static_ttl: utils.BoolPointer(false), + Precache: utils.BoolPointer(false)}, utils.CacheCDRIDs: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, + Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false), + Precache: utils.BoolPointer(false)}, utils.CacheLoadIDs: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false), Precache: utils.BoolPointer(false)}, utils.CacheRPCConnections: &CacheParamJsonCfg{Limit: utils.IntPointer(-1), - Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)}, + Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false), + Precache: utils.BoolPointer(false)}, } if gCfg, err := dfCgrJsonCfg.CacheJsonCfg(); err != nil { diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index 60fe13b3b..6b7c123bd 100644 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -32,6 +32,9 @@ // }, +// "rpc_conns": {}, // rpc connections definitions + + // "data_db": { // database used to store runtime data (eg: accounts) // "db_type": "*redis", // data_db type: <*redis|*mongo> // "db_host": "127.0.0.1", // data_db host address @@ -141,29 +144,31 @@ // "*timings": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // timings caching // "*resource_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control resource profiles caching // "*resources": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control resources caching -// "*event_resources": {"limit": -1, "ttl": "", "static_ttl": false}, // matching resources to events -// "*statqueue_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // statqueue profiles -// "*statqueues": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // statqueues with metrics -// "*threshold_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control threshold profiles caching -// "*thresholds": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control thresholds caching +// "*event_resources": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // matching resources to events +// "*statqueue_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // statqueue profiles +// "*statqueues": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // statqueues with metrics +// "*threshold_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control threshold profiles caching +// "*thresholds": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control thresholds caching // "*filters": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control filters caching // "*supplier_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control supplier profile caching -// "*attribute_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control attribute profile caching +// "*attribute_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control attribute profile caching // "*charger_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control charger profile caching // "*dispatcher_profiles": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control dispatcher profile caching // "*dispatcher_hosts": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control dispatcher hosts caching -// "*resource_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control resource filter indexes caching -// "*stat_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control stat filter indexes caching +// "*resource_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control resource filter indexes caching +// "*stat_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control stat filter indexes caching // "*threshold_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control threshold filter indexes caching -// "*supplier_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control supplier filter indexes caching +// "*supplier_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control supplier filter indexes caching // "*attribute_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control attribute filter indexes caching // "*charger_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control charger filter indexes caching // "*dispatcher_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control dispatcher filter indexes caching -// "*dispatcher_routes": {"limit": -1, "ttl": "", "static_ttl": false}, // control dispatcher routes caching -// "*diameter_messages": {"limit": -1, "ttl": "3h", "static_ttl": false}, // diameter messages caching -// "*rpc_responses": {"limit": 0, "ttl": "2s", "static_ttl": false}, // RPC responses caching -// "*closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false}, // closed sessions cached for CDRs +// "*dispatcher_routes": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control dispatcher routes caching +// "*diameter_messages": {"limit": -1, "ttl": "3h", "static_ttl": false, "precache": false}, // diameter messages caching +// "*rpc_responses": {"limit": 0, "ttl": "2s", "static_ttl": false, "precache": false}, // RPC responses caching +// "*closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false, "precache": false}, // closed sessions cached for CDRs +// "*cdr_ids": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // protects CDRs against double-charging // "*load_ids": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control the load_ids for items +// "*rpc_connections": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // RPC connections caching // }, @@ -204,7 +209,7 @@ // "store_cdrs": true, // store cdrs in StorDB // "session_cost_retries": 5, // number of queries to session_costs before recalculating CDR // "chargers_conns": [], // connection to ChargerS for CDR forking, empty to disable billing for CDRs: <""|*internal|x.y.z.y:1234> -// "rals_conns": [], // connections to RALs for cost calculation: <""|*internal|x.y.z.y:1234> +// "rals_conns": [], // connections to RALs for cost calculation: <""|*internal|x.y.z.y:1234> // "attributes_conns": [], // connection to AttributeS for altering *raw CDRs, empty to disable attributes functionality: <""|*internal|x.y.z.y:1234> // "thresholds_conns": [], // connection to ThresholdS for CDR reporting, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> // "stats_conns": [], // connections to StatS for CDR reporting, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> @@ -269,17 +274,17 @@ // "partial_cache_expiry_action": "*dump_to_file", // action taken when cache when records in cache are timed-out <*dump_to_file|*post_cdr> // "header_fields": [], // template of the import header fields // "content_fields":[ // import content_fields template, tag will match internally CDR field, in case of .csv value will be represented by index of the field value -// {"tag": "TOR", "field_id": "ToR", "type": "*composed", "value": "~2", "mandatory": true}, -// {"tag": "OriginID", "field_id": "OriginID", "type": "*composed", "value": "~3", "mandatory": true}, -// {"tag": "RequestType", "field_id": "RequestType", "type": "*composed", "value": "~4", "mandatory": true}, -// {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~6", "mandatory": true}, -// {"tag": "Category", "field_id": "Category", "type": "*composed", "value": "~7", "mandatory": true}, -// {"tag": "Account", "field_id": "Account", "type": "*composed", "value": "~8", "mandatory": true}, -// {"tag": "Subject", "field_id": "Subject", "type": "*composed", "value": "~9", "mandatory": true}, -// {"tag": "Destination", "field_id": "Destination", "type": "*composed", "value": "~10", "mandatory": true}, -// {"tag": "SetupTime", "field_id": "SetupTime", "type": "*composed", "value": "~11", "mandatory": true}, -// {"tag": "AnswerTime", "field_id": "AnswerTime", "type": "*composed", "value": "~12", "mandatory": true}, -// {"tag": "Usage", "field_id": "Usage", "type": "*composed", "value": "~13", "mandatory": true}, +// {"tag": "TOR", "field_id": "ToR", "type": "*composed", "value": "~*req.2", "mandatory": true}, +// {"tag": "OriginID", "field_id": "OriginID", "type": "*composed", "value": "~*req.3", "mandatory": true}, +// {"tag": "RequestType", "field_id": "RequestType", "type": "*composed", "value": "~*req.4", "mandatory": true}, +// {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~*req.6", "mandatory": true}, +// {"tag": "Category", "field_id": "Category", "type": "*composed", "value": "~*req.7", "mandatory": true}, +// {"tag": "Account", "field_id": "Account", "type": "*composed", "value": "~*req.8", "mandatory": true}, +// {"tag": "Subject", "field_id": "Subject", "type": "*composed", "value": "~*req.9", "mandatory": true}, +// {"tag": "Destination", "field_id": "Destination", "type": "*composed", "value": "~*req.10", "mandatory": true}, +// {"tag": "SetupTime", "field_id": "SetupTime", "type": "*composed", "value": "~*req.11", "mandatory": true}, +// {"tag": "AnswerTime", "field_id": "AnswerTime", "type": "*composed", "value": "~*req.12", "mandatory": true}, +// {"tag": "Usage", "field_id": "Usage", "type": "*composed", "value": "~*req.13", "mandatory": true}, // ], // "trailer_fields": [], // template of the import trailer fields // "cache_dump_fields": [ // template used when dumping cached CDR, eg: partial CDRs @@ -304,9 +309,7 @@ // "ers": { // EventReaderService // "enabled": false, // starts the EventReader service: -// "sessions_conns": [ // connections to SessionS: <*internal|127.0.0.1:2012> -// {"address": "*internal"} -// ], +// "sessions_conns":["*internal"], // RPC Connections IDs // "readers": [ // { // "id": "*default", // identifier of the EventReader profile diff --git a/data/conf/samples/diamagent/cgrates.json b/data/conf/samples/diamagent/cgrates.json index 88ba19213..05f30fcb0 100644 --- a/data/conf/samples/diamagent/cgrates.json +++ b/data/conf/samples/diamagent/cgrates.json @@ -47,6 +47,9 @@ "chargers": { "enabled": true, + "attributes_conns": [ + {"address": "*internal"} + ], }, diff --git a/data/conf/samples/diamagentmaxconn/cgrates.json b/data/conf/samples/diamagentmaxconn/cgrates.json index 285c8879a..e8782d40c 100755 --- a/data/conf/samples/diamagentmaxconn/cgrates.json +++ b/data/conf/samples/diamagentmaxconn/cgrates.json @@ -46,6 +46,9 @@ "chargers": { "enabled": true, + "attributes_conns": [ + {"address": "*internal"} + ], }, diff --git a/data/conf/samples/diamsctpagent/cgrates.json b/data/conf/samples/diamsctpagent/cgrates.json index 36ee4182f..b276d8d8c 100755 --- a/data/conf/samples/diamsctpagent/cgrates.json +++ b/data/conf/samples/diamsctpagent/cgrates.json @@ -47,6 +47,9 @@ "chargers": { "enabled": true, + "attributes_conns": [ + {"address": "*internal"} + ], }, diff --git a/data/conf/samples/ers/cgrates.json b/data/conf/samples/ers/cgrates.json index fbe396566..a3ad6ea93 100644 --- a/data/conf/samples/ers/cgrates.json +++ b/data/conf/samples/ers/cgrates.json @@ -58,6 +58,7 @@ "rals_conns": [ {"address": "*internal"} ], + "session_cost_retries": 0, // number of queries to session_costs before recalculating CDR }, @@ -184,7 +185,6 @@ "id": "file_reader_with_filters", "run_delay": -1, "type": "*file_csv", - // "flags": ["*dryrun"], "field_separator": ";", "source_path": "/tmp/ers_with_filters/in", "processed_path": "/tmp/ers_with_filters/out", diff --git a/data/conf/samples/precache/tutmongo/cgrates.json b/data/conf/samples/precache/tutmongo/cgrates.json index 73d4a1d14..2ae88ca0f 100644 --- a/data/conf/samples/precache/tutmongo/cgrates.json +++ b/data/conf/samples/precache/tutmongo/cgrates.json @@ -56,7 +56,7 @@ "*charger_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true}, "*dispatcher_profiles" : {"limit": 10000, "ttl":"0s", "precache": true}, "*dispatcher_hosts" : {"limit": 10000, "ttl":"0s", "precache": true}, - "*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": true}, + "*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false}, }, diff --git a/data/conf/samples/precache/tutmysql/cgrates.json b/data/conf/samples/precache/tutmysql/cgrates.json index d79432570..9a7eac82e 100644 --- a/data/conf/samples/precache/tutmysql/cgrates.json +++ b/data/conf/samples/precache/tutmysql/cgrates.json @@ -52,7 +52,7 @@ "*charger_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true}, "*dispatcher_profiles" : {"limit": 10000, "ttl":"0s", "precache": true}, "*dispatcher_hosts" : {"limit": 10000, "ttl":"0s", "precache": true}, - "*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": true}, + "*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false}, }, diff --git a/data/conf/samples/rpccaching/cgrates.json b/data/conf/samples/rpccaching/cgrates.json index 0c1b1b681..131a5edb6 100644 --- a/data/conf/samples/rpccaching/cgrates.json +++ b/data/conf/samples/rpccaching/cgrates.json @@ -34,6 +34,7 @@ "cdrs": { "enabled": true, + "session_cost_retries": 2, // number of queries to session_costs before recalculating CDR }, diff --git a/data/tariffplans/tutorial/Attributes.csv b/data/tariffplans/tutorial/Attributes.csv index a52b9d86a..2d40f5f98 100644 --- a/data/tariffplans/tutorial/Attributes.csv +++ b/data/tariffplans/tutorial/Attributes.csv @@ -22,3 +22,4 @@ cgrates.com,ATTR_TNT_ALIAS,*any,,,,RequestType,*constant,*prepaid,, cgrates.com,ATTR_TNT_ALIAS,*any,,,,*tenant,*constant,cgrates.org,, cgrates.com,ATTR_TNT_1001,*any,*string:~*req.Account:1001,,,*tenant,*constant,cgrates.org,, cgrates.com,ATTR_TNT_DISC,*any,*string:~*req.Account:testDiamInitWithSessionDisconnect,,,*tenant,*constant,cgrates.org,, +cgrates.org,ATTR_RAW_REQ,*any,*string:~*req.RunID:*raw,,,RequestType,*constant,*none,false,10 diff --git a/data/tariffplans/tutorial/Chargers.csv b/data/tariffplans/tutorial/Chargers.csv index c270b5867..d6acebd62 100644 --- a/data/tariffplans/tutorial/Chargers.csv +++ b/data/tariffplans/tutorial/Chargers.csv @@ -1,2 +1,3 @@ #Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight -cgrates.org,DEFAULT,,,*default,*none,0 \ No newline at end of file +cgrates.org,DEFAULT,,,*default,*none,0 +cgrates.org,Raw,,,*raw,ATTR_RAW_REQ,0 \ No newline at end of file diff --git a/dispatchers/caches_it_test.go b/dispatchers/caches_it_test.go index 842f83cfc..c13ac54ee 100644 --- a/dispatchers/caches_it_test.go +++ b/dispatchers/caches_it_test.go @@ -22,6 +22,7 @@ package dispatchers import ( "reflect" + "sort" "testing" "time" @@ -120,8 +121,8 @@ func testDspChcLoadAfterFolder(t *testing.T) { t.Error(reply) } expStats[utils.CacheActions].Items = 2 - expStats[utils.CacheAttributeProfiles].Items = 10 - expStats[utils.CacheChargerProfiles].Items = 1 + expStats[utils.CacheAttributeProfiles].Items = 11 + expStats[utils.CacheChargerProfiles].Items = 2 expStats[utils.CacheFilters].Items = 7 expStats[utils.CacheRatingPlans].Items = 5 expStats[utils.CacheRatingProfiles].Items = 4 @@ -199,7 +200,7 @@ func testDspChcPrecacheStatus(t *testing.T) { func testDspChcGetItemIDs(t *testing.T) { var rcvKeys []string - expKeys := []string{"cgrates.org:DEFAULT"} + expKeys := []string{"cgrates.org:DEFAULT", "cgrates.org:Raw"} argsAPI := utils.ArgsGetCacheItemIDsWithArgDispatcher{ ArgsGetCacheItemIDs: utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheChargerProfiles, @@ -214,6 +215,7 @@ func testDspChcGetItemIDs(t *testing.T) { if err := dispEngine.RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Fatalf("Got error on ApierV1.GetCacheStats: %s ", err.Error()) } + sort.Strings(rcvKeys) if !reflect.DeepEqual(expKeys, rcvKeys) { t.Errorf("Expected: %+v, received: %+v", expKeys, rcvKeys) } diff --git a/dispatchers/chargers_it_test.go b/dispatchers/chargers_it_test.go index bb40b3eab..dc6ebb7a4 100755 --- a/dispatchers/chargers_it_test.go +++ b/dispatchers/chargers_it_test.go @@ -22,6 +22,8 @@ package dispatchers import ( "reflect" + "sort" + "strings" "testing" "github.com/cgrates/cgrates/engine" @@ -125,11 +127,27 @@ func testDspCppGetChtgFailover(t *testing.T) { } allEngine2.stopEngine(t) - + *eChargers = append(*eChargers, + &engine.ChargerProfile{ + Tenant: "cgrates.org", + ID: "Raw", + FilterIDs: []string{}, + RunID: utils.MetaRaw, + AttributeIDs: []string{"ATTR_RAW_REQ"}, + Weight: 0, + }, + ) + if *encoding == utils.MetaGOB { + (*eChargers)[1].FilterIDs = nil // empty slice are nil in gob + } if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, args, &reply); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(eChargers, reply) { + t.Fatal(err) + } + sort.Slice(*reply, func(i, j int) bool { + return strings.Compare((*reply)[i].ID, (*reply)[j].ID) < 0 + }) + if !reflect.DeepEqual(eChargers, reply) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eChargers), utils.ToJSON(reply)) } @@ -199,15 +217,28 @@ func testDspCppTestAuthKey2(t *testing.T) { AttributeIDs: []string{"*none"}, Weight: 0, }, + &engine.ChargerProfile{ + Tenant: "cgrates.org", + ID: "Raw", + FilterIDs: []string{}, + RunID: utils.MetaRaw, + AttributeIDs: []string{"ATTR_RAW_REQ"}, + Weight: 0, + }, } if *encoding == utils.MetaGOB { (*eChargers)[0].FilterIDs = nil // empty slice are nil in gob + (*eChargers)[1].FilterIDs = nil // empty slice are nil in gob } var reply *engine.ChargerProfiles if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, args, &reply); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(eChargers, reply) { + t.Fatal(err) + } + sort.Slice(*reply, func(i, j int) bool { + return strings.Compare((*reply)[i].ID, (*reply)[j].ID) < 0 + }) + if !reflect.DeepEqual(eChargers, reply) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eChargers), utils.ToJSON(reply)) } } @@ -248,10 +279,27 @@ func testDspCppGetChtgRoundRobin(t *testing.T) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eChargers), utils.ToJSON(reply)) } // To ALL + *eChargers = append(*eChargers, + &engine.ChargerProfile{ + Tenant: "cgrates.org", + ID: "Raw", + FilterIDs: []string{}, + RunID: utils.MetaRaw, + AttributeIDs: []string{"ATTR_RAW_REQ"}, + Weight: 0, + }, + ) + if *encoding == utils.MetaGOB { + (*eChargers)[1].FilterIDs = nil // empty slice are nil in gob + } if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, args, &reply); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(eChargers, reply) { + t.Fatal(err) + } + sort.Slice(*reply, func(i, j int) bool { + return strings.Compare((*reply)[i].ID, (*reply)[j].ID) < 0 + }) + if !reflect.DeepEqual(eChargers, reply) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eChargers), utils.ToJSON(reply)) } diff --git a/engine/caches.go b/engine/caches.go index e771b6af6..e89f89368 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -28,6 +28,7 @@ import ( "github.com/cgrates/ltcache" ) +// Cache is the global cache used var Cache *ltcache.TransCache func init() { @@ -60,7 +61,7 @@ type CacheS struct { pcItems map[string]chan struct{} // signal precaching } -// GetChannel returns the channel used to signal precaching +// GetPrecacheChannel returns the channel used to signal precaching func (chS *CacheS) GetPrecacheChannel(chID string) chan struct{} { return chS.pcItems[chID] } @@ -81,7 +82,7 @@ func (chS *CacheS) Precache() (err error) { utils.CacheInstanceToPrefix[cacheID], nil, false) if errCache != nil { - errChan <- errCache + errChan <- fmt.Errorf("precaching cacheID <%s>, got error: %s", cacheID, errCache) } close(chS.pcItems[cacheID]) wg.Done() diff --git a/engine/cdrs.go b/engine/cdrs.go index a4890e697..41051d1f0 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -170,7 +170,7 @@ func (cdrS *CDRServer) rateCDR(cdr *CDRWithArgDispatcher) ([]*CDR, error) { if err == nil && len(smCosts) != 0 { break } - if i != 3 { + if i <= cdrS.cgrCfg.CdrsCfg().SMCostRetries-1 { time.Sleep(time.Duration(fib()) * time.Second) } } @@ -486,7 +486,7 @@ func (cdrS *CDRServer) processEvent(ev *utils.CGREventWithArgDispatcher, me.GetStringIgnoreErrors(utils.CGRID), me.GetStringIgnoreErrors(utils.RunID), ) - if Cache.HasItem(utils.CacheCDRIDs, uID) { + if Cache.HasItem(utils.CacheCDRIDs, uID) && !reRate { utils.Logger.Warning( fmt.Sprintf("<%s> error: <%s> processing event %+v with %s", utils.CDRs, utils.ErrExists, utils.ToJSON(cgrEv), utils.CacheS)) diff --git a/general_tests/session2_it_test.go b/general_tests/session2_it_test.go index 57f85955c..f7f57ac41 100644 --- a/general_tests/session2_it_test.go +++ b/general_tests/session2_it_test.go @@ -158,8 +158,8 @@ func testSes2ItAsActiveSessions(t *testing.T) { Filters: []string{"*string:~Account:1001"}, }, &count); err != nil { t.Fatal(err) - } else if count != 1 { - t.Errorf("Expeced 1 session received %v session(s)", count) + } else if count != 2 { // 2 chargers + t.Errorf("Expeced 2 session received %v session(s)", count) } if err := ses2RPC.Call(utils.SessionSv1GetActiveSessionsCount, utils.SessionFilter{ Filters: []string{"*string:~Account:1002"}, diff --git a/sessions/sessions.go b/sessions/sessions.go index d60f4f95d..872f77eb3 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -764,6 +764,20 @@ func (sS *SessionS) registerSession(s *Session, passive bool) { sS.indexSession(s, passive) } +// isIndexed returns if the session is indexed +func (sS *SessionS) isIndexed(s *Session, passive bool) (has bool) { + sMux := &sS.aSsMux + sMp := sS.aSessions + if passive { + sMux = &sS.pSsMux + sMp = sS.pSessions + } + sMux.Lock() + _, has = sMp[s.CGRID] + sMux.Unlock() + return +} + // uregisterSession will unregister an active or passive session based on it's CGRID // called on session terminate or relocate func (sS *SessionS) unregisterSession(cgrID string, passive bool) bool { @@ -1384,6 +1398,9 @@ func (sS *SessionS) initSession(tnt string, evStart engine.MapEvent, clntConnID DebitInterval: dbtItval, ArgDispatcher: argDisp, } + if sS.isIndexed(s, true) { // check if already exists + return nil, utils.ErrExists + } if err = sS.forkSession(s); err != nil { return nil, err }