mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated integration tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
ad4f1fbd52
commit
946051a067
@@ -821,6 +821,8 @@ func testApierLoadAccountActions(t *testing.T) {
|
||||
expectedStats[utils.CacheAccountActionPlans].Items = 1
|
||||
expectedStats[utils.CacheActionPlans].Items = 1
|
||||
expectedStats[utils.CacheActions].Items = 1
|
||||
expectedStats[utils.CacheLoadIDs].Items = 20
|
||||
expectedStats[utils.CacheRPCConnections].Items = 1
|
||||
if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithArgDispatcher), &rcvStats); err != nil {
|
||||
t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
|
||||
} else if !reflect.DeepEqual(expectedStats, rcvStats) {
|
||||
@@ -856,10 +858,12 @@ func testApierSetRatingProfile(t *testing.T) {
|
||||
expectedStats[utils.CacheActionPlans].Items = 1
|
||||
expectedStats[utils.CacheActions].Items = 1
|
||||
expectedStats[utils.CacheRatingProfiles].Items = 1
|
||||
expectedStats[utils.CacheRPCConnections].Items = 1
|
||||
expectedStats[utils.CacheLoadIDs].Items = 20
|
||||
if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithArgDispatcher), &rcvStats); err != nil {
|
||||
t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
|
||||
} else if !reflect.DeepEqual(expectedStats, rcvStats) {
|
||||
t.Errorf("Calling CacheSv1.GetCacheStats expected: %+v, received: %+v", expectedStats, rcvStats)
|
||||
t.Errorf("Calling CacheSv1.GetCacheStats expected: %+v, received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats))
|
||||
}
|
||||
// Calling the second time should not raise EXISTS
|
||||
if err := rater.Call(utils.APIerSv1SetRatingProfile, rpf, &reply); err != nil {
|
||||
@@ -963,6 +967,7 @@ func testApierReloadCache(t *testing.T) {
|
||||
expectedStats[utils.CacheRatingPlans].Items = 1
|
||||
expectedStats[utils.CacheReverseDestinations].Items = 10
|
||||
expectedStats[utils.CacheLoadIDs].Items = 20
|
||||
expectedStats[utils.CacheRPCConnections].Items = 1
|
||||
if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithArgDispatcher), &rcvStats); err != nil {
|
||||
t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
|
||||
} else if !reflect.DeepEqual(expectedStats, rcvStats) {
|
||||
|
||||
@@ -366,11 +366,9 @@ func (cfg *CGRConfig) loadRPCConns(jsnCfg *CgrJsonCfg) (err error) {
|
||||
cfg.rpcConns[utils.MetaInternal] = &RPCConn{
|
||||
Strategy: rpcclient.PoolFirst,
|
||||
PoolSize: 0,
|
||||
Conns: []*RemoteHost{
|
||||
&RemoteHost{
|
||||
Address: utils.MetaInternal,
|
||||
},
|
||||
},
|
||||
Conns: []*RemoteHost{{
|
||||
Address: utils.MetaInternal,
|
||||
}},
|
||||
}
|
||||
for key, val := range jsnRPCConns {
|
||||
cfg.rpcConns[key] = NewDfltRPCConn()
|
||||
@@ -804,8 +802,8 @@ func (cfg *CGRConfig) ThresholdSCfg() *ThresholdSCfg {
|
||||
return cfg.thresholdSCfg
|
||||
}
|
||||
|
||||
// SupplierSCfg returns the config for SupplierS
|
||||
func (cfg *CGRConfig) RouteCfg() *RouteSCfg {
|
||||
// RouteSCfg returns the config for RouteS
|
||||
func (cfg *CGRConfig) RouteSCfg() *RouteSCfg {
|
||||
cfg.lks[RouteSJson].Lock()
|
||||
defer cfg.lks[RouteSJson].Unlock()
|
||||
return cfg.routeSCfg
|
||||
@@ -1062,7 +1060,7 @@ func (cfg *CGRConfig) V1GetConfigSection(args *StringWithArgDispatcher, reply *m
|
||||
case THRESHOLDS_JSON:
|
||||
jsonString = utils.ToJSON(cfg.ThresholdSCfg())
|
||||
case RouteSJson:
|
||||
jsonString = utils.ToJSON(cfg.RouteCfg())
|
||||
jsonString = utils.ToJSON(cfg.RouteSCfg())
|
||||
case SURETAX_JSON:
|
||||
jsonString = utils.ToJSON(cfg.SureTaxCfg())
|
||||
case DispatcherSJson:
|
||||
|
||||
@@ -249,13 +249,13 @@ func testCGRConfigReloadSupplierS(t *testing.T) {
|
||||
var reply string
|
||||
if err = cfg.V1ReloadConfigFromPath(&ConfigReloadWithArgDispatcher{
|
||||
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"),
|
||||
Section: SupplierSJson,
|
||||
Section: RouteSJson,
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expected OK received: %s", reply)
|
||||
}
|
||||
expAttr := &SupplierSCfg{
|
||||
expAttr := &RouteSCfg{
|
||||
Enabled: true,
|
||||
StringIndexedFields: &[]string{"LCRProfile"},
|
||||
PrefixIndexedFields: &[]string{utils.Destination},
|
||||
@@ -266,8 +266,8 @@ func testCGRConfigReloadSupplierS(t *testing.T) {
|
||||
IndexedSelects: true,
|
||||
DefaultRatio: 1,
|
||||
}
|
||||
if !reflect.DeepEqual(expAttr, cfg.SupplierSCfg()) {
|
||||
t.Errorf("Expected %s , received: %s ", utils.ToJSON(expAttr), utils.ToJSON(cfg.SupplierSCfg()))
|
||||
if !reflect.DeepEqual(expAttr, cfg.RouteSCfg()) {
|
||||
t.Errorf("Expected %s , received: %s ", utils.ToJSON(expAttr), utils.ToJSON(cfg.RouteSCfg()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ func testCGRConfigReloadSessionS(t *testing.T) {
|
||||
ResSConns: []string{utils.MetaLocalHost},
|
||||
ThreshSConns: []string{},
|
||||
StatSConns: []string{},
|
||||
SupplSConns: []string{utils.MetaLocalHost},
|
||||
RouteSConns: []string{utils.MetaLocalHost},
|
||||
AttrSConns: []string{utils.MetaLocalHost},
|
||||
CDRsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)},
|
||||
|
||||
@@ -949,7 +949,7 @@ func testCGRConfigReloadConfigFromJSONSessionS(t *testing.T) {
|
||||
ResSConns: []string{utils.MetaLocalHost},
|
||||
ThreshSConns: []string{},
|
||||
StatSConns: []string{},
|
||||
SupplSConns: []string{utils.MetaLocalHost},
|
||||
RouteSConns: []string{utils.MetaLocalHost},
|
||||
AttrSConns: []string{utils.MetaLocalHost},
|
||||
CDRsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)},
|
||||
|
||||
@@ -996,7 +996,7 @@ func testCGRConfigReloadAll(t *testing.T) {
|
||||
ResSConns: []string{utils.MetaLocalHost},
|
||||
ThreshSConns: []string{},
|
||||
StatSConns: []string{},
|
||||
SupplSConns: []string{utils.MetaLocalHost},
|
||||
RouteSConns: []string{utils.MetaLocalHost},
|
||||
AttrSConns: []string{utils.MetaLocalHost},
|
||||
CDRsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)},
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -95,6 +96,11 @@ func testLoaderITInitDataDB(t *testing.T) {
|
||||
if err = dbConn.Flush(utils.EmptyString); err != nil {
|
||||
t.Fatal("Error when flushing datadb")
|
||||
}
|
||||
cacheChan := make(chan rpcclient.ClientConnector, 1)
|
||||
cacheChan <- NewCacheS(lCfg, dataDbCsv)
|
||||
connMgr = NewConnManager(lCfg, map[string]chan rpcclient.ClientConnector{
|
||||
utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): cacheChan,
|
||||
})
|
||||
}
|
||||
|
||||
// Create/reset storage tariff plan tables, used as database connectin establishment also
|
||||
@@ -130,7 +136,7 @@ func testLoaderITRemoveLoad(t *testing.T) {
|
||||
}
|
||||
}*/
|
||||
loader, err = NewTpReader(dataDbCsv.DataDB(), NewFileCSVStorage(utils.CSV_SEP,
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario)), "", "", nil, nil)
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario)), "", "", []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -207,7 +213,7 @@ func testLoaderITLoadFromCSV(t *testing.T) {
|
||||
t.Error("Failed validating data: ", err.Error())
|
||||
}
|
||||
}*/
|
||||
loader, err = NewTpReader(dataDbCsv.DataDB(), NewFileCSVStorage(utils.CSV_SEP, path.Join(*dataDir, "tariffplans", *tpCsvScenario)), "", "", nil, nil)
|
||||
loader, err = NewTpReader(dataDbCsv.DataDB(), NewFileCSVStorage(utils.CSV_SEP, path.Join(*dataDir, "tariffplans", *tpCsvScenario)), "", "", []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -510,7 +516,7 @@ func testLoaderITImportToStorDb(t *testing.T) {
|
||||
|
||||
// Loads data from storDb into dataDb
|
||||
func testLoaderITLoadFromStorDb(t *testing.T) {
|
||||
loader, _ := NewTpReader(dataDbCsv.DataDB(), storDb, utils.TEST_SQL, "", nil, nil)
|
||||
loader, _ := NewTpReader(dataDbCsv.DataDB(), storDb, utils.TEST_SQL, "", []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, nil)
|
||||
if err := loader.LoadDestinations(); err != nil && err.Error() != utils.NotFoundCaps {
|
||||
t.Error("Failed loading destinations: ", err.Error())
|
||||
}
|
||||
@@ -544,7 +550,7 @@ func testLoaderITLoadFromStorDb(t *testing.T) {
|
||||
}
|
||||
|
||||
func testLoaderITLoadIndividualProfiles(t *testing.T) {
|
||||
loader, _ := NewTpReader(dataDbCsv.DataDB(), storDb, utils.TEST_SQL, "", nil, nil)
|
||||
loader, _ := NewTpReader(dataDbCsv.DataDB(), storDb, utils.TEST_SQL, "", []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, nil)
|
||||
// Load ratingPlans. This will also set destination keys
|
||||
if rps, err := storDb.GetTPRatingPlans(utils.TEST_SQL, "", nil); err != nil {
|
||||
t.Fatal("Could not retrieve rating plans")
|
||||
|
||||
@@ -83,7 +83,7 @@ func (rp *RouteProfile) compileCacheParameters() error {
|
||||
route.cacheRoute = make(map[string]interface{})
|
||||
if ratioSupplier, has := ratioMap[route.ID]; !has { // in case that ratio isn't defined for specific suppliers check for default
|
||||
if ratioDefault, has := ratioMap[utils.MetaDefault]; !has { // in case that *default ratio isn't defined take it from config
|
||||
route.cacheRoute[utils.MetaRatio] = config.CgrConfig().RouteCfg().DefaultRatio
|
||||
route.cacheRoute[utils.MetaRatio] = config.CgrConfig().RouteSCfg().DefaultRatio
|
||||
} else {
|
||||
route.cacheRoute[utils.MetaRatio] = ratioDefault
|
||||
}
|
||||
@@ -155,11 +155,11 @@ func (rpS *RouteService) Shutdown() error {
|
||||
// matchingRouteProfilesForEvent returns ordered list of matching resources which are active by the time of the call
|
||||
func (rpS *RouteService) matchingRouteProfilesForEvent(ev *utils.CGREvent, singleResult bool) (matchingRPrf []*RouteProfile, err error) {
|
||||
rPrfIDs, err := MatchingItemIDsForEvent(ev.Event,
|
||||
rpS.cgrcfg.RouteCfg().StringIndexedFields,
|
||||
rpS.cgrcfg.RouteCfg().PrefixIndexedFields,
|
||||
rpS.cgrcfg.RouteSCfg().StringIndexedFields,
|
||||
rpS.cgrcfg.RouteSCfg().PrefixIndexedFields,
|
||||
rpS.dm, utils.CacheRouteFilterIndexes, ev.Tenant,
|
||||
rpS.cgrcfg.RouteCfg().IndexedSelects,
|
||||
rpS.cgrcfg.RouteCfg().NestedFields,
|
||||
rpS.cgrcfg.RouteSCfg().IndexedSelects,
|
||||
rpS.cgrcfg.RouteSCfg().NestedFields,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -241,7 +241,7 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent,
|
||||
usage = time.Duration(1 * time.Minute)
|
||||
err = nil
|
||||
}
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteCfg().ResponderSConns, nil, utils.ResponderGetMaxSessionTimeOnAccounts,
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().ResponderSConns, nil, utils.ResponderGetMaxSessionTimeOnAccounts,
|
||||
&utils.GetMaxSessionTimeOnAccountsArgs{
|
||||
Tenant: ev.Tenant,
|
||||
Subject: subj,
|
||||
@@ -252,7 +252,7 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent,
|
||||
}, &costData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteCfg().ResponderSConns, nil, utils.ResponderGetCostOnRatingPlans,
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().ResponderSConns, nil, utils.ResponderGetCostOnRatingPlans,
|
||||
&utils.GetCostOnRatingPlansArgs{
|
||||
Tenant: ev.Tenant,
|
||||
Account: acnt,
|
||||
@@ -272,10 +272,10 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent,
|
||||
func (rpS *RouteService) statMetrics(statIDs []string, tenant string) (stsMetric map[string]float64, err error) {
|
||||
stsMetric = make(map[string]float64)
|
||||
provStsMetrics := make(map[string][]float64)
|
||||
if len(rpS.cgrcfg.RouteCfg().StatSConns) != 0 {
|
||||
if len(rpS.cgrcfg.RouteSCfg().StatSConns) != 0 {
|
||||
for _, statID := range statIDs {
|
||||
var metrics map[string]float64
|
||||
if err = rpS.connMgr.Call(rpS.cgrcfg.RouteCfg().StatSConns, nil, utils.StatSv1GetQueueFloatMetrics,
|
||||
if err = rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().StatSConns, nil, utils.StatSv1GetQueueFloatMetrics,
|
||||
&utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: tenant, ID: statID}}, &metrics); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
@@ -301,13 +301,13 @@ func (rpS *RouteService) statMetrics(statIDs []string, tenant string) (stsMetric
|
||||
// first metric found is always returned
|
||||
func (rpS *RouteService) statMetricsForLoadDistribution(statIDs []string, tenant string) (result float64, err error) {
|
||||
provStsMetrics := make(map[string][]float64)
|
||||
if len(rpS.cgrcfg.RouteCfg().StatSConns) != 0 {
|
||||
if len(rpS.cgrcfg.RouteSCfg().StatSConns) != 0 {
|
||||
for _, statID := range statIDs {
|
||||
// check if we get an ID in the following form (StatID:MetricID)
|
||||
statWithMetric := strings.Split(statID, utils.InInFieldSep)
|
||||
var metrics map[string]float64
|
||||
if err = rpS.connMgr.Call(
|
||||
rpS.cgrcfg.RouteCfg().StatSConns, nil,
|
||||
rpS.cgrcfg.RouteSCfg().StatSConns, nil,
|
||||
utils.StatSv1GetQueueFloatMetrics,
|
||||
&utils.TenantIDWithArgDispatcher{
|
||||
TenantID: &utils.TenantID{
|
||||
@@ -346,10 +346,10 @@ func (rpS *RouteService) statMetricsForLoadDistribution(statIDs []string, tenant
|
||||
|
||||
// resourceUsage returns sum of all resource usages out of list
|
||||
func (rpS *RouteService) resourceUsage(resIDs []string, tenant string) (tUsage float64, err error) {
|
||||
if len(rpS.cgrcfg.RouteCfg().ResourceSConns) != 0 {
|
||||
if len(rpS.cgrcfg.RouteSCfg().ResourceSConns) != 0 {
|
||||
for _, resID := range resIDs {
|
||||
var res Resource
|
||||
if err = rpS.connMgr.Call(rpS.cgrcfg.RouteCfg().ResourceSConns, nil, utils.ResourceSv1GetResource,
|
||||
if err = rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().ResourceSConns, nil, utils.ResourceSv1GetResource,
|
||||
&utils.TenantIDWithArgDispatcher{TenantID: &utils.TenantID{Tenant: tenant, ID: resID}}, &res); err != nil && err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<SupplierS> error: %s getting resource for ID : %s", err.Error(), resID))
|
||||
@@ -584,7 +584,7 @@ func (rpS *RouteService) V1GetRoutes(args *ArgsGetRoutes, reply *SortedRoutes) (
|
||||
} else if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.Event)
|
||||
}
|
||||
if len(rpS.cgrcfg.RouteCfg().AttributeSConns) != 0 {
|
||||
if len(rpS.cgrcfg.RouteSCfg().AttributeSConns) != 0 {
|
||||
attrArgs := &AttrArgsProcessEvent{
|
||||
Context: utils.StringPointer(utils.FirstNonEmpty(
|
||||
utils.IfaceAsString(args.CGREvent.Event[utils.Context]),
|
||||
@@ -593,7 +593,7 @@ func (rpS *RouteService) V1GetRoutes(args *ArgsGetRoutes, reply *SortedRoutes) (
|
||||
ArgDispatcher: args.ArgDispatcher,
|
||||
}
|
||||
var rplyEv AttrSProcessEventReply
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteCfg().AttributeSConns, nil,
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().AttributeSConns, nil,
|
||||
utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 {
|
||||
args.CGREvent = rplyEv.CGREvent
|
||||
args.Opts = rplyEv.Opts
|
||||
|
||||
@@ -291,8 +291,8 @@ func TestRoutesPopulateRouteService(t *testing.T) {
|
||||
defaultCfg, _ := config.NewDefaultCGRConfig()
|
||||
data := NewInternalDB(nil, nil, true, defaultCfg.DataDbCfg().Items)
|
||||
dmSPP = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
|
||||
defaultCfg.RouteCfg().StringIndexedFields = nil
|
||||
defaultCfg.RouteCfg().PrefixIndexedFields = nil
|
||||
defaultCfg.RouteSCfg().StringIndexedFields = nil
|
||||
defaultCfg.RouteSCfg().PrefixIndexedFields = nil
|
||||
splService, err = NewRouteService(dmSPP, &FilterS{
|
||||
dm: dmSPP, cfg: defaultCfg}, defaultCfg, nil)
|
||||
if err != nil {
|
||||
@@ -626,7 +626,7 @@ func TestRoutesAsOptsGetRoutesMaxCost(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRoutesMatchWithIndexFalse(t *testing.T) {
|
||||
splService.cgrcfg.RouteCfg().IndexedSelects = false
|
||||
splService.cgrcfg.RouteSCfg().IndexedSelects = false
|
||||
sprf, err := splService.matchingRouteProfilesForEvent(argsGetRoutes[0].CGREvent, true)
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
|
||||
@@ -453,6 +453,7 @@ func (m *Migrator) migrateSupplierProfileFiltersV1() (err error) {
|
||||
var spp *SupplierProfile
|
||||
spp, err = m.dmIN.getSupplier()
|
||||
if err == utils.ErrNoMoreData {
|
||||
err = nil
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
@@ -663,6 +664,7 @@ func (m *Migrator) migrateSupplierProfileFiltersV2() (err error) {
|
||||
var spp *SupplierProfile
|
||||
spp, err = m.dmIN.getSupplier()
|
||||
if err == utils.ErrNoMoreData {
|
||||
err = nil
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -136,24 +136,20 @@ func testFltrITMigrateAndMove(t *testing.T) {
|
||||
Filters := &v1Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_2",
|
||||
Rules: []*v1FilterRule{
|
||||
&v1FilterRule{
|
||||
Type: utils.MetaPrefix,
|
||||
FieldName: "Account",
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
},
|
||||
Rules: []*v1FilterRule{{
|
||||
Type: utils.MetaPrefix,
|
||||
FieldName: "Account",
|
||||
Values: []string{"1001"},
|
||||
}},
|
||||
}
|
||||
expFilters := &engine.Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_2",
|
||||
Rules: []*engine.FilterRule{
|
||||
&engine.FilterRule{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account,
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
},
|
||||
Rules: []*engine.FilterRule{{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account,
|
||||
Values: []string{"1001"},
|
||||
}},
|
||||
}
|
||||
expFilters.Compile()
|
||||
attrProf := &engine.AttributeProfile{
|
||||
@@ -237,8 +233,8 @@ func testFltrITMigrateAndMove(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expAttrProf), utils.ToJSON(resultattr))
|
||||
}
|
||||
expFltrIdx := map[string]utils.StringMap{
|
||||
"*prefix:~*req.Account:1001": utils.StringMap{"ATTR_1": true},
|
||||
"*string:~*req.Account:1001": utils.StringMap{"ATTR_1": true}}
|
||||
"*prefix:~*req.Account:1001": {"ATTR_1": true},
|
||||
"*string:~*req.Account:1001": {"ATTR_1": true}}
|
||||
|
||||
if fltridx, err := fltrMigrator.dmOut.DataManager().GetFilterIndexes(utils.PrefixToIndexCache[utils.AttributeProfilePrefix], utils.ConcatenatedKey(attrProf.Tenant, utils.META_ANY), utils.MetaString, nil); err != nil {
|
||||
t.Error(err)
|
||||
@@ -284,17 +280,17 @@ func testFltrITMigratev2(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_2",
|
||||
Rules: []*v1FilterRule{
|
||||
&v1FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
FieldName: "~Account",
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
&v1FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
FieldName: "~*req.Subject",
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
&v1FilterRule{
|
||||
{
|
||||
Type: utils.MetaRSR,
|
||||
FieldName: utils.EmptyString,
|
||||
Values: []string{"~Tenant(~^cgr.*\\.org$)"},
|
||||
@@ -305,17 +301,17 @@ func testFltrITMigratev2(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_2",
|
||||
Rules: []*engine.FilterRule{
|
||||
&engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account,
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
&engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Subject",
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
&engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaRSR,
|
||||
Element: utils.EmptyString,
|
||||
Values: []string{"~*req.Tenant(~^cgr.*\\.org$)"},
|
||||
|
||||
@@ -113,7 +113,7 @@ func (m *Migrator) migrateCurrentRouteProfile() (err error) {
|
||||
if err := m.dmIN.DataManager().RemoveRouteProfile(tntID[0], tntID[1], utils.NonTransactional, true); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Routes] += 1
|
||||
m.stats[utils.Routes]++
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (m *Migrator) migrateRouteProfiles() (err error) {
|
||||
err.Error(),
|
||||
fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error()))
|
||||
}
|
||||
if routeVersion, has := vrs[utils.RouteProfilePrefix]; !has {
|
||||
if routeVersion, has := vrs[utils.Routes]; !has {
|
||||
if vrs[utils.RQF] != current[utils.RQF] {
|
||||
return fmt.Errorf("please migrate the filters before migrating the routes")
|
||||
}
|
||||
|
||||
@@ -173,31 +173,29 @@ func testSupITFlush(t *testing.T) {
|
||||
}
|
||||
|
||||
func testSupITMigrateAndMove(t *testing.T) {
|
||||
supPrfl := &engine.SupplierProfile{
|
||||
supPrfl := &engine.RouteProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SUP1",
|
||||
FilterIDs: []string{"*string:~Account:1001"},
|
||||
Weight: 10,
|
||||
Sorting: utils.MetaQOS,
|
||||
SortingParameters: []string{},
|
||||
Suppliers: []*engine.Supplier{
|
||||
&engine.Supplier{
|
||||
ID: "Sup",
|
||||
FilterIDs: []string{},
|
||||
AccountIDs: []string{"1001"},
|
||||
RatingPlanIDs: []string{"RT_PLAN1"},
|
||||
ResourceIDs: []string{"RES1"},
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Routes: []*engine.Route{{
|
||||
ID: "Sup",
|
||||
FilterIDs: []string{},
|
||||
AccountIDs: []string{"1001"},
|
||||
RatingPlanIDs: []string{"RT_PLAN1"},
|
||||
ResourceIDs: []string{"RES1"},
|
||||
Weight: 10,
|
||||
}},
|
||||
}
|
||||
switch supAction {
|
||||
case utils.Migrate: // for the momment only one version of rating plans exists
|
||||
case utils.Move:
|
||||
if err := supMigrator.dmIN.DataManager().SetSupplierProfile(supPrfl, true); err != nil {
|
||||
if err := supMigrator.dmIN.DataManager().SetRouteProfile(supPrfl, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := supMigrator.dmIN.DataManager().GetSupplierProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional); err != nil {
|
||||
if _, err := supMigrator.dmIN.DataManager().GetRouteProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
@@ -206,23 +204,23 @@ func testSupITMigrateAndMove(t *testing.T) {
|
||||
t.Error("Error when setting version for Suppliers ", err.Error())
|
||||
}
|
||||
|
||||
_, err = supMigrator.dmOut.DataManager().GetSupplierProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional)
|
||||
_, err = supMigrator.dmOut.DataManager().GetRouteProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err, _ = supMigrator.Migrate([]string{utils.MetaSuppliers})
|
||||
err, _ = supMigrator.Migrate([]string{utils.MetaRoutes})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Suppliers ", err.Error())
|
||||
}
|
||||
result, err := supMigrator.dmOut.DataManager().GetSupplierProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional)
|
||||
result, err := supMigrator.dmOut.DataManager().GetRouteProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(result, supPrfl) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", supPrfl, result)
|
||||
}
|
||||
result, err = supMigrator.dmIN.DataManager().GetSupplierProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional)
|
||||
result, err = supMigrator.dmIN.DataManager().GetRouteProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ var (
|
||||
tpSplCfgIn *config.CGRConfig
|
||||
tpSplCfgOut *config.CGRConfig
|
||||
tpSplMigrator *Migrator
|
||||
tpSuppliers []*utils.TPSupplierProfile
|
||||
tpSuppliers []*utils.TPRouteProfile
|
||||
)
|
||||
|
||||
var sTestsTpSplIT = []func(t *testing.T){
|
||||
@@ -107,7 +107,7 @@ func testTpSplITFlush(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTpSplITPopulate(t *testing.T) {
|
||||
tpSuppliers = []*utils.TPSupplierProfile{
|
||||
tpSuppliers = []*utils.TPRouteProfile{
|
||||
{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
@@ -119,23 +119,23 @@ func testTpSplITPopulate(t *testing.T) {
|
||||
},
|
||||
Sorting: "*lowest_cost",
|
||||
SortingParameters: []string{},
|
||||
Suppliers: []*utils.TPSupplier{
|
||||
Routes: []*utils.TPRoute{
|
||||
{
|
||||
ID: "supplier1",
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
AccountIDs: []string{"Acc1", "Acc2"},
|
||||
RatingPlanIDs: []string{"RPL_1"},
|
||||
ResourceIDs: []string{"ResGroup1"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
Weight: 10,
|
||||
Blocker: false,
|
||||
SupplierParameters: "SortingParam1",
|
||||
ID: "supplier1",
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
AccountIDs: []string{"Acc1", "Acc2"},
|
||||
RatingPlanIDs: []string{"RPL_1"},
|
||||
ResourceIDs: []string{"ResGroup1"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
Weight: 10,
|
||||
Blocker: false,
|
||||
RouteParameters: "SortingParam1",
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
},
|
||||
}
|
||||
if err := tpSplMigrator.storDBIn.StorDB().SetTPSuppliers(tpSuppliers); err != nil {
|
||||
if err := tpSplMigrator.storDBIn.StorDB().SetTPRoutes(tpSuppliers); err != nil {
|
||||
t.Error("Error when setting TpSuppliers ", err.Error())
|
||||
}
|
||||
currentVersion := engine.CurrentStorDBVersions()
|
||||
@@ -146,14 +146,14 @@ func testTpSplITPopulate(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTpSplITMove(t *testing.T) {
|
||||
err, _ := tpSplMigrator.Migrate([]string{utils.MetaTpSuppliers})
|
||||
err, _ := tpSplMigrator.Migrate([]string{utils.MetaTpRoutes})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating TpSuppliers ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func testTpSplITCheckData(t *testing.T) {
|
||||
result, err := tpSplMigrator.storDBOut.StorDB().GetTPSuppliers(
|
||||
result, err := tpSplMigrator.storDBOut.StorDB().GetTPRoutes(
|
||||
tpSuppliers[0].TPid, "", tpSuppliers[0].ID)
|
||||
if err != nil {
|
||||
t.Error("Error when getting TpSuppliers ", err.Error())
|
||||
@@ -162,7 +162,7 @@ func testTpSplITCheckData(t *testing.T) {
|
||||
if !reflect.DeepEqual(tpSuppliers[0], result[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpSuppliers[0]), utils.ToJSON(result[0]))
|
||||
}
|
||||
result, err = tpSplMigrator.storDBIn.StorDB().GetTPSuppliers(
|
||||
result, err = tpSplMigrator.storDBIn.StorDB().GetTPRoutes(
|
||||
tpSuppliers[0].TPid, "", tpSuppliers[0].ID)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
|
||||
@@ -137,7 +137,7 @@ func (db *DataDBService) ShouldRun() bool {
|
||||
func (db *DataDBService) mandatoryDB() bool {
|
||||
return db.cfg.RalsCfg().Enabled || db.cfg.SchedulerCfg().Enabled || db.cfg.ChargerSCfg().Enabled ||
|
||||
db.cfg.AttributeSCfg().Enabled || db.cfg.ResourceSCfg().Enabled || db.cfg.StatSCfg().Enabled ||
|
||||
db.cfg.ThresholdSCfg().Enabled || db.cfg.RouteCfg().Enabled || db.cfg.DispatcherSCfg().Enabled ||
|
||||
db.cfg.ThresholdSCfg().Enabled || db.cfg.RouteSCfg().Enabled || db.cfg.DispatcherSCfg().Enabled ||
|
||||
db.cfg.LoaderCfg().Enabled() || db.cfg.ApierCfg().Enabled
|
||||
}
|
||||
|
||||
|
||||
@@ -82,127 +82,127 @@ func TestDataDBReload(t *testing.T) {
|
||||
DataDbUser: "cgrates",
|
||||
QueryTimeout: 10 * time.Second,
|
||||
Items: map[string]*config.ItemOpt{
|
||||
utils.MetaAccounts: &config.ItemOpt{
|
||||
utils.MetaAccounts: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaReverseDestinations: &config.ItemOpt{
|
||||
utils.MetaReverseDestinations: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaDestinations: &config.ItemOpt{
|
||||
utils.MetaDestinations: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaRatingPlans: &config.ItemOpt{
|
||||
utils.MetaRatingPlans: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaRatingProfiles: &config.ItemOpt{
|
||||
utils.MetaRatingProfiles: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaActions: &config.ItemOpt{
|
||||
utils.MetaActions: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaActionPlans: &config.ItemOpt{
|
||||
utils.MetaActionPlans: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaAccountActionPlans: &config.ItemOpt{
|
||||
utils.MetaAccountActionPlans: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaActionTriggers: &config.ItemOpt{
|
||||
utils.MetaActionTriggers: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaSharedGroups: &config.ItemOpt{
|
||||
utils.MetaSharedGroups: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaTimings: &config.ItemOpt{
|
||||
utils.MetaTimings: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaResourceProfile: &config.ItemOpt{
|
||||
utils.MetaResourceProfile: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaStatQueues: &config.ItemOpt{
|
||||
utils.MetaStatQueues: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaResources: &config.ItemOpt{
|
||||
utils.MetaResources: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaStatQueueProfiles: &config.ItemOpt{
|
||||
utils.MetaStatQueueProfiles: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaThresholds: &config.ItemOpt{
|
||||
utils.MetaThresholds: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaThresholdProfiles: &config.ItemOpt{
|
||||
utils.MetaThresholdProfiles: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaFilters: &config.ItemOpt{
|
||||
utils.MetaFilters: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaSupplierProfiles: &config.ItemOpt{
|
||||
utils.MetaRouteProfiles: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaAttributeProfiles: &config.ItemOpt{
|
||||
utils.MetaAttributeProfiles: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaDispatcherHosts: &config.ItemOpt{
|
||||
utils.MetaDispatcherHosts: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaChargerProfiles: &config.ItemOpt{
|
||||
utils.MetaChargerProfiles: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaDispatcherProfiles: &config.ItemOpt{
|
||||
utils.MetaDispatcherProfiles: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaFilterIndexes: &config.ItemOpt{
|
||||
utils.MetaFilterIndexes: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
Limit: -1},
|
||||
utils.MetaLoadIDs: &config.ItemOpt{
|
||||
utils.MetaLoadIDs: {
|
||||
Replicate: false,
|
||||
Remote: false,
|
||||
TTL: time.Duration(0),
|
||||
|
||||
@@ -132,5 +132,5 @@ func (routeS *RouteService) ServiceName() string {
|
||||
|
||||
// ShouldRun returns if the service should be running
|
||||
func (routeS *RouteService) ShouldRun() bool {
|
||||
return routeS.cfg.RouteCfg().Enabled
|
||||
return routeS.cfg.RouteSCfg().Enabled
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestSupplierSReload(t *testing.T) {
|
||||
srvMngr := servmanager.NewServiceManager(cfg, engineShutdown)
|
||||
db := NewDataDBService(cfg, nil)
|
||||
sts := NewStatService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil)
|
||||
supS := NewSupplierService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil)
|
||||
supS := NewRouteService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil)
|
||||
engine.NewConnManager(cfg, nil)
|
||||
srvMngr.AddServices(supS, sts,
|
||||
NewLoaderService(cfg, db, filterSChan, server, engineShutdown, make(chan rpcclient.ClientConnector, 1), nil), db)
|
||||
@@ -69,7 +69,7 @@ func TestSupplierSReload(t *testing.T) {
|
||||
var reply string
|
||||
if err := cfg.V1ReloadConfigFromPath(&config.ConfigReloadWithArgDispatcher{
|
||||
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongonew"),
|
||||
Section: config.SupplierSJson,
|
||||
Section: config.RouteSJson,
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
@@ -82,8 +82,8 @@ func TestSupplierSReload(t *testing.T) {
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
cfg.SupplierSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.SupplierSJson) <- struct{}{}
|
||||
cfg.RouteSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.RouteSJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if supS.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
|
||||
@@ -156,7 +156,7 @@ func (srvMngr *ServiceManager) StartServices() (err error) {
|
||||
utils.ThresholdS: srvMngr.GetConfig().ThresholdSCfg().Enabled,
|
||||
utils.StatS: srvMngr.GetConfig().StatSCfg().Enabled,
|
||||
utils.ResourceS: srvMngr.GetConfig().ResourceSCfg().Enabled,
|
||||
utils.RouteS: srvMngr.GetConfig().RouteCfg().Enabled,
|
||||
utils.RouteS: srvMngr.GetConfig().RouteSCfg().Enabled,
|
||||
utils.SchedulerS: srvMngr.GetConfig().SchedulerCfg().Enabled,
|
||||
utils.RALService: srvMngr.GetConfig().RalsCfg().Enabled,
|
||||
utils.CDRServer: srvMngr.GetConfig().CdrsCfg().Enabled,
|
||||
|
||||
Reference in New Issue
Block a user