Tested cases for indexes as DynamicDP

This commit is contained in:
porosnicuadrian
2021-05-26 16:03:21 +03:00
committed by Dan Christian Bogos
parent e36d56e953
commit b21c3e1ca3
2 changed files with 106 additions and 2 deletions

View File

@@ -1262,3 +1262,108 @@ func TestFilterPassCronExpParseDPErr(t *testing.T) {
t.Error("should not be passing")
}
}
func TestFilterIndexesCheckingDynamicPathToNotIndex(t *testing.T) {
Cache.Clear(nil)
cfg := config.NewDefaultCGRConfig()
db := NewInternalDB(nil, nil, true)
dm := NewDataManager(db, cfg.CacheCfg(), nil)
//set 4 attr profiles with different filters to index them
attrPrf1 := &AttributeProfile{
Tenant: "cgrates.org",
ID: "AttrPrf1",
FilterIDs: []string{"*string:~*req.Account:1001", "*ai:~*req.AnswerTime:2014-07-29T15:00:00Z", "*string:~*opts.*context:con1|con2|con3"},
Attributes: []*Attribute{
{
FilterIDs: []string{"*string:~*req.Field1:Initial"},
Path: utils.MetaReq + utils.NestingSep + "Field1",
Type: utils.MetaVariable,
Value: config.NewRSRParsersMustCompile("Sub1", utils.InfieldSep),
},
},
Blocker: true,
Weight: 20,
}
attrPrf2 := &AttributeProfile{
Tenant: "cgrates.org",
ID: "AttrPrf2",
FilterIDs: []string{"*gte:~*resource.RES_GRP1.Available:~*stats.STS_PRF1.*tcc"},
Attributes: []*Attribute{
{
Path: utils.MetaReq + utils.NestingSep + "Password",
Type: utils.MetaVariable,
Value: config.NewRSRParsersMustCompile("admin", utils.InfieldSep),
},
},
Blocker: true,
Weight: 20,
}
attrPrf3 := &AttributeProfile{
Tenant: "cgrates.org",
ID: "AttrPrf3",
FilterIDs: []string{"*prefix:~*req.Destination:1007", "*string:~*req.Account:1001", "*gte:~*opts.TotalCost:~*stats.STS_PRF1.*tcc"},
Attributes: []*Attribute{
{
Path: utils.MetaReq + utils.NestingSep + "RequestType",
Type: utils.MetaVariable,
Value: config.NewRSRParsersMustCompile("*rated", utils.InfieldSep),
},
},
Blocker: true,
Weight: 20,
}
attrPrf4 := &AttributeProfile{
Tenant: "cgrates.org",
ID: "AttrPrf4",
FilterIDs: []string{"*prefix:~*req.Destination:1007", "*lt:~*resource.RES_GRP1.Available:10"},
Attributes: []*Attribute{
{
Path: utils.MetaReq + utils.NestingSep + "TCC",
Type: utils.MetaVariable,
Value: config.NewRSRParsersMustCompile("203", utils.InfieldSep),
},
},
Blocker: true,
Weight: 20,
}
if err := dm.SetAttributeProfile(context.Background(), attrPrf1, true); err != nil {
t.Error(err)
} else if err := dm.SetAttributeProfile(context.Background(), attrPrf2, true); err != nil {
t.Error(err)
} else if err := dm.SetAttributeProfile(context.Background(), attrPrf3, true); err != nil {
t.Error(err)
} else if err := dm.SetAttributeProfile(context.Background(), attrPrf4, true); err != nil {
t.Error(err)
}
expIDx := map[string]utils.StringSet{
"*prefix:*req.Destination:1007": {
"AttrPrf3": {},
"AttrPrf4": {},
},
"*string:*req.Account:1001": {
"AttrPrf3": {},
"AttrPrf1": {},
},
"*string:*opts.*context:con1": {
"AttrPrf1": {},
},
"*string:*opts.*context:con2": {
"AttrPrf1": {},
},
"*string:*opts.*context:con3": {
"AttrPrf1": {},
},
}
if fltrIDx, err := dm.GetIndexes(context.Background(), utils.CacheAttributeFilterIndexes,
"cgrates.org", utils.EmptyString, true, true); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expIDx, fltrIDx) {
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIDx), utils.ToJSON(fltrIDx))
}
}

View File

@@ -35,8 +35,7 @@ var (
ToNotBeIndexed = []string{utils.DynamicDataPrefix + utils.MetaAccounts,
utils.DynamicDataPrefix + utils.MetaStats,
utils.DynamicDataPrefix + utils.MetaResources,
utils.DynamicDataPrefix + utils.MetaLibPhoneNumber,
utils.DynamicDataPrefix + utils.MetaAsm}
utils.DynamicDataPrefix + utils.MetaLibPhoneNumber}
)
// newFilterIndex will get the index from DataManager if is not found it will create it