Tests passing with TransCache

This commit is contained in:
DanB
2018-03-01 12:37:10 +01:00
parent 441a7355e3
commit 8829d7bac7
6 changed files with 29 additions and 27 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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")
}

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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
}