mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added unit tests for composeArgsReload
This commit is contained in:
committed by
Dan Christian Bogos
parent
cd14ab0a2b
commit
ee78db2617
@@ -1338,51 +1338,12 @@ func (apierSv1 *APIerSv1) ReplayFailedPosts(args *ArgsReplyFailedPosts, reply *s
|
||||
return nil
|
||||
}
|
||||
|
||||
// CallCache caching the item based on cacheopt
|
||||
// visible in APIerSv2
|
||||
func (apierSv1 *APIerSv1) CallCache(cacheopt *string, tnt, cacheID, itemID string, filters *[]string, contexts []string, opts map[string]interface{}) (err error) {
|
||||
var reply, method string
|
||||
var args interface{}
|
||||
cacheOpt := apierSv1.Config.GeneralCfg().DefaultCaching
|
||||
if cacheopt != nil && *cacheopt != utils.EmptyString {
|
||||
cacheOpt = *cacheopt
|
||||
}
|
||||
switch cacheOpt {
|
||||
case utils.META_NONE:
|
||||
return
|
||||
case utils.MetaReload:
|
||||
method = utils.CacheSv1ReloadCache
|
||||
if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
|
||||
return
|
||||
}
|
||||
case utils.MetaLoad:
|
||||
method = utils.CacheSv1LoadCache
|
||||
if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
|
||||
return
|
||||
}
|
||||
case utils.MetaRemove:
|
||||
method = utils.CacheSv1RemoveItems
|
||||
if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
|
||||
return
|
||||
}
|
||||
case utils.MetaClear:
|
||||
method = utils.CacheSv1Clear
|
||||
args = &utils.AttrCacheIDsWithOpts{
|
||||
TenantArg: utils.TenantArg{Tenant: tnt},
|
||||
CacheIDs: []string{cacheID, utils.CacheInstanceToCacheIndex[cacheID]},
|
||||
Opts: opts,
|
||||
}
|
||||
}
|
||||
return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil,
|
||||
method, args, &reply)
|
||||
}
|
||||
|
||||
func (apierSv1 *APIerSv1) GetLoadIDs(args *string, reply *map[string]int64) (err error) {
|
||||
if loadIDs, err := apierSv1.DataManager.GetItemLoadIDs(*args, false); err != nil {
|
||||
return err
|
||||
} else {
|
||||
*reply = loadIDs
|
||||
var loadIDs map[string]int64
|
||||
if loadIDs, err = apierSv1.DataManager.GetItemLoadIDs(*args, false); err != nil {
|
||||
return
|
||||
}
|
||||
*reply = loadIDs
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,46 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// CallCache caching the item based on cacheopt
|
||||
// visible in APIerSv2
|
||||
func (apierSv1 *APIerSv1) CallCache(cacheopt *string, tnt, cacheID, itemID string,
|
||||
filters *[]string, contexts []string, opts map[string]interface{}) (err error) {
|
||||
var reply, method string
|
||||
var args interface{}
|
||||
cacheOpt := apierSv1.Config.GeneralCfg().DefaultCaching
|
||||
if cacheopt != nil && *cacheopt != utils.EmptyString {
|
||||
cacheOpt = *cacheopt
|
||||
}
|
||||
switch cacheOpt {
|
||||
case utils.META_NONE:
|
||||
return
|
||||
case utils.MetaReload:
|
||||
method = utils.CacheSv1ReloadCache
|
||||
if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
|
||||
return
|
||||
}
|
||||
case utils.MetaLoad:
|
||||
method = utils.CacheSv1LoadCache
|
||||
if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
|
||||
return
|
||||
}
|
||||
case utils.MetaRemove:
|
||||
method = utils.CacheSv1RemoveItems
|
||||
if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
|
||||
return
|
||||
}
|
||||
case utils.MetaClear:
|
||||
method = utils.CacheSv1Clear
|
||||
args = &utils.AttrCacheIDsWithOpts{
|
||||
TenantArg: utils.TenantArg{Tenant: tnt},
|
||||
CacheIDs: []string{cacheID, utils.CacheInstanceToCacheIndex[cacheID]},
|
||||
Opts: opts,
|
||||
}
|
||||
}
|
||||
return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil,
|
||||
method, args, &reply)
|
||||
}
|
||||
|
||||
// composeArgsReload add the ItemID to AttrReloadCache
|
||||
// for a specific CacheID
|
||||
func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterIDs *[]string, contexts []string, opts map[string]interface{}) (rpl utils.AttrReloadCacheWithOpts, err error) {
|
||||
@@ -39,7 +79,7 @@ func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterI
|
||||
return
|
||||
}
|
||||
// popultate the indexes
|
||||
idxCacheID := utils.CacheInstanceToCacheIndex[cacheID]
|
||||
idxCacheID := utils.CacheInstanceToArg[utils.CacheInstanceToCacheIndex[cacheID]]
|
||||
if len(*filterIDs) == 0 { // in case we do not have any filters reload the *none filter indexes
|
||||
indxID := utils.ConcatenatedKey(utils.META_NONE, utils.META_ANY, utils.META_ANY)
|
||||
if cacheID != utils.CacheAttributeProfiles &&
|
||||
@@ -51,6 +91,7 @@ func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterI
|
||||
for i, ctx := range contexts {
|
||||
rpl.ArgsCache[idxCacheID][i] = utils.ConcatenatedKey(tnt, ctx, indxID)
|
||||
}
|
||||
return
|
||||
}
|
||||
indxIDs := make([]string, 0, len(*filterIDs))
|
||||
for _, id := range *filterIDs {
|
||||
|
||||
66
apier/v1/libapier_test.go
Normal file
66
apier/v1/libapier_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestComposeArgsReload(t *testing.T) {
|
||||
apv1 := &APIerSv1{DataManager: &engine.DataManager{}}
|
||||
expArgs := utils.AttrReloadCacheWithOpts{
|
||||
Opts: make(map[string]interface{}),
|
||||
TenantArg: utils.TenantArg{Tenant: "cgrates.org"},
|
||||
ArgsCache: map[string][]string{
|
||||
utils.AttributeProfileIDs: {"cgrates.org:ATTR1"},
|
||||
},
|
||||
}
|
||||
|
||||
if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheAttributeProfiles,
|
||||
"cgrates.org:ATTR1", nil, nil, make(map[string]interface{})); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(expArgs, rply) {
|
||||
t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply))
|
||||
}
|
||||
|
||||
expArgs.ArgsCache[utils.AttributeFilterIndexIDs] = []string{"cgrates.org:*cdrs:*none:*any:*any"}
|
||||
|
||||
if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheAttributeProfiles,
|
||||
"cgrates.org:ATTR1", &[]string{}, []string{utils.MetaCDRs}, make(map[string]interface{})); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(expArgs, rply) {
|
||||
t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply))
|
||||
}
|
||||
|
||||
expArgs.ArgsCache[utils.AttributeFilterIndexIDs] = []string{
|
||||
"cgrates.org:*cdrs:*string:*req.Account:1001",
|
||||
"cgrates.org:*cdrs:*prefix:*req.Destination:1001",
|
||||
}
|
||||
|
||||
if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheAttributeProfiles,
|
||||
"cgrates.org:ATTR1", &[]string{"*string:~*req.Account:1001;~req.Subject", "*prefix:1001:~*req.Destination"}, []string{utils.MetaCDRs}, make(map[string]interface{})); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(expArgs, rply) {
|
||||
t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply))
|
||||
}
|
||||
}
|
||||
@@ -112,16 +112,16 @@ var (
|
||||
}
|
||||
|
||||
CacheInstanceToCacheIndex = map[string]string{
|
||||
CacheThresholdFilterIndexes: CacheThresholdProfiles,
|
||||
CacheResourceFilterIndexes: CacheResourceProfiles,
|
||||
CacheStatFilterIndexes: CacheStatQueueProfiles,
|
||||
CacheRouteFilterIndexes: CacheRouteProfiles,
|
||||
CacheAttributeFilterIndexes: CacheAttributeProfiles,
|
||||
CacheChargerFilterIndexes: CacheChargerProfiles,
|
||||
CacheDispatcherFilterIndexes: CacheDispatcherProfiles,
|
||||
CacheRateProfilesFilterIndexes: CacheRateProfiles,
|
||||
// CacheRateFilterIndexes: CacheRates,
|
||||
CacheReverseFilterIndexes: CacheFilters,
|
||||
CacheThresholdProfiles: CacheThresholdFilterIndexes,
|
||||
CacheResourceProfiles: CacheResourceFilterIndexes,
|
||||
CacheStatQueueProfiles: CacheStatFilterIndexes,
|
||||
CacheRouteProfiles: CacheRouteFilterIndexes,
|
||||
CacheAttributeProfiles: CacheAttributeFilterIndexes,
|
||||
CacheChargerProfiles: CacheChargerFilterIndexes,
|
||||
CacheDispatcherProfiles: CacheDispatcherFilterIndexes,
|
||||
CacheRateProfiles: CacheRateProfilesFilterIndexes,
|
||||
CacheFilters: CacheReverseFilterIndexes,
|
||||
// CacheRates: CacheRateFilterIndexes,
|
||||
}
|
||||
|
||||
// NonMonetaryBalances are types of balances which are not handled as monetary
|
||||
|
||||
Reference in New Issue
Block a user