Tutorial LcrRules.csv fixups, adding TestTutLocalLcrStatic

This commit is contained in:
DanB
2015-05-24 20:50:26 +02:00
parent 83bab44b3c
commit a81bf953b7
7 changed files with 99 additions and 51 deletions

View File

@@ -2,4 +2,3 @@
DST_1002,1002
DST_1003,1003
DST_FS,10
DST_2002,2002
1 #Tag Prefix
2 DST_1002 1002
3 DST_1003 1003
4 DST_FS 10
DST_2002 2002

View File

@@ -1,9 +1,9 @@
#Direction,Tenant,Category,Account,Subject,DestinationId,RPCategory,Strategy,StrategyParams,ActivationTime,Weight
*out,cgrates.org,call,1001,*any,DST_2002,lcr_profile1,*static,suppl2;suppl1,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,1001,*any,DST_1002,lcr_profile1,*static,suppl2;suppl1,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,1001,*any,*any,lcr_profile1,*static,suppl1;suppl2,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,1002,*any,DST_2002,lcr_profile1,*highest_cost,,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,1002,*any,DST_1002,lcr_profile1,*highest_cost,,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,1002,*any,*any,lcr_profile1,*qos,,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,1003,*any,DST_2002,lcr_profile1,*qos_threshold,20;;2m;;;;;;;,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,1003,*any,DST_1002,lcr_profile1,*qos_threshold,20;;2m;;;;;;;,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,1003,*any,*any,lcr_profile1,*qos_threshold,40;;4m;;;;;;;,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,*any,*any,DST_2002,lcr_profile2,*lowest_cost,,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,*any,*any,DST_1002,lcr_profile2,*lowest_cost,,2014-01-14T00:00:00Z,10
*out,cgrates.org,call,*any,*any,*any,lcr_profile1,*lowest_cost,,2014-01-14T00:00:00Z,10
1 #Direction Tenant Category Account Subject DestinationId RPCategory Strategy StrategyParams ActivationTime Weight
2 *out cgrates.org call 1001 *any DST_2002 DST_1002 lcr_profile1 *static suppl2;suppl1 2014-01-14T00:00:00Z 10
3 *out cgrates.org call 1001 *any *any lcr_profile1 *static suppl1;suppl2 2014-01-14T00:00:00Z 10
4 *out cgrates.org call 1002 *any DST_2002 DST_1002 lcr_profile1 *highest_cost 2014-01-14T00:00:00Z 10
5 *out cgrates.org call 1002 *any *any lcr_profile1 *qos 2014-01-14T00:00:00Z 10
6 *out cgrates.org call 1003 *any DST_2002 DST_1002 lcr_profile1 *qos_threshold 20;;2m;;;;;;; 2014-01-14T00:00:00Z 10
7 *out cgrates.org call 1003 *any *any lcr_profile1 *qos_threshold 40;;4m;;;;;;; 2014-01-14T00:00:00Z 10
8 *out cgrates.org call *any *any DST_2002 DST_1002 lcr_profile2 *lowest_cost 2014-01-14T00:00:00Z 10
9 *out cgrates.org call *any *any *any lcr_profile1 *lowest_cost 2014-01-14T00:00:00Z 10

View File

@@ -2,8 +2,8 @@
*out,cgrates.org,call,*any,2014-01-14T00:00:00Z,RP_RETAIL1,,
*out,cgrates.org,call,1001;1006,2014-01-14T00:00:00Z,RP_RETAIL2,,
*out,cgrates.org,call,SPECIAL_1002,2014-01-14T00:00:00Z,RP_SPECIAL_1002,,
*out,cgrates.org,lcr_profile1,supplier1,2014-01-14T00:00:00Z,RP_RETAIL1,,STATS_SUPPL1
*out,cgrates.org,lcr_profile1,supplier2,2014-01-14T00:00:00Z,RP_RETAIL2,,STATS_SUPPL2
*out,cgrates.org,lcr_profile2,supplier1,2014-01-14T00:00:00Z,RP_RETAIL2,,STATS_SUPPL1
*out,cgrates.org,lcr_profile2,supplier2,2014-01-14T00:00:00Z,RP_RETAIL1,,STATS_SUPPL2
*out,cgrates.org,lcr_profile2,supplier3,2014-01-14T00:00:00Z,RP_SPECIAL_1002,,
*out,cgrates.org,lcr_profile1,suppl1,2014-01-14T00:00:00Z,RP_RETAIL1,,STATS_SUPPL1
*out,cgrates.org,lcr_profile1,suppl2,2014-01-14T00:00:00Z,RP_RETAIL2,,STATS_SUPPL2
*out,cgrates.org,lcr_profile2,suppl1,2014-01-14T00:00:00Z,RP_RETAIL2,,STATS_SUPPL1
*out,cgrates.org,lcr_profile2,suppl2,2014-01-14T00:00:00Z,RP_RETAIL1,,STATS_SUPPL2
*out,cgrates.org,lcr_profile2,suppl3,2014-01-14T00:00:00Z,RP_SPECIAL_1002,,
1 #Direction Tenant Category Subject ActivationTime RatingPlanId RatesFallbackSubject CdrStatQueueIds
2 *out cgrates.org call *any 2014-01-14T00:00:00Z RP_RETAIL1
3 *out cgrates.org call 1001;1006 2014-01-14T00:00:00Z RP_RETAIL2
4 *out cgrates.org call SPECIAL_1002 2014-01-14T00:00:00Z RP_SPECIAL_1002
5 *out cgrates.org lcr_profile1 supplier1 suppl1 2014-01-14T00:00:00Z RP_RETAIL1 STATS_SUPPL1
6 *out cgrates.org lcr_profile1 supplier2 suppl2 2014-01-14T00:00:00Z RP_RETAIL2 STATS_SUPPL2
7 *out cgrates.org lcr_profile2 supplier1 suppl1 2014-01-14T00:00:00Z RP_RETAIL2 STATS_SUPPL1
8 *out cgrates.org lcr_profile2 supplier2 suppl2 2014-01-14T00:00:00Z RP_RETAIL1 STATS_SUPPL2
9 *out cgrates.org lcr_profile2 supplier3 suppl3 2014-01-14T00:00:00Z RP_SPECIAL_1002

