mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added tests for round_robin strategy in DispatcherS
This commit is contained in:
committed by
Dan Christian Bogos
parent
f8ed6445d9
commit
aa00a3d598
@@ -1,5 +1,7 @@
|
||||
#Tenant,ID,Subsystems,FilterIDs,ActivationInterval,Strategy,StrategyParameters,ConnID,ConnFilterIDs,ConnWeight,ConnBlocker,ConnParameters,Weight
|
||||
cgrates.org,PING1,*any,,,*weight,,ALL,,20,false,,10
|
||||
cgrates.org,PING1,,,,,,ALL2,,10,,,
|
||||
cgrates.org,EVENT1,*any,*string:EventName:Event1,,*weight,,ALL2,,20,false,,20
|
||||
cgrates.org,EVENT1,*any,*string:EventName:Event1,,*weight,,ALL2,,20,false,,30
|
||||
cgrates.org,EVENT1,,,,,,ALL,,10,,,
|
||||
cgrates.org,EVENT2,*any,*string:EventName:RoundRobin,,*round_robin,,ALL2,,20,false,,20
|
||||
cgrates.org,EVENT2,,,,,,ALL,,10,,,
|
||||
|
||||
|
@@ -32,6 +32,7 @@ import (
|
||||
var sTestsDspAttr = []func(t *testing.T){
|
||||
testDspAttrPingFailover,
|
||||
testDspAttrGetAttrFailover,
|
||||
testDspAttrGetAttrRoundRobin,
|
||||
|
||||
testDspAttrPing,
|
||||
testDspAttrTestMissingApiKey,
|
||||
@@ -360,3 +361,90 @@ func testDspAttrTestAuthKey3(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspAttrGetAttrRoundRobin(t *testing.T) {
|
||||
args := &ArgsAttrProcessEventWithApiKey{
|
||||
DispatcherResource: DispatcherResource{
|
||||
APIKey: "attr12345",
|
||||
},
|
||||
AttrArgsProcessEvent: engine.AttrArgsProcessEvent{
|
||||
Context: utils.StringPointer("simpleauth"),
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testAttributeSGetAttributeForEvent",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1002",
|
||||
utils.EVENT_NAME: "RoundRobin",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
eAttrPrf := &engine.AttributeProfile{
|
||||
Tenant: args.Tenant,
|
||||
ID: "ATTR_1002_SIMPLEAUTH",
|
||||
FilterIDs: []string{"*string:Account:1002"},
|
||||
Contexts: []string{"simpleauth"},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: "Password",
|
||||
Initial: utils.ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("CGRateS.org", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20.0,
|
||||
}
|
||||
eAttrPrf.Compile()
|
||||
|
||||
eRply := &engine.AttrSProcessEventReply{
|
||||
MatchedProfiles: []string{"ATTR_1002_SIMPLEAUTH"},
|
||||
AlteredFields: []string{"Password"},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testAttributeSGetAttributeForEvent",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1002",
|
||||
utils.EVENT_NAME: "RoundRobin",
|
||||
"Password": "CGRateS.org",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var attrReply *engine.AttributeProfile
|
||||
var rplyEv engine.AttrSProcessEventReply
|
||||
// To ALL2
|
||||
if err := dispEngine.RCP.Call(utils.AttributeSv1GetAttributeForEvent,
|
||||
args, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// To ALL
|
||||
if err := dispEngine.RCP.Call(utils.AttributeSv1GetAttributeForEvent,
|
||||
args, &attrReply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if attrReply != nil {
|
||||
attrReply.Compile()
|
||||
}
|
||||
if !reflect.DeepEqual(eAttrPrf, attrReply) {
|
||||
t.Errorf("Expecting: %s, received: %s", utils.ToJSON(eAttrPrf), utils.ToJSON(attrReply))
|
||||
}
|
||||
|
||||
// To ALL2
|
||||
if err := dispEngine.RCP.Call(utils.AttributeSv1ProcessEvent,
|
||||
args, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
} else if reflect.DeepEqual(eRply, &rplyEv) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
utils.ToJSON(eRply), utils.ToJSON(rplyEv))
|
||||
}
|
||||
|
||||
// To ALL
|
||||
if err := dispEngine.RCP.Call(utils.AttributeSv1ProcessEvent,
|
||||
args, &rplyEv); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRply, &rplyEv) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
utils.ToJSON(eRply), utils.ToJSON(rplyEv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
var sTestsDspCpp = []func(t *testing.T){
|
||||
testDspCppPingFailover,
|
||||
testDspCppGetChtgFailover,
|
||||
testDspCppGetChtgRoundRobin,
|
||||
|
||||
testDspCppPing,
|
||||
testDspCppTestAuthKey,
|
||||
@@ -194,3 +195,44 @@ func testDspCppTestAuthKey2(t *testing.T) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eChargers), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testDspCppGetChtgRoundRobin(t *testing.T) {
|
||||
args := CGREvWithApiKey{
|
||||
DispatcherResource: DispatcherResource{
|
||||
APIKey: "chrg12345",
|
||||
},
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "RoundRobin",
|
||||
utils.Account: "1001",
|
||||
},
|
||||
},
|
||||
}
|
||||
eChargers := &engine.ChargerProfiles{
|
||||
&engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "DEFAULT",
|
||||
FilterIDs: []string{},
|
||||
RunID: "*default",
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 0,
|
||||
},
|
||||
}
|
||||
var reply *engine.ChargerProfiles
|
||||
// To ALL2
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1GetChargersForEvent,
|
||||
args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expected error NOT_FOUND but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
|
||||
// To ALL
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1GetChargersForEvent,
|
||||
args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eChargers, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eChargers), utils.ToJSON(reply))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
var sTestsDspSup = []func(t *testing.T){
|
||||
testDspSupPingFailover,
|
||||
testDspSupGetSupFailover,
|
||||
testDspSupGetSupRoundRobin,
|
||||
|
||||
testDspSupPing,
|
||||
testDspSupTestAuthKey,
|
||||
@@ -256,3 +257,76 @@ func testDspSupTestAuthKey2(t *testing.T) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl), utils.ToJSON(rpl))
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupGetSupRoundRobin(t *testing.T) {
|
||||
var rpl *engine.SortedSuppliers
|
||||
eRpl1 := &engine.SortedSuppliers{
|
||||
ProfileID: "SPL_WEIGHT_2",
|
||||
Sorting: utils.MetaWeight,
|
||||
SortedSuppliers: []*engine.SortedSupplier{
|
||||
{
|
||||
SupplierID: "supplier1",
|
||||
SupplierParameters: "",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Weight: 10.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
eRpl := &engine.SortedSuppliers{
|
||||
ProfileID: "SPL_ACNT_1002",
|
||||
Sorting: utils.MetaLeastCost,
|
||||
SortedSuppliers: []*engine.SortedSupplier{
|
||||
{
|
||||
SupplierID: "supplier1",
|
||||
SupplierParameters: "",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Cost: 0.1166,
|
||||
utils.RatingPlanID: "RP_1002_LOW",
|
||||
utils.Weight: 10.0,
|
||||
},
|
||||
},
|
||||
{
|
||||
SupplierID: "supplier2",
|
||||
SupplierParameters: "",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Cost: 0.2334,
|
||||
utils.RatingPlanID: "RP_1002",
|
||||
utils.Weight: 20.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
args := &ArgsGetSuppliersWithApiKey{
|
||||
DispatcherResource: DispatcherResource{
|
||||
APIKey: "sup12345",
|
||||
},
|
||||
ArgsGetSuppliers: engine.ArgsGetSuppliers{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Time: &nowTime,
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "RoundRobin",
|
||||
utils.Account: "1002",
|
||||
utils.Subject: "1002",
|
||||
utils.Destination: "1001",
|
||||
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: "1m20s",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRpl1, rpl) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl1), utils.ToJSON(rpl))
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRpl, rpl) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl), utils.ToJSON(rpl))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user