Update filterindexer test

This commit is contained in:
TeoV
2018-03-12 04:30:23 -04:00
committed by Dan Christian Bogos
parent 037bb1f0d8
commit 1188bbf4ca
2 changed files with 58 additions and 8 deletions

View File

@@ -56,6 +56,10 @@ func (rfi *FilterIndexer) ChangedKeys(reverse bool) utils.StringMap {
// IndexTPFilter parses reqFltrs, adding itemID in the indexes and marks the changed keys in chngdIndxKeys
func (rfi *FilterIndexer) IndexTPFilter(tpFltr *utils.TPFilterProfile, itemID string) {
concatKey := utils.ConcatenatedKey(utils.MetaDefault, utils.ANY, utils.ANY)
if _, hasIt := rfi.indexes[concatKey]; !hasIt {
rfi.indexes[concatKey] = make(utils.StringMap)
}
for _, fltr := range tpFltr.Filters {
switch fltr.Type {
case MetaString:
@@ -87,10 +91,6 @@ func (rfi *FilterIndexer) IndexTPFilter(tpFltr *utils.TPFilterProfile, itemID st
}
rfi.chngdRevIndxKeys[itemID] = true
default:
concatKey := utils.ConcatenatedKey(utils.MetaDefault, utils.ANY, utils.ANY)
if _, hasIt := rfi.indexes[concatKey]; !hasIt {
rfi.indexes[concatKey] = make(utils.StringMap)
}
if _, hasIt := rfi.reveseIndex[itemID]; !hasIt {
rfi.reveseIndex[itemID] = make(utils.StringMap)
}

View File

@@ -806,19 +806,37 @@ func testITTestIndexingWithEmptyFltrID(t *testing.T) {
Weight: 1.4,
ActionIDs: []string{},
}
th2 := &ThresholdProfile{
Tenant: "cgrates.org",
ID: "THD_Test2",
ActivationInterval: &utils.ActivationInterval{},
FilterIDs: []string{},
Recurrent: true,
MinSleep: time.Duration(0 * time.Second),
Blocker: true,
Weight: 1.4,
ActionIDs: []string{},
}
if err := dataManager.SetThresholdProfile(th, true); err != nil {
t.Error(err)
}
if err := dataManager.SetThresholdProfile(th2, true); err != nil {
t.Error(err)
}
eIdxes := map[string]utils.StringMap{
"*default:*any:*any": utils.StringMap{
"THD_Test": true,
"THD_Test": true,
"THD_Test2": true,
},
}
reverseIdxes := map[string]utils.StringMap{
"THD_Test": utils.StringMap{
"*default:*any:*any": true,
},
"THD_Test2": utils.StringMap{
"*default:*any:*any": true,
},
}
rfi := NewFilterIndexer(onStor, utils.ThresholdProfilePrefix, th.Tenant)
if rcvIdx, err := dataManager.GetFilterIndexes(
@@ -840,7 +858,8 @@ func testITTestIndexingWithEmptyFltrID(t *testing.T) {
}
}
eMp := utils.StringMap{
"THD_Test": true,
"THD_Test": true,
"THD_Test2": true,
}
if rcvMp, err := dataManager.MatchFilterIndex(utils.CacheThresholdFilterIndexes, th.Tenant,
utils.MetaDefault, utils.META_ANY, utils.META_ANY); err != nil {
@@ -874,19 +893,49 @@ func testITTestIndexingWithEmptyFltrID2(t *testing.T) {
},
Weight: 20,
}
splProfile2 := &SupplierProfile{
Tenant: "cgrates.org",
ID: "SPL_Weight2",
FilterIDs: []string{},
ActivationInterval: &utils.ActivationInterval{
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
},
Sorting: "*weight",
SortingParameters: []string{},
Suppliers: []*Supplier{
&Supplier{
ID: "supplier1",
FilterIDs: []string{""},
AccountIDs: []string{""},
RatingPlanIDs: []string{""},
ResourceIDs: []string{""},
StatIDs: []string{""},
Weight: 10,
SupplierParameters: "",
},
},
Weight: 20,
}
if err := dataManager.SetSupplierProfile(splProfile, true); err != nil {
t.Error(err)
}
if err := dataManager.SetSupplierProfile(splProfile2, true); err != nil {
t.Error(err)
}
eIdxes := map[string]utils.StringMap{
"*default:*any:*any": utils.StringMap{
"SPL_Weight": true,
"SPL_Weight": true,
"SPL_Weight2": true,
},
}
reverseIdxes := map[string]utils.StringMap{
"SPL_Weight": utils.StringMap{
"*default:*any:*any": true,
},
"SPL_Weight2": utils.StringMap{
"*default:*any:*any": true,
},
}
rfi := NewFilterIndexer(onStor, utils.SupplierProfilePrefix, splProfile.Tenant)
if rcvIdx, err := dataManager.GetFilterIndexes(
@@ -908,7 +957,8 @@ func testITTestIndexingWithEmptyFltrID2(t *testing.T) {
}
}
eMp := utils.StringMap{
"SPL_Weight": true,
"SPL_Weight": true,
"SPL_Weight2": true,
}
if rcvMp, err := dataManager.MatchFilterIndex(utils.CacheSupplierFilterIndexes,
splProfile.Tenant, utils.MetaDefault, utils.META_ANY, utils.META_ANY); err != nil {