From 63ba0ffca7be49995e84baf98e5c957f5f03bc3f Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 2 May 2019 15:28:01 +0300 Subject: [PATCH] Update integration tests --- apier/v1/resourcesv1.go | 12 ++---------- apier/v1/sessionsv1_it_test.go | 5 +++-- apier/v1/suppliers_it_test.go | 6 ++++++ console/chargers_process_event.go | 2 +- console/debit.go | 4 ++-- console/debit_max.go | 4 ++-- console/maxduration.go | 4 ++-- dispatchers/suppliers_it_test.go | 5 +++++ engine/chargers.go | 2 +- engine/filters.go | 4 ++-- engine/resources.go | 13 +++++++++++++ engine/suppliers.go | 5 +++-- sessions/sessions.go | 25 ++++++++++++++----------- utils/consts.go | 2 +- 14 files changed, 57 insertions(+), 36 deletions(-) diff --git a/apier/v1/resourcesv1.go b/apier/v1/resourcesv1.go index 8a3eb783b..7567a4808 100644 --- a/apier/v1/resourcesv1.go +++ b/apier/v1/resourcesv1.go @@ -60,16 +60,8 @@ func (rsv1 *ResourceSv1) ReleaseResources(args utils.ArgRSv1ResourceUsage, reply } // GetResource returns a resource configuration -func (apierV1 *ApierV1) GetResource(arg utils.TenantID, reply *engine.Resource) error { - if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing - return utils.NewErrMandatoryIeMissing(missing...) - } - if res, err := apierV1.DataManager.GetResource(arg.Tenant, arg.ID, true, true, utils.NonTransactional); err != nil { - return utils.APIErrorHandler(err) - } else { - *reply = *res - } - return nil +func (rsv1 *ResourceSv1) GetResource(args *utils.TenantID, reply *engine.Resource) error { + return rsv1.rls.V1GetResource(args, reply) } // GetResourceProfile returns a resource configuration diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index 40e3a9fda..9f284115d 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -164,6 +164,7 @@ func TestSSv1ItAuth(t *testing.T) { eSplrs := &engine.SortedSuppliers{ ProfileID: "SPL_ACNT_1001", Sorting: utils.MetaWeight, + Count: 2, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier1", @@ -180,7 +181,7 @@ func TestSSv1ItAuth(t *testing.T) { }, } if !reflect.DeepEqual(eSplrs, rply.Suppliers) { - t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.Suppliers)) + t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.Suppliers)) } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, @@ -316,7 +317,7 @@ func TestSSv1ItInitiateSession(t *testing.T) { if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 2 { - t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) + t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) } } diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index a08516100..cccf6ff9f 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -144,6 +144,7 @@ func testV1SplSGetWeightSuppliers(t *testing.T) { eSpls := engine.SortedSuppliers{ ProfileID: "SPL_WEIGHT_1", Sorting: utils.MetaWeight, + Count: 2, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier2", @@ -186,6 +187,7 @@ func testV1SplSGetLeastCostSuppliers(t *testing.T) { eSpls := engine.SortedSuppliers{ ProfileID: "SPL_LEASTCOST_1", Sorting: utils.MetaLeastCost, + Count: 3, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier3", @@ -241,6 +243,7 @@ func testV1SplSGetLeastCostSuppliersWithMaxCost(t *testing.T) { eSpls := engine.SortedSuppliers{ ProfileID: "SPL_LEASTCOST_1", Sorting: utils.MetaLeastCost, + Count: 2, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier3", @@ -311,6 +314,7 @@ func testV1SplSGetLeastCostSuppliersWithMaxCost2(t *testing.T) { eSpls := engine.SortedSuppliers{ ProfileID: "SPL_LEASTCOST_1", Sorting: utils.MetaLeastCost, + Count: 2, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier3", @@ -357,6 +361,7 @@ func testV1SplSGetHighestCostSuppliers(t *testing.T) { eSpls := engine.SortedSuppliers{ ProfileID: "SPL_HIGHESTCOST_1", Sorting: utils.MetaHighestCost, + Count: 3, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier2", @@ -712,6 +717,7 @@ func testV1SplSGetSupplierWithoutFilter(t *testing.T) { eSpls := engine.SortedSuppliers{ ProfileID: "SPL_WEIGHT_2", Sorting: utils.MetaWeight, + Count: 1, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier1", diff --git a/console/chargers_process_event.go b/console/chargers_process_event.go index dd33a9fa7..252cc9f21 100644 --- a/console/chargers_process_event.go +++ b/console/chargers_process_event.go @@ -58,7 +58,7 @@ func (self *CmdChargersProcessEvent) RpcParams(reset bool) interface{} { } func (self *CmdChargersProcessEvent) PostprocessRpcParams() error { - if self.rpcParams.Time == nil { + if self.rpcParams.CGREvent != nil && self.rpcParams.Time == nil { self.rpcParams.Time = utils.TimePointer(time.Now()) } return nil diff --git a/console/debit.go b/console/debit.go index f20251337..c98fd0b8f 100644 --- a/console/debit.go +++ b/console/debit.go @@ -34,7 +34,7 @@ func init() { type CmdDebit struct { name string rpcMethod string - rpcParams *engine.CallDescriptor + rpcParams *engine.CallDescriptorWithArgDispatcher clientArgs []string *CommandExecuter } @@ -49,7 +49,7 @@ func (self *CmdDebit) RpcMethod() string { func (self *CmdDebit) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = new(engine.CallDescriptor) + self.rpcParams = new(engine.CallDescriptorWithArgDispatcher) } return self.rpcParams } diff --git a/console/debit_max.go b/console/debit_max.go index 3565f8c90..a50f62569 100644 --- a/console/debit_max.go +++ b/console/debit_max.go @@ -34,7 +34,7 @@ func init() { type CmdMaxDebit struct { name string rpcMethod string - rpcParams *engine.CallDescriptor + rpcParams *engine.CallDescriptorWithArgDispatcher clientArgs []string *CommandExecuter } @@ -49,7 +49,7 @@ func (self *CmdMaxDebit) RpcMethod() string { func (self *CmdMaxDebit) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = new(engine.CallDescriptor) + self.rpcParams = new(engine.CallDescriptorWithArgDispatcher) } return self.rpcParams } diff --git a/console/maxduration.go b/console/maxduration.go index a4bb8e179..9efb2f1a3 100644 --- a/console/maxduration.go +++ b/console/maxduration.go @@ -38,7 +38,7 @@ func init() { type CmdGetMaxDuration struct { name string rpcMethod string - rpcParams *engine.CallDescriptor + rpcParams *engine.CallDescriptorWithArgDispatcher clientArgs []string *CommandExecuter } @@ -53,7 +53,7 @@ func (self *CmdGetMaxDuration) RpcMethod() string { func (self *CmdGetMaxDuration) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = new(engine.CallDescriptor) + self.rpcParams = new(engine.CallDescriptorWithArgDispatcher) } return self.rpcParams } diff --git a/dispatchers/suppliers_it_test.go b/dispatchers/suppliers_it_test.go index 89f1634c4..7f202f930 100755 --- a/dispatchers/suppliers_it_test.go +++ b/dispatchers/suppliers_it_test.go @@ -110,6 +110,7 @@ func testDspSupGetSupFailover(t *testing.T) { eRpl1 := &engine.SortedSuppliers{ ProfileID: "SPL_WEIGHT_2", Sorting: utils.MetaWeight, + Count: 1, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier1", @@ -123,6 +124,7 @@ func testDspSupGetSupFailover(t *testing.T) { eRpl := &engine.SortedSuppliers{ ProfileID: "SPL_ACNT_1002", Sorting: utils.MetaLeastCost, + Count: 2, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier1", @@ -208,6 +210,7 @@ func testDspSupTestAuthKey2(t *testing.T) { eRpl := &engine.SortedSuppliers{ ProfileID: "SPL_ACNT_1002", Sorting: utils.MetaLeastCost, + Count: 2, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier1", @@ -259,6 +262,7 @@ func testDspSupGetSupRoundRobin(t *testing.T) { eRpl1 := &engine.SortedSuppliers{ ProfileID: "SPL_WEIGHT_2", Sorting: utils.MetaWeight, + Count: 1, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier1", @@ -272,6 +276,7 @@ func testDspSupGetSupRoundRobin(t *testing.T) { eRpl := &engine.SortedSuppliers{ ProfileID: "SPL_ACNT_1002", Sorting: utils.MetaLeastCost, + Count: 2, SortedSuppliers: []*engine.SortedSupplier{ { SupplierID: "supplier1", diff --git a/engine/chargers.go b/engine/chargers.go index fa43748da..0c10ece9e 100644 --- a/engine/chargers.go +++ b/engine/chargers.go @@ -152,7 +152,7 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREventWithArgDispatcher) ( // V1ProcessEvent will process the event received via API and return list of events forked func (cS *ChargerService) V1ProcessEvent(args *utils.CGREventWithArgDispatcher, reply *[]*ChrgSProcessEventReply) (err error) { - if args.Event == nil { + if args.CGREvent == nil || args.Event == nil { return utils.NewErrMandatoryIeMissing("Event") } rply, err := cS.processEvent(args) diff --git a/engine/filters.go b/engine/filters.go index 9c0696c23..a332da106 100644 --- a/engine/filters.go +++ b/engine/filters.go @@ -550,8 +550,8 @@ func (fltr *FilterRule) passResourceS(dP config.DataProvider, } for _, resItem := range fltr.resourceItems { //take total usage for resource - var reply *Resource - if err := resourceS.Call(utils.ApierV1GetResource, + var reply Resource + if err := resourceS.Call(utils.ResourceSv1GetResource, &utils.TenantID{Tenant: tenant, ID: resItem.ItemID}, &reply); err != nil { return false, err } diff --git a/engine/resources.go b/engine/resources.go index d8e2101fa..f6aadf5e0 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -721,3 +721,16 @@ func (rS *ResourceService) V1ReleaseResource(args utils.ArgRSv1ResourceUsage, re *reply = utils.OK return } + +// GetResource returns a resource configuration +func (rS *ResourceService) V1GetResource(arg *utils.TenantID, reply *Resource) error { + if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing + return utils.NewErrMandatoryIeMissing(missing...) + } + if res, err := rS.dm.GetResource(arg.Tenant, arg.ID, true, true, utils.NonTransactional); err != nil { + return err + } else { + *reply = *res + } + return nil +} diff --git a/engine/suppliers.go b/engine/suppliers.go index a5ab6f989..2f3628cdb 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -299,12 +299,13 @@ func (spS *SupplierService) statMetrics(statIDs []string, tenant string) (stsMet func (spS *SupplierService) resourceUsage(resIDs []string, tenant string) (tUsage float64, err error) { if spS.resourceS != nil { for _, resID := range resIDs { - var res *Resource - if err = spS.resourceS.Call(utils.ApierV1GetResource, + var res Resource + if err = spS.resourceS.Call(utils.ResourceSv1GetResource, &utils.TenantID{Tenant: tenant, ID: resID}, &res); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( fmt.Sprintf(" error: %s getting resource for ID : %s", err.Error(), resID)) + continue } tUsage += res.totalUsage() } diff --git a/sessions/sessions.go b/sessions/sessions.go index a5d136c87..336b1ca2c 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -471,8 +471,9 @@ func (sS *SessionS) debitSession(s *Session, sRunIdx int, dur time.Duration, argDsp := s.ArgDispatcher s.Unlock() cc := new(engine.CallCost) - if err := sS.ralS.Call(utils.ResponderMaxDebit, &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd, - ArgDispatcher: argDsp}, cc); err != nil { + if err := sS.ralS.Call(utils.ResponderMaxDebit, + &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd, + ArgDispatcher: argDsp}, cc); err != nil { s.Lock() sr.ExtraDuration += dbtRsrv s.Unlock() @@ -606,8 +607,9 @@ func (sS *SessionS) refundSession(s *Session, sRunIdx int, rUsage time.Duration) Increments: incrmts, } var acnt engine.Account - if err = sS.ralS.Call(utils.ResponderRefundIncrements, &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd, - ArgDispatcher: s.ArgDispatcher}, &acnt); err != nil { + if err = sS.ralS.Call(utils.ResponderRefundIncrements, + &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd, + ArgDispatcher: s.ArgDispatcher}, &acnt); err != nil { return } if acnt.ID != "" { // Account info updated, update also cached AccountSummary @@ -913,15 +915,14 @@ func (sS *SessionS) asActiveSessions(fltrs map[string]string, if len(fltrs) == 0 { // no filters applied ss := sS.getSessions(utils.EmptyString, psv) - if count { - return nil, len(ss), nil - } - aSs = make([]*ActiveSession, len(ss)) for _, s := range ss { aSs = append(aSs, s.AsActiveSessions(sS.cgrCfg.GeneralCfg().DefaultTimezone, sS.cgrCfg.GeneralCfg().NodeID)...) // Expensive for large number of sessions } + if count { + return nil, len(aSs), nil + } return } @@ -1330,8 +1331,9 @@ func (sS *SessionS) endSession(s *Session, tUsage, lastUsage *time.Duration) (er sr.CD.TimeEnd = sr.CD.TimeStart.Add(notCharged) sr.CD.DurationIndex += notCharged cc := new(engine.CallCost) - if err = sS.ralS.Call(utils.ResponderDebit, &engine.CallDescriptorWithArgDispatcher{CallDescriptor: sr.CD, - ArgDispatcher: s.ArgDispatcher}, cc); err == nil { + if err = sS.ralS.Call(utils.ResponderDebit, + &engine.CallDescriptorWithArgDispatcher{CallDescriptor: sr.CD, + ArgDispatcher: s.ArgDispatcher}, cc); err == nil { sr.EventCost.Merge( engine.NewEventCostFromCallCost(cc, s.CGRID, sr.Event.GetStringIgnoreErrors(utils.RunID))) @@ -2401,7 +2403,8 @@ func (sS *SessionS) BiRPCv1ProcessCDR(clnt rpcclient.RpcClientConnection, } if s == nil { // no cached session, CDR will be handled by CDRs return sS.cdrS.Call(utils.CDRsV1ProcessEvent, - &engine.ArgV1ProcessEvent{CGREvent: *cgrEvWithArgDisp.CGREvent, + &engine.ArgV1ProcessEvent{ + CGREvent: *cgrEvWithArgDisp.CGREvent, ArgDispatcher: cgrEvWithArgDisp.ArgDispatcher}, rply) } diff --git a/utils/consts.go b/utils/consts.go index c552f74d7..bd1f23e79 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -727,7 +727,6 @@ const ( ApierV1GetDispatcherHost = "ApierV1.GetDispatcherHost" ApierV1GetDispatcherHostIDs = "ApierV1.GetDispatcherHostIDs" ApierV1RemoveDispatcherHost = "ApierV1.RemoveDispatcherHost" - ApierV1GetResource = "ApierV1.GetResource" ApierV1GetEventCost = "ApierV1.GetEventCost" ApierV1LoadTariffPlanFromFolder = "ApierV1.LoadTariffPlanFromFolder" ApierV1GetCost = "ApierV1.GetCost" @@ -833,6 +832,7 @@ const ( ResourceSv1AllocateResources = "ResourceSv1.AllocateResources" ResourceSv1ReleaseResources = "ResourceSv1.ReleaseResources" ResourceSv1Ping = "ResourceSv1.Ping" + ResourceSv1GetResource = "ResourceSv1.GetResource" ApierV1SetResourceProfile = "ApierV1.SetResourceProfile" ApierV1RemoveResourceProfile = "ApierV1.RemoveResourceProfile" ApierV1GetResourceProfile = "ApierV1.GetResourceProfile"