View File

@@ -174,19 +174,6 @@ func TestTutFsCallsAccountsBefore(t *testing.T) {
}
}
func TestTutFsCallsCdrStats(t *testing.T) {
if !*testCalls {
return
}
var queueIds []string
eQueueIds := []string{"*default", "CDRST1", "CDRST_1001", "CDRST_1002", "CDRST_1003", "STATS_SUPPL1", "STATS_SUPPL2"}
if err := tutFsCallsRpc.Call("CDRStatsV1.GetQueueIds", "", &queueIds); err != nil {
t.Error("Calling CDRStatsV1.GetQueueIds, got error: ", err.Error())
} else if len(eQueueIds) != len(queueIds) {
t.Errorf("Expecting: %v, received: %v", eQueueIds, queueIds)
}
}
// Start Pjsua as listener and register it to receive calls
func TestTutFsCallsStartPjsuaListener(t *testing.T) {
if !*testCalls {

View File

@@ -172,19 +172,6 @@ func TestTutKamCallsAccountsBefore(t *testing.T) {
}
}
func TestTutKamCallsCdrStats(t *testing.T) {
if !*testCalls {
return
}
var queueIds []string
eQueueIds := []string{"*default", "CDRST1", "CDRST_1001", "CDRST_1002", "CDRST_1003", "STATS_SUPPL1", "STATS_SUPPL2"}
if err := tutKamCallsRpc.Call("CDRStatsV1.GetQueueIds", "", &queueIds); err != nil {
t.Error("Calling CDRStatsV1.GetQueueIds, got error: ", err.Error())
} else if len(eQueueIds) != len(queueIds) {
t.Errorf("Expecting: %v, received: %v", eQueueIds, queueIds)
}
}
// Start Pjsua as listener and register it to receive calls
func TestTutKamCallsStartPjsuaListener(t *testing.T) {
if !*testCalls {

View File

@@ -42,7 +42,7 @@ func TestTutLocalInitCfg(t *testing.T) {
if !*testLocal {
return
}
tutLocalCfgPath = path.Join(*dataDir, "conf", "samples", "cgradmin")
tutLocalCfgPath = path.Join(*dataDir, "conf", "samples", "tutlocal")
// Init config first
var err error
tutFsLocalCfg, err = config.NewCGRConfigFromFolder(tutLocalCfgPath)
@@ -116,7 +116,8 @@ func TestTutLocalCacheStats(t *testing.T) {
return
}
var rcvStats *utils.CacheStats
expectedStats := &utils.CacheStats{Destinations: 4, RatingPlans: 3, RatingProfiles: 8, Actions: 6, SharedGroups: 1, RatingAliases: 1, AccountAliases: 1, DerivedChargers: 1}
expectedStats := &utils.CacheStats{Destinations: 3, RatingPlans: 3, RatingProfiles: 8, Actions: 6, SharedGroups: 1, RatingAliases: 1, AccountAliases: 1,
DerivedChargers: 1, LcrProfiles: 4}
var args utils.AttrCacheStats
if err := tutLocalRpc.Call("ApierV1.GetCacheStats", args, &rcvStats); err != nil {
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
@@ -156,6 +157,17 @@ func TestTutLocalGetCachedItemAge(t *testing.T) {
} else if rcvAge.SharedGroup > time.Duration(2)*time.Second {
t.Errorf("Cache too old: %d", rcvAge)
}
if err := tutLocalRpc.Call("ApierV1.GetCachedItemAge", "*out:cgrates.org:call:1001:*any", &rcvAge); err != nil {
t.Error("Got error on ApierV1.GetCachedItemAge: ", err.Error())
} else if rcvAge.SharedGroup > time.Duration(2)*time.Second {
t.Errorf("Cache too old: %d", rcvAge)
}
if err := tutLocalRpc.Call("ApierV1.GetCachedItemAge", "*out:cgrates.org:call:*any:*any", &rcvAge); err != nil {
t.Error("Got error on ApierV1.GetCachedItemAge: ", err.Error())
} else if rcvAge.SharedGroup > time.Duration(2)*time.Second {
t.Errorf("Cache too old: %d", rcvAge)
}
/*
if err := tutLocalRpc.Call("ApierV1.GetCachedItemAge", "1006", &rcvAge); err != nil {
t.Error("Got error on ApierV1.GetCachedItemAge: ", err.Error())
@@ -312,6 +324,82 @@ func TestTutLocalMaxDebit(t *testing.T) {
}
}
// Make sure queueids were created
func TestTutFsCallsCdrStats(t *testing.T) {
if !*testCalls {
return
}
var queueIds []string
eQueueIds := []string{"*default", "CDRST1", "CDRST_1001", "CDRST_1002", "CDRST_1003", "STATS_SUPPL1", "STATS_SUPPL2"}
if err := tutLocalRpc.Call("CDRStatsV1.GetQueueIds", "", &queueIds); err != nil {
t.Error("Calling CDRStatsV1.GetQueueIds, got error: ", err.Error())
} else if len(eQueueIds) != len(queueIds) {
t.Errorf("Expecting: %v, received: %v", eQueueIds, queueIds)
}
}
// Check LCR
//FixMe:
/*{"id":16,"result":{"Entry":{"DestinationId":"*any","RPCategory":"lcr_profile1","Strategy":"*static","StrategyParams":"suppl1;suppl2","Weight":10},"SupplierCosts":[{"Supplier":"*out:cgrates.org:lcr_profile1:suppl1","Cost":0,"Duration":0,"Error":{},"QOS":null},{"Supplier":"*out:cgrates.org:lcr_profile1:suppl2","Cost":0,"Duration":0,"Error":{},"QOS":null}]},"error":null}
*/
func TestTutLocalLcrStatic(t *testing.T) {
if !*testLocal {
return
}
tStart, _ := utils.ParseDate("2014-08-04T13:00:00Z")
tEnd, _ := utils.ParseDate("2014-08-04T13:01:00Z")
cd := engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1002",
TimeStart: tStart,
TimeEnd: tEnd,
}
eStLcr := &engine.LCRCost{
Entry: &engine.LCREntry{DestinationId: "DST_1002", RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_STATIC, StrategyParams: "suppl2;suppl1", Weight: 10.0},
SupplierCosts: []*engine.LCRSupplierCost{
&engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 0.6, Duration: 60 * time.Second},
&engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second},
},
}
var lcr engine.LCRCost
if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
} else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1003",
TimeStart: tStart,
TimeEnd: tEnd,
}
eStLcr = &engine.LCRCost{
Entry: &engine.LCREntry{DestinationId: utils.ANY, RPCategory: "lcr_profile1", Strategy: engine.LCR_STRATEGY_STATIC, StrategyParams: "suppl1;suppl2", Weight: 10.0},
SupplierCosts: []*engine.LCRSupplierCost{
&engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second},
&engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 1.2, Duration: 60 * time.Second},
},
}
if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
} else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0])
}
}
func TestTutLocalStopCgrEngine(t *testing.T) {
if !*testLocal {
return

View File

@@ -172,19 +172,6 @@ func TestTutOsipsCallsAccountsBefore(t *testing.T) {
}
}
func TestTutOsipsCallsCdrStats(t *testing.T) {
if !*testCalls {
return
}
var queueIds []string
eQueueIds := []string{"*default", "CDRST1", "CDRST_1001", "CDRST_1002", "CDRST_1003", "STATS_SUPPL1", "STATS_SUPPL2"}
if err := tutOsipsCallsRpc.Call("CDRStatsV1.GetQueueIds", "", &queueIds); err != nil {
t.Error("Calling CDRStatsV1.GetQueueIds, got error: ", err.Error())
} else if len(eQueueIds) != len(queueIds) {
t.Errorf("Expecting: %v, received: %v", eQueueIds, queueIds)
}
}
// Start Pjsua as listener and register it to receive calls
func TestTutOsipsCallsStartPjsuaListener(t *testing.T) {
if !*testCalls {