diff --git a/data/rates/prepaid1centpsec/AccountActions.csv b/data/rates/prepaid1centpsec/AccountActions.csv
new file mode 100644
index 000000000..f29a618b7
--- /dev/null
+++ b/data/rates/prepaid1centpsec/AccountActions.csv
@@ -0,0 +1,6 @@
+Tenant,Account,Direction,ActionTimingsTag,ActionTriggersTag
+0,1000,OUT,TOPUP_10,
+0,1001,OUT,TOPUP_10,
+0,1002,OUT,TOPUP_10,
+0,1003,OUT,TOPUP_10,
+0,1004,OUT,TOPUP_10,
diff --git a/data/rates/prepaid1centpsec/ActionTimings.csv b/data/rates/prepaid1centpsec/ActionTimings.csv
new file mode 100644
index 000000000..3666bbbdd
--- /dev/null
+++ b/data/rates/prepaid1centpsec/ActionTimings.csv
@@ -0,0 +1,2 @@
+Tag,ActionsTag,TimingTag, Weight
+TOPUP_10,TOPUP_10,ONE_TIME_RUN,10
diff --git a/data/rates/prepaid1centpsec/ActionTriggers.csv b/data/rates/prepaid1centpsec/ActionTriggers.csv
new file mode 100644
index 000000000..98f8664a3
--- /dev/null
+++ b/data/rates/prepaid1centpsec/ActionTriggers.csv
@@ -0,0 +1 @@
+Tag,BalanceTag,Direction,ThresholdValue,DestinationTag,ActionsTag,Weight
diff --git a/data/rates/prepaid1centpsec/Actions.csv b/data/rates/prepaid1centpsec/Actions.csv
new file mode 100644
index 000000000..51185c239
--- /dev/null
+++ b/data/rates/prepaid1centpsec/Actions.csv
@@ -0,0 +1,2 @@
+Tag,Action,BalanceTag,Direction,Units,DestinationTag,PriceType,PriceValue,MinutesWeight,Weight
+TOPUP_10,TOPUP_RESET,MONETARY,OUT,10,*all,,,,10
diff --git a/data/rates/prepaid1centpsec/Destinations.csv b/data/rates/prepaid1centpsec/Destinations.csv
new file mode 100644
index 000000000..6ce750b31
--- /dev/null
+++ b/data/rates/prepaid1centpsec/Destinations.csv
@@ -0,0 +1,2 @@
+Tag,Prefix
+FS_USERS,10
diff --git a/data/rates/prepaid1centpsec/README.md b/data/rates/prepaid1centpsec/README.md
new file mode 100644
index 000000000..b5eb5182a
--- /dev/null
+++ b/data/rates/prepaid1centpsec/README.md
@@ -0,0 +1,10 @@
+CGRateS - Prepaid1CentPSec
+===========================
+
+Scenario:
+--------
+
+* Creates 5 prepaid accounts
+* Loads prepaid accounts each with 10 units of credit
+* Defines rates of 1 cent per second for TOR 0, Tenant 0, independent of time of the call.
+
diff --git a/data/rates/prepaid1centpsec/RateTimings.csv b/data/rates/prepaid1centpsec/RateTimings.csv
new file mode 100644
index 000000000..358b46120
--- /dev/null
+++ b/data/rates/prepaid1centpsec/RateTimings.csv
@@ -0,0 +1,2 @@
+Tag,RatesTag,TimingProfile,Weight
+1CENTPERSEC,1CENTPERSEC,ALWAYS,10
diff --git a/data/rates/prepaid1centpsec/Rates.csv b/data/rates/prepaid1centpsec/Rates.csv
new file mode 100644
index 000000000..4dc0502c1
--- /dev/null
+++ b/data/rates/prepaid1centpsec/Rates.csv
@@ -0,0 +1,2 @@
+Tag,DestinationsTag,ConnectFee,Price,PricedUnits,RateIncrements
+1CENTPERSEC,FS_USERS,0,0.01,1,1
diff --git a/data/rates/prepaid1centpsec/RatingProfiles.csv b/data/rates/prepaid1centpsec/RatingProfiles.csv
new file mode 100644
index 000000000..2a572f58f
--- /dev/null
+++ b/data/rates/prepaid1centpsec/RatingProfiles.csv
@@ -0,0 +1,2 @@
+Tenant,TOR,Direction,Subject,RatesFallbackSubject,RatesTimingTag,ActivationTime
+0,0,OUT,*all,,1CENTPERSEC,2013-01-01T00:00:00Z
diff --git a/data/rates/prepaid1centpsec/Timings.csv b/data/rates/prepaid1centpsec/Timings.csv
new file mode 100644
index 000000000..95475f4dc
--- /dev/null
+++ b/data/rates/prepaid1centpsec/Timings.csv
@@ -0,0 +1,3 @@
+Tag,Years,Months,MonthDays,WeekDays,Time
+ALWAYS,*all,*all,*all,*all,00:00:00
+ONE_TIME_RUN,,,,,*asap
diff --git a/rater/accountlock_test.go b/rater/accountlock_test.go
index e9974df94..d9372837c 100644
--- a/rater/accountlock_test.go
+++ b/rater/accountlock_test.go
@@ -19,12 +19,12 @@ along with this program. If not, see
package rater
import (
+ "log"
"testing"
"time"
- "log"
)
-func ATestAccountLock(t *testing.T) {
+func ATestAccountLock(t *testing.T) {
go AccLock.Guard("1", func() (float64, error) {
log.Print("first 1")
time.Sleep(1 * time.Second)
diff --git a/rater/action.go b/rater/action.go
index df35b599d..7aece9371 100644
--- a/rater/action.go
+++ b/rater/action.go
@@ -40,30 +40,30 @@ type Action struct {
type actionTypeFunc func(*UserBalance, *Action) error
-func getActionFunc(typ string)(actionTypeFunc, bool) {
+func getActionFunc(typ string) (actionTypeFunc, bool) {
switch typ {
- case "LOG":
- return logAction, true
- case "RESET_TRIGGERS":
- return resetTriggersAction, true
- case "SET_POSTPAID":
- return setPostpaidAction, true
- case "RESET_POSTPAID":
- return resetPostpaidAction, true
- case "SET_PREPAID":
- return setPrepaidAction, true
- case "RESET_PREPAID":
- return resetPrepaidAction, true
- case "TOPUP_RESET":
- return topupResetAction, true
- case "TOPUP":
- return topupAction, true
- case "DEBIT":
- return debitAction, true
- case "RESET_COUNTER":
- return resetCounterAction, true
- case "RESET_COUNTERS":
- return resetCountersAction, true
+ case "LOG":
+ return logAction, true
+ case "RESET_TRIGGERS":
+ return resetTriggersAction, true
+ case "SET_POSTPAID":
+ return setPostpaidAction, true
+ case "RESET_POSTPAID":
+ return resetPostpaidAction, true
+ case "SET_PREPAID":
+ return setPrepaidAction, true
+ case "RESET_PREPAID":
+ return resetPrepaidAction, true
+ case "TOPUP_RESET":
+ return topupResetAction, true
+ case "TOPUP":
+ return topupAction, true
+ case "DEBIT":
+ return debitAction, true
+ case "RESET_COUNTER":
+ return resetCounterAction, true
+ case "RESET_COUNTERS":
+ return resetCountersAction, true
}
return nil, false
}
@@ -79,7 +79,7 @@ func resetTriggersAction(ub *UserBalance, a *Action) (err error) {
}
func setPostpaidAction(ub *UserBalance, a *Action) (err error) {
- ub.Type = UB_TYPE_POSTPAID
+ ub.Type = UB_TYPE_POSTPAID
return
}
diff --git a/rater/action_timing.go b/rater/action_timing.go
index d38f4e56e..22913b25f 100644
--- a/rater/action_timing.go
+++ b/rater/action_timing.go
@@ -305,7 +305,7 @@ func (at *ActionTiming) restore(input string) {
at.Id = elements[0]
at.Tag = elements[1]
for _, ubi := range strings.Split(elements[2], ",") {
- if strings.TrimSpace(ubi) != ""{
+ if strings.TrimSpace(ubi) != "" {
at.UserBalanceIds = append(at.UserBalanceIds, ubi)
}
}
diff --git a/rater/calldesc.go b/rater/calldesc.go
index 5dbabd9d8..6431580e6 100644
--- a/rater/calldesc.go
+++ b/rater/calldesc.go
@@ -350,10 +350,10 @@ func (cd *CallDescriptor) Debit() (cc *CallCost, err error) {
Logger.Err(fmt.Sprintf(" Error getting cost for account key %v: %v", cd.GetUserBalanceKey(), err))
return
}
- if userBalance, err := cd.getUserBalance(); err == nil && userBalance != nil {
+ if userBalance, err := cd.getUserBalance(); err != nil {
Logger.Err(fmt.Sprintf(" Error retrieving user balance: %v", err))
} else if userBalance == nil {
- Logger.Debug(fmt.Sprintf(" No user balance defined: %v",cd.GetUserBalanceKey()))
+ Logger.Debug(fmt.Sprintf(" No user balance defined: %v", cd.GetUserBalanceKey()))
} else {
Logger.Debug(fmt.Sprintf(" Attempting to debit from %v, value: %v", cd.GetUserBalanceKey(), cc.Cost+cc.ConnectFee))
defer storageGetter.SetUserBalance(userBalance)
diff --git a/sessionmanager/fssessionmanager.go b/sessionmanager/fssessionmanager.go
index d5cf0ef36..694dad2ae 100644
--- a/sessionmanager/fssessionmanager.go
+++ b/sessionmanager/fssessionmanager.go
@@ -207,14 +207,14 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
return
}
cd := rater.CallDescriptor{
- Direction: ev.GetDirection(),
- Tenant: ev.GetTenant(),
- TOR: ev.GetTOR(),
- Subject: ev.GetSubject(),
- Account: ev.GetAccount(),
- Destination: ev.GetDestination(),
- TimeStart: startTime,
- TimeEnd: endTime,
+ Direction: ev.GetDirection(),
+ Tenant: ev.GetTenant(),
+ TOR: ev.GetTOR(),
+ Subject: ev.GetSubject(),
+ Account: ev.GetAccount(),
+ Destination: ev.GetDestination(),
+ TimeStart: startTime,
+ TimeEnd: endTime,
FallbackSubject: ev.GetFallbackSubj(),
}
cc := &rater.CallCost{}
@@ -342,8 +342,8 @@ func (sm *FSSessionManager) Shutdown() (err error) {
rater.Logger.Info("Shutting down all sessions...")
cmdKillPrepaid := "hupall MANAGER_REQUEST cgr_reqtype prepaid"
cmdKillPostpaid := "hupall MANAGER_REQUEST cgr_reqtype postpaid"
- for _,cmd := range[]string{cmdKillPrepaid, cmdKillPostpaid} {
- if err = fsock.FS.SendApiCmd(cmd); err!= nil {
+ for _, cmd := range []string{cmdKillPrepaid, cmdKillPostpaid} {
+ if err = fsock.FS.SendApiCmd(cmd); err != nil {
rater.Logger.Err(fmt.Sprintf("Error on calls shutdown: %s", err))
return
}
diff --git a/sessionmanager/session.go b/sessionmanager/session.go
index bb5caf900..482a74343 100644
--- a/sessionmanager/session.go
+++ b/sessionmanager/session.go
@@ -43,7 +43,7 @@ func NewSession(ev Event, sm SessionManager) (s *Session) {
return
}
// Make sure cgr_type is enforced even if not set by FreeSWITCH
- if err := fsock.FS.SendApiCmd(fmt.Sprintf("uuid_setvar %s cgr_reqtype %s\n\n", ev.GetUUID(), ev.GetReqType())); err!=nil {
+ if err := fsock.FS.SendApiCmd(fmt.Sprintf("uuid_setvar %s cgr_reqtype %s\n\n", ev.GetUUID(), ev.GetReqType())); err != nil {
rater.Logger.Err(fmt.Sprintf("Error on attempting to overwrite cgr_type in chan variables: %v", err))
}
startTime, err := ev.GetStartTime(START_TIME)
diff --git a/sessionmanager/session_test.go b/sessionmanager/session_test.go
index fd831f50a..b1673db2f 100644
--- a/sessionmanager/session_test.go
+++ b/sessionmanager/session_test.go
@@ -19,8 +19,8 @@ along with this program. If not, see
package sessionmanager
import (
- "testing"
"github.com/cgrates/cgrates/config"
+ "testing"
// "time"
)
@@ -67,9 +67,9 @@ var (
func TestSessionNilSession(t *testing.T) {
cfgTestPath := "../config/test_data.txt"
var errCfg error
- cfg,errCfg = config.NewCGRConfig(&cfgTestPath) // Needed here to avoid nil on cfg variable
- if errCfg!= nil {
- t.Errorf("Cannot get configuration %v",errCfg)
+ cfg, errCfg = config.NewCGRConfig(&cfgTestPath) // Needed here to avoid nil on cfg variable
+ if errCfg != nil {
+ t.Errorf("Cannot get configuration %v", errCfg)
}
newEvent := new(FSEvent).New("")
sm := &FSSessionManager{}