mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Verified overwriting filters and profiles for indexes
This commit is contained in:
@@ -47,7 +47,10 @@ var (
|
||||
testV1FIdxStartEngine,
|
||||
testV1FIdxRpcConn,
|
||||
|
||||
testV1FIdxSetThresholdProfile,
|
||||
testSetProfilesWithFltrsAndOverwriteThemFIdx,
|
||||
testSetAndChangeFiltersOnProfiles,
|
||||
|
||||
/* testV1FIdxSetThresholdProfile,
|
||||
testV1FIdxComputeThresholdsIndexes,
|
||||
testV1FIdxSetSecondThresholdProfile,
|
||||
testV1FIdxSecondComputeThresholdsIndexes,
|
||||
@@ -105,7 +108,7 @@ var (
|
||||
testV1FIdxResetStorDb,
|
||||
testV1FIdxClearCache,
|
||||
//testV1FIdxSetDispatcherComputeIDs,
|
||||
testV1FIdxSetResourceComputeIDs,
|
||||
testV1FIdxSetResourceComputeIDs, */
|
||||
|
||||
testV1FIdxStopEngine,
|
||||
}
|
||||
@@ -3165,6 +3168,329 @@ func testV1FIdxSetResourceComputeIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testSetProfilesWithFltrsAndOverwriteThemFIdx(t *testing.T) {
|
||||
// FLTR_Charger, FLTR_Charger2 will be changed
|
||||
filter1 := &engine.FilterWithAPIOpts{
|
||||
Filter: &engine.Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_Charger",
|
||||
Rules: []*engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Bank",
|
||||
Values: []string{"BoA", "CEC"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "~*req.Customer",
|
||||
Values: []string{"11", "22"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
filter2 := &engine.FilterWithAPIOpts{
|
||||
Filter: &engine.Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_Charger2",
|
||||
Rules: []*engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Account",
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
var result string
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter1, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter2, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
|
||||
stat1 := &engine.StatQueueProfileWithAPIOpts{
|
||||
StatQueueProfile: &engine.StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats1",
|
||||
FilterIDs: []string{
|
||||
"FLTR_Charger",
|
||||
"FLTR_Charger2",
|
||||
},
|
||||
QueueLength: 10,
|
||||
TTL: time.Duration(10) * time.Second,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
{
|
||||
MetricID: utils.MetaACD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
MinItems: 1,
|
||||
},
|
||||
}
|
||||
stat2 := &engine.StatQueueProfileWithAPIOpts{
|
||||
StatQueueProfile: &engine.StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats2",
|
||||
FilterIDs: []string{
|
||||
"FLTR_Charger",
|
||||
},
|
||||
QueueLength: 10,
|
||||
TTL: time.Duration(10) * time.Second,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
{
|
||||
MetricID: utils.MetaACD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
MinItems: 1,
|
||||
},
|
||||
}
|
||||
var reply string
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, stat1, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, stat2, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
|
||||
tPrfl1 := &engine.ThresholdProfileWithAPIOpts{
|
||||
ThresholdProfile: &engine.ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TEST_PROFILE1",
|
||||
FilterIDs: []string{"FLTR_Charger"},
|
||||
MaxHits: 1,
|
||||
MinSleep: time.Duration(5 * time.Minute),
|
||||
Blocker: false,
|
||||
Weight: 10.0,
|
||||
Async: true,
|
||||
},
|
||||
}
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl1, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
|
||||
arg := &AttrGetFilterIndexes{
|
||||
Tenant: "cgrates.org",
|
||||
ItemType: utils.MetaStats,
|
||||
}
|
||||
expectedIndexes := []string{
|
||||
// Stats1
|
||||
"*string:*req.Bank:BoA:Stats1",
|
||||
"*string:*req.Bank:CEC:Stats1",
|
||||
"*prefix:*req.Customer:11:Stats1",
|
||||
"*prefix:*req.Customer:22:Stats1",
|
||||
"*string:*req.Account:1001:Stats1",
|
||||
|
||||
// Stats2
|
||||
"*string:*req.Bank:BoA:Stats2",
|
||||
"*string:*req.Bank:CEC:Stats2",
|
||||
"*prefix:*req.Customer:11:Stats2",
|
||||
"*prefix:*req.Customer:22:Stats2",
|
||||
}
|
||||
sort.Strings(expectedIndexes)
|
||||
var replyIDx []string
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil {
|
||||
t.Error(err)
|
||||
} else if sort.Strings(replyIDx); !reflect.DeepEqual(expectedIndexes, replyIDx) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(replyIDx))
|
||||
}
|
||||
|
||||
// FLTR_Charger, FLTR_Charger12312 and FLTR_Charger4564 will be changed
|
||||
filter1 = &engine.FilterWithAPIOpts{
|
||||
Filter: &engine.Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_Charger",
|
||||
Rules: []*engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.RatingPlan",
|
||||
Values: []string{"RP1"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "~*req.Subject",
|
||||
Values: []string{"1001", "1002"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
filter2 = &engine.FilterWithAPIOpts{
|
||||
Filter: &engine.Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_Charger2",
|
||||
Rules: []*engine.FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Destination",
|
||||
Values: []string{"randomID"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter1, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter2, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
|
||||
arg = &AttrGetFilterIndexes{
|
||||
Tenant: "cgrates.org",
|
||||
ItemType: utils.MetaStats,
|
||||
}
|
||||
expectedIndexes = []string{
|
||||
// Stats1
|
||||
"*string:*req.RatingPlan:RP1:Stats1",
|
||||
"*prefix:*req.Subject:1001:Stats1",
|
||||
"*prefix:*req.Subject:1002:Stats1",
|
||||
"*string:*req.Destination:randomID:Stats1",
|
||||
|
||||
// Stats2
|
||||
"*string:*req.RatingPlan:RP1:Stats2",
|
||||
"*prefix:*req.Subject:1001:Stats2",
|
||||
"*prefix:*req.Subject:1002:Stats2",
|
||||
}
|
||||
sort.Strings(expectedIndexes)
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil {
|
||||
t.Error(err)
|
||||
} else if sort.Strings(replyIDx); !reflect.DeepEqual(expectedIndexes, replyIDx) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(replyIDx))
|
||||
}
|
||||
}
|
||||
|
||||
func testSetAndChangeFiltersOnProfiles(t *testing.T) {
|
||||
stat1 := &engine.StatQueueProfileWithAPIOpts{
|
||||
StatQueueProfile: &engine.StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats1",
|
||||
FilterIDs: []string{},
|
||||
QueueLength: 10,
|
||||
TTL: time.Duration(10) * time.Second,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
{
|
||||
MetricID: utils.MetaACD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
MinItems: 1,
|
||||
},
|
||||
}
|
||||
|
||||
stat2 := &engine.StatQueueProfileWithAPIOpts{
|
||||
StatQueueProfile: &engine.StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats2",
|
||||
FilterIDs: []string{
|
||||
"FLTR_Charger2",
|
||||
},
|
||||
QueueLength: 10,
|
||||
TTL: time.Duration(10) * time.Second,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
{
|
||||
MetricID: utils.MetaACD,
|
||||
},
|
||||
{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
},
|
||||
ThresholdIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
MinItems: 1,
|
||||
},
|
||||
}
|
||||
var reply string
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, stat1, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, stat2, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
|
||||
tPrfl1 := &engine.ThresholdProfileWithAPIOpts{
|
||||
ThresholdProfile: &engine.ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TEST_PROFILE1",
|
||||
FilterIDs: []string{"FLTR_Charger",
|
||||
"FLTR_Charger2"},
|
||||
MaxHits: 1,
|
||||
MinSleep: time.Duration(5 * time.Minute),
|
||||
Blocker: false,
|
||||
Weight: 10.0,
|
||||
Async: true,
|
||||
},
|
||||
}
|
||||
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl1, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
|
||||
arg := &AttrGetFilterIndexes{
|
||||
Tenant: "cgrates.org",
|
||||
ItemType: utils.MetaStats,
|
||||
}
|
||||
expectedIndexes := []string{
|
||||
"*none:*any:*any:Stats1",
|
||||
"*string:*req.Destination:randomID:Stats2",
|
||||
}
|
||||
sort.Strings(expectedIndexes)
|
||||
var replyIDx []string
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil {
|
||||
t.Error(err)
|
||||
} else if sort.Strings(replyIDx); !reflect.DeepEqual(expectedIndexes, replyIDx) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(replyIDx))
|
||||
}
|
||||
|
||||
arg = &AttrGetFilterIndexes{
|
||||
Tenant: "cgrates.org",
|
||||
ItemType: utils.MetaThresholds,
|
||||
}
|
||||
expectedIndexes = []string{
|
||||
"*string:*req.Destination:randomID:TEST_PROFILE1",
|
||||
"*string:*req.RatingPlan:RP1:TEST_PROFILE1",
|
||||
"*prefix:*req.Subject:1001:TEST_PROFILE1",
|
||||
"*prefix:*req.Subject:1002:TEST_PROFILE1",
|
||||
}
|
||||
sort.Strings(expectedIndexes)
|
||||
if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil {
|
||||
t.Error(err)
|
||||
} else if sort.Strings(replyIDx); !reflect.DeepEqual(expectedIndexes, replyIDx) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(replyIDx))
|
||||
}
|
||||
}
|
||||
|
||||
func testV1FIdxStopEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(100); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user