Reload cache on SetRatingProfile API

This commit is contained in:
DanB
2014-03-05 19:10:27 +01:00
parent 90e3791c0d
commit 5b10f63c94
2 changed files with 47 additions and 20 deletions

View File

@@ -200,7 +200,7 @@ type AttrSetRatingProfile struct {
Direction string // Traffic direction, OUT is the only one supported for now
Subject string // Rating subject, usually the same as account
Overwrite bool // Overwrite if exists
RatingPlanActivations []*utils.TPRatingActivation // Activate rate profiles at specific time
RatingPlanActivations []*utils.TPRatingActivation // Activate rating plans at specific time
}
// Sets a specific rating profile working with data directly in the RatingDb without involving storDb
@@ -239,6 +239,10 @@ func (self *ApierV1) SetRatingProfile(attrs AttrSetRatingProfile, reply *string)
if err := self.RatingDb.SetRatingProfile(rpfl); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
//Automatic cache of the newly inserted rating profile
if err := self.RatingDb.CacheRating(nil, nil, []string{engine.RATING_PROFILE_PREFIX + keyId}, nil); err != nil {
return err
}
*reply = OK
return nil
}

View File

@@ -738,6 +738,48 @@ func TestApierLoadRatingPlan(t *testing.T) {
}
}
// Test here SetRatingProfile
func TestApierSetRatingProfile(t *testing.T) {
if !*testLocal {
return
}
reply := ""
rpa := &utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1", FallbackSubjects: "dan2"}
rpf := &AttrSetRatingProfile{Tenant: "cgrates.org", TOR: "call", Direction: "*out", Subject: "dan", RatingPlanActivations: []*utils.TPRatingActivation{rpa}}
if err := rater.Call("ApierV1.SetRatingProfile", rpf, &reply); err != nil {
t.Error("Got error on ApierV1.SetRatingProfile: ", err.Error())
} else if reply != "OK" {
t.Error("Calling ApierV1.SetRatingProfile got reply: ", reply)
}
// Calling the second time should raise EXISTS
if err := rater.Call("ApierV1.SetRatingProfile", rpf, &reply); err == nil || err.Error() != "EXISTS" {
t.Error("Unexpected result on duplication: ", err.Error())
}
time.Sleep(10 * time.Millisecond) // Give time for cache reload
// Make sure rates were loaded for account dan
// Test here ResponderGetCost
tStart, _ := utils.ParseDate("2013-08-07T17:30:00Z")
tEnd, _ := utils.ParseDate("2013-08-07T17:31:30Z")
cd := engine.CallDescriptor{
Direction: "*out",
TOR: "call",
Tenant: "cgrates.org",
Subject: "dan",
Account: "dan",
Destination: "+4917621621391",
CallDuration: 90,
TimeStart: tStart,
TimeEnd: tEnd,
}
var cc engine.CallCost
// Simple test that command is executed without errors
if err := rater.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0 {
t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
}
}
// Test here LoadRatingProfile
func TestApierLoadRatingProfile(t *testing.T) {
if !*testLocal {
@@ -752,25 +794,6 @@ func TestApierLoadRatingProfile(t *testing.T) {
}
}
// Test here SetRatingProfile
func TestApierSetRatingProfile(t *testing.T) {
if !*testLocal {
return
}
reply := ""
rpa := &utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1", FallbackSubjects: "dan2;*any"}
rpf := &AttrSetRatingProfile{Tenant: "cgrates.org", TOR: "call", Direction: "*out", Subject: "dan", RatingPlanActivations: []*utils.TPRatingActivation{rpa}}
if err := rater.Call("ApierV1.SetRatingProfile", rpf, &reply); err != nil {
t.Error("Got error on ApierV1.SetRatingProfile: ", err.Error())
} else if reply != "OK" {
t.Error("Calling ApierV1.SetRatingProfile got reply: ", reply)
}
// Calling the second time should raise EXISTS
if err := rater.Call("ApierV1.SetRatingProfile", rpf, &reply); err == nil || err.Error() != "EXISTS" {
t.Error("Unexpected result on duplication: ", err.Error())
}
}
// Test here LoadAccountActions
func TestApierLoadAccountActions(t *testing.T) {
if !*testLocal {