Updated EventCost FieldAsInterface. Fixes #2375

This commit is contained in:
Trial97
2020-12-02 17:17:26 +02:00
committed by Dan Christian Bogos
parent 53f8b34f01
commit fbc2af6845
12 changed files with 243 additions and 69 deletions

View File

@@ -92,6 +92,7 @@ func init() {
gob.Register(time.Time{})
gob.Register(url.Values{})
gob.Register(json.RawMessage{})
gob.Register(BalanceSummaries{})
}
//SetCache shared the cache from other subsystems
@@ -440,6 +441,11 @@ func (chS *CacheS) ReplicateSet(chID, itmID string, value interface{}) (err erro
// V1ReplicateSet replicate an item
func (chS *CacheS) V1ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error) {
if cmp, canCast := args.Value.(utils.Compiler); canCast {
if err = cmp.Compile(); err != nil {
return
}
}
chS.tCache.Set(args.CacheID, args.ItemID, args.Value, nil, true, utils.EmptyString)
*reply = utils.OK
return

View File

@@ -901,6 +901,9 @@ func (ec *EventCost) FieldAsInterface(fldPath []string) (val interface{}, err er
if len(fldPath) == 0 {
return nil, utils.ErrNotFound
}
if ec.cache == nil {
ec.cache = utils.MapStorage{} // fix gob deserialization
}
if val, err = ec.cache.FieldAsInterface(fldPath); err != nil {
if err != utils.ErrNotFound { // item found in cache
return
@@ -958,12 +961,18 @@ func (ec *EventCost) fieldAsInterface(fldPath []string) (val interface{}, err er
if len(fldPath) != 1 {
return nil, utils.ErrNotFound
}
return ec.Usage, nil
if ec.Usage == nil {
return nil, nil
}
return *ec.Usage, nil
case utils.Cost:
if len(fldPath) != 1 {
return nil, utils.ErrNotFound
}
return ec.Cost, nil
if ec.Cost == nil {
return nil, nil
}
return *ec.Cost, nil
case utils.AccountSummary:
if len(fldPath) == 1 {
return ec.AccountSummary, nil

View File

@@ -2714,8 +2714,8 @@ func TestEventCostfieldAsInterface(t *testing.T) {
}
if rcv, err := eventCost.fieldAsInterface([]string{utils.Usage}); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(utils.DurationPointer(5*time.Minute), rcv) {
t.Errorf("Expecting: %+v, received: %+v", utils.DurationPointer(5*time.Minute), rcv)
} else if !reflect.DeepEqual(5*time.Minute, rcv) {
t.Errorf("Expecting: %+v, received: %+v", 5*time.Minute, rcv)
}
// case utils.Cost:
if rcv, err := eventCost.fieldAsInterface([]string{utils.Cost, utils.Cost}); err == nil || err != utils.ErrNotFound {
@@ -2728,8 +2728,8 @@ func TestEventCostfieldAsInterface(t *testing.T) {
}
if rcv, err := eventCost.fieldAsInterface([]string{utils.Cost}); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(utils.Float64Pointer(0.7), rcv) {
t.Errorf("Expecting: %+v, received: %+v", utils.Float64Pointer(0.7), rcv)
} else if !reflect.DeepEqual(0.7, rcv) {
t.Errorf("Expecting: %+v, received: %+v", 0.7, rcv)
}
// case utils.AccountSummary:
eventCost = &EventCost{

View File

@@ -592,11 +592,11 @@ func (iDB *InternalDB) RemTpData(table, tpid string, args map[string]string) (er
}
key := tpid
if args != nil {
if tpid == utils.TBLTPAccountActions {
if table == utils.TBLTPAccountActions {
key += utils.CONCATENATED_KEY_SEP + args["loadid"] +
utils.CONCATENATED_KEY_SEP + args["tenant"] +
utils.CONCATENATED_KEY_SEP + args["account"]
} else if tpid == utils.TBLTPRatingProfiles {
} else if table == utils.TBLTPRatingProfiles {
key += utils.CONCATENATED_KEY_SEP + args["loadid"] +
utils.CONCATENATED_KEY_SEP + args["tenant"] +
utils.CONCATENATED_KEY_SEP + args["category"] +