mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 21:59:53 +05:00
Suppliers integration test improvement
This commit is contained in:
@@ -44,7 +44,7 @@ var sTestsSupplierSV1 = []func(t *testing.T){
|
||||
testV1SplSLoadConfig,
|
||||
testV1SplSInitDataDb,
|
||||
testV1SplSResetStorDb,
|
||||
testV1SplSStartEngine,
|
||||
//testV1SplSStartEngine,
|
||||
testV1SplSRpcConn,
|
||||
testV1SplSFromFolder,
|
||||
//testV1SplSGetWeightSuppliers,
|
||||
@@ -161,6 +161,7 @@ func testV1SplSGetLeastCostSuppliers(t *testing.T) {
|
||||
ID: "testV1SplSGetLeastCostSuppliers",
|
||||
Event: map[string]interface{}{
|
||||
utils.ACCOUNT: "1001",
|
||||
utils.SUBJECT: "1001",
|
||||
utils.DESTINATION: "1002",
|
||||
utils.ANSWER_TIME: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
|
||||
utils.USAGE: "1m20s",
|
||||
|
||||
@@ -3,6 +3,6 @@ cgrates.org,SPP_1,FLTR_ACNT_dan;FLTR_DST_DE,2017-07-29T15:00:00Z,*lowest_cost,,s
|
||||
cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE;FLTR_ACNT_1007,2017-11-27T00:00:00Z,*weight,,supplier1,,,,,,10,false,10
|
||||
cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE,,,,supplier2,,,,,,20,,
|
||||
cgrates.org,SPL_WEIGHT_1,FLTR_ACNT_1007,,,,supplier3,FLTR_ACNT_dan,,,,,15,,
|
||||
cgrates.org,SPL_LEASTCOST_1,FLTR_1,2017-11-27T00:00:00Z,*weight,,supplier1,,RP_SPECIAL_1002,,,,10,false,10
|
||||
cgrates.org,SPL_LEASTCOST_1,FLTR_1,2017-11-27T00:00:00Z,*least_cost,,supplier1,,RP_SPECIAL_1002,,,,10,false,10
|
||||
cgrates.org,SPL_LEASTCOST_1,,,,,supplier2,,RP_RETAIL1,,,,20,,
|
||||
cgrates.org,SPL_LEASTCOST_1,,,,,supplier3,,RP_SPECIAL_1002,,,,15,,
|
||||
|
||||
|
@@ -28,7 +28,8 @@ import (
|
||||
// fieldIDs limits the fields which are checked against indexes
|
||||
// helper on top of dataDB.MatchReqFilterIndex, adding utils.NOT_AVAILABLE to list of fields queried
|
||||
// executes a number of $(len(fields) + 1) queries to dataDB so the size of event influences the speed of return
|
||||
func matchingItemIDsForEvent(ev map[string]interface{}, fieldIDs []string, dm *DataManager, dbIdxKey string) (itemIDs utils.StringMap, err error) {
|
||||
func matchingItemIDsForEvent(ev map[string]interface{}, fieldIDs []string,
|
||||
dm *DataManager, dbIdxKey string) (itemIDs utils.StringMap, err error) {
|
||||
if len(fieldIDs) == 0 {
|
||||
fieldIDs = make([]string, len(ev))
|
||||
i := 0
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
@@ -115,7 +116,6 @@ func (spS *SupplierService) matchingSupplierProfilesForEvent(ev *SupplierEvent)
|
||||
matchingLPs := make(map[string]*SupplierProfile)
|
||||
sPrflIDs, err := matchingItemIDsForEvent(ev.Event, spS.indexedFields,
|
||||
spS.dm, utils.SupplierProfilesStringIndex+ev.Tenant)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,8 +123,7 @@ func (spS *SupplierService) matchingSupplierProfilesForEvent(ev *SupplierEvent)
|
||||
guardian.Guardian.GuardIDs(config.CgrConfig().LockingTimeout, lockIDs...)
|
||||
defer guardian.Guardian.UnguardIDs(lockIDs...)
|
||||
for lpID := range sPrflIDs {
|
||||
lcrPrfl, err := spS.dm.GetSupplierProfile(ev.Tenant, lpID, false, utils.NonTransactional)
|
||||
//fmt.Printf("LoadedSupplier: %s\n", utils.ToJSON(lcrPrfl))
|
||||
splPrfl, err := spS.dm.GetSupplierProfile(ev.Tenant, lpID, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
continue
|
||||
@@ -139,17 +138,17 @@ func (spS *SupplierService) matchingSupplierProfilesForEvent(ev *SupplierEvent)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if lcrPrfl.ActivationInterval != nil &&
|
||||
!lcrPrfl.ActivationInterval.IsActiveAtTime(aTime) { // not active
|
||||
if splPrfl.ActivationInterval != nil &&
|
||||
!splPrfl.ActivationInterval.IsActiveAtTime(aTime) { // not active
|
||||
continue
|
||||
}
|
||||
if pass, err := spS.filterS.PassFiltersForEvent(ev.Tenant,
|
||||
ev.Event, lcrPrfl.FilterIDs); err != nil {
|
||||
ev.Event, splPrfl.FilterIDs); err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
continue
|
||||
}
|
||||
matchingLPs[lpID] = lcrPrfl
|
||||
matchingLPs[lpID] = splPrfl
|
||||
}
|
||||
// All good, convert from Map to Slice so we can sort
|
||||
sPrfls = make(SupplierProfiles, len(matchingLPs))
|
||||
@@ -230,7 +229,7 @@ func (spS *SupplierService) costForEvent(ev *SupplierEvent,
|
||||
}
|
||||
return NewEventCostFromCallCost(cc, "", ""), nil
|
||||
}
|
||||
return
|
||||
return nil, errors.New("no cost found")
|
||||
}
|
||||
|
||||
// statMetrics will query a list of statIDs and return composed metric values
|
||||
@@ -253,9 +252,9 @@ func (spS *SupplierService) sortedSuppliersForEvent(ev *SupplierEvent) (sortedSu
|
||||
} else if len(suppPrfls) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
lcrPrfl := suppPrfls[0] // pick up the first lcr profile as winner
|
||||
splPrfl := suppPrfls[0] // pick up the first lcr profile as winner
|
||||
var spls []*Supplier
|
||||
for _, s := range lcrPrfl.Suppliers {
|
||||
for _, s := range splPrfl.Suppliers {
|
||||
if len(s.FilterIDs) != 0 { // filters should be applied, check them here
|
||||
if pass, err := spS.filterS.PassFiltersForEvent(ev.Tenant,
|
||||
ev.Event, s.FilterIDs); err != nil {
|
||||
@@ -266,7 +265,7 @@ func (spS *SupplierService) sortedSuppliersForEvent(ev *SupplierEvent) (sortedSu
|
||||
}
|
||||
spls = append(spls, s)
|
||||
}
|
||||
return spS.sorter.SortSuppliers(lcrPrfl.ID, lcrPrfl.Sorting, spls, ev)
|
||||
return spS.sorter.SortSuppliers(splPrfl.ID, splPrfl.Sorting, spls, ev)
|
||||
}
|
||||
|
||||
// V1GetSuppliersForEvent returns the list of valid supplier IDs
|
||||
|
||||
Reference in New Issue
Block a user