mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated tests and methods for thresholds.go with tenant default value
This commit is contained in:
committed by
Dan Christian Bogos
parent
0af62ead8d
commit
79c5c99fcb
@@ -62,10 +62,14 @@ func (tSv1 *ThresholdSv1) ProcessEvent(args *engine.ThresholdsArgsProcessEvent,
|
||||
|
||||
// GetThresholdProfile returns a Threshold Profile
|
||||
func (apierSv1 *APIerSv1) GetThresholdProfile(arg *utils.TenantID, reply *engine.ThresholdProfile) (err error) {
|
||||
if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if th, err := apierSv1.DataManager.GetThresholdProfile(arg.Tenant, arg.ID, true, true, utils.NonTransactional); err != nil {
|
||||
tnt := arg.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if th, err := apierSv1.DataManager.GetThresholdProfile(tnt, arg.ID, true, true, utils.NonTransactional); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
} else {
|
||||
*reply = *th
|
||||
@@ -75,10 +79,11 @@ func (apierSv1 *APIerSv1) GetThresholdProfile(arg *utils.TenantID, reply *engine
|
||||
|
||||
// GetThresholdProfileIDs returns list of thresholdProfile IDs registered for a tenant
|
||||
func (apierSv1 *APIerSv1) GetThresholdProfileIDs(args *utils.PaginatorWithTenant, thPrfIDs *[]string) error {
|
||||
if missing := utils.MissingStructFields(args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
prfx := utils.ThresholdProfilePrefix + args.Tenant + ":"
|
||||
prfx := utils.ThresholdProfilePrefix + tnt + ":"
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -97,11 +102,12 @@ func (apierSv1 *APIerSv1) GetThresholdProfileIDs(args *utils.PaginatorWithTenant
|
||||
// GetThresholdProfileIDsCount sets in reply var the total number of ThresholdProfileIDs registered for the received tenant
|
||||
// returns ErrNotFound in case of 0 ThresholdProfileIDs
|
||||
func (apierSv1 *APIerSv1) GetThresholdProfileIDsCount(args *utils.TenantWithOpts, reply *int) (err error) {
|
||||
if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
var keys []string
|
||||
prfx := utils.ThresholdProfilePrefix + args.Tenant + ":"
|
||||
prfx := utils.ThresholdProfilePrefix + tnt + ":"
|
||||
if keys, err = apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -114,9 +120,12 @@ func (apierSv1 *APIerSv1) GetThresholdProfileIDsCount(args *utils.TenantWithOpts
|
||||
|
||||
// SetThresholdProfile alters/creates a ThresholdProfile
|
||||
func (apierSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdWithCache, reply *string) error {
|
||||
if missing := utils.MissingStructFields(args.ThresholdProfile, []string{"Tenant", "ID"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(args.ThresholdProfile, []string{utils.ID}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if args.Tenant == utils.EmptyString {
|
||||
args.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.DataManager.SetThresholdProfile(args.ThresholdProfile, true); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
@@ -146,18 +155,22 @@ func (apierSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdWithCache, r
|
||||
|
||||
// Remove a specific Threshold Profile
|
||||
func (apierSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithCache, reply *string) error {
|
||||
if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.DataManager.RemoveThresholdProfile(args.Tenant, args.ID, utils.NonTransactional, true); err != nil {
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.DataManager.RemoveThresholdProfile(tnt, args.ID, utils.NonTransactional, true); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
//handle caching for ThresholdProfile
|
||||
if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheThresholdProfiles,
|
||||
args.TenantID(), nil, nil, args.Opts); err != nil {
|
||||
if err := apierSv1.CallCache(args.Cache, tnt, utils.CacheThresholdProfiles,
|
||||
utils.ConcatenatedKey(tnt, args.ID), nil, nil, args.Opts); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
if err := apierSv1.DataManager.RemoveThreshold(args.Tenant, args.ID, utils.NonTransactional); err != nil {
|
||||
if err := apierSv1.DataManager.RemoveThreshold(tnt, args.ID, utils.NonTransactional); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
//generate a loadID for CacheThresholdProfiles and CacheThresholds and store it in database
|
||||
@@ -167,8 +180,8 @@ func (apierSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithCache,
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
//handle caching for Threshold
|
||||
if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheThresholds,
|
||||
args.TenantID(), nil, nil, args.Opts); err != nil {
|
||||
if err := apierSv1.CallCache(args.Cache, tnt, utils.CacheThresholds,
|
||||
utils.ConcatenatedKey(tnt, args.ID), nil, nil, args.Opts); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -233,12 +233,16 @@ var (
|
||||
testV1TSGetThresholdsAfterProcess,
|
||||
testV1TSGetThresholdsAfterRestart,
|
||||
testv1TSGetThresholdProfileIDs,
|
||||
testv1TSGetThresholdProfileIDsCount,
|
||||
testV1TSSetThresholdProfileBrokenReference,
|
||||
testV1TSSetThresholdProfile,
|
||||
testV1TSUpdateThresholdProfile,
|
||||
testV1TSRemoveThresholdProfile,
|
||||
testV1TSMaxHits,
|
||||
testV1TSUpdateSnooze,
|
||||
testV1TSGetThresholdProfileWithoutTenant,
|
||||
testV1TSRemThresholdProfileWithoutTenant,
|
||||
testV1TSProcessEventWithoutTenant,
|
||||
testV1TSStopEngine,
|
||||
}
|
||||
)
|
||||
@@ -457,6 +461,11 @@ func testV1TSSetThresholdProfileBrokenReference(t *testing.T) {
|
||||
func testv1TSGetThresholdProfileIDs(t *testing.T) {
|
||||
expected := []string{"THD_STATS_1", "THD_STATS_2", "THD_STATS_3", "THD_RES_1", "THD_CDRS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED"}
|
||||
var result []string
|
||||
if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(expected) != len(result) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expected, result)
|
||||
}
|
||||
if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(expected) != len(result) {
|
||||
@@ -613,6 +622,20 @@ func testV1TSMaxHits(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(eTd.Hits, ths[0].Hits) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eTd.Hits, ths[0].Hits)
|
||||
}
|
||||
|
||||
//check threshold for event without tenant
|
||||
thEvent.Tenant = utils.EmptyString
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdsForEvent,
|
||||
thEvent, &ths); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(ths) != 1 {
|
||||
t.Errorf("expecting: 1, received: %+v", utils.ToJSON(ths))
|
||||
} else if !reflect.DeepEqual(eTd.TenantID(), ths[0].TenantID()) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eTd.TenantID(), ths[0].TenantID())
|
||||
} else if !reflect.DeepEqual(eTd.Hits, ths[0].Hits) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eTd.Hits, ths[0].Hits)
|
||||
}
|
||||
|
||||
//check threshold after second process ( hits : 2)
|
||||
eTd.Hits = 2
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
|
||||
@@ -725,3 +748,93 @@ func testV1TSStopEngine(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1TSGetThresholdProfileWithoutTenant(t *testing.T) {
|
||||
tPrfl = &engine.ThresholdWithCache{
|
||||
ThresholdProfile: &engine.ThresholdProfile{
|
||||
ID: "randomID",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
MaxHits: -1,
|
||||
MinSleep: time.Duration(5 * time.Minute),
|
||||
Blocker: false,
|
||||
Weight: 20.0,
|
||||
ActionIDs: []string{"ACT_1"},
|
||||
Async: true,
|
||||
},
|
||||
}
|
||||
var reply string
|
||||
if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
tPrfl.ThresholdProfile.Tenant = "cgrates.org"
|
||||
var result *engine.ThresholdProfile
|
||||
if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
|
||||
&utils.TenantID{ID: "randomID"},
|
||||
&result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tPrfl.ThresholdProfile, result) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(tPrfl.ThresholdProfile), utils.ToJSON(result))
|
||||
}
|
||||
}
|
||||
|
||||
func testV1TSRemThresholdProfileWithoutTenant(t *testing.T) {
|
||||
var reply string
|
||||
if err := tSv1Rpc.Call(utils.APIerSv1RemoveThresholdProfile,
|
||||
&utils.TenantIDWithCache{ID: "randomID"},
|
||||
&reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
var result *engine.ThresholdProfile
|
||||
if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
|
||||
&utils.TenantID{ID: "randomID"},
|
||||
&result); err == nil || utils.ErrNotFound.Error() != err.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testv1TSGetThresholdProfileIDsCount(t *testing.T) {
|
||||
var reply int
|
||||
if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDsCount,
|
||||
&utils.TenantWithOpts{},
|
||||
&reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != 7 {
|
||||
t.Errorf("Expected 7, received %+v", reply)
|
||||
}
|
||||
if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDsCount,
|
||||
&utils.TenantWithOpts{Tenant: "cgrates.org"},
|
||||
&reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != 7 {
|
||||
t.Errorf("Expected 7, received %+v", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1TSProcessEventWithoutTenant(t *testing.T) {
|
||||
var ids []string
|
||||
eIDs := []string{"TH4"}
|
||||
thEvent := &engine.ThresholdsArgsProcessEvent{
|
||||
ThresholdIDs: []string{"TH4"},
|
||||
CGREventWithOpts: &utils.CGREventWithOpts{
|
||||
CGREvent: &utils.CGREvent{ // hitting TH4
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
"CustomEv": "SnoozeEv",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(ids, eIDs) {
|
||||
t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func (tS *ThresholdService) StoreThreshold(t *Threshold) (err error) {
|
||||
}
|
||||
|
||||
// matchingThresholdsForEvent returns ordered list of matching thresholds which are active for an Event
|
||||
func (tS *ThresholdService) matchingThresholdsForEvent(args *ThresholdsArgsProcessEvent) (ts Thresholds, err error) {
|
||||
func (tS *ThresholdService) matchingThresholdsForEvent(tnt string, args *ThresholdsArgsProcessEvent) (ts Thresholds, err error) {
|
||||
evNm := utils.MapStorage{
|
||||
utils.MetaReq: args.Event,
|
||||
utils.MetaOpts: args.Opts,
|
||||
@@ -243,7 +243,7 @@ func (tS *ThresholdService) matchingThresholdsForEvent(args *ThresholdsArgsProce
|
||||
tS.cgrcfg.ThresholdSCfg().StringIndexedFields,
|
||||
tS.cgrcfg.ThresholdSCfg().PrefixIndexedFields,
|
||||
tS.cgrcfg.ThresholdSCfg().SuffixIndexedFields,
|
||||
tS.dm, utils.CacheThresholdFilterIndexes, args.Tenant,
|
||||
tS.dm, utils.CacheThresholdFilterIndexes, tnt,
|
||||
tS.cgrcfg.ThresholdSCfg().IndexedSelects,
|
||||
tS.cgrcfg.ThresholdSCfg().NestedFields,
|
||||
)
|
||||
@@ -253,7 +253,7 @@ func (tS *ThresholdService) matchingThresholdsForEvent(args *ThresholdsArgsProce
|
||||
}
|
||||
ts = make(Thresholds, 0, len(tIDs))
|
||||
for tID := range tIDs {
|
||||
tPrfl, err := tS.dm.GetThresholdProfile(args.Tenant, tID, true, true, utils.NonTransactional)
|
||||
tPrfl, err := tS.dm.GetThresholdProfile(tnt, tID, true, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
continue
|
||||
@@ -264,7 +264,7 @@ func (tS *ThresholdService) matchingThresholdsForEvent(args *ThresholdsArgsProce
|
||||
!tPrfl.ActivationInterval.IsActiveAtTime(*args.Time) { // not active
|
||||
continue
|
||||
}
|
||||
if pass, err := tS.filterS.Pass(args.Tenant, tPrfl.FilterIDs,
|
||||
if pass, err := tS.filterS.Pass(tnt, tPrfl.FilterIDs,
|
||||
evNm); err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
@@ -330,8 +330,8 @@ func (attr *ThresholdsArgsProcessEvent) Clone() *ThresholdsArgsProcessEvent {
|
||||
}
|
||||
|
||||
// processEvent processes a new event, dispatching to matching thresholds
|
||||
func (tS *ThresholdService) processEvent(args *ThresholdsArgsProcessEvent) (thresholdsIDs []string, err error) {
|
||||
matchTs, err := tS.matchingThresholdsForEvent(args)
|
||||
func (tS *ThresholdService) processEvent(tnt string, args *ThresholdsArgsProcessEvent) (thresholdsIDs []string, err error) {
|
||||
matchTs, err := tS.matchingThresholdsForEvent(tnt, args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -344,7 +344,7 @@ func (tS *ThresholdService) processEvent(args *ThresholdsArgsProcessEvent) (thre
|
||||
if err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<ThresholdService> threshold: %s, ignoring event: %s, error: %s",
|
||||
t.TenantID(), args.CGREvent.TenantID(), err.Error()))
|
||||
t.TenantID(), utils.ConcatenatedKey(tnt, args.CGREvent.ID), err.Error()))
|
||||
withErrors = true
|
||||
continue
|
||||
}
|
||||
@@ -390,13 +390,17 @@ func (tS *ThresholdService) V1ProcessEvent(args *ThresholdsArgsProcessEvent, rep
|
||||
if args.CGREvent == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.CGREventString)
|
||||
}
|
||||
if missing := utils.MissingStructFields(args, []string{utils.Tenant, utils.ID}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.Event)
|
||||
}
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = tS.cgrcfg.GeneralCfg().DefaultTenant
|
||||
}
|
||||
var ids []string
|
||||
if ids, err = tS.processEvent(args); err != nil {
|
||||
if ids, err = tS.processEvent(tnt, args); err != nil {
|
||||
return
|
||||
}
|
||||
*reply = ids
|
||||
@@ -408,13 +412,17 @@ func (tS *ThresholdService) V1GetThresholdsForEvent(args *ThresholdsArgsProcessE
|
||||
if args.CGREvent == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.CGREventString)
|
||||
}
|
||||
if missing := utils.MissingStructFields(args, []string{utils.Tenant, utils.ID}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.Event)
|
||||
}
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = tS.cgrcfg.GeneralCfg().DefaultTenant
|
||||
}
|
||||
var ts Thresholds
|
||||
if ts, err = tS.matchingThresholdsForEvent(args); err == nil {
|
||||
if ts, err = tS.matchingThresholdsForEvent(tnt, args); err == nil {
|
||||
*reply = ts
|
||||
}
|
||||
return
|
||||
|
||||
@@ -242,7 +242,7 @@ func TestThresholdsCache(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestThresholdsmatchingThresholdsForEvent(t *testing.T) {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[0]); err != nil {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[0].Tenant, argsGetThresholds[0]); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(ths[0].Tenant, thMatched[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ths[0].Tenant, thMatched[0].Tenant)
|
||||
@@ -252,7 +252,7 @@ func TestThresholdsmatchingThresholdsForEvent(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ths[0].Hits, thMatched[0].Hits)
|
||||
}
|
||||
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[1]); err != nil {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[1].Tenant, argsGetThresholds[1]); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(ths[1].Tenant, thMatched[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ths[1].Tenant, thMatched[0].Tenant)
|
||||
@@ -262,7 +262,7 @@ func TestThresholdsmatchingThresholdsForEvent(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ths[1].Hits, thMatched[0].Hits)
|
||||
}
|
||||
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[2]); err != nil {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[2].Tenant, argsGetThresholds[2]); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(ths[2].Tenant, thMatched[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ths[2].Tenant, thMatched[0].Tenant)
|
||||
@@ -275,21 +275,21 @@ func TestThresholdsmatchingThresholdsForEvent(t *testing.T) {
|
||||
|
||||
func TestThresholdsProcessEvent(t *testing.T) {
|
||||
thIDs := []string{"TH_1"}
|
||||
if thMatched, err := thServ.processEvent(argsGetThresholds[0]); err != utils.ErrPartiallyExecuted {
|
||||
if thMatched, err := thServ.processEvent(argsGetThresholds[0].Tenant, argsGetThresholds[0]); err != utils.ErrPartiallyExecuted {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(thIDs, thMatched) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", thIDs, thMatched)
|
||||
}
|
||||
|
||||
thIDs = []string{"TH_2"}
|
||||
if thMatched, err := thServ.processEvent(argsGetThresholds[1]); err != utils.ErrPartiallyExecuted {
|
||||
if thMatched, err := thServ.processEvent(argsGetThresholds[1].Tenant, argsGetThresholds[1]); err != utils.ErrPartiallyExecuted {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(thIDs, thMatched) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", thIDs, thMatched)
|
||||
}
|
||||
|
||||
thIDs = []string{"TH_3"}
|
||||
if thMatched, err := thServ.processEvent(argsGetThresholds[2]); err != utils.ErrPartiallyExecuted {
|
||||
if thMatched, err := thServ.processEvent(argsGetThresholds[2].Tenant, argsGetThresholds[2]); err != utils.ErrPartiallyExecuted {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(thIDs, thMatched) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", thIDs, thMatched)
|
||||
@@ -297,7 +297,7 @@ func TestThresholdsProcessEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestThresholdsVerifyIfExecuted(t *testing.T) {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[0]); err != nil {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[0].Tenant, argsGetThresholds[0]); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(ths[0].Tenant, thMatched[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ths[0].Tenant, thMatched[0].Tenant)
|
||||
@@ -307,7 +307,7 @@ func TestThresholdsVerifyIfExecuted(t *testing.T) {
|
||||
t.Errorf("Expecting: 1, received: %+v", thMatched[0].Hits)
|
||||
}
|
||||
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[1]); err != nil {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[1].Tenant, argsGetThresholds[1]); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(ths[1].Tenant, thMatched[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ths[1].Tenant, thMatched[0].Tenant)
|
||||
@@ -317,7 +317,7 @@ func TestThresholdsVerifyIfExecuted(t *testing.T) {
|
||||
t.Errorf("Expecting: 1, received: %+v", thMatched[0].Hits)
|
||||
}
|
||||
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[2]); err != nil {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(argsGetThresholds[2].Tenant, argsGetThresholds[2]); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(ths[2].Tenant, thMatched[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", ths[2].Tenant, thMatched[0].Tenant)
|
||||
@@ -373,13 +373,13 @@ func TestThresholdsProcessEvent2(t *testing.T) {
|
||||
}
|
||||
thIDs := []string{"TH_1", "TH_4"}
|
||||
thIDsRev := []string{"TH_4", "TH_1"}
|
||||
if thMatched, err := thServ.processEvent(ev); err != utils.ErrPartiallyExecuted {
|
||||
if thMatched, err := thServ.processEvent(ev.Tenant, ev); err != utils.ErrPartiallyExecuted {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else if !reflect.DeepEqual(thIDs, thMatched) && !reflect.DeepEqual(thIDsRev, thMatched) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", thIDs, thMatched)
|
||||
}
|
||||
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(ev); err != nil {
|
||||
if thMatched, err := thServ.matchingThresholdsForEvent(ev.Tenant, ev); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
} else {
|
||||
for _, thM := range thMatched {
|
||||
|
||||
@@ -1478,15 +1478,16 @@ const (
|
||||
|
||||
// ThresholdS APIs
|
||||
const (
|
||||
ThresholdSv1ProcessEvent = "ThresholdSv1.ProcessEvent"
|
||||
ThresholdSv1GetThreshold = "ThresholdSv1.GetThreshold"
|
||||
ThresholdSv1GetThresholdIDs = "ThresholdSv1.GetThresholdIDs"
|
||||
ThresholdSv1Ping = "ThresholdSv1.Ping"
|
||||
ThresholdSv1GetThresholdsForEvent = "ThresholdSv1.GetThresholdsForEvent"
|
||||
APIerSv1GetThresholdProfileIDs = "APIerSv1.GetThresholdProfileIDs"
|
||||
APIerSv1GetThresholdProfile = "APIerSv1.GetThresholdProfile"
|
||||
APIerSv1RemoveThresholdProfile = "APIerSv1.RemoveThresholdProfile"
|
||||
APIerSv1SetThresholdProfile = "APIerSv1.SetThresholdProfile"
|
||||
ThresholdSv1ProcessEvent = "ThresholdSv1.ProcessEvent"
|
||||
ThresholdSv1GetThreshold = "ThresholdSv1.GetThreshold"
|
||||
ThresholdSv1GetThresholdIDs = "ThresholdSv1.GetThresholdIDs"
|
||||
ThresholdSv1Ping = "ThresholdSv1.Ping"
|
||||
ThresholdSv1GetThresholdsForEvent = "ThresholdSv1.GetThresholdsForEvent"
|
||||
APIerSv1GetThresholdProfileIDs = "APIerSv1.GetThresholdProfileIDs"
|
||||
APIerSv1GetThresholdProfileIDsCount = "APIerSv1.GetThresholdProfileIDsCount"
|
||||
APIerSv1GetThresholdProfile = "APIerSv1.GetThresholdProfile"
|
||||
APIerSv1RemoveThresholdProfile = "APIerSv1.RemoveThresholdProfile"
|
||||
APIerSv1SetThresholdProfile = "APIerSv1.SetThresholdProfile"
|
||||
)
|
||||
|
||||
// StatS APIs
|
||||
|
||||
Reference in New Issue
Block a user