Fix caching panic when item has errors

This commit is contained in:
DanB
2016-06-14 16:24:24 +02:00
parent 8bbb584b5d
commit 179da9c54e
3 changed files with 22 additions and 8 deletions

View File

@@ -32,7 +32,7 @@ import (
"github.com/cgrates/cgrates/utils"
)
var testTP = flag.Bool("tp", false, "Perform the tests in integration mode, not by default.")
var testTP = flag.Bool("tp", false, "Perform the tests for TariffPlans, not by default.") // Separate from integration so we can run on multiple DBs without involving all other tests on each run
var configDIR = flag.String("config_dir", "tutmysql", "Relative path towards a config directory under samples prefix")
var tpCfgPath string

View File

@@ -497,7 +497,9 @@ func (self *CdrServer) RateCDRs(cdrFltr *utils.CDRsFilter, sendToStats bool) err
func (self *CdrServer) V1ProcessCDR(cdr *CDR, reply *string) error {
cacheKey := "ProcessCdr" + cdr.CGRID
if item, err := self.getCache().Get(cacheKey); err == nil && item != nil {
*reply = item.Value.(string)
if item.Value != nil {
*reply = item.Value.(string)
}
return item.Err
}
if err := self.LocalProcessCdr(cdr); err != nil {

View File

@@ -150,7 +150,9 @@ func (rs *Responder) Debit(arg *CallDescriptor, reply *CallCost) (err error) {
func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error) {
cacheKey := utils.MAX_DEBIT_CACHE_PREFIX + arg.CgrID + arg.RunID + arg.DurationIndex.String()
if item, err := rs.getCache().Get(cacheKey); err == nil && item != nil {
*reply = *(item.Value.(*CallCost))
if item.Value != nil {
*reply = *(item.Value.(*CallCost))
}
return item.Err
}
if arg.Subject == "" {
@@ -198,7 +200,9 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err error) {
cacheKey := utils.REFUND_INCR_CACHE_PREFIX + arg.CgrID + arg.RunID
if item, err := rs.getCache().Get(cacheKey); err == nil && item != nil {
*reply = *(item.Value.(*float64))
if item.Value != nil {
*reply = *(item.Value.(*float64))
}
return item.Err
}
if arg.Subject == "" {
@@ -240,7 +244,9 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
func (rs *Responder) RefundRounding(arg *CallDescriptor, reply *float64) (err error) {
cacheKey := utils.REFUND_ROUND_CACHE_PREFIX + arg.CgrID + arg.RunID + arg.DurationIndex.String()
if item, err := rs.getCache().Get(cacheKey); err == nil && item != nil {
*reply = *(item.Value.(*float64))
if item.Value != nil {
*reply = *(item.Value.(*float64))
}
return item.Err
}
if arg.Subject == "" {
@@ -317,7 +323,9 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
}
cacheKey := utils.GET_DERIV_MAX_SESS_TIME + ev.CGRID + ev.RunID
if item, err := rs.getCache().Get(cacheKey); err == nil && item != nil {
*reply = *(item.Value.(*float64))
if item.Value != nil {
*reply = *(item.Value.(*float64))
}
return item.Err
}
if ev.Subject == "" {
@@ -423,7 +431,9 @@ func (rs *Responder) GetSessionRuns(ev *CDR, sRuns *[]*SessionRun) error {
}
cacheKey := utils.GET_SESS_RUNS_CACHE_PREFIX + ev.CGRID
if item, err := rs.getCache().Get(cacheKey); err == nil && item != nil {
*sRuns = *(item.Value.(*[]*SessionRun))
if item.Value != nil {
*sRuns = *(item.Value.(*[]*SessionRun))
}
return item.Err
}
if ev.Subject == "" {
@@ -519,7 +529,9 @@ func (rs *Responder) GetDerivedChargers(attrs *utils.AttrDerivedChargers, dcs *u
func (rs *Responder) GetLCR(attrs *AttrGetLcr, reply *LCRCost) error {
cacheKey := utils.LCRCachePrefix + attrs.CgrID + attrs.RunID
if item, err := rs.getCache().Get(cacheKey); err == nil && item != nil {
*reply = *(item.Value.(*LCRCost))
if item.Value != nil {
*reply = *(item.Value.(*LCRCost))
}
return item.Err
}
if attrs.CallDescriptor.Subject == "" {