mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 08:08:45 +05:00
fixes and tests for blocker flag, fixes #274
This commit is contained in:
@@ -318,11 +318,11 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo
|
||||
}
|
||||
// check for blocker
|
||||
if dryRun && balance.Blocker {
|
||||
//log.Print("BLOCKER!")
|
||||
return // don't go to next balances
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// debit money
|
||||
moneyBalanceChecker := true
|
||||
for moneyBalanceChecker {
|
||||
@@ -336,14 +336,13 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo
|
||||
return nil, debitErr
|
||||
}
|
||||
//utils.Logger.Info(fmt.Sprintf("CD AFTER MONEY: %+v", cd))
|
||||
//log.Printf("partCC: %+v", partCC)
|
||||
if partCC != nil {
|
||||
cc.Timespans = append(cc.Timespans, partCC.Timespans...)
|
||||
cc.negativeConnectFee = partCC.negativeConnectFee
|
||||
|
||||
//for i, ts := range cc.Timespans {
|
||||
//log.Printf("cc.times[an[%d]: %+v\n", i, ts)
|
||||
//}
|
||||
/*for i, ts := range cc.Timespans {
|
||||
log.Printf("cc.times[an[%d]: %+v\n", i, ts)
|
||||
}*/
|
||||
cd.TimeStart = cc.GetEndTime()
|
||||
//log.Printf("CD: %+v", cd)
|
||||
//log.Printf("CD: %+v - %+v", cd.TimeStart, cd.TimeEnd)
|
||||
@@ -360,6 +359,7 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo
|
||||
}
|
||||
// check for blocker
|
||||
if dryRun && balance.Blocker {
|
||||
//log.Print("BLOCKER!")
|
||||
return // don't go to next balances
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,7 @@ func (b *Balance) Clone() *Balance {
|
||||
SharedGroups: b.SharedGroups,
|
||||
TimingIDs: b.TimingIDs,
|
||||
Timings: b.Timings, // should not be a problem with aliasing
|
||||
Blocker: b.Blocker,
|
||||
Disabled: b.Disabled,
|
||||
dirty: b.dirty,
|
||||
}
|
||||
|
||||
@@ -555,7 +555,6 @@ func (origCD *CallDescriptor) getMaxSessionDuration(origAcc *Account) (time.Dura
|
||||
//utils.Logger.Debug("ACCOUNT: " + utils.ToJSON(account))
|
||||
//utils.Logger.Debug("DEFAULT_BALANCE: " + utils.ToJSON(defaultBalance))
|
||||
|
||||
//
|
||||
cc, err := cd.debit(account, true, false)
|
||||
//utils.Logger.Debug("CC: " + utils.ToJSON(cc))
|
||||
//log.Print("CC: ", utils.ToIJSON(cc))
|
||||
|
||||
@@ -537,6 +537,57 @@ func TestMaxSessionTimeWithMaxCost(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMaxSessiontWithBlocker(t *testing.T) {
|
||||
ap, _ := ratingStorage.GetActionPlan("BLOCK_AT", false)
|
||||
for _, at := range ap.ActionTimings {
|
||||
at.accountIDs = ap.AccountIDs
|
||||
at.Execute()
|
||||
}
|
||||
acc, err := accountingStorage.GetAccount("cgrates.org:block")
|
||||
if err != nil {
|
||||
t.Error("error getting account: ", err)
|
||||
}
|
||||
if len(acc.BalanceMap[utils.MONETARY]) != 2 ||
|
||||
acc.BalanceMap[utils.MONETARY][0].Blocker != true {
|
||||
for _, b := range acc.BalanceMap[utils.MONETARY] {
|
||||
t.Logf("B: %+v", b)
|
||||
}
|
||||
t.Error("Error executing action plan on account: ", acc.BalanceMap[utils.MONETARY])
|
||||
}
|
||||
cd := &CallDescriptor{
|
||||
Direction: "*out",
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "block",
|
||||
Account: "block",
|
||||
Destination: "0723",
|
||||
TimeStart: time.Date(2016, 1, 13, 14, 0, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2016, 1, 13, 14, 30, 0, 0, time.UTC),
|
||||
MaxCostSoFar: 0,
|
||||
}
|
||||
result, err := cd.GetMaxSessionDuration()
|
||||
expected := 985 * time.Second
|
||||
if result != expected || err != nil {
|
||||
t.Errorf("Expected %v was %v (%v)", expected, result, err)
|
||||
}
|
||||
cd = &CallDescriptor{
|
||||
Direction: "*out",
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "block",
|
||||
Account: "block",
|
||||
Destination: "444",
|
||||
TimeStart: time.Date(2016, 1, 13, 14, 0, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2016, 1, 13, 14, 30, 0, 0, time.UTC),
|
||||
MaxCostSoFar: 0,
|
||||
}
|
||||
result, err = cd.GetMaxSessionDuration()
|
||||
expected = 30 * time.Minute
|
||||
if result != expected || err != nil {
|
||||
t.Errorf("Expected %v was %v (%v)", expected, result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCostWithMaxCost(t *testing.T) {
|
||||
ap, _ := ratingStorage.GetActionPlan("TOPUP10_AT", false)
|
||||
for _, at := range ap.ActionTimings {
|
||||
@@ -560,6 +611,7 @@ func TestGetCostWithMaxCost(t *testing.T) {
|
||||
t.Errorf("Expected %v was %v", expected, cc.Cost)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCostRoundingIssue(t *testing.T) {
|
||||
ap, _ := ratingStorage.GetActionPlan("TOPUP10_AT", false)
|
||||
for _, at := range ap.ActionTimings {
|
||||
|
||||
@@ -147,6 +147,7 @@ DY_PLAN,RT_DY,*any,10
|
||||
*in,cgrates.org,LCR_STANDARD,max,2013-03-23T00:00:00Z,RP_MX,,
|
||||
*out,cgrates.org,call,money,2015-02-28T00:00:00Z,EVENING,,
|
||||
*out,cgrates.org,call,dy,2015-02-28T00:00:00Z,DY_PLAN,,
|
||||
*out,cgrates.org,call,block,2015-02-28T00:00:00Z,DY_PLAN,,
|
||||
`
|
||||
sharedGroups = `
|
||||
SG1,*any,*lowest,
|
||||
@@ -171,6 +172,8 @@ EE0,*topup_reset,,,*monetary,*out,,,,SG3,*unlimited,,0,10,false,false,10
|
||||
EE0,*allow_negative,,,*monetary,*out,,,,,*unlimited,,0,10,false,false,10
|
||||
DEFEE,*cdrlog,"{""Category"":""^ddi"",""MediationRunId"":""^did_run""}",,,,,,,,,,,,false,false,10
|
||||
NEG,*allow_negative,,,*monetary,*out,,,,,*unlimited,,0,10,false,false,10
|
||||
BLOCK,*topup,,bblocker,*monetary,*out,,NAT,,,*unlimited,,10,20,true,false,20
|
||||
BLOCK,*topup,,bfree,*monetary,*out,,,,,*unlimited,,20,10,false,false,10
|
||||
`
|
||||
actionPlans = `
|
||||
MORE_MINUTES,MINI,ONE_TIME_RUN,10
|
||||
@@ -181,6 +184,7 @@ TOPUP_SHARED0_AT,SE0,*asap,10
|
||||
TOPUP_SHARED10_AT,SE10,*asap,10
|
||||
TOPUP_EMPTY_AT,EE0,*asap,10
|
||||
POST_AT,NEG,*asap,10
|
||||
BLOCK_AT,BLOCK,*asap,10
|
||||
`
|
||||
|
||||
actionTriggers = `
|
||||
@@ -207,6 +211,7 @@ vdf,emptyX,TOPUP_EMPTY_AT,,,
|
||||
vdf,emptyY,TOPUP_EMPTY_AT,,,
|
||||
vdf,post,POST_AT,,,
|
||||
cgrates.org,alodis,TOPUP_EMPTY_AT,,true,true
|
||||
cgrates.org,block,BLOCK_AT,,false,false
|
||||
`
|
||||
|
||||
derivedCharges = `
|
||||
@@ -790,7 +795,7 @@ func TestLoadRatingPlans(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadRatingProfiles(t *testing.T) {
|
||||
if len(csvr.ratingProfiles) != 22 {
|
||||
if len(csvr.ratingProfiles) != 23 {
|
||||
t.Error("Failed to load rating profiles: ", len(csvr.ratingProfiles), csvr.ratingProfiles)
|
||||
}
|
||||
rp := csvr.ratingProfiles["*out:test:0:trp"]
|
||||
@@ -809,7 +814,7 @@ func TestLoadRatingProfiles(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadActions(t *testing.T) {
|
||||
if len(csvr.actions) != 9 {
|
||||
if len(csvr.actions) != 10 {
|
||||
t.Error("Failed to load actions: ", len(csvr.actions))
|
||||
}
|
||||
as1 := csvr.actions["MINI"]
|
||||
@@ -822,12 +827,14 @@ func TestLoadActions(t *testing.T) {
|
||||
ExtraParameters: "",
|
||||
Weight: 10,
|
||||
Balance: &Balance{
|
||||
Uuid: as1[0].Balance.Uuid,
|
||||
Directions: utils.NewStringMap(utils.OUT),
|
||||
Value: 10,
|
||||
Weight: 10,
|
||||
TimingIDs: utils.StringMap{},
|
||||
SharedGroups: utils.StringMap{},
|
||||
Uuid: as1[0].Balance.Uuid,
|
||||
Directions: utils.NewStringMap(utils.OUT),
|
||||
Value: 10,
|
||||
Weight: 10,
|
||||
DestinationIds: utils.StringMap{},
|
||||
TimingIDs: utils.StringMap{},
|
||||
SharedGroups: utils.StringMap{},
|
||||
Categories: utils.StringMap{},
|
||||
},
|
||||
},
|
||||
&Action{
|
||||
@@ -846,10 +853,11 @@ func TestLoadActions(t *testing.T) {
|
||||
DestinationIds: utils.NewStringMap("NAT"),
|
||||
TimingIDs: utils.StringMap{},
|
||||
SharedGroups: utils.StringMap{},
|
||||
Categories: utils.StringMap{},
|
||||
},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(as1[1], expected[1]) {
|
||||
if !reflect.DeepEqual(as1, expected) {
|
||||
t.Errorf("Error loading action1: %+v", as1[0].Balance)
|
||||
}
|
||||
as2 := csvr.actions["SHARED"]
|
||||
@@ -868,10 +876,11 @@ func TestLoadActions(t *testing.T) {
|
||||
Weight: 10,
|
||||
SharedGroups: utils.NewStringMap("SG1"),
|
||||
TimingIDs: utils.StringMap{},
|
||||
Categories: utils.StringMap{},
|
||||
},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(as2[0], expected[0]) {
|
||||
if !reflect.DeepEqual(as2, expected) {
|
||||
t.Errorf("Error loading action: %+v", as2[0].Balance)
|
||||
}
|
||||
as3 := csvr.actions["DEFEE"]
|
||||
@@ -886,7 +895,9 @@ func TestLoadActions(t *testing.T) {
|
||||
Directions: utils.StringMap{},
|
||||
DestinationIds: utils.StringMap{},
|
||||
TimingIDs: utils.StringMap{},
|
||||
Categories: utils.StringMap{},
|
||||
SharedGroups: utils.StringMap{},
|
||||
Blocker: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -982,7 +993,7 @@ func TestLoadLCRs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadActionTimings(t *testing.T) {
|
||||
if len(csvr.actionPlans) != 6 {
|
||||
if len(csvr.actionPlans) != 7 {
|
||||
t.Error("Failed to load action timings: ", len(csvr.actionPlans))
|
||||
}
|
||||
atm := csvr.actionPlans["MORE_MINUTES"]
|
||||
@@ -1070,7 +1081,7 @@ func TestLoadActionTriggers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadAccountActions(t *testing.T) {
|
||||
if len(csvr.accountActions) != 11 {
|
||||
if len(csvr.accountActions) != 12 {
|
||||
t.Error("Failed to load account actions: ", len(csvr.accountActions))
|
||||
}
|
||||
aa := csvr.accountActions["vdf:minitsboy"]
|
||||
|
||||
@@ -274,7 +274,7 @@ func TestDifferentUuid(t *testing.T) {
|
||||
|
||||
func TestStorageTask(t *testing.T) {
|
||||
// clean previous unused tasks
|
||||
for i := 0; i < 16; i++ {
|
||||
for i := 0; i < 18; i++ {
|
||||
ratingStorage.PopTask()
|
||||
}
|
||||
|
||||
|
||||
@@ -523,6 +523,8 @@ func (tpr *TpReader) LoadActions() (err error) {
|
||||
DestinationIds: utils.ParseStringMap(tpact.DestinationIds),
|
||||
SharedGroups: utils.ParseStringMap(tpact.SharedGroups),
|
||||
TimingIDs: utils.ParseStringMap(tpact.TimingTags),
|
||||
Blocker: tpact.BalanceBlocker,
|
||||
Disabled: tpact.BalanceDisabled,
|
||||
},
|
||||
}
|
||||
// load action timings from tags
|
||||
@@ -640,6 +642,8 @@ func (tpr *TpReader) LoadActionTriggers() (err error) {
|
||||
BalanceRatingSubject: atr.BalanceRatingSubject,
|
||||
BalanceCategories: utils.ParseStringMap(atr.BalanceCategories),
|
||||
BalanceSharedGroups: utils.ParseStringMap(atr.BalanceSharedGroups),
|
||||
BalanceBlocker: atr.BalanceBlocker,
|
||||
BalanceDisabled: atr.BalanceDisabled,
|
||||
Weight: atr.Weight,
|
||||
ActionsId: atr.ActionsId,
|
||||
MinQueuedItems: atr.MinQueuedItems,
|
||||
@@ -788,9 +792,12 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
|
||||
BalanceDestinationIds: utils.ParseStringMap(apiAtr.BalanceDestinationIds),
|
||||
BalanceWeight: apiAtr.BalanceWeight,
|
||||
BalanceExpirationDate: expTime,
|
||||
BalanceTimingTags: utils.ParseStringMap(apiAtr.BalanceTimingTags),
|
||||
BalanceRatingSubject: apiAtr.BalanceRatingSubject,
|
||||
BalanceCategories: utils.ParseStringMap(apiAtr.BalanceCategories),
|
||||
BalanceSharedGroups: utils.ParseStringMap(apiAtr.BalanceSharedGroups),
|
||||
BalanceBlocker: apiAtr.BalanceBlocker,
|
||||
BalanceDisabled: apiAtr.BalanceDisabled,
|
||||
Weight: apiAtr.Weight,
|
||||
ActionsId: apiAtr.ActionsId,
|
||||
}
|
||||
@@ -831,13 +838,17 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
|
||||
ExtraParameters: tpact.ExtraParameters,
|
||||
ExpirationString: tpact.ExpiryTime,
|
||||
Balance: &Balance{
|
||||
Id: tpact.BalanceId,
|
||||
Value: tpact.Units,
|
||||
Weight: tpact.BalanceWeight,
|
||||
RatingSubject: tpact.RatingSubject,
|
||||
Categories: utils.ParseStringMap(tpact.Categories),
|
||||
Directions: utils.ParseStringMap(tpact.Directions),
|
||||
DestinationIds: utils.ParseStringMap(tpact.DestinationIds),
|
||||
SharedGroups: utils.ParseStringMap(tpact.SharedGroups),
|
||||
TimingIDs: utils.ParseStringMap(tpact.TimingTags),
|
||||
Blocker: tpact.BalanceBlocker,
|
||||
Disabled: tpact.BalanceDisabled,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1056,13 +1067,17 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
|
||||
ExtraParameters: tpact.ExtraParameters,
|
||||
ExpirationString: tpact.ExpiryTime,
|
||||
Balance: &Balance{
|
||||
Id: tpact.BalanceId,
|
||||
Value: tpact.Units,
|
||||
Weight: tpact.BalanceWeight,
|
||||
RatingSubject: tpact.RatingSubject,
|
||||
Categories: utils.ParseStringMap(tpact.Categories),
|
||||
Directions: utils.ParseStringMap(tpact.Directions),
|
||||
DestinationIds: utils.ParseStringMap(tpact.DestinationIds),
|
||||
SharedGroups: utils.ParseStringMap(tpact.SharedGroups),
|
||||
TimingIDs: utils.ParseStringMap(tpact.TimingTags),
|
||||
Blocker: tpact.BalanceBlocker,
|
||||
Disabled: tpact.BalanceDisabled,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user