mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Added Resource,Threshold and Stats ids to TPReader cache reload
This commit is contained in:
committed by
Dan Christian Bogos
parent
486629a63f
commit
3aaf612b03
@@ -45,7 +45,9 @@ var (
|
||||
testV1RsResetStorDb,
|
||||
testV1RsStartEngine,
|
||||
testV1RsRpcConn,
|
||||
testV1RsCacheResourceBeforeLoad,
|
||||
testV1RsFromFolder,
|
||||
testV1RsCacheResourceAfterLoad,
|
||||
testV1RsGetResourcesForEvent,
|
||||
testV1RsTTL0,
|
||||
testV1RsAllocateResource,
|
||||
@@ -142,6 +144,31 @@ func testV1RsRpcConn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testV1RsCacheResourceBeforeLoad(t *testing.T) { // cache it with not found
|
||||
var rplyRes *engine.Resource
|
||||
if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{
|
||||
TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"},
|
||||
}, &rplyRes); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1RsCacheResourceAfterLoad(t *testing.T) { // the APIerSv1LoadTariffPlanFromFolder should also reload the cache for resources
|
||||
var rplyRes *engine.Resource
|
||||
expRes := &engine.Resource{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ResGroup1",
|
||||
Usages: map[string]*engine.ResourceUsage{},
|
||||
}
|
||||
if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{
|
||||
TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"},
|
||||
}, &rplyRes); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expRes, rplyRes) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expRes), utils.ToJSON(rplyRes))
|
||||
}
|
||||
}
|
||||
|
||||
func testV1RsFromFolder(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")}
|
||||
@@ -873,7 +900,6 @@ func testV1RsAllocateUnlimited(t *testing.T) {
|
||||
} else if reply != "CustomUnlimitedMessage" {
|
||||
t.Errorf("Expecting: %+v, received: %+v", "CustomUnlimitedMessage", reply)
|
||||
}
|
||||
|
||||
var rplyRes *engine.Resource
|
||||
expRes := &engine.Resource{
|
||||
Tenant: "cgrates.org",
|
||||
|
||||
@@ -70,7 +70,9 @@ var (
|
||||
testV1STSInitDataDb,
|
||||
testV1STSStartEngine,
|
||||
testV1STSRpcConn,
|
||||
testV1STSCacheQueueBeforeLoad,
|
||||
testV1STSFromFolder,
|
||||
testV1STSCacheQueueAfterLoad,
|
||||
testV1STSGetStats,
|
||||
testV1STSProcessEvent,
|
||||
testV1STSGetStatsAfterRestart,
|
||||
@@ -166,6 +168,29 @@ func testV1STSRpcConn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testV1STSCacheQueueBeforeLoad(t *testing.T) { // cache it with not found
|
||||
var replySq engine.StatQueue
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{
|
||||
TenantID: &utils.TenantID{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats1",
|
||||
},
|
||||
}, &replySq); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1STSCacheQueueAfterLoad(t *testing.T) { // the APIerSv1LoadTariffPlanFromFolder should also reload the cache for resources
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{
|
||||
TenantID: &utils.TenantID{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats1",
|
||||
},
|
||||
}, nil); err != nil { // do not care about value only that they were recached correctly
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1STSFromFolder(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")}
|
||||
|
||||
@@ -209,7 +209,9 @@ var (
|
||||
testV1TSResetStorDb,
|
||||
testV1TSStartEngine,
|
||||
testV1TSRpcConn,
|
||||
testV1TSCacheThresholdBeforeLoad,
|
||||
testV1TSFromFolder,
|
||||
testV1TSCacheThresholdAfterLoad,
|
||||
testV1TSGetThresholds,
|
||||
testV1TSProcessEvent,
|
||||
testV1TSGetThresholdsAfterProcess,
|
||||
@@ -301,6 +303,25 @@ func testV1TSRpcConn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testV1TSCacheThresholdBeforeLoad(t *testing.T) { // cache it with not found
|
||||
var td engine.Threshold
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
|
||||
&utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}},
|
||||
&td); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1TSCacheThresholdAfterLoad(t *testing.T) { // the APIerSv1LoadTariffPlanFromFolder should also reload the cache for resources
|
||||
var td engine.Threshold
|
||||
eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
|
||||
&utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}}, &td); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eTd, td) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eTd, td)
|
||||
}
|
||||
}
|
||||
func testV1TSFromFolder(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")}
|
||||
|
||||
@@ -1889,6 +1889,24 @@ func (tpr *TpReader) ShowStatistics() {
|
||||
// GetLoadedIds returns the identities loaded for a specific category, useful for cache reloads
|
||||
func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
|
||||
switch categ {
|
||||
case utils.ResourcesPrefix:
|
||||
keys := make([]string, len(tpr.resources))
|
||||
for i, k := range tpr.resources {
|
||||
keys[i] = k.TenantID()
|
||||
}
|
||||
return keys, nil
|
||||
case utils.StatQueuePrefix:
|
||||
keys := make([]string, len(tpr.statQueues))
|
||||
for i, k := range tpr.statQueues {
|
||||
keys[i] = k.TenantID()
|
||||
}
|
||||
return keys, nil
|
||||
case utils.ThresholdPrefix:
|
||||
keys := make([]string, len(tpr.thresholds))
|
||||
for i, k := range tpr.thresholds {
|
||||
keys[i] = k.TenantID()
|
||||
}
|
||||
return keys, nil
|
||||
case utils.DestinationPrefix:
|
||||
keys := make([]string, len(tpr.destinations))
|
||||
i := 0
|
||||
|
||||
Reference in New Issue
Block a user