mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated actionplan cache tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
a6aa435a8d
commit
ca50dd2f73
@@ -820,7 +820,7 @@ func testApierLoadAccountActions(t *testing.T) {
|
||||
t.Error("Calling APIerSv1.LoadAccountActions got reply: ", reply)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
expectedStats[utils.CacheAccountActionPlans].Items = 1
|
||||
// expectedStats[utils.CacheAccountActionPlans].Items = 1 // was removed because the accountActionPlans are only set in DB not in Cache
|
||||
expectedStats[utils.CacheActionPlans].Items = 1
|
||||
expectedStats[utils.CacheActions].Items = 1
|
||||
expectedStats[utils.CacheLoadIDs].Items = 20
|
||||
@@ -856,7 +856,7 @@ func testApierSetRatingProfile(t *testing.T) {
|
||||
}
|
||||
var rcvStats map[string]*ltcache.CacheStats
|
||||
expectedStats := engine.GetDefaultEmptyCacheStats()
|
||||
expectedStats[utils.CacheAccountActionPlans].Items = 1
|
||||
// expectedStats[utils.CacheAccountActionPlans].Items = 1 // was removed because the accountActionPlans are only set in DB not in Cache
|
||||
expectedStats[utils.CacheActionPlans].Items = 1
|
||||
expectedStats[utils.CacheActions].Items = 1
|
||||
expectedStats[utils.CacheRatingProfiles].Items = 1
|
||||
@@ -1012,7 +1012,7 @@ func testApierReloadCache(t *testing.T) {
|
||||
}
|
||||
var rcvStats map[string]*ltcache.CacheStats
|
||||
expectedStats := engine.GetDefaultEmptyCacheStats()
|
||||
expectedStats[utils.CacheAccountActionPlans].Items = 1
|
||||
// expectedStats[utils.CacheAccountActionPlans].Items = 1 // was removed because the accountActionPlans are only set in DB not in Cache
|
||||
expectedStats[utils.CacheActionPlans].Items = 1
|
||||
expectedStats[utils.CacheActions].Items = 1
|
||||
expectedStats[utils.CacheRatingProfiles].Items = 2
|
||||
@@ -1503,7 +1503,7 @@ func testApierComputeReverse(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Received: ", reply)
|
||||
}
|
||||
if err := rater.Call(utils.APIerSv1ComputeAccountActionPlans, utils.EmptyString, &reply); err != nil {
|
||||
if err := rater.Call(utils.APIerSv1ComputeAccountActionPlans, new(utils.TenantWithAPIOpts), &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Received: ", reply)
|
||||
@@ -1514,8 +1514,8 @@ func testApierResetDataAfterLoadFromFolder(t *testing.T) {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
var rcvStats map[string]*ltcache.CacheStats
|
||||
expStats := engine.GetDefaultEmptyCacheStats()
|
||||
expStats[utils.CacheAccountActionPlans].Items = 13
|
||||
expStats[utils.CacheActionPlans].Items = 7
|
||||
// expStats[utils.CacheAccountActionPlans].Items = 13 // the items are cleared from Cache on Compute
|
||||
// expStats[utils.CacheActionPlans].Items = 7
|
||||
expStats[utils.CacheActions].Items = 5
|
||||
expStats[utils.CacheDestinations].Items = 3
|
||||
expStats[utils.CacheLoadIDs].Items = 17
|
||||
@@ -1532,6 +1532,8 @@ func testApierResetDataAfterLoadFromFolder(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Error(reply)
|
||||
}
|
||||
expStats[utils.CacheAccountActionPlans].Items = 3
|
||||
expStats[utils.CacheActionPlans].Items = 7
|
||||
expStats[utils.CacheActionTriggers].Items = 1
|
||||
expStats[utils.CacheActions].Items = 13
|
||||
expStats[utils.CacheAttributeProfiles].Items = 1
|
||||
|
||||
@@ -128,8 +128,6 @@ func testCacheSLoadTariffPlanFromFolder(t *testing.T) {
|
||||
func testCacheSAfterLoadFromFolder(t *testing.T) {
|
||||
var rcvStats map[string]*ltcache.CacheStats
|
||||
expStats := engine.GetDefaultEmptyCacheStats()
|
||||
expStats[utils.CacheAccountActionPlans].Items = 13
|
||||
expStats[utils.CacheActionPlans].Items = 7
|
||||
expStats[utils.CacheActions].Items = 5
|
||||
expStats[utils.CacheDestinations].Items = 3
|
||||
expStats[utils.CacheLoadIDs].Items = 17
|
||||
@@ -146,6 +144,8 @@ func testCacheSAfterLoadFromFolder(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Error(reply)
|
||||
}
|
||||
expStats[utils.CacheAccountActionPlans].Items = 13
|
||||
expStats[utils.CacheActionPlans].Items = 7
|
||||
expStats[utils.CacheActionTriggers].Items = 1
|
||||
expStats[utils.CacheActions].Items = 13
|
||||
expStats[utils.CacheAttributeProfiles].Items = 1
|
||||
|
||||
@@ -260,7 +260,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) {
|
||||
{ActionsId: argActs1.ActionsId,
|
||||
Time: fmt.Sprintf("%v:%v:%v", tNow.Hour(), tNow.Minute(), tNow.Second()), // 10:4:12
|
||||
Weight: 20.0}}}
|
||||
if _, err := dm.GetActionPlan(argAP1.Id, false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
if _, err := dm.GetActionPlan(argAP1.Id, false, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv1SetActionPlan, argAP1, &reply); err != nil {
|
||||
@@ -274,19 +274,19 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) {
|
||||
ActionPlanIDs: []string{argAP1.Id},
|
||||
}
|
||||
acntID := utils.ConcatenatedKey(argSetAcnt1.Tenant, argSetAcnt1.Account)
|
||||
if _, err := dm.GetAccountActionPlans(acntID, false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
if _, err := dm.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2SetAccount, argSetAcnt1, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ap, err := dm.GetActionPlan(argAP1.Id, false, false, utils.NonTransactional); err != nil {
|
||||
if ap, err := dm.GetActionPlan(argAP1.Id, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, hasIt := ap.AccountIDs[acntID]; !hasIt {
|
||||
t.Errorf("ActionPlan does not contain the accountID: %+v", ap)
|
||||
}
|
||||
eAAPids := []string{argAP1.Id}
|
||||
if aapIDs, err := dm.GetAccountActionPlans(acntID, false, false, utils.NonTransactional); err != nil {
|
||||
if aapIDs, err := dm.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eAAPids, aapIDs) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAAPids, aapIDs)
|
||||
@@ -295,7 +295,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) {
|
||||
argAP2 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAP_AP_2",
|
||||
ActionPlan: []*v1.AttrActionPlan{
|
||||
{ActionsId: argActs1.ActionsId, MonthDays: "1", Time: "00:00:00", Weight: 20.0}}}
|
||||
if _, err := dm.GetActionPlan(argAP2.Id, false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
if _, err := dm.GetActionPlan(argAP2.Id, false, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2SetActionPlan, argAP2, &reply); err != nil {
|
||||
@@ -312,18 +312,18 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) {
|
||||
if err := apierRPC.Call(utils.APIerSv2SetAccount, argSetAcnt2, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ap, err := dm.GetActionPlan(argAP2.Id, false, false, utils.NonTransactional); err != nil {
|
||||
if ap, err := dm.GetActionPlan(argAP2.Id, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, hasIt := ap.AccountIDs[acntID]; !hasIt {
|
||||
t.Errorf("ActionPlan does not contain the accountID: %+v", ap)
|
||||
}
|
||||
if ap, err := dm.GetActionPlan(argAP1.Id, false, false, utils.NonTransactional); err != nil {
|
||||
if ap, err := dm.GetActionPlan(argAP1.Id, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, hasIt := ap.AccountIDs[acntID]; !hasIt {
|
||||
t.Errorf("ActionPlan does not contain the accountID: %+v", ap)
|
||||
}
|
||||
eAAPids = []string{argAP1.Id, argAP2.Id}
|
||||
if aapIDs, err := dm.GetAccountActionPlans(acntID, false, false, utils.NonTransactional); err != nil {
|
||||
if aapIDs, err := dm.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eAAPids, aapIDs) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAAPids, aapIDs)
|
||||
@@ -338,18 +338,18 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) {
|
||||
if err := apierRPC.Call(utils.APIerSv2SetAccount, argSetAcnt2, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ap, err := dm.GetActionPlan(argAP1.Id, false, false, utils.NonTransactional); err != nil {
|
||||
if ap, err := dm.GetActionPlan(argAP1.Id, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, hasIt := ap.AccountIDs[acntID]; hasIt {
|
||||
t.Errorf("ActionPlan does contain the accountID: %+v", ap)
|
||||
}
|
||||
if ap, err := dm.GetActionPlan(argAP2.Id, false, false, utils.NonTransactional); err != nil {
|
||||
if ap, err := dm.GetActionPlan(argAP2.Id, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, hasIt := ap.AccountIDs[acntID]; !hasIt {
|
||||
t.Errorf("ActionPlan does not contain the accountID: %+v", ap)
|
||||
}
|
||||
eAAPids = []string{argAP2.Id}
|
||||
if aapIDs, err := dm.GetAccountActionPlans(acntID, false, false, utils.NonTransactional); err != nil {
|
||||
if aapIDs, err := dm.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eAAPids, aapIDs) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eAAPids, aapIDs)
|
||||
|
||||
@@ -141,6 +141,7 @@ func testDspChcLoadAfterFolder(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Error(reply)
|
||||
}
|
||||
expStats[utils.CacheActionPlans].Items = 1
|
||||
expStats[utils.CacheActions].Items = 2
|
||||
expStats[utils.CacheAttributeProfiles].Items = 10
|
||||
expStats[utils.CacheChargerProfiles].Items = 2
|
||||
|
||||
@@ -584,7 +584,7 @@ func TestActionPlansRemoveMember(t *testing.T) {
|
||||
[]string{account1.ID}, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
dm.GetAccountActionPlans(account1.ID, false,false, utils.NonTransactional) // FixMe: remove here after finishing testing of map
|
||||
dm.GetAccountActionPlans(account1.ID, false, true, utils.NonTransactional) // FixMe: remove here after finishing testing of map
|
||||
if err = dm.SetAccountActionPlans(account2.ID,
|
||||
[]string{ap2.Id}, false); err != nil {
|
||||
t.Error(err)
|
||||
@@ -613,7 +613,7 @@ func TestActionPlansRemoveMember(t *testing.T) {
|
||||
t.Errorf("Execute Action: %v", err)
|
||||
}
|
||||
|
||||
apr, err1 := dm.GetActionPlan(ap1.Id, true,true, utils.NonTransactional)
|
||||
apr, err1 := dm.GetActionPlan(ap1.Id, true, true, utils.NonTransactional)
|
||||
|
||||
if err1 != nil {
|
||||
t.Errorf("Get action plan test: %v", err1)
|
||||
|
||||
@@ -326,16 +326,16 @@ func (dm *DataManager) RebuildReverseForPrefix(prefix string) (err error) {
|
||||
return
|
||||
}
|
||||
var keys []string
|
||||
if keys, err = dm.dataDB.GetKeysForPrefix(utils.DestinationPrefix); err != nil {
|
||||
if keys, err = dm.dataDB.GetKeysForPrefix(utils.DESTINATION_PREFIX); err != nil {
|
||||
return
|
||||
}
|
||||
for _, key := range keys {
|
||||
var dest *Destination
|
||||
if dest, err = dm.GetDestination(key[len(utils.DestinationPrefix):], false, utils.NonTransactional); err != nil {
|
||||
return err
|
||||
if dest, err = dm.GetDestination(key[len(utils.DESTINATION_PREFIX):], false, utils.NonTransactional); err != nil {
|
||||
return
|
||||
}
|
||||
if err = dm.SetReverseDestination(dest, utils.NonTransactional); err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
}
|
||||
case utils.AccountActionPlansPrefix:
|
||||
@@ -1414,7 +1414,7 @@ func (dm *DataManager) SetActionPlan(key string, ats *ActionPlan,
|
||||
}
|
||||
if !overwrite {
|
||||
// get existing action plan to merge the account ids
|
||||
if oldAP, _ := dm.GetActionPlan(key, true, true, transactionID); oldAP != nil {
|
||||
if oldAP, _ := dm.GetActionPlan(key, true, false, transactionID); oldAP != nil {
|
||||
if ats.AccountIDs == nil && len(oldAP.AccountIDs) > 0 {
|
||||
ats.AccountIDs = make(utils.StringMap)
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ func testLoaderITWriteToDatabase(t *testing.T) {
|
||||
}
|
||||
|
||||
for k, ap := range loader.actionPlans {
|
||||
rcv, err := loader.dm.GetActionPlan(k, false, false, utils.NonTransactional)
|
||||
rcv, err := loader.dm.GetActionPlan(k, false, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Failed GetActionPlan: ", err.Error())
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -1035,13 +1036,13 @@ func testOnStorITCRUDActionPlan(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, rcvErr := onStor.GetActionPlan(ap.Id, false, false, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
if _, rcvErr := onStor.GetActionPlan(ap.Id, false, true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
if err := onStor.SetActionPlan(ap.Id, ap, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rcv, err := onStor.GetActionPlan(ap.Id, false, false, utils.NonTransactional); err != nil {
|
||||
if rcv, err := onStor.GetActionPlan(ap.Id, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(ap, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", ap, rcv)
|
||||
@@ -1074,13 +1075,13 @@ func testOnStorITCRUDAccountActionPlans(t *testing.T) {
|
||||
expect := []string{"PACKAGE_10_SHARED_A_5", "USE_SHARED_A", "apl_PACKAGE_1001"}
|
||||
aAPs := []string{"PACKAGE_10_SHARED_A_5", "apl_PACKAGE_1001"}
|
||||
aAPs2 := []string{"USE_SHARED_A"}
|
||||
if _, rcvErr := onStor.GetAccountActionPlans(acntID, false, false, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
if _, rcvErr := onStor.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
if err := onStor.SetAccountActionPlans(acntID, aAPs, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rcv, err := onStor.GetAccountActionPlans(acntID, false, false, utils.NonTransactional); err != nil {
|
||||
if rcv, err := onStor.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(aAPs, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", aAPs, rcv)
|
||||
@@ -1149,15 +1150,21 @@ func testOnStorITCRUDAccountActionPlans2(t *testing.T) {
|
||||
if err = onStor.RebuildReverseForPrefix(utils.AccountActionPlansPrefix); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if rcv, err := onStor.GetAccountActionPlans(acntID, false, false, utils.NonTransactional); err != nil {
|
||||
if rcv, err := onStor.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expect, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", expect, rcv)
|
||||
} else {
|
||||
sort.Strings(rcv)
|
||||
if !reflect.DeepEqual(expect, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", expect, rcv)
|
||||
}
|
||||
}
|
||||
if rcv, err := onStor.GetAccountActionPlans(acntID2, false, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expect, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", expect, rcv)
|
||||
} else {
|
||||
sort.Strings(rcv)
|
||||
if !reflect.DeepEqual(expect, rcv) {
|
||||
t.Errorf("Expecting: %v, received: %v", expect, rcv)
|
||||
}
|
||||
}
|
||||
if err := onStor.RemAccountActionPlans(acntID, nil); err != nil {
|
||||
t.Error(err)
|
||||
@@ -1165,7 +1172,7 @@ func testOnStorITCRUDAccountActionPlans2(t *testing.T) {
|
||||
if err := onStor.RemAccountActionPlans(acntID2, nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, rcvErr := onStor.GetAccountActionPlans(acntID, false, false, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
if _, rcvErr := onStor.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,7 +749,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions)
|
||||
if accountAction.ActionPlanId != "" {
|
||||
// get old userBalanceIds
|
||||
exitingAccountIds := make(utils.StringMap)
|
||||
existingActionPlan, err := tpr.dm.GetActionPlan(accountAction.ActionPlanId, false, false, utils.NonTransactional)
|
||||
existingActionPlan, err := tpr.dm.GetActionPlan(accountAction.ActionPlanId, false, true, utils.NonTransactional)
|
||||
if err == nil && existingActionPlan != nil {
|
||||
exitingAccountIds = existingActionPlan.AccountIDs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user