mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Started tested health indexes for the missing/broken cases
This commit is contained in:
committed by
Dan Christian Bogos
parent
5c3798a4b3
commit
a16f6106dc
@@ -3103,7 +3103,7 @@ func (dm *DataManager) GetIndexes(idxItmType, tntCtx, idxKey string,
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite && idxKey != utils.EmptyString && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(idxItmType, utils.ConcatenatedKey(tntCtx, idxKey), nil, []string{tntCtx},
|
||||
true, utils.NonTransactional); errCh != nil {
|
||||
true, utils.NonTransactional); errCh != nil {
|
||||
return nil, errCh
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,3 +388,116 @@ func TestHealthReverseFilter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthIndexThreshold(t *testing.T) {
|
||||
Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
|
||||
// we will set this threshold but without indexing
|
||||
thPrf := &ThresholdProfileWithAPIOpts{
|
||||
ThresholdProfile: &ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestHealthIndexThreshold",
|
||||
FilterIDs: []string{"*string:~*opts.*eventType:AccountUpdate",
|
||||
"*string:~*asm.ID:1002",
|
||||
"*suffix:BrokenFilter:Invalid"},
|
||||
MaxHits: 1,
|
||||
},
|
||||
}
|
||||
if err := dm.SetThresholdProfile(thPrf.ThresholdProfile, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
args := &IndexHealthArgsWith3Ch{}
|
||||
exp := &FilterIHReply{
|
||||
MissingIndexes: map[string][]string{
|
||||
"cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"},
|
||||
"cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"},
|
||||
},
|
||||
BrokenIndexes: map[string][]string{},
|
||||
MissingFilters: map[string][]string{},
|
||||
}
|
||||
if rply, err := GetFltrIdxHealth(dm,
|
||||
ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil),
|
||||
ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil),
|
||||
ltcache.NewCache(args.ObjectCacheLimit, args.ObjectCacheTTL, args.ObjectCacheStaticTTL, nil),
|
||||
utils.CacheThresholdFilterIndexes); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(exp, rply) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
|
||||
}
|
||||
|
||||
indexes := map[string]utils.StringSet{
|
||||
"*prefix:req.InvalidIdx:10": { // obj exist but the index don't
|
||||
"TestHealthIndexThreshold": {},
|
||||
},
|
||||
"*string:*req.Destination:123": { // index is valid but the obj does not exist
|
||||
"InexistingThreshold": {},
|
||||
},
|
||||
}
|
||||
|
||||
// we will set manually some indexes that points to an nil object or index is valid but the obj is missing
|
||||
if err := dm.SetIndexes(utils.CacheThresholdFilterIndexes, "cgrates.org",
|
||||
indexes, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
exp = &FilterIHReply{
|
||||
MissingObjects: []string{"cgrates.org:InexistingThreshold"},
|
||||
MissingIndexes: map[string][]string{
|
||||
"cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"},
|
||||
"cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"},
|
||||
},
|
||||
BrokenIndexes: map[string][]string{
|
||||
"cgrates.org:*prefix:req.InvalidIdx:10": {"TestHealthIndexThreshold"},
|
||||
},
|
||||
MissingFilters: map[string][]string{},
|
||||
}
|
||||
if rply, err := GetFltrIdxHealth(dm,
|
||||
ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil),
|
||||
ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil),
|
||||
ltcache.NewCache(args.ObjectCacheLimit, args.ObjectCacheTTL, args.ObjectCacheStaticTTL, nil),
|
||||
utils.CacheThresholdFilterIndexes); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(exp, rply) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
|
||||
}
|
||||
|
||||
//we will use an inexisting Filter(not inline) for the same ThresholdProfile
|
||||
thPrf = &ThresholdProfileWithAPIOpts{
|
||||
ThresholdProfile: &ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestHealthIndexThreshold",
|
||||
FilterIDs: []string{"*string:~*opts.*eventType:AccountUpdate",
|
||||
"*string:~*asm.ID:1002",
|
||||
"FLTR_1_DOES_NOT_EXIST"},
|
||||
MaxHits: 1,
|
||||
},
|
||||
}
|
||||
if err := dm.SetThresholdProfile(thPrf.ThresholdProfile, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
exp = &FilterIHReply{
|
||||
MissingObjects: []string{"cgrates.org:InexistingThreshold"},
|
||||
MissingIndexes: map[string][]string{
|
||||
"cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"},
|
||||
"cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"},
|
||||
},
|
||||
BrokenIndexes: map[string][]string{
|
||||
"cgrates.org:*prefix:req.InvalidIdx:10": {"TestHealthIndexThreshold"},
|
||||
},
|
||||
MissingFilters: map[string][]string{
|
||||
"cgrates.org:FLTR_1_DOES_NOT_EXIST": {"TestHealthIndexThreshold"},
|
||||
},
|
||||
}
|
||||
if rply, err := GetFltrIdxHealth(dm,
|
||||
ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil),
|
||||
ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil),
|
||||
ltcache.NewCache(args.ObjectCacheLimit, args.ObjectCacheTTL, args.ObjectCacheStaticTTL, nil),
|
||||
utils.CacheThresholdFilterIndexes); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(exp, rply) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user