more tests and disabled shared gropup caching

This commit is contained in:
Radu Ioan Fericean
2014-03-20 19:05:31 +02:00
parent 22adfb552f
commit c6de153685
4 changed files with 60 additions and 23 deletions

View File

@@ -379,6 +379,43 @@ func TestMaxSessionTimeWithAccountShared(t *testing.T) {
}
}
func TestMaxDebitWithAccountShared(t *testing.T) {
ap, _ := accountingStorage.GetActionTimings("TOPUP_SHARED0_AT")
for _, at := range ap {
at.Execute()
}
ap, _ = accountingStorage.GetActionTimings("TOPUP_SHARED10_AT")
for _, at := range ap {
at.Execute()
}
cd := &CallDescriptor{
TimeStart: time.Date(2013, 10, 21, 18, 34, 0, 0, time.UTC),
TimeEnd: time.Date(2013, 10, 21, 18, 34, 5, 0, time.UTC),
Direction: "*out",
TOR: "0",
Tenant: "vdf",
Subject: "minu",
Account: "empty0",
Destination: "0723",
}
cc, err := cd.MaxDebit()
if err != nil || cc.Cost != 2.5 {
t.Errorf("Wrong callcost in shared debit: %+v, %v", cc, err)
}
acc, _ := cd.getAccount()
log.Print(cd.GetAccountKey())
balanceMap := acc.BalanceMap[CREDIT+OUTBOUND]
if len(balanceMap) != 1 || balanceMap[0].Value != 0 {
t.Errorf("Wrong shared balance debited: %+v", balanceMap)
}
other, err := accountingStorage.GetAccount("*out:vdf:empty10")
if err != nil || other.BalanceMap[CREDIT+OUTBOUND][0].Value != 7.5 {
t.Errorf("Error debiting shared balance: %+v", other.BalanceMap[CREDIT+OUTBOUND][0])
}
}
func TestMaxSessionTimeWithAccountAccount(t *testing.T) {
cd := &CallDescriptor{
TimeStart: time.Date(2013, 10, 21, 18, 34, 0, 0, time.UTC),

View File

@@ -122,9 +122,9 @@ cgrates.directvoip.co.uk,call,*out,*any,2013-01-06T00:00:00Z,RP_UK,
cgrates.directvoip.co.uk,call,*out,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,
`
sharedGroups = `
SG1,*any,*lowest_first,
SG2,*any,*lowest_first,EVENING
SG3,*any,*lowest_first,
SG1,*any,*lowest,
SG2,*any,*lowest,one
SG3,*any,*lowest,
`
actions = `
@@ -676,7 +676,7 @@ func TestLoadSharedGroups(t *testing.T) {
Id: "SG1",
AccountParameters: map[string]*SharingParameters{
"*any": &SharingParameters{
Strategy: "*lowest_first",
Strategy: "*lowest",
RateSubject: "",
},
},
@@ -689,8 +689,8 @@ func TestLoadSharedGroups(t *testing.T) {
Id: "SG2",
AccountParameters: map[string]*SharingParameters{
"*any": &SharingParameters{
Strategy: "*lowest_first",
RateSubject: "EVENING",
Strategy: "*lowest",
RateSubject: "one",
},
},
}

View File

@@ -201,7 +201,7 @@ var FileValidators = map[string]*FileLineRegexValidator{
regexp.MustCompile(`(?:\w+\s*,\s*){2}(?:\*out\s*,\s*){1}(?:\*any\s*,\s*|(\w+;?)+\s*,\s*){1}(?:\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z){1}(?:\w*\s*,?\s*){2}$`),
"Tenant([0-9A-Za-z_]),TOR([0-9A-Za-z_]),Direction(*out),Subject([0-9A-Za-z_]|*all),RatesFallbackSubject([0-9A-Za-z_]|<empty>),RatesTimingTag([0-9A-Za-z_]),ActivationTime([0-9T:X])"},
utils.SHARED_GROUPS_CSV: &FileLineRegexValidator{utils.SHARED_GROUPS_NRCOLS,
regexp.MustCompile(`(?:\w+\s*),(?:\*?\w+\s*),(?:\*\w+\s*),(?:\*?\w+\s*)?`),
regexp.MustCompile(`(?:\w+\s*),(?:\*?\w+\s*),(?:\*\w+\s*),(?:\*?\w]+\s*)?`),
"Id([0-9A-Za-z_]),Account(*?[0-9A-Za-z_]),Strategy(*[0-9A-Za-z_]),RatingSubject(*?[0-9A-Za-z_])"},
utils.ACTIONS_CSV: &FileLineRegexValidator{utils.ACTIONS_NRCOLS,
regexp.MustCompile(`^(?:\w+\s*),(?:\*\w+\s*),(?:\*\w+\s*)?,(?:\*out\s*)?,(?:\d+\s*)?,(?:\*\w+\s*|\+\d+[smh]\s*|\d+\s*)?,(?:\*any|\w+\s*)?,(?:\*?\w+\s*)?,(?:\d+\.?\d*\s*)?,(?:\w+\s*)?,(?:\S+\s*)?,(?:\d+\.?\d*\s*)$`),

View File

@@ -41,7 +41,7 @@ type SharedGroup struct {
Id string
AccountParameters map[string]*SharingParameters
MemberIds []string
members []*Account // accounts caching
//members []*Account // accounts caching
}
type SharingParameters struct {
@@ -103,27 +103,27 @@ func (sg *SharedGroup) SortBalancesByStrategy(myBalance *Balance, bc BalanceChai
// Returns all shared group's balances collected from user accounts'
func (sg *SharedGroup) GetBalances(destination, balanceType string, ub *Account) (bc BalanceChain) {
if len(sg.members) == 0 {
for _, ubId := range sg.MemberIds {
var nUb *Account
if ubId == ub.Id { // skip the initiating user
nUb = ub
} else {
nUb, _ = accountingStorage.GetAccount(ubId)
if nUb == nil || nUb.Disabled {
continue
}
// if len(sg.members) == 0 {
for _, ubId := range sg.MemberIds {
var nUb *Account
if ubId == ub.Id { // skip the initiating user
nUb = ub
} else {
nUb, _ = accountingStorage.GetAccount(ubId)
if nUb == nil || nUb.Disabled {
continue
}
sg.members = append(sg.members, nUb)
sb := nUb.getBalancesForPrefix(destination, nUb.BalanceMap[balanceType], sg.Id)
bc = append(bc, sb...)
}
} else {
//sg.members = append(sg.members, nUb)
sb := nUb.getBalancesForPrefix(destination, nUb.BalanceMap[balanceType], sg.Id)
bc = append(bc, sb...)
}
/* } else {
for _, m := range sg.members {
sb := m.getBalancesForPrefix(destination, m.BalanceMap[balanceType], sg.Id)
bc = append(bc, sb...)
}
}
}*/
return
}