From e5f8a4147b6518d95d4926468067e4fedae07a7d Mon Sep 17 00:00:00 2001 From: DanB Date: Tue, 27 Dec 2016 15:31:16 +0100 Subject: [PATCH] Fix SMGV1 tests --- apier/v1/apier.go | 2 +- apier/v1/smgenericv1_it_test.go | 26 +++++++++++++++--------- data/conf/samples/smgeneric/cgrates.json | 17 ++++++++++++++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 7bf6b097e..d990eb88e 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1111,7 +1111,6 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, if attrs.Validate { if !loader.IsValid() { - *reply = OK return errors.New("invalid data") } } @@ -1151,6 +1150,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, if len(aps) != 0 { sched := self.ServManager.GetScheduler() if sched != nil { + utils.Logger.Info("ApierV1.LoadTariffPlanFromFolder, reloading scheduler.") sched.Reload() } } diff --git a/apier/v1/smgenericv1_it_test.go b/apier/v1/smgenericv1_it_test.go index 450798690..0a4fa08d5 100644 --- a/apier/v1/smgenericv1_it_test.go +++ b/apier/v1/smgenericv1_it_test.go @@ -83,25 +83,31 @@ func TestSMGV1RpcConn(t *testing.T) { // Load the tariff plan, creating accounts and their balances func TestSMGV1LoadTariffPlanFromFolder(t *testing.T) { + var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := smgV1Rpc.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &smgV1LoadInst); err != nil { + if err := smgV1Rpc.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil { t.Error(err) - } else if smgV1LoadInst.RatingLoadID != "" && smgV1LoadInst.AccountingLoadID != "" { - t.Error("Non Empty loadId received, loadInstance: ", smgV1LoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } // Check loaded stats func TestSMGV1CacheStats(t *testing.T) { + var reply string + if err := smgV1Rpc.Call("ApierV1.PreloadCache", utils.AttrReloadCache{}, &reply); err != nil { + t.Error(err) + } else if reply != "OK" { + t.Error(reply) + } var rcvStats *utils.CacheStats - expectedStats := &utils.CacheStats{Destinations: 0, RatingPlans: 4, RatingProfiles: 0, Actions: 7, ActionPlans: 4, SharedGroups: 0, Aliases: 0, ResourceLimits: 0, - DerivedChargers: 0, LcrProfiles: 0, CdrStats: 6, Users: 3} + expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 9, + Actions: 8, ActionPlans: 4, SharedGroups: 1, DerivedChargers: 1, + LcrProfiles: 5, CdrStats: 6, Users: 3, Aliases: 1, ReverseAliases: 2, ResourceLimits: 2} var args utils.AttrCacheStats - if err := smgV1Rpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { - t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) + if err := smgV1Rpc.Call("ApierV1.GetCacheStats", args, &rcvStats); err != nil { + t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { - t.Errorf("Calling ApierV2.GetCacheStats expected: %+v, received: %+v", expectedStats, rcvStats) + t.Errorf("Calling ApierV1.GetCacheStats expected: %+v, received: %+v", expectedStats, rcvStats) } } @@ -113,7 +119,7 @@ func TestSMGV1AccountsBefore(t *testing.T) { t.Error("Got error on ApierV2.GetAccount: ", err.Error()) } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() != 10.0 { // Make sure we debitted jsn, _ := json.Marshal(reply) - t.Errorf("Calling ApierV2.GetBalance received: %s", jsn) + t.Errorf("Received: %s", jsn) } } @@ -125,7 +131,7 @@ func TestSMGV1GetMaxUsage(t *testing.T) { if err := smgV1Rpc.Call("SMGenericV1.MaxUsage", setupReq, &maxTime); err != nil { t.Error(err) } else if maxTime != 2700 { - t.Errorf("Calling ApierV2.MaxUsage got maxTime: %f", maxTime) + t.Errorf("Calling ApierV1.MaxUsage got maxTime: %f", maxTime) } } diff --git a/data/conf/samples/smgeneric/cgrates.json b/data/conf/samples/smgeneric/cgrates.json index 5f565caed..774102977 100644 --- a/data/conf/samples/smgeneric/cgrates.json +++ b/data/conf/samples/smgeneric/cgrates.json @@ -12,6 +12,23 @@ "http": "0.0.0.0:3080", // HTTP listening address }, +"cache":{ + "destinations": {"limit": 10000, "ttl":"0s", "precache": true}, + "reverse_destinations": {"limit": 10000, "ttl":"0s", "precache": true}, + "rating_plans": {"limit": 10000, "ttl":"0s","precache": true}, + "rating_profiles": {"limit": 10000, "ttl":"0s", "precache": true}, + "lcr": {"limit": 10000, "ttl":"0s", "precache": true}, + "cdr_stats": {"limit": 10000, "ttl":"0s", "precache": true}, + "actions": {"limit": 10000, "ttl":"0s", "precache": true}, + "action_plans": {"limit": 10000, "ttl":"0s", "precache": true}, + "action_triggers": {"limit": 10000, "ttl":"0s", "precache": true}, + "shared_groups": {"limit": 10000, "ttl":"0s", "precache": true}, + "aliases": {"limit": 10000, "ttl":"0s", "precache": true}, + "reverse_aliases": {"limit": 10000, "ttl":"0s", "precache": true}, + "derived_chargers": {"limit": 10000, "ttl":"0s", "precache": true}, + "resource_limits": {"limit": 10000, "ttl":"0s", "precache": true}, +}, + "rals": { "enabled": true, // enable Rater service: