diff --git a/engine/attributes.go b/engine/attributes.go index 50b5889db..2eaaa8de4 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -65,7 +65,7 @@ func (alS *AttributeService) matchingAttributeProfilesForEvent(ev *utils.CGREven attrIdxKey = utils.ConcatenatedKey(ev.Tenant, contextVal) matchingAPs := make(map[string]*AttributeProfile) aPrflIDs, err := matchingItemIDsForEvent(ev.Event, alS.stringIndexedFields, alS.prefixIndexedFields, - alS.dm, utils.AttributeFilterIndexes, attrIdxKey) + alS.dm, utils.CacheAttributeFilterIndexes, attrIdxKey) if err != nil { if err != utils.ErrNotFound { return nil, err diff --git a/engine/attributes_test.go b/engine/attributes_test.go index 9ac1f2567..77019cd88 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -176,7 +176,8 @@ func TestAttributeCache(t *testing.T) { } //Test each attribute from cache for _, atr := range atrPs { - if tempAttr, err := dmAtr.GetAttributeProfile(atr.Tenant, atr.ID, false, utils.NonTransactional); err != nil { + if tempAttr, err := dmAtr.GetAttributeProfile(atr.Tenant, atr.ID, + false, utils.NonTransactional); err != nil { t.Errorf("Error: %+v", err) } else if !reflect.DeepEqual(atr, tempAttr) { t.Errorf("Expecting: %+v, received: %+v", atr, tempAttr) diff --git a/engine/destinations_test.go b/engine/destinations_test.go index 3eae18092..ebfaea941 100644 --- a/engine/destinations_test.go +++ b/engine/destinations_test.go @@ -36,13 +36,17 @@ func TestDestinationStoreRestore(t *testing.T) { } func TestDestinationStorageStore(t *testing.T) { - nationale := &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}} + nationale := &Destination{Id: "nat", + Prefixes: []string{"0257", "0256", "0723"}} err := dm.DataDB().SetDestination(nationale, utils.NonTransactional) if err != nil { t.Error("Error storing destination: ", err) } - result, err := dm.DataDB().GetDestination(nationale.Id, false, utils.NonTransactional) - if nationale.containsPrefix("0257") == 0 || nationale.containsPrefix("0256") == 0 || nationale.containsPrefix("0723") == 0 { + result, err := dm.DataDB().GetDestination(nationale.Id, + false, utils.NonTransactional) + if nationale.containsPrefix("0257") == 0 || + nationale.containsPrefix("0256") == 0 || + nationale.containsPrefix("0723") == 0 { t.Errorf("Expected %q was %q", nationale, result) } } @@ -86,38 +90,34 @@ func TestDestinationReverseGetExistsCache(t *testing.T) { } func TestDestinationGetNotExists(t *testing.T) { + if d, ok := Cache.Get(utils.CacheDestinations, "not existing"); ok { + t.Error("Bad destination cached: ", d) + } d, err := dm.DataDB().GetDestination("not existing", false, utils.NonTransactional) if d != nil { t.Error("Got false destination: ", d, err) } } -func TestDestinationGetNotExistsCache(t *testing.T) { - dm.DataDB().GetDestination("not existing", false, utils.NonTransactional) - if d, ok := Cache.Get(utils.CacheDestinations, "not existing"); ok { - t.Error("Bad destination cached: ", d) - } -} - -func TestCachedDestHasPrefix(t *testing.T) { +func TestDestinationCachedDestHasPrefix(t *testing.T) { if !CachedDestHasPrefix("NAT", "0256") { t.Error("Could not find prefix in destination") } } -func TestCachedDestHasWrongPrefix(t *testing.T) { +func TestDestinationCachedDestHasWrongPrefix(t *testing.T) { if CachedDestHasPrefix("NAT", "771") { t.Error("Prefix should not belong to destination") } } -func TestNonCachedDestRightPrefix(t *testing.T) { +func TestDestinationNonCachedDestRightPrefix(t *testing.T) { if CachedDestHasPrefix("FAKE", "0256") { t.Error("Destination should not belong to prefix") } } -func TestNonCachedDestWrongPrefix(t *testing.T) { +func TestDestinationNonCachedDestWrongPrefix(t *testing.T) { if CachedDestHasPrefix("FAKE", "771") { t.Error("Both arguments should be fake") } diff --git a/engine/filterhelpers_test.go b/engine/filterhelpers_test.go index d8027998c..1bb995db5 100644 --- a/engine/filterhelpers_test.go +++ b/engine/filterhelpers_test.go @@ -33,9 +33,7 @@ var ( ) func TestFilterMatchingItemIDsForEvent(t *testing.T) { - var stringFilter []*FilterRule - var prefixFilter []*FilterRule - var defaultFilter []*FilterRule + var stringFilter, prefixFilter, defaultFilter []*FilterRule stringFilterID := "stringFilterID" prefixFilterID := "prefixFilterID" defaultFilterID := "defaultFilterID" @@ -47,21 +45,24 @@ func TestFilterMatchingItemIDsForEvent(t *testing.T) { t.Errorf("Error: %+v", err) } stringFilter = append(stringFilter, x) - attribStringF := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "stringFilter", Rules: stringFilter} + attribStringF := &Filter{Tenant: config.CgrConfig().DefaultTenant, + ID: "stringFilter", Rules: stringFilter} dmMatch.SetFilter(attribStringF) x, err = NewFilterRule(MetaPrefix, "Field", []string{"profilePrefix"}) if err != nil { t.Errorf("Error: %+v", err) } prefixFilter = append(prefixFilter, x) - attribPrefF := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "prefFilter", Rules: prefixFilter} + attribPrefF := &Filter{Tenant: config.CgrConfig().DefaultTenant, + ID: "prefFilter", Rules: prefixFilter} dmMatch.SetFilter(attribPrefF) x, err = NewFilterRule(MetaGreaterOrEqual, "Weight", []string{"200.00"}) if err != nil { t.Errorf("Error: %+v", err) } defaultFilter = append(defaultFilter, x) - attribDefaultF := &Filter{Tenant: config.CgrConfig().DefaultTenant, ID: "defaultFilter", Rules: defaultFilter} + attribDefaultF := &Filter{Tenant: config.CgrConfig().DefaultTenant, + ID: "defaultFilter", Rules: defaultFilter} dmMatch.SetFilter(attribDefaultF) prefix := utils.ConcatenatedKey(config.CgrConfig().DefaultTenant, context) atrRFI := NewFilterIndexer(dmMatch, utils.AttributeProfilePrefix, prefix) @@ -89,7 +90,7 @@ func TestFilterMatchingItemIDsForEvent(t *testing.T) { "Field": "profilePrefix", } aPrflIDs, err = matchingItemIDsForEvent(matchEV, nil, nil, - dmMatch, utils.AttributeFilterIndexes, prefix) + dmMatch, utils.CacheAttributeFilterIndexes, prefix) if err != nil { t.Errorf("Error: %+v", err) } diff --git a/engine/storage_map.go b/engine/storage_map.go index 77343dbf2..9024c74a9 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1060,7 +1060,7 @@ func (ms *MapStorage) SetDerivedChargers(key string, return nil } result, err := ms.ms.Marshal(dcs) - ms.dict[key] = result + ms.dict[utils.DERIVEDCHARGERS_PREFIX+key] = result Cache.Remove(utils.CacheDerivedChargers, key, cCommit, transactionID) return err @@ -1385,7 +1385,7 @@ func (ms *MapStorage) MatchFilterIndexDrv(cacheID, itemIDPrefix, filterType, fldName, fldVal string) (itemIDs utils.StringMap, err error) { ms.mu.RLock() defer ms.mu.RUnlock() - values, ok := ms.dict[utils.ConcatenatedKey(utils.CacheInstanceToPrefix[cacheID], itemIDPrefix)] + values, ok := ms.dict[utils.CacheInstanceToPrefix[cacheID]+itemIDPrefix] if !ok { return nil, utils.ErrNotFound } diff --git a/engine/suppliers.go b/engine/suppliers.go index 46ffc09f0..41c58d3e1 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -115,8 +115,8 @@ func (spS *SupplierService) Shutdown() error { // matchingSupplierProfilesForEvent returns ordered list of matching resources which are active by the time of the call func (spS *SupplierService) matchingSupplierProfilesForEvent(ev *utils.CGREvent) (sPrfls SupplierProfiles, err error) { matchingLPs := make(map[string]*SupplierProfile) - sPrflIDs, err := matchingItemIDsForEvent(ev.Event, spS.stringIndexedFields, - spS.prefixIndexedFields, spS.dm, utils.CacheSupplierFilterIndexes, ev.Tenant) + sPrflIDs, err := matchingItemIDsForEvent(ev.Event, spS.stringIndexedFields, spS.prefixIndexedFields, + spS.dm, utils.CacheSupplierFilterIndexes, ev.Tenant) if err != nil { return nil, err }