mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
improving coverage tests at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
64c6d3358f
commit
8d2450ecea
@@ -20,25 +20,19 @@ package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestV1LoadCache(t *testing.T) {
|
||||
defer func() {
|
||||
InitCache(nil)
|
||||
}()
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
Cache.Clear(nil)
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
dm.cacheCfg[utils.CacheThresholds].Precache = true
|
||||
thd := &Threshold{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TH_1",
|
||||
Hits: 0,
|
||||
}
|
||||
if err := dm.SetThreshold(thd); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
args := utils.AttrReloadCacheWithArgDispatcher{
|
||||
ArgDispatcher: &utils.ArgDispatcher{},
|
||||
AttrReloadCache: utils.AttrReloadCache{
|
||||
@@ -47,6 +41,14 @@ func TestV1LoadCache(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
loadIds := map[string]int64{
|
||||
utils.CacheThresholdProfiles: time.Now().Unix(),
|
||||
utils.CacheStatQueueProfiles: time.Now().Unix(),
|
||||
utils.CacheChargerProfiles: time.Now().Unix(),
|
||||
}
|
||||
if err := dm.SetLoadIDs(loadIds); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cacheS := NewCacheS(cfg, dm)
|
||||
var reply string
|
||||
if err := cacheS.V1LoadCache(args, &reply); err != nil {
|
||||
@@ -59,37 +61,102 @@ func TestV1LoadCache(t *testing.T) {
|
||||
func TestCacheV1ReloadCache(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
defer func() {
|
||||
InitCache(cfg.CacheCfg())
|
||||
InitCache(nil)
|
||||
}()
|
||||
Cache.Clear(nil)
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
|
||||
chS := NewCacheS(cfg, dm)
|
||||
attrs := utils.AttrReloadCacheWithArgDispatcher{
|
||||
AttrReloadCache: utils.AttrReloadCache{
|
||||
ArgsCache: utils.ArgsCache{
|
||||
FilterIDs: []string{"DSP_FLTR"},
|
||||
FilterIDs: []string{"DSP_FLT"},
|
||||
},
|
||||
},
|
||||
}
|
||||
fltr := &Filter{
|
||||
ID: "DSP_FLTR",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "DSP_FLT",
|
||||
Rules: []*FilterRule{
|
||||
{Type: utils.MetaString,
|
||||
Element: "~*req.Account",
|
||||
Values: []string{"1001"},
|
||||
{
|
||||
Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account,
|
||||
Type: utils.MetaString,
|
||||
Values: []string{"2009"},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dm.SetFilter(fltr); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
Cache = db.db
|
||||
if _, err := GetFilter(dm, "cgrates.org", "DSP_FLT", false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
var reply string
|
||||
if err := chS.V1ReloadCache(attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expected ok ,received %v", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheSV1FlushCache(t *testing.T) {
|
||||
defer func() {
|
||||
InitCache(nil)
|
||||
}()
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
chS := NewCacheS(cfg, dm)
|
||||
args := utils.AttrReloadCacheWithArgDispatcher{
|
||||
AttrReloadCache: utils.AttrReloadCache{
|
||||
ArgsCache: utils.ArgsCache{
|
||||
DestinationIDs: []string{"DST1"},
|
||||
RatingPlanIDs: []string{"RP1"},
|
||||
ResourceIDs: []string{"RSC1"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
loadIds := map[string]int64{
|
||||
utils.CacheAttributeProfiles: time.Now().UnixNano(),
|
||||
utils.CacheSupplierProfiles: time.Now().UnixNano(),
|
||||
}
|
||||
if err := dm.SetLoadIDs(loadIds); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
var reply string
|
||||
if err := chS.V1FlushCache(args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expected ok,recieved %v", reply)
|
||||
}
|
||||
for id := range loadIds {
|
||||
if _, has := Cache.Get(utils.CacheLoadIDs, id); !has {
|
||||
t.Error("Load not stored in cache")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadDataDbCache(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
rp := &RatingPlan{
|
||||
Id: "RT_PLAN1",
|
||||
Timings: map[string]*RITiming{},
|
||||
Ratings: map[string]*RIRate{
|
||||
"asjkilj": {
|
||||
ConnectFee: 10,
|
||||
RoundingMethod: utils.ROUNDING_UP,
|
||||
RoundingDecimals: 1,
|
||||
MaxCost: 10,
|
||||
},
|
||||
},
|
||||
DestinationRates: map[string]RPRateList{},
|
||||
}
|
||||
if err := dm.SetRatingPlan(rp, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := dm.PreloadCacheForPrefix(utils.RATING_PLAN_PREFIX); err != nil {
|
||||
t.Error(nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1751,3 +1751,128 @@ func TestComputeDispatcherIndexes(t *testing.T) {
|
||||
t.Errorf("Expected %v,Received %v", utils.ToJSON(expIndexes), utils.ToJSON(fltrIndexer.indexes))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveItemFromIndexSQP(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
fltr := &Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_1",
|
||||
Rules: []*FilterRule{
|
||||
{
|
||||
Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account,
|
||||
Type: utils.MetaString,
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
if err := dm.SetFilter(fltr); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
sqs := &StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "DistinctMetricProfile",
|
||||
QueueLength: 10,
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
TTL: time.Duration(10) * time.Second,
|
||||
Metrics: []*MetricWithFilters{
|
||||
{
|
||||
MetricID: utils.MetaDDC,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{utils.META_NONE},
|
||||
Stored: true,
|
||||
Weight: 20,
|
||||
}
|
||||
if err := dm.SetStatQueueProfile(sqs, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fltrIndexer := NewFilterIndexer(dm, utils.StatQueueProfilePrefix, sqs.Tenant)
|
||||
if err := fltrIndexer.RemoveItemFromIndex(sqs.Tenant, sqs.ID, []string{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveItemFromIndexSPP(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
fltr := &Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_SUPP_1",
|
||||
Rules: []*FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Supplier",
|
||||
Values: []string{"SupplierProfile1"},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dm.SetFilter(fltr); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
spp := &SupplierProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SPL_ACNT_1001",
|
||||
FilterIDs: []string{"FLTR_SUPP_1"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2017, 11, 27, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
Sorting: utils.MetaWeight,
|
||||
SortingParameters: []string{},
|
||||
Suppliers: []*Supplier{
|
||||
{
|
||||
ID: "supplier1",
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
if err := dm.SetSupplierProfile(spp, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fltrIndexer := NewFilterIndexer(dm, utils.SupplierProfilePrefix, spp.Tenant)
|
||||
if err := fltrIndexer.RemoveItemFromIndex(spp.Tenant, spp.ID, []string{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveItemFromIndexDP(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
fltr := &Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "DSP_FLT",
|
||||
Rules: []*FilterRule{
|
||||
{
|
||||
Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Account,
|
||||
Type: utils.MetaString,
|
||||
Values: []string{"2009"},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dm.SetFilter(fltr); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
dpp := &DispatcherProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "DSP_Test1",
|
||||
FilterIDs: []string{"DSP_FLT"},
|
||||
Strategy: utils.MetaFirst,
|
||||
Subsystems: []string{utils.MetaAttributes, utils.MetaSessionS},
|
||||
Weight: 20,
|
||||
}
|
||||
if err := dm.SetDispatcherProfile(dpp, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fltrIndexer := NewFilterIndexer(dm, utils.DispatcherProfilePrefix, dpp.Tenant)
|
||||
if err := fltrIndexer.RemoveItemFromIndex(dpp.Tenant, dpp.ID, []string{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user