mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
added tests for #381
This commit is contained in:
@@ -722,7 +722,7 @@ func (self *ApierV1) ReloadScheduler(input string, reply *string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *ApierV1) ReloadCache(attrs utils.ApiReloadCache, reply *string) error {
|
||||
func (self *ApierV1) ReloadCache(attrs utils.AttrReloadCache, reply *string) error {
|
||||
var dstKeys, rpKeys, rpfKeys, actKeys, aplKeys, shgKeys, lcrKeys, dcsKeys, alsKeys []string
|
||||
if len(attrs.DestinationIds) > 0 {
|
||||
dstKeys = make([]string, len(attrs.DestinationIds))
|
||||
|
||||
@@ -374,7 +374,7 @@ func main() {
|
||||
if *flush {
|
||||
dstIds, rplIds, rpfIds, lcrIds = nil, nil, nil, nil // Should reload all these on flush
|
||||
}
|
||||
if err = rater.Call("ApierV1.ReloadCache", utils.ApiReloadCache{
|
||||
if err = rater.Call("ApierV1.ReloadCache", utils.AttrReloadCache{
|
||||
DestinationIds: dstIds,
|
||||
RatingPlanIds: rplIds,
|
||||
RatingProfileIds: rpfIds,
|
||||
|
||||
@@ -33,7 +33,7 @@ func init() {
|
||||
type CmdReloadCache struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *utils.ApiReloadCache
|
||||
rpcParams *utils.AttrReloadCache
|
||||
rpcResult string
|
||||
*CommandExecuter
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (self *CmdReloadCache) RpcMethod() string {
|
||||
|
||||
func (self *CmdReloadCache) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &utils.ApiReloadCache{}
|
||||
self.rpcParams = &utils.AttrReloadCache{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
DR_100x,DST_100x,R_100x,*up,4,0,
|
||||
|
@@ -0,0 +1,2 @@
|
||||
DST_100x,1001
|
||||
DST_100x,1002
|
||||
|
1
data/tariffplans/test/destinations/cacheall/Rates.csv
Normal file
1
data/tariffplans/test/destinations/cacheall/Rates.csv
Normal file
@@ -0,0 +1 @@
|
||||
R_100x,0,10,60s,1s,0s
|
||||
|
@@ -0,0 +1 @@
|
||||
RPL_100x,DR_100x,always,10
|
||||
|
@@ -0,0 +1 @@
|
||||
*out,cgrates.org,call,test,2014-01-14T00:00:00Z,RPL_100x,,
|
||||
|
1
data/tariffplans/test/destinations/cacheall/Timings.csv
Normal file
1
data/tariffplans/test/destinations/cacheall/Timings.csv
Normal file
@@ -0,0 +1 @@
|
||||
always,*any,*any,*any,*any,00:00:00
|
||||
|
@@ -0,0 +1 @@
|
||||
DR_100x,DST_100x,R_100x,*up,4,0,
|
||||
|
@@ -0,0 +1 @@
|
||||
DST_100x,1001
|
||||
|
1
data/tariffplans/test/destinations/cacheone/Rates.csv
Normal file
1
data/tariffplans/test/destinations/cacheone/Rates.csv
Normal file
@@ -0,0 +1 @@
|
||||
R_100x,0,10,60s,1s,0s
|
||||
|
@@ -0,0 +1 @@
|
||||
RPL_100x,DR_100x,always,10
|
||||
|
@@ -0,0 +1 @@
|
||||
*out,cgrates.org,call,test,2014-01-14T00:00:00Z,RPL_100x,,
|
||||
|
1
data/tariffplans/test/destinations/cacheone/Timings.csv
Normal file
1
data/tariffplans/test/destinations/cacheone/Timings.csv
Normal file
@@ -0,0 +1 @@
|
||||
always,*any,*any,*any,*any,00:00:00
|
||||
|
@@ -4,5 +4,4 @@ GERMANY_MOBILE,+4915
|
||||
GERMANY_MOBILE,+4916
|
||||
GERMANY_MOBILE,+4917
|
||||
DATA_DEST,222
|
||||
EUROPE,+40
|
||||
EUROPE,+49
|
||||
|
||||
|
@@ -140,6 +140,38 @@ func TestDestManagRemoveSomeDestinationLoaded(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestManagLoadTariffPlanFromFolderRemoveSomeFlush(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome"), FlushDb: true}
|
||||
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
|
||||
t.Error(err)
|
||||
} else if destLoadInst.LoadId == "" {
|
||||
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
|
||||
}
|
||||
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
||||
}
|
||||
|
||||
func TestDestManagRemoveSomeFlushDestinationLoaded(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
dests := make([]*engine.Destination, 0)
|
||||
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
|
||||
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
|
||||
} else if len(dests) != 4 {
|
||||
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
|
||||
}
|
||||
|
||||
var rcvStats utils.CacheStats
|
||||
if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil {
|
||||
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
|
||||
} else if rcvStats.Destinations != 5 {
|
||||
t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestManagLoadTariffPlanFromFolderAddBack(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
@@ -203,3 +235,124 @@ func TestDestManagAddOneDestinationLoaded(t *testing.T) {
|
||||
t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestManagCacheWithGetCache(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
if err := engine.InitDataDb(destCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var reply string
|
||||
if err := destRPC.Call("ApierV1.ReloadCache", utils.AttrReloadCache{}, &reply); err != nil {
|
||||
t.Error("Got error on ApierV1.ReloadCache: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling ApierV1.ReloadCache received: %+v", reply)
|
||||
}
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true}
|
||||
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
|
||||
t.Error(err)
|
||||
} else if destLoadInst.LoadId == "" {
|
||||
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
|
||||
}
|
||||
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
||||
|
||||
dests := make([]*engine.Destination, 0)
|
||||
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
|
||||
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
|
||||
} else if len(dests) != 1 {
|
||||
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
|
||||
}
|
||||
|
||||
var rcvStats utils.CacheStats
|
||||
if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil {
|
||||
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
|
||||
} else if rcvStats.Destinations != 2 {
|
||||
t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats)
|
||||
}
|
||||
|
||||
attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheone"), FlushDb: true}
|
||||
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
|
||||
t.Error(err)
|
||||
} else if destLoadInst.LoadId == "" {
|
||||
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
|
||||
}
|
||||
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
||||
|
||||
dests = make([]*engine.Destination, 0)
|
||||
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
|
||||
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
|
||||
} else if len(dests) != 1 {
|
||||
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
|
||||
}
|
||||
|
||||
if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil {
|
||||
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
|
||||
} else if rcvStats.Destinations != 1 {
|
||||
t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestManagCacheWithGetCost(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
if err := engine.InitDataDb(destCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var reply string
|
||||
if err := destRPC.Call("ApierV1.ReloadCache", utils.AttrReloadCache{}, &reply); err != nil {
|
||||
t.Error("Got error on ApierV1.ReloadCache: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Calling ApierV1.ReloadCache received: %+v", reply)
|
||||
}
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true}
|
||||
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
|
||||
t.Error(err)
|
||||
} else if destLoadInst.LoadId == "" {
|
||||
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
|
||||
}
|
||||
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
||||
|
||||
dests := make([]*engine.Destination, 0)
|
||||
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
|
||||
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
|
||||
} else if len(dests) != 1 {
|
||||
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
|
||||
}
|
||||
|
||||
var cc engine.CallCost
|
||||
cd := &engine.CallDescriptor{
|
||||
Direction: "*out",
|
||||
Tenant: "cgrates.org",
|
||||
Category: "call",
|
||||
Account: "test",
|
||||
Destination: "1002",
|
||||
TimeStart: time.Date(2016, 2, 24, 0, 0, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2016, 2, 24, 0, 0, 10, 0, time.UTC),
|
||||
}
|
||||
if err := destRPC.Call("Responder.GetCost", cd, &cc); err != nil {
|
||||
t.Error(err)
|
||||
} else if cc.Cost != 1.6667 {
|
||||
t.Error("Empty loadId received, loadInstance: ", utils.ToIJSON(cc))
|
||||
}
|
||||
|
||||
attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheone"), FlushDb: true}
|
||||
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
|
||||
t.Error(err)
|
||||
} else if destLoadInst.LoadId == "" {
|
||||
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
|
||||
}
|
||||
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
||||
|
||||
dests = make([]*engine.Destination, 0)
|
||||
if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil {
|
||||
t.Error("Got error on ApierV2.GetDestinations: ", err.Error())
|
||||
} else if len(dests) != 1 {
|
||||
t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests))
|
||||
}
|
||||
|
||||
if err := destRPC.Call("Responder.GetCost", cd, &cc); err.Error() != utils.ErrUnauthorizedDestination.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,7 +560,7 @@ type AttrGetAccounts struct {
|
||||
}
|
||||
|
||||
// Data used to do remote cache reloads via api
|
||||
type ApiReloadCache struct {
|
||||
type AttrReloadCache struct {
|
||||
DestinationIds []string
|
||||
RatingPlanIds []string
|
||||
RatingProfileIds []string
|
||||
|
||||
Reference in New Issue
Block a user