mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added a verification for internal to avoid Cache.Set for an empty obj
This commit is contained in:
committed by
Dan Christian Bogos
parent
7a5396b2cc
commit
c777bb5c7d
@@ -49,7 +49,6 @@ var (
|
||||
testV1FIdxHResetStorDb,
|
||||
testV1FIdxHLoadFromFolderTutorial,
|
||||
testV1FIdxGetThresholdsIndexesHealth,
|
||||
/*
|
||||
testV1FIdxGetResourcesIndexesHealth,
|
||||
testV1FIdxGetStatsIndexesHealth,
|
||||
testV1FIdxGetRoutesIndexesHealth,
|
||||
@@ -61,8 +60,6 @@ var (
|
||||
testV1FIdxHLoadFromFolderDispatchers,
|
||||
testV1FIdxHGetDispatchersIndexesHealth,
|
||||
|
||||
*/
|
||||
|
||||
testV1FIdxHStopEngine,
|
||||
}
|
||||
)
|
||||
@@ -123,6 +120,13 @@ func testV1FIdxHRpcConn(t *testing.T) {
|
||||
|
||||
func testV1FIdxHLoadFromFolderTutorial2(t *testing.T) {
|
||||
var reply string
|
||||
if err := tFIdxHRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
|
||||
CacheIDs: nil,
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Reply: ", reply)
|
||||
}
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial2")}
|
||||
if err := tFIdxHRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
@@ -166,6 +170,13 @@ func testV1FIdxHReverseDestinationHealth(t *testing.T) {
|
||||
|
||||
func testV1FIdxHLoadFromFolderTutorial(t *testing.T) {
|
||||
var reply string
|
||||
if err := tFIdxHRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
|
||||
CacheIDs: nil,
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Reply: ", reply)
|
||||
}
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
|
||||
if err := tFIdxHRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -40,7 +40,7 @@ var (
|
||||
precacheRPC *rpc.Client
|
||||
precacheConfigDIR string //run tests for specific configuration
|
||||
|
||||
// use this flag to test the APIBan implemnentation for precache
|
||||
// use this flag to test the APIBan implementation for precache
|
||||
apiBan = flag.Bool("apiban", true, "used to control if we run the apiban tests")
|
||||
|
||||
sTestsPrecache = []func(t *testing.T){
|
||||
|
||||
@@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
|
||||
package engine
|
||||
|
||||
import (
|
||||
@@ -52,8 +51,8 @@ func TestCDRSV1ProcessCDRNoTenant(t *testing.T) {
|
||||
*rply = AttrSProcessEventReply{
|
||||
AlteredFields: []string{utils.AccountField},
|
||||
CGREvent: &utils.CGREvent{
|
||||
ID: "TestBiRPCv1AuthorizeEventNoTenant",
|
||||
Time: utils.TimePointer(time.Date(2016, time.January, 5, 18, 30, 49, 0, time.UTC)),
|
||||
ID: "TestBiRPCv1AuthorizeEventNoTenant",
|
||||
Time: utils.TimePointer(time.Date(2016, time.January, 5, 18, 30, 49, 0, time.UTC)),
|
||||
Event: map[string]interface{}{
|
||||
"Account": "1002",
|
||||
"Category": "call",
|
||||
@@ -75,10 +74,10 @@ func TestCDRSV1ProcessCDRNoTenant(t *testing.T) {
|
||||
db := NewInternalDB(nil, nil, true)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), connMngr)
|
||||
cdrs := &CDRServer{
|
||||
cgrCfg: cfg,
|
||||
cgrCfg: cfg,
|
||||
connMgr: connMngr,
|
||||
cdrDb: NewInternalDB(nil, nil, true),
|
||||
dm: dm,
|
||||
cdrDb: NewInternalDB(nil, nil, true),
|
||||
dm: dm,
|
||||
}
|
||||
cdr := &CDRWithAPIOpts{ // no tenant, take the default
|
||||
CDR: &CDR{
|
||||
@@ -131,24 +130,24 @@ func TestCDRSV1ProcessEventNoTenant(t *testing.T) {
|
||||
db := NewInternalDB(nil, nil, true)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), connMngr)
|
||||
cdrs := &CDRServer{
|
||||
cgrCfg: cfg,
|
||||
cgrCfg: cfg,
|
||||
connMgr: connMngr,
|
||||
cdrDb: NewInternalDB(nil, nil, true),
|
||||
dm: dm,
|
||||
cdrDb: NewInternalDB(nil, nil, true),
|
||||
dm: dm,
|
||||
}
|
||||
args := &ArgV1ProcessEvent{
|
||||
Flags: []string{utils.MetaChargers},
|
||||
CGREvent: utils.CGREvent{
|
||||
ID: "TestV1ProcessEventNoTenant",
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: "test1",
|
||||
utils.RunID: utils.MetaDefault,
|
||||
utils.OriginID: "testV1CDRsRefundOutOfSessionCost",
|
||||
utils.RequestType: utils.MetaPrepaid,
|
||||
utils.AccountField: "testV1CDRsRefundOutOfSessionCost",
|
||||
utils.Destination: "+4986517174963",
|
||||
utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
|
||||
utils.Usage: 123 * time.Minute,
|
||||
utils.CGRID: "test1",
|
||||
utils.RunID: utils.MetaDefault,
|
||||
utils.OriginID: "testV1CDRsRefundOutOfSessionCost",
|
||||
utils.RequestType: utils.MetaPrepaid,
|
||||
utils.AccountField: "testV1CDRsRefundOutOfSessionCost",
|
||||
utils.Destination: "+4986517174963",
|
||||
utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
|
||||
utils.Usage: 123 * time.Minute,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -185,10 +184,10 @@ func TestCDRSV1V1ProcessExternalCDRNoTenant(t *testing.T) {
|
||||
db := NewInternalDB(nil, nil, true)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), connMngr)
|
||||
cdrs := &CDRServer{
|
||||
cgrCfg: cfg,
|
||||
cgrCfg: cfg,
|
||||
connMgr: connMngr,
|
||||
cdrDb: NewInternalDB(nil, nil, true),
|
||||
dm: dm,
|
||||
cdrDb: NewInternalDB(nil, nil, true),
|
||||
dm: dm,
|
||||
}
|
||||
|
||||
args := &ExternalCDRWithAPIOpts{
|
||||
@@ -215,4 +214,3 @@ func TestCDRSV1V1ProcessExternalCDRNoTenant(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -349,7 +349,7 @@ func (dm *DataManager) GetDestination(key string, cacheRead, cacheWrite bool, tr
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheDestinations, key, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -477,7 +477,7 @@ func (dm *DataManager) GetReverseDestination(prefix string,
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheReverseDestinations, prefix, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -646,7 +646,7 @@ func (dm *DataManager) GetFilter(tenant, id string, cacheRead, cacheWrite bool,
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheFilters, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -774,7 +774,7 @@ func (dm *DataManager) GetThreshold(tenant, id string,
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheThresholds, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -975,7 +975,7 @@ func (dm *DataManager) RemoveThresholdProfile(tenant, id string, withIndex bool)
|
||||
APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID,
|
||||
config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString)})
|
||||
}
|
||||
return dm.RemoveThreshold(tenant, id) // remove the thrshold
|
||||
return dm.RemoveThreshold(tenant, id) // remove the threshold
|
||||
}
|
||||
|
||||
// GetStatQueue retrieves a StatQueue from dataDB
|
||||
@@ -1016,7 +1016,7 @@ func (dm *DataManager) GetStatQueue(tenant, id string,
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
if err = utils.CastRPCErr(err); err == utils.ErrNotFound && cacheWrite {
|
||||
if err = utils.CastRPCErr(err); err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheStatQueues, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -1115,7 +1115,7 @@ func (dm *DataManager) GetStatQueueProfile(tenant, id string, cacheRead, cacheWr
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheStatQueueProfiles, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -1385,7 +1385,7 @@ func (dm *DataManager) GetResource(tenant, id string, cacheRead, cacheWrite bool
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheResources, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -1474,7 +1474,7 @@ func (dm *DataManager) GetResourceProfile(tenant, id string, cacheRead, cacheWri
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheResourceProfiles, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -1922,7 +1922,7 @@ func (dm *DataManager) GetActionPlan(key string, cacheRead, cacheWrite bool, tra
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheActionPlans, key, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -2059,7 +2059,7 @@ func (dm *DataManager) GetAccountActionPlans(acntID string, cacheRead, cacheWrit
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheAccountActionPlans, acntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -2389,7 +2389,7 @@ func (dm *DataManager) GetRouteProfile(tenant, id string, cacheRead, cacheWrite
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheRouteProfiles, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -2523,7 +2523,7 @@ func (dm *DataManager) GetAttributeProfile(tenant, id string, cacheRead, cacheWr
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheAttributeProfiles, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -2658,7 +2658,7 @@ func (dm *DataManager) GetChargerProfile(tenant, id string, cacheRead, cacheWrit
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheChargerProfiles, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -2785,7 +2785,7 @@ func (dm *DataManager) GetDispatcherProfile(tenant, id string, cacheRead, cacheW
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheDispatcherProfiles, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -2916,7 +2916,7 @@ func (dm *DataManager) GetDispatcherHost(tenant, id string, cacheRead, cacheWrit
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(utils.CacheDispatcherHosts, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
@@ -3004,7 +3004,7 @@ func (dm *DataManager) GetItemLoadIDs(itemIDPrefix string, cacheWrite bool) (loa
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
for key := range loadIDs {
|
||||
if errCh := Cache.Set(utils.CacheLoadIDs, key, nil, nil,
|
||||
cacheCommit(utils.NonTransactional), utils.NonTransactional); errCh != nil {
|
||||
@@ -3101,12 +3101,10 @@ func (dm *DataManager) GetIndexes(idxItmType, tntCtx, idxKey string,
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound {
|
||||
if cacheWrite && idxKey != utils.EmptyString {
|
||||
if errCh := Cache.Set(idxItmType, utils.ConcatenatedKey(tntCtx, idxKey), nil, []string{tntCtx},
|
||||
true, utils.NonTransactional); errCh != nil {
|
||||
return nil, errCh
|
||||
}
|
||||
if err == utils.ErrNotFound && cacheWrite && idxKey != utils.EmptyString && dm.dataDB.GetStorageType() != utils.INTERNAL {
|
||||
if errCh := Cache.Set(idxItmType, utils.ConcatenatedKey(tntCtx, idxKey), nil, []string{tntCtx},
|
||||
true, utils.NonTransactional); errCh != nil {
|
||||
return nil, errCh
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -303,8 +303,8 @@ func TestHealthFilter(t *testing.T) {
|
||||
|
||||
if err := dm.SetIndexes(utils.CacheAttributeFilterIndexes, "cgrates.org:*any",
|
||||
map[string]utils.StringSet{"*string:*req.Account:1002": {
|
||||
"ATTR1": {},
|
||||
"ATTR2": {},
|
||||
"ATTR1": {},
|
||||
"ATTR2": {},
|
||||
}},
|
||||
true, utils.NonTransactional); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user