diff --git a/engine/calldesc.go b/engine/calldesc.go index 0ca85df9a..e8b64d1f5 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -125,7 +125,7 @@ func (cd *CallDescriptor) ValidateCallData() error { return errors.New("TimeStart must be strctly before TimeEnd") } if cd.TimeEnd.Sub(cd.TimeStart) < cd.DurationIndex { - return errors.New("CallDuration must be equal or grater than TimeEnd - TimeStart") + return errors.New("DurationIndex must be equal or grater than TimeEnd - TimeStart") } return nil } diff --git a/engine/realcalls_test.go b/engine/realcalls_test.go index cf459464b..fbe353f1d 100644 --- a/engine/realcalls_test.go +++ b/engine/realcalls_test.go @@ -25,7 +25,7 @@ import ( var balance1 string = `{"Id":"*out:192.168.56.66:dan","Type":"*prepaid","BalanceMap":{"*monetary*out":[{"Uuid":"7fe5d6e740b6edd180b96274b8bd4123","Value":10,"ExpirationDate":"0001-01-01T00:00:00Z","Weight":10,"GroupIds":null,"DestinationId":"*any","RateSubject":""}]},"UnitCounters":null,"ActionTriggers":[{"Id":"120ea04d40af91c580adb0da11554c88","BalanceId":"*monetary","Direction":"*out","ThresholdType":"*min_balance","ThresholdValue":2,"DestinationId":"","Weight":10,"ActionsId":"LOG_BALANCE","Executed":false},{"Id":"fa217a904059cfd3806239f5ad229f4a","BalanceId":"*monetary","Direction":"*out","ThresholdType":"*max_balance","ThresholdValue":20,"DestinationId":"","Weight":10,"ActionsId":"LOG_BALANCE","Executed":false},{"Id":"f05174b740ab987c802a0a29aa5a2764","BalanceId":"*monetary","Direction":"*out","ThresholdType":"*max_counter","ThresholdValue":15,"DestinationId":"FS_USERS","Weight":10,"ActionsId":"LOG_BALANCE","Executed":false},{"Id":"4d6ebf454048371280100094246163a7","BalanceId":"*monetary","Direction":"*out","ThresholdType":"*min_balance","ThresholdValue":0.1,"DestinationId":"","Weight":10,"ActionsId":"WARN_HTTP","Executed":false}],"Groups":null,"UserIds":null}` -var callCost1 string = `{"Direction":"*out","TOR":"call","Tenant":"192.168.56.66","Subject":"dan","Account":"dan","Destination":"+4986517174963","Cost":0.6,"ConnectFee":0,"Timespans":[{"TimeStart":"2013-12-03T14:36:48+01:00","TimeEnd":"2013-12-03T14:37:48+01:00","Cost":0.6,"RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0,"Rates":[{"GroupIntervalStart":0,"Value":0.6,"RateIncrement":60000000000,"RateUnit":60000000000}],"RoundingMethod":"*up","RoundingDecimals":2},"Weight":10},"CallDuration":60000000000,"Increments":null,"MatchedSubject":"*out:192.168.56.66:call:*any","MatchedPrefix":"+49"}]}` +var callCost1 string = `{"Direction":"*out","TOR":"call","Tenant":"192.168.56.66","Subject":"dan","Account":"dan","Destination":"+4986517174963","Cost":0.6,"ConnectFee":0,"Timespans":[{"TimeStart":"2013-12-03T14:36:48+01:00","TimeEnd":"2013-12-03T14:37:48+01:00","Cost":0.6,"RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0,"Rates":[{"GroupIntervalStart":0,"Value":0.6,"RateIncrement":60000000000,"RateUnit":60000000000}],"RoundingMethod":"*up","RoundingDecimals":2},"Weight":10},"DurationIndex":60000000000,"Increments":null,"MatchedSubject":"*out:192.168.56.66:call:*any","MatchedPrefix":"+49"}]}` func TestDebitBalanceForCall1(t *testing.T) { b1 := new(Account) @@ -47,7 +47,7 @@ func TestDebitBalanceForCall1(t *testing.T) { var balanceInsufficient = `{"Id":"*out:192.168.56.66:dan","Type":"*prepaid","BalanceMap":{"*monetary*out":[{"Uuid":"de49cb1a40b2740a8087a1d28112e11c","Value":1,"ExpirationDate":"0001-01-01T00:00:00Z","Weight":10,"GroupIds":null,"DestinationId":"*any","RateSubject":""}]},"UnitCounters":[{"Direction":"*out","BalanceId":"*monetary","Balances":[{"Uuid":"","Value":4,"ExpirationDate":"0001-01-01T00:00:00Z","Weight":0,"GroupIds":null,"DestinationId":"","RateSubject":""}]}],"ActionTriggers":[{"Id":"a33f036e402c2b47801f1380c5c82564","BalanceId":"*monetary","Direction":"*out","ThresholdType":"*min_balance","ThresholdValue":2,"DestinationId":"","Weight":10,"ActionsId":"LOG_BALANCE","Executed":true},{"Id":"91776f2d40496c03806cdbc73ae6b5f9","BalanceId":"*monetary","Direction":"*out","ThresholdType":"*max_balance","ThresholdValue":20,"DestinationId":"","Weight":10,"ActionsId":"LOG_BALANCE","Executed":false},{"Id":"e85e933a4045f77c80ef647295ae209b","BalanceId":"*monetary","Direction":"*out","ThresholdType":"*max_counter","ThresholdValue":15,"DestinationId":"FS_USERS","Weight":10,"ActionsId":"LOG_BALANCE","Executed":false},{"Id":"89c178b440a640b6802334b17b63cd4e","BalanceId":"*monetary","Direction":"*out","ThresholdType":"*min_balance","ThresholdValue":2.1,"DestinationId":"","Weight":10,"ActionsId":"WARN_HTTP","Executed":true}],"Groups":null,"UserIds":null}` -var costInsufficient = `{"Direction":"*out","TOR":"call","Tenant":"192.168.56.66","Subject":"dan","Account":"dan","Destination":"+4986517174963","Cost":1,"ConnectFee":3,"Timespans":[{"TimeStart":"2013-12-05T09:52:17+01:00","TimeEnd":"2013-12-05T09:53:17+01:00","Cost":1,"RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":3,"Rates":[{"GroupIntervalStart":0,"Value":1,"RateIncrement":60000000000,"RateUnit":60000000000}],"RoundingMethod":"*up","RoundingDecimals":2},"Weight":10},"CallDuration":60000000000,"Increments":null,"MatchedSubject":"*out:192.168.56.66:call:*any","MatchedPrefix":"+49"}]}` +var costInsufficient = `{"Direction":"*out","TOR":"call","Tenant":"192.168.56.66","Subject":"dan","Account":"dan","Destination":"+4986517174963","Cost":1,"ConnectFee":3,"Timespans":[{"TimeStart":"2013-12-05T09:52:17+01:00","TimeEnd":"2013-12-05T09:53:17+01:00","Cost":1,"RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":3,"Rates":[{"GroupIntervalStart":0,"Value":1,"RateIncrement":60000000000,"RateUnit":60000000000}],"RoundingMethod":"*up","RoundingDecimals":2},"Weight":10},"DurationIndex":60000000000,"Increments":null,"MatchedSubject":"*out:192.168.56.66:call:*any","MatchedPrefix":"+49"}]}` func TestDebitInsufficientBalance(t *testing.T) { b1 := new(Account) diff --git a/engine/timespans.go b/engine/timespans.go index dfb148bda..6d2c48809 100644 --- a/engine/timespans.go +++ b/engine/timespans.go @@ -341,7 +341,7 @@ func (ts *TimeSpan) SplitByRateInterval(i *RateInterval) (nts *TimeSpan) { ts.TimeEnd = splitTime nts.SetRateInterval(i) nts.DurationIndex = ts.DurationIndex - ts.SetNewCallDuration(nts) + ts.SetNewDurationIndex(nts) // Logger.Debug(fmt.Sprintf("Group splitting: %+v %+v", ts, nts)) return } @@ -369,7 +369,7 @@ func (ts *TimeSpan) SplitByRateInterval(i *RateInterval) (nts *TimeSpan) { nts.copyRatingInfo(ts) ts.TimeEnd = splitTime nts.DurationIndex = ts.DurationIndex - ts.SetNewCallDuration(nts) + ts.SetNewDurationIndex(nts) // Logger.Debug(fmt.Sprintf("right: %+v %+v", ts, nts)) return } @@ -391,7 +391,7 @@ func (ts *TimeSpan) SplitByRateInterval(i *RateInterval) (nts *TimeSpan) { nts.SetRateInterval(i) nts.DurationIndex = ts.DurationIndex - ts.SetNewCallDuration(nts) + ts.SetNewDurationIndex(nts) // Logger.Debug(fmt.Sprintf("left: %+v %+v", ts, nts)) return } @@ -414,7 +414,7 @@ func (ts *TimeSpan) SplitByIncrement(index int) *TimeSpan { ts.TimeEnd = timeStart newTs.Increments = ts.Increments[index:] ts.Increments = ts.Increments[:index] - ts.SetNewCallDuration(newTs) + ts.SetNewDurationIndex(newTs) return newTs } @@ -449,7 +449,7 @@ func (ts *TimeSpan) SplitByDuration(duration time.Duration) *TimeSpan { break } } - ts.SetNewCallDuration(newTs) + ts.SetNewDurationIndex(newTs) return newTs } @@ -465,7 +465,7 @@ func (ts *TimeSpan) SplitByRatingPlan(rp *RatingInfo) (newTs *TimeSpan) { newTs.copyRatingInfo(ts) newTs.DurationIndex = ts.DurationIndex ts.TimeEnd = rp.ActivationTime - ts.SetNewCallDuration(newTs) + ts.SetNewDurationIndex(newTs) // Logger.Debug(fmt.Sprintf("RP SPLITTING: %+v %+v", ts, newTs)) return } @@ -483,8 +483,8 @@ func (ts *TimeSpan) GetGroupEnd() time.Duration { return ts.DurationIndex } -// sets the CallDuration attribute to reflect new timespan -func (ts *TimeSpan) SetNewCallDuration(nts *TimeSpan) { +// sets the DurationIndex attribute to reflect new timespan +func (ts *TimeSpan) SetNewDurationIndex(nts *TimeSpan) { d := ts.DurationIndex - nts.GetDuration() if d < 0 { d = 0 diff --git a/engine/timespans_test.go b/engine/timespans_test.go index 78cb78b5d..8dfd85d94 100644 --- a/engine/timespans_test.go +++ b/engine/timespans_test.go @@ -533,7 +533,7 @@ func TestTimespanExpandingPastEnd(t *testing.T) { } } -func TestTimespanExpandingCallDuration(t *testing.T) { +func TestTimespanExpandingDurationIndex(t *testing.T) { timespans := []*TimeSpan{ &TimeSpan{ TimeStart: time.Date(2013, 9, 10, 14, 30, 0, 0, time.UTC),