From c6de1536850ee759b4a2291102e7d7fba9f05e09 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 20 Mar 2014 19:05:31 +0200 Subject: [PATCH] more tests and disabled shared gropup caching --- engine/calldesc_test.go | 37 +++++++++++++++++++++++++++++++++++++ engine/loader_csv_test.go | 12 ++++++------ engine/loader_helpers.go | 2 +- engine/sharedgroup.go | 32 ++++++++++++++++---------------- 4 files changed, 60 insertions(+), 23 deletions(-) diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 37820d67e..a791aee6a 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -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), diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 10d291bee..ec90f6250 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -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", }, }, } diff --git a/engine/loader_helpers.go b/engine/loader_helpers.go index 81a964f48..0b712e29d 100644 --- a/engine/loader_helpers.go +++ b/engine/loader_helpers.go @@ -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_]|),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*)$`), diff --git a/engine/sharedgroup.go b/engine/sharedgroup.go index 7e00218a6..00e4c1a02 100644 --- a/engine/sharedgroup.go +++ b/engine/sharedgroup.go @@ -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 }