cache refactoring for save and load

This commit is contained in:
Radu Ioan Fericean
2016-06-07 22:43:02 +03:00
parent 95e8230a5c
commit e84e28faae
35 changed files with 736 additions and 605 deletions

View File

@@ -21,7 +21,6 @@ package engine
import (
"encoding/json"
"github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"testing"
@@ -83,7 +82,7 @@ func TestDestinationGetExists(t *testing.T) {
func TestDestinationGetExistsCache(t *testing.T) {
ratingStorage.GetDestination("NAT")
if _, err := cache2go.Get(utils.DESTINATION_PREFIX + "0256"); err != nil {
if _, err := CacheGet(utils.DESTINATION_PREFIX + "0256"); err != nil {
t.Error("Destination not cached:", err)
}
}
@@ -97,7 +96,7 @@ func TestDestinationGetNotExists(t *testing.T) {
func TestDestinationGetNotExistsCache(t *testing.T) {
ratingStorage.GetDestination("not existing")
if d, err := cache2go.Get("not existing"); err == nil {
if d, err := CacheGet("not existing"); err == nil {
t.Error("Bad destination cached: ", d)
}
}
@@ -128,17 +127,17 @@ func TestNonCachedDestWrongPrefix(t *testing.T) {
func TestCleanStalePrefixes(t *testing.T) {
x := struct{}{}
cache2go.Cache(utils.DESTINATION_PREFIX+"1", map[interface{}]struct{}{"D1": x, "D2": x})
cache2go.Cache(utils.DESTINATION_PREFIX+"2", map[interface{}]struct{}{"D1": x})
cache2go.Cache(utils.DESTINATION_PREFIX+"3", map[interface{}]struct{}{"D2": x})
CacheSet(utils.DESTINATION_PREFIX+"1", map[string]struct{}{"D1": x, "D2": x})
CacheSet(utils.DESTINATION_PREFIX+"2", map[string]struct{}{"D1": x})
CacheSet(utils.DESTINATION_PREFIX+"3", map[string]struct{}{"D2": x})
CleanStalePrefixes([]string{"D1"})
if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "1"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
if r, err := CacheGet(utils.DESTINATION_PREFIX + "1"); err != nil || len(r.(map[string]struct{})) != 1 {
t.Error("Error cleaning stale destination ids", r)
}
if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "2"); err == nil {
if r, err := CacheGet(utils.DESTINATION_PREFIX + "2"); err == nil {
t.Error("Error removing stale prefix: ", r)
}
if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "3"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
if r, err := CacheGet(utils.DESTINATION_PREFIX + "3"); err != nil || len(r.(map[string]struct{})) != 1 {
t.Error("Error performing stale cleaning: ", r)
}
}