From 2b8b7a3b96b4273582906924cb46d07df8b55f27 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Tue, 16 Mar 2021 14:11:24 +0200 Subject: [PATCH] Renamed join func + fixed intgration indexes tests for internal --- apier/v1/filter_indexes.go | 1 + apier/v1/filter_indexes_it_test.go | 11 ++++++++++- engine/storage_internal_datadb.go | 4 ++++ utils/consts.go | 2 +- utils/stringset.go | 3 ++- utils/stringset_test.go | 2 +- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apier/v1/filter_indexes.go b/apier/v1/filter_indexes.go index 5bae59e83..9575696f0 100644 --- a/apier/v1/filter_indexes.go +++ b/apier/v1/filter_indexes.go @@ -381,6 +381,7 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexes(args *utils.ArgsComputeFilterInde for key := range rpr.Rates { rtIds = append(rtIds, key) } + _, e = engine.ComputeIndexes(apierSv1.DataManager, tnt, id, utils.CacheRateFilterIndexes, &rtIds, transactionID, func(_, id, _ string) (*[]string, error) { rateFilters := make([]string, len(rpr.Rates[id].FilterIDs)) diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index a2af246b4..e769cb373 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -93,6 +93,7 @@ var ( testVF1ComputeIDsRateProfileRateIndexes, testVF1RemoveRateProfileRates, testV1FIdxdxInitDataDb, + testV1IndexClearCache, testV1FISetRateProfileIndexes, testV1FIComputeRateProfileIndexes, @@ -158,6 +159,13 @@ func testV1FIdxdxInitDataDb(t *testing.T) { } } +func testV1IndexClearCache(t *testing.T) { + var reply string + if err := tFIdxRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithOpts{}, &reply); err != nil { + t.Fatal(err) + } +} + // Wipe out the cdr database func testV1FIdxResetStorDb(t *testing.T) { if err := engine.InitStorDb(tSv1Cfg); err != nil { @@ -1804,7 +1812,7 @@ func testV1FISetRateProfileRatesIndexes(t *testing.T) { //there are not any rates in db var reply *engine.RateProfile if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile, - &utils.TenantIDWithOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RRATE_PRF"}}, &reply); err == nil || + &utils.TenantIDWithOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP1"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -2197,6 +2205,7 @@ func testVF1RemoveRateProfileRates(t *testing.T) { &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } + } //RateProfile Indexes diff --git a/engine/storage_internal_datadb.go b/engine/storage_internal_datadb.go index 17e9b657a..c24d0ee7f 100644 --- a/engine/storage_internal_datadb.go +++ b/engine/storage_internal_datadb.go @@ -921,6 +921,10 @@ func (iDB *InternalDB) SetIndexesDrv(idxItmType, tntCtx string, cacheCommit(utils.NonTransactional), utils.NonTransactional) continue } + //to be the same as HMSET + if x, ok := Cache.Get(idxItmType, dbKey); ok && x != nil { + indx = utils.JoinStringSet(indx, x.(utils.StringSet)) + } Cache.SetWithoutReplicate(idxItmType, dbKey, indx, []string{tntCtx}, cacheCommit(utils.NonTransactional), utils.NonTransactional) } diff --git a/utils/consts.go b/utils/consts.go index 450029b66..d87ee7910 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -66,7 +66,7 @@ var ( CacheTBLTPDispatcherHosts, CacheTBLTPRateProfiles, CacheTBLTPActionProfiles, CacheTBLTPAccountProfiles}) // CachePartitions enables creation of cache partitions - CachePartitions = Join(extraDBPartition, dataDBPartition, storDBPartition) + CachePartitions = JoinStringSet(extraDBPartition, dataDBPartition, storDBPartition) CacheInstanceToPrefix = map[string]string{ CacheDestinations: DestinationPrefix, diff --git a/utils/stringset.go b/utils/stringset.go index 1c6f61961..29bdfb807 100644 --- a/utils/stringset.go +++ b/utils/stringset.go @@ -115,7 +115,8 @@ func (s StringSet) GetOne() string { return EmptyString } -func Join(s ...StringSet) (conc StringSet) { +// JoinStringSet intersect multiple StringSets in one +func JoinStringSet(s ...StringSet) (conc StringSet) { conc = make(StringSet) for _, k := range s { for key := range k { diff --git a/utils/stringset_test.go b/utils/stringset_test.go index 301af8248..da1c00d4e 100644 --- a/utils/stringset_test.go +++ b/utils/stringset_test.go @@ -253,7 +253,7 @@ func TestStringSetJoin(t *testing.T) { set3 := StringSet{ "test3": struct{}{}, } - rcv := Join(set1, set2, set3) + rcv := JoinStringSet(set1, set2, set3) expected := StringSet{ "test1": struct{}{},