mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
better balance selection excluded destinations
This commit is contained in:
@@ -302,21 +302,30 @@ func (ub *Account) getBalancesForPrefix(prefix, category, direction, tor string,
|
||||
continue
|
||||
}
|
||||
b.account = ub
|
||||
|
||||
if len(b.DestinationIDs) > 0 && b.DestinationIDs[utils.ANY] == false {
|
||||
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
|
||||
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.(map[interface{}]struct{})
|
||||
foundResult := false
|
||||
includeDest := true // wheter it is excluded or included
|
||||
allInclude := true // wheter it is excluded or included
|
||||
for dId, _ := range destIds {
|
||||
inclDest, found := b.DestinationIDs[dId.(string)]
|
||||
if found {
|
||||
foundResult = true
|
||||
includeDest = includeDest && inclDest
|
||||
allInclude = allInclude && inclDest
|
||||
}
|
||||
}
|
||||
if foundResult {
|
||||
if includeDest {
|
||||
// check wheter all destination ids in the balance were exclusions
|
||||
allExclude := true
|
||||
for _, inclDest := range b.DestinationIDs {
|
||||
if inclDest {
|
||||
allExclude = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if foundResult || allExclude {
|
||||
if allInclude {
|
||||
b.precision = len(p)
|
||||
usefulBalances = append(usefulBalances, b)
|
||||
} else {
|
||||
|
||||
@@ -1721,6 +1721,75 @@ func TestAccountDoubleInitCounters(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountGetBalancesForPrefixMixed(t *testing.T) {
|
||||
acc := &Account{
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{
|
||||
&Balance{
|
||||
Value: 10,
|
||||
DestinationIDs: utils.StringMap{"NAT": true, "RET": false},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
bcs := acc.getBalancesForPrefix("999123", "", utils.OUT, utils.MONETARY, "")
|
||||
if len(bcs) != 0 {
|
||||
t.Error("error excluding on mixed balances")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountGetBalancesForPrefixAllExcl(t *testing.T) {
|
||||
acc := &Account{
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{
|
||||
&Balance{
|
||||
Value: 10,
|
||||
DestinationIDs: utils.StringMap{"NAT": false, "RET": false},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
bcs := acc.getBalancesForPrefix("999123", "", utils.OUT, utils.MONETARY, "")
|
||||
if len(bcs) == 0 {
|
||||
t.Error("error finding balance on all excluded")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountGetBalancesForPrefixMixedGood(t *testing.T) {
|
||||
acc := &Account{
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{
|
||||
&Balance{
|
||||
Value: 10,
|
||||
DestinationIDs: utils.StringMap{"NAT": true, "RET": false, "EXOTIC": true},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
bcs := acc.getBalancesForPrefix("999123", "", utils.OUT, utils.MONETARY, "")
|
||||
if len(bcs) == 0 {
|
||||
t.Error("error finding on mixed balances good")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountGetBalancesForPrefixMixedBad(t *testing.T) {
|
||||
acc := &Account{
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{
|
||||
&Balance{
|
||||
Value: 10,
|
||||
DestinationIDs: utils.StringMap{"NAT": true, "RET": false, "EXOTIC": false},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
bcs := acc.getBalancesForPrefix("999123", "", utils.OUT, utils.MONETARY, "")
|
||||
if len(bcs) != 0 {
|
||||
t.Error("error excluding on mixed balances bad")
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************** Benchmarks *******************************/
|
||||
|
||||
func BenchmarkGetSecondForPrefix(b *testing.B) {
|
||||
|
||||
@@ -39,6 +39,7 @@ func TestHistoryDestinations(t *testing.T) {
|
||||
expected := `{"Id":"ALL","Prefixes":["49","41","43"]},
|
||||
{"Id":"DST_UK_Mobile_BIG5","Prefixes":["447956"]},
|
||||
{"Id":"EU_LANDLINE","Prefixes":["444"]},
|
||||
{"Id":"EXOTIC","Prefixes":["999"]},
|
||||
{"Id":"GERMANY","Prefixes":["49"]},
|
||||
{"Id":"GERMANY_O2","Prefixes":["41"]},
|
||||
{"Id":"GERMANY_PREMIUM","Prefixes":["43"]},
|
||||
|
||||
@@ -49,6 +49,7 @@ PSTN_70,+4970
|
||||
DST_UK_Mobile_BIG5,447956
|
||||
URG,112
|
||||
EU_LANDLINE,444
|
||||
EXOTIC,999
|
||||
`
|
||||
timings = `
|
||||
WORKDAYS_00,*any,*any,*any,1;2;3;4;5,00:00:00
|
||||
@@ -322,7 +323,7 @@ func init() {
|
||||
}
|
||||
|
||||
func TestLoadDestinations(t *testing.T) {
|
||||
if len(csvr.destinations) != 13 {
|
||||
if len(csvr.destinations) != 14 {
|
||||
t.Error("Failed to load destinations: ", len(csvr.destinations))
|
||||
}
|
||||
for _, d := range csvr.destinations {
|
||||
|
||||
Reference in New Issue
Block a